diff --git a/tests/cursor.rs b/tests/cursor.rs index dc3f3ef..ac92556 100644 --- a/tests/cursor.rs +++ b/tests/cursor.rs @@ -66,3 +66,61 @@ fn test_back() { assert_eq!(t.cursor(), pos); } } + +#[test] +fn test_up() { + let mut t = TextArea::from(["abc", "def", "ghi"]); + + for col in 0..=3 { + let mut row = 2; + + t.move_cursor(CursorMove::Jump(2 as u16, col as u16)); + assert_eq!(t.cursor(), (row, col)); + + while row > 0 { + t.move_cursor(CursorMove::Up); + row -= 1; + assert_eq!(t.cursor(), (row, col)); + } + } +} + +#[test] +fn test_up_trim() { + let mut t = TextArea::from(["", "a", "bcd", "efgh"]); + t.move_cursor(CursorMove::Jump(3, 3)); + + for expected in [(2, 3), (1, 1), (0, 0)] { + t.move_cursor(CursorMove::Up); + assert_eq!(t.cursor(), expected); + } +} + +#[test] +fn test_down() { + let mut t = TextArea::from(["abc", "def", "ghi"]); + + for col in 0..=3 { + let mut row = 0; + + t.move_cursor(CursorMove::Jump(0, col as u16)); + assert_eq!(t.cursor(), (row, col)); + + while row < 2 { + t.move_cursor(CursorMove::Down); + row += 1; + assert_eq!(t.cursor(), (row, col)); + } + } +} + +#[test] +fn test_down_trim() { + let mut t = TextArea::from(["abcd", "efg", "h", ""]); + t.move_cursor(CursorMove::Jump(0, 3)); + + for expected in [(1, 3), (2, 1), (3, 0)] { + t.move_cursor(CursorMove::Down); + assert_eq!(t.cursor(), expected); + } +} diff --git a/tests/mod.rs b/tests/mod.rs new file mode 100644 index 0000000..0e02b79 --- /dev/null +++ b/tests/mod.rs @@ -0,0 +1 @@ +mod cursor;