mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 11:29:06 +02:00
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 sets_the_column() {
|
||||
assert_eq!(actual.out, "0.7.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doesnt_convert_record_to_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", r#"{a:1} | update a 2 | to nuon"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "{a: 2}");
|
||||
}
|
||||
|
||||
#[cfg(features = "inc")]
|
||||
#[test]
|
||||
fn sets_the_column_from_a_block_run_output() {
|
||||
@ -105,3 +114,13 @@ fn update_nonexistent_column() {
|
||||
|
||||
assert!(actual.err.contains("cannot find column 'b'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uses_optional_index_argument() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"[[a]; [7] [6]] | update a {|el ind| $ind + 1 + $el.a } | to nuon"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[[a]; [8], [8]]");
|
||||
}
|
||||
|
Reference in New Issue
Block a user