Skip to content

Commit

Permalink
Merge pull request #327 from andrewliebenow/tr-empty-equiv
Browse files Browse the repository at this point in the history
tr: improve argument validation errors
  • Loading branch information
jgarzik authored Oct 14, 2024
2 parents 042f262 + 13bc1a8 commit 8f878a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions text/tests/tr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,16 @@ fn tr_streaming_state() {
fn tr_minimal_d_s() {
tr_test(&["-d", "-s", "", "A"], "1AA", "1A");
}

#[test]
fn tr_missing_equiv() {
tr_bad_arguments_failure_test(
&["-d", "[==]"],
"tr: missing equivalence class character '[==]'\n",
);
}

#[test]
fn tr_missing_character_class() {
tr_bad_arguments_failure_test(&["-d", "[::]"], "tr: missing character class name '[::]'\n");
}
5 changes: 4 additions & 1 deletion text/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ mod parsing {
let char_between_equals_signs = match between_equals_signs.as_slice() {
&[ch] => ch,
&[] => {
unreachable!();
return Err("tr: missing equivalence class character '[==]'".to_owned());
}
sl => {
const ERROR_MESSAGE_PREFIX: &str = "tr: ";
Expand Down Expand Up @@ -756,6 +756,9 @@ mod parsing {
.chain('A'..='F')
.chain('a'..='f')
.collect::<Vec<_>>(),
"" => {
return Err("tr: missing character class name '[::]'".to_string());
}
st => return Err(format!("tr: invalid character class ‘{st}’")),
};

Expand Down

0 comments on commit 8f878a9

Please sign in to comment.