From da463e1ab80793bd87f3ecb523e8a0fe137d89af Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 6 Mar 2021 14:42:01 -0500 Subject: add a Write implementation for Parser --- tests/write.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/write.rs (limited to 'tests') diff --git a/tests/write.rs b/tests/write.rs new file mode 100644 index 0000000..0b1d5fe --- /dev/null +++ b/tests/write.rs @@ -0,0 +1,60 @@ +use std::io::Write as _; + +#[test] +fn write_text() { + let mut parser = vt100::Parser::default(); + let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; + let bytes = parser.write(input).unwrap(); + assert_eq!(bytes, input.len()); + assert_eq!(parser.screen().contents(), "foobar"); +} + +#[test] +fn cell_contents() { + let mut parser = vt100::Parser::default(); + let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; + let bytes = parser.write(input).unwrap(); + assert_eq!(bytes, input.len()); + 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(), "b"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), ""); +} + +#[test] +fn cell_colors() { + let mut parser = vt100::Parser::default(); + let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; + let bytes = parser.write(input).unwrap(); + assert_eq!(bytes, input.len()); + + assert_eq!( + parser.screen().cell(0, 0).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 3).unwrap().fgcolor(), + vt100::Color::Idx(2) + ); + assert_eq!( + parser.screen().cell(0, 4).unwrap().fgcolor(), + vt100::Color::Idx(2) + ); + assert_eq!( + parser.screen().cell(0, 4).unwrap().bgcolor(), + vt100::Color::Idx(2) + ); +} + +#[test] +fn cell_attrs() { + let mut parser = vt100::Parser::default(); + let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; + let bytes = parser.write(input).unwrap(); + assert_eq!(bytes, input.len()); + + assert!(parser.screen().cell(0, 4).unwrap().italic()); +} -- cgit v1.2.3-54-g00ecf