119625d8cSopenharmony_ciuse super::utils;
219625d8cSopenharmony_ci
319625d8cSopenharmony_ciuse clap::{arg, error::ErrorKind, Arg, ArgAction, Command};
419625d8cSopenharmony_ci
519625d8cSopenharmony_ci#[test]
619625d8cSopenharmony_cifn flag_subcommand_normal() {
719625d8cSopenharmony_ci    let matches = Command::new("test")
819625d8cSopenharmony_ci        .subcommand(
919625d8cSopenharmony_ci            Command::new("some").short_flag('S').long_flag("some").arg(
1019625d8cSopenharmony_ci                Arg::new("test")
1119625d8cSopenharmony_ci                    .short('t')
1219625d8cSopenharmony_ci                    .long("test")
1319625d8cSopenharmony_ci                    .help("testing testing")
1419625d8cSopenharmony_ci                    .action(ArgAction::SetTrue),
1519625d8cSopenharmony_ci            ),
1619625d8cSopenharmony_ci        )
1719625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "some", "--test"])
1819625d8cSopenharmony_ci        .unwrap();
1919625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
2019625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
2119625d8cSopenharmony_ci    assert!(*sub_matches
2219625d8cSopenharmony_ci        .get_one::<bool>("test")
2319625d8cSopenharmony_ci        .expect("defaulted by clap"));
2419625d8cSopenharmony_ci}
2519625d8cSopenharmony_ci
2619625d8cSopenharmony_ci#[test]
2719625d8cSopenharmony_cifn flag_subcommand_normal_with_alias() {
2819625d8cSopenharmony_ci    let matches = Command::new("test")
2919625d8cSopenharmony_ci        .subcommand(
3019625d8cSopenharmony_ci            Command::new("some")
3119625d8cSopenharmony_ci                .short_flag('S')
3219625d8cSopenharmony_ci                .long_flag("S")
3319625d8cSopenharmony_ci                .arg(
3419625d8cSopenharmony_ci                    Arg::new("test")
3519625d8cSopenharmony_ci                        .short('t')
3619625d8cSopenharmony_ci                        .long("test")
3719625d8cSopenharmony_ci                        .help("testing testing")
3819625d8cSopenharmony_ci                        .action(ArgAction::SetTrue),
3919625d8cSopenharmony_ci                )
4019625d8cSopenharmony_ci                .alias("result"),
4119625d8cSopenharmony_ci        )
4219625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "result", "--test"])
4319625d8cSopenharmony_ci        .unwrap();
4419625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
4519625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
4619625d8cSopenharmony_ci    assert!(*sub_matches
4719625d8cSopenharmony_ci        .get_one::<bool>("test")
4819625d8cSopenharmony_ci        .expect("defaulted by clap"));
4919625d8cSopenharmony_ci}
5019625d8cSopenharmony_ci
5119625d8cSopenharmony_ci#[test]
5219625d8cSopenharmony_cifn flag_subcommand_short() {
5319625d8cSopenharmony_ci    let matches = Command::new("test")
5419625d8cSopenharmony_ci        .subcommand(
5519625d8cSopenharmony_ci            Command::new("some").short_flag('S').arg(
5619625d8cSopenharmony_ci                Arg::new("test")
5719625d8cSopenharmony_ci                    .short('t')
5819625d8cSopenharmony_ci                    .long("test")
5919625d8cSopenharmony_ci                    .help("testing testing")
6019625d8cSopenharmony_ci                    .action(ArgAction::SetTrue),
6119625d8cSopenharmony_ci            ),
6219625d8cSopenharmony_ci        )
6319625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-S", "--test"])
6419625d8cSopenharmony_ci        .unwrap();
6519625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
6619625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
6719625d8cSopenharmony_ci    assert!(*sub_matches
6819625d8cSopenharmony_ci        .get_one::<bool>("test")
6919625d8cSopenharmony_ci        .expect("defaulted by clap"));
7019625d8cSopenharmony_ci}
7119625d8cSopenharmony_ci
7219625d8cSopenharmony_ci#[test]
7319625d8cSopenharmony_cifn flag_subcommand_short_with_args() {
7419625d8cSopenharmony_ci    let matches = Command::new("test")
7519625d8cSopenharmony_ci        .subcommand(
7619625d8cSopenharmony_ci            Command::new("some").short_flag('S').arg(
7719625d8cSopenharmony_ci                Arg::new("test")
7819625d8cSopenharmony_ci                    .short('t')
7919625d8cSopenharmony_ci                    .long("test")
8019625d8cSopenharmony_ci                    .help("testing testing")
8119625d8cSopenharmony_ci                    .action(ArgAction::SetTrue),
8219625d8cSopenharmony_ci            ),
8319625d8cSopenharmony_ci        )
8419625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-St"])
8519625d8cSopenharmony_ci        .unwrap();
8619625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
8719625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
8819625d8cSopenharmony_ci    assert!(*sub_matches
8919625d8cSopenharmony_ci        .get_one::<bool>("test")
9019625d8cSopenharmony_ci        .expect("defaulted by clap"));
9119625d8cSopenharmony_ci}
9219625d8cSopenharmony_ci
9319625d8cSopenharmony_ci#[test]
9419625d8cSopenharmony_cifn flag_subcommand_short_with_alias() {
9519625d8cSopenharmony_ci    let matches = Command::new("test")
9619625d8cSopenharmony_ci        .subcommand(
9719625d8cSopenharmony_ci            Command::new("some")
9819625d8cSopenharmony_ci                .short_flag('S')
9919625d8cSopenharmony_ci                .arg(
10019625d8cSopenharmony_ci                    Arg::new("test")
10119625d8cSopenharmony_ci                        .short('t')
10219625d8cSopenharmony_ci                        .long("test")
10319625d8cSopenharmony_ci                        .help("testing testing")
10419625d8cSopenharmony_ci                        .action(ArgAction::SetTrue),
10519625d8cSopenharmony_ci                )
10619625d8cSopenharmony_ci                .short_flag_alias('M')
10719625d8cSopenharmony_ci                .short_flag_alias('B'),
10819625d8cSopenharmony_ci        )
10919625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-Bt"])
11019625d8cSopenharmony_ci        .unwrap();
11119625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
11219625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
11319625d8cSopenharmony_ci    assert!(*sub_matches
11419625d8cSopenharmony_ci        .get_one::<bool>("test")
11519625d8cSopenharmony_ci        .expect("defaulted by clap"));
11619625d8cSopenharmony_ci}
11719625d8cSopenharmony_ci
11819625d8cSopenharmony_ci#[test]
11919625d8cSopenharmony_cifn flag_subcommand_short_with_alias_same_as_short_flag() {
12019625d8cSopenharmony_ci    let matches = Command::new("test")
12119625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('S').short_flag_alias('S'))
12219625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-S"])
12319625d8cSopenharmony_ci        .unwrap();
12419625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
12519625d8cSopenharmony_ci}
12619625d8cSopenharmony_ci
12719625d8cSopenharmony_ci#[test]
12819625d8cSopenharmony_cifn flag_subcommand_long_with_alias_same_as_long_flag() {
12919625d8cSopenharmony_ci    let matches = Command::new("test")
13019625d8cSopenharmony_ci        .subcommand(
13119625d8cSopenharmony_ci            Command::new("some")
13219625d8cSopenharmony_ci                .long_flag("sync")
13319625d8cSopenharmony_ci                .long_flag_alias("sync"),
13419625d8cSopenharmony_ci        )
13519625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--sync"])
13619625d8cSopenharmony_ci        .unwrap();
13719625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
13819625d8cSopenharmony_ci}
13919625d8cSopenharmony_ci
14019625d8cSopenharmony_ci#[test]
14119625d8cSopenharmony_cifn flag_subcommand_short_with_aliases_vis_and_hidden() {
14219625d8cSopenharmony_ci    let cmd = Command::new("test").subcommand(
14319625d8cSopenharmony_ci        Command::new("some")
14419625d8cSopenharmony_ci            .short_flag('S')
14519625d8cSopenharmony_ci            .arg(
14619625d8cSopenharmony_ci                Arg::new("test")
14719625d8cSopenharmony_ci                    .short('t')
14819625d8cSopenharmony_ci                    .long("test")
14919625d8cSopenharmony_ci                    .help("testing testing"),
15019625d8cSopenharmony_ci            )
15119625d8cSopenharmony_ci            .visible_short_flag_aliases(['M', 'B'])
15219625d8cSopenharmony_ci            .short_flag_alias('C'),
15319625d8cSopenharmony_ci    );
15419625d8cSopenharmony_ci    let app1 = cmd.clone();
15519625d8cSopenharmony_ci    let matches1 = app1.try_get_matches_from(vec!["test", "-M"]).unwrap();
15619625d8cSopenharmony_ci    assert_eq!(matches1.subcommand_name().unwrap(), "some");
15719625d8cSopenharmony_ci
15819625d8cSopenharmony_ci    let app2 = cmd.clone();
15919625d8cSopenharmony_ci    let matches2 = app2.try_get_matches_from(vec!["test", "-C"]).unwrap();
16019625d8cSopenharmony_ci    assert_eq!(matches2.subcommand_name().unwrap(), "some");
16119625d8cSopenharmony_ci
16219625d8cSopenharmony_ci    let app3 = cmd.clone();
16319625d8cSopenharmony_ci    let matches3 = app3.try_get_matches_from(vec!["test", "-B"]).unwrap();
16419625d8cSopenharmony_ci    assert_eq!(matches3.subcommand_name().unwrap(), "some");
16519625d8cSopenharmony_ci}
16619625d8cSopenharmony_ci
16719625d8cSopenharmony_ci#[test]
16819625d8cSopenharmony_cifn flag_subcommand_short_with_aliases() {
16919625d8cSopenharmony_ci    let matches = Command::new("test")
17019625d8cSopenharmony_ci        .subcommand(
17119625d8cSopenharmony_ci            Command::new("some")
17219625d8cSopenharmony_ci                .short_flag('S')
17319625d8cSopenharmony_ci                .arg(
17419625d8cSopenharmony_ci                    Arg::new("test")
17519625d8cSopenharmony_ci                        .short('t')
17619625d8cSopenharmony_ci                        .long("test")
17719625d8cSopenharmony_ci                        .help("testing testing")
17819625d8cSopenharmony_ci                        .action(ArgAction::SetTrue),
17919625d8cSopenharmony_ci                )
18019625d8cSopenharmony_ci                .short_flag_aliases(['M', 'B']),
18119625d8cSopenharmony_ci        )
18219625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-Bt"])
18319625d8cSopenharmony_ci        .unwrap();
18419625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
18519625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
18619625d8cSopenharmony_ci    assert!(*sub_matches
18719625d8cSopenharmony_ci        .get_one::<bool>("test")
18819625d8cSopenharmony_ci        .expect("defaulted by clap"));
18919625d8cSopenharmony_ci}
19019625d8cSopenharmony_ci
19119625d8cSopenharmony_ci#[test]
19219625d8cSopenharmony_ci#[should_panic]
19319625d8cSopenharmony_cifn flag_subcommand_short_with_alias_hyphen() {
19419625d8cSopenharmony_ci    let _ = Command::new("test")
19519625d8cSopenharmony_ci        .subcommand(
19619625d8cSopenharmony_ci            Command::new("some")
19719625d8cSopenharmony_ci                .short_flag('S')
19819625d8cSopenharmony_ci                .arg(
19919625d8cSopenharmony_ci                    Arg::new("test")
20019625d8cSopenharmony_ci                        .short('t')
20119625d8cSopenharmony_ci                        .long("test")
20219625d8cSopenharmony_ci                        .help("testing testing"),
20319625d8cSopenharmony_ci                )
20419625d8cSopenharmony_ci                .short_flag_alias('-'),
20519625d8cSopenharmony_ci        )
20619625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-Bt"])
20719625d8cSopenharmony_ci        .unwrap();
20819625d8cSopenharmony_ci}
20919625d8cSopenharmony_ci
21019625d8cSopenharmony_ci#[test]
21119625d8cSopenharmony_ci#[should_panic]
21219625d8cSopenharmony_cifn flag_subcommand_short_with_aliases_hyphen() {
21319625d8cSopenharmony_ci    let _ = Command::new("test")
21419625d8cSopenharmony_ci        .subcommand(
21519625d8cSopenharmony_ci            Command::new("some")
21619625d8cSopenharmony_ci                .short_flag('S')
21719625d8cSopenharmony_ci                .arg(
21819625d8cSopenharmony_ci                    Arg::new("test")
21919625d8cSopenharmony_ci                        .short('t')
22019625d8cSopenharmony_ci                        .long("test")
22119625d8cSopenharmony_ci                        .help("testing testing"),
22219625d8cSopenharmony_ci                )
22319625d8cSopenharmony_ci                .short_flag_aliases(['-', '-', '-']),
22419625d8cSopenharmony_ci        )
22519625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-Bt"])
22619625d8cSopenharmony_ci        .unwrap();
22719625d8cSopenharmony_ci}
22819625d8cSopenharmony_ci
22919625d8cSopenharmony_ci#[test]
23019625d8cSopenharmony_cifn flag_subcommand_short_after_long_arg() {
23119625d8cSopenharmony_ci    let m = Command::new("pacman")
23219625d8cSopenharmony_ci        .subcommand(
23319625d8cSopenharmony_ci            Command::new("sync")
23419625d8cSopenharmony_ci                .short_flag('S')
23519625d8cSopenharmony_ci                .arg(Arg::new("clean").short('c').action(ArgAction::SetTrue)),
23619625d8cSopenharmony_ci        )
23719625d8cSopenharmony_ci        .arg(Arg::new("arg").long("arg").action(ArgAction::Set))
23819625d8cSopenharmony_ci        .try_get_matches_from(vec!["pacman", "--arg", "foo", "-Sc"])
23919625d8cSopenharmony_ci        .unwrap();
24019625d8cSopenharmony_ci    let subm = m.subcommand_matches("sync");
24119625d8cSopenharmony_ci    assert!(subm.is_some());
24219625d8cSopenharmony_ci    let subm = subm.unwrap();
24319625d8cSopenharmony_ci    assert!(*subm.get_one::<bool>("clean").expect("defaulted by clap"));
24419625d8cSopenharmony_ci}
24519625d8cSopenharmony_ci
24619625d8cSopenharmony_ci#[test]
24719625d8cSopenharmony_cifn flag_subcommand_long() {
24819625d8cSopenharmony_ci    let matches = Command::new("test")
24919625d8cSopenharmony_ci        .subcommand(
25019625d8cSopenharmony_ci            Command::new("some").long_flag("some").arg(
25119625d8cSopenharmony_ci                Arg::new("test")
25219625d8cSopenharmony_ci                    .short('t')
25319625d8cSopenharmony_ci                    .long("test")
25419625d8cSopenharmony_ci                    .help("testing testing")
25519625d8cSopenharmony_ci                    .action(ArgAction::SetTrue),
25619625d8cSopenharmony_ci            ),
25719625d8cSopenharmony_ci        )
25819625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--some", "--test"])
25919625d8cSopenharmony_ci        .unwrap();
26019625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
26119625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
26219625d8cSopenharmony_ci    assert!(*sub_matches
26319625d8cSopenharmony_ci        .get_one::<bool>("test")
26419625d8cSopenharmony_ci        .expect("defaulted by clap"));
26519625d8cSopenharmony_ci}
26619625d8cSopenharmony_ci
26719625d8cSopenharmony_ci#[test]
26819625d8cSopenharmony_cifn flag_subcommand_long_with_alias() {
26919625d8cSopenharmony_ci    let matches = Command::new("test")
27019625d8cSopenharmony_ci        .subcommand(
27119625d8cSopenharmony_ci            Command::new("some")
27219625d8cSopenharmony_ci                .long_flag("some")
27319625d8cSopenharmony_ci                .arg(
27419625d8cSopenharmony_ci                    Arg::new("test")
27519625d8cSopenharmony_ci                        .short('t')
27619625d8cSopenharmony_ci                        .long("test")
27719625d8cSopenharmony_ci                        .help("testing testing")
27819625d8cSopenharmony_ci                        .action(ArgAction::SetTrue),
27919625d8cSopenharmony_ci                )
28019625d8cSopenharmony_ci                .long_flag_alias("result"),
28119625d8cSopenharmony_ci        )
28219625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--result", "--test"])
28319625d8cSopenharmony_ci        .unwrap();
28419625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
28519625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
28619625d8cSopenharmony_ci    assert!(*sub_matches
28719625d8cSopenharmony_ci        .get_one::<bool>("test")
28819625d8cSopenharmony_ci        .expect("defaulted by clap"));
28919625d8cSopenharmony_ci}
29019625d8cSopenharmony_ci
29119625d8cSopenharmony_ci#[test]
29219625d8cSopenharmony_cifn flag_subcommand_long_with_aliases() {
29319625d8cSopenharmony_ci    let matches = Command::new("test")
29419625d8cSopenharmony_ci        .subcommand(
29519625d8cSopenharmony_ci            Command::new("some")
29619625d8cSopenharmony_ci                .long_flag("some")
29719625d8cSopenharmony_ci                .arg(
29819625d8cSopenharmony_ci                    Arg::new("test")
29919625d8cSopenharmony_ci                        .short('t')
30019625d8cSopenharmony_ci                        .long("test")
30119625d8cSopenharmony_ci                        .help("testing testing")
30219625d8cSopenharmony_ci                        .action(ArgAction::SetTrue),
30319625d8cSopenharmony_ci                )
30419625d8cSopenharmony_ci                .long_flag_aliases(["result", "someall"]),
30519625d8cSopenharmony_ci        )
30619625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--result", "--test"])
30719625d8cSopenharmony_ci        .unwrap();
30819625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
30919625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
31019625d8cSopenharmony_ci    assert!(*sub_matches
31119625d8cSopenharmony_ci        .get_one::<bool>("test")
31219625d8cSopenharmony_ci        .expect("defaulted by clap"));
31319625d8cSopenharmony_ci}
31419625d8cSopenharmony_ci
31519625d8cSopenharmony_ci#[test]
31619625d8cSopenharmony_cifn flag_subcommand_multiple() {
31719625d8cSopenharmony_ci    let matches = Command::new("test")
31819625d8cSopenharmony_ci        .subcommand(
31919625d8cSopenharmony_ci            Command::new("some")
32019625d8cSopenharmony_ci                .short_flag('S')
32119625d8cSopenharmony_ci                .long_flag("some")
32219625d8cSopenharmony_ci                .arg(arg!(-f --flag "some flag").action(ArgAction::SetTrue))
32319625d8cSopenharmony_ci                .arg(arg!(-p --print "print something").action(ArgAction::SetTrue))
32419625d8cSopenharmony_ci                .subcommand(
32519625d8cSopenharmony_ci                    Command::new("result")
32619625d8cSopenharmony_ci                        .short_flag('R')
32719625d8cSopenharmony_ci                        .long_flag("result")
32819625d8cSopenharmony_ci                        .arg(arg!(-f --flag "some flag").action(ArgAction::SetTrue))
32919625d8cSopenharmony_ci                        .arg(arg!(-p --print "print something").action(ArgAction::SetTrue)),
33019625d8cSopenharmony_ci                ),
33119625d8cSopenharmony_ci        )
33219625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-SfpRfp"])
33319625d8cSopenharmony_ci        .unwrap();
33419625d8cSopenharmony_ci    assert_eq!(matches.subcommand_name().unwrap(), "some");
33519625d8cSopenharmony_ci    let sub_matches = matches.subcommand_matches("some").unwrap();
33619625d8cSopenharmony_ci    assert!(*sub_matches
33719625d8cSopenharmony_ci        .get_one::<bool>("flag")
33819625d8cSopenharmony_ci        .expect("defaulted by clap"));
33919625d8cSopenharmony_ci    assert!(*sub_matches
34019625d8cSopenharmony_ci        .get_one::<bool>("print")
34119625d8cSopenharmony_ci        .expect("defaulted by clap"));
34219625d8cSopenharmony_ci    assert_eq!(sub_matches.subcommand_name().unwrap(), "result");
34319625d8cSopenharmony_ci    let result_matches = sub_matches.subcommand_matches("result").unwrap();
34419625d8cSopenharmony_ci    assert!(*result_matches
34519625d8cSopenharmony_ci        .get_one::<bool>("flag")
34619625d8cSopenharmony_ci        .expect("defaulted by clap"));
34719625d8cSopenharmony_ci    assert!(*result_matches
34819625d8cSopenharmony_ci        .get_one::<bool>("print")
34919625d8cSopenharmony_ci        .expect("defaulted by clap"));
35019625d8cSopenharmony_ci}
35119625d8cSopenharmony_ci
35219625d8cSopenharmony_ci#[cfg(debug_assertions)]
35319625d8cSopenharmony_ci#[test]
35419625d8cSopenharmony_ci#[should_panic = "the \'-f\' short flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"]
35519625d8cSopenharmony_cifn flag_subcommand_short_conflict_with_arg() {
35619625d8cSopenharmony_ci    let _ = Command::new("test")
35719625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('f').long_flag("some"))
35819625d8cSopenharmony_ci        .arg(Arg::new("test").short('f'))
35919625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-f"])
36019625d8cSopenharmony_ci        .unwrap();
36119625d8cSopenharmony_ci}
36219625d8cSopenharmony_ci
36319625d8cSopenharmony_ci#[cfg(debug_assertions)]
36419625d8cSopenharmony_ci#[test]
36519625d8cSopenharmony_ci#[should_panic = "the \'-f\' short flag is specified for both \'some\' and \'result\' subcommands"]
36619625d8cSopenharmony_cifn flag_subcommand_short_conflict_with_alias() {
36719625d8cSopenharmony_ci    let _ = Command::new("test")
36819625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('f').long_flag("some"))
36919625d8cSopenharmony_ci        .subcommand(Command::new("result").short_flag('t').short_flag_alias('f'))
37019625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-f"])
37119625d8cSopenharmony_ci        .unwrap();
37219625d8cSopenharmony_ci}
37319625d8cSopenharmony_ci
37419625d8cSopenharmony_ci#[cfg(debug_assertions)]
37519625d8cSopenharmony_ci#[test]
37619625d8cSopenharmony_ci#[should_panic = "the \'--flag\' long flag is specified for both \'some\' and \'result\' subcommands"]
37719625d8cSopenharmony_cifn flag_subcommand_long_conflict_with_alias() {
37819625d8cSopenharmony_ci    let _ = Command::new("test")
37919625d8cSopenharmony_ci        .subcommand(Command::new("some").long_flag("flag"))
38019625d8cSopenharmony_ci        .subcommand(
38119625d8cSopenharmony_ci            Command::new("result")
38219625d8cSopenharmony_ci                .long_flag("test")
38319625d8cSopenharmony_ci                .long_flag_alias("flag"),
38419625d8cSopenharmony_ci        )
38519625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--flag"])
38619625d8cSopenharmony_ci        .unwrap();
38719625d8cSopenharmony_ci}
38819625d8cSopenharmony_ci
38919625d8cSopenharmony_ci#[cfg(debug_assertions)]
39019625d8cSopenharmony_ci#[test]
39119625d8cSopenharmony_ci#[should_panic = "the \'-f\' short flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"]
39219625d8cSopenharmony_cifn flag_subcommand_short_conflict_with_arg_alias() {
39319625d8cSopenharmony_ci    let _ = Command::new("test")
39419625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('f').long_flag("some"))
39519625d8cSopenharmony_ci        .arg(Arg::new("test").short('t').short_alias('f'))
39619625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "-f"])
39719625d8cSopenharmony_ci        .unwrap();
39819625d8cSopenharmony_ci}
39919625d8cSopenharmony_ci
40019625d8cSopenharmony_ci#[cfg(debug_assertions)]
40119625d8cSopenharmony_ci#[test]
40219625d8cSopenharmony_ci#[should_panic = "the \'--some\' long flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"]
40319625d8cSopenharmony_cifn flag_subcommand_long_conflict_with_arg_alias() {
40419625d8cSopenharmony_ci    let _ = Command::new("test")
40519625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('f').long_flag("some"))
40619625d8cSopenharmony_ci        .arg(Arg::new("test").long("test").alias("some"))
40719625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--some"])
40819625d8cSopenharmony_ci        .unwrap();
40919625d8cSopenharmony_ci}
41019625d8cSopenharmony_ci
41119625d8cSopenharmony_ci#[cfg(debug_assertions)]
41219625d8cSopenharmony_ci#[test]
41319625d8cSopenharmony_ci#[should_panic = "the \'--flag\' long flag for the \'flag\' argument conflicts with the short flag for \'some\' subcommand"]
41419625d8cSopenharmony_cifn flag_subcommand_long_conflict_with_arg() {
41519625d8cSopenharmony_ci    let _ = Command::new("test")
41619625d8cSopenharmony_ci        .subcommand(Command::new("some").short_flag('a').long_flag("flag"))
41719625d8cSopenharmony_ci        .arg(Arg::new("flag").long("flag"))
41819625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--flag"])
41919625d8cSopenharmony_ci        .unwrap();
42019625d8cSopenharmony_ci}
42119625d8cSopenharmony_ci
42219625d8cSopenharmony_ci#[test]
42319625d8cSopenharmony_ci#[should_panic = "the '--help' long flag for the 'help' argument conflicts with the short flag for 'help' subcommand"]
42419625d8cSopenharmony_cifn flag_subcommand_conflict_with_help() {
42519625d8cSopenharmony_ci    let _ = Command::new("test")
42619625d8cSopenharmony_ci        .subcommand(Command::new("help").short_flag('h').long_flag("help"))
42719625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--help"])
42819625d8cSopenharmony_ci        .unwrap();
42919625d8cSopenharmony_ci}
43019625d8cSopenharmony_ci
43119625d8cSopenharmony_ci#[test]
43219625d8cSopenharmony_ci#[cfg(debug_assertions)]
43319625d8cSopenharmony_ci#[should_panic = "the '--version' long flag for the 'version' argument conflicts with the short flag for 'ver' subcommand"]
43419625d8cSopenharmony_cifn flag_subcommand_conflict_with_version() {
43519625d8cSopenharmony_ci    let _ = Command::new("test")
43619625d8cSopenharmony_ci        .version("1.0.0")
43719625d8cSopenharmony_ci        .subcommand(Command::new("ver").short_flag('V').long_flag("version"))
43819625d8cSopenharmony_ci        .try_get_matches_from(vec!["myprog", "--version"])
43919625d8cSopenharmony_ci        .unwrap();
44019625d8cSopenharmony_ci}
44119625d8cSopenharmony_ci
44219625d8cSopenharmony_ci#[test]
44319625d8cSopenharmony_cifn flag_subcommand_long_infer_pass() {
44419625d8cSopenharmony_ci    let m = Command::new("prog")
44519625d8cSopenharmony_ci        .infer_subcommands(true)
44619625d8cSopenharmony_ci        .subcommand(Command::new("test").long_flag("test"))
44719625d8cSopenharmony_ci        .try_get_matches_from(vec!["prog", "--te"])
44819625d8cSopenharmony_ci        .unwrap();
44919625d8cSopenharmony_ci    assert_eq!(m.subcommand_name(), Some("test"));
45019625d8cSopenharmony_ci}
45119625d8cSopenharmony_ci
45219625d8cSopenharmony_ci#[cfg(not(feature = "suggestions"))]
45319625d8cSopenharmony_ci#[test]
45419625d8cSopenharmony_cifn flag_subcommand_long_infer_fail() {
45519625d8cSopenharmony_ci    let m = Command::new("prog")
45619625d8cSopenharmony_ci        .infer_subcommands(true)
45719625d8cSopenharmony_ci        .subcommand(Command::new("test").long_flag("test"))
45819625d8cSopenharmony_ci        .subcommand(Command::new("temp").long_flag("temp"))
45919625d8cSopenharmony_ci        .try_get_matches_from(vec!["prog", "--te"]);
46019625d8cSopenharmony_ci    assert!(m.is_err(), "{:#?}", m.unwrap());
46119625d8cSopenharmony_ci    assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
46219625d8cSopenharmony_ci}
46319625d8cSopenharmony_ci
46419625d8cSopenharmony_ci#[cfg(feature = "suggestions")]
46519625d8cSopenharmony_ci#[test]
46619625d8cSopenharmony_cifn flag_subcommand_long_infer_fail() {
46719625d8cSopenharmony_ci    let m = Command::new("prog")
46819625d8cSopenharmony_ci        .infer_subcommands(true)
46919625d8cSopenharmony_ci        .subcommand(Command::new("test").long_flag("test"))
47019625d8cSopenharmony_ci        .subcommand(Command::new("temp").long_flag("temp"))
47119625d8cSopenharmony_ci        .try_get_matches_from(vec!["prog", "--te"]);
47219625d8cSopenharmony_ci    assert!(m.is_err(), "{:#?}", m.unwrap());
47319625d8cSopenharmony_ci    assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
47419625d8cSopenharmony_ci}
47519625d8cSopenharmony_ci
47619625d8cSopenharmony_ci#[test]
47719625d8cSopenharmony_cifn flag_subcommand_long_infer_pass_close() {
47819625d8cSopenharmony_ci    let m = Command::new("prog")
47919625d8cSopenharmony_ci        .infer_subcommands(true)
48019625d8cSopenharmony_ci        .subcommand(Command::new("test").long_flag("test"))
48119625d8cSopenharmony_ci        .subcommand(Command::new("temp").long_flag("temp"))
48219625d8cSopenharmony_ci        .try_get_matches_from(vec!["prog", "--tes"])
48319625d8cSopenharmony_ci        .unwrap();
48419625d8cSopenharmony_ci    assert_eq!(m.subcommand_name(), Some("test"));
48519625d8cSopenharmony_ci}
48619625d8cSopenharmony_ci
48719625d8cSopenharmony_ci#[test]
48819625d8cSopenharmony_cifn flag_subcommand_long_infer_exact_match() {
48919625d8cSopenharmony_ci    let m = Command::new("prog")
49019625d8cSopenharmony_ci        .infer_subcommands(true)
49119625d8cSopenharmony_ci        .subcommand(Command::new("test").long_flag("test"))
49219625d8cSopenharmony_ci        .subcommand(Command::new("testa").long_flag("testa"))
49319625d8cSopenharmony_ci        .subcommand(Command::new("testb").long_flag("testb"))
49419625d8cSopenharmony_ci        .try_get_matches_from(vec!["prog", "--test"])
49519625d8cSopenharmony_ci        .unwrap();
49619625d8cSopenharmony_ci    assert_eq!(m.subcommand_name(), Some("test"));
49719625d8cSopenharmony_ci}
49819625d8cSopenharmony_ci
49919625d8cSopenharmony_cistatic FLAG_SUBCOMMAND_HELP: &str = "\
50019625d8cSopenharmony_ciQuery the package database.
50119625d8cSopenharmony_ci
50219625d8cSopenharmony_ciUsage: pacman {query|--query|-Q} [OPTIONS]
50319625d8cSopenharmony_ci
50419625d8cSopenharmony_ciOptions:
50519625d8cSopenharmony_ci  -s, --search <search>...  search locally installed packages for matching strings
50619625d8cSopenharmony_ci  -i, --info <info>...      view package information
50719625d8cSopenharmony_ci  -h, --help                Print help
50819625d8cSopenharmony_ci";
50919625d8cSopenharmony_ci
51019625d8cSopenharmony_ci#[test]
51119625d8cSopenharmony_cifn flag_subcommand_long_short_normal_usage_string() {
51219625d8cSopenharmony_ci    let cmd = Command::new("pacman")
51319625d8cSopenharmony_ci        .about("package manager utility")
51419625d8cSopenharmony_ci        .version("5.2.1")
51519625d8cSopenharmony_ci        .subcommand_required(true)
51619625d8cSopenharmony_ci        .author("Pacman Development Team")
51719625d8cSopenharmony_ci        // Query subcommand
51819625d8cSopenharmony_ci        //
51919625d8cSopenharmony_ci        // Only a few of its arguments are implemented below.
52019625d8cSopenharmony_ci        .subcommand(
52119625d8cSopenharmony_ci            Command::new("query")
52219625d8cSopenharmony_ci                .short_flag('Q')
52319625d8cSopenharmony_ci                .long_flag("query")
52419625d8cSopenharmony_ci                .about("Query the package database.")
52519625d8cSopenharmony_ci                .arg(
52619625d8cSopenharmony_ci                    Arg::new("search")
52719625d8cSopenharmony_ci                        .short('s')
52819625d8cSopenharmony_ci                        .long("search")
52919625d8cSopenharmony_ci                        .help("search locally installed packages for matching strings")
53019625d8cSopenharmony_ci                        .conflicts_with("info")
53119625d8cSopenharmony_ci                        .action(ArgAction::Set)
53219625d8cSopenharmony_ci                        .num_args(1..),
53319625d8cSopenharmony_ci                )
53419625d8cSopenharmony_ci                .arg(
53519625d8cSopenharmony_ci                    Arg::new("info")
53619625d8cSopenharmony_ci                        .long("info")
53719625d8cSopenharmony_ci                        .short('i')
53819625d8cSopenharmony_ci                        .conflicts_with("search")
53919625d8cSopenharmony_ci                        .help("view package information")
54019625d8cSopenharmony_ci                        .action(ArgAction::Set)
54119625d8cSopenharmony_ci                        .num_args(1..),
54219625d8cSopenharmony_ci                ),
54319625d8cSopenharmony_ci        );
54419625d8cSopenharmony_ci    utils::assert_output(cmd, "pacman -Qh", FLAG_SUBCOMMAND_HELP, false);
54519625d8cSopenharmony_ci}
54619625d8cSopenharmony_ci
54719625d8cSopenharmony_cistatic FLAG_SUBCOMMAND_NO_SHORT_HELP: &str = "\
54819625d8cSopenharmony_ciQuery the package database.
54919625d8cSopenharmony_ci
55019625d8cSopenharmony_ciUsage: pacman {query|--query} [OPTIONS]
55119625d8cSopenharmony_ci
55219625d8cSopenharmony_ciOptions:
55319625d8cSopenharmony_ci  -s, --search <search>...  search locally installed packages for matching strings
55419625d8cSopenharmony_ci  -i, --info <info>...      view package information
55519625d8cSopenharmony_ci  -h, --help                Print help
55619625d8cSopenharmony_ci";
55719625d8cSopenharmony_ci
55819625d8cSopenharmony_ci#[test]
55919625d8cSopenharmony_cifn flag_subcommand_long_normal_usage_string() {
56019625d8cSopenharmony_ci    let cmd = Command::new("pacman")
56119625d8cSopenharmony_ci        .about("package manager utility")
56219625d8cSopenharmony_ci        .version("5.2.1")
56319625d8cSopenharmony_ci        .subcommand_required(true)
56419625d8cSopenharmony_ci        .author("Pacman Development Team")
56519625d8cSopenharmony_ci        // Query subcommand
56619625d8cSopenharmony_ci        //
56719625d8cSopenharmony_ci        // Only a few of its arguments are implemented below.
56819625d8cSopenharmony_ci        .subcommand(
56919625d8cSopenharmony_ci            Command::new("query")
57019625d8cSopenharmony_ci                .long_flag("query")
57119625d8cSopenharmony_ci                .about("Query the package database.")
57219625d8cSopenharmony_ci                .arg(
57319625d8cSopenharmony_ci                    Arg::new("search")
57419625d8cSopenharmony_ci                        .short('s')
57519625d8cSopenharmony_ci                        .long("search")
57619625d8cSopenharmony_ci                        .help("search locally installed packages for matching strings")
57719625d8cSopenharmony_ci                        .conflicts_with("info")
57819625d8cSopenharmony_ci                        .action(ArgAction::Set)
57919625d8cSopenharmony_ci                        .num_args(1..),
58019625d8cSopenharmony_ci                )
58119625d8cSopenharmony_ci                .arg(
58219625d8cSopenharmony_ci                    Arg::new("info")
58319625d8cSopenharmony_ci                        .long("info")
58419625d8cSopenharmony_ci                        .short('i')
58519625d8cSopenharmony_ci                        .conflicts_with("search")
58619625d8cSopenharmony_ci                        .help("view package information")
58719625d8cSopenharmony_ci                        .action(ArgAction::Set)
58819625d8cSopenharmony_ci                        .num_args(1..),
58919625d8cSopenharmony_ci                ),
59019625d8cSopenharmony_ci        );
59119625d8cSopenharmony_ci    utils::assert_output(
59219625d8cSopenharmony_ci        cmd,
59319625d8cSopenharmony_ci        "pacman query --help",
59419625d8cSopenharmony_ci        FLAG_SUBCOMMAND_NO_SHORT_HELP,
59519625d8cSopenharmony_ci        false,
59619625d8cSopenharmony_ci    );
59719625d8cSopenharmony_ci}
59819625d8cSopenharmony_ci
59919625d8cSopenharmony_cistatic FLAG_SUBCOMMAND_NO_LONG_HELP: &str = "\
60019625d8cSopenharmony_ciQuery the package database.
60119625d8cSopenharmony_ci
60219625d8cSopenharmony_ciUsage: pacman {query|-Q} [OPTIONS]
60319625d8cSopenharmony_ci
60419625d8cSopenharmony_ciOptions:
60519625d8cSopenharmony_ci  -s, --search <search>...  search locally installed packages for matching strings
60619625d8cSopenharmony_ci  -i, --info <info>...      view package information
60719625d8cSopenharmony_ci  -h, --help                Print help
60819625d8cSopenharmony_ci";
60919625d8cSopenharmony_ci
61019625d8cSopenharmony_ci#[test]
61119625d8cSopenharmony_cifn flag_subcommand_short_normal_usage_string() {
61219625d8cSopenharmony_ci    let cmd = Command::new("pacman")
61319625d8cSopenharmony_ci        .about("package manager utility")
61419625d8cSopenharmony_ci        .version("5.2.1")
61519625d8cSopenharmony_ci        .subcommand_required(true)
61619625d8cSopenharmony_ci        .author("Pacman Development Team")
61719625d8cSopenharmony_ci        // Query subcommand
61819625d8cSopenharmony_ci        //
61919625d8cSopenharmony_ci        // Only a few of its arguments are implemented below.
62019625d8cSopenharmony_ci        .subcommand(
62119625d8cSopenharmony_ci            Command::new("query")
62219625d8cSopenharmony_ci                .short_flag('Q')
62319625d8cSopenharmony_ci                .about("Query the package database.")
62419625d8cSopenharmony_ci                .arg(
62519625d8cSopenharmony_ci                    Arg::new("search")
62619625d8cSopenharmony_ci                        .short('s')
62719625d8cSopenharmony_ci                        .long("search")
62819625d8cSopenharmony_ci                        .help("search locally installed packages for matching strings")
62919625d8cSopenharmony_ci                        .conflicts_with("info")
63019625d8cSopenharmony_ci                        .action(ArgAction::Set)
63119625d8cSopenharmony_ci                        .num_args(1..),
63219625d8cSopenharmony_ci                )
63319625d8cSopenharmony_ci                .arg(
63419625d8cSopenharmony_ci                    Arg::new("info")
63519625d8cSopenharmony_ci                        .long("info")
63619625d8cSopenharmony_ci                        .short('i')
63719625d8cSopenharmony_ci                        .conflicts_with("search")
63819625d8cSopenharmony_ci                        .help("view package information")
63919625d8cSopenharmony_ci                        .action(ArgAction::Set)
64019625d8cSopenharmony_ci                        .num_args(1..),
64119625d8cSopenharmony_ci                ),
64219625d8cSopenharmony_ci        );
64319625d8cSopenharmony_ci    utils::assert_output(
64419625d8cSopenharmony_ci        cmd,
64519625d8cSopenharmony_ci        "pacman query --help",
64619625d8cSopenharmony_ci        FLAG_SUBCOMMAND_NO_LONG_HELP,
64719625d8cSopenharmony_ci        false,
64819625d8cSopenharmony_ci    );
64919625d8cSopenharmony_ci}
650