2023-11-29 23:21:34 +01:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::playground::Playground;
|
2020-05-07 13:03:43 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-12-15 17:15:06 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn splits() {
|
2023-11-29 23:21:34 +01:00
|
|
|
let sample = r#"
|
|
|
|
[[first_name, last_name, rusty_at, type];
|
|
|
|
[Andrés, Robalino, "10/11/2013", A],
|
|
|
|
[JT, Turner, "10/12/2013", B],
|
|
|
|
[Yehuda, Katz, "10/11/2013", A]]
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let actual = nu!(pipeline(&format!(
|
|
|
|
r#"
|
|
|
|
{sample}
|
2019-12-15 17:15:06 +01:00
|
|
|
| group-by rusty_at
|
|
|
|
| split-by type
|
|
|
|
| get A."10/11/2013"
|
2021-03-13 22:46:40 +01:00
|
|
|
| length
|
2019-12-15 17:15:06 +01:00
|
|
|
"#
|
2023-11-29 23:21:34 +01:00
|
|
|
)));
|
2019-12-15 17:15:06 +01:00
|
|
|
|
2023-11-29 23:21:34 +01:00
|
|
|
assert_eq!(actual.out, "2");
|
2019-12-15 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-11-07 16:27:10 +01:00
|
|
|
fn errors_if_no_input() {
|
|
|
|
Playground::setup("split_by_no_input", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(cwd: dirs.test(), pipeline("split-by type"));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("no input value was piped in"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn errors_if_non_record_input() {
|
2019-12-15 17:15:06 +01:00
|
|
|
Playground::setup("split_by_test_2", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[
|
2019-12-15 17:15:06 +01:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
|
|
|
]);
|
|
|
|
|
2023-11-07 16:27:10 +01:00
|
|
|
let input_mismatch = nu!(cwd: dirs.test(), pipeline("5 | split-by type"));
|
|
|
|
|
|
|
|
assert!(input_mismatch.err.contains("doesn't support int input"));
|
|
|
|
|
|
|
|
let only_supports = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| split-by type
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
));
|
|
|
|
|
2023-11-07 16:27:10 +01:00
|
|
|
assert!(only_supports
|
|
|
|
.err
|
|
|
|
.contains("only Record input data is supported"));
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|