Require block params (#4505)

* Require block params

* Improve errors
This commit is contained in:
JT
2022-02-17 06:40:24 -05:00
committed by GitHub
parent f169a9be3b
commit 6e733f49bc
27 changed files with 149 additions and 102 deletions

View File

@ -5,7 +5,7 @@ fn each_works_separately() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [1 2 3] | each { echo $it 10 | math sum } | to json -r
echo [1 2 3] | each { |it| echo $it 10 | math sum } | to json -r
"#
));
@ -17,7 +17,7 @@ fn each_group_works() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [1 2 3 4 5 6] | each group 3 { $it } | to json --raw
echo [1 2 3 4 5 6] | each group 3 { |it| $it } | to json --raw
"#
));
@ -29,7 +29,7 @@ fn each_window() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [1 2 3 4] | each window 3 { $it } | to json --raw
echo [1 2 3 4] | each window 3 { |it| $it } | to json --raw
"#
));
@ -41,7 +41,7 @@ fn each_window_stride() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [1 2 3 4 5 6] | each window 3 -s 2 { echo $it } | to json --raw
echo [1 2 3 4 5 6] | each window 3 -s 2 { |it| echo $it } | to json --raw
"#
));
@ -65,7 +65,7 @@ fn each_implicit_it_in_block() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo [[foo bar]; [a b] [c d] [e f]] | each { nu --testbin cococo $it.foo } | str collect
echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str collect
"#
));

View File

@ -17,7 +17,7 @@ fn echo_range_handles_inclusive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 1..3 | each { $it } | to json --raw
echo 1..3 | each { |x| $x } | to json --raw
"#
));
@ -29,7 +29,7 @@ fn echo_range_handles_exclusive() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 1..<3 | each { $it } | to json --raw
echo 1..<3 | each { |x| $x } | to json --raw
"#
));
@ -41,7 +41,7 @@ fn echo_range_handles_inclusive_down() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 3..1 | each { $it } | to json --raw
echo 3..1 | each { |it| $it } | to json --raw
"#
));
@ -53,7 +53,7 @@ fn echo_range_handles_exclusive_down() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo 3..<1 | each { $it } | to json --raw
echo 3..<1 | each { |it| $it } | to json --raw
"#
));

View File

@ -5,7 +5,7 @@ fn into_int_filesize() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 1kb | into int | each { $it / 1000 }
echo 1kb | into int | each { |it| $it / 1000 }
"#
));
@ -17,7 +17,7 @@ fn into_int_filesize2() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 1kib | into int | each { $it / 1024 }
echo 1kib | into int | each { |it| $it / 1024 }
"#
));
@ -29,7 +29,7 @@ fn into_int_int() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 1024 | into int | each { $it / 1024 }
echo 1024 | into int | each { |it| $it / 1024 }
"#
));

View File

@ -87,7 +87,7 @@ fn lists_all_files_in_directories_from_stream() {
cwd: dirs.test(), pipeline(
r#"
echo dir_a dir_b
| each { ls $it }
| each { |it| ls $it }
| flatten | length
"#
));

View File

@ -22,7 +22,7 @@ mod simple {
r#"
open key_value_separated_arepa_ingredients.txt
| lines
| each { echo $it | parse "{Name}={Value}" }
| each { |it| echo $it | parse "{Name}={Value}" }
| flatten
| get 1
| get Value

View File

@ -8,7 +8,7 @@ fn reduce_table_column() {
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
| from json
| get total
| reduce -f 20 { $it.item + (math eval $"($it.acc)^1.05")}
| reduce -f 20 { |it, acc| $it + (math eval $"($acc)^1.05")}
| into string -d 1
"#
)
@ -23,7 +23,7 @@ fn reduce_table_column_with_path() {
cwd: ".", pipeline(
r#"
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
| reduce -f 20 { $it.item.total + (math eval $"($it.acc)^1.05")}
| reduce -f 20 { |it, acc| $it.total + (math eval $"($acc)^1.05")}
| into string -d 1
"#
)
@ -38,7 +38,7 @@ fn reduce_rows_example() {
cwd: ".", pipeline(
r#"
[[a,b]; [1,2] [3,4]]
| reduce -f 1.6 { $it.acc * ($it.item.a | into int) + ($it.item.b | into int) }
| reduce -f 1.6 { |it, acc| $acc * ($it.a | into int) + ($it.b | into int) }
"#
)
);
@ -54,7 +54,7 @@ fn reduce_numbered_example() {
cwd: ".", pipeline(
r#"
echo one longest three bar
reduce -n { if ($it.item | str length) > ($acc.item | str length) {echo $it} {echo $acc}}
reduce -n { |it, acc| if ($it | str length) > ($acc | str length) {echo $it} else {echo $acc}}
| get index
"#
)
@ -69,7 +69,7 @@ fn reduce_numbered_integer_addition_example() {
cwd: ".", pipeline(
r#"
echo [1 2 3 4]
| reduce -n { $it.acc + $it.item }
| reduce -n { |it, acc| $acc + $it.item }
| get item
"#
)
@ -84,9 +84,9 @@ fn folding_with_tables() {
cwd: ".", pipeline(
r#"
echo [10 20 30 40]
| reduce -f [] {
with-env [value $it.item] {
echo $it.acc | append (10 * ($env.value | into int))
| reduce -f [] { |it, acc|
with-env [value $it] {
echo $acc | append (10 * ($env.value | into int))
}
}
| math sum
@ -102,7 +102,7 @@ fn error_reduce_fold_type_mismatch() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo a b c | reduce -f 0 { $it.acc + $it.item }
echo a b c | reduce -f 0 { |it, acc| $acc + $it }
"#
)
);
@ -115,7 +115,7 @@ fn error_reduce_empty() {
let actual = nu!(
cwd: ".", pipeline(
r#"
reduce { $it.$acc + $it.item }
reduce { |it, acc| $acc + $it }
"#
)
);

View File

@ -135,7 +135,7 @@ mod columns {
transpose bit --ignore-titles
| get bit
| reverse
| each --numbered {
| each --numbered { |it|
$it.item * (2 ** $it.index)
}
| math sum
@ -155,7 +155,7 @@ mod columns {
pipeline(
r#"
split chars
| each { $it | into int }
| each { |it| $it | into int }
| rotate --ccw
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8
"#

View File

@ -44,7 +44,7 @@ fn sum_one_to_four() {
let actual = nu!(
cwd: ".", pipeline(
r#"
1..4 | each { $it } | into string | str collect "+" | math eval
1..4 | each { |it| $it } | into string | str collect "+" | math eval
"#
)
);