From b1c60ba25891b56787c76d6a43a69d7eea1825e0 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 29 Jul 2022 06:40:26 -0700 Subject: [PATCH] termwiz: add test cases for parse_first_as_vec w/ OSC+ST refs: https://github.com/markbt/streampager/issues/57 --- termwiz/src/escape/parser/mod.rs | 128 +++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/termwiz/src/escape/parser/mod.rs b/termwiz/src/escape/parser/mod.rs index dd1949a26..f961c0948 100644 --- a/termwiz/src/escape/parser/mod.rs +++ b/termwiz/src/escape/parser/mod.rs @@ -354,6 +354,134 @@ mod test { String::from_utf8(res).unwrap() } + // + #[test] + fn osc_bel_parse_first_as_vec() { + let data = b"\x1b]8;;http://example.com\x07example\x1b]8;;\x07"; + let mut p = Parser::new(); + + let mut offset = 0; + let mut actions = vec![]; + while let Some((mut act, off)) = p.parse_first_as_vec(&data[offset..]) { + actions.append(&mut act); + offset += off; + } + + k9::snapshot!( + actions, + r#" +[ + OperatingSystemCommand( + SetHyperlink( + Some( + Hyperlink { + params: {}, + uri: "http://example.com", + implicit: false, + }, + ), + ), + ), + Print( + 'e', + ), + Print( + 'x', + ), + Print( + 'a', + ), + Print( + 'm', + ), + Print( + 'p', + ), + Print( + 'l', + ), + Print( + 'e', + ), + OperatingSystemCommand( + SetHyperlink( + None, + ), + ), +] +"# + ); + } + + // + #[test] + fn osc_st_parse_first_as_vec() { + let data = b"\x1b]8;;http://example.com\x1b\\example\x1b]8;;\x1b\\"; + let mut p = Parser::new(); + + let mut offset = 0; + let mut actions = vec![]; + while let Some((mut act, off)) = p.parse_first_as_vec(&data[offset..]) { + actions.append(&mut act); + offset += off; + } + + k9::snapshot!( + actions, + r#" +[ + OperatingSystemCommand( + SetHyperlink( + Some( + Hyperlink { + params: {}, + uri: "http://example.com", + implicit: false, + }, + ), + ), + ), + Esc( + Code( + StringTerminator, + ), + ), + Print( + 'e', + ), + Print( + 'x', + ), + Print( + 'a', + ), + Print( + 'm', + ), + Print( + 'p', + ), + Print( + 'l', + ), + Print( + 'e', + ), + OperatingSystemCommand( + SetHyperlink( + None, + ), + ), + Esc( + Code( + StringTerminator, + ), + ), +] +"# + ); + } + #[test] fn basic_parse() { let mut p = Parser::new();