-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(macros): Support shorthand syntax for ArgGroups
Fixes #1231.
- Loading branch information
Showing
2 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#[macro_use] | ||
extern crate clap; | ||
|
||
use clap::ErrorKind; | ||
|
||
#[test] | ||
fn basic() { | ||
clap_app!(claptests => | ||
|
@@ -151,6 +153,105 @@ fn quoted_arg_name() { | |
assert!(matches.is_present("option2")); | ||
} | ||
|
||
#[test] | ||
fn group_macro() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@group difficulty => | ||
(@arg hard: -h --hard "Sets hard mode") | ||
(@arg normal: -n --normal "Sets normal mode") | ||
(@arg easy: -e --easy "Sets easy mode") | ||
) | ||
); | ||
|
||
let result = app.get_matches_from_safe(vec!["bin_name", "--hard"]); | ||
assert!(result.is_ok()); | ||
let matches = result.expect("Expected to successfully match the given args."); | ||
assert!(matches.is_present("difficulty")); | ||
assert!(matches.is_present("hard")); | ||
} | ||
|
||
#[test] | ||
fn group_macro_set_multiple() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@group difficulty +multiple => | ||
(@arg hard: -h --hard "Sets hard mode") | ||
(@arg normal: -n --normal "Sets normal mode") | ||
(@arg easy: -e --easy "Sets easy mode") | ||
) | ||
); | ||
|
||
let result = app.get_matches_from_safe(vec!["bin_name", "--hard", "--easy"]); | ||
assert!(result.is_ok()); | ||
let matches = result.expect("Expected to successfully match the given args."); | ||
assert!(matches.is_present("difficulty")); | ||
assert!(matches.is_present("hard")); | ||
assert!(matches.is_present("easy")); | ||
assert!(!matches.is_present("normal")); | ||
} | ||
|
||
#[test] | ||
fn group_macro_set_not_multiple() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@group difficulty !multiple => | ||
(@arg hard: -h --hard "Sets hard mode") | ||
(@arg normal: -n --normal "Sets normal mode") | ||
(@arg easy: -e --easy "Sets easy mode") | ||
) | ||
); | ||
|
||
let result = app.get_matches_from_safe(vec!["bin_name", "--hard", "--easy"]); | ||
assert!(result.is_err()); | ||
let err = result.unwrap_err(); | ||
assert_eq!(err.kind, ErrorKind::ArgumentConflict); | ||
} | ||
|
||
#[test] | ||
fn group_macro_set_required() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@group difficulty +required => | ||
(@arg hard: -h --hard "Sets hard mode") | ||
(@arg normal: -n --normal "Sets normal mode") | ||
(@arg easy: -e --easy "Sets easy mode") | ||
) | ||
); | ||
|
||
let result = app.get_matches_from_safe(vec!["bin_name"]); | ||
assert!(result.is_err()); | ||
let err = result.unwrap_err(); | ||
assert_eq!(err.kind, ErrorKind::MissingRequiredArgument); | ||
} | ||
|
||
#[test] | ||
fn group_macro_set_not_required() { | ||
let app = clap_app!(claptests => | ||
(version: "0.1") | ||
(about: "tests clap library") | ||
(author: "Kevin K. <[email protected]>") | ||
(@group difficulty !required => | ||
(@arg hard: -h --hard "Sets hard mode") | ||
(@arg normal: -n --normal "Sets normal mode") | ||
(@arg easy: -e --easy "Sets easy mode") | ||
) | ||
); | ||
|
||
let result = app.get_matches_from_safe(vec!["bin_name"]); | ||
assert!(result.is_ok()); | ||
let matches = result.expect("Expected to successfully match the given args."); | ||
assert!(!matches.is_present("difficulty")); | ||
} | ||
|
||
#[test] | ||
fn arg_enum() { | ||
arg_enum!{ | ||
|