Files
2026-10-14 15:28:51 -03:00

143 lines
5.1 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Editing, count, insertion, history and repeat contracts.
mod support;
use notescraft_vim::Mode;
#[test]
fn delete_and_change_commands() {
support::check(
&[
("|abc", "x", "|bc"),
("a|bc", "x", "a|c"),
("ab|c", "x", "a|b"),
("|abc", "2x", "|c"),
("|abc", "9x", "|"),
("|é猫🙂", "x", "|猫🙂"),
("é|猫🙂", "2x", "|é"),
("|abc", "X", "|abc"),
("a|bc", "X", "|bc"),
("ab|c", "2X", "|c"),
("é猫|🙂", "X", "é|🙂"),
("|", "xX", "|"),
("|one two", "dw", "|two"),
("|one two three", "2dw", "|three"),
("|one two three", "d2w", "|three"),
("|one two three four five", "2d2w", "|five"),
("|one two", "de", "| two"),
("one |two", "db", "|two"),
("a|bc", "dl", "a|c"),
("ab|c", "dh", "a|c"),
("a|bc", "d$", "|a"),
("ab|c", "d0", "|c"),
("|abc\ndef", "dd", "|def"),
("abc\n|def", "dd", "|abc"),
("|a\nb\nc", "2dd", "|c"),
("|é\n猫\n🙂", "d2d", "|🙂"),
("|abc", "dd", "|"),
("|abc", "D", "|"),
("a|bc", "D", "|a"),
("a|bc\ndef", "D", "|a\ndef"),
("|one two", "cwX<Esc>", "|X two"),
("|one two", "ceX<Esc>", "|X two"),
("a|bc", "clX<Esc>", "a|Xc"),
("|abc\ndef", "ccX<Esc>", "|X\ndef"),
("abc\n|def", "ccX<Esc>", "abc\n|X"),
("|a\nb\nc", "2ccX<Esc>", "|X\nc"),
("|abc", "sX<Esc>", "|Xbc"),
("|abc", "2sX<Esc>", "|Xc"),
("|abc\ndef", "SX<Esc>", "|X\ndef"),
("a|bc", "CX<Esc>", "a|X"),
("|é猫🙂", "c2lα<Esc>", "|α🙂"),
("|abc", "d<Esc>x", "|bc"),
("|abc", "100000x", "|"),
],
Mode::Normal,
);
}
#[test]
fn insertion_replace_join_and_case_commands() {
support::check(
&[
("|abc", "iX<Esc>", "|Xabc"),
("a|bc", "iXY<Esc>", "aX|Ybc"),
("|", "iabc<Esc>", "ab|c"),
("|猫", "ié🙂<Esc>", "é|🙂猫"),
("|abc", "aX<Esc>", "a|Xbc"),
("ab|c", "aX<Esc>", "abc|X"),
("|", "aX<Esc>", "|X"),
("|abc", "AX<Esc>", "abc|X"),
("a|bc\ndef", "AX<Esc>", "abc|X\ndef"),
(" ab|c", "IX<Esc>", " |Xabc"),
("|abc", "oX<Esc>", "abc\n|X"),
("|abc\ndef", "oX<Esc>", "abc\n|X\ndef"),
("|abc", "OX<Esc>", "|X\nabc"),
("abc\n|def", "OX<Esc>", "abc\n|X\ndef"),
("|abc", "rX", "|Xbc"),
("a|bc", "r猫", "a|猫c"),
("|abc", "2rX", "X|Xc"),
("|abc", "9rX", "|abc"),
("|é猫🙂", "rα", "|α猫🙂"),
("|abc", "RXY<Esc>", "X|Yc"),
("ab|c", "RXY<Esc>", "abX|Y"),
("|abc", "RX<BS><Esc>", "|abc"),
("|abc\ndef", "J", "abc| def"),
("|a\nb\nc", "3J", "a b| c"),
("|é\n猫", "J", "é| 猫"),
("|abc", "J", "|abc"),
("|abc", "~", "A|bc"),
("|aB猫", "2~", "Ab|猫"),
("|éα", "~", "É|α"),
("|one TWO", "gUw", "|ONE TWO"),
("|ONE two", "guw", "|one two"),
("|oNe two", "g~w", "|OnE two"),
("|aBc\ndef", "gUU", "|ABC\ndef"),
("|ABC\ndef", "guu", "|abc\ndef"),
("|aBc\ndef", "g~~", "|AbC\ndef"),
("|abc", "iX<BS><Esc>", "|abc"),
("|abc", "iX<CR>Y<Esc>", "X\n|Yabc"),
("|abc", "i<Tab><Esc>", "|\tabc"),
],
Mode::Normal,
);
}
#[test]
fn undo_redo_and_dot_group_changes() {
support::check(
&[
("|abc", "xu", "|abc"),
("|abc", "xu<C-r>", "|bc"),
("|abc", "xxu", "|bc"),
("|abc", "xx2u", "|abc"),
("|abc", "iXYZ<Esc>u", "|abc"),
("|abc", "iXYZ<Esc>u<C-r>", "XY|Zabc"),
("|one two", "cwXYZ<Esc>u", "|one two"),
("|abc", "RuV<Esc>u", "|abc"),
("|abc", "u<C-r>", "|abc"),
("|abc", "x.", "|c"),
("|abcdef", "2x.", "|ef"),
("|one two three", "dw.", "|three"),
("|abc", "rXl.", "X|Xc"),
("|abc", "iX<Esc>l.", "X|Xabc"),
("|abc", "~.", "AB|c"),
("|abc", "xulx<C-r>", "a|c"),
("|é猫🙂", "xu<C-r>", "|猫🙂"),
("|one two three", "cwX<Esc>w.", "X |X three"),
("|abc", ".", "|abc"),
("|abc", "x2.", "|"),
("|abcd", "x..", "|d"),
],
Mode::Normal,
);
}
#[test]
fn unfinished_commands_expose_modes() {
support::check(&[("|abc", "i", "|abc"), ("|", "i猫", "猫|")], Mode::Insert);
support::check(&[("|abc", "R", "|abc"), ("|abc", "R猫", "猫|bc")], Mode::Replace);
support::check(&[("|abc", "v", "|abc"), ("|abc", "vl", "a|bc")], Mode::Visual);
support::check(&[("|abc", "V", "|abc"), ("|abc", "V<Esc>V", "|abc")], Mode::VisualLine);
support::check(&[("|abc", ":", "|abc"), ("|abc", "/abc", "|abc")], Mode::CommandLine);
}