mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 00:27:13 +00:00
Merge pull request #4525 from epage/source
test(parser): Verify value_source
This commit is contained in:
commit
d95d371e74
2 changed files with 38 additions and 0 deletions
|
@ -17,6 +17,10 @@ fn opts() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("o"));
|
||||
assert_eq!(
|
||||
m.value_source("o").unwrap(),
|
||||
clap::parser::ValueSource::DefaultValue
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("o").map(|v| v.as_str()).unwrap(),
|
||||
"default"
|
||||
|
@ -59,6 +63,10 @@ fn opt_user_override() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("opt"));
|
||||
assert_eq!(
|
||||
m.value_source("opt").unwrap(),
|
||||
clap::parser::ValueSource::CommandLine
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("opt").map(|v| v.as_str()).unwrap(),
|
||||
"value"
|
||||
|
@ -73,6 +81,10 @@ fn positionals() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::DefaultValue
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"default"
|
||||
|
@ -87,6 +99,10 @@ fn positional_user_override() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::CommandLine
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"value"
|
||||
|
|
|
@ -20,6 +20,10 @@ fn env() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::EnvVariable
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"env"
|
||||
|
@ -100,6 +104,7 @@ fn no_env() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(!m.contains_id("arg"));
|
||||
assert_eq!(m.value_source("arg"), None);
|
||||
assert_eq!(m.get_one::<String>("arg").map(|v| v.as_str()), None);
|
||||
}
|
||||
|
||||
|
@ -116,6 +121,7 @@ fn no_env_no_takes_value() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(!m.contains_id("arg"));
|
||||
assert_eq!(m.value_source("arg"), None);
|
||||
assert_eq!(m.get_one::<String>("arg").map(|v| v.as_str()), None);
|
||||
}
|
||||
|
||||
|
@ -135,6 +141,10 @@ fn with_default() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::EnvVariable
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"env"
|
||||
|
@ -156,6 +166,10 @@ fn opt_user_override() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::CommandLine
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"opt"
|
||||
|
@ -185,6 +199,10 @@ fn positionals() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::EnvVariable
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"env"
|
||||
|
@ -206,6 +224,10 @@ fn positionals_user_override() {
|
|||
assert!(r.is_ok(), "{}", r.unwrap_err());
|
||||
let m = r.unwrap();
|
||||
assert!(m.contains_id("arg"));
|
||||
assert_eq!(
|
||||
m.value_source("arg").unwrap(),
|
||||
clap::parser::ValueSource::CommandLine
|
||||
);
|
||||
assert_eq!(
|
||||
m.get_one::<String>("arg").map(|v| v.as_str()).unwrap(),
|
||||
"opt"
|
||||
|
|
Loading…
Reference in a new issue