mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
70 lines
No EOL
2.3 KiB
Rust
70 lines
No EOL
2.3 KiB
Rust
extern crate clap;
|
|
|
|
use clap::{App, Arg};
|
|
|
|
#[test]
|
|
fn opts_using_short() {
|
|
let m = App::new("opts")
|
|
.args(vec![
|
|
Arg::from_usage("-f [flag] 'some flag'"),
|
|
Arg::from_usage("-c [color] 'some other flag'")
|
|
])
|
|
.get_matches_from(vec!["", "-f", "some", "-c", "other"]);
|
|
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_space() {
|
|
let m = App::new("opts")
|
|
.args(vec![
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
|
|
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 m = App::new("opts")
|
|
.args(vec![
|
|
Arg::from_usage("--flag [flag] 'some flag'"),
|
|
Arg::from_usage("--color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from(vec!["", "--flag=some", "--color=other"]);
|
|
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 m = App::new("opts")
|
|
.args(vec![
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from(vec!["", "-f", "some", "--color", "other"]);
|
|
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");
|
|
|
|
let m = App::new("opts")
|
|
.args(vec![
|
|
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")
|
|
])
|
|
.get_matches_from(vec!["", "--flag=some", "-c", "other"]);
|
|
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");
|
|
} |