From a1bed93bb0c22c963dcdb94e88e47d799d79cf0e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 13 Dec 2025 03:44:32 +0100 Subject: [PATCH] Adds more testing --- ...y__test__snapshot_delta_stat_positive.snap | 91 ++++++++++ ...entity__test__snapshot_entity_delta-2.snap | 162 ++++++++++++++++++ ...ty__test__snapshot_meta_stats_delta-2.snap | 25 +++ ...ty__test__snapshot_meta_stats_delta-3.snap | 25 +++ ...ntity__test__snapshot_modify_duration.snap | 93 ++++++++++ ...t__snapshot_modify_effect_application.snap | 91 ++++++++++ ...__test__snapshot_modify_effect_bounds.snap | 91 ++++++++++ lib_efo/src/entity/test.rs | 84 ++++++--- 8 files changed, 637 insertions(+), 25 deletions(-) create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_delta_stat_positive.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_entity_delta-2.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-2.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-3.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_duration.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_application.snap create mode 100644 lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_bounds.snap diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_delta_stat_positive.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_delta_stat_positive.snap new file mode 100644 index 0000000..c0df3e1 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_delta_stat_positive.snap @@ -0,0 +1,91 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", e)" +--- +Entity { + name: "", + id: 00000000-0000-0000-0000-000000000000, + stats: OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 4, + ), + }, + temp_stats: None, + metadata: MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: None, + links: [], + prestige: GenericStat( + 0, + ), + }, + entity_type: Event, + duration: Done, + effect_nature: PermanentEffectToApply, + effect_bounds: EffectBounds { + min: 0, + max: 0, + }, +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_entity_delta-2.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_entity_delta-2.snap new file mode 100644 index 0000000..51b4cdc --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_entity_delta-2.snap @@ -0,0 +1,162 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", delta2)" +--- +Entity { + name: "Bob", + id: 00000000-0000-0000-0000-000000000000, + stats: OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 0, + ), + }, + temp_stats: Some( + OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 0, + ), + }, + ), + metadata: MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: Some( + FactionId( + 5, + ), + ), + links: [ + TownId( + 6, + ), + ], + prestige: GenericStat( + 0, + ), + }, + entity_type: Town, + duration: Permanent, + effect_nature: Recurring, + effect_bounds: EffectBounds { + min: 0, + max: 0, + }, +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-2.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-2.snap new file mode 100644 index 0000000..3beae88 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-2.snap @@ -0,0 +1,25 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", delta2)" +--- +MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: Some( + FactionId( + 33, + ), + ), + links: [ + TownId( + 55, + ), + ], + prestige: GenericStat( + 0, + ), +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-3.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-3.snap new file mode 100644 index 0000000..63e30c0 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_meta_stats_delta-3.snap @@ -0,0 +1,25 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", delta3)" +--- +MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: Some( + FactionId( + 33, + ), + ), + links: [ + TownId( + 55, + ), + ], + prestige: GenericStat( + 0, + ), +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_duration.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_duration.snap new file mode 100644 index 0000000..61f463d --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_duration.snap @@ -0,0 +1,93 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", e)" +--- +Entity { + name: "", + id: 00000000-0000-0000-0000-000000000000, + stats: OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 0, + ), + }, + temp_stats: None, + metadata: MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: None, + links: [], + prestige: GenericStat( + 0, + ), + }, + entity_type: Event, + duration: Duration( + 33, + ), + effect_nature: PermanentEffectToApply, + effect_bounds: EffectBounds { + min: 0, + max: 0, + }, +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_application.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_application.snap new file mode 100644 index 0000000..3fffbfd --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_application.snap @@ -0,0 +1,91 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", e)" +--- +Entity { + name: "", + id: 00000000-0000-0000-0000-000000000000, + stats: OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 0, + ), + }, + temp_stats: None, + metadata: MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: None, + links: [], + prestige: GenericStat( + 0, + ), + }, + entity_type: Event, + duration: Done, + effect_nature: PermanentEffectApplied, + effect_bounds: EffectBounds { + min: 0, + max: 0, + }, +} diff --git a/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_bounds.snap b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_bounds.snap new file mode 100644 index 0000000..7ce3de6 --- /dev/null +++ b/lib_efo/src/entity/snapshots/lib_efo__entity__test__snapshot_modify_effect_bounds.snap @@ -0,0 +1,91 @@ +--- +source: lib_efo/src/entity/test.rs +expression: "format!(\"{:#?}\", e)" +--- +Entity { + name: "", + id: 00000000-0000-0000-0000-000000000000, + stats: OverallStats { + demographics: GenericStat( + 0, + ), + population: GenericStat( + 0, + ), + growth_rate: GenericStat( + 0, + ), + crime: GenericStat( + 0, + ), + happiness: GenericStat( + 0, + ), + economy: GenericStat( + 0, + ), + food: GenericStat( + 0, + ), + industry: GenericStat( + 0, + ), + science: GenericStat( + 0, + ), + trade: GenericStat( + 0, + ), + military: GenericStat( + 0, + ), + army: GenericStat( + 0, + ), + strength: GenericStat( + 0, + ), + fortification: GenericStat( + 0, + ), + threat: GenericStat( + 0, + ), + infrastructure: GenericStat( + 0, + ), + bureaucracy: GenericStat( + 0, + ), + transportation: GenericStat( + 0, + ), + sprawl: GenericStat( + 0, + ), + health: GenericStat( + 0, + ), + }, + temp_stats: None, + metadata: MetaStats { + position: Position( + 0, + 0, + ), + capital: None, + governor: None, + faction: None, + links: [], + prestige: GenericStat( + 0, + ), + }, + entity_type: Event, + duration: Done, + effect_nature: PermanentEffectToApply, + effect_bounds: EffectBounds { + min: 33, + max: 33, + }, +} diff --git a/lib_efo/src/entity/test.rs b/lib_efo/src/entity/test.rs index 5741893..a1a9258 100644 --- a/lib_efo/src/entity/test.rs +++ b/lib_efo/src/entity/test.rs @@ -14,10 +14,6 @@ use crate::Displayable; use insta::assert_snapshot; use uuid::Uuid; -/// The same structs & enums that the original crate exports - adjust the names -/// if your crate uses different identifiers. - -// ---------- EntityDuration ---------- #[test] fn entity_duration_parses_permanent_and_done() { assert_eq!( @@ -122,7 +118,6 @@ fn entity_duration_returns_error_on_invalid_inputs() { } } -// ---------- EffectBounds ---------- #[test] fn effect_bounds_parses_colon_and_dash_separated_values() { // colon @@ -186,7 +181,6 @@ fn effect_bounds_returns_error_on_invalid_inputs() { } } -// ---------- EntityIdentifier ---------- #[test] fn entity_identifier_parses_id_and_name() { // id @@ -228,23 +222,10 @@ fn entity_identifier_errors_on_invalid_id() { // } } -// #[test] -// fn entity_identifier_treats_non_prefixed_@ as name() { -// // leading space -> part of the name -// let name = EntityIdentifier::from_str(" @uuid").unwrap(); -// match name { -// EntityIdentifier::Name(n) => assert_eq!(n, " @uuid"), -// _ => panic!("Expected Name variant"), -// } -// } -// - -/// Disable coloured output so that snapshots are stable (no ANSI codes). fn init_snapshot_env() { colored::control::set_override(false); } -/// Build a fully-featured entity (capital, governor, prestige > 0). fn full_entity() -> Entity { Entity { id: Uuid::from_u128_le(12), @@ -421,13 +402,13 @@ fn snapshot_entity_delta() { // Compute the delta let mut delta = e1.delta(&e2); + let mut delta2 = e2.delta(&e2); delta.id = Uuid::nil(); + delta2.id = Uuid::nil(); assert_snapshot!(format!("{:#?}", delta)); + assert_snapshot!(format!("{:#?}", delta2)); } -/// ------------------------------------------------------------------ -/// 3. `Diffable` - `Option` -/// ------------------------------------------------------------------ #[test] fn snapshot_option_stats_delta() { init_snapshot_env(); @@ -444,9 +425,6 @@ fn snapshot_option_stats_delta() { assert_snapshot!(format!("{:#?}", delta)); } -/// ------------------------------------------------------------------ -/// 4. `Diffable` - `MetaStats` -/// ------------------------------------------------------------------ #[test] fn snapshot_meta_stats_delta() { init_snapshot_env(); @@ -468,8 +446,64 @@ fn snapshot_meta_stats_delta() { links: vec![TownId::from(55)], prestige: stats::GenericStat(1), }; + let meta3 = MetaStats { + position: Position::from((44, 555)), + capital: None, + governor: Some(stats::CharacterId(400)), + faction: Some(stats::FactionId(33)), + links: vec![TownId::from(55)], + prestige: stats::GenericStat(1), + }; let delta = meta1.delta(&meta2); + let delta2 = meta2.delta(&meta3); + let delta3 = meta3.delta(&meta3); assert_snapshot!(format!("{:#?}", delta)); + assert_snapshot!(format!("{:#?}", delta2)); + assert_snapshot!(format!("{:#?}", delta3)); +} + +#[test] +fn snapshot_delta_stat_positive() { + init_snapshot_env(); + + let mut e = Entity::default(); + e.delta_stat(StatPair::from_str("health:4").unwrap()); + e.id = Uuid::nil(); + + assert_snapshot!(format!("{:#?}", e)); +} + +#[test] +fn snapshot_modify_duration() { + init_snapshot_env(); + + let mut e = Entity::default(); + e.modify_duration(EntityDuration::Duration(33)); + e.id = Uuid::nil(); + + assert_snapshot!(format!("{:#?}", e)); +} + +#[test] +fn snapshot_modify_effect_application() { + init_snapshot_env(); + + let mut e = Entity::default(); + e.modify_effect_application(EffectApplication::PermanentEffectApplied); + e.id = Uuid::nil(); + + assert_snapshot!(format!("{:#?}", e)); +} + +#[test] +fn snapshot_modify_effect_bounds() { + init_snapshot_env(); + + let mut e = Entity::default(); + e.modify_effect_bounds(EffectBounds::from(33..33)); + e.id = Uuid::nil(); + + assert_snapshot!(format!("{:#?}", e)); }