mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 15:28:53 +02:00
SyntaxShape checking in Alias (#2377)
* initial, working for shallow internals * add recurion on Block * clean up/abstract, Invocations * use Result * inspection of Binary, tests * improve code structure * move arg shape inspection to Alias command * add spanned errors, tests, cleanup for PR * fix test, clippy
This commit is contained in:
@ -15,3 +15,85 @@ fn alias_args_work() {
|
||||
assert_eq!(actual.out, "[1,2]");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn alias_parses_path_tilde() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"
|
||||
alias new-cd [dir] { cd $dir }
|
||||
new-cd ~
|
||||
pwd
|
||||
"#
|
||||
);
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
assert!(actual.out.contains("home"));
|
||||
#[cfg(target_os = "macos")]
|
||||
assert!(actual.out.contains("Users"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_alias_wrong_shape_shallow() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
alias round-to [num digits] { echo $num | str from -d $digits }
|
||||
round-to 3.45 a
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_alias_wrong_shape_deep_invocation() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
alias round-to [nums digits] { echo $nums | each {= $(str from -d $digits)}}
|
||||
round-to 3.45 a
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_alias_wrong_shape_deep_binary() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
alias round-plus-one [nums digits] { echo $nums | each {= $(str from -d $digits | str to-decimal) + 1}}
|
||||
round-plus-one 3.45 a
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_alias_wrong_shape_deeper_binary() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
alias round-one-more [num digits] { echo $num | str from -d $(= $digits + 1) }
|
||||
round-one-more 3.45 a
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("Type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_alias_syntax_shape_clash() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
alias clash [a] { echo 1.1 2 3 | each { str from -d $a } | range $a } }
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(actual.err.contains("alias"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user