use super::*;
#[test]
fn an_existing_node_still_has_a_weight_in_its_parent() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let Ok(spec) = std::fs::read_to_string(root.join("SPEC.md")) else {
unreachable!("this repository has a root spec")
};
let (rows, tokens) = row_weight(&spec, "tdd");
assert!(rows > 0, "root names `tdd` on real rows");
assert!(tokens > 0);
assert_eq!(row_weight(&spec, "wombat"), (0, 0));
}
#[test]
fn a_filename_is_not_a_row_about_the_node_it_spells() {
assert!(!names_word("the node carries `SPEC.md`", "spec"));
assert!(names_word("`spec` owns the section split", "spec"));
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let Ok(text) = std::fs::read_to_string(root.join("SPEC.md")) else {
unreachable!("this repository has a root spec")
};
let counted = naming_rows(&text, "spec").len();
let lowercased = text
.lines()
.filter(|l| !l.starts_with("## \u{a7}"))
.filter(|l| {
l.to_lowercase()
.split(|c: char| !c.is_alphanumeric() && c != '_')
.any(|w| w == "spec")
})
.count();
assert!(
lowercased > counted,
"the lowercasing counted more than the case-sensitive read: \
{lowercased} against {counted}"
);
for row in naming_rows(&text, "spec") {
assert!(
names_word(row.as_str(), "spec"),
"a row was counted only for spelling the FILE: {row}"
);
}
}
#[test]
fn generated_navigation_is_not_law_about_a_sibling() {
let spec = "## \u{a7}N NAV\n\nrel|path|lens\nsib|src/tdd|the loop\n\n\
## \u{a7}F FEDERATION\n\ndir|lens|grade\ntdd|the loop|HT\n\n\
## \u{a7}V INVARIANTS\n\nV1: `tdd` refuses a green test\n";
assert_eq!(
naming_rows(spec, "tdd"),
vec!["V1: `tdd` refuses a green test".to_string()],
"only the §V row is law about `tdd`"
);
}
#[test]
fn a_leaf_spec_weighs_nothing_for_its_siblings() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let Ok(text) = std::fs::read_to_string(root.join("src/tdd/SPEC.md")) else {
unreachable!("this repository has a spec for `src/tdd`")
};
assert!(
text.contains("sib|src/lens"),
"the nav does list `lens` as a sibling"
);
for row in naming_rows(&text, "lens") {
assert!(
!row.starts_with("sib|")
&& !row.starts_with("up|")
&& !row.starts_with("rel|"),
"a nav row was weighed as law about a sibling: {row}"
);
}
}