Table operating commands. (#1686)

* Table operating commands.

* Updated merge test for clarity.

* More clarity.

* Better like this..
This commit is contained in:
Andrés N. Robalino
2020-04-29 23:18:24 -05:00
committed by GitHub
parent d834708be8
commit cf53264438
17 changed files with 854 additions and 30 deletions

View File

@ -1,16 +1,31 @@
use nu_test_support::{nu, pipeline};
#[test]
fn creates_a_new_table_with_the_new_row_given() {
fn sets_the_column() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| edit dev-dependencies.pretty_assertions "7"
| edit dev-dependencies.pretty_assertions "0.7.0"
| get dev-dependencies.pretty_assertions
| echo $it
"#
));
assert_eq!(actual, "7");
assert_eq!(actual, "0.7.0");
}
#[test]
fn sets_the_column_from_a_block_run_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| edit dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
| echo $it
"#
));
assert_eq!(actual, "0.7.0");
}

View File

@ -0,0 +1,32 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn rows() {
Playground::setup("keep_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"caballeros.csv",
r#"
name,lucky_code
Andrés,1
Jonathan,1
Jason,2
Yehuda,1
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open caballeros.csv
| keep 3
| get lucky_code
| sum
| echo $it
"#
));
assert_eq!(actual, "4");
})
}

View File

@ -0,0 +1,51 @@
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("keep-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
Jonathan,1,1,1
Jason,1,1,1
Yehuda,1,1,1
Blue Chickens,,,
Andrés,1,1,2
Jonathan,1,1,2
Jason,1,1,2
Yehuda,1,1,2
Red Chickens,,,
Andrés,1,1,3
Jonathan,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
| split-column ','
| headers
| skip-while "Chickens Collction" != "Blue Chickens"
| keep-until "Chicken Collection" == "Red Chickens"
| str "31/04/2020" --to-int
| get "31/04/2020"
| sum
| echo $it
"#
));
assert_eq!(actual, "8");
})
}

View File

@ -0,0 +1,51 @@
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("keep-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
Jonathan,1,1,1
Jason,1,1,1
Yehuda,1,1,1
Blue Chickens,,,
Andrés,1,1,2
Jonathan,1,1,2
Jason,1,1,2
Yehuda,1,1,2
Red Chickens,,,
Andrés,1,1,3
Jonathan,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
| split-column ','
| headers
| skip 1
| keep-while "Chicken Collection" != "Blue Chickens"
| str "31/04/2020" --to-int
| get "31/04/2020"
| sum
| echo $it
"#
));
assert_eq!(actual, "4");
})
}

View File

@ -0,0 +1,43 @@
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
Jonathan,USA,0
Jason,Canada,0
Yehuda,USA,0
"#,
),
FileWithContentToBeTrimmed(
"new_caballeros.csv",
r#"
name,country,luck
Andrés Robalino,Guayaquil Ecuador,1
Jonathan Turner,New Zealand,1
"#,
),
]);
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
| sum
| echo $it
"#
));
assert_eq!(actual, "2");
})
}

View File

@ -17,10 +17,14 @@ mod headers;
mod histogram;
mod insert;
mod is_empty;
mod keep;
mod keep_until;
mod keep_while;
mod last;
mod lines;
mod ls;
mod math;
mod merge;
mod mkdir;
mod mv;
mod open;
@ -33,6 +37,7 @@ mod reverse;
mod rm;
mod save;
mod semicolon;
mod skip_until;
mod sort_by;
mod split_by;
mod split_column;

View File

@ -0,0 +1,50 @@
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,1,1,1
Jonathan,1,1,1
Jason,1,1,1
Yehuda,1,1,1
Blue Chickens,,,
Andrés,1,1,2
Jonathan,1,1,2
Jason,1,1,2
Yehuda,1,1,2
Red Chickens,,,
Andrés,1,1,3
Jonathan,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
| split-column ','
| headers
| skip-until "Chicken Collection" != "Red Chickens"
| str "31/04/2020" --to-int
| get "31/04/2020"
| sum
| echo $it
"#
));
assert_eq!(actual, "12");
})
}