mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Split split command to sub commands.
This commit is contained in:
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -10,7 +10,7 @@ fn lines() {
|
||||
| skip-while $it != "[dependencies]"
|
||||
| skip 1
|
||||
| first 1
|
||||
| split-column "="
|
||||
| split column "="
|
||||
| get Column1
|
||||
| trim
|
||||
| echo $it
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -9,7 +9,7 @@ fn by_column() {
|
||||
| lines
|
||||
| skip 1
|
||||
| first 4
|
||||
| split-column "="
|
||||
| split column "="
|
||||
| sort-by Column1
|
||||
| skip 1
|
||||
| first 1
|
||||
|
@ -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"));
|
||||
})
|
||||
}
|
||||
|
29
crates/nu-cli/tests/commands/split_row.rs
Normal file
29
crates/nu-cli/tests/commands/split_row.rs
Normal 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"));
|
||||
})
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user