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.
This commit is contained in:
1 parent
8223a55cfb
commit
c8ec0866d4
1 file changed
+46
@@ -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<Cell<usize>>,
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user