From c8ec0866d4cabfacc51860c3c7eee1ce316b7cd0 Mon Sep 17 00:00:00 2001 From: iris-ai <4+iris-ai@noreply.localhost> Date: Mon, 14 Sep 2026 03:25:35 -0400 Subject: [PATCH] Exercise the subtree remap, which no test reached `mov` ran ten times across the suite and never once recursed: `Rect`, `Image` and `()` are the only widgets claiming `OnResize::Scale` and all three are childless, so the walk that remaps a subtree's children -- the thing `Remap` exists for -- had no coverage at all. `Stretchy` is a test widget that claims `Scale` and holds a child, which is the shape no shipped container has. Removing the recursion leaves its child behind at the old box and the test says so. --- tests/retained.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/retained.rs b/tests/retained.rs index 6941a48..7cedb57 100644 --- a/tests/retained.rs +++ b/tests/retained.rs @@ -250,3 +250,49 @@ fn a_change_two_levels_under_its_reader_still_reaches_it() { assert_corners!(h, below, (12, 232), (388, 388)); } + +/// Claims its drawing may be stretched, and has a child so that the stretch +/// has to reach one. No shipped container claims `Scale` -- `Rect`, `Image` +/// and `()` are all childless -- so nothing else walks a subtree to remap it. +struct Stretchy { + inner: StrongWidget, + draws: Rc>, +} + +impl Widget for Stretchy { + fn draw(&mut self, painter: &mut Painter) -> Size { + self.draws.set(self.draws.get() + 1); + painter.widget(&self.inner).size() + } + + fn on_resize(&self, _: Axis) -> OnResize { + OnResize::Scale + } +} + +#[test] +fn stretching_a_subtree_remaps_the_children_in_it() { + let mut h = Harness::new((400, 400)); + let first = rect(Color::RED).height(40).add(&mut h.rsc); + let inner = rect(Color::BLUE).add(&mut h.rsc); + let draws = Rc::new(Cell::new(0)); + let outer = Stretchy { + inner: inner.add_strong(&mut h.rsc), + draws: draws.clone(), + } + .add(&mut h.rsc); + h.set_root((first, outer).span(Dir::DOWN)); + let settled = draws.get(); + assert_corners!(h, inner, (0, 40), (400, 400)); + + h.rsc[first].y = Some(Len::abs(80)); + h.frame(); + + assert_eq!( + draws.get(), + settled, + "its drawing is stretched, not redrawn" + ); + assert_corners!(h, outer, (0, 80), (400, 400)); + assert_corners!(h, inner, (0, 80), (400, 400)); +}