aboutsummaryrefslogtreecommitdiffstats
path: root/tests/window_contents.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-04 00:49:21 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-04 00:49:21 -0500
commitea55c107307ef8bca11accc09ff2c47c74745cb1 (patch)
tree395f68717c932559f0d027d73dd226e0c380c135 /tests/window_contents.rs
parent7958770a507d17e4beed17009206322c6d8fb7c0 (diff)
downloadvt100-rust-ea55c107307ef8bca11accc09ff2c47c74745cb1.tar.gz
vt100-rust-ea55c107307ef8bca11accc09ff2c47c74745cb1.zip
more useful contents/contents_formatted behavior
Diffstat (limited to 'tests/window_contents.rs')
-rw-r--r--tests/window_contents.rs48
1 files changed, 20 insertions, 28 deletions
diff --git a/tests/window_contents.rs b/tests/window_contents.rs
index 6391763..9d7553e 100644
--- a/tests/window_contents.rs
+++ b/tests/window_contents.rs
@@ -2,10 +2,7 @@
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"
- );
+ assert_eq!(screen.contents_formatted(0, 0, 23, 79), "");
screen.process(b"foobar");
compare_formatted(&screen);
@@ -13,10 +10,7 @@ fn formatted() {
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\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.contents_formatted(0, 0, 23, 79), "foobar");
screen.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb");
compare_formatted(&screen);
@@ -24,7 +18,10 @@ fn formatted() {
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[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");
+ assert_eq!(
+ 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);
@@ -32,41 +29,36 @@ fn formatted() {
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");
+ assert_eq!(
+ 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);
- 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");
+ assert_eq!(
+ 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);
- 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");
+ assert_eq!(
+ screen.contents_formatted(0, 0, 23, 79),
+ "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux"
+ );
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");
+ 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");
}
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);
+ screen2.process(contents.as_bytes());
compare_cells(screen, &screen2);
}