mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Refactor first
and last
(#12478)
# Description - Refactors `first` and `last` using `Vec::truncate` and `Vec::drain`. - `std::mem::take` was also used to eliminate a few `Value` clones. - The `NeedsPositiveValue` error now uses the span of the `rows` argument instead of the call head span. - `last` now errors on an empty stream to match `first` which does error. - Made metadata preservation more consistent. # User-Facing Changes Breaking change: `last` now errors on an empty stream to match `first` which does error.
This commit is contained in:
@ -28,7 +28,7 @@ fn adds_row_data_if_column_missing() {
|
||||
|
||||
#[test]
|
||||
fn default_after_empty_filter() {
|
||||
let actual = nu!("[a b] | where $it == 'c' | last | default 'd'");
|
||||
let actual = nu!("[a b] | where $it == 'c' | get -i 0 | default 'd'");
|
||||
|
||||
assert_eq!(actual.out, "d");
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ fn gets_first_row_when_no_amount_given() {
|
||||
fn gets_first_row_as_list_when_amount_given() {
|
||||
let actual = nu!("[1, 2, 3] | first 1 | describe");
|
||||
|
||||
assert_eq!(actual.out, "list<int> (stream)");
|
||||
assert_eq!(actual.out, "list<int>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -51,7 +51,7 @@ fn requests_more_rows_than_table_has() {
|
||||
fn gets_last_row_as_list_when_amount_given() {
|
||||
let actual = nu!("[1, 2, 3] | last 1 | describe");
|
||||
|
||||
assert_eq!(actual.out, "list<int> (stream)");
|
||||
assert_eq!(actual.out, "list<int>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user