From 8097183e752957ad369479e060b62467a4f77632 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 20 Jul 2022 15:47:21 +0900 Subject: [PATCH] add tests for `CursorMove::Top` and `CursorMove::Bottom` --- .cargo/config.toml | 2 +- tests/cursor.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 638c996..ff007af 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] -watch-check = ["watch", "-x", "check --examples --all-features --workspace --benches"] +watch-check = ["watch", "-x", "check --examples --all-features --workspace --benches --tests"] watch-test = ["watch", "-x", "test --all-features -- --skip=src/lib.rs", "-w", "src"] diff --git a/tests/cursor.rs b/tests/cursor.rs index 3420b9b..b35ca3c 100644 --- a/tests/cursor.rs +++ b/tests/cursor.rs @@ -213,3 +213,69 @@ fn end() { } } } + +#[test] +fn top() { + for text in [ + ["abc", "def", "ghi"], + ["あいう", "🐢🐱🐰", "πŸ‘ͺπŸ€ŸπŸΏπŸ‘©πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸΎ"], + ] { + let mut t = TextArea::from(text); + for row in 0..=2 { + for col in 0..=3 { + t.move_cursor(CursorMove::Jump(row, col)); + t.move_cursor(CursorMove::Top); + assert_eq!(t.cursor(), (0, col as usize), "{:?}", t.lines()); + } + } + } +} + +#[test] +fn top_trim() { + for lines in [ + &["a", "bc"][..], + &["あ", "🐢🐱"][..], + &["a", "bcd", "ef"][..], + &["", "犬"][..], + ] { + let mut t: TextArea = lines.iter().cloned().collect(); + t.move_cursor(CursorMove::Jump(u16::MAX, u16::MAX)); + t.move_cursor(CursorMove::Top); + let col = t.lines()[0].chars().count(); + assert_eq!(t.cursor(), (0, col), "{:?}", t.lines()); + } +} + +#[test] +fn bottom() { + for text in [ + ["abc", "def", "ghi"], + ["あいう", "🐢🐱🐰", "πŸ‘ͺπŸ€ŸπŸΏπŸ‘©πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸΎ"], + ] { + let mut t = TextArea::from(text); + for row in 0..=2 { + for col in 0..=3 { + t.move_cursor(CursorMove::Jump(row, col)); + t.move_cursor(CursorMove::Bottom); + assert_eq!(t.cursor(), (2, col as usize), "{:?}", t.lines()); + } + } + } +} + +#[test] +fn bottom_trim() { + for lines in [ + &["bc", "a"][..], + &["🐢🐱", "🐰"][..], + &["ef", "bcd", "a"][..], + &["犬", ""][..], + ] { + let mut t: TextArea = lines.iter().cloned().collect(); + t.move_cursor(CursorMove::Jump(0, u16::MAX)); + t.move_cursor(CursorMove::Bottom); + let col = t.lines().last().unwrap().chars().count(); + assert_eq!(t.cursor(), (t.lines().len() - 1, col), "{:?}", t.lines()); + } +}