Split split command to sub commands.

This commit is contained in:
Andrés N. Robalino
2020-05-24 01:41:30 -05:00
parent 74c2daf665
commit edbecda14d
22 changed files with 154 additions and 57 deletions

View File

@ -35,7 +35,7 @@ fn condition_is_met() {
open --raw caballeros.txt
| lines
| skip 2
| split-column ','
| split column ','
| headers
| skip-while "Chickens Collction" != "Blue Chickens"
| keep-until "Chicken Collection" == "Red Chickens"

View File

@ -35,7 +35,7 @@ fn condition_is_met() {
open --raw caballeros.txt
| lines
| skip 2
| split-column ','
| split column ','
| headers
| skip 1
| keep-while "Chicken Collection" != "Blue Chickens"

View File

@ -10,7 +10,7 @@ fn lines() {
| skip-while $it != "[dependencies]"
| skip 1
| first 1
| split-column "="
| split column "="
| get Column1
| trim
| echo $it

View File

@ -41,6 +41,7 @@ mod skip_until;
mod sort_by;
mod split_by;
mod split_column;
mod split_row;
mod sum;
mod touch;
mod trim;

View File

@ -35,7 +35,7 @@ fn condition_is_met() {
open --raw caballeros.txt
| lines
| skip 2
| split-column ','
| split column ','
| headers
| skip-until "Chicken Collection" == "Red Chickens"
| str "31/04/2020" --to-int

View File

@ -9,7 +9,7 @@ fn by_column() {
| lines
| skip 1
| first 4
| split-column "="
| split column "="
| sort-by Column1
| skip 1
| first 1

View File

@ -1,20 +1,30 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn by_column() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml --raw
| lines
| skip 1
| first 1
| split-column "="
| get Column1
| trim
| echo $it
"#
));
fn to_column() {
Playground::setup("split_column_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"sample.txt",
r#"
importer,shipper,tariff_item,name,origin
"#,
)]);
assert_eq!(actual.out, "name");
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open sample.txt
| lines
| trim
| split column ","
| pivot
| nth 1
| echo $it
"#
));
assert!(actual.out.contains("shipper"));
})
}

View File

@ -0,0 +1,29 @@
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn to_row() {
Playground::setup("split_row_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"sample.txt",
r#"
importer,shipper,tariff_item,name,origin
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open sample.txt
| lines
| trim
| split row ","
| count
| echo $it
"#
));
assert!(actual.out.contains("5"));
})
}

View File

@ -30,7 +30,7 @@ fn table_to_csv_text() {
open csv_text_sample.txt
| lines
| trim
| split-column "," a b c d origin
| split column "," a b c d origin
| last 1
| to csv
| lines
@ -63,7 +63,7 @@ fn table_to_csv_text_skipping_headers_after_conversion() {
open csv_text_sample.txt
| lines
| trim
| split-column "," a b c d origin
| split column "," a b c d origin
| last 1
| to csv --headerless
| echo $it

View File

@ -88,7 +88,7 @@ fn table_to_json_text() {
r#"
open sample.txt
| lines
| split-column "," name luck
| split column "," name luck
| select name
| to json
| from json

View File

@ -39,7 +39,7 @@ fn table_to_tsv_text() {
r#"
open tsv_text_sample.txt
| lines
| split-column "\t" a b c d origin
| split column "\t" a b c d origin
| last 1
| to tsv
| lines
@ -69,7 +69,7 @@ fn table_to_tsv_text_skipping_headers_after_conversion() {
r#"
open tsv_text_sample.txt
| lines
| split-column "\t" a b c d origin
| split column "\t" a b c d origin
| last 1
| to tsv --headerless
| echo $it