|
2 | 2 | // |
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | | -// spell-checker:ignore fullwidth |
| 5 | +// spell-checker:ignore fullwidth refgh tefgh nefgh |
6 | 6 |
|
7 | 7 | use bytecount::count; |
8 | 8 | use unicode_width::UnicodeWidthChar; |
@@ -958,3 +958,37 @@ fn test_fullwidth_characters() { |
958 | 958 | .succeeds() |
959 | 959 | .stdout_is(format!("{e_fullwidth}\n{e_fullwidth}")); |
960 | 960 | } |
| 961 | + |
| 962 | +#[test] |
| 963 | +fn test_character_mode_special_chars() { |
| 964 | + for (args, input, expected) in [ |
| 965 | + // backspace decreases column |
| 966 | + (&["-c", "-w", "5"][..], "abcde\x08fg\n", "abcde\x08f\ng\n"), |
| 967 | + // carriage return resets column |
| 968 | + (&["-c", "-w", "5"], "abcd\refgh\n", "abcd\refgh\n"), |
| 969 | + // tab at start exceeds width |
| 970 | + (&["-c", "-w", "4"], "\tabc\n", "\t\nabc\n"), |
| 971 | + // multiple tabs |
| 972 | + (&["-c", "-w", "10"], "a\tb\tc\n", "a\tb\n\tc\n"), |
| 973 | + // basic folding |
| 974 | + (&["-c", "-w", "3"], "abcdef\n", "abc\ndef\n"), |
| 975 | + // preserves empty lines |
| 976 | + (&["-c", "-w", "5"], "abc\n\ndef\n", "abc\n\ndef\n"), |
| 977 | + // word boundary with -s |
| 978 | + (&["-c", "-s", "-w", "5"], "ab cd ef\n", "ab \ncd ef\n"), |
| 979 | + // tab as word boundary |
| 980 | + (&["-c", "-s", "-w", "10"], "abcd\tefgh\n", "abcd\t\nefgh\n"), |
| 981 | + // wide chars count as 1 in -c mode |
| 982 | + ( |
| 983 | + &["-c", "-w", "3"], |
| 984 | + "\u{FF1A}\u{FF1A}\u{FF1A}\u{FF1A}\n", |
| 985 | + "\u{FF1A}\u{FF1A}\u{FF1A}\n\u{FF1A}\n", |
| 986 | + ), |
| 987 | + ] { |
| 988 | + new_ucmd!() |
| 989 | + .args(args) |
| 990 | + .pipe_in(input) |
| 991 | + .succeeds() |
| 992 | + .stdout_is(expected); |
| 993 | + } |
| 994 | +} |
0 commit comments