Skip to content

Commit

Permalink
chore: add tests for not_strict
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Jul 20, 2024
1 parent dbf67db commit b1df2b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bpaf_derive/src/field_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,19 @@ fn strict_positional_named_fields() {
};
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn not_strict_positional_named_fields() {
let input: NamedField = parse_quote! {
#[bpaf(positional("ARG"), not_strict)]
name: String
};
let output = quote! {
::bpaf::positional::<String>("ARG").not_strict()
};
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn optional_named_pathed() {
let input: NamedField = parse_quote! {
Expand Down
14 changes: 14 additions & 0 deletions tests/positionals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ fn strictly_positional() {
let r = parser.run_inner(&["--"]).unwrap_err().unwrap_stderr();
assert_eq!(r, "expected `A`, pass `--help` for usage information");
}

#[test]
fn not_strictly_positional() {
let parser = positional::<String>("A").not_strict().to_options();

let r = parser.run_inner(&["a"]).unwrap();
assert_eq!(r, "a");

let r = parser.run_inner(&["--", "a"]).unwrap_err().unwrap_stderr();
assert_eq!(r, "expected `A` to be on the left side of `--`");

let r = parser.run_inner(&["--"]).unwrap_err().unwrap_stderr();
assert_eq!(r, "expected `A`, pass `--help` for usage information");
}

0 comments on commit b1df2b0

Please sign in to comment.