From 7a2fb34f9a4983b1d35429b0de238e30a556776f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 May 2022 21:07:20 -0500 Subject: [PATCH] test(parser): Ensure conditional requirements work with new Actions --- tests/builder/action.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/builder/action.rs b/tests/builder/action.rs index 8e634b1c6bd1..4edde7c729fa 100644 --- a/tests/builder/action.rs +++ b/tests/builder/action.rs @@ -103,6 +103,36 @@ fn set_true_with_default_value_if_value() { assert_eq!(*matches.get_one::("mammal").unwrap(), true); } +#[test] +fn set_true_with_required_if_eq() { + let cmd = Command::new("test") + .arg( + Arg::new("mammal") + .long("mammal") + .action(ArgAction::SetTrue) + .required_if_eq("dog", "true"), + ) + .arg(Arg::new("dog").long("dog").action(ArgAction::SetTrue)); + + let matches = cmd + .clone() + .try_get_matches_from(["test", "--mammal"]) + .unwrap(); + assert_eq!(matches.get_one::("dog"), None); + assert_eq!(*matches.get_one::("mammal").unwrap(), true); + + cmd.clone() + .try_get_matches_from(["test", "--dog"]) + .unwrap_err(); + + let matches = cmd + .clone() + .try_get_matches_from(["test", "--dog", "--mammal"]) + .unwrap(); + assert_eq!(*matches.get_one::("dog").unwrap(), true); + assert_eq!(*matches.get_one::("mammal").unwrap(), true); +} + #[test] fn set_false() { let cmd = Command::new("test").arg(