forge
Explore
Log in

Don't you dare go Hollow

Use saturating_sub in window_height_for_tile_height()

Browse files at this commit

44d3a5b9a2b0ce2bfeccfa0be16196052b6fdd50Ivan MolodetskikhParent: 5d95de9
src/layout/mod.rsmodified+31 -0
@@ -1752,6 +1752,19 @@ mod tests {
1752 }1752 }
1753 }1753 }
1754 1754
1755+ #[track_caller]
1756+ fn check_ops_with_options(options: Options, ops: &[Op]) {
1757+ let mut layout = Layout {
1758+ options: Rc::new(options),
1759+ ..Default::default()
1760+ };
1761+
1762+ for op in ops {
1763+ op.apply(&mut layout);
1764+ layout.verify_invariants();
1765+ }
1766+ }
1767+
1755 #[test]1768 #[test]
1756 fn operations_dont_panic() {1769 fn operations_dont_panic() {
1757 let every_op = [1770 let every_op = [
@@ -2081,6 +2094,24 @@ mod tests {
2081 check_ops(&ops);2094 check_ops(&ops);
2082 }2095 }
2083 2096
2097+ #[test]
2098+ fn large_negative_height_change() {
2099+ let ops = [
2100+ Op::AddOutput(1),
2101+ Op::AddWindow {
2102+ id: 1,
2103+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
2104+ },
2105+ Op::SetWindowHeight(SizeChange::AdjustProportion(-1e129)),
2106+ ];
2107+
2108+ let mut options = Options::default();
2109+ options.border.off = false;
2110+ options.border.width = 1;
2111+
2112+ check_ops_with_options(options, &ops);
2113+ }
2114+
2084 proptest! {2115 proptest! {
2085 #![proptest_config(ProptestConfig {2116 #![proptest_config(ProptestConfig {
2086 cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() {2117 cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() {
src/layout/tile.rsmodified+1 -1
@@ -189,7 +189,7 @@ impl<W: LayoutElement> Tile<W> {
189 if self.border.is_off() {189 if self.border.is_off() {
190 size190 size
191 } else {191 } else {
192- size - self.border.width() * 2192+ size.saturating_sub(self.border.width() * 2)
193 }193 }
194 }194 }
195 195