diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-28 14:57:07 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-12-05 12:54:34 -0500 |
commit | 971b744c9c7c2c3dc9f055f69c5630ca11f0a09e (patch) | |
tree | 8b8c8e88d6dbd809cc6bcd5a82ef512c6e3d9f65 /tests | |
parent | 42b25717605bcb8206f71722f09d02ef4b4275f2 (diff) | |
download | vt100-rust-971b744c9c7c2c3dc9f055f69c5630ca11f0a09e.tar.gz vt100-rust-971b744c9c7c2c3dc9f055f69c5630ca11f0a09e.zip |
fix a couple more issues with end of line behavior
Diffstat (limited to 'tests')
-rw-r--r-- | tests/control.rs | 15 | ||||
-rw-r--r-- | tests/text.rs | 11 | ||||
-rw-r--r-- | tests/window_contents.rs | 51 |
3 files changed, 71 insertions, 6 deletions
diff --git a/tests/control.rs b/tests/control.rs index e0dc276..74e8d9c 100644 --- a/tests/control.rs +++ b/tests/control.rs @@ -97,6 +97,21 @@ fn lf_with(b: u8) { assert_eq!(parser.screen().cell(1, 5).unwrap().contents(), "r"); assert_eq!(parser.screen().cell(1, 6).unwrap().contents(), ""); assert_eq!(parser.screen().contents(), "foo\n bar"); + + parser.process(b"\x1b[H\x1b[J\x1b[4;80H"); + assert_eq!(parser.screen().cursor_position(), (3, 79)); + parser.process(b"a"); + assert_eq!(parser.screen().cursor_position(), (3, 80)); + + // note: this is a behavior that terminals disagree on - xterm and urxvt + // would leave the cursor at (4, 79) here, but alacritty, tmux, and screen + // put it at (4, 80). in general, i'm aiming for roughly tmux/screen + // compat where possible, so that's what i'm going with here. + parser.process(&[b]); + assert_eq!(parser.screen().cursor_position(), (4, 80)); + + parser.process(b"b"); + assert_eq!(parser.screen().cursor_position(), (5, 1)); } #[test] diff --git a/tests/text.rs b/tests/text.rs index 1ad16ae..4206925 100644 --- a/tests/text.rs +++ b/tests/text.rs @@ -221,6 +221,17 @@ fn wrap() { assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), ""); assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "a"); assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), ""); + + parser.process(b"\x1b[H\x1b[J"); + assert_eq!(parser.screen().contents(), ""); + parser.process(b" "); + assert_eq!(parser.screen().contents(), " "); + parser.process(b"\n"); + assert_eq!(parser.screen().contents(), " "); + parser.process(b"\n"); + assert_eq!(parser.screen().contents(), " "); + parser.process(b" "); + assert_eq!(parser.screen().contents(), " \n\n\n "); } #[test] diff --git a/tests/window_contents.rs b/tests/window_contents.rs index 34f5a66..352ffd5 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -80,33 +80,72 @@ fn empty_cells() { #[test] fn cursor_positioning() { let mut parser = vt100::Parser::default(); - let screen1 = parser.screen().clone(); + let screen = parser.screen().clone(); parser.process(b":\x1b[K"); - let screen2 = parser.screen().clone(); assert_eq!(parser.screen().cursor_position(), (0, 1)); assert_eq!( parser.screen().contents_formatted(), b"\x1b[?25h\x1b[m\x1b[H\x1b[J:" ); - assert_eq!(parser.screen().contents_diff(&screen1), b":"); + assert_eq!(parser.screen().contents_diff(&screen), b":"); + let screen = parser.screen().clone(); parser.process(b"a"); - let screen3 = parser.screen().clone(); assert_eq!(parser.screen().cursor_position(), (0, 2)); assert_eq!( parser.screen().contents_formatted(), b"\x1b[?25h\x1b[m\x1b[H\x1b[J:a" ); - assert_eq!(parser.screen().contents_diff(&screen2), b"a"); + assert_eq!(parser.screen().contents_diff(&screen), b"a"); + let screen = parser.screen().clone(); parser.process(b"\x1b[1;2H\x1b[K"); assert_eq!(parser.screen().cursor_position(), (0, 1)); assert_eq!( parser.screen().contents_formatted(), b"\x1b[?25h\x1b[m\x1b[H\x1b[J:" ); - assert_eq!(parser.screen().contents_diff(&screen3), b"\x1b[1;2H\x1b[K"); + assert_eq!(parser.screen().contents_diff(&screen), b"\x1b[1;2H\x1b[K"); + + let screen = parser.screen().clone(); + parser.process(b"\x1b[H\x1b[J\x1b[4;80H"); + assert_eq!(parser.screen().cursor_position(), (3, 79)); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[m\x1b[H\x1b[J\x1b[4;80H" + ); + assert_eq!( + parser.screen().contents_diff(&screen), + b"\x1b[H\x1b[K\x1b[4;80H" + ); + + let screen = parser.screen().clone(); + parser.process(b"a"); + assert_eq!(parser.screen().cursor_position(), (3, 80)); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[m\x1b[H\x1b[J\x1b[4;80Ha" + ); + assert_eq!(parser.screen().contents_diff(&screen), b"a"); + + let screen = parser.screen().clone(); + parser.process(b"\n"); + assert_eq!(parser.screen().cursor_position(), (4, 80)); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[m\x1b[H\x1b[J\x1b[4;80Ha\n" + ); + assert_eq!(parser.screen().contents_diff(&screen), b"\n"); + + let screen = parser.screen().clone(); + parser.process(b"b"); + assert_eq!(parser.screen().cursor_position(), (5, 1)); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[m\x1b[H\x1b[J\x1b[4;80Ha\x1b[6;1Hb" + ); + assert_eq!(parser.screen().contents_diff(&screen), b"\r\nb"); } #[test] |