diff --git a/crates/nu-command/src/filters/first.rs b/crates/nu-command/src/filters/first.rs index 340bf3a116..d7bdcf561b 100644 --- a/crates/nu-command/src/filters/first.rs +++ b/crates/nu-command/src/filters/first.rs @@ -146,7 +146,7 @@ fn first_helper( } } _ => { - if rows_desired == 1 { + if rows_desired == 1 && rows.is_none() { match input_peek.next() { Some(val) => Ok(val.into_pipeline_data()), None => Err(ShellError::AccessBeyondEndOfStream(head)), diff --git a/crates/nu-command/tests/commands/first.rs b/crates/nu-command/tests/commands/first.rs index 686fc6565e..8570fe7296 100644 --- a/crates/nu-command/tests/commands/first.rs +++ b/crates/nu-command/tests/commands/first.rs @@ -65,3 +65,17 @@ fn gets_first_row_when_no_amount_given() { assert_eq!(actual.out, "1"); }) } + +#[test] +fn gets_first_row_as_list_when_amount_given() { + let actual = nu!( + cwd: ".", pipeline( + r#" + [1, 2, 3] + | first 1 + | describe + "# + )); + + assert_eq!(actual.out, "list"); +} diff --git a/crates/nu-command/tests/commands/last.rs b/crates/nu-command/tests/commands/last.rs index ad8d29c9f9..ba0baae999 100644 --- a/crates/nu-command/tests/commands/last.rs +++ b/crates/nu-command/tests/commands/last.rs @@ -64,3 +64,17 @@ fn requests_more_rows_than_table_has() { assert_eq!(actual.out, "1"); } + +#[test] +fn gets_last_row_as_list_when_amount_given() { + let actual = nu!( + cwd: ".", pipeline( + r#" + [1, 2, 3] + | last 1 + | describe + "# + )); + + assert_eq!(actual.out, "list"); +} diff --git a/crates/nu-command/tests/commands/lines.rs b/crates/nu-command/tests/commands/lines.rs index 1e0283b7c5..c78bf43922 100644 --- a/crates/nu-command/tests/commands/lines.rs +++ b/crates/nu-command/tests/commands/lines.rs @@ -9,7 +9,7 @@ fn lines() { | lines | skip while $it != "[dependencies]" | skip 1 - | first 1 + | first | split column "=" | get column1.0 | str trim diff --git a/crates/nu-command/tests/commands/open.rs b/crates/nu-command/tests/commands/open.rs index c0a1fd0cf1..999f31a57d 100644 --- a/crates/nu-command/tests/commands/open.rs +++ b/crates/nu-command/tests/commands/open.rs @@ -154,7 +154,7 @@ fn parses_tsv() { cwd: "tests/fixtures/formats", pipeline( r#" open caco3_plastics.tsv - | first 1 + | first | get origin "# )); @@ -216,7 +216,7 @@ fn parses_arrow_ipc() { r#" open-df caco3_plastics.arrow | into nu - | first 1 + | first | get origin "# )); diff --git a/crates/nu-command/tests/commands/reverse.rs b/crates/nu-command/tests/commands/reverse.rs index e994aa4927..70f037d006 100644 --- a/crates/nu-command/tests/commands/reverse.rs +++ b/crates/nu-command/tests/commands/reverse.rs @@ -4,7 +4,7 @@ use nu_test_support::nu; fn can_get_reverse_first() { let actual = nu!( cwd: "tests/fixtures/formats", - "ls | sort-by name | reverse | first 1 | get name | str trim " + "ls | sort-by name | reverse | first | get name | str trim " ); assert_eq!(actual.out, "utf16.ini"); diff --git a/crates/nu-command/tests/commands/sort_by.rs b/crates/nu-command/tests/commands/sort_by.rs index 5b84c002fe..9d90eba183 100644 --- a/crates/nu-command/tests/commands/sort_by.rs +++ b/crates/nu-command/tests/commands/sort_by.rs @@ -12,7 +12,7 @@ fn by_column() { | split column "=" | sort-by column1 | skip 1 - | first 1 + | first | get column1 | str trim "# @@ -33,7 +33,7 @@ fn by_invalid_column() { | split column "=" | sort-by ColumnThatDoesNotExist | skip 1 - | first 1 + | first | get column1 | str trim "# @@ -69,7 +69,7 @@ fn sort_primitive_values() { | skip 1 | first 6 | sort-by - | first 1 + | first "# )); diff --git a/crates/nu-command/tests/commands/where_.rs b/crates/nu-command/tests/commands/where_.rs index bc1e0ca6ef..102d0d5d4a 100644 --- a/crates/nu-command/tests/commands/where_.rs +++ b/crates/nu-command/tests/commands/where_.rs @@ -6,7 +6,7 @@ use nu_test_support::pipeline; fn filters_by_unit_size_comparison() { let actual = nu!( cwd: "tests/fixtures/formats", - "ls | where size > 1kib | sort-by size | get name | first 1 | str trim" + "ls | where size > 1kib | sort-by size | get name | first | str trim" ); assert_eq!(actual.out, "cargo_sample.toml"); @@ -103,7 +103,7 @@ fn binary_operator_comparisons() { open sample.db | get ints | where z != 1 - | first 1 + | first | get z "# )); diff --git a/crates/nu-command/tests/format_conversions/csv.rs b/crates/nu-command/tests/format_conversions/csv.rs index 7f74e77190..2a8736175a 100644 --- a/crates/nu-command/tests/format_conversions/csv.rs +++ b/crates/nu-command/tests/format_conversions/csv.rs @@ -6,7 +6,7 @@ use nu_test_support::{nu, pipeline}; fn table_to_csv_text_and_from_csv_text_back_into_table() { let actual = nu!( cwd: "tests/fixtures/formats", - "open caco3_plastics.csv | to csv | from csv | first 1 | get origin " + "open caco3_plastics.csv | to csv | from csv | first | get origin " ); assert_eq!(actual.out, "SPAIN"); diff --git a/crates/nu-command/tests/format_conversions/tsv.rs b/crates/nu-command/tests/format_conversions/tsv.rs index ec6a98f9da..ef2dae6c75 100644 --- a/crates/nu-command/tests/format_conversions/tsv.rs +++ b/crates/nu-command/tests/format_conversions/tsv.rs @@ -6,7 +6,7 @@ use nu_test_support::{nu, pipeline}; fn table_to_tsv_text_and_from_tsv_text_back_into_table() { let actual = nu!( cwd: "tests/fixtures/formats", - "open caco3_plastics.tsv | to tsv | from tsv | first 1 | get origin" + "open caco3_plastics.tsv | to tsv | from tsv | first | get origin" ); assert_eq!(actual.out, "SPAIN"); @@ -16,7 +16,7 @@ fn table_to_tsv_text_and_from_tsv_text_back_into_table() { fn table_to_tsv_text_and_from_tsv_text_back_into_table_using_csv_separator() { let actual = nu!( cwd: "tests/fixtures/formats", - r"open caco3_plastics.tsv | to tsv | from csv --separator '\t' | first 1 | get origin" + r"open caco3_plastics.tsv | to tsv | from csv --separator '\t' | first | get origin" ); assert_eq!(actual.out, "SPAIN"); diff --git a/tests/plugins/core_inc.rs b/tests/plugins/core_inc.rs index 61f105fd57..6bfe79172e 100644 --- a/tests/plugins/core_inc.rs +++ b/tests/plugins/core_inc.rs @@ -7,7 +7,7 @@ fn chooses_highest_increment_if_given_more_than_one() { let actual = nu_with_plugins!( cwd: "tests/fixtures/formats", plugin: ("nu_plugin_inc"), - "open cargo_sample.toml | first 1 | inc package.version --major --minor | get package.version" + "open cargo_sample.toml | first | inc package.version --major --minor | get package.version" ); assert_eq!(actual.out, "1.0.0"); @@ -16,7 +16,7 @@ fn chooses_highest_increment_if_given_more_than_one() { cwd: "tests/fixtures/formats", plugin: ("nu_plugin_inc"), // Regardless of order of arguments - "open cargo_sample.toml | first 1 | inc package.version --minor --major | get package.version" + "open cargo_sample.toml | first | inc package.version --minor --major | get package.version" ); assert_eq!(actual.out, "1.0.0"); diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index ee894f562f..df73b96d16 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -232,7 +232,7 @@ mod stdin_evaluation { | nu --testbin chop | nu --testbin chop | lines - | first 1 ) + | first ) "# )) .out;