Skip to content

Commit 140d5b7

Browse files
Disallow string2 when using -d
1 parent 440b976 commit 140d5b7

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

text/tests/tr/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,14 @@ A ᚠᛏᛘᛌᛏᛏᛧᛧ B",
782782
fn tr_multi_byte_squeeze_translate() {
783783
tr_test(&["-s", "ᚢ", "A"], "123 ᚢᚢᚢᚢᚢᚢ 456", "123 A 456");
784784
}
785+
786+
#[test]
787+
fn tr_dash_d_two_strings() {
788+
tr_bad_arguments_failure_test(
789+
&["-d", "A", "B"],
790+
"\
791+
tr: extra operand 'B'
792+
Only one string may be given when deleting without squeezing repeats.
793+
",
794+
);
795+
}

text/tr.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ impl Args {
4747
return Err("options '-c' and '-C' cannot be used together".to_owned());
4848
}
4949

50-
#[allow(clippy::collapsible_if)]
51-
if self.string2.is_none() {
52-
if !self.delete && !self.squeeze_repeats {
53-
return Err(format!(
54-
"missing operand after '{}'. Two strings must be given when translating.",
55-
self.string1
56-
));
50+
match &self.string2 {
51+
Some(st) => {
52+
if self.delete && !self.squeeze_repeats {
53+
return Err(format!(
54+
"\
55+
extra operand '{st}'
56+
Only one string may be given when deleting without squeezing repeats."
57+
));
58+
}
59+
}
60+
None => {
61+
if !self.delete && !self.squeeze_repeats {
62+
return Err(format!(
63+
"missing operand after '{}'. Two strings must be given when translating.",
64+
self.string1
65+
));
66+
}
5767
}
5868
}
5969

0 commit comments

Comments
 (0)