mirror of
https://github.com/nushell/nushell.git
synced 2024-12-13 18:52:01 +01:00
56cdee1fd8
# 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.
35 lines
845 B
Rust
35 lines
845 B
Rust
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn adds_row_data_if_column_missing() {
|
|
let sample = r#"
|
|
{
|
|
"amigos": [
|
|
{"name": "Yehuda"},
|
|
{"name": "JT", "rusty_luck": 0},
|
|
{"name": "Andres", "rusty_luck": 0},
|
|
{"name":"GorbyPuff"}
|
|
]
|
|
}
|
|
"#;
|
|
|
|
let actual = nu!(pipeline(&format!(
|
|
"
|
|
{sample}
|
|
| get amigos
|
|
| default 1 rusty_luck
|
|
| where rusty_luck == 1
|
|
| length
|
|
"
|
|
)));
|
|
|
|
assert_eq!(actual.out, "2");
|
|
}
|
|
|
|
#[test]
|
|
fn default_after_empty_filter() {
|
|
let actual = nu!("[a b] | where $it == 'c' | get -i 0 | default 'd'");
|
|
|
|
assert_eq!(actual.out, "d");
|
|
}
|