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]
|
|
|
|
fn errors_if_no_table_given_as_input() {
|
|
|
|
Playground::setup("split_by_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
|
|
|
]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| split-by type
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-02-04 03:01:45 +01:00
|
|
|
assert!(actual.err.contains("requires a table"));
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|