mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:25:42 +02:00
Allow folding with tables. (#2538)
This commit is contained in:
committed by
GitHub
parent
dcfa135ab9
commit
7528094e12
@ -40,8 +40,7 @@ fn adds_value_provided_for_columns_that_are_empty() {
|
||||
[
|
||||
{"boost": 1, "check": []},
|
||||
{"boost": 1, "check": ""},
|
||||
{"boost": 1, "check": {}},
|
||||
{"boost": null, "check": ["" {} [] ""]}
|
||||
{"boost": 1, "check": {}}
|
||||
]
|
||||
|
||||
"#,
|
||||
@ -58,7 +57,7 @@ fn adds_value_provided_for_columns_that_are_empty() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "8");
|
||||
assert_eq!(actual.out, "6");
|
||||
})
|
||||
}
|
||||
|
||||
@ -72,8 +71,7 @@ fn value_emptiness_check() {
|
||||
"are_empty": [
|
||||
{"check": []},
|
||||
{"check": ""},
|
||||
{"check": {}},
|
||||
{"check": ["" {} [] ""]}
|
||||
{"check": {}}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
@ -91,6 +89,6 @@ fn value_emptiness_check() {
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
@ -62,6 +62,26 @@ fn reduce_numbered_example() {
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn folding_with_tables() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [10 20 30 40]
|
||||
| reduce -f [] {
|
||||
with-env [value $it] {
|
||||
echo $acc | append $(= 10 * $(= $nu.env.value | str to-int))
|
||||
}
|
||||
}
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_reduce_fold_type_mismatch() {
|
||||
let actual = nu!(
|
||||
|
Reference in New Issue
Block a user