2019-07-16 12:28:55 +02:00
|
|
|
mod helpers;
|
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
use helpers as h;
|
2019-08-29 08:31:56 +02:00
|
|
|
use helpers::{Playground, Stub::*};
|
2019-07-16 12:28:55 +02:00
|
|
|
|
2019-07-21 09:08:05 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_csv_text_and_from_csv_text_back_into_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats",
|
2019-07-22 04:23:02 +02:00
|
|
|
"open caco3_plastics.csv | to-csv | from-csv | first 1 | get origin | echo $it"
|
|
|
|
);
|
2019-07-21 09:08:05 +02:00
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
assert_eq!(actual, "SPAIN");
|
2019-07-21 09:08:05 +02:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:59:46 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_structured_table_to_csv_text() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_to_csv_test_1", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"csv_text_sample.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
importer,shipper,tariff_item,name,origin
|
|
|
|
Plasticos Rival,Reverte,2509000000,Calcium carbonate,Spain
|
|
|
|
Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open csv_text_sample.txt
|
|
|
|
| lines
|
|
|
|
| split-column "," a b c d origin
|
|
|
|
| last 1
|
|
|
|
| to-csv
|
|
|
|
| lines
|
|
|
|
| nth 1
|
2019-09-08 03:35:02 +02:00
|
|
|
| echo $it
|
2019-08-29 02:32:42 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia"));
|
|
|
|
})
|
2019-08-25 14:59:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_structured_table_to_csv_text_skipping_headers_after_conversion() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_to_csv_test_2", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"csv_text_sample.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
importer,shipper,tariff_item,name,origin
|
|
|
|
Plasticos Rival,Reverte,2509000000,Calcium carbonate,Spain
|
|
|
|
Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open csv_text_sample.txt
|
|
|
|
| lines
|
|
|
|
| split-column "," a b c d origin
|
|
|
|
| last 1
|
|
|
|
| to-csv --headerless
|
2019-09-08 03:35:02 +02:00
|
|
|
| echo $it
|
2019-08-29 02:32:42 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.contains("Tigre Ecuador,OMYA Andina,3824909999,Calcium carbonate,Colombia"));
|
|
|
|
})
|
2019-08-25 14:59:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_from_csv_text_to_structured_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_from_csv_test_1", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
2019-08-30 00:52:32 +02:00
|
|
|
"los_tres_caballeros.txt",
|
2019-08-27 23:45:18 +02:00
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
first_name,last_name,rusty_luck
|
|
|
|
Andrés,Robalino,1
|
|
|
|
Jonathan,Turner,1
|
|
|
|
Yehuda,Katz,1
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open los_tres_caballeros.txt
|
|
|
|
| from-csv
|
|
|
|
| get rusty_luck
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
2019-08-29 04:01:35 +02:00
|
|
|
| echo $it
|
2019-08-29 02:32:42 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
2019-08-25 14:59:46 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 14:11:04 +01:00
|
|
|
#[test]
|
|
|
|
fn converts_from_csv_text_with_separator_to_structured_table() {
|
|
|
|
Playground::setup("filter_from_csv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.txt",
|
|
|
|
r#"
|
|
|
|
first_name;last_name;rusty_luck
|
|
|
|
Andrés;Robalino;1
|
|
|
|
Jonathan;Turner;1
|
|
|
|
Yehuda;Katz;1
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.txt
|
|
|
|
| from-csv --separator ';'
|
|
|
|
| get rusty_luck
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:13:10 +01:00
|
|
|
#[test]
|
|
|
|
fn converts_from_csv_text_with_tab_separator_to_structured_table() {
|
|
|
|
Playground::setup("filter_from_csv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.txt",
|
|
|
|
r#"
|
|
|
|
first_name last_name rusty_luck
|
|
|
|
Andrés Robalino 1
|
|
|
|
Jonathan Turner 1
|
|
|
|
Yehuda Katz 1
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
|
|
|
open los_tres_caballeros.txt
|
|
|
|
| from-csv --separator '\t'
|
|
|
|
| get rusty_luck
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-25 14:59:46 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_from_csv_text_skipping_headers_to_structured_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_from_csv_test_2", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_amigos.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
Andrés,Robalino,1
|
|
|
|
Jonathan,Turner,1
|
|
|
|
Yehuda,Katz,1
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open los_tres_amigos.txt
|
|
|
|
| from-csv --headerless
|
|
|
|
| get Column3
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
2019-08-25 14:59:46 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 12:28:55 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_json_text_and_from_json_text_back_into_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open sgml_description.json
|
|
|
|
| to-json
|
|
|
|
| from-json
|
|
|
|
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "markup");
|
2019-07-16 12:28:55 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 13:05:51 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_from_json_text_to_structured_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_from_json_test_1", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"katz.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
{
|
|
|
|
"katz": [
|
2019-09-03 02:49:51 +02:00
|
|
|
{"name": "Yehuda", "rusty_luck": 1},
|
|
|
|
{"name": "Jonathan", "rusty_luck": 1},
|
2019-08-30 00:52:32 +02:00
|
|
|
{"name": "Andres", "rusty_luck": 1},
|
|
|
|
{"name":"GorbyPuff", "rusty_luck": 1}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(),
|
2019-08-29 02:32:42 +02:00
|
|
|
"open katz.txt | from-json | get katz | get rusty_luck | sum | echo $it"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual, "4");
|
|
|
|
})
|
2019-08-27 13:05:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_from_json_text_recognizing_objects_independendtly_to_structured_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_from_json_test_2", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"katz.txt",
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
{"name": "Yehuda", "rusty_luck": 1}
|
|
|
|
{"name": "Jonathan", "rusty_luck": 1}
|
2019-08-30 00:52:32 +02:00
|
|
|
{"name": "Andres", "rusty_luck": 1}
|
|
|
|
{"name":"GorbyPuff", "rusty_luck": 3}
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open katz.txt
|
|
|
|
| from-json --objects
|
|
|
|
| where name == "GorbyPuff"
|
|
|
|
| get rusty_luck
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
2019-08-27 13:05:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_structured_table_to_json_text() {
|
2019-08-29 02:32:42 +02:00
|
|
|
Playground::setup("filter_to_json_test", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"sample.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
JonAndrehudaTZ,3
|
|
|
|
GorbyPuff,100
|
|
|
|
"#,
|
2019-08-29 02:32:42 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open sample.txt
|
|
|
|
| lines
|
|
|
|
| split-column "," name luck
|
|
|
|
| pick name
|
|
|
|
| to-json
|
|
|
|
| from-json
|
2019-09-04 08:48:40 +02:00
|
|
|
| nth 0
|
2019-09-03 02:49:51 +02:00
|
|
|
| get name
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "JonAndrehudaTZ");
|
|
|
|
})
|
2019-08-27 13:05:51 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 11:02:16 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_tsv_text_and_from_tsv_text_back_into_table() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
|
|
|
"open caco3_plastics.tsv | to-tsv | from-tsv | first 1 | get origin | echo $it"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual, "SPAIN");
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:13:10 +01:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_tsv_text_and_from_tsv_text_back_into_table_using_csv_separator() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
|
|
|
r"open caco3_plastics.tsv | to-tsv | from-csv --separator '\t' | first 1 | get origin | echo $it"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual, "SPAIN");
|
|
|
|
}
|
|
|
|
|
2019-08-29 11:02:16 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_structured_table_to_tsv_text() {
|
|
|
|
Playground::setup("filter_to_tsv_test_1", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"tsv_text_sample.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
importer shipper tariff_item name origin
|
|
|
|
Plasticos Rival Reverte 2509000000 Calcium carbonate Spain
|
|
|
|
Tigre Ecuador OMYA Andina 3824909999 Calcium carbonate Colombia
|
|
|
|
"#,
|
2019-08-29 11:02:16 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open tsv_text_sample.txt
|
|
|
|
| lines
|
|
|
|
| split-column "\t" a b c d origin
|
|
|
|
| last 1
|
2019-08-29 11:02:16 +02:00
|
|
|
| to-tsv
|
2019-09-03 02:49:51 +02:00
|
|
|
| lines
|
|
|
|
| nth 1
|
2019-09-08 03:35:02 +02:00
|
|
|
| echo $it
|
2019-08-29 11:02:16 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.contains("Colombia"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_structured_table_to_tsv_text_skipping_headers_after_conversion() {
|
|
|
|
Playground::setup("filter_to_tsv_test_2", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"tsv_text_sample.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
importer shipper tariff_item name origin
|
|
|
|
Plasticos Rival Reverte 2509000000 Calcium carbonate Spain
|
|
|
|
Tigre Ecuador OMYA Andina 3824909999 Calcium carbonate Colombia
|
|
|
|
"#,
|
2019-08-29 11:02:16 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open tsv_text_sample.txt
|
|
|
|
| lines
|
|
|
|
| split-column "\t" a b c d origin
|
|
|
|
| last 1
|
|
|
|
| to-tsv --headerless
|
2019-09-08 03:35:02 +02:00
|
|
|
| echo $it
|
2019-08-29 11:02:16 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.contains("Colombia"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_from_tsv_text_to_structured_table() {
|
|
|
|
Playground::setup("filter_from_tsv_test_1", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_amigos.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
first Name Last Name rusty_luck
|
|
|
|
Andrés Robalino 1
|
|
|
|
Jonathan Turner 1
|
|
|
|
Yehuda Katz 1
|
|
|
|
"#,
|
2019-08-29 11:02:16 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open los_tres_amigos.txt
|
|
|
|
| from-tsv
|
|
|
|
| get rusty_luck
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
2019-08-29 11:02:16 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn converts_from_tsv_text_skipping_headers_to_structured_table() {
|
|
|
|
Playground::setup("filter_from_tsv_test_2", |dirs, sandbox| {
|
2019-08-27 23:45:18 +02:00
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_amigos.txt",
|
|
|
|
r#"
|
2019-08-30 00:52:32 +02:00
|
|
|
Andrés Robalino 1
|
|
|
|
Jonathan Turner 1
|
|
|
|
Yehuda Katz 1
|
|
|
|
"#,
|
2019-08-29 11:02:16 +02:00
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-08-27 23:45:18 +02:00
|
|
|
open los_tres_amigos.txt
|
|
|
|
| from-tsv --headerless
|
|
|
|
| get Column3
|
|
|
|
| str --to-int
|
|
|
|
| sum
|
2019-08-29 11:02:16 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "3");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-13 21:15:30 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_from_ssv_text_to_structured_table() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
2019-10-13 22:50:45 +02:00
|
|
|
"oc_get_svc.txt",
|
2019-10-13 21:15:30 +02:00
|
|
|
r#"
|
|
|
|
NAME LABELS SELECTOR IP PORT(S)
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-10-13 22:50:45 +02:00
|
|
|
open oc_get_svc.txt
|
2019-10-13 21:15:30 +02:00
|
|
|
| from-ssv
|
|
|
|
| nth 0
|
2019-10-13 22:50:45 +02:00
|
|
|
| get IP
|
2019-10-13 21:15:30 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2019-10-13 22:50:45 +02:00
|
|
|
assert_eq!(actual, "172.30.78.158");
|
2019-10-13 21:15:30 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-15 20:58:46 +02:00
|
|
|
#[test]
|
|
|
|
fn converts_from_ssv_text_to_structured_table_with_separator_specified() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"oc_get_svc.txt",
|
|
|
|
r#"
|
|
|
|
NAME LABELS SELECTOR IP PORT(S)
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2019-10-15 22:05:32 +02:00
|
|
|
| from-ssv --minimum-spaces 3
|
2019-10-15 20:58:46 +02:00
|
|
|
| nth 0
|
|
|
|
| get IP
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "172.30.78.158");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-13 21:15:30 +02:00
|
|
|
#[test]
|
2019-11-03 23:12:14 +01:00
|
|
|
fn converts_from_ssv_text_treating_first_line_as_data_with_flag() {
|
2019-10-13 21:15:30 +02:00
|
|
|
Playground::setup("filter_from_ssv_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
2019-10-13 22:50:45 +02:00
|
|
|
"oc_get_svc.txt",
|
2019-10-13 21:15:30 +02:00
|
|
|
r#"
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
2019-11-11 15:07:02 +01:00
|
|
|
let aligned_columns = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
|
|
|
| from-ssv --headerless --aligned-columns
|
|
|
|
| first
|
|
|
|
| get Column1
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
let separator_based = nu!(
|
2019-10-13 21:15:30 +02:00
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-10-13 22:50:45 +02:00
|
|
|
open oc_get_svc.txt
|
2019-10-13 21:15:30 +02:00
|
|
|
| from-ssv --headerless
|
2019-11-03 23:12:14 +01:00
|
|
|
| first
|
|
|
|
| get Column1
|
2019-10-13 21:15:30 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2019-11-11 15:07:02 +01:00
|
|
|
assert_eq!(aligned_columns, separator_based);
|
|
|
|
assert_eq!(separator_based, "docker-registry");
|
2019-10-13 21:15:30 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-26 16:16:34 +02:00
|
|
|
#[test]
|
2019-08-27 23:45:18 +02:00
|
|
|
fn can_convert_table_to_bson_and_back_into_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-27 23:45:18 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-30 00:52:32 +02:00
|
|
|
r#"
|
|
|
|
open sample.bson
|
|
|
|
| to-bson
|
|
|
|
| from-bson
|
|
|
|
| get root
|
2019-11-04 16:47:03 +01:00
|
|
|
| get 1.b
|
2019-08-30 00:52:32 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-27 23:45:18 +02:00
|
|
|
));
|
2019-08-26 16:16:34 +02:00
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
assert_eq!(actual, "whel");
|
2019-08-26 16:16:34 +02:00
|
|
|
}
|
|
|
|
|
2019-11-17 04:18:41 +01:00
|
|
|
#[test]
|
|
|
|
fn can_read_excel_file() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
|
|
|
r#"
|
|
|
|
open sample_data.xlsx
|
|
|
|
| get SalesOrders
|
|
|
|
| nth 4
|
|
|
|
| get Column2
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "Gill");
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:45:18 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_sqlite_and_back_into_table() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-30 00:52:32 +02:00
|
|
|
r#"
|
|
|
|
open sample.db
|
|
|
|
| to-sqlite
|
|
|
|
| from-sqlite
|
|
|
|
| get table_values
|
|
|
|
| nth 2
|
|
|
|
| get x
|
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-27 23:45:18 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "hello");
|
|
|
|
}
|
|
|
|
|
2019-07-16 12:28:55 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_toml_text_and_from_toml_text_back_into_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-27 23:45:18 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-30 00:52:32 +02:00
|
|
|
r#"
|
|
|
|
open cargo_sample.toml
|
|
|
|
| to-toml
|
|
|
|
| from-toml
|
|
|
|
| get package.name
|
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-27 23:45:18 +02:00
|
|
|
));
|
2019-07-16 12:28:55 +02:00
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
assert_eq!(actual, "nu");
|
2019-07-16 12:28:55 +02:00
|
|
|
}
|
|
|
|
|
2019-07-17 19:51:53 +02:00
|
|
|
#[test]
|
|
|
|
fn can_convert_table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open appveyor.yml
|
|
|
|
| to-yaml
|
|
|
|
| from-yaml
|
|
|
|
| get environment.global.PROJECT_NAME
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "nushell");
|
2019-07-17 19:51:53 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 06:25:29 +02:00
|
|
|
#[test]
|
|
|
|
fn can_encode_and_decode_urlencoding() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.url
|
|
|
|
| to-url
|
|
|
|
| from-url
|
|
|
|
| get cheese
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "comté");
|
|
|
|
}
|
|
|
|
|
2019-07-16 12:28:55 +02:00
|
|
|
#[test]
|
|
|
|
fn can_sort_by_column() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open cargo_sample.toml --raw
|
|
|
|
| lines
|
|
|
|
| skip 1
|
|
|
|
| first 4
|
|
|
|
| split-column "="
|
|
|
|
| sort-by Column1
|
|
|
|
| skip 1
|
|
|
|
| first 1
|
|
|
|
| get Column1
|
|
|
|
| trim
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "description");
|
2019-08-24 22:31:45 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 12:28:55 +02:00
|
|
|
#[test]
|
|
|
|
fn can_split_by_column() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open cargo_sample.toml --raw
|
|
|
|
| lines
|
|
|
|
| skip 1
|
|
|
|
| first 1
|
|
|
|
| split-column "="
|
|
|
|
| get Column1
|
|
|
|
| trim
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "name");
|
2019-07-16 12:28:55 +02:00
|
|
|
}
|
|
|
|
|
2019-07-26 20:40:00 +02:00
|
|
|
#[test]
|
|
|
|
fn can_sum() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
2019-08-29 02:32:42 +02:00
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open sgml_description.json
|
|
|
|
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
|
|
|
| sum
|
2019-08-29 02:32:42 +02:00
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "203")
|
2019-07-26 20:40:00 +02:00
|
|
|
}
|
2019-08-10 11:11:38 +02:00
|
|
|
|
2019-10-14 23:55:42 +02:00
|
|
|
#[test]
|
2019-10-17 02:45:37 +02:00
|
|
|
fn can_average_numbers() {
|
2019-10-14 23:55:42 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", h::pipeline(
|
|
|
|
r#"
|
|
|
|
open sgml_description.json
|
|
|
|
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
|
|
|
| average
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "101.5000000000000")
|
|
|
|
}
|
|
|
|
|
2019-10-17 02:45:37 +02:00
|
|
|
#[test]
|
|
|
|
fn can_average_bytes() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats",
|
2019-10-19 02:43:07 +02:00
|
|
|
"ls | sort-by name | skip 1 | first 2 | get size | average | echo $it"
|
2019-10-17 02:45:37 +02:00
|
|
|
);
|
|
|
|
|
2019-10-19 02:43:07 +02:00
|
|
|
assert_eq!(actual, "1600.000000000000");
|
2019-10-17 02:45:37 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 12:28:55 +02:00
|
|
|
#[test]
|
|
|
|
fn can_filter_by_unit_size_comparison() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats",
|
2019-08-29 11:02:16 +02:00
|
|
|
"ls | where size > 1kb | sort-by size | get name | first 1 | trim | echo $it"
|
2019-07-17 19:51:53 +02:00
|
|
|
);
|
2019-07-16 12:28:55 +02:00
|
|
|
|
2019-08-29 11:02:16 +02:00
|
|
|
assert_eq!(actual, "cargo_sample.toml");
|
2019-07-16 12:28:55 +02:00
|
|
|
}
|
2019-08-24 23:55:42 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_get_last() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats",
|
2019-08-25 02:21:09 +02:00
|
|
|
"ls | sort-by name | last 1 | get name | trim | echo $it"
|
2019-08-24 23:55:42 +02:00
|
|
|
);
|
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
assert_eq!(actual, "utf16.ini");
|
2019-08-24 20:32:48 +02:00
|
|
|
}
|
2019-08-25 18:14:17 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_get_reverse_first() {
|
2019-08-29 02:32:42 +02:00
|
|
|
let actual = nu!(
|
2019-08-29 08:31:56 +02:00
|
|
|
cwd: "tests/fixtures/formats",
|
2019-08-25 18:14:17 +02:00
|
|
|
"ls | sort-by name | reverse | first 1 | get name | trim | echo $it"
|
|
|
|
);
|
|
|
|
|
2019-08-29 02:32:42 +02:00
|
|
|
assert_eq!(actual, "utf16.ini");
|
2019-08-25 18:14:17 +02:00
|
|
|
}
|
2019-09-02 07:37:13 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn embed() {
|
|
|
|
Playground::setup("embed_test", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.txt",
|
|
|
|
r#"
|
|
|
|
first_name,last_name
|
|
|
|
Andrés,Robalino
|
|
|
|
Jonathan,Turner
|
|
|
|
Yehuda,Katz
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open los_tres_caballeros.txt
|
2019-09-02 07:37:13 +02:00
|
|
|
| from-csv
|
2019-09-03 02:49:51 +02:00
|
|
|
| embed caballeros
|
|
|
|
| get caballeros
|
2019-09-02 07:37:13 +02:00
|
|
|
| nth 0
|
|
|
|
| get last_name
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "Robalino");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn get() {
|
|
|
|
Playground::setup("get_test", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"los_tres_caballeros.txt",
|
|
|
|
r#"
|
|
|
|
first_name,last_name
|
|
|
|
Andrés,Robalino
|
|
|
|
Jonathan,Turner
|
|
|
|
Yehuda,Katz
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), h::pipeline(
|
|
|
|
r#"
|
2019-09-03 02:49:51 +02:00
|
|
|
open los_tres_caballeros.txt
|
|
|
|
| from-csv
|
2019-09-02 07:37:13 +02:00
|
|
|
| nth 1
|
|
|
|
| get last_name
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual, "Turner");
|
|
|
|
})
|
|
|
|
}
|