Add rest support to blocks (#2962)

This commit is contained in:
Jonathan Turner
2021-01-23 10:28:32 +13:00
committed by GitHub
parent a3be6affa4
commit a4b8d4a098
2 changed files with 83 additions and 9 deletions

View File

@@ -428,6 +428,42 @@ fn run_broken_inner_custom_command() {
assert!(actual.err.contains("not found"));
}
#[test]
fn run_custom_command_with_rest() {
let actual = nu!(
cwd: ".",
r#"
def rest-me [...rest: string] { echo $rest.1 $rest.0}; rest-me "hello" "world" | to json
"#
);
assert_eq!(actual.out, r#"["world","hello"]"#);
}
#[test]
fn run_custom_command_with_rest_and_arg() {
let actual = nu!(
cwd: ".",
r#"
def rest-me-with-arg [name: string, ...rest: string] { echo $rest.1 $rest.0 $name}; rest-me-with-arg "hello" "world" "yay" | to json
"#
);
assert_eq!(actual.out, r#"["yay","world","hello"]"#);
}
#[test]
fn run_custom_command_with_rest_and_flag() {
let actual = nu!(
cwd: ".",
r#"
def rest-me-with-flag [--name: string, ...rest: string] { echo $rest.1 $rest.0 $name}; rest-me-with-flag "hello" "world" --name "yay" | to json
"#
);
assert_eq!(actual.out, r#"["world","hello","yay"]"#);
}
#[test]
fn set_variable() {
let actual = nu!(