2015-09-28 02:48:15 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2016-05-10 02:46:09 +00:00
|
|
|
extern crate regex;
|
|
|
|
|
|
|
|
include!("../clap-test.rs");
|
2015-09-28 02:48:15 +00:00
|
|
|
|
2016-01-25 20:56:37 +00:00
|
|
|
use clap::{App, Arg};
|
2015-08-27 21:03:45 +00:00
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
static SCF2OP: &'static str = "flag NOT present
|
|
|
|
option NOT present
|
|
|
|
positional NOT present
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option NOT present
|
|
|
|
positional NOT present
|
|
|
|
subcmd present
|
|
|
|
flag present 2 times
|
|
|
|
scoption present with value: some
|
|
|
|
An scoption: some
|
|
|
|
scpositional present with value: value
|
|
|
|
";
|
|
|
|
|
|
|
|
static SCFOP: &'static str = "flag NOT present
|
|
|
|
option NOT present
|
|
|
|
positional NOT present
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option NOT present
|
|
|
|
positional NOT present
|
|
|
|
subcmd present
|
|
|
|
flag present 1 times
|
|
|
|
scoption present with value: some
|
|
|
|
An scoption: some
|
|
|
|
scpositional present with value: value
|
|
|
|
";
|
|
|
|
|
|
|
|
static O2P: &'static str = "flag NOT present
|
|
|
|
option present 2 times with value: some
|
|
|
|
An option: some
|
|
|
|
An option: other
|
|
|
|
positional present with value: value
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option present 2 times with value: some
|
|
|
|
An option: some
|
|
|
|
An option: other
|
|
|
|
positional present with value: value
|
|
|
|
subcmd NOT present
|
|
|
|
";
|
|
|
|
|
|
|
|
static F2OP: &'static str = "flag present 2 times
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
subcmd NOT present
|
|
|
|
";
|
|
|
|
|
|
|
|
static FOP: &'static str = "flag present 1 times
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
subcmd NOT present
|
|
|
|
";
|
|
|
|
|
2015-08-27 21:03:45 +00:00
|
|
|
arg_enum!{
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Val1 {
|
|
|
|
ValOne,
|
|
|
|
ValTwo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arg_enum!{
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Val2 {
|
|
|
|
ValOne,
|
|
|
|
ValTwo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arg_enum!{
|
|
|
|
enum Val3 {
|
|
|
|
ValOne,
|
|
|
|
ValTwo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arg_enum!{
|
|
|
|
pub enum Val4 {
|
|
|
|
ValOne,
|
|
|
|
ValTwo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_enums() {
|
|
|
|
let v1_lower = "valone";
|
|
|
|
let v1_camel = "ValOne";
|
|
|
|
|
|
|
|
let v1_lp = v1_lower.parse::<Val1>().unwrap();
|
|
|
|
let v1_cp = v1_camel.parse::<Val1>().unwrap();
|
|
|
|
match v1_lp {
|
|
|
|
Val1::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
match v1_cp {
|
|
|
|
Val1::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
let v1_lp = v1_lower.parse::<Val2>().unwrap();
|
|
|
|
let v1_cp = v1_camel.parse::<Val2>().unwrap();
|
|
|
|
match v1_lp {
|
|
|
|
Val2::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
match v1_cp {
|
|
|
|
Val2::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
let v1_lp = v1_lower.parse::<Val3>().unwrap();
|
|
|
|
let v1_cp = v1_camel.parse::<Val3>().unwrap();
|
|
|
|
match v1_lp {
|
|
|
|
Val3::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
match v1_cp {
|
|
|
|
Val3::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
let v1_lp = v1_lower.parse::<Val4>().unwrap();
|
|
|
|
let v1_cp = v1_camel.parse::<Val4>().unwrap();
|
|
|
|
match v1_lp {
|
|
|
|
Val4::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
match v1_cp {
|
|
|
|
Val4::ValOne => (),
|
|
|
|
_ => panic!("Val1 didn't parse correctly"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_app() {
|
2015-09-07 01:07:46 +00:00
|
|
|
let _ =
|
2016-10-04 21:22:43 +00:00
|
|
|
App::new("test").version("1.0").author("kevin").about("does awesome things").get_matches_from(vec![""]);
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn add_multiple_arg() {
|
|
|
|
let _ = App::new("test")
|
2016-01-21 05:18:53 +00:00
|
|
|
.args(&mut [
|
2015-08-27 21:03:45 +00:00
|
|
|
Arg::with_name("test").short("s"),
|
|
|
|
Arg::with_name("test2").short("l")])
|
2016-10-04 21:22:43 +00:00
|
|
|
.get_matches_from(vec![""]);
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
2016-05-09 03:20:50 +00:00
|
|
|
#[test]
|
|
|
|
fn flag_x2_opt() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value -f -f -o some",
|
2016-05-09 03:20:50 +00:00
|
|
|
"flag present 2 times
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
flag2 NOT present
|
|
|
|
option2 maybe present with value of: Nothing
|
|
|
|
positional2 maybe present with value of: Nothing
|
|
|
|
option3 NOT present
|
|
|
|
positional3 NOT present
|
|
|
|
option present 1 times with value: some
|
|
|
|
An option: some
|
|
|
|
positional present with value: value
|
|
|
|
subcmd NOT present
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_opt_x2_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value --option some --option other", O2P);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_opt_eq_x2_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value --option=some --option=other", O2P);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn short_opt_x2_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value -o some -o other", O2P);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn short_opt_eq_x2_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value -o=some -o=other", O2P);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn short_flag_x2_comb_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value -ff -o some", F2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn short_flag_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value -f -o some", FOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_flag_long_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value --flag --option some", FOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn long_flag_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test value --flag --option=some", FOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_long_opt() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --option some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag -o some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --option=some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_long_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f --option some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -o some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_short_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -o=some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f --option=some", SCFOP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_comb_long_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -ff --option some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_comb_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -ff -o some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_comb_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -ff --option=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_comb_short_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -ff -o=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_x2_long_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --flag --option some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_x2_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --flag -o some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_x2_short_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --flag -o=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_long_flag_x2_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value --flag --flag --option=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_long_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -f --option some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_short_opt_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -f -o some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_short_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -f -o=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sc_short_flag_x2_long_opt_eq_pos() {
|
2016-05-10 02:46:09 +00:00
|
|
|
test::check_complex_output("clap-test subcmd value -f -f --option=some", SCF2OP);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|