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

fix inser_str doesn't handle \r\n and ignores newline at end of input

Этот коммит содержится в:
rhysd
2023-11-19 22:08:25 +09:00
родитель 1194331a02
Коммит 9e3df38b54
2 изменённых файлов: 70 добавлений и 7 удалений

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

@@ -301,6 +301,24 @@ fn test_insert_str_multiple_lines() {
"ef",
][..],
),
// Newline at end of line
(
&[
"ab",
"cd",
"ef",
][..],
(1, 1),
"x\ny\n",
(3, 0),
&[
"ab",
"cx",
"y",
"d",
"ef",
][..],
),
// Empty lines
(
&[
@@ -376,8 +394,9 @@ fn test_insert_str_multiple_lines() {
][..],
(0, 0),
"\n\n\n",
(2, 0),
(3, 0),
&[
"",
"",
"",
"ab",
@@ -393,11 +412,12 @@ fn test_insert_str_multiple_lines() {
][..],
(1, 0),
"\n\n\n",
(3, 0),
(4, 0),
&[
"ab",
"",
"",
"",
"cd",
"ef",
][..],
@@ -410,11 +430,12 @@ fn test_insert_str_multiple_lines() {
][..],
(1, 1),
"\n\n\n",
(3, 0),
(4, 0),
&[
"ab",
"c",
"",
"",
"d",
"ef",
][..],
@@ -427,12 +448,13 @@ fn test_insert_str_multiple_lines() {
][..],
(1, 2),
"\n\n\n",
(3, 0),
(4, 0),
&[
"ab",
"cd",
"",
"",
"",
"ef",
][..],
),
@@ -444,13 +466,14 @@ fn test_insert_str_multiple_lines() {
][..],
(2, 2),
"\n\n\n",
(4, 0),
(5, 0),
&[
"ab",
"cd",
"ef",
"",
"",
"",
][..],
),
// Multi-byte characters
@@ -539,6 +562,41 @@ fn test_insert_str_multiple_lines() {
"🐴",
][..],
),
// Handle \r\n as newlines
(
&[
"ab",
"cd",
"ef",
][..],
(1, 1),
"x\r\ny\r\nz",
(3, 1),
&[
"ab",
"cx",
"y",
"zd",
"ef",
][..],
),
(
&[
"ab",
"cd",
"ef",
][..],
(1, 1),
"x\ny\r\nz",
(3, 1),
&[
"ab",
"cx",
"y",
"zd",
"ef",
][..],
),
];
for test in tests {
@@ -549,8 +607,8 @@ fn test_insert_str_multiple_lines() {
t.move_cursor(CursorMove::Jump(row as _, col as _));
assert!(t.insert_str(input), "{test:?}");
assert_eq!(t.cursor(), after_pos, "{test:?}");
assert_eq!(t.lines(), expected, "{test:?}");
assert_eq!(t.cursor(), after_pos, "{test:?}");
assert_undo_redo(before_pos, before, expected, &mut t, test);
}