Cotton code
109 lines · 3.4 KB · RustRaw
//! The section registry's totality gates.//!//! One list, judged in one place. The Swift tests (`SectionRegistryTests`)//! stay where they are: they prove the GENERATED file says this, which is a//! different claim from the list being total, and both are worth having.use super::*;use std::collections::BTreeMap;#[test]fn every_record_kind_is_placed_exactly_once_or_excused_in_writing() {    let mut placed: BTreeMap<&str, &str> = BTreeMap::new();    for entry in SECTION_LIST {        for kind in section_kinds(entry.key) {            let already = placed.insert(kind.as_str(), entry.key.as_str());            assert!(                already.is_none(),                "{} is owned by {} and by {}",                kind.as_str(),                already.unwrap_or(""),                entry.key.as_str()            );        }    }    for kind in PrimitiveKind::ALL {        let excused = MACHINERY_KINDS.iter().any(|(named, _)| *named == kind);        assert!(            placed.contains_key(kind.as_str()) || excused,            "{} is in no section and is not excused — that is invisible, not hidden",            kind.as_str()        );    }}#[test]fn the_list_and_the_key_enum_are_one_declaration() {    assert_eq!(SECTION_LIST.len(), SectionKey::ALL.len());    for key in SectionKey::ALL {        assert_eq!(section_entry(key).key, key);    }    for (at, entry) in SECTION_LIST.iter().enumerate() {        assert_eq!(entry.key, SectionKey::ALL[at], "the two orders disagree");    }}#[test]fn shortcuts_are_usable_digits_and_never_shared() {    let mut seen: Vec<u8> = Vec::new();    for entry in SECTION_LIST {        let Some(shortcut) = entry.shortcut else {            continue;        };        assert!(            (1..=9).contains(&shortcut),            "{} has ⌘{shortcut}",            entry.key.as_str()        );        assert!(!seen.contains(&shortcut), "⌘{shortcut} is claimed twice");        seen.push(shortcut);    }}#[test]fn every_group_the_list_names_is_a_declared_group_and_every_group_is_used() {    for group in SectionGroup::ALL {        assert!(            SECTION_LIST.iter().any(|entry| entry.group == group),            "{} has no rows",            group.as_str()        );    }    // The rows are contiguous per group, in `SectionGroup::ALL`'s order —    // which is what makes the navigator's headings correct without sorting.    let order: Vec<usize> = SECTION_LIST        .iter()        .map(|entry| {            SectionGroup::ALL                .iter()                .position(|group| *group == entry.group)                .expect("a declared group")        })        .collect();    let mut sorted = order.clone();    sorted.sort_unstable();    assert_eq!(order, sorted, "the groups interleave");}#[test]fn a_key_round_trips_through_its_string() {    for key in SectionKey::ALL {        assert_eq!(SectionKey::parse(key.as_str()), Some(key));    }    assert_eq!(SectionKey::parse("shelf"), None);}#[test]fn the_section_for_a_kind_is_the_one_that_owns_it() {    assert_eq!(        section_for_kind(PrimitiveKind::Photo).map(|entry| entry.key),        Some(SectionKey::Photos)    );    assert_eq!(        section_for_kind(PrimitiveKind::Memory).map(|entry| entry.key),        Some(SectionKey::Writing)    );    // Machinery has no section, and that is the answer, not a bug.    assert_eq!(section_for_kind(PrimitiveKind::TodoRecurrence), None);}