зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-07 16:05:50 +03:00
add tests for CursorMove::Head and CursorMove::End
Этот коммит содержится в:
@@ -3,7 +3,7 @@ use tui_textarea::{CursorMove, TextArea};
|
|||||||
const BOTTOM_RIGHT: CursorMove = CursorMove::Jump(u16::MAX, u16::MAX);
|
const BOTTOM_RIGHT: CursorMove = CursorMove::Jump(u16::MAX, u16::MAX);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_textarea() {
|
fn empty_textarea() {
|
||||||
use CursorMove::*;
|
use CursorMove::*;
|
||||||
|
|
||||||
let mut t = TextArea::default();
|
let mut t = TextArea::default();
|
||||||
@@ -29,7 +29,7 @@ fn test_empty_textarea() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_forward() {
|
fn forward() {
|
||||||
let mut t = TextArea::from(["abc", "def"]);
|
let mut t = TextArea::from(["abc", "def"]);
|
||||||
|
|
||||||
for pos in [
|
for pos in [
|
||||||
@@ -48,7 +48,7 @@ fn test_forward() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_back() {
|
fn back() {
|
||||||
let mut t = TextArea::from(["abc", "def"]);
|
let mut t = TextArea::from(["abc", "def"]);
|
||||||
t.move_cursor(BOTTOM_RIGHT);
|
t.move_cursor(BOTTOM_RIGHT);
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ fn test_back() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_up() {
|
fn up() {
|
||||||
let mut t = TextArea::from(["abc", "def", "ghi"]);
|
let mut t = TextArea::from(["abc", "def", "ghi"]);
|
||||||
|
|
||||||
for col in 0..=3 {
|
for col in 0..=3 {
|
||||||
@@ -86,7 +86,7 @@ fn test_up() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_up_trim() {
|
fn up_trim() {
|
||||||
let mut t = TextArea::from(["", "a", "bcd", "efgh"]);
|
let mut t = TextArea::from(["", "a", "bcd", "efgh"]);
|
||||||
t.move_cursor(CursorMove::Jump(3, 3));
|
t.move_cursor(CursorMove::Jump(3, 3));
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ fn test_up_trim() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_down() {
|
fn down() {
|
||||||
let mut t = TextArea::from(["abc", "def", "ghi"]);
|
let mut t = TextArea::from(["abc", "def", "ghi"]);
|
||||||
|
|
||||||
for col in 0..=3 {
|
for col in 0..=3 {
|
||||||
@@ -115,7 +115,7 @@ fn test_down() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_down_trim() {
|
fn down_trim() {
|
||||||
let mut t = TextArea::from(["abcd", "efg", "h", ""]);
|
let mut t = TextArea::from(["abcd", "efg", "h", ""]);
|
||||||
t.move_cursor(CursorMove::Jump(0, 3));
|
t.move_cursor(CursorMove::Jump(0, 3));
|
||||||
|
|
||||||
@@ -124,3 +124,29 @@ fn test_down_trim() {
|
|||||||
assert_eq!(t.cursor(), expected);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user