mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
tests(Suggestions): update tests for subcommand suggestions
This commit is contained in:
parent
2671ca7260
commit
e8518cf07d
5 changed files with 16 additions and 6 deletions
|
@ -70,6 +70,7 @@ mod test {
|
|||
.version("0.1")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg_from_usage("-o --option [scoption]... 'tests options'")
|
||||
.arg_from_usage("-s --subcmdarg [subcmdarg] 'tests other args'")
|
||||
.arg_from_usage("[scpositional] 'tests positionals'"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1665,7 +1665,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
|
||||
// Didn't match a flag or option
|
||||
let suffix =
|
||||
suggestions::did_you_mean_arg_suffix(arg, longs!(self), &self.subcommands);
|
||||
suggestions::did_you_mean_flag_suffix(arg, longs!(self), &self.subcommands);
|
||||
|
||||
// Add the arg to the matches to build a proper usage string
|
||||
if let Some(name) = suffix.1 {
|
||||
|
|
|
@ -103,15 +103,13 @@ mod test {
|
|||
fn suffix_long() {
|
||||
let p_vals = ["test", "possible", "values"];
|
||||
let suffix = "\n\tDid you mean \'--test\'?";
|
||||
assert_eq!(did_you_mean_suffix("tst", p_vals.iter(), DidYouMeanMessageStyle::LongFlag),
|
||||
(suffix, Some("test")));
|
||||
assert_eq!(did_you_mean_flag_suffix("tst", p_vals.iter(), []), (suffix, Some("test")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suffix_enum() {
|
||||
let p_vals = ["test", "possible", "values"];
|
||||
let suffix = "\n\tDid you mean \'test\'?";
|
||||
assert_eq!(did_you_mean_suffix("tst", p_vals.iter(), DidYouMeanMessageStyle::EnumValue),
|
||||
(suffix, Some("test")));
|
||||
assert_eq!(did_you_mean_value_suffix("tst", p_vals.iter()), (suffix, Some("test")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,8 @@ FLAGS:
|
|||
-V, --version Prints version information
|
||||
|
||||
OPTIONS:
|
||||
-o, --option <scoption>... tests options
|
||||
-o, --option <scoption>... tests options
|
||||
-s, --subcmdarg <subcmdarg> tests other args
|
||||
|
||||
ARGS:
|
||||
<scpositional> tests positionals";
|
||||
|
|
|
@ -42,6 +42,15 @@ USAGE:
|
|||
|
||||
For more information try --help";
|
||||
|
||||
#[cfg(feature = "suggestions")]
|
||||
static DYM2: &'static str = "error: Found argument '--subcmdarg' which wasn't expected, or isn't valid in this context
|
||||
\tDid you mean to put '--subcmdarg' after the subcommand 'subcmdarg'?
|
||||
|
||||
USAGE:
|
||||
clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]
|
||||
|
||||
For more information try --help";
|
||||
|
||||
#[test]
|
||||
fn subcommand() {
|
||||
let m = App::new("test")
|
||||
|
@ -121,6 +130,7 @@ fn multiple_aliases() {
|
|||
#[cfg(feature="suggestions")]
|
||||
fn subcmd_did_you_mean_output() {
|
||||
assert!(test::compare_output(test::complex_app(), "clap-test subcm", DYM, true));
|
||||
assert!(test::compare_output(test::complex_app(), "clap-test --subcmdarg foo", DYM2, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue