2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
|
|
|
|
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() {
|
|
|
|
Playground::setup("split_by_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.csv",
|
|
|
|
r#"
|
|
|
|
first_name,last_name,rusty_at,type
|
|
|
|
Andrés,Robalino,10/11/2013,A
|
2023-03-15 06:54:55 +01:00
|
|
|
JT,Turner,10/12/2013,B
|
2019-12-15 17:15:06 +01:00
|
|
|
Yehuda,Katz,10/11/2013,A
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.csv
|
|
|
|
| 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
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02: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| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|