✅ test(@projects/@magic-civilization): 🧪 add serde round-trip and default mode tests
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
b75e3c67f3
commit
fbaca9de95
1 changed files with 75 additions and 0 deletions
|
|
@ -112,6 +112,81 @@ mod tests {
|
|||
assert_eq!(LairCombatMode::default(), LairCombatMode::Assault);
|
||||
}
|
||||
|
||||
// ── p3-10a acceptance-named tests ──────────────────────────────────
|
||||
// Aliases that match the names cited in the objective brief so a
|
||||
// grep for the canonical test names resolves directly. Bodies are
|
||||
// deliberately distinct (round-trip via Vec, default-as-existing-
|
||||
// callers contract, total-Ord consistency over the full variant
|
||||
// set) to give independent coverage rather than duplicating the
|
||||
// older tests above.
|
||||
|
||||
#[test]
|
||||
fn test_lair_mode_serde_round_trip() {
|
||||
// Round-trip every variant through a Vec to exercise the derived
|
||||
// Serialize/Deserialize end-to-end (not just one variant at a time).
|
||||
let all = vec![
|
||||
LairCombatMode::Assault,
|
||||
LairCombatMode::Siege,
|
||||
LairCombatMode::Raid,
|
||||
];
|
||||
let json = serde_json::to_string(&all).expect("serialise vec of modes");
|
||||
assert_eq!(json, "[\"assault\",\"siege\",\"raid\"]");
|
||||
let back: Vec<LairCombatMode> =
|
||||
serde_json::from_str(&json).expect("deserialise vec of modes");
|
||||
assert_eq!(back, all);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_assault_is_default_mode_for_existing_callers() {
|
||||
// Existing callers in `mc-turn` and `api-gdext` rely on `Default`
|
||||
// returning `Assault` so wiring `mode: LairCombatMode` defaults to
|
||||
// unchanged behaviour. Pin that contract.
|
||||
let m: LairCombatMode = Default::default();
|
||||
assert_eq!(m, LairCombatMode::Assault);
|
||||
// And: a freshly Default-constructed mode must be the only variant
|
||||
// for which `resolve_lair_combat` (in mc-combat) returns Ok — the
|
||||
// siege/raid stubs deliberately error. We only check the local
|
||||
// contract here; the dispatcher contract lives in mc-combat.
|
||||
assert!(matches!(m, LairCombatMode::Assault));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lair_mode_ord_consistent_with_all_variants() {
|
||||
// `Ord` is derived; lock in the declared order
|
||||
// (Assault < Siege < Raid) so JSON-config code that sorts modes
|
||||
// by enum order keeps a stable shape across crate refactors.
|
||||
let mut all = vec![
|
||||
LairCombatMode::Raid,
|
||||
LairCombatMode::Assault,
|
||||
LairCombatMode::Siege,
|
||||
];
|
||||
all.sort();
|
||||
assert_eq!(
|
||||
all,
|
||||
vec![
|
||||
LairCombatMode::Assault,
|
||||
LairCombatMode::Siege,
|
||||
LairCombatMode::Raid,
|
||||
]
|
||||
);
|
||||
|
||||
// Total-order consistency: comparing every pair must agree with
|
||||
// PartialOrd and be antisymmetric.
|
||||
let variants = [
|
||||
LairCombatMode::Assault,
|
||||
LairCombatMode::Siege,
|
||||
LairCombatMode::Raid,
|
||||
];
|
||||
for a in &variants {
|
||||
for b in &variants {
|
||||
assert_eq!(a.cmp(b), a.partial_cmp(b).unwrap());
|
||||
if a != b {
|
||||
assert_ne!(a.cmp(b), std::cmp::Ordering::Equal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lair_id_round_trips_as_bare_string() {
|
||||
let id = LairId::new("frostfang_den_01");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue