diff --git a/src/args.rs b/src/args.rs index 2c7e929..d07b048 100644 --- a/src/args.rs +++ b/src/args.rs @@ -34,7 +34,7 @@ pub fn get_matches() -> ArgMatches<'static> { } #[cfg(test)] -pub fn get_matches_for(args : Vec) -> Result> { +pub fn get_matches_for(args : Vec<&str>) -> Result> { return build().get_matches_from_safe(args); } diff --git a/src/tests/args.rs b/src/tests/args.rs index d44b261..5b18678 100644 --- a/src/tests/args.rs +++ b/src/tests/args.rs @@ -1,7 +1,31 @@ use args; #[test] -fn error_if_no_subcommand() { - let out = args::get_matches_for(vec!("mdp".into())); - assert!(out.is_err()); +fn incorrect_subcommand() { + assert!(args::get_matches_for(vec!("mdp")).is_err()); + assert!(args::get_matches_for(vec!("mdp", "invalid")).is_err()); +} + +#[test] +fn verbose_number() { + fn get_verbose_level(arg_list: Vec<&str>) -> u64 { + return args::get_verbose(args::get_matches_for(arg_list).unwrap()); + } + + assert_eq!(get_verbose_level(vec!("mdp", "build", "-v")), 1); + assert_eq!(get_verbose_level(vec!("mdp", "build", "-vv")), 2); + assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-vv")), 3); + assert_eq!(get_verbose_level(vec!("mdp", "-vv", "build", "-v")), 3); + assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-v")), 2); + assert_eq!(get_verbose_level(vec!("mdp", "-v", "build")), 1); + assert_eq!(get_verbose_level(vec!("mdp", "--verbose", "build", "-v")), 2); + assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "--verbose")), 2); +} + + +#[test] +fn build_subcommand() { + let out = args::get_matches_for(vec!("mdp", "build")); + assert!(out.is_ok()); + assert_eq!(out.unwrap().subcommand_name().unwrap(), "build"); }