aboutsummaryrefslogtreecommitdiff
path: root/structopt/tests/issues.rs
diff options
context:
space:
mode:
Diffstat (limited to 'structopt/tests/issues.rs')
-rw-r--r--structopt/tests/issues.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/structopt/tests/issues.rs b/structopt/tests/issues.rs
new file mode 100644
index 0000000..4d250ae
--- /dev/null
+++ b/structopt/tests/issues.rs
@@ -0,0 +1,67 @@
+// https://github.com/TeXitoi/structopt/issues/151
+// https://github.com/TeXitoi/structopt/issues/289
+
+#[test]
+fn issue_151() {
+ use structopt::{clap::ArgGroup, StructOpt};
+
+ #[derive(StructOpt, Debug)]
+ #[structopt(group = ArgGroup::with_name("verb").required(true).multiple(true))]
+ struct Opt {
+ #[structopt(long, group = "verb")]
+ foo: bool,
+ #[structopt(long, group = "verb")]
+ bar: bool,
+ }
+
+ #[derive(Debug, StructOpt)]
+ struct Cli {
+ #[structopt(flatten)]
+ a: Opt,
+ }
+
+ assert!(Cli::clap().get_matches_from_safe(&["test"]).is_err());
+ assert!(Cli::clap()
+ .get_matches_from_safe(&["test", "--foo"])
+ .is_ok());
+ assert!(Cli::clap()
+ .get_matches_from_safe(&["test", "--bar"])
+ .is_ok());
+ assert!(Cli::clap()
+ .get_matches_from_safe(&["test", "--zebra"])
+ .is_err());
+ assert!(Cli::clap()
+ .get_matches_from_safe(&["test", "--foo", "--bar"])
+ .is_ok());
+}
+
+#[test]
+fn issue_289() {
+ use structopt::{clap::AppSettings, StructOpt};
+
+ #[derive(StructOpt)]
+ #[structopt(setting = AppSettings::InferSubcommands)]
+ enum Args {
+ SomeCommand(SubSubCommand),
+ AnotherCommand,
+ }
+
+ #[derive(StructOpt)]
+ #[structopt(setting = AppSettings::InferSubcommands)]
+ enum SubSubCommand {
+ TestCommand,
+ }
+
+ assert!(Args::clap()
+ .get_matches_from_safe(&["test", "some-command", "test-command"])
+ .is_ok());
+ assert!(Args::clap()
+ .get_matches_from_safe(&["test", "some", "test-command"])
+ .is_ok());
+ assert!(Args::clap()
+ .get_matches_from_safe(&["test", "some-command", "test"])
+ .is_ok());
+ assert!(Args::clap()
+ .get_matches_from_safe(&["test", "some", "test"])
+ .is_ok());
+}