2018-08-01 03:47:08 +00:00
|
|
|
// // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
|
|
|
// // Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
|
|
|
// // Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
|
|
|
// //
|
|
|
|
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// // option. This file may not be copied, modified, or distributed
|
|
|
|
// // except according to those terms.
|
|
|
|
// #[macro_use]
|
|
|
|
// extern crate clap;
|
2017-11-15 17:49:55 +00:00
|
|
|
|
2018-08-01 03:47:08 +00:00
|
|
|
// use clap::{App, Arg, ArgEnum};
|
2017-11-15 17:49:55 +00:00
|
|
|
|
2018-08-01 03:47:08 +00:00
|
|
|
// #[derive(ArgEnum, Debug, PartialEq)]
|
|
|
|
// #[case_sensitive]
|
|
|
|
// enum ArgChoice {
|
|
|
|
// Foo,
|
|
|
|
// Bar,
|
|
|
|
// Baz,
|
|
|
|
// }
|
2017-11-15 17:49:55 +00:00
|
|
|
|
2018-08-01 03:47:08 +00:00
|
|
|
// #[test]
|
|
|
|
// fn when_lowercase() {
|
|
|
|
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
|
|
|
// .arg(
|
|
|
|
// Arg::with_name("arg")
|
|
|
|
// .required(true)
|
|
|
|
// .takes_value(true)
|
|
|
|
// .possible_values(&ArgChoice::variants()),
|
|
|
|
// )
|
2019-09-17 06:26:01 +00:00
|
|
|
// .try_get_matches_from(vec!["", "foo"]); // We expect this to fail.
|
2018-08-01 03:47:08 +00:00
|
|
|
// assert!(matches.is_err());
|
|
|
|
// assert_eq!(matches.unwrap_err().kind, clap::ErrorKind::InvalidValue);
|
|
|
|
// }
|
2017-11-15 17:49:55 +00:00
|
|
|
|
2018-08-01 03:47:08 +00:00
|
|
|
// #[test]
|
|
|
|
// fn when_capitalized() {
|
|
|
|
// let matches = App::new(env!("CARGO_PKG_NAME"))
|
|
|
|
// .arg(
|
|
|
|
// Arg::with_name("arg")
|
|
|
|
// .required(true)
|
|
|
|
// .takes_value(true)
|
|
|
|
// .possible_values(&ArgChoice::variants()),
|
|
|
|
// )
|
2019-09-17 06:26:01 +00:00
|
|
|
// .try_get_matches_from(vec!["", "Foo"])
|
2018-08-01 03:47:08 +00:00
|
|
|
// .unwrap();
|
|
|
|
// let t = value_t!(matches.value_of("arg"), ArgChoice);
|
|
|
|
// assert!(t.is_ok());
|
|
|
|
// assert_eq!(t.unwrap(), ArgChoice::Foo);
|
|
|
|
// }
|