mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
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:
@ -10,7 +10,7 @@ fn filesystem_change_from_current_directory_using_relative_path() {
|
||||
cwd: dirs.root(),
|
||||
r#"
|
||||
cd cd_test_1
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -25,7 +25,7 @@ fn filesystem_change_from_current_directory_using_absolute_path() {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd "{}"
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#,
|
||||
dirs.formats()
|
||||
);
|
||||
@ -44,7 +44,7 @@ fn filesystem_switch_back_to_previous_working_directory() {
|
||||
r#"
|
||||
cd {}
|
||||
cd -
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#,
|
||||
dirs.test()
|
||||
);
|
||||
@ -62,7 +62,7 @@ fn filesytem_change_from_current_directory_using_relative_path_and_dash() {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd odin/-
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -80,7 +80,7 @@ fn filesystem_change_current_directory_to_parent_directory() {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd ..
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -97,7 +97,7 @@ fn filesystem_change_current_directory_to_two_parents_up_using_multiple_dots() {
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
cd ...
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -116,7 +116,7 @@ fn filesystem_change_current_directory_to_parent_directory_after_delete_cwd() {
|
||||
rm {}/foo/bar
|
||||
echo ","
|
||||
cd ..
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#,
|
||||
dirs.test()
|
||||
);
|
||||
@ -135,7 +135,7 @@ fn filesystem_change_to_home_directory() {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd ~
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -152,7 +152,7 @@ fn filesystem_change_to_a_directory_containing_spaces() {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
cd "robalino turner katz"
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
@ -219,7 +219,7 @@ fn filesystem_change_directory_to_symlink_relative() {
|
||||
cwd: dirs.test().join("boo"),
|
||||
r#"
|
||||
cd ../foo_link
|
||||
echo $(pwd)
|
||||
echo (pwd)
|
||||
"#
|
||||
);
|
||||
|
||||
|
@ -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 { echo $it } | to json
|
||||
echo [1 2 3 4 5 6] | each group 3 { $it } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
@ -29,7 +29,7 @@ fn each_window() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3 4] | each window 3 { echo $it } | to json
|
||||
echo [1 2 3 4] | each window 3 { $it } | to json
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -6,9 +6,9 @@ fn reports_emptiness() {
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[are_empty];
|
||||
[$(= [[check]; [[]] ])]
|
||||
[$(= [[check]; [""] ])]
|
||||
[$(= [[check]; [$(wrap)] ])]
|
||||
[([[check]; [[]] ])]
|
||||
[([[check]; [""] ])]
|
||||
[([[check]; [(wrap)] ])]
|
||||
]
|
||||
| get are_empty
|
||||
| empty? check
|
||||
@ -32,7 +32,7 @@ fn sets_block_run_value_for_an_empty_column() {
|
||||
[ Jason, Gedge, 10/11/2013, 1 ]
|
||||
[ Yehuda, Katz, 10/11/2013, '' ]
|
||||
]
|
||||
| empty? likes { = 1 }
|
||||
| empty? likes { 1 }
|
||||
| get likes
|
||||
| math sum
|
||||
"#
|
||||
@ -50,9 +50,9 @@ fn sets_block_run_value_for_many_empty_columns() {
|
||||
[ boost check ];
|
||||
[ 1, [] ]
|
||||
[ 1, "" ]
|
||||
[ 1, $(wrap) ]
|
||||
[ 1, (wrap) ]
|
||||
]
|
||||
| empty? boost check { = 1 }
|
||||
| empty? boost check { 1 }
|
||||
| get boost check
|
||||
| math sum
|
||||
"#
|
||||
@ -73,9 +73,9 @@ fn passing_a_block_will_set_contents_on_empty_cells_and_leave_non_empty_ones_unt
|
||||
[ Arepas, "", "" ]
|
||||
[ Jorge, 30, 3000 ]
|
||||
]
|
||||
| empty? LVL { = 9 }
|
||||
| empty? LVL { 9 }
|
||||
| empty? HP {
|
||||
= $it.LVL * 1000
|
||||
$it.LVL * 1000
|
||||
}
|
||||
| math sum
|
||||
| get HP
|
||||
|
@ -7,8 +7,8 @@ fn flatten_nested_tables_with_columns() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[origin, people]; [Ecuador, $(= 'Andres' | wrap name)]]
|
||||
[[origin, people]; [Nu, $(= 'nuno' | wrap name)]]
|
||||
echo [[origin, people]; [Ecuador, ('Andres' | wrap name)]]
|
||||
[[origin, people]; [Nu, ('nuno' | wrap name)]]
|
||||
| flatten
|
||||
| get name
|
||||
| str collect ','
|
||||
@ -23,8 +23,8 @@ fn flatten_nested_tables_that_have_many_columns() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[origin, people]; [Ecuador, $(echo [[name, meal]; ['Andres', 'arepa']])]]
|
||||
[[origin, people]; [USA, $(echo [[name, meal]; ['Katz', 'nurepa']])]]
|
||||
echo [[origin, people]; [Ecuador, (echo [[name, meal]; ['Andres', 'arepa']])]]
|
||||
[[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]]
|
||||
| flatten
|
||||
| get meal
|
||||
| str collect ','
|
||||
|
@ -35,7 +35,7 @@ fn sets_the_column_from_an_invocation() {
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap content
|
||||
| insert content $(open --raw cargo_sample.toml | lines | first 5)
|
||||
| insert content (open --raw cargo_sample.toml | lines | first 5)
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
|
@ -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 / 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 / 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 / 1024 }
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -12,7 +12,7 @@ fn one_arg() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1
|
||||
1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -24,7 +24,7 @@ fn add() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 1
|
||||
1 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -36,7 +36,7 @@ fn add_compound() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 + 2
|
||||
1 + 2 + 2
|
||||
"#
|
||||
));
|
||||
|
||||
@ -48,7 +48,7 @@ fn precedence_of_operators() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 * 2
|
||||
1 + 2 * 2
|
||||
"#
|
||||
));
|
||||
|
||||
@ -60,7 +60,7 @@ fn precedence_of_operators2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 + 2 * 2 + 1
|
||||
1 + 2 * 2 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -72,7 +72,7 @@ fn division_of_ints() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 / 2
|
||||
4 / 2
|
||||
"#
|
||||
));
|
||||
|
||||
@ -84,7 +84,7 @@ fn division_of_ints2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 4
|
||||
1 / 4
|
||||
"#
|
||||
));
|
||||
|
||||
@ -96,7 +96,7 @@ fn error_zero_division_int_int() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 0
|
||||
1 / 0
|
||||
"#
|
||||
));
|
||||
|
||||
@ -108,7 +108,7 @@ fn error_zero_division_decimal_int() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1.0 / 0
|
||||
1.0 / 0
|
||||
"#
|
||||
));
|
||||
|
||||
@ -120,7 +120,7 @@ fn error_zero_division_int_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1 / 0.0
|
||||
1 / 0.0
|
||||
"#
|
||||
));
|
||||
|
||||
@ -132,7 +132,7 @@ fn error_zero_division_decimal_decimal() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1.0 / 0.0
|
||||
1.0 / 0.0
|
||||
"#
|
||||
));
|
||||
|
||||
@ -144,7 +144,7 @@ fn proper_precedence_history() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 2 / 2 / 2 + 1
|
||||
2 / 2 / 2 + 1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -156,7 +156,7 @@ fn parens_precedence() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 * (6 - 3)
|
||||
4 * (6 - 3)
|
||||
"#
|
||||
));
|
||||
|
||||
@ -168,7 +168,7 @@ fn modulo() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 9 mod 2
|
||||
9 mod 2
|
||||
"#
|
||||
));
|
||||
|
||||
@ -180,7 +180,7 @@ fn duration_math() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1wk + 1day
|
||||
1wk + 1day
|
||||
"#
|
||||
));
|
||||
|
||||
@ -192,7 +192,7 @@ fn duration_decimal_math() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 5.5day + 0.5day
|
||||
5.5day + 0.5day
|
||||
"#
|
||||
));
|
||||
|
||||
@ -204,7 +204,7 @@ fn duration_math_with_nanoseconds() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1wk + 10ns
|
||||
1wk + 10ns
|
||||
"#
|
||||
));
|
||||
|
||||
@ -216,7 +216,7 @@ fn duration_decimal_math_with_nanoseconds() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1.5wk + 10ns
|
||||
1.5wk + 10ns
|
||||
"#
|
||||
));
|
||||
|
||||
@ -228,7 +228,7 @@ fn duration_math_with_negative() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 1day - 1wk
|
||||
1day - 1wk
|
||||
"#
|
||||
));
|
||||
|
||||
@ -240,7 +240,7 @@ fn compound_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 > 3 && 2 > 1
|
||||
4 > 3 && 2 > 1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -252,7 +252,7 @@ fn compound_comparison2() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
= 4 < 3 || 2 > 1
|
||||
4 < 3 || 2 > 1
|
||||
"#
|
||||
));
|
||||
|
||||
@ -276,7 +276,7 @@ fn compound_where_paren() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where (a == 2 && b == 1) || b == 2 | to json
|
||||
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where ($it.a == 2 && $it.b == 1) || $it.b == 2 | to json
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -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 }
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
@ -136,7 +136,7 @@ mod columns {
|
||||
| get bit
|
||||
| reverse
|
||||
| each --numbered {
|
||||
= $it.item * (2 ** $it.index)
|
||||
$it.item * (2 ** $it.index)
|
||||
}
|
||||
| math sum
|
||||
"#,
|
||||
|
@ -50,7 +50,7 @@ fn sets_the_column_from_an_invocation() {
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
wrap content
|
||||
| update content $(open --raw cargo_sample.toml | lines | first 5)
|
||||
| update content (open --raw cargo_sample.toml | lines | first 5)
|
||||
| get content.1
|
||||
| str contains "nu"
|
||||
"#
|
||||
|
@ -86,7 +86,7 @@ fn md_combined() {
|
||||
};
|
||||
|
||||
title
|
||||
| append $(meals)
|
||||
| append (meals)
|
||||
| to md --per-element --pretty
|
||||
"#
|
||||
));
|
||||
|
Reference in New Issue
Block a user