Weksa/crates/weksa/tests/display.rs
Weksa 577f61092e Retire the English template table, lower(), request_gate and show_working
Delete the table rows, lower(), request_gate, their seven LowerError
variants, the show_working example with tools/show-working and its publish
script, and the table-pinned tests. lower.rs stays as the entity port,
pronounce and phones. weksa lower becomes weksa pronounce (IPA lines, or the
phones JSON with --phones); no deterministic path produces lowered text.
The consent-gate invariant has no owner after this cut (follow-up
table-retirement-consent-owner); V14 and V15 still own the field.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 03:55:13 +00:00

120 lines
3.6 KiB
Rust

//! Error text is a fixed message naming the rule or variant. The caller's
//! identifiers (entity, node and inventory ids, IPA text, value strings) stay
//! on the typed value and never reach Display.
use std::collections::HashSet;
use weksa::packet::{EntityId, NodeId, ProvenanceSource};
use weksa::{Family, InvId, LowerError, Refusal, Slot};
const SENTINEL: &str = "sentinelzz";
fn inv() -> InvId {
InvId::parse("concept:4242").unwrap()
}
fn node() -> NodeId {
NodeId::parse("n4242").unwrap()
}
fn entity() -> EntityId {
EntityId::parse(&format!("entity:{SENTINEL}")).unwrap()
}
fn assert_clean_and_distinct<T: std::fmt::Display + std::fmt::Debug>(all: Vec<T>) {
let mut seen = HashSet::new();
for e in all {
let text = e.to_string();
assert!(!text.is_empty(), "{e:?}");
for leak in [SENTINEL, "4242", "{", "}"] {
assert!(!text.contains(leak), "{e:?} leaks {leak:?}: {text}");
}
assert!(seen.insert(text.clone()), "{e:?} repeats {text:?}");
}
}
#[test]
fn lower_error_display_names_the_variant_and_no_identifier() {
assert_clean_and_distinct(vec![
LowerError::UnknownEntity { entity: entity() },
LowerError::NoForm { entity: entity() },
LowerError::NoPronunciation { entity: entity() },
LowerError::NoEntityReferent,
LowerError::UnknownPhone {
entity: entity(),
at: 4242,
text: SENTINEL.into(),
},
LowerError::DanglingStress {
entity: entity(),
at: 4242,
},
LowerError::EntityRead {
entity: entity(),
why: SENTINEL.into(),
},
]);
assert_eq!(
LowerError::NoPronunciation { entity: entity() }.to_string(),
"entity has no ruled pronunciation"
);
}
#[test]
fn refusal_display_names_the_rule_and_no_identifier() {
let all = vec![
Refusal::V1SchemaVersion { found: 4242 },
Refusal::V2PayloadRequired,
Refusal::V3DuplicateNode { id: node() },
Refusal::V4DanglingRef {
id: node(),
at: SENTINEL,
},
Refusal::V5Unresolved { id: inv() },
Refusal::V6WrongFamily {
id: inv(),
expected: Family::Role,
at: SENTINEL,
},
Refusal::V7ValueKind {
what: SENTINEL.into(),
},
Refusal::V8NotApplicable {
feature: inv(),
slot: Slot::Scene,
},
Refusal::V10UnknownRevision { rev: 4242 },
Refusal::V11DuplicateFeature {
feature: inv(),
slot: Some(Slot::Scene),
},
Refusal::V11DuplicateNodeRef {
id: node(),
at: SENTINEL,
},
Refusal::V11DuplicateRole {
role: inv(),
predication: node(),
},
Refusal::V12TooManyNodes {
count: 4242,
max: 4242,
},
Refusal::V14ConsentWithoutAddressee,
Refusal::V14ConsentNotAPredication { id: node() },
Refusal::V15ConsentSource {
source: ProvenanceSource::ImportedCorpus,
},
Refusal::V16SpeakerNotInScene,
Refusal::V17AddresseeNotAReferent { id: node() },
];
assert_eq!(
Refusal::V16SpeakerNotInScene.to_string(),
"V16: the scene does not cover the speaker of every live item of its group"
);
for r in &all {
assert!(r.to_string().starts_with(r.rule()), "{r:?}");
}
assert_clean_and_distinct(all);
assert_eq!(
Refusal::V14ConsentNotAPredication { id: node() }.to_string(),
"V14: consent names no predication"
);
}