2020-04-30 06:18:24 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rows() {
|
2023-11-29 23:21:34 +01:00
|
|
|
let sample = r#"
|
|
|
|
[[name, lucky_code];
|
|
|
|
[Andrés, 1],
|
|
|
|
[JT , 1],
|
|
|
|
[Jason , 2],
|
|
|
|
[Yehuda, 1]]"#;
|
|
|
|
|
|
|
|
let actual = nu!(pipeline(&format!(
|
|
|
|
r#"
|
|
|
|
{sample}
|
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
|
|
|
"#
|
2023-11-29 23:21:34 +01:00
|
|
|
)));
|
2020-04-30 06:18:24 +02:00
|
|
|
|
2023-11-29 23:21:34 +01: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() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!("[1 2 3] | take");
|
2022-11-09 11:32:16 +01:00
|
|
|
|
2023-07-17 18:43:51 +02:00
|
|
|
assert!(actual.err.contains("missing_positional"));
|
2022-11-09 11:32:16 +01:00
|
|
|
}
|
2022-11-14 00:15:27 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fails_on_string() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#""foo bar" | take 2"#);
|
2022-11-14 00:15:27 +01:00
|
|
|
|
2023-07-14 05:20:35 +02:00
|
|
|
assert!(actual.err.contains("command doesn't support"));
|
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() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
|
|
|
([0x[01 11]] | take 1 | get 0) == 0x[01 11]
|
|
|
|
"#);
|
2022-11-14 00:15:27 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
|
|
|
}
|