Skip to content

Commit 13bc1a8

Browse files
tr: improve argument validation errors
1 parent 042f262 commit 13bc1a8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

text/tests/tr/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,16 @@ fn tr_streaming_state() {
628628
fn tr_minimal_d_s() {
629629
tr_test(&["-d", "-s", "", "A"], "1AA", "1A");
630630
}
631+
632+
#[test]
633+
fn tr_missing_equiv() {
634+
tr_bad_arguments_failure_test(
635+
&["-d", "[==]"],
636+
"tr: missing equivalence class character '[==]'\n",
637+
);
638+
}
639+
640+
#[test]
641+
fn tr_missing_character_class() {
642+
tr_bad_arguments_failure_test(&["-d", "[::]"], "tr: missing character class name '[::]'\n");
643+
}

text/tr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ mod parsing {
388388
let char_between_equals_signs = match between_equals_signs.as_slice() {
389389
&[ch] => ch,
390390
&[] => {
391-
unreachable!();
391+
return Err("tr: missing equivalence class character '[==]'".to_owned());
392392
}
393393
sl => {
394394
const ERROR_MESSAGE_PREFIX: &str = "tr: ";
@@ -756,6 +756,9 @@ mod parsing {
756756
.chain('A'..='F')
757757
.chain('a'..='f')
758758
.collect::<Vec<_>>(),
759+
"" => {
760+
return Err("tr: missing character class name '[::]'".to_string());
761+
}
759762
st => return Err(format!("tr: invalid character class ‘{st}’")),
760763
};
761764

0 commit comments

Comments
 (0)