2020-04-30 06:18:24 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rows() {
|
2022-04-07 22:49:28 +02:00
|
|
|
Playground::setup("take_test_1", |dirs, sandbox| {
|
2020-04-30 06:18:24 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"caballeros.csv",
|
|
|
|
r#"
|
|
|
|
name,lucky_code
|
|
|
|
Andrés,1
|
|
|
|
Jonathan,1
|
|
|
|
Jason,2
|
|
|
|
Yehuda,1
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open caballeros.csv
|
2022-04-07 22:49:28 +02:00
|
|
|
| take 3
|
2020-04-30 06:18:24 +02:00
|
|
|
| get lucky_code
|
2020-06-19 04:02:01 +02:00
|
|
|
| math sum
|
2020-04-30 06:18:24 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "4");
|
2020-04-30 06:18:24 +02:00
|
|
|
})
|
|
|
|
}
|
2022-11-09 11:32:16 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rows_with_no_arguments_should_lead_to_error() {
|
|
|
|
Playground::setup("take_test_2", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"[1 2 3] | take"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("missing_positional"));
|
|
|
|
})
|
|
|
|
}
|
2022-11-14 00:15:27 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fails_on_string() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
"foo bar" | take 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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
2022-12-31 12:35:12 +01:00
|
|
|
assert!(actual.err.contains("only_supports_this_input_type"));
|
2022-11-14 00:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
// covers a situation where `take` used to behave strangely on list<binary> input
|
|
|
|
fn works_with_binary_list() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
([0x[01 11]] | take 1 | get 0) == 0x[01 11]
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
|
|
|
}
|