Skip to content

Commit

Permalink
test: add validation test for clap-rs#1794
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Aug 11, 2021
1 parent 69d7594 commit 4f31d88
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/positionals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, Arg, ErrorKind};
use clap::{App, AppSettings, Arg, ArgGroup, ErrorKind};

#[test]
fn only_pos_follow() {
Expand Down Expand Up @@ -307,3 +307,26 @@ fn positional_arg_with_multiple_occurrences() {
.arg(Arg::new("arg").multiple_occurrences(true))
.try_get_matches();
}

/// Test for https://github.com/clap-rs/clap/issues/1794.
#[test]
fn positional_args_with_options() {
let app = clap::App::new("hello")
.bin_name("deno")
.setting(AppSettings::AllowMissingPositional)
.arg(Arg::new("option1").long("option1").takes_value(false))
.arg(Arg::new("pos1").takes_value(true))
.arg(Arg::new("pos2").takes_value(true))
.arg(Arg::new("pos3").takes_value(true))
.group(
ArgGroup::new("arg1")
.args(&["pos1", "pos2", "option1"])
.required(true),
);

let m = app.get_matches_from(&["deno", "--option1", "abcd"]);
assert!(m.is_present("option1"));
assert!(!m.is_present("pos1"));
assert!(m.is_present("pos2"));
assert_eq!(m.value_of("pos2"), Some("abcd"));
}

0 comments on commit 4f31d88

Please sign in to comment.