Skip to content

tr: improve argument validation errors #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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