use virtual_tty::VirtualTty;
#[test]
fn test_clear_line_from_cursor() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[3D"); tty.stdout_write("123");
tty.stdout_write("\x1b[K"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
He123 \n
\n
\n
");
}
#[test]
fn test_clear_entire_line() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello\nWorld\nTest");
tty.stdout_write("\x1b[2A"); tty.stdout_write("\x1b[2K"); tty.stdout_write("New");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
New \n
World \n
Test \n
");
}
#[test]
fn test_clear_from_cursor_to_end_of_screen() {
let mut tty = VirtualTty::new(10, 4);
tty.stdout_write("Line1\nLine2\nLine3\nLine4");
tty.stdout_write("\x1b[2;3H"); tty.stdout_write("\x1b[0J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
Li \n
\n
\n
");
}
#[test]
fn test_clear_from_cursor_to_end_of_screen_default() {
let mut tty = VirtualTty::new(10, 4);
tty.stdout_write("Line1\nLine2\nLine3\nLine4");
tty.stdout_write("\x1b[2;3H"); tty.stdout_write("\x1b[J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
Li \n
\n
\n
");
}
#[test]
fn test_clear_from_cursor_at_start_of_line() {
let mut tty = VirtualTty::new(8, 3);
tty.stdout_write("ABCD\nEFGH\nIJKL");
tty.stdout_write("\x1b[2;1H"); tty.stdout_write("\x1b[0J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
ABCD \n
\n
\n
");
}
#[test]
fn test_clear_from_cursor_at_end_of_line() {
let mut tty = VirtualTty::new(8, 3);
tty.stdout_write("ABCD\nEFGH\nIJKL");
tty.stdout_write("\x1b[1;4H"); tty.stdout_write("\x1b[0J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
ABC \n
\n
\n
");
}
#[test]
fn test_clear_from_cursor_preserves_position() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello\nWorld\nTest");
tty.stdout_write("\x1b[2;2H"); tty.stdout_write("\x1b[0J"); tty.stdout_write("X"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello \n
WX \n
\n
");
}
#[test]
fn test_clear_from_cursor_on_last_line() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Line1\nLine2\nLine3");
tty.stdout_write("\x1b[3D"); tty.stdout_write("\x1b[0J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
Line2 \n
Li \n
");
}
#[test]
fn test_clear_from_beginning_to_cursor_basic() {
let mut tty = VirtualTty::new(10, 4);
tty.stdout_write("Line1\nLine2\nLine3\nLine4");
tty.stdout_write("\x1b[2;3H"); tty.stdout_write("\x1b[1J"); let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
\n
ne2 \n
Line3 \n
Line4 \n
");
}