From 3bda2fa258cc094382efb49573c242757f620928 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 15 Dec 2025 16:56:43 +0100 Subject: [PATCH] Updates coverage and adds some tests --- .run_status.toml | 8 ++--- badges/coverage.svg | 2 +- lib_efo/src/entity.rs | 3 +- ...effect_application_from_str_snapshots.snap | 14 +++++++++ .../lib_efo__entity__test__recurring.snap | 7 +++++ ...ib_efo__entity__test__when_present_wh.snap | 7 +++++ lib_efo/src/entity/test.rs | 29 ++++++++++++++++++- lib_efo/src/stats.rs | 1 - 8 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__effect_application_from_str_snapshots.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__recurring.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__when_present_wh.snap diff --git a/.run_status.toml b/.run_status.toml index bf74534..4208424 100644 --- a/.run_status.toml +++ b/.run_status.toml @@ -1,8 +1,8 @@ [last_run_clean] run_status = "Success" -lines_parsed = 98 -coverage = 52.9 +lines_parsed = 102 +coverage = 47.96 [last_run_clean.run_duration] -secs = 25 -nanos = 607715147 +secs = 26 +nanos = 496094925 diff --git a/badges/coverage.svg b/badges/coverage.svg index 0416daf..cbbfba6 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -test-coverage: 53%test-coverage53% \ No newline at end of file +test-coverage: 48%test-coverage48% \ No newline at end of file diff --git a/lib_efo/src/entity.rs b/lib_efo/src/entity.rs index 0dcdcd5..ae03914 100644 --- a/lib_efo/src/entity.rs +++ b/lib_efo/src/entity.rs @@ -13,7 +13,6 @@ use std::str::FromStr; -use clap::ValueEnum; use derive_more::{Add, Display, Sub}; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -95,7 +94,7 @@ pub struct EffectBounds { } /// How the entity's effect is applied over time. -#[derive(Debug, Serialize, Deserialize, Clone, Default, ValueEnum)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub enum EffectApplication { /// Repeatedly applied every turn while the entity is present. Recurring, diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__effect_application_from_str_snapshots.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__effect_application_from_str_snapshots.snap new file mode 100644 index 0000000..27f9970 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__effect_application_from_str_snapshots.snap @@ -0,0 +1,14 @@ +--- +source: lib_efo/src/entity/test.rs +expression: collect +--- + +recurring = Ok(Recurring) +when_present_wh = Ok(WhenPresent) +when_present_present = Ok(WhenPresent) +when_present_toap = Ok(WhenPresent) +when_present_appl = Ok(WhenPresent) +permanent_effect_applied_done = Ok(PermanentEffectApplied) +permanent_effect_applied_ok = Ok(PermanentEffectApplied) +permanent_effect_to_apply = Ok(PermanentEffectToApply) +parse_error = Err(ParsingArgument { argument_parsed: "unknown", while_parsing: "EffectApplication" }) diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__recurring.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__recurring.snap new file mode 100644 index 0000000..a4f657f --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__recurring.snap @@ -0,0 +1,7 @@ +--- +source: lib_efo/src/entity/test.rs +expression: result +--- +Ok( + Recurring, +) diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__when_present_wh.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__when_present_wh.snap new file mode 100644 index 0000000..fe0d597 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__when_present_wh.snap @@ -0,0 +1,7 @@ +--- +source: lib_efo/src/entity/test.rs +expression: result +--- +Ok( + WhenPresent, +) diff --git a/lib_efo/src/entity/test.rs b/lib_efo/src/entity/test.rs index 053b02b..d8b3882 100644 --- a/lib_efo/src/entity/test.rs +++ b/lib_efo/src/entity/test.rs @@ -1,6 +1,7 @@ // tests/mod.rs - or put this inside your crate's tests module #![allow(unused_imports)] +use std::arch::x86_64::_mm256_mask_inserti64x2; use std::str::FromStr; use crate::entity::{EffectApplication, EffectBounds, Entity, EntityDuration, EntityIdentifier}; @@ -12,7 +13,7 @@ use std::io::Write; use super::*; use crate::Displayable; -use insta::assert_snapshot; +use insta::{assert_debug_snapshot, assert_snapshot}; use uuid::Uuid; #[test] @@ -566,3 +567,29 @@ fn test_rng() { Entity::create_rng(&EntityType::Event, &crate::utils::RngLevel::Mixed).unwrap(); Entity::create_rng(&EntityType::Event, &crate::utils::RngLevel::Flawed).unwrap(); } + +/// All the inputs we want to test, in the same order the original +/// `match` evaluates them. The key is the snapshot name, the +/// value is the input string. +const TEST_CASES: &[(&str, &str)] = &[ + ("recurring", "re"), + ("when_present_wh", "wh"), + ("when_present_present", "present"), + ("when_present_toap", "toap"), + ("when_present_appl", "appl"), + ("permanent_effect_applied_done", "done"), + ("permanent_effect_applied_ok", "ok"), + ("permanent_effect_to_apply", "todo"), + ("parse_error", "unknown"), +]; + +#[test] +fn effect_application_from_str_snapshots() { + let mut collect = String::new(); + for (snapshot_name, input) in TEST_CASES { + let result: Result = + ::from_str(input); + collect = format!("{}\n{} = {:?}", collect, snapshot_name, result); + } + assert_snapshot!(collect); +} diff --git a/lib_efo/src/stats.rs b/lib_efo/src/stats.rs index ce55cde..8186a0e 100644 --- a/lib_efo/src/stats.rs +++ b/lib_efo/src/stats.rs @@ -391,7 +391,6 @@ pub struct MetaStats { /// UIDs of all entities the entity is linked to (roads, trade routes, /// alliances, war declarations, etc.). - // TODO: Type this vector, with a smart type: (Uuid, EntityType) pub links: Vec, /// Prestige / reputation of the entity in the eyes of the empire