2018-01-31 20:15:01 +00:00
|
|
|
use clap::{App, Arg, ArgSettings};
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_default_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-31 20:15:01 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-01-31 20:15:01 +00:00
|
|
|
.long("option")
|
|
|
|
.setting(ArgSettings::TakesValue),
|
|
|
|
)
|
|
|
|
.try_get_matches_from(vec!["", "--option", "val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_eq_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-31 20:15:01 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-01-31 20:15:01 +00:00
|
|
|
.long("option")
|
|
|
|
.setting(ArgSettings::TakesValue),
|
|
|
|
)
|
|
|
|
.try_get_matches_from(vec!["", "--option=val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_s_eq_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-31 20:15:01 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-31 20:15:01 +00:00
|
|
|
.setting(ArgSettings::TakesValue),
|
|
|
|
)
|
|
|
|
.try_get_matches_from(vec!["", "-o=val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
2017-05-06 23:12:07 +00:00
|
|
|
assert!(m.is_ok(), "{:?}", m.unwrap_err());
|
2016-09-18 19:24:59 +00:00
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_s_default_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-31 20:15:01 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-31 20:15:01 +00:00
|
|
|
.setting(ArgSettings::TakesValue),
|
|
|
|
)
|
|
|
|
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
2017-05-06 23:12:07 +00:00
|
|
|
assert!(m.is_ok(), "{:?}", m.unwrap_err());
|
2016-09-18 19:24:59 +00:00
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_s_no_space_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-31 20:15:01 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-31 20:15:01 +00:00
|
|
|
.setting(ArgSettings::TakesValue),
|
|
|
|
)
|
|
|
|
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_s_no_space_mult_no_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-31 20:15:01 +00:00
|
|
|
.setting(ArgSettings::MultipleValues),
|
2018-01-25 04:05:05 +00:00
|
|
|
)
|
2018-01-31 20:15:01 +00:00
|
|
|
.try_get_matches_from(vec!["", "-o", "val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
|
|
|
assert_eq!(m.value_of("option").unwrap(), "val1,val2,val3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opt_eq_mult_def_delim() {
|
|
|
|
let m = App::new("no_delim")
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("opt")
|
|
|
|
.multiple(true)
|
|
|
|
.use_delimiter(true)
|
2018-01-31 20:15:01 +00:00
|
|
|
.setting(ArgSettings::TakesValue),
|
2018-01-25 04:05:05 +00:00
|
|
|
)
|
2018-01-31 20:15:01 +00:00
|
|
|
.try_get_matches_from(vec!["", "--opt=val1,val2,val3"]);
|
2016-09-18 19:24:59 +00:00
|
|
|
|
|
|
|
assert!(m.is_ok());
|
|
|
|
let m = m.unwrap();
|
|
|
|
|
|
|
|
assert!(m.is_present("option"));
|
|
|
|
assert_eq!(m.occurrences_of("option"), 1);
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(
|
|
|
|
m.values_of("option").unwrap().collect::<Vec<_>>(),
|
|
|
|
&["val1", "val2", "val3"]
|
|
|
|
);
|
2016-09-18 19:24:59 +00:00
|
|
|
}
|