run ensure_flag_arg_type for short flag values (#14074)

Closes #13654

# User-Facing Changes

- Short flags are now fully type-checked,
  including null and record signatures for literal arguments:

```nushell
def test [-v: record<l: int>] {};
test -v null # error
test -v {l: ""} # error

def test2 [-v: int] {};
let v = ""
test2 -v $v # error
```

- `polars unpivot` `--index`/`--on` and `into value --columns`
now accept `list` values
This commit is contained in:
Solomon
2024-10-17 02:25:17 +00:00
committed by sholderbach
parent 3af575cce7
commit b0427ca9ff
4 changed files with 28 additions and 19 deletions

View File

@ -1,6 +1,7 @@
use crate::repl::tests::{fail_test, run_test, run_test_contains, TestResult};
use nu_test_support::nu;
use pretty_assertions::assert_eq;
use rstest::rstest;
#[test]
fn no_scope_leak1() -> TestResult {
@ -73,10 +74,21 @@ fn custom_switch1() -> TestResult {
)
}
#[test]
fn custom_flag_with_type_checking() -> TestResult {
#[rstest]
fn custom_flag_with_type_checking(
#[values(
("int", "\"3\""),
("int", "null"),
("record<i: int>", "{i: \"\"}"),
("list<int>", "[\"\"]")
)]
type_sig_value: (&str, &str),
#[values("--dry-run", "-d")] flag: &str,
) -> TestResult {
let (type_sig, value) = type_sig_value;
fail_test(
r#"def florb [--dry-run: int] { $dry_run }; let y = "3"; florb --dry-run=$y"#,
&format!("def florb [{flag}: {type_sig}] {{}}; let y = {value}; florb {flag} $y"),
"type_mismatch",
)
}