aboutsummaryrefslogtreecommitdiffstats
path: root/tests/escape.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-05 01:32:25 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-05 01:32:25 -0500
commit4b4a9c18e4c55a2ba6558ef614292db9c18ab88a (patch)
tree03c9ada690835acbf3d1b02f46341bde5b579989 /tests/escape.rs
parent59e7c620a516278719c1689ebebeb558bede5b60 (diff)
downloadvt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.tar.gz
vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.zip
expose the screen separately from the parser
Diffstat (limited to 'tests/escape.rs')
-rw-r--r--tests/escape.rs209
1 files changed, 109 insertions, 100 deletions
diff --git a/tests/escape.rs b/tests/escape.rs
index 2385704..d2dd5b1 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -2,177 +2,186 @@
#[test]
fn deckpam() {
- let mut screen = vt100::Screen::new(24, 80);
- assert!(!screen.application_keypad());
- screen.process(b"\x1b=");
- assert!(screen.application_keypad());
- screen.process(b"\x1b>");
- assert!(!screen.application_keypad());
+ let mut parser = vt100::Parser::new(24, 80);
+ assert!(!parser.screen().application_keypad());
+ parser.process(b"\x1b=");
+ assert!(parser.screen().application_keypad());
+ parser.process(b"\x1b>");
+ assert!(!parser.screen().application_keypad());
}
#[test]
fn ri() {
- let mut screen = vt100::Screen::new(24, 80);
- screen.process(b"foo\nbar\x1bMbaz");
- assert_eq!(screen.contents(0, 0, 23, 79), "foo baz\n bar");
+ let mut parser = vt100::Parser::new(24, 80);
+ parser.process(b"foo\nbar\x1bMbaz");
+ assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo baz\n bar");
}
#[test]
fn ris() {
- let mut screen = vt100::Screen::new(24, 80);
- assert_eq!(screen.cursor_position(), (0, 0));
+ let mut parser = vt100::Parser::new(24, 80);
+ assert_eq!(parser.screen().cursor_position(), (0, 0));
- let cell = screen.cell(0, 0).unwrap();
+ let cell = parser.screen().cell(0, 0).unwrap();
assert_eq!(cell.contents(), "");
- assert_eq!(screen.contents(0, 0, 23, 79), "");
- assert_eq!(screen.contents_formatted(0, 0, 23, 79), "");
+ assert_eq!(parser.screen().contents(0, 0, 23, 79), "");
+ assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), "");
- assert_eq!(screen.title(), "");
- assert_eq!(screen.icon_name(), "");
+ assert_eq!(parser.screen().title(), "");
+ assert_eq!(parser.screen().icon_name(), "");
- assert_eq!(screen.fgcolor(), vt100::Color::Default);
- assert_eq!(screen.bgcolor(), vt100::Color::Default);
+ assert_eq!(parser.screen().fgcolor(), vt100::Color::Default);
+ assert_eq!(parser.screen().bgcolor(), vt100::Color::Default);
- assert!(!screen.bold());
- assert!(!screen.italic());
- assert!(!screen.underline());
- assert!(!screen.inverse());
+ assert!(!parser.screen().bold());
+ assert!(!parser.screen().italic());
+ assert!(!parser.screen().underline());
+ assert!(!parser.screen().inverse());
- assert!(!screen.check_visual_bell());
- assert!(!screen.check_audible_bell());
- assert!(!screen.application_keypad());
- assert!(!screen.application_cursor());
- assert!(!screen.hide_cursor());
- assert!(!screen.bracketed_paste());
- assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None);
+ assert!(!parser.screen_mut().check_visual_bell());
+ assert!(!parser.screen_mut().check_audible_bell());
+ assert!(!parser.screen().application_keypad());
+ assert!(!parser.screen().application_cursor());
+ assert!(!parser.screen().hide_cursor());
+ assert!(!parser.screen().bracketed_paste());
assert_eq!(
- screen.mouse_protocol_encoding(),
+ parser.screen().mouse_protocol_mode(),
+ vt100::MouseProtocolMode::None
+ );
+ assert_eq!(
+ parser.screen().mouse_protocol_encoding(),
vt100::MouseProtocolEncoding::Default
);
- screen.process(b"f\x1b[31m\x1b[47;1;3;4moo\x1b[7m\x1b[21;21H\x1b]2;window title\x07\x1b]1;window icon name\x07\x1b[?25l\x1b[?1h\x1b=\x1b[?9h\x1b[?1000h\x1b[?1006h\x1b[?2004h\x07\x1bg");
+ parser.process(b"f\x1b[31m\x1b[47;1;3;4moo\x1b[7m\x1b[21;21H\x1b]2;window title\x07\x1b]1;window icon name\x07\x1b[?25l\x1b[?1h\x1b=\x1b[?9h\x1b[?1000h\x1b[?1006h\x1b[?2004h\x07\x1bg");
- assert_eq!(screen.cursor_position(), (20, 20));
+ assert_eq!(parser.screen().cursor_position(), (20, 20));
- let cell = screen.cell(0, 0).unwrap();
+ let cell = parser.screen().cell(0, 0).unwrap();
assert_eq!(cell.contents(), "f");
- assert_eq!(screen.contents(0, 0, 23, 79), "foo");
+ assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo");
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"f\x1b[31;47;1;3;4moo"
);
- assert_eq!(screen.title(), "window title");
- assert_eq!(screen.icon_name(), "window icon name");
+ assert_eq!(parser.screen().title(), "window title");
+ assert_eq!(parser.screen().icon_name(), "window icon name");
- assert_eq!(screen.fgcolor(), vt100::Color::Idx(1));
- assert_eq!(screen.bgcolor(), vt100::Color::Idx(7));
+ assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(1));
+ assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(7));
- assert!(screen.bold());
- assert!(screen.italic());
- assert!(screen.underline());
- assert!(screen.inverse());
+ assert!(parser.screen().bold());
+ assert!(parser.screen().italic());
+ assert!(parser.screen().underline());
+ assert!(parser.screen().inverse());
- assert!(screen.check_visual_bell());
- assert!(screen.check_audible_bell());
- assert!(screen.application_keypad());
- assert!(screen.application_cursor());
- assert!(screen.hide_cursor());
- assert!(screen.bracketed_paste());
+ assert!(parser.screen_mut().check_visual_bell());
+ assert!(parser.screen_mut().check_audible_bell());
+ assert!(parser.screen().application_keypad());
+ assert!(parser.screen().application_cursor());
+ assert!(parser.screen().hide_cursor());
+ assert!(parser.screen().bracketed_paste());
assert_eq!(
- screen.mouse_protocol_mode(),
+ parser.screen().mouse_protocol_mode(),
vt100::MouseProtocolMode::PressRelease
);
assert_eq!(
- screen.mouse_protocol_encoding(),
+ parser.screen().mouse_protocol_encoding(),
vt100::MouseProtocolEncoding::Sgr
);
- screen.process(b"\x07\x1bg\x1bc");
- assert_eq!(screen.cursor_position(), (0, 0));
+ parser.process(b"\x07\x1bg\x1bc");
+ assert_eq!(parser.screen().cursor_position(), (0, 0));
- let cell = screen.cell(0, 0).unwrap();
+ let cell = parser.screen().cell(0, 0).unwrap();
assert_eq!(cell.contents(), "");
- assert_eq!(screen.contents(0, 0, 23, 79), "");
- assert_eq!(screen.contents_formatted(0, 0, 23, 79), "");
+ assert_eq!(parser.screen().contents(0, 0, 23, 79), "");
+ assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), "");
// title and icon name don't change with reset
- assert_eq!(screen.title(), "window title");
- assert_eq!(screen.icon_name(), "window icon name");
+ assert_eq!(parser.screen().title(), "window title");
+ assert_eq!(parser.screen().icon_name(), "window icon name");
- assert_eq!(screen.fgcolor(), vt100::Color::Default);
- assert_eq!(screen.bgcolor(), vt100::Color::Default);
+ assert_eq!(parser.screen().fgcolor(), vt100::Color::Default);
+ assert_eq!(parser.screen().bgcolor(), vt100::Color::Default);
- assert!(!screen.bold());
- assert!(!screen.italic());
- assert!(!screen.underline());
- assert!(!screen.inverse());
+ assert!(!parser.screen().bold());
+ assert!(!parser.screen().italic());
+ assert!(!parser.screen().underline());
+ assert!(!parser.screen().inverse());
// 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());
- assert!(!screen.bracketed_paste());
- assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None);
+ assert!(parser.screen_mut().check_visual_bell());
+ assert!(parser.screen_mut().check_audible_bell());
+
+ assert!(!parser.screen().application_keypad());
+ assert!(!parser.screen().application_cursor());
+ assert!(!parser.screen().hide_cursor());
+ assert!(!parser.screen().bracketed_paste());
assert_eq!(
- screen.mouse_protocol_encoding(),
+ parser.screen().mouse_protocol_mode(),
+ vt100::MouseProtocolMode::None
+ );
+ assert_eq!(
+ parser.screen().mouse_protocol_encoding(),
vt100::MouseProtocolEncoding::Default
);
}
#[test]
fn vb() {
- let mut screen = vt100::Screen::new(24, 80);
- assert!(!screen.check_visual_bell());
- screen.process(b"\x1bg");
- assert!(screen.check_visual_bell());
- assert!(!screen.check_visual_bell());
+ let mut parser = vt100::Parser::new(24, 80);
+ assert!(!parser.screen_mut().check_visual_bell());
+ parser.process(b"\x1bg");
+ assert!(parser.screen_mut().check_visual_bell());
+ assert!(!parser.screen_mut().check_visual_bell());
}
#[test]
fn decsc() {
- let mut screen = vt100::Screen::new(24, 80);
- screen.process(b"foo\x1b7\r\n\r\n\r\n bar\x1b8baz");
- assert_eq!(screen.contents(0, 0, 23, 79), "foobaz\n\n\n bar");
- assert_eq!(screen.cursor_position(), (0, 6));
+ let mut parser = vt100::Parser::new(24, 80);
+ parser.process(b"foo\x1b7\r\n\r\n\r\n bar\x1b8baz");
+ assert_eq!(
+ parser.screen().contents(0, 0, 23, 79),
+ "foobaz\n\n\n bar"
+ );
+ assert_eq!(parser.screen().cursor_position(), (0, 6));
- screen.process(b"\x1b[?47h\x1b[20;20H");
- assert_eq!(screen.contents(0, 0, 23, 79), "");
- assert_eq!(screen.cursor_position(), (19, 19));
+ parser.process(b"\x1b[?47h\x1b[20;20H");
+ assert_eq!(parser.screen().contents(0, 0, 23, 79), "");
+ assert_eq!(parser.screen().cursor_position(), (19, 19));
- screen.process(b"\x1b8");
- assert_eq!(screen.cursor_position(), (0, 0));
+ parser.process(b"\x1b8");
+ assert_eq!(parser.screen().cursor_position(), (0, 0));
- screen.process(b"\x1b[?47l\x1b[20;20H");
- assert_eq!(screen.cursor_position(), (19, 19));
+ parser.process(b"\x1b[?47l\x1b[20;20H");
+ assert_eq!(parser.screen().cursor_position(), (19, 19));
- screen.process(b"\x1b8");
- assert_eq!(screen.cursor_position(), (0, 3));
+ parser.process(b"\x1b8");
+ assert_eq!(parser.screen().cursor_position(), (0, 3));
- screen.process(b"\x1bc\x1b[31m\x1b[5;15r\x1b[?6hfoo\x1b7");
- assert_eq!(screen.cursor_position(), (4, 3));
+ parser.process(b"\x1bc\x1b[31m\x1b[5;15r\x1b[?6hfoo\x1b7");
+ assert_eq!(parser.screen().cursor_position(), (4, 3));
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"\r\n\r\n\r\n\r\n\x1b[31mfoo"
);
- screen.process(b"\x1b[32m\x1b[?6lbar");
- assert_eq!(screen.cursor_position(), (0, 3));
+ parser.process(b"\x1b[32m\x1b[?6lbar");
+ assert_eq!(parser.screen().cursor_position(), (0, 3));
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mfoo"
);
- screen.process(b"\x1b8\x1b[Hz");
- assert_eq!(screen.cursor_position(), (4, 1));
+ parser.process(b"\x1b8\x1b[Hz");
+ assert_eq!(parser.screen().cursor_position(), (4, 1));
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mzoo"
);
}