tests: adds tests for requiring the equals syntax in options

This commit is contained in:
Kevin K 2017-02-17 21:56:34 -05:00
parent f002693dec
commit a01812fed8
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A

View file

@ -14,6 +14,62 @@ USAGE:
For more information try --help";
#[test]
fn require_equals_fail() {
let res = App::new("prog")
.arg(Arg::with_name("cfg")
.require_equals(true)
.takes_value(true)
.long("config"))
.get_matches_from_safe(vec![
"prog", "--config", "file.conf"
]);
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
}
#[test]
fn require_equals_no_empty_values_fail() {
let res = App::new("prog")
.arg(Arg::with_name("cfg")
.require_equals(true)
.takes_value(true)
.long("config"))
.arg(Arg::with_name("some"))
.get_matches_from_safe(vec![
"prog", "--config=", "file.conf"
]);
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
}
#[test]
fn require_equals_empty_vals_pass() {
let res = App::new("prog")
.arg(Arg::with_name("cfg")
.require_equals(true)
.takes_value(true)
.empty_values(true)
.long("config"))
.get_matches_from_safe(vec![
"prog", "--config="
]);
assert!(res.is_ok());
}
#[test]
fn require_equals_pass() {
let res = App::new("prog")
.arg(Arg::with_name("cfg")
.require_equals(true)
.takes_value(true)
.long("config"))
.get_matches_from_safe(vec![
"prog", "--config=file.conf"
]);
assert!(res.is_ok());
}
#[test]
fn stdin_char() {
let r = App::new("opts")