oxedyne/fe2o3/fe2o3_core/tests/term_inert.rs
1.4 KiB, 1 run
created by r1870400018:77717, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! `Term::inert`: foreign text printed to a terminal draws what it says and acts on nothing. |
| 2 | |
| 3 | use oxedyne_fe2o3_core::prelude::*; |
| 4 | use oxedyne_fe2o3_core::term::Term; |
| 5 | |
| 6 | use std::borrow::Cow; |
| 7 | |
| 8 | |
| 9 | #[test] |
| 10 | fn test_live_characters_are_shown_not_acted_on() -> Outcome<()> { |
| 11 | for (raw, shown) in [ |
| 12 | ("a\u{1b}[31mred", "a\u{241b}[31mred"), |
| 13 | ("\u{1b}]52;c;aGk=\u{7}", "\u{241b}]52;c;aGk=\u{2407}"), |
| 14 | ("nul\u{0}bs\u{8}cr\r", "nul\u{2400}bs\u{2408}cr\u{240d}"), |
| 15 | ("del\u{7f} c1\u{9b}", "del\u{2421} c1<U+009B>"), |
| 16 | ("abc\u{202e}fed\u{2066}x\u{2069}", "abc<U+202E>fed<U+2066>x<U+2069>"), |
| 17 | ] { |
| 18 | let got = Term::inert(raw); |
| 19 | if got != shown { |
| 20 | return Err(err!("{:?} was shown as {:?}, not {:?}.", raw, got, shown; Test, Mismatch)); |
| 21 | } |
| 22 | if got.chars().any(Term::is_live) { |
| 23 | return Err(err!("{:?} still holds a live character.", got; Test, Invalid)); |
| 24 | } |
| 25 | } |
| 26 | Ok(()) |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn test_ordinary_text_is_untouched() -> Outcome<()> { |
| 31 | for s in ["", "printf 'a\\nb'\n\tC:\\new\\table", "Grüße 東京 😀 👩👩👧 ❤️ مرحبا", "US$8 a month, 7,40 €"] { |
| 32 | match Term::inert(s) { |
| 33 | Cow::Borrowed(b) if b == s => (), |
| 34 | got => return Err(err!("{:?} was changed to {:?}.", s, got; Test, Mismatch)), |
| 35 | } |
| 36 | } |
| 37 | Ok(()) |
| 38 | } |