From e2b18f199f77d18b272732907c1fe991e20ec1c2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 10 Jan 2024 20:14:59 -0600 Subject: [PATCH] test(parser): Show flag behavior --- tests/builder/conflicts.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/builder/conflicts.rs b/tests/builder/conflicts.rs index 77f9d5cae17..799dcd3d0dd 100644 --- a/tests/builder/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -724,6 +724,30 @@ For more information, try '--help'. utils::assert_output(cmd, "test value1 sub1", CONFLICT_ERR, true); } +#[test] +#[cfg(feature = "error-context")] +fn flag_conflicts_with_subcommand_long_flag() { + let cmd = Command::new("test") + .args_conflicts_with_subcommands(true) + .arg(arg!(--hello)) + .subcommand(Command::new("sub").long_flag("sub")); + + let res = cmd.try_get_matches_from(vec!["", "--hello", "--sub"]); + assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind()); +} + +#[test] +#[cfg(feature = "error-context")] +fn flag_conflicts_with_subcommand_short_flag() { + let cmd = Command::new("test") + .args_conflicts_with_subcommands(true) + .arg(arg!(--hello)) + .subcommand(Command::new("sub").short_flag('s')); + + let res = cmd.try_get_matches_from(vec!["", "--hello", "-s"]); + assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind()); +} + #[test] fn subcommand_conflict_negates_required() { let cmd = Command::new("test")