tests: adds tests for .last(true) args

This commit is contained in:
Kevin K 2017-03-11 00:17:57 -05:00
parent f9668297a4
commit 3a10353f4b
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
2 changed files with 133 additions and 0 deletions

View file

@ -290,6 +290,72 @@ FLAGS:
-H, --help Print help information -H, --help Print help information
-v, --version Print version information"; -v, --version Print version information";
static LAST_ARG: &'static str = "last 0.1
USAGE:
last <TARGET> [CORPUS] [-- <ARGS>...]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<TARGET> some
<CORPUS> some
<ARGS>... some";
static LAST_ARG_SC: &'static str = "last 0.1
USAGE:
last <TARGET> [CORPUS] [-- <ARGS>...]
last <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<TARGET> some
<CORPUS> some
<ARGS>... some
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
test some";
static LAST_ARG_REQ: &'static str = "last 0.1
USAGE:
last <TARGET> [CORPUS] -- <ARGS>...
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<TARGET> some
<CORPUS> some
<ARGS>... some";
static LAST_ARG_REQ_SC: &'static str = "last 0.1
USAGE:
last <TARGET> [CORPUS] -- <ARGS>...
last <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<TARGET> some
<CORPUS> some
<ARGS>... some
SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
test some";
#[test] #[test]
fn help_short() { fn help_short() {
let m = App::new("test") let m = App::new("test")
@ -641,3 +707,47 @@ fn customize_version_and_help() {
.version_message("Print version information"); .version_message("Print version information");
assert!(test::compare_output(app, "customize --help", CUSTOM_VERSION_AND_HELP, false)); assert!(test::compare_output(app, "customize --help", CUSTOM_VERSION_AND_HELP, false));
} }
#[test]
fn last_arg_mult_usage() {
let app = App::new("last")
.version("0.1")
.arg(Arg::with_name("TARGET").required(true).help("some"))
.arg(Arg::with_name("CORPUS").help("some"))
.arg(Arg::with_name("ARGS").multiple(true).last(true).help("some"));
assert!(test::compare_output(app, "last --help", LAST_ARG, false));
}
#[test]
fn last_arg_mult_usage_req() {
let app = App::new("last")
.version("0.1")
.arg(Arg::with_name("TARGET").required(true).help("some"))
.arg(Arg::with_name("CORPUS").help("some"))
.arg(Arg::with_name("ARGS").multiple(true).last(true).required(true).help("some"));
assert!(test::compare_output(app, "last --help", LAST_ARG_REQ, false));
}
#[test]
fn last_arg_mult_usage_req_with_sc() {
let app = App::new("last")
.version("0.1")
.setting(AppSettings::SubcommandsNegateReqs)
.arg(Arg::with_name("TARGET").required(true).help("some"))
.arg(Arg::with_name("CORPUS").help("some"))
.arg(Arg::with_name("ARGS").multiple(true).last(true).required(true).help("some"))
.subcommand(SubCommand::with_name("test").about("some"));
assert!(test::compare_output(app, "last --help", LAST_ARG_REQ_SC, false));
}
#[test]
fn last_arg_mult_usage_with_sc() {
let app = App::new("last")
.version("0.1")
.setting(AppSettings::ArgsNegateSubcommands)
.arg(Arg::with_name("TARGET").required(true).help("some"))
.arg(Arg::with_name("CORPUS").help("some"))
.arg(Arg::with_name("ARGS").multiple(true).last(true).help("some"))
.subcommand(SubCommand::with_name("test").about("some"));
assert!(test::compare_output(app, "last --help", LAST_ARG_SC, false));
}

View file

@ -211,3 +211,26 @@ fn missing_required_2() {
assert!(r.is_err()); assert!(r.is_err());
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument); assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
} }
#[test]
fn last_positional() {
let r = App::new("test")
.arg_from_usage("<TARGET> 'some target'")
.arg_from_usage("[CORPUS] 'some corpus'")
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
.get_matches_from_safe(vec!["test", "tgt", "--", "arg"]);
assert!(r.is_ok());
let m = r.unwrap();
assert_eq!(m.values_of("ARGS").unwrap().collect::<Vec<_>>(), &["arg"]);
}
#[test]
fn last_positional_no_double_dash() {
let r = App::new("test")
.arg_from_usage("<TARGET> 'some target'")
.arg_from_usage("[CORPUS] 'some corpus'")
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
.get_matches_from_safe(vec!["test", "tgt", "crp", "arg"]);
assert!(r.is_err());
assert_eq!(r.unwrap_err().kind, ErrorKind::UnknownArgument);
}