From a7206db6f9f66ca3ad846e04d24634bd5d2e3a21 Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 19 Jul 2022 18:00:04 +0900 Subject: [PATCH] add tests for `CursorMove::Head` and `CursorMove::End` --- tests/cursor.rs | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/cursor.rs b/tests/cursor.rs index ac92556..89eb98f 100644 --- a/tests/cursor.rs +++ b/tests/cursor.rs @@ -3,7 +3,7 @@ use tui_textarea::{CursorMove, TextArea}; const BOTTOM_RIGHT: CursorMove = CursorMove::Jump(u16::MAX, u16::MAX); #[test] -fn test_empty_textarea() { +fn empty_textarea() { use CursorMove::*; let mut t = TextArea::default(); @@ -29,7 +29,7 @@ fn test_empty_textarea() { } #[test] -fn test_forward() { +fn forward() { let mut t = TextArea::from(["abc", "def"]); for pos in [ @@ -48,7 +48,7 @@ fn test_forward() { } #[test] -fn test_back() { +fn back() { let mut t = TextArea::from(["abc", "def"]); t.move_cursor(BOTTOM_RIGHT); @@ -68,7 +68,7 @@ fn test_back() { } #[test] -fn test_up() { +fn up() { let mut t = TextArea::from(["abc", "def", "ghi"]); for col in 0..=3 { @@ -86,7 +86,7 @@ fn test_up() { } #[test] -fn test_up_trim() { +fn up_trim() { let mut t = TextArea::from(["", "a", "bcd", "efgh"]); t.move_cursor(CursorMove::Jump(3, 3)); @@ -97,7 +97,7 @@ fn test_up_trim() { } #[test] -fn test_down() { +fn down() { let mut t = TextArea::from(["abc", "def", "ghi"]); for col in 0..=3 { @@ -115,7 +115,7 @@ fn test_down() { } #[test] -fn test_down_trim() { +fn down_trim() { let mut t = TextArea::from(["abcd", "efg", "h", ""]); t.move_cursor(CursorMove::Jump(0, 3)); @@ -124,3 +124,29 @@ fn test_down_trim() { assert_eq!(t.cursor(), expected); } } + +#[test] +fn head() { + let mut t = TextArea::from(["efg", "h", ""]); + for row in 0..t.lines().len() { + let len = t.lines()[row].len(); + for col in [0, len / 2, len] { + t.move_cursor(CursorMove::Jump(row as u16, col as u16)); + t.move_cursor(CursorMove::Head); + assert_eq!(t.cursor(), (row, 0)); + } + } +} + +#[test] +fn end() { + let mut t = TextArea::from(["efg", "h", ""]); + for row in 0..t.lines().len() { + let len = t.lines()[row].len(); + for col in [0, len / 2, len] { + t.move_cursor(CursorMove::Jump(row as u16, col as u16)); + t.move_cursor(CursorMove::End); + assert_eq!(t.cursor(), (row, len)); + } + } +}