From f7fa9c73ce6fbf46ad5233024323e857ce173cd7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 15:51:10 +0100 Subject: [PATCH] thing tests: f11's Cells nest is a layout assertion; its blank screen golden is dropped Finding f11-screen-golden-vacuous. f11 is a chain of paintless Boxes, so its Cells screen golden was whitespace and would have stayed whitespace if layout broke. The nest is asserted where it is a fact: in Cells every level is the only child of the last, inside it, and within a cell of its Pixels rect at the metric (the 2 px padding per side compounds over 84 levels). f11 leaves the screen set with the reason in a comment. Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/tests/layout.rs | 29 +++++++ crates/thing-tui/tests/goldens/README.md | 2 +- .../tests/goldens/screen-f11-deep-cells.txt | 75 ------------------- crates/thing-tui/tests/screen.rs | 7 +- 4 files changed, 34 insertions(+), 79 deletions(-) delete mode 100644 crates/thing-tui/tests/goldens/screen-f11-deep-cells.txt diff --git a/crates/thing-core/tests/layout.rs b/crates/thing-core/tests/layout.rs index 74a4045..9afb8b3 100644 --- a/crates/thing-core/tests/layout.rs +++ b/crates/thing-core/tests/layout.rs @@ -1461,3 +1461,32 @@ fn a_margin_and_a_min_size_convert_each_side_at_its_own_axis_in_cells() { fn a_style_with_margin_right() -> BoxStyle { BoxStyle { size: size2(px(8.0), px(16.0)), margin: Edges { top: px(0.0), right: px(24.0), bottom: px(0.0), left: px(8.0) }, ..plain() } } + +#[test] +fn f11_lays_out_its_whole_nest_in_cells_at_the_cell_metric_of_its_pixels_layout() { + // f11 paints nothing in any mode, so its nesting is a layout fact. In Cells the chain is the + // same nest at the metric: each level inside the last, every rect within a cell of the Pixels + // rect divided by 8 across and 16 down (its 2 px padding per side compounds over the levels). + let document = Fixture::F11Deep.load().surfaces.remove(0); + let tree = bind(&mut MemState::from_fixture(Fixture::F11Deep), &document).unwrap(); + let device = layout(&tree, &pixels(800.0, 600.0, 1.0), &mut FixedMeasure::pixels()).unwrap(); + let laid = layout(&tree, &cells(100.0, 37.0), &mut FixedMeasure::cells()).unwrap(); + assert_eq!(laid.nodes.len(), device.nodes.len()); + assert!(laid.nodes.len() > 20); + for (i, (cell, px)) in laid.nodes.iter().zip(&device.nodes).enumerate() { + assert_eq!((&cell.id, cell.parent), (&px.id, px.parent), "level {i}"); + assert_eq!(cell.parent, i.checked_sub(1).map(|p| p as u32), "level {i} is the only child of the last"); + for (cells, device, per) in [(cell.rect.x, px.rect.x, 8.0), (cell.rect.y, px.rect.y, 16.0), (cell.rect.w, px.rect.w, 8.0), (cell.rect.h, px.rect.h, 16.0)] { + assert!((cells - device / per).abs() <= 1.0, "level {i}: {cells} cells vs {device} px / {per}"); + } + if let Some(parent) = cell.parent { + let outer = laid.nodes[parent as usize].rect; + let inner = cell.rect; + assert!(inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.w <= outer.x + outer.w && inner.y + inner.h <= outer.y + outer.h, "level {i} lies inside level {}", i - 1); + } + } + let root = laid.nodes[0].rect; + let innermost = laid.nodes.last().expect("a nest").rect; + assert_eq!((root.x, root.y, root.w), (0.0, 0.0, 100.0), "the root fills the viewport across"); + assert!(innermost.w > 0.0 && innermost.x > root.x, "the padding of every level narrows the nest to the innermost"); +} diff --git a/crates/thing-tui/tests/goldens/README.md b/crates/thing-tui/tests/goldens/README.md index 8cdc989..0fb26aa 100644 --- a/crates/thing-tui/tests/goldens/README.md +++ b/crates/thing-tui/tests/goldens/README.md @@ -1,5 +1,5 @@ # thing-tui goldens -`screen--cells.txt` is `Screen::dump` of each fixture surface painted from its Cells render at +`screen--cells.txt` is `Screen::dump` of each fixture surface (f11, which paints nothing, is a layout fact and has none) painted from its Cells render at 100x37 (CellMeasure, the standard theme). `THING_BLESS=1` through `thing_testkit::golden::check` is the only way one changes. diff --git a/crates/thing-tui/tests/goldens/screen-f11-deep-cells.txt b/crates/thing-tui/tests/goldens/screen-f11-deep-cells.txt deleted file mode 100644 index 5e4762c..0000000 --- a/crates/thing-tui/tests/goldens/screen-f11-deep-cells.txt +++ /dev/null @@ -1,75 +0,0 @@ -surface thing:surface:provider.deep.deep 100x37 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -style 0 0 100 - - - -style 1 0 100 - - - -style 2 0 100 - - - -style 3 0 100 - - - -style 4 0 100 - - - -style 5 0 100 - - - -style 6 0 100 - - - -style 7 0 100 - - - -style 8 0 100 - - - -style 9 0 100 - - - -style 10 0 100 - - - -style 11 0 100 - - - -style 12 0 100 - - - -style 13 0 100 - - - -style 14 0 100 - - - -style 15 0 100 - - - -style 16 0 100 - - - -style 17 0 100 - - - -style 18 0 100 - - - -style 19 0 100 - - - -style 20 0 100 - - - -style 21 0 100 - - - -style 22 0 100 - - - -style 23 0 100 - - - -style 24 0 100 - - - -style 25 0 100 - - - -style 26 0 100 - - - -style 27 0 100 - - - -style 28 0 100 - - - -style 29 0 100 - - - -style 30 0 100 - - - -style 31 0 100 - - - -style 32 0 100 - - - -style 33 0 100 - - - -style 34 0 100 - - - -style 35 0 100 - - - -style 36 0 100 - - - diff --git a/crates/thing-tui/tests/screen.rs b/crates/thing-tui/tests/screen.rs index 056e004..b5f685f 100644 --- a/crates/thing-tui/tests/screen.rs +++ b/crates/thing-tui/tests/screen.rs @@ -77,13 +77,14 @@ fn golden_text(fixture: Fixture) -> String { #[test] fn goldens() { - for fixture in Fixture::ALL { + // f11 is a chain of Boxes with no paint: its screen is blank in every mode, so a golden of it pins + // nothing. Its nesting in Cells is a layout fact, asserted in thing-core tests/layout.rs. + for fixture in Fixture::ALL.into_iter().filter(|fixture| !matches!(fixture, Fixture::F11Deep)) { golden::check(&golden_dir(), &format!("screen-{}-cells.txt", stem(fixture)), golden_text(fixture).as_bytes()); } } -/// The substitutes the table promises show up on the screens that carry them. f11 is a chain of -/// Boxes with no paint, so it draws nothing in any mode: its nesting is a layout fact, not a screen one. +/// The substitutes the table promises show up on the screens that carry them. #[test] fn image_and_embed_are_on_screen() { let glyphs = |fixture| golden_text(fixture).lines().take(ROWS + 1).collect::();