forked from extern/nushell
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:
@ -14,6 +14,15 @@ fn insert_the_column() {
|
||||
assert_eq!(actual.out, "0.7.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doesnt_convert_record_to_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", r#"{a:1} | insert b 2 | to nuon"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "{a: 1, b: 2}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_the_column_conflict() {
|
||||
let actual = nu!(
|
||||
@ -76,3 +85,13 @@ fn insert_past_end_list() {
|
||||
|
||||
assert_eq!(actual.out, r#"[1,2,3,null,null,"abc"]"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uses_optional_index_argument() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"[[a]; [7] [6]] | insert b {|el ind| $ind + 1 + $el.a } | to nuon"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[a, b]; [7, 8], [6, 8]]");
|
||||
}
|
||||
|
Reference in New Issue
Block a user