diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
commit | 4b4a9c18e4c55a2ba6558ef614292db9c18ab88a (patch) | |
tree | 03c9ada690835acbf3d1b02f46341bde5b579989 /tests/processing.rs | |
parent | 59e7c620a516278719c1689ebebeb558bede5b60 (diff) | |
download | vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.tar.gz vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.zip |
expose the screen separately from the parser
Diffstat (limited to 'tests/processing.rs')
-rw-r--r-- | tests/processing.rs | 320 |
1 files changed, 172 insertions, 148 deletions
diff --git a/tests/processing.rs b/tests/processing.rs index f390493..282ab65 100644 --- a/tests/processing.rs +++ b/tests/processing.rs @@ -2,199 +2,223 @@ #[test] fn split_escape_sequences() { - let mut screen = vt100::Screen::new(24, 80); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"abc"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"abc\x1b[12;24Hdef"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + let mut parser = vt100::Parser::new(24, 80); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"abc"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"abc\x1b[12;24Hdef"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); assert!(contents.contains("abc")); assert!(contents.contains("def")); - assert_eq!(screen.cursor_position(), (11, 26)); + assert_eq!(parser.screen().cursor_position(), (11, 26)); - screen.process(b"\x1b"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"1"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"2"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b";"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"2"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"4"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"H"); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + parser.process(b"\x1b"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"1"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"2"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b";"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"2"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"4"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"H"); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - screen.process(b"\x1b"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"?"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"1"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"h"); - assert_eq!( - screen.mouse_protocol_mode(), + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + parser.process(b"\x1b"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"?"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"1"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"h"); + assert_eq!( + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); - assert_eq!(screen.title(), ""); - screen.process(b"\x1b"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().title(), ""); + parser.process(b"\x1b"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"]"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"]"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b";"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b";"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"a"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"a"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b" "); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b" "); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"'"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"'"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"]"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"]"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"_"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"_"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x07"); - assert_eq!(screen.title(), "a '[]_"); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x07"); + assert_eq!(parser.screen().title(), "a '[]_"); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); } #[test] fn split_utf8() { - let mut screen = vt100::Screen::new(24, 80); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"a"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + let mut parser = vt100::Parser::new(24, 80); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"a"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xc3"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xa1"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + parser.process(b"\xc3"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xa1"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xe3"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x82"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xad"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + parser.process(b"\xe3"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x82"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xad"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xf0"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x9f"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x92"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xa9"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); + parser.process(b"\xf0"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x9f"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x92"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xa9"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); } |