Skip to content

Commit cdc27b6

Browse files
committed
test: arg groups from enum
1 parent e99f27f commit cdc27b6

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/derive/groups.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,70 @@ For more information, try '--help'.
239239
";
240240
assert_output::<Opt>("test", OUTPUT, true);
241241
}
242+
243+
#[test]
244+
fn enum_groups_1() {
245+
#[derive(Parser, Debug, PartialEq, Eq)]
246+
struct Opt {
247+
#[command(flatten)]
248+
source: Source,
249+
}
250+
251+
#[derive(clap::Args, Clone, Debug, PartialEq, Eq)]
252+
enum Source {
253+
A {
254+
#[arg(short)]
255+
a: bool,
256+
#[arg(long)]
257+
aa: bool,
258+
#[arg(long)]
259+
aaa: bool,
260+
},
261+
B {
262+
#[arg(short)]
263+
b: bool,
264+
#[arg(long)]
265+
bb: bool,
266+
#[arg(long)]
267+
bbb: bool,
268+
},
269+
}
270+
271+
assert_eq!(
272+
Opt {
273+
source: Source::A {
274+
a: true,
275+
aa: false,
276+
aaa: false
277+
}
278+
},
279+
Opt::try_parse_from(["test", "-a"]).unwrap()
280+
);
281+
assert_eq!(
282+
Opt {
283+
source: Source::A {
284+
a: true,
285+
aa: false,
286+
aaa: true
287+
}
288+
},
289+
Opt::try_parse_from(["test", "-a", "--aaa"]).unwrap()
290+
);
291+
assert_eq!(
292+
Opt {
293+
source: Source::B {
294+
b: true,
295+
bb: false,
296+
bbb: false
297+
}
298+
},
299+
Opt::try_parse_from(["test", "-b"]).unwrap()
300+
);
301+
302+
assert_eq!(
303+
clap::error::ErrorKind::ArgumentConflict,
304+
Opt::try_parse_from(["test", "-b", "-a"]).unwrap_err().kind(),
305+
);
306+
307+
// assert_eq!( )
308+
}

0 commit comments

Comments
 (0)