last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623)

Closes https://github.com/nushell/nushell/issues/6941
This commit is contained in:
WindSoilder
2022-12-31 19:35:12 +08:00
committed by GitHub
parent 81a7d17b33
commit e9cc417fd5
29 changed files with 159 additions and 25 deletions

View File

@ -13,3 +13,10 @@ fn adds_a_row_to_the_end() {
assert_eq!(actual.out, "pollo loco");
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | append 3"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -65,7 +65,7 @@ fn rows() {
#[test]
fn more_rows_than_table_has() {
let actual = nu!(cwd: ".", "date | drop 50 | length");
let actual = nu!(cwd: ".", "[date] | drop 50 | length");
assert_eq!(actual.out, "0");
}
@ -90,3 +90,10 @@ fn nth_missing_first_argument() {
assert!(actual.err.contains("int or range"));
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | drop 50"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -58,7 +58,7 @@ fn requests_more_rows_than_table_has() {
let actual = nu!(
cwd: ".", pipeline(
r#"
date | last 50 | length
[date] | last 50 | length
"#
));
@ -91,3 +91,10 @@ fn last_errors_on_negative_index() {
assert!(actual.err.contains("use a positive value"));
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | last"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -27,3 +27,10 @@ fn adds_a_row_to_the_beginning() {
assert_eq!(actual.out, "pollo loco");
})
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | prepend 4"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -1,4 +1,4 @@
use nu_test_support::nu;
use nu_test_support::{nu, pipeline};
#[test]
fn can_get_reverse_first() {
@ -9,3 +9,10 @@ fn can_get_reverse_first() {
assert_eq!(actual.out, "utf16.ini");
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | reverse"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -5,12 +5,19 @@ fn binary_skip() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open sample_data.ods --raw |
skip 2 |
take 2 |
open sample_data.ods --raw |
skip 2 |
take 2 |
into int
"#
));
assert_eq!(actual.out, "772");
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip 2"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -49,3 +49,10 @@ fn condition_is_met() {
assert_eq!(actual.out, "6");
})
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip until {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -49,3 +49,10 @@ fn condition_is_met() {
assert_eq!(actual.out, "6");
})
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip while {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -119,3 +119,10 @@ fn no_column_specified_fails() {
assert!(actual.err.contains("missing parameter"));
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | sort-by"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -123,7 +123,7 @@ fn converts_to_int() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
echo '{number_as_string: "1"}'
echo '[{number_as_string: "1"}]'
| from json
| into int number_as_string
| rename number

View File

@ -51,7 +51,7 @@ fn fails_on_string() {
"#
));
assert!(actual.err.contains("pipeline_mismatch"));
assert!(actual.err.contains("only_supports_this_input_type"));
}
#[test]

View File

@ -50,3 +50,10 @@ fn condition_is_met() {
assert_eq!(actual.out, "8");
})
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | take until {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -49,3 +49,10 @@ fn condition_is_met() {
assert_eq!(actual.out, "4");
})
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | take while {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
}

View File

@ -188,3 +188,10 @@ fn contains_operator() {
assert_eq!(actual.out, "2");
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline(r#"{"name": "foo", "size": 3} | where name == "foo""#));
assert!(actual.err.contains("only_supports_this_input_type"));
}