use virtual_tty::VirtualTty;
#[test]
fn test_cursor_up_basic() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1\nLine2\nLine3");
tty.stdout_write("\x1b[1A"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
Line2X \n
Line3 \n
\n
\n
");
}
#[test]
fn test_cursor_up_multiple() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1\nLine2\nLine3");
tty.stdout_write("\x1b[2A"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1X \n
Line2 \n
Line3 \n
\n
\n
");
}
#[test]
fn test_cursor_up_no_parameter() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1\nLine2");
tty.stdout_write("\x1b[A"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1X \n
Line2 \n
\n
\n
\n
");
}
#[test]
fn test_cursor_up_bounds_check() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[10A"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HelloX \n
\n
\n
");
}
#[test]
fn test_cursor_down_basic() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1");
tty.stdout_write("\x1b[1B"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
X \n
\n
\n
\n
");
}
#[test]
fn test_cursor_down_multiple() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1");
tty.stdout_write("\x1b[2B"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
\n
X \n
\n
\n
");
}
#[test]
fn test_cursor_down_no_parameter() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Line1");
tty.stdout_write("\x1b[B"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Line1 \n
X \n
\n
\n
\n
");
}
#[test]
fn test_cursor_down_bounds_check() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[10B"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello \n
\n
X \n
");
}
#[test]
fn test_cursor_forward_basic() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[3D"); tty.stdout_write("\x1b[1C"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HelXo \n
\n
\n
");
}
#[test]
fn test_cursor_forward_multiple() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[5D"); tty.stdout_write("\x1b[2C"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HeXlo \n
\n
\n
");
}
#[test]
fn test_cursor_forward_no_parameter() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[3D"); tty.stdout_write("\x1b[C"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HelXo \n
\n
\n
");
}
#[test]
fn test_cursor_forward_bounds_check() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[20C"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello X\n
\n
\n
");
}
#[test]
fn test_cursor_back_basic() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[1D"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HellX \n
\n
\n
");
}
#[test]
fn test_cursor_back_multiple() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[3D"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HeXlo \n
\n
\n
");
}
#[test]
fn test_cursor_back_no_parameter() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[D"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
HellX \n
\n
\n
");
}
#[test]
fn test_cursor_back_bounds_check() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[20D"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Xello \n
\n
\n
");
}
#[test]
fn test_absolute_cursor_positioning() {
let mut tty = VirtualTty::new(10, 3);
tty.stdout_write("Hello");
tty.stdout_write("\x1b[1;1H"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Xello \n
\n
\n
");
}
#[test]
fn test_set_cursor_to_row_col() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Hello\nWorld");
tty.stdout_write("\x1b[2;3H"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello \n
WoXld \n
\n
\n
\n
");
}
#[test]
fn test_set_cursor_to_row_col_alt_syntax() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Hello\nWorld");
tty.stdout_write("\x1b[2;3f"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello \n
WoXld \n
\n
\n
\n
");
}
#[test]
fn test_set_cursor_to_home_position() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Hello\nWorld");
tty.stdout_write("\x1b[H"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Xello \n
World \n
\n
\n
\n
");
}
#[test]
fn test_set_cursor_partial_coordinates() {
let mut tty = VirtualTty::new(10, 5);
tty.stdout_write("Hello\nWorld");
tty.stdout_write("\x1b[2;H"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
Hello \n
Xorld \n
\n
\n
\n
");
}
#[test]
fn test_set_cursor_bounds_clamping() {
let mut tty = VirtualTty::new(15, 10);
tty.stdout_write("Hello\nWorld");
tty.stdout_write("\x1b[20;30H"); tty.stdout_write("X");
let snapshot = tty.get_snapshot();
insta::assert_snapshot!(snapshot, @r"
World \n
\n
\n
\n
\n
\n
\n
\n
X\n
\n
");
}