mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #6006 from BenWiederhake/dev-tr-multi-arg
tr: Correctly handle multiple appearances of flag-args
This commit is contained in:
commit
174864566e
2 changed files with 98 additions and 7 deletions
|
@ -164,20 +164,23 @@ pub fn uu_app() -> Command {
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.override_usage(format_usage(USAGE))
|
.override_usage(format_usage(USAGE))
|
||||||
.infer_long_args(true)
|
.infer_long_args(true)
|
||||||
|
.trailing_var_arg(true)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::COMPLEMENT)
|
Arg::new(options::COMPLEMENT)
|
||||||
.visible_short_alias('C')
|
.visible_short_alias('C')
|
||||||
.short('c')
|
.short('c')
|
||||||
.long(options::COMPLEMENT)
|
.long(options::COMPLEMENT)
|
||||||
.help("use the complement of SET1")
|
.help("use the complement of SET1")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue)
|
||||||
|
.overrides_with(options::COMPLEMENT),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::DELETE)
|
Arg::new(options::DELETE)
|
||||||
.short('d')
|
.short('d')
|
||||||
.long(options::DELETE)
|
.long(options::DELETE)
|
||||||
.help("delete characters in SET1, do not translate")
|
.help("delete characters in SET1, do not translate")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue)
|
||||||
|
.overrides_with(options::DELETE),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SQUEEZE)
|
Arg::new(options::SQUEEZE)
|
||||||
|
@ -188,14 +191,16 @@ pub fn uu_app() -> Command {
|
||||||
listed in the last specified SET, with a single occurrence \
|
listed in the last specified SET, with a single occurrence \
|
||||||
of that character",
|
of that character",
|
||||||
)
|
)
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue)
|
||||||
|
.overrides_with(options::SQUEEZE),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::TRUNCATE_SET1)
|
Arg::new(options::TRUNCATE_SET1)
|
||||||
.long(options::TRUNCATE_SET1)
|
.long(options::TRUNCATE_SET1)
|
||||||
.short('t')
|
.short('t')
|
||||||
.help("first truncate SET1 to length of SET2")
|
.help("first truncate SET1 to length of SET2")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue)
|
||||||
|
.overrides_with(options::TRUNCATE_SET1),
|
||||||
)
|
)
|
||||||
.arg(Arg::new(options::SETS).num_args(1..))
|
.arg(Arg::new(options::SETS).num_args(1..))
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,32 @@ fn test_delete() {
|
||||||
.stdout_is("BD");
|
.stdout_is("BD");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_afterwards_is_not_flag() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["a-z", "-d"])
|
||||||
|
.pipe_in("aBcD")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("-BdD");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_multi() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-d", "-d", "a-z"])
|
||||||
|
.pipe_in("aBcD")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("BD");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_late() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-d", "a-z", "-d"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("extra operand '-d'");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_delete_complement() {
|
fn test_delete_complement() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -78,6 +104,14 @@ fn test_complement1() {
|
||||||
.stdout_is("aX");
|
.stdout_is("aX");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_complement_afterwards_is_not_flag() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["a", "X", "-c"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("extra operand '-c'");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_complement2() {
|
fn test_complement2() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -118,12 +152,46 @@ fn test_complement5() {
|
||||||
.stdout_is("0a1b2c3");
|
.stdout_is("0a1b2c3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_complement_multi_early() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "-c", "a", "X"])
|
||||||
|
.pipe_in("ab")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("aX");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_complement_multi_middle() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "a", "-c", "X"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("tr: extra operand 'X'");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_complement_multi_late() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-c", "a", "X", "-c"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("tr: extra operand '-c'");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_squeeze() {
|
fn test_squeeze() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-s", "a-z"])
|
.args(&["-s", "a-z"])
|
||||||
.pipe_in("aaBBcDcc")
|
.pipe_in("aaBBcDcc")
|
||||||
.run()
|
.succeeds()
|
||||||
|
.stdout_is("aBBcDc");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_squeeze_multi() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-ss", "-s", "a-z"])
|
||||||
|
.pipe_in("aaBBcDcc")
|
||||||
|
.succeeds()
|
||||||
.stdout_is("aBBcDc");
|
.stdout_is("aBBcDc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +200,16 @@ fn test_squeeze_complement() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-sc", "a-z"])
|
.args(&["-sc", "a-z"])
|
||||||
.pipe_in("aaBBcDcc")
|
.pipe_in("aaBBcDcc")
|
||||||
.run()
|
.succeeds()
|
||||||
|
.stdout_is("aaBcDcc");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_squeeze_complement_multi() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-scsc", "a-z"]) // spell-checker:disable-line
|
||||||
|
.pipe_in("aaBBcDcc")
|
||||||
|
.succeeds()
|
||||||
.stdout_is("aaBcDcc");
|
.stdout_is("aaBcDcc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +300,16 @@ fn test_truncate() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-t", "abc", "xy"])
|
.args(&["-t", "abc", "xy"])
|
||||||
.pipe_in("abcde")
|
.pipe_in("abcde")
|
||||||
.run()
|
.succeeds()
|
||||||
|
.stdout_is("xycde"); // spell-checker:disable-line
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_truncate_multi() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-tt", "-t", "abc", "xy"])
|
||||||
|
.pipe_in("abcde")
|
||||||
|
.succeeds()
|
||||||
.stdout_is("xycde"); // spell-checker:disable-line
|
.stdout_is("xycde"); // spell-checker:disable-line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue