From 44d3a5b9a2b0ce2bfeccfa0be16196052b6fdd50 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 29 Dec 2023 11:38:01 +0400 Subject: Use saturating_sub in window_height_for_tile_height() --- src/layout/mod.rs | 31 +++++++++++++++++++++++++++++++ src/layout/tile.rs | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 48d7ed9e..0ef10b16 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1752,6 +1752,19 @@ mod tests { } } + #[track_caller] + fn check_ops_with_options(options: Options, ops: &[Op]) { + let mut layout = Layout { + options: Rc::new(options), + ..Default::default() + }; + + for op in ops { + op.apply(&mut layout); + layout.verify_invariants(); + } + } + #[test] fn operations_dont_panic() { let every_op = [ @@ -2081,6 +2094,24 @@ mod tests { check_ops(&ops); } + #[test] + fn large_negative_height_change() { + let ops = [ + Op::AddOutput(1), + Op::AddWindow { + id: 1, + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), + }, + Op::SetWindowHeight(SizeChange::AdjustProportion(-1e129)), + ]; + + let mut options = Options::default(); + options.border.off = false; + options.border.width = 1; + + check_ops_with_options(options, &ops); + } + proptest! { #![proptest_config(ProptestConfig { cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() { diff --git a/src/layout/tile.rs b/src/layout/tile.rs index bd684ea0..4f668c17 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -189,7 +189,7 @@ impl Tile { if self.border.is_off() { size } else { - size - self.border.width() * 2 + size.saturating_sub(self.border.width() * 2) } } -- cgit