mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
83 lines
2.6 KiB
Rust
83 lines
2.6 KiB
Rust
extern crate clap;
|
|
|
|
use clap::{App, Arg};
|
|
|
|
#[test]
|
|
fn opts_using_short() {
|
|
let r = App::new("opts")
|
|
.args(&[
|
|
Arg::from_usage("-f [flag] 'some flag'"),
|
|
Arg::from_usage("-c [color] 'some other flag'")
|
|
])
|
|
.get_matches_from_safe(vec!["", "-f", "some", "-c", "other"]);
|
|
assert!(r.is_ok());
|
|
let m = r.unwrap();
|
|
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");
|
|
}
|
|
|
|
#[test]
|
|
fn opts_using_long_space() {
|
|
let r = App::new("opts")
|
|
.args(&[
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from_safe(vec!["", "--flag", "some", "--color", "other"]);
|
|
assert!(r.is_ok());
|
|
let m = r.unwrap();
|
|
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() {
|
|
let r = App::new("opts")
|
|
.args(&[
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from_safe(vec!["", "--flag=some", "--color=other"]);
|
|
assert!(r.is_ok());
|
|
let m = r.unwrap();
|
|
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() {
|
|
let r = App::new("opts")
|
|
.args(&[
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from_safe(vec!["", "-f", "some", "--color", "other"]);
|
|
assert!(r.is_ok());
|
|
let m = r.unwrap();
|
|
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_mixed2() {
|
|
let r = App::new("opts")
|
|
.args(&[
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from_safe(vec!["", "--flag=some", "-c", "other"]);
|
|
assert!(r.is_ok());
|
|
let m = r.unwrap();
|
|
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");
|
|
}
|