//! The page's order and what it draws, stated as arithmetic. //! //! Nothing here reads a clock or a file: the module under test is a function of //! its arguments. Every key is a section key or an invented one no build has //! ([nothing-real-ever-goes-in-cotton-s-public-tree]). use super::{ briefing_holds, default_order, present_sections, tile_order, section_view, view_section, Holding, PageSection, PresentSection, PLACED_AFTER, }; use crate::constants::ProjectSectionKey; fn said(entries: &[&str]) -> Vec { entries.iter().map(|entry| (*entry).to_string()).collect() } fn keys(order: &[PageSection]) -> Vec<&'static str> { order.iter().map(|section| section.as_str()).collect() } /// RULE: Every link group of a project is a section of its page, exactly once, and a group added to the crate takes its place with no second list to edit. #[test] fn the_default_order_holds_every_link_group_once_in_the_crates_own_order() { let order = default_order(); let linked: Vec = order .iter() .filter_map(|section| match section { PageSection::Linked(key) => Some(*key), _ => None, }) .collect(); assert_eq!(linked, ProjectSectionKey::ALL.to_vec()); assert_eq!(order.len(), ProjectSectionKey::ALL.len() + PLACED_AFTER.len()); for (placed, anchor) in PLACED_AFTER { let at = order.iter().position(|section| *section == placed).expect("placed"); assert_eq!(order[at - 1], PageSection::Linked(anchor), "{} follows its anchor", placed.as_str()); } } #[test] fn a_key_reads_back_as_the_section_it_spells_and_an_unknown_one_as_nothing() { for section in default_order() { assert_eq!(PageSection::parse(section.as_str()), Some(section)); } assert_eq!(PageSection::parse("an-invented-section"), None); assert_eq!(PageSection::parse(""), None); } // ── Home's order ────────────────────────────────────────────────────────── /// RULE: a project's sections read in Home's order — each where its tile sits, its own view or the list of the tool covering it — and a section with no tile keeps its default place after them (architect, 13 Oct 2026: the board's tile order is the one order). #[test] fn the_sections_read_where_their_tiles_sit_on_home() { assert_eq!(tile_order(&[], "kiln"), default_order(), "no tiles: the default order"); let views = said(&["project/brand/kiln", "tool/notes", "project/memory/other", "project/procedures/kiln"]); let order = tile_order(&views, "kiln"); assert_eq!(&keys(&order)[..3], &["brand", "notes", "procedures"]); let mut every = keys(&order); let mut expected = keys(&default_order()); every.sort_unstable(); expected.sort_unstable(); assert_eq!(every, expected, "every section once"); let rest: Vec<&str> = keys(&order)[3..].to_vec(); let defaults: Vec<&str> = keys(&default_order()).into_iter().filter(|key| rest.contains(key)).collect(); assert_eq!(rest, defaults, "a section with no tile keeps its default place; another project's tile is not this one's"); } // ── what is drawn ───────────────────────────────────────────────────────── /// RULE: A section with nothing in it appears nowhere — a list holding zero and a single thing that is not there are both left off the page. #[test] fn only_a_section_that_holds_something_is_drawn_in_the_arranged_order() { // Brand's tile at the very top; everything else where it was. let order = tile_order(&said(&["project/brand/kiln"]), "kiln"); let drawn = present_sections(&order, |section| match section.as_str() { "notes" => Holding::Count(12), "todos" => Holding::Count(0), "brand" => Holding::One, "briefing" => Holding::Nothing, "code" => Holding::Count(2), "sessions" => Holding::Count(5), _ => Holding::Nothing, }); assert_eq!( drawn, vec![ PresentSection { section: PageSection::Brand, holding: Holding::One }, PresentSection { section: PageSection::Linked(ProjectSectionKey::Notes), holding: Holding::Count(12) }, PresentSection { section: PageSection::Linked(ProjectSectionKey::Code), holding: Holding::Count(2) }, PresentSection { section: PageSection::Sessions, holding: Holding::Count(5) }, ] ); } #[test] fn a_briefing_holds_something_with_a_summary_or_a_memory() { assert!(!briefing_holds(false, 0)); assert!(briefing_holds(true, 0)); assert!(briefing_holds(false, 1)); } #[test] fn a_section_view_reads_back_as_its_section_and_project() { for section in default_order() { let view = section_view(section, "cotton"); assert_eq!(view_section(&view), Some((section, "cotton")), "{view}"); } assert_eq!(view_section("project/memory/"), None); assert_eq!(view_section("project/unknown/cotton"), None); assert_eq!(view_section("project/memory/a/b"), None); assert_eq!(view_section("tool/notes"), None); }