nushell/crates/nu-protocol/src/value
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
..
custom_value.rs Fix to json for SQLite databases (#8343) 2023-03-06 14:36:26 -08:00
from_value.rs Convert more ShellError variants to named fields (#11222) 2023-12-04 10:19:32 +01:00
from.rs Spanned Value step 1: span all value cases (#10042) 2023-08-25 08:48:05 +12:00
lazy_record.rs Create Record type (#10103) 2023-08-25 07:50:29 +12:00
mod.rs Fix replacement closures for update, insert, and upsert (#11258) 2023-12-09 15:22:45 -06:00
range.rs Auto format let-else block (#10214) 2023-09-04 19:42:31 +12:00
record.rs Add Record::truncate for trimming based on len (#11004) 2023-11-09 00:00:20 +01:00
stream.rs Move Value to helpers, separate span call (#10121) 2023-09-03 07:27:29 -07:00
unit.rs Convert Shellerror::GenericError to named fields (#11230) 2023-12-07 00:40:03 +01:00