feat: apply the --numbered option to acc in reduce command. (#5575)

* feat: apply the `-n` option to acc

* feat: update tests and examples
This commit is contained in:
Jae-Heon Ji
2022-05-18 23:49:34 +09:00
committed by GitHub
parent 1e94793df5
commit 9c779b071b
2 changed files with 54 additions and 34 deletions

View File

@ -46,15 +46,13 @@ fn reduce_rows_example() {
assert_eq!(actual.out, "14.8");
}
// FIXME: jt: needs more work
#[ignore]
#[test]
fn reduce_numbered_example() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo one longest three bar
| reduce -n { |it, acc| if ($it.item | str length) > ($acc | str length) {echo $it.item} else {echo $acc}}
| reduce -n { |it, acc| if ($it.item | str length) > ($acc.item | str length) {echo $it} else {echo $acc}}
| get index
"#
)
@ -69,7 +67,7 @@ fn reduce_numbered_integer_addition_example() {
cwd: ".", pipeline(
r#"
echo [1 2 3 4]
| reduce -n { |it, acc| $acc + $it.item }
| reduce -n { |it, acc| $acc.item + $it.item }
"#
)
);