use amont_runtime::registry::CHECKS;
fn page(rel: &str) -> String {
let p = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join(rel);
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("read {}: {e}", p.display()))
}
fn spelled(n: usize) -> &'static str {
match n {
18 => "eighteen",
19 => "nineteen",
20 => "twenty",
21 => "twenty-one",
22 => "twenty-two",
23 => "twenty-three",
24 => "twenty-four",
25 => "twenty-five",
_ => panic!("teach spelled() the word for {n} while updating the prose"),
}
}
#[test]
fn the_prose_count_matches_the_registry() {
let word = spelled(CHECKS.len());
for rel in ["README.md", "docs/index.md", "docs/checks.md"] {
assert!(
page(rel).to_lowercase().contains(word),
"{rel} does not say \"{word}\" anywhere, but the registry has \
{} checks — the page is stating a stale count",
CHECKS.len()
);
}
let digit = format!("{} built-in checks", CHECKS.len());
assert!(
page("docs/similar-projects.md").contains(&digit),
"docs/similar-projects.md's comparison table does not say \
\"{digit}\" — the table is stating a stale count"
);
}
#[test]
fn no_page_states_a_neighbouring_count() {
let stale: Vec<&str> = (18..=25)
.filter(|&n| n != CHECKS.len())
.map(spelled)
.collect();
for rel in ["README.md", "docs/index.md", "docs/checks.md"] {
let text = page(rel).to_lowercase();
for word in &stale {
for phrase in [format!("{word} checks"), format!("{word} built-in checks")] {
assert!(
!text.contains(&phrase),
"{rel} says \"{phrase}\" while the registry has {} — \
one of them is wrong",
CHECKS.len()
);
}
}
}
}