use std::collections::HashSet;
use wasm4pm_compat::declare::DeclareTemplate::{self, *};
const ALL: [DeclareTemplate; 22] = [
Existence,
Absence,
Init,
Existence2,
Existence3,
Absence2,
Absence3,
RespondedExistence,
CoExistence,
Response,
Precedence,
Succession,
AlternateResponse,
AlternatePrecedence,
AlternateSuccession,
ChainResponse,
ChainPrecedence,
ChainSuccession,
NotSuccession,
NotChainSuccession,
NotCoExistence,
ExclusiveChoice,
];
#[test]
fn every_declare_template_has_a_lawful_arity_and_taxonomy() {
for t in ALL {
let (expected_arity, unary) = match t {
Existence | Absence | Init | Existence2 | Existence3 | Absence2 | Absence3 => (1, true),
RespondedExistence | CoExistence | Response | Precedence | Succession
| AlternateResponse | AlternatePrecedence | AlternateSuccession | ChainResponse
| ChainPrecedence | ChainSuccession | NotSuccession | NotChainSuccession
| NotCoExistence | ExclusiveChoice => (2, false),
};
assert_eq!(t.arity(), expected_arity, "{t:?} arity");
assert_eq!(t.arity() == 1, unary, "{t:?} unary/binary classification");
}
}
#[test]
fn negative_and_chain_taxonomies_match_the_library_contract() {
for t in [
Absence,
Absence2,
Absence3,
NotCoExistence,
NotSuccession,
NotChainSuccession,
] {
assert!(t.is_negative(), "{t:?} is a negative (forbidding) template");
}
for t in [Existence, Response, Succession, ExclusiveChoice] {
assert!(!t.is_negative(), "{t:?} is NOT negative per the library");
}
for t in [
ChainResponse,
ChainPrecedence,
ChainSuccession,
NotChainSuccession,
] {
assert!(t.is_chain(), "{t:?} is a chain template");
}
assert!(!Response.is_chain(), "Response is not a chain template");
}
#[test]
fn all_22_templates_are_distinct() {
let set: HashSet<_> = ALL.iter().collect();
assert_eq!(set.len(), 22, "no two templates collapse to the same value");
}