From 3ecaa539359b4a7cf634d9a891149616a22360a5 Mon Sep 17 00:00:00 2001 From: ysndr Date: Sun, 25 Aug 2024 18:26:21 +0200 Subject: [PATCH] test: Arg groups from enum --- tests/derive/groups.rs | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/derive/groups.rs b/tests/derive/groups.rs index 37141968e29..64fe92eb69d 100644 --- a/tests/derive/groups.rs +++ b/tests/derive/groups.rs @@ -239,3 +239,57 @@ For more information, try '--help'. "; assert_output::("test", OUTPUT, true); } + +#[test] +fn enum_groups_1() { + #[derive(Parser, Debug, PartialEq, Eq)] + struct Opt { + #[command(flatten)] + source: Source, + } + + #[derive(clap::Args, Clone, Debug, PartialEq, Eq)] + enum Source { + A { + #[arg(short)] + a: bool, + #[arg(long)] + aaa: bool, + }, + B { + #[arg(short)] + b: bool, + }, + } + + assert_eq!( + Opt { + source: Source::A { + a: true, + aaa: false, + } + }, + Opt::try_parse_from(["test", "-a"]).unwrap() + ); + assert_eq!( + Opt { + source: Source::A { a: true, aaa: true } + }, + Opt::try_parse_from(["test", "-a", "--aaa"]).unwrap() + ); + assert_eq!( + Opt { + source: Source::B { b: true } + }, + Opt::try_parse_from(["test", "-b"]).unwrap() + ); + + assert_eq!( + clap::error::ErrorKind::ArgumentConflict, + Opt::try_parse_from(["test", "-b", "-a"]) + .unwrap_err() + .kind(), + ); + + // assert_eq!( ) +}