Files
wanderbooks/crates/ledger-core/tests/bookspec/rules_md.rs
T
swaitsandMuse Wonder 1.0 de57598df8 docs(spec): every CHOICE wanderbooks claims has a declared pick
Add the seven older CHOICE records (with a B number) that carried no declared pick in the adapter, taking each option from its record's options and the claims file's existing Pick line for its B section:

- BS-arap-2 lines-that-stand, BS-arap-5 direct-write-off, BS-asset-3 tag-and-never-reuse, BS-ledger-6 reversible-once, BS-ledger-9 facts-in-the-books, BS-ledger-10 label-only, BS-statement-5 project-is-a-class
- PICKS in crates/ledger-core/tests/bookspec/engine.rs gains all seven; each claims file gains a '**Pick (BS-...):**' line beside its B section's Pick
- Widen rules_md.rs's pick check from b == 0 records to every non-retired CHOICE record wanderbooks claims, so no CHOICE can go undeclared again

Co-Authored-By: Muse Wonder 1.0
2026-11-08 15:59:44 -07:00

79 lines
3.0 KiB
Rust

use crate::*;
/// `docs/spec/claims/*.md` carry every stated rule's id under its heading,
/// `docs/spec/rules.md` indexes every rule to its claims file, and neither
/// calls a choice a decision (P14 unit S-D0; P13 step 3).
#[test]
pub(crate) fn rules_md_carries_every_id() {
let spec = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../docs/spec");
let index = std::fs::read_to_string(spec.join("rules.md")).expect("docs/spec/rules.md");
let mut claims = std::fs::read_dir(spec.join("claims"))
.expect("docs/spec/claims")
.map(|entry| entry.expect("a claims entry").path())
.filter(|path| path.extension().is_some_and(|ext| ext == "md"))
.collect::<Vec<_>>();
claims.sort();
assert!(!claims.is_empty(), "docs/spec/claims holds the rule text");
let mut all = String::new();
for path in &claims {
let text = std::fs::read_to_string(path)
.unwrap_or_else(|error| panic!("{}: {error}", path.display()));
all.push_str(&text);
all.push('\n');
}
for rule in bookspec_checker::rules().iter() {
if rule.is_retired() {
continue;
}
// Every non-retired CHOICE record wanderbooks claims -- whether
// it carries a B number or was split out of another rule (P14
// unit S-C7) -- has its pick recorded in its claims file, and
// the engine's adapter declares the same option, which the
// record names, so no CHOICE can go undeclared.
if rule.status == Some(bookspec_checker::Status::Choice) {
let marker = format!("**Pick ({}):** `", rule.id);
let at = all
.find(&marker)
.unwrap_or_else(|| panic!("{} carries its pick in its claims file", rule.id));
let option = all[at + marker.len()..].split('`').next().unwrap();
assert!(
rule.record().options.iter().any(|o| o.name == option),
"{}'s pick {option:?} is one of its options",
rule.id
);
assert!(
engine::PICKS
.iter()
.any(|&(area, n, o)| RuleId::new(area, n) == rule.id && o == option),
"{}'s pick {option:?} is declared in the adapter's claims()",
rule.id
);
}
if rule.b == 0 {
// A rule born after the B numbering has no row in the index.
continue;
}
assert!(
index.contains(&format!("| B-{} | `{}` |", rule.b, rule.id)),
"rules.md indexes B-{} to {}",
rule.b,
rule.id
);
if rule.status.is_some() {
assert!(
all.contains(&format!("**bookspec:** `{}`", rule.id)),
"B-{} carries {} in its claims file",
rule.b,
rule.id
);
}
}
assert!(
!index.contains("DECISION") && !all.contains("DECISION"),
"the rules speak bookspec's CHOICE"
);
}