From 1d12ddbdfcfd235bf6ea136b9720aede53b9a3a2 Mon Sep 17 00:00:00 2001 From: Kenta Iwasaki Date: Sat, 6 Jun 2020 15:14:58 +0900 Subject: [PATCH] layout: add vertical split constraint test on height --- src/layout.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/layout.rs b/src/layout.rs index aa14182b..ffb4edea 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -463,6 +463,31 @@ impl Rect { mod tests { use super::*; + #[test] + fn test_vertical_split_by_height() { + let target = Rect { + x: 2, + y: 2, + width: 10, + height: 10, + }; + + let chunks = Layout::default() + .direction(Direction::Vertical) + .constraints( + [ + Constraint::Percentage(10), + Constraint::Max(5), + Constraint::Min(1), + ] + .as_ref(), + ) + .split(target); + + assert_eq!(target.height, chunks.iter().map(|r| r.height).sum::()); + chunks.windows(2).for_each(|w| assert!(w[0].y <= w[1].y)); + } + #[test] fn test_rect_size_truncation() { for width in 256u16..300u16 {