2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::Stub::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 groups() {
|
|
|
|
Playground::setup("group_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
|
|
|
|
Jonathan,Turner,10/12/2013,B
|
|
|
|
Yehuda,Katz,10/11/2013,A
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.csv
|
|
|
|
| group-by rusty_at
|
|
|
|
| get "10/11/2013"
|
|
|
|
| count
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "2");
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-14 15:45:19 +02:00
|
|
|
fn errors_if_given_unknown_column_name() {
|
2019-12-15 17:15:06 +01:00
|
|
|
Playground::setup("group_by_test_2", |dirs, sandbox| {
|
2020-07-14 15:45:19 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.json",
|
|
|
|
r#"
|
|
|
|
{
|
|
|
|
"nu": {
|
|
|
|
"committers": [
|
|
|
|
{"name": "Andrés N. Robalino"},
|
|
|
|
{"name": "Jonathan Turner"},
|
|
|
|
{"name": "Yehuda Katz"}
|
|
|
|
],
|
|
|
|
"releases": [
|
|
|
|
{"version": "0.2"}
|
|
|
|
{"version": "0.8"},
|
|
|
|
{"version": "0.9999999"}
|
|
|
|
],
|
|
|
|
"0xATYKARNU": [
|
|
|
|
["Th", "e", " "],
|
|
|
|
["BIG", " ", "UnO"],
|
|
|
|
["punto", "cero"]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.json
|
|
|
|
| group-by { get nu.releases.version }
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("requires a table with one value for grouping"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn errors_if_block_given_evaluates_more_than_one_row() {
|
|
|
|
Playground::setup("group_by_test_3", |dirs, sandbox| {
|
2019-12-15 17:15:06 +01:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.csv",
|
|
|
|
r#"
|
|
|
|
first_name,last_name,rusty_at,type
|
|
|
|
Andrés,Robalino,10/11/2013,A
|
|
|
|
Jonathan,Turner,10/12/2013,B
|
|
|
|
Yehuda,Katz,10/11/2013,A
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
let actual = nu!(
|
2019-12-15 17:15:06 +01:00
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.csv
|
|
|
|
| group-by ttype
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert!(actual.err.contains("Unknown column"));
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|