Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdfa79a

Browse files
committed
test(help): Test mixed argument types
1 parent 66fe920 commit bdfa79a

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

tests/builder/help.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,3 +3967,79 @@ Print this message or the help of the given subcommand(s)
39673967
"#]];
39683968
utils::assert_output(cmd, "parent -h", expected, false);
39693969
}
3970+
3971+
#[test]
3972+
fn mixed_argument_types() {
3973+
let cmd = Command::new("myprog")
3974+
.about("mixed arguments")
3975+
.next_help_heading("Mixed")
3976+
.arg(arg!(-b --both "Both long and short"))
3977+
.arg(arg!(--long "Long only"))
3978+
.arg(arg!(<POSITIONAL> "Positional"));
3979+
3980+
let expected = str![[r#"
3981+
mixed arguments
3982+
3983+
Usage: myprog [OPTIONS] <POSITIONAL>
3984+
3985+
Options:
3986+
-h, --help Print help
3987+
3988+
Mixed:
3989+
-b, --both Both long and short
3990+
--long Long only
3991+
<POSITIONAL> Positional
3992+
3993+
"#]];
3994+
utils::assert_output(cmd, "myprog --help", expected, false);
3995+
}
3996+
3997+
#[test]
3998+
fn mixed_argument_types_short_positional() {
3999+
let cmd = Command::new("myprog")
4000+
.about("mixed arguments")
4001+
.next_help_heading("Mixed")
4002+
.arg(arg!(-b --both "Both long and short"))
4003+
.arg(arg!(--long "Long only"))
4004+
.arg(arg!(<S> "Short positional"));
4005+
4006+
let expected = str![[r#"
4007+
mixed arguments
4008+
4009+
Usage: myprog [OPTIONS] <S>
4010+
4011+
Options:
4012+
-h, --help Print help
4013+
4014+
Mixed:
4015+
-b, --both Both long and short
4016+
--long Long only
4017+
<S> Short positional
4018+
4019+
"#]];
4020+
utils::assert_output(cmd, "myprog --help", expected, false);
4021+
}
4022+
4023+
#[test]
4024+
fn mixed_argument_types_no_short() {
4025+
let cmd = Command::new("myprog")
4026+
.about("mixed arguments")
4027+
.next_help_heading("Mixed")
4028+
.arg(arg!(--long "Long only"))
4029+
.arg(arg!(<POSITIONAL> "Positional"));
4030+
4031+
let expected = str![[r#"
4032+
mixed arguments
4033+
4034+
Usage: myprog [OPTIONS] <POSITIONAL>
4035+
4036+
Options:
4037+
-h, --help Print help
4038+
4039+
Mixed:
4040+
--long Long only
4041+
<POSITIONAL> Positional
4042+
4043+
"#]];
4044+
utils::assert_output(cmd, "myprog --help", expected, false);
4045+
}

0 commit comments

Comments
 (0)