forked from extern/nushell
Remove file I/O from tests that don't need it (#11182)
# Description This PR implements modifications to command tests that write unnecessary json and csv to disk then load it with open, by using nuon literals instead. - Fixes #7189 # User-Facing Changes None # Tests + Formatting This only affects existing tests, which still pass.
This commit is contained in:
parent
d08e254d16
commit
54d73748e4
@ -1,13 +1,8 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn discards_rows_where_given_column_is_empty() {
|
||||
Playground::setup("compact_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_amigos.json",
|
||||
r#"
|
||||
let sample_json = r#"
|
||||
{
|
||||
"amigos": [
|
||||
{"name": "Yehuda", "rusty_luck": 1},
|
||||
@ -16,35 +11,29 @@ fn discards_rows_where_given_column_is_empty() {
|
||||
{"name":"GorbyPuff"}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_amigos.json
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample_json}
|
||||
| get amigos
|
||||
| compact rusty_luck
|
||||
| length
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
});
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
#[test]
|
||||
fn discards_empty_rows_by_default() {
|
||||
Playground::setup("compact_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
let actual = nu!(pipeline(
|
||||
r#"
|
||||
echo "[1,2,3,14,null]"
|
||||
| from json
|
||||
| compact
|
||||
| length
|
||||
"#
|
||||
));
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
});
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
@ -1,13 +1,8 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn adds_row_data_if_column_missing() {
|
||||
Playground::setup("default_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_amigos.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
{
|
||||
"amigos": [
|
||||
{"name": "Yehuda"},
|
||||
@ -16,22 +11,19 @@ fn adds_row_data_if_column_missing() {
|
||||
{"name":"GorbyPuff"}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_amigos.json
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample}
|
||||
| get amigos
|
||||
| default 1 rusty_luck
|
||||
| where rusty_luck == 1
|
||||
| length
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
});
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,3 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
@ -43,10 +41,7 @@ fn flatten_nested_tables() {
|
||||
|
||||
#[test]
|
||||
fn flatten_row_column_explicitly() {
|
||||
Playground::setup("flatten_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
@ -61,24 +56,18 @@ fn flatten_row_column_explicitly() {
|
||||
}
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten people --all | where name == Andres | length"
|
||||
);
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"{sample} | flatten people --all | where name == Andres | length"
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
})
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_row_columns_having_same_column_names_flats_separately() {
|
||||
Playground::setup("flatten_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
@ -95,24 +84,18 @@ fn flatten_row_columns_having_same_column_names_flats_separately() {
|
||||
"city": [{"name": "Oregon"}, {"name": "Brooklin"}]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten --all | flatten people city | get city_name | length"
|
||||
);
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"{sample} | flatten --all | flatten people city | get city_name | length"
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_table_columns_explicitly() {
|
||||
Playground::setup("flatten_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
@ -129,24 +112,18 @@ fn flatten_table_columns_explicitly() {
|
||||
"city": ["Oregon", "Brooklin"]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten city --all | where people.name == Katz | length"
|
||||
);
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"{sample} | flatten city --all | where people.name == Katz | length",
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_more_than_one_column_that_are_subtables_not_supported() {
|
||||
Playground::setup("flatten_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
[
|
||||
{
|
||||
"people": {
|
||||
@ -165,15 +142,10 @@ fn flatten_more_than_one_column_that_are_subtables_not_supported() {
|
||||
"city": ["Oregon", "Brooklin"]
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten tags city --all"
|
||||
);
|
||||
let actual = nu!(pipeline(&format!("{sample} | flatten tags city --all")));
|
||||
|
||||
assert!(actual.err.contains("tried flattening"));
|
||||
assert!(actual.err.contains("but is flattened already"));
|
||||
})
|
||||
assert!(actual.err.contains("tried flattening"));
|
||||
assert!(actual.err.contains("but is flattened already"));
|
||||
}
|
||||
|
@ -1,40 +1,29 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[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
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
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!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| group-by rusty_at
|
||||
| get "10/11/2013"
|
||||
| length
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_given_unknown_column_name() {
|
||||
Playground::setup("group_by_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
{
|
||||
"nu": {
|
||||
"committers": [
|
||||
@ -54,46 +43,33 @@ fn errors_if_given_unknown_column_name() {
|
||||
]
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.json
|
||||
| group-by {|| get nu.releases.version }
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
'{sample}'
|
||||
| from json
|
||||
| group-by {{|| get nu.releases.version }}
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("requires a table with one value for grouping"));
|
||||
})
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("requires a table with one value for grouping"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_column_not_found() {
|
||||
Playground::setup("group_by_test_3", |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
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
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!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.csv
|
||||
| group-by ttype
|
||||
"
|
||||
));
|
||||
let actual = nu!(pipeline(&format!("{sample} | group-by ttype")));
|
||||
|
||||
assert!(actual.err.contains("did you mean 'type'"),);
|
||||
})
|
||||
assert!(actual.err.contains("did you mean 'type'"),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,95 +1,61 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
const SAMPLE_INPUT: &str = r#"
|
||||
[[first_name, last_name, rusty_at];
|
||||
[Andrés, Robalino, Ecuador],
|
||||
[JT, Turner, "Estados Unidos"],
|
||||
[Yehuda, Katz, "Estados Unidos"]]
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_column_given() {
|
||||
Playground::setup("histogram_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
JT,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{SAMPLE_INPUT}
|
||||
| histogram rusty_at countries --percentage-type relative
|
||||
| where rusty_at == "Ecuador"
|
||||
| get countries
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"**************************************************"
|
||||
);
|
||||
// 50%
|
||||
})
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"**************************************************"
|
||||
);
|
||||
// 50%
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_column_given_with_normalize_percentage() {
|
||||
Playground::setup("histogram_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
JT,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{SAMPLE_INPUT}
|
||||
| histogram rusty_at countries
|
||||
| where rusty_at == "Ecuador"
|
||||
| get countries
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "*********************************");
|
||||
// 33%
|
||||
})
|
||||
assert_eq!(actual.out, "*********************************");
|
||||
// 33%
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_values() {
|
||||
Playground::setup("histogram_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
JT,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{SAMPLE_INPUT}
|
||||
| get rusty_at
|
||||
| histogram
|
||||
| where value == "Estados Unidos"
|
||||
| get count
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,14 +1,9 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
Playground::setup("sum_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"meals.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
{
|
||||
meals: [
|
||||
{description: "1 large egg", calories: 90},
|
||||
@ -16,21 +11,18 @@ fn all() {
|
||||
{description: "1 tablespoon fish oil", calories: 108}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open meals.json
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| get meals
|
||||
| get calories
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "448");
|
||||
})
|
||||
assert_eq!(actual.out, "448");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,44 +1,27 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn row() {
|
||||
Playground::setup("merge_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
FileWithContentToBeTrimmed(
|
||||
"caballeros.csv",
|
||||
r#"
|
||||
name,country,luck
|
||||
Andrés,Ecuador,0
|
||||
JT,USA,0
|
||||
Jason,Canada,0
|
||||
Yehuda,USA,0
|
||||
"#,
|
||||
),
|
||||
FileWithContentToBeTrimmed(
|
||||
"new_caballeros.csv",
|
||||
r#"
|
||||
name,country,luck
|
||||
Andrés Robalino,Guayaquil Ecuador,1
|
||||
JT Turner,New Zealand,1
|
||||
"#,
|
||||
),
|
||||
]);
|
||||
let left_sample = r#"[[name, country, luck];
|
||||
[Andrés, Ecuador, 0],
|
||||
[JT, USA, 0],
|
||||
[Jason, Canada, 0],
|
||||
[Yehuda, USA, 0]]"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open caballeros.csv
|
||||
| merge (open new_caballeros.csv)
|
||||
| where country in ["Guayaquil Ecuador" "New Zealand"]
|
||||
| get luck
|
||||
| math sum
|
||||
let right_sample = r#"[[name, country, luck];
|
||||
["Andrés Robalino", "Guayaquil Ecuador", 1],
|
||||
["JT Turner", "New Zealand", 1]]"#;
|
||||
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#" ({left_sample})
|
||||
| merge ({right_sample})
|
||||
| where country in ["Guayaquil Ecuador" "New Zealand"]
|
||||
| get luck
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
});
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,130 +1,102 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn moves_a_column_before() {
|
||||
Playground::setup("move_column_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,column3,...,column98,column99,column100
|
||||
-------,-------,-------,---,--------, A ,---------
|
||||
-------,-------,-------,---,--------, N ,---------
|
||||
-------,-------,-------,---,--------, D ,---------
|
||||
-------,-------,-------,---,--------, R ,---------
|
||||
-------,-------,-------,---,--------, E ,---------
|
||||
-------,-------,-------,---,--------, S ,---------
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[column1 column2 column3 ... column98 column99 column100];
|
||||
[------- ------- ------- --- -------- " A " ---------],
|
||||
[------- ------- ------- --- -------- " N " ---------],
|
||||
[------- ------- ------- --- -------- " D " ---------],
|
||||
[------- ------- ------- --- -------- " R " ---------],
|
||||
[------- ------- ------- --- -------- " E " ---------],
|
||||
[------- ------- ------- --- -------- " S " ---------]]"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| move column99 --before column1
|
||||
| rename chars
|
||||
| get chars
|
||||
| str trim
|
||||
| str join
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.out.contains("ANDRES"));
|
||||
})
|
||||
assert!(actual.out.contains("ANDRES"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_columns_before() {
|
||||
Playground::setup("move_column_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,column3,...,column98,column99,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, T ,---------
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[column1 column2 column3 ... column98 column99 column100];
|
||||
[------- ------- " A " --- -------- " N " ---------]
|
||||
[------- ------- " D " --- -------- " R " ---------]
|
||||
[------- ------- " E " --- -------- " S " ---------]
|
||||
[------- ------- " : " --- -------- " : " ---------]
|
||||
[------- ------- " J " --- -------- " T " ---------]]"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| move column99 column3 --before column2
|
||||
| rename _ chars_1 chars_2
|
||||
| select chars_2 chars_1
|
||||
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
|
||||
| upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}}
|
||||
| get new_col
|
||||
| str join
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.out.contains("ANDRES::JT"));
|
||||
})
|
||||
assert!(actual.out.contains("ANDRES::JT"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_a_column_after() {
|
||||
Playground::setup("move_column_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,letters,...,column98,and_more,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, T ,---------
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[column1 column2 letters ... column98 and_more column100];
|
||||
[------- ------- " A " --- -------- " N " ---------]
|
||||
[------- ------- " D " --- -------- " R " ---------]
|
||||
[------- ------- " E " --- -------- " S " ---------]
|
||||
[------- ------- " : " --- -------- " : " ---------]
|
||||
[------- ------- " J " --- -------- " T " ---------]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| move letters --after and_more
|
||||
| move letters and_more --before column2
|
||||
| rename _ chars_1 chars_2
|
||||
| select chars_1 chars_2
|
||||
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
|
||||
| upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}}
|
||||
| get new_col
|
||||
| str join
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.out.contains("ANDRES::JT"));
|
||||
})
|
||||
assert!(actual.out.contains("ANDRES::JT"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moves_columns_after() {
|
||||
Playground::setup("move_column_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.csv",
|
||||
r#"
|
||||
column1,column2,letters,...,column98,and_more,column100
|
||||
-------,-------, A ,---,--------, N ,---------
|
||||
-------,-------, D ,---,--------, R ,---------
|
||||
-------,-------, E ,---,--------, S ,---------
|
||||
-------,-------, : ,---,--------, : ,---------
|
||||
-------,-------, J ,---,--------, T ,---------
|
||||
"#,
|
||||
)]);
|
||||
let content = r#"
|
||||
[[column1 column2 letters ... column98 and_more column100];
|
||||
[------- ------- " A " --- -------- " N " ---------]
|
||||
[------- ------- " D " --- -------- " R " ---------]
|
||||
[------- ------- " E " --- -------- " S " ---------]
|
||||
[------- ------- " : " --- -------- " : " ---------]
|
||||
[------- ------- " J " --- -------- " T " ---------]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{content}
|
||||
| move letters and_more --after column1
|
||||
| columns
|
||||
| select 1 2
|
||||
| str join
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.out.contains("lettersand_more"));
|
||||
})
|
||||
assert!(actual.out.contains("lettersand_more"));
|
||||
}
|
||||
|
@ -1,116 +1,85 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn changes_the_column_name() {
|
||||
Playground::setup("rename_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
JT Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Andrés N. Robalino"],
|
||||
["JT Turner"],
|
||||
["Yehuda Katz"],
|
||||
["Jason Gedge"]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
let actual = nu!(pipeline(&format!(
|
||||
" {sample}
|
||||
| wrap name
|
||||
| rename mosqueteros
|
||||
| get mosqueteros
|
||||
| length
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_remaining_original_names_given_less_new_names_than_total_original_names() {
|
||||
Playground::setup("rename_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
JT Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Andrés N. Robalino"],
|
||||
["JT Turner"],
|
||||
["Yehuda Katz"],
|
||||
["Jason Gedge"]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| wrap name
|
||||
| default "arepa!" hit
|
||||
| rename mosqueteros
|
||||
| get hit
|
||||
| length
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_no_columns_present() {
|
||||
Playground::setup("rename_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
JT Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Andrés N. Robalino"],
|
||||
["JT Turner"],
|
||||
["Yehuda Katz"],
|
||||
["Jason Gedge"]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample}
|
||||
| rename mosqueteros
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.err.contains("command doesn't support"));
|
||||
})
|
||||
assert!(actual.err.contains("command doesn't support"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_columns_param_is_empty() {
|
||||
Playground::setup("rename_test_4", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_cuatro_mosqueteros.txt",
|
||||
r#"
|
||||
Andrés N. Robalino
|
||||
JT Turner
|
||||
Yehuda Katz
|
||||
Jason Gedge
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Andrés N. Robalino"],
|
||||
["JT Turner"],
|
||||
["Yehuda Katz"],
|
||||
["Jason Gedge"]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.txt
|
||||
| lines
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| wrap name
|
||||
| default "arepa!" hit
|
||||
| rename --column {}
|
||||
| rename --column {{}}
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual.err.contains("The column info cannot be empty"));
|
||||
})
|
||||
assert!(actual.err.contains("The column info cannot be empty"));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
@ -24,10 +24,7 @@ fn regular_columns() {
|
||||
|
||||
#[test]
|
||||
fn complex_nested_columns() {
|
||||
Playground::setup("select_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
{
|
||||
"nu": {
|
||||
"committers": [
|
||||
@ -47,22 +44,19 @@ fn complex_nested_columns() {
|
||||
]
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.json
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| select nu."0xATYKARNU" nu.committers.name nu.releases.version
|
||||
| get nu_releases_version
|
||||
| where $it > "0.8"
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "0.9999999");
|
||||
})
|
||||
assert_eq!(actual.out, "0.9999999");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,53 +1,38 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip_until_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020
|
||||
Yellow Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,1
|
||||
Blue Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,2
|
||||
Red Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,3
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"];
|
||||
["Yellow Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 1],
|
||||
[JT, 0, 0, 1],
|
||||
[Jason, 0, 0, 1],
|
||||
[Yehuda, 0, 0, 1],
|
||||
["Blue Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 2],
|
||||
[JT, 0, 0, 2],
|
||||
[Jason, 0, 0, 2],
|
||||
[Yehuda, 0, 0, 2],
|
||||
["Red Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 1],
|
||||
[JT, 0, 0, 1],
|
||||
[Jason, 0, 0, 1],
|
||||
[Yehuda, 0, 0, 3]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw ./caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| str trim
|
||||
| str join (char nl)
|
||||
| from csv
|
||||
| skip until {|row| $row."Chicken Collection" == "Red Chickens" }
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| skip until {{|row| $row."Chicken Collection" == "Red Chickens" }}
|
||||
| skip 1
|
||||
| into int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
})
|
||||
assert_eq!(actual.out, "6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,53 +1,38 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip_while_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020
|
||||
Yellow Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,1
|
||||
Blue Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,2
|
||||
Red Chickens,,,
|
||||
Andrés,0,0,1
|
||||
JT,0,0,1
|
||||
Jason,0,0,1
|
||||
Yehuda,0,0,3
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"];
|
||||
["Yellow Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 1],
|
||||
[JT, 0, 0, 1],
|
||||
[Jason, 0, 0, 1],
|
||||
[Yehuda, 0, 0, 1],
|
||||
["Blue Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 2],
|
||||
[JT, 0, 0, 2],
|
||||
[Jason, 0, 0, 2],
|
||||
[Yehuda, 0, 0, 2],
|
||||
["Red Chickens", "", "", ""],
|
||||
[Andrés, 0, 0, 1],
|
||||
[JT, 0, 0, 1],
|
||||
[Jason, 0, 0, 1],
|
||||
[Yehuda, 0, 0, 3]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| str trim
|
||||
| str join (char nl)
|
||||
| from csv
|
||||
| skip while {|row| $row."Chicken Collection" != "Red Chickens" }
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| skip while {{|row| $row."Chicken Collection" != "Red Chickens" }}
|
||||
| skip 1
|
||||
| into int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "6");
|
||||
})
|
||||
assert_eq!(actual.out, "6");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,33 +1,27 @@
|
||||
use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed};
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[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
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
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!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| group-by rusty_at
|
||||
| split-by type
|
||||
| get A."10/11/2013"
|
||||
| length
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,33 +1,24 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn rows() {
|
||||
Playground::setup("take_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.csv",
|
||||
r#"
|
||||
name,lucky_code
|
||||
Andrés,1
|
||||
JT,1
|
||||
Jason,2
|
||||
Yehuda,1
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[name, lucky_code];
|
||||
[Andrés, 1],
|
||||
[JT , 1],
|
||||
[Jason , 2],
|
||||
[Yehuda, 1]]"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| take 3
|
||||
| get lucky_code
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,54 +1,39 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("take_until_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020
|
||||
Yellow Chickens,,,
|
||||
Andrés,1,1,1
|
||||
JT,1,1,1
|
||||
Jason,1,1,1
|
||||
Yehuda,1,1,1
|
||||
Blue Chickens,,,
|
||||
Andrés,1,1,2
|
||||
JT,1,1,2
|
||||
Jason,1,1,2
|
||||
Yehuda,1,1,2
|
||||
Red Chickens,,,
|
||||
Andrés,1,1,3
|
||||
JT,1,1,3
|
||||
Jason,1,1,3
|
||||
Yehuda,1,1,3
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"];
|
||||
["Yellow Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 1],
|
||||
[JT, 1, 1, 1],
|
||||
[Jason, 1, 1, 1],
|
||||
[Yehuda, 1, 1, 1],
|
||||
["Blue Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 2],
|
||||
[JT, 1, 1, 2],
|
||||
[Jason, 1, 1, 2],
|
||||
[Yehuda, 1, 1, 2],
|
||||
["Red Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 3],
|
||||
[JT, 1, 1, 3],
|
||||
[Jason, 1, 1, 3],
|
||||
[Yehuda, 1, 1, 3]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| str trim
|
||||
| str join (char nl)
|
||||
| from csv
|
||||
| skip while {|row| $row."Chicken Collection" != "Blue Chickens" }
|
||||
| take until {|row| $row."Chicken Collection" == "Red Chickens" }
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| skip while {{|row| $row."Chicken Collection" != "Blue Chickens" }}
|
||||
| take until {{|row| $row."Chicken Collection" == "Red Chickens" }}
|
||||
| skip 1
|
||||
| into int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "8");
|
||||
})
|
||||
assert_eq!(actual.out, "8");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,53 +1,38 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("take_while_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
CHICKEN SUMMARY report date: April 29th, 2020
|
||||
--------------------------------------------------------------------
|
||||
Chicken Collection,29/04/2020,30/04/2020,31/04/2020
|
||||
Yellow Chickens,,,
|
||||
Andrés,1,1,1
|
||||
JT,1,1,1
|
||||
Jason,1,1,1
|
||||
Yehuda,1,1,1
|
||||
Blue Chickens,,,
|
||||
Andrés,1,1,2
|
||||
JT,1,1,2
|
||||
Jason,1,1,2
|
||||
Yehuda,1,1,2
|
||||
Red Chickens,,,
|
||||
Andrés,1,1,3
|
||||
JT,1,1,3
|
||||
Jason,1,1,3
|
||||
Yehuda,1,1,3
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"];
|
||||
["Yellow Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 1],
|
||||
[JT, 1, 1, 1],
|
||||
[Jason, 1, 1, 1],
|
||||
[Yehuda, 1, 1, 1],
|
||||
["Blue Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 2],
|
||||
[JT, 1, 1, 2],
|
||||
[Jason, 1, 1, 2],
|
||||
[Yehuda, 1, 1, 2],
|
||||
["Red Chickens", "", "", ""],
|
||||
[Andrés, 1, 1, 3],
|
||||
[JT, 1, 1, 3],
|
||||
[Jason, 1, 1, 3],
|
||||
[Yehuda, 1, 1, 3]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open --raw caballeros.txt
|
||||
| lines
|
||||
| skip 2
|
||||
| str trim
|
||||
| str join (char nl)
|
||||
| from csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| skip 1
|
||||
| take while {|row| $row."Chicken Collection" != "Blue Chickens"}
|
||||
| take while {{|row| $row."Chicken Collection" != "Blue Chickens"}}
|
||||
| into int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,62 +1,27 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
const SAMPLE_CSV_CONTENT: &str = 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],
|
||||
[JT, Turner, "10/12/2013", B],
|
||||
[Yehuda, Katz, "10/11/2013", A]]
|
||||
"#;
|
||||
#[test]
|
||||
fn removes_duplicate_rows() {
|
||||
Playground::setup("uniq_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
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
let actual = nu!(pipeline(&format!("{SAMPLE_CSV_CONTENT} | uniq | length ")));
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.csv
|
||||
| uniq
|
||||
| length
|
||||
"
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uniq_values() {
|
||||
Playground::setup("uniq_test_2", |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
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"{SAMPLE_CSV_CONTENT} | select type | uniq | length ",
|
||||
)));
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.csv
|
||||
| select type
|
||||
| uniq
|
||||
| length
|
||||
"
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -68,10 +33,7 @@ fn uniq_empty() {
|
||||
|
||||
#[test]
|
||||
fn nested_json_structures() {
|
||||
Playground::setup("uniq_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"nested_json_structures.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
[
|
||||
{
|
||||
"name": "this is duplicated",
|
||||
@ -114,19 +76,11 @@ fn nested_json_structures() {
|
||||
}
|
||||
}
|
||||
]
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open nested_json_structures.json
|
||||
| uniq
|
||||
| length
|
||||
"
|
||||
));
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
let actual = nu!(pipeline(&format!("'{sample}' | from json | uniq | length")));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,32 +1,24 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn removes_duplicate_rows() {
|
||||
Playground::setup("uniq_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
|
||||
Afonso,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
JT,Turner,11/12/2011,O
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[first_name , last_name, rusty_at, type];
|
||||
[Andrés , Robalino, "10/11/2013", A],
|
||||
[Afonso , Turner, "10/12/2013", B],
|
||||
[Yehuda , Katz, "10/11/2013", A],
|
||||
[JT , Turner, "11/12/2011", O]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample}
|
||||
| uniq-by last_name
|
||||
| length
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,61 +1,45 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn wrap_rows_into_a_row() {
|
||||
Playground::setup("wrap_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.txt",
|
||||
r#"
|
||||
first_name,last_name
|
||||
Andrés,Robalino
|
||||
JT,Turner
|
||||
Yehuda,Katz
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[first_name, last_name];
|
||||
[Andrés, Robalino],
|
||||
[JT, Turner],
|
||||
[Yehuda, Katz]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.txt
|
||||
| from csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample}
|
||||
| wrap caballeros
|
||||
| get caballeros
|
||||
| get 0
|
||||
| get last_name
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "Robalino");
|
||||
})
|
||||
assert_eq!(actual.out, "Robalino");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrap_rows_into_a_table() {
|
||||
Playground::setup("wrap_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.txt",
|
||||
r#"
|
||||
first_name,last_name
|
||||
Andrés,Robalino
|
||||
JT,Turner
|
||||
Yehuda,Katz
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[first_name, last_name];
|
||||
[Andrés, Robalino],
|
||||
[JT, Turner],
|
||||
[Yehuda, Katz]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.txt
|
||||
| from csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
{sample}
|
||||
| get last_name
|
||||
| wrap caballero
|
||||
| get 2
|
||||
| get caballero
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "Katz");
|
||||
})
|
||||
assert_eq!(actual.out, "Katz");
|
||||
}
|
||||
|
@ -5,31 +5,25 @@ use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
|
||||
Playground::setup("internal_to_external_pipe_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"nu_times.csv",
|
||||
"
|
||||
name,rusty_luck,origin
|
||||
Jason,1,Canada
|
||||
JT,1,New Zealand
|
||||
Andrés,1,Ecuador
|
||||
AndKitKatz,1,Estados Unidos
|
||||
",
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[name, rusty_luck, origin];
|
||||
[Jason, 1, Canada],
|
||||
[JT, 1, "New Zealand"],
|
||||
[Andrés, 1, Ecuador],
|
||||
[AndKitKatz, 1, "Estados Unidos"]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
let actual = nu!(pipeline(&format!(
|
||||
"
|
||||
open nu_times.csv
|
||||
{sample}
|
||||
| get origin
|
||||
| each { |it| nu --testbin cococo $it | nu --testbin chop }
|
||||
| each {{ |it| nu --testbin cococo $it | nu --testbin chop }}
|
||||
| get 2
|
||||
"
|
||||
));
|
||||
)));
|
||||
|
||||
// chop will remove the last escaped double quote from \"Estados Unidos\"
|
||||
assert_eq!(actual.out, "Ecuado");
|
||||
})
|
||||
// chop will remove the last escaped double quote from \"Estados Unidos\"
|
||||
assert_eq!(actual.out, "Ecuado");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -111,7 +105,7 @@ fn subexpression_handles_dot() {
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "AndKitKat");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user