mirror of
https://github.com/clap-rs/clap
synced 2025-01-07 10:18:48 +00:00
tests: adds tests for using double hyphen -- as a value
This commit is contained in:
parent
34a7436dd3
commit
5209b61192
1 changed files with 16 additions and 2 deletions
|
@ -28,6 +28,20 @@ fn require_equals_fail() {
|
||||||
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn double_hyphen_as_value() {
|
||||||
|
let res = App::new("prog")
|
||||||
|
.arg(Arg::with_name("cfg")
|
||||||
|
.takes_value(true)
|
||||||
|
.allow_hyphen_values(true)
|
||||||
|
.long("config"))
|
||||||
|
.get_matches_from_safe(vec![
|
||||||
|
"prog", "--config", "--"
|
||||||
|
]);
|
||||||
|
assert!(res.is_ok(), "{:?}", res);
|
||||||
|
assert_eq!(res.unwrap().value_of("cfg"), Some("--"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn require_equals_no_empty_values_fail() {
|
fn require_equals_no_empty_values_fail() {
|
||||||
let res = App::new("prog")
|
let res = App::new("prog")
|
||||||
|
@ -330,10 +344,10 @@ fn leading_hyphen_with_flag_before() {
|
||||||
#[test]
|
#[test]
|
||||||
fn leading_hyphen_with_only_pos_follows() {
|
fn leading_hyphen_with_only_pos_follows() {
|
||||||
let r = App::new("mvae")
|
let r = App::new("mvae")
|
||||||
.arg(Arg::from_usage("-o [opt]... 'some opt'").allow_hyphen_values(true))
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").number_of_values(1).allow_hyphen_values(true))
|
||||||
.arg_from_usage("[arg] 'some arg'")
|
.arg_from_usage("[arg] 'some arg'")
|
||||||
.get_matches_from_safe(vec!["", "-o", "-2", "--", "val"]);
|
.get_matches_from_safe(vec!["", "-o", "-2", "--", "val"]);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok(), "{:?}", r);
|
||||||
let m = r.unwrap();
|
let m = r.unwrap();
|
||||||
assert!(m.is_present("o"));
|
assert!(m.is_present("o"));
|
||||||
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2"]);
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2"]);
|
||||||
|
|
Loading…
Reference in a new issue