1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 22:35:50 +03:00

add tests for CursorMove::Top and CursorMove::Bottom

Этот коммит содержится в:
rhysd
2022-07-20 15:47:21 +09:00
родитель 851db5eadb
Коммит 8097183e75
2 изменённых файлов: 67 добавлений и 1 удалений

Просмотреть файл

@@ -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"]

Просмотреть файл

@@ -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());
}
}