2015-08-27 21:03:45 +00:00
|
|
|
extern crate clap;
|
|
|
|
|
2016-01-31 12:06:21 +00:00
|
|
|
use clap::{App, Arg};
|
2015-08-27 21:03:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opts_using_short() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-01-25 20:56:37 +00:00
|
|
|
.args(&[
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::from_usage("-f [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c [color] 'some other flag'")
|
|
|
|
])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-f", "some", "-c", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2016-01-25 20:56:37 +00:00
|
|
|
assert!(m.is_present("f"));
|
|
|
|
assert_eq!(m.value_of("f").unwrap(), "some");
|
|
|
|
assert!(m.is_present("c"));
|
|
|
|
assert_eq!(m.value_of("c").unwrap(), "other");
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 12:43:53 +00:00
|
|
|
#[test]
|
|
|
|
fn lots_o_vals() {
|
|
|
|
let r = App::new("opts")
|
|
|
|
.arg(
|
|
|
|
Arg::from_usage("-o [opt]... 'some opt'"),
|
|
|
|
)
|
|
|
|
.get_matches_from_safe(vec!["", "-o",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
|
|
|
]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>().len(), 297); // i.e. more than u8
|
|
|
|
}
|
|
|
|
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_long_space() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-01-21 06:48:30 +00:00
|
|
|
.args(&[
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
|
|
])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag", "some", "--color", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opts_using_long_equals() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-01-21 06:48:30 +00:00
|
|
|
.args(&[
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
|
|
])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag=some", "--color=other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opts_using_mixed() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-01-21 06:48:30 +00:00
|
|
|
.args(&[
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
|
|
])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-f", "some", "--color", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
2016-01-26 07:05:32 +00:00
|
|
|
}
|
2015-08-27 21:03:45 +00:00
|
|
|
|
2016-01-26 07:05:32 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_mixed2() {
|
|
|
|
let r = App::new("opts")
|
2016-01-21 06:48:30 +00:00
|
|
|
.args(&[
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
|
|
])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag=some", "-c", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
2016-01-21 05:18:53 +00:00
|
|
|
}
|