Skip to content

Commit

Permalink
test: Arg groups from enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ysndr committed Aug 25, 2024
1 parent f11570c commit 3ecaa53
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/derive/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,57 @@ For more information, try '--help'.
";
assert_output::<Opt>("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!( )
}

0 comments on commit 3ecaa53

Please sign in to comment.