Allow iteration blocks to have an optional extra index parameter (alternative to -n flags) (#6994)

Alters `all`, `any`, `each while`, `each`, `insert`, `par-each`, `reduce`, `update`, `upsert` and `where`,
so that their blocks take an optional parameter containing the index.
This commit is contained in:
Leon
2022-11-21 23:35:11 +10:00
committed by GitHub
parent 899383c30c
commit 833825ae9a
19 changed files with 486 additions and 74 deletions

View File

@ -14,6 +14,15 @@ fn sets_the_column() {
assert_eq!(actual.out, "0.7.0");
}
#[test]
fn doesnt_convert_record_to_table() {
let actual = nu!(
cwd: ".", r#"{a:1} | upsert a 2 | to nuon"#
);
assert_eq!(actual.out, "{a: 2}");
}
#[cfg(features = "inc")]
#[test]
fn sets_the_column_from_a_block_run_output() {
@ -58,3 +67,23 @@ fn sets_the_column_from_a_subexpression() {
assert_eq!(actual.out, "true");
}
#[test]
fn uses_optional_index_argument_inserting() {
let actual = nu!(
cwd: ".", pipeline(
r#"[[a]; [7] [6]] | upsert b {|el ind| $ind + 1 + $el.a } | to nuon"#
));
assert_eq!(actual.out, "[[a, b]; [7, 8], [6, 8]]");
}
#[test]
fn uses_optional_index_argument_updating() {
let actual = nu!(
cwd: ".", pipeline(
r#"[[a]; [7] [6]] | upsert a {|el ind| $ind + 1 + $el.a } | to nuon"#
));
assert_eq!(actual.out, "[[a]; [8], [8]]");
}