nushell/crates/nu-command
Ian Manske fa5d7babb9
Fix replacement closures for update, insert, and upsert (#11258)
# Description
This PR addresses #11204 which points out that using a closure for the
replacement value with `update`, `insert`, or `upsert` does not work for
lists.

# User-Facing Changes
- Replacement closures should now work for lists in `upsert`, `insert`,
and `update`. E.g., `[0] | update 0 {|i| $i + 1 }` now gives `[1]`
instead of an unhelpful error.
- `[1 2] | insert 4 20` no longer works. Before, this would give `[1, 2,
null, null, 20]`, but now it gives an error. This was done to match the
intended behavior in `Value::insert_data_at_cell_path`, whereas the
behavior before was probably unintentional. Following
`Value::insert_data_at_cell_path`, inserting at the end of a list is
also fine, so the valid indices for `upsert` and `insert` are
`0..=length` just like `Vec::insert` or list inserts in other languages.

# Tests + Formatting
Added tests for `upsert`, `insert`, and `update`:
- Replacement closures for lists, list streams, records, and tables
- Other list stream tests
2023-12-09 15:22:45 -06:00
..
src Fix replacement closures for update, insert, and upsert (#11258) 2023-12-09 15:22:45 -06:00
tests Fix replacement closures for update, insert, and upsert (#11258) 2023-12-09 15:22:45 -06:00
Cargo.toml Bump ureq from 2.8.0 to 2.9.1 (#11163) 2023-11-29 17:48:18 +00:00
LICENSE Fix rest of license year ranges (#8727) 2023-04-04 09:03:29 +12:00