mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:37:45 +02:00
make command signature parsing more strict (#14309)
# User-Facing Changes The parser now errors on more invalid command signatures: ```nushell # expected parameter or flag def foo [ bar: int: ] {} # expected type def foo [ bar: = ] {} def foo [ bar: ] {} # expected default value def foo [ bar = ] {} ```
This commit is contained in:
@ -2,6 +2,13 @@ use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn def_with_trailing_comma() {
|
||||
let actual = nu!("def test-command [ foo: int, ] { $foo }; test-command 1");
|
||||
|
||||
assert!(actual.out == "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_with_comment() {
|
||||
Playground::setup("def_with_comment", |dirs, _| {
|
||||
@ -72,6 +79,13 @@ fn def_errors_with_comma_before_equals() {
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_colon_before_equals() {
|
||||
let actual = nu!("def test-command [ foo: = 1 ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_comma_before_colon() {
|
||||
let actual = nu!("def test-command [ foo, : int ] {}");
|
||||
@ -85,7 +99,6 @@ fn def_errors_with_multiple_colons() {
|
||||
assert!(actual.err.contains("expected type"));
|
||||
}
|
||||
|
||||
#[ignore = "This error condition is not implemented yet"]
|
||||
#[test]
|
||||
fn def_errors_with_multiple_types() {
|
||||
let actual = nu!("def test-command [ foo:int:string ] {}");
|
||||
@ -93,6 +106,20 @@ fn def_errors_with_multiple_types() {
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_trailing_colon() {
|
||||
let actual = nu!("def test-command [ foo: int: ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_trailing_default_value() {
|
||||
let actual = nu!("def test-command [ foo: int = ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected default value"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_multiple_commas() {
|
||||
let actual = nu!("def test-command [ foo,,bar ] {}");
|
||||
|
Reference in New Issue
Block a user