From 4b4a9c18e4c55a2ba6558ef614292db9c18ab88a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 5 Nov 2019 01:32:25 -0500 Subject: expose the screen separately from the parser --- tests/control.rs | 122 +++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'tests/control.rs') diff --git a/tests/control.rs b/tests/control.rs index b1e8ea2..03352b7 100644 --- a/tests/control.rs +++ b/tests/control.rs @@ -1,74 +1,74 @@ #[test] fn bel() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - assert!(!screen.check_audible_bell()); + assert!(!parser.screen_mut().check_audible_bell()); - screen.process(b"\x07"); - assert!(screen.check_audible_bell()); - assert!(!screen.check_audible_bell()); + parser.process(b"\x07"); + assert!(parser.screen_mut().check_audible_bell()); + assert!(!parser.screen_mut().check_audible_bell()); } #[test] fn bs() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo\x08\x08aa"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "faa"); + parser.process(b"foo\x08\x08aa"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "faa"); - screen.process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar"); - assert_eq!(screen.cell(1, 0).unwrap().contents(), "b"); - assert_eq!(screen.cell(1, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 2).unwrap().contents(), "r"); - assert_eq!(screen.cell(1, 3).unwrap().contents(), "x"); - assert_eq!(screen.cell(1, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(2, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "faa\nbarx"); + parser.process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar"); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "x"); + assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(2, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "faa\nbarx"); } #[test] fn tab() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo\tbar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 5).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 6).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 7).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 8).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 9).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 10).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 11).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "foo bar"); + parser.process(b"foo\tbar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 7).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 8).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 9).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 10).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 11).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo bar"); } fn lf_with(b: u8) { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo"); - screen.process(&[b]); - screen.process(b"bar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 1).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 2).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(1, 4).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 5).unwrap().contents(), "r"); - assert_eq!(screen.cell(1, 6).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n bar"); + parser.process(b"foo"); + parser.process(&[b]); + parser.process(b"bar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 5).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(1, 6).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n bar"); } #[test] @@ -88,14 +88,14 @@ fn ff() { #[test] fn cr() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"fooo\rbar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "baro"); + parser.process(b"fooo\rbar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "baro"); } -- cgit v1.2.3-54-g00ecf