aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-03 14:48:09 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-03 15:50:45 -0500
commitb7ab7295dcb5e4252acc25aee7d4261ac9cbd60f (patch)
treeeedd82f7df37ad41617e4d4bf565073536d0b41c
parentd79e96ca09562b07d40fc39d14938967ab908a64 (diff)
downloadvt100-rust-b7ab7295dcb5e4252acc25aee7d4261ac9cbd60f.tar.gz
vt100-rust-b7ab7295dcb5e4252acc25aee7d4261ac9cbd60f.zip
more tests
-rw-r--r--tests/escape.rs25
-rw-r--r--tests/scroll.rs9
-rw-r--r--tests/window_contents.rs59
3 files changed, 90 insertions, 3 deletions
diff --git a/tests/escape.rs b/tests/escape.rs
index d3eda71..6793b5c 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -99,7 +99,7 @@ fn ris() {
vt100::MouseProtocolEncoding::Sgr
);
- screen.process(b"\x1bc");
+ screen.process(b"\x07\x1bg\x1bc");
assert_eq!(screen.cursor_position(), (0, 0));
let cell = screen.cell(0, 0).unwrap();
@@ -126,8 +126,10 @@ fn ris() {
assert!(!screen.underline());
assert!(!screen.inverse());
- assert!(!screen.check_visual_bell());
- assert!(!screen.check_audible_bell());
+ // bell states don't change with reset
+ assert!(screen.check_visual_bell());
+ assert!(screen.check_audible_bell());
+
assert!(!screen.application_keypad());
assert!(!screen.application_cursor());
assert!(!screen.hide_cursor());
@@ -156,4 +158,21 @@ fn decsc() {
screen.contents(0, 0, 23, 79),
"foobaz\n\n\n bar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
);
+ assert_eq!(screen.cursor_position(), (0, 6));
+
+ screen.process(b"\x1b[?47h\x1b[20;20H");
+ assert_eq!(
+ screen.contents(0, 0, 23, 79),
+ "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
+ );
+ assert_eq!(screen.cursor_position(), (19, 19));
+
+ screen.process(b"\x1b8");
+ assert_eq!(screen.cursor_position(), (0, 0));
+
+ screen.process(b"\x1b[?47l\x1b[20;20H");
+ assert_eq!(screen.cursor_position(), (19, 19));
+
+ screen.process(b"\x1b8");
+ assert_eq!(screen.cursor_position(), (0, 3));
}
diff --git a/tests/scroll.rs b/tests/scroll.rs
index 6a4bd83..e7f0e7f 100644
--- a/tests/scroll.rs
+++ b/tests/scroll.rs
@@ -52,4 +52,13 @@ fn origin_mode() {
screen.process(b"\x1b[10;50H");
assert_eq!(screen.cursor_position(), (9, 49));
+
+ screen.process(b"\x1b[?6h\x1b[?47h\x1b[6;16r\x1b[H");
+ assert_eq!(screen.cursor_position(), (0, 0));
+
+ screen.process(b"\x1b[?6h");
+ assert_eq!(screen.cursor_position(), (5, 0));
+
+ screen.process(b"\x1b[?47l\x1b[H");
+ assert_eq!(screen.cursor_position(), (4, 0));
}
diff --git a/tests/window_contents.rs b/tests/window_contents.rs
index ac2e2e8..6391763 100644
--- a/tests/window_contents.rs
+++ b/tests/window_contents.rs
@@ -1,12 +1,14 @@
#[test]
fn formatted() {
let mut screen = vt100::Screen::new(24, 80);
+ compare_formatted(&screen);
assert_eq!(
screen.contents_formatted(0, 0, 23, 79),
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
);
screen.process(b"foobar");
+ compare_formatted(&screen);
assert!(!screen.cell(0, 2).unwrap().bold());
assert!(!screen.cell(0, 3).unwrap().bold());
assert!(!screen.cell(0, 4).unwrap().bold());
@@ -17,6 +19,7 @@ fn formatted() {
);
screen.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb");
+ compare_formatted(&screen);
assert!(!screen.cell(0, 2).unwrap().bold());
assert!(screen.cell(0, 3).unwrap().bold());
assert!(!screen.cell(0, 4).unwrap().bold());
@@ -24,9 +27,65 @@ fn formatted() {
assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[mar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
screen.process(b"\x1b[1;5H\x1b[22;42ma");
+ compare_formatted(&screen);
assert!(!screen.cell(0, 2).unwrap().bold());
assert!(screen.cell(0, 3).unwrap().bold());
assert!(!screen.cell(0, 4).unwrap().bold());
assert!(!screen.cell(0, 5).unwrap().bold());
assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+
+ screen.process(b"\x1b[1;6H\x1b[35mr\r\nquux");
+ compare_formatted(&screen);
+ assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\nquux\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+
+ screen.process(b"\x1b[2;1H\x1b[45mquux");
+ compare_formatted(&screen);
+ assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\n\x1b[45mquux\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+
+ screen
+ .process(b"\x1b[2;2H\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx");
+ compare_formatted(&screen);
+ assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\n\x1b[45mq\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
+}
+
+fn compare_formatted(screen: &vt100::Screen) {
+ let (rows, cols) = screen.size();
+ let contents = screen.contents_formatted(0, 0, rows - 1, cols - 1);
+ let mut screen2 = vt100::Screen::new(rows, cols);
+ let input =
+ contents
+ .trim_end()
+ .as_bytes()
+ .iter()
+ .fold(vec![], |mut acc, &c| {
+ if c == b'\n' {
+ acc.push(b'\r');
+ acc.push(b'\n');
+ } else {
+ acc.push(c);
+ }
+ acc
+ });
+ screen2.process(&input);
+ compare_cells(screen, &screen2);
+}
+
+fn compare_cells(screen1: &vt100::Screen, screen2: &vt100::Screen) {
+ assert_eq!(screen1.size(), screen2.size());
+ let (rows, cols) = screen1.size();
+
+ for row in 0..rows {
+ for col in 0..cols {
+ let cell1 = screen1.cell(row, col).unwrap();
+ let cell2 = screen2.cell(row, col).unwrap();
+
+ assert_eq!(cell1.contents(), cell2.contents());
+ assert_eq!(cell1.fgcolor(), cell2.fgcolor());
+ assert_eq!(cell1.bgcolor(), cell2.bgcolor());
+ assert_eq!(cell1.bold(), cell2.bold());
+ assert_eq!(cell1.italic(), cell2.italic());
+ assert_eq!(cell1.underline(), cell2.underline());
+ assert_eq!(cell1.inverse(), cell2.inverse());
+ }
+ }
}