Skip to content

Commit 0d821e0

Browse files
Add tr test
1 parent 95a7258 commit 0d821e0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

text/tests/tr/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,18 @@ fn tr_arguments_validation_error_message_format() {
594594
"tr: missing operand after ‘a’. Two strings must be given when translating.\n",
595595
);
596596
}
597+
598+
// POSIX does not specify how invalid backslash sequences are handled, so there is some flexibility here
599+
// Still, something useful should be done (for instance, tr should not abort in this case)
600+
#[test]
601+
fn tr_ranges_with_invalid_escape_sequences() {
602+
const INPUT: &str = "abcdef ABCDEF -\\ \x07 -\\ 123456789";
603+
604+
// "\7-\9" is:
605+
// treated as a range from \007 through '9' by bsdutils and GNU Core Utilities
606+
// treated as: 1) a range from \007 through '\', and 2) separately the character '9', by BusyBox
607+
tr_test(&["-d", r"\7-\9"], INPUT, r"abcdefABCDEF\\");
608+
609+
// Similar to above
610+
tr_test(&["-d", r"\7-\A"], INPUT, r"abcdefBCDEF\\");
611+
}

0 commit comments

Comments
 (0)