aboutsummaryrefslogtreecommitdiffstats
path: root/tests/window_contents.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/window_contents.rs
parent59e7c620a516278719c1689ebebeb558bede5b60 (diff)
downloadvt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.tar.gz
vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.zip
expose the screen separately from the parser
Diffstat (limited to 'tests/window_contents.rs')
-rw-r--r--tests/window_contents.rs89
1 files changed, 45 insertions, 44 deletions
diff --git a/tests/window_contents.rs b/tests/window_contents.rs
index 9d7553e..898351e 100644
--- a/tests/window_contents.rs
+++ b/tests/window_contents.rs
@@ -1,75 +1,76 @@
#[test]
fn formatted() {
- let mut screen = vt100::Screen::new(24, 80);
- compare_formatted(&screen);
- assert_eq!(screen.contents_formatted(0, 0, 23, 79), "");
+ let mut parser = vt100::Parser::new(24, 80);
+ compare_formatted(&parser);
+ assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), "");
- 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());
- assert!(!screen.cell(0, 5).unwrap().bold());
- assert_eq!(screen.contents_formatted(0, 0, 23, 79), "foobar");
+ parser.process(b"foobar");
+ compare_formatted(&parser);
+ assert!(!parser.screen().cell(0, 2).unwrap().bold());
+ assert!(!parser.screen().cell(0, 3).unwrap().bold());
+ assert!(!parser.screen().cell(0, 4).unwrap().bold());
+ assert!(!parser.screen().cell(0, 5).unwrap().bold());
+ assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), "foobar");
- 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());
- assert!(!screen.cell(0, 5).unwrap().bold());
+ parser.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb");
+ compare_formatted(&parser);
+ assert!(!parser.screen().cell(0, 2).unwrap().bold());
+ assert!(parser.screen().cell(0, 3).unwrap().bold());
+ assert!(!parser.screen().cell(0, 4).unwrap().bold());
+ assert!(!parser.screen().cell(0, 5).unwrap().bold());
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"foo\x1b[33;1;7mb\x1b[mar"
);
- 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());
+ parser.process(b"\x1b[1;5H\x1b[22;42ma");
+ compare_formatted(&parser);
+ assert!(!parser.screen().cell(0, 2).unwrap().bold());
+ assert!(parser.screen().cell(0, 3).unwrap().bold());
+ assert!(!parser.screen().cell(0, 4).unwrap().bold());
+ assert!(!parser.screen().cell(0, 5).unwrap().bold());
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr"
);
- screen.process(b"\x1b[1;6H\x1b[35mr\r\nquux");
- compare_formatted(&screen);
+ parser.process(b"\x1b[1;6H\x1b[35mr\r\nquux");
+ compare_formatted(&parser);
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux"
);
- screen.process(b"\x1b[2;1H\x1b[45mquux");
- compare_formatted(&screen);
+ parser.process(b"\x1b[2;1H\x1b[45mquux");
+ compare_formatted(&parser);
assert_eq!(
- screen.contents_formatted(0, 0, 23, 79),
+ parser.screen().contents_formatted(0, 0, 23, 79),
"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux"
);
- screen
+ parser
.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\r\n\x1b[45mq\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx");
+ compare_formatted(&parser);
+ assert_eq!(parser.screen().contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mq\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx");
}
-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);
- screen2.process(contents.as_bytes());
- compare_cells(screen, &screen2);
+fn compare_formatted(parser: &vt100::Parser) {
+ let (rows, cols) = parser.screen().size();
+ let contents =
+ parser.screen().contents_formatted(0, 0, rows - 1, cols - 1);
+ let mut parser2 = vt100::Parser::new(rows, cols);
+ parser2.process(contents.as_bytes());
+ compare_cells(parser, &parser2);
}
-fn compare_cells(screen1: &vt100::Screen, screen2: &vt100::Screen) {
- assert_eq!(screen1.size(), screen2.size());
- let (rows, cols) = screen1.size();
+fn compare_cells(parser1: &vt100::Parser, parser2: &vt100::Parser) {
+ assert_eq!(parser1.screen().size(), parser2.screen().size());
+ let (rows, cols) = parser1.screen().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();
+ let cell1 = parser1.screen().cell(row, col).unwrap();
+ let cell2 = parser2.screen().cell(row, col).unwrap();
assert_eq!(cell1.contents(), cell2.contents());
assert_eq!(cell1.fgcolor(), cell2.fgcolor());