Simplify expressions (#3389)

* WIP: experiment with simpler expressions

* fix simple invoke

* update tests

* fix a few tests

* Make paren parsing more robust

* fix external args

* Remove old invocation

* Update tests

* Update tests
This commit is contained in:
JT
2021-05-12 13:01:48 +12:00
committed by GitHub
parent c80a9585b0
commit 25a8caa9b0
38 changed files with 181 additions and 364 deletions

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 + $( math eval `{{$acc}}^1.05` )}
| reduce -f 20 { $it + ( math eval `{{$acc}}^1.05` )}
| str from -d 1
"#
)
@ -21,7 +21,7 @@ fn reduce_table_column() {
r#"
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
| from json
| reduce -f 20 { = $it.total + $( math eval `{{$acc}}^1.05` )}
| reduce -f 20 { $it.total + ( math eval `{{$acc}}^1.05` )}
| str from -d 1
"#
)
@ -38,7 +38,7 @@ fn reduce_rows_example() {
echo a,b 1,2 3,4
| split column ,
| headers
| reduce -f 1.6 { = $acc * $(echo $it.a | str to-int) + $(echo $it.b | str to-int) }
| reduce -f 1.6 { $acc * ($it.a | str to-int) + ($it.b | str to-int) }
"#
)
);
@ -52,7 +52,7 @@ fn reduce_numbered_example() {
cwd: ".", pipeline(
r#"
echo one longest three bar
| reduce -n { if $(echo $it.item | str length) > $(echo $acc.item | str length) {echo $it} {echo $acc}}
| reduce -n { if ($it.item | str length) > ($acc.item | str length) {echo $it} {echo $acc}}
| get index
"#
)
@ -67,7 +67,7 @@ fn reduce_numbered_integer_addition_example() {
cwd: ".", pipeline(
r#"
echo [1 2 3 4]
| reduce -n {= $acc.item + $it.item }
| reduce -n { $acc.item + $it.item }
| get item
"#
)
@ -84,7 +84,7 @@ fn folding_with_tables() {
echo [10 20 30 40]
| reduce -f [] {
with-env [value $it] {
echo $acc | append $(= 10 * $(= $nu.env.value | str to-int))
echo $acc | append (10 * ($nu.env.value | str to-int))
}
}
| math sum
@ -100,7 +100,7 @@ fn error_reduce_fold_type_mismatch() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo a b c | reduce -f 0 { = $acc + $it }
echo a b c | reduce -f 0 { $acc + $it }
"#
)
);
@ -113,7 +113,7 @@ fn error_reduce_empty() {
let actual = nu!(
cwd: ".", pipeline(
r#"
reduce { = $acc + $it }
reduce { $acc + $it }
"#
)
);