forked from extern/nushell
Remove old nushell/merge engine-q
This commit is contained in:
17
crates/nu-command/tests/format_conversions/bson.rs
Normal file
17
crates/nu-command/tests/format_conversions/bson.rs
Normal file
@ -0,0 +1,17 @@
|
||||
#[cfg(feature = "bson")]
|
||||
#[test]
|
||||
fn table_to_bson_and_back_into_table() {
|
||||
use nu_test_support::{nu, pipeline};
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.bson
|
||||
| to bson
|
||||
| from bson
|
||||
| get root
|
||||
| get 1.b
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "whel");
|
||||
}
|
@ -34,11 +34,7 @@ fn table_to_csv_text() {
|
||||
| last 1
|
||||
| to csv
|
||||
| lines
|
||||
<<<<<<< HEAD
|
||||
| nth 1
|
||||
=======
|
||||
| get 1
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
"#
|
||||
));
|
||||
|
||||
@ -149,11 +145,7 @@ fn from_csv_text_with_separator_to_table() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
<<<<<<< HEAD
|
||||
| from csv --separator ';'
|
||||
=======
|
||||
| from csv --separator ";"
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
| get rusty_luck
|
||||
| length
|
||||
"#
|
||||
@ -180,11 +172,7 @@ fn from_csv_text_with_tab_separator_to_table() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.txt
|
||||
<<<<<<< HEAD
|
||||
| from csv --separator '\t'
|
||||
=======
|
||||
| from csv --separator (char tab)
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
| get rusty_luck
|
||||
| length
|
||||
"#
|
||||
|
93
crates/nu-command/tests/format_conversions/eml.rs
Normal file
93
crates/nu-command/tests/format_conversions/eml.rs
Normal file
@ -0,0 +1,93 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
const TEST_CWD: &str = "tests/fixtures/formats";
|
||||
|
||||
// The To field in this email is just "to@example.com", which gets parsed out as the Address. The Name is empty.
|
||||
#[test]
|
||||
fn from_eml_get_to_field() {
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get To
|
||||
| get Address
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "to@example.com");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get To
|
||||
| get Name
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
// The Reply-To field in this email is "replyto@example.com" <replyto@example.com>, meaning both the Name and Address values are identical.
|
||||
#[test]
|
||||
fn from_eml_get_replyto_field() {
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get Reply-To
|
||||
| get Address
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "replyto@example.com");
|
||||
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get Reply-To
|
||||
| get Name
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "replyto@example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_eml_get_subject_field() {
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get Subject
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "Test Message");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_eml_get_another_header_field() {
|
||||
let actual = nu!(
|
||||
cwd: TEST_CWD,
|
||||
pipeline(
|
||||
r#"
|
||||
open sample.eml
|
||||
| get MIME-Version
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1.0");
|
||||
}
|
@ -56,11 +56,7 @@ fn test_cd_html_color_flag_dark_false() {
|
||||
);
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
<<<<<<< HEAD
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> > cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called 'dirname'<br> > <span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>dirname<span style='color:black;font-weight:normal;'><br><br> Change to your home directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> > </span></span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to the previous directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
|
||||
=======
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Usage:<br> > cd (path) <br><br>Flags:<br> -h, --help<br> Display this help message<br><br>Parameters:<br> (optional) path: the path to change to<br><br></body></html>"
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
);
|
||||
}
|
||||
|
||||
@ -75,11 +71,7 @@ fn test_no_color_flag() {
|
||||
);
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
<<<<<<< HEAD
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> > cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called 'dirname'<br> > cd dirname<br><br> Change to your home directory<br> > cd<br><br> Change to your home directory (alternate version)<br> > cd ~<br><br> Change to the previous directory<br> > cd -<br><br></body></html>"
|
||||
=======
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Usage:<br> > cd (path) <br><br>Flags:<br> -h, --help<br> Display this help message<br><br>Parameters:<br> (optional) path: the path to change to<br><br></body></html>"
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
);
|
||||
}
|
||||
|
||||
@ -94,10 +86,6 @@ fn test_html_color_where_flag_dark_false() {
|
||||
);
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
<<<<<<< HEAD
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Filter table to match the condition.<br><br>Usage:<br> > where <condition> {flags} <br><br>Parameters:<br> <condition> the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> > <span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>size<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>><span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>kb<span style='color:black;font-weight:normal;'><br><br> List only the files in the current directory<br> > </span></span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>type<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>==<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>File<span style='color:black;font-weight:normal;'><br><br> List all files with names that contain "Car"<br> > </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>name<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>=~<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>"Car"<span style='color:black;font-weight:normal;'><br><br> List all files that were modified in the last two weeks<br> > </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>modified<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'><=<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>wk<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
|
||||
=======
|
||||
r"<html><style>body { background-color:white;color:black; }</style><body>Usage:<br> > where <cond> <br><br>Flags:<br> -h, --help<br> Display this help message<br><br>Parameters:<br> cond: condition<br><br></body></html>"
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
);
|
||||
}
|
||||
|
@ -47,11 +47,7 @@ fn infers_types() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open calendar.ics
|
||||
<<<<<<< HEAD
|
||||
| get events
|
||||
=======
|
||||
| get events.0
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
| length
|
||||
"#
|
||||
));
|
||||
@ -90,13 +86,8 @@ fn from_ics_text_to_table() {
|
||||
r#"
|
||||
open calendar.txt
|
||||
| from ics
|
||||
<<<<<<< HEAD
|
||||
| get events
|
||||
| get properties
|
||||
=======
|
||||
| get events.0
|
||||
| get properties.0
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
| where name == "SUMMARY"
|
||||
| first
|
||||
| get value
|
||||
|
100
crates/nu-command/tests/format_conversions/json.rs
Normal file
100
crates/nu-command/tests/format_conversions/json.rs
Normal file
@ -0,0 +1,100 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn table_to_json_text_and_from_json_text_back_into_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sgml_description.json
|
||||
| to json
|
||||
| from json
|
||||
| get glossary.GlossDiv.GlossList.GlossEntry.GlossSee
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "markup");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_json_text_to_table() {
|
||||
Playground::setup("filter_from_json_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.txt",
|
||||
r#"
|
||||
{
|
||||
"katz": [
|
||||
{"name": "Yehuda", "rusty_luck": 1},
|
||||
{"name": "Jonathan", "rusty_luck": 1},
|
||||
{"name": "Andres", "rusty_luck": 1},
|
||||
{"name":"GorbyPuff", "rusty_luck": 1}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.txt | from json | get katz | get rusty_luck | length "
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_json_text_recognizing_objects_independently_to_table() {
|
||||
Playground::setup("filter_from_json_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"katz.txt",
|
||||
r#"
|
||||
{"name": "Yehuda", "rusty_luck": 1}
|
||||
{"name": "Jonathan", "rusty_luck": 1}
|
||||
{"name": "Andres", "rusty_luck": 1}
|
||||
{"name":"GorbyPuff", "rusty_luck": 3}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open katz.txt
|
||||
| from json -o
|
||||
| where name == "GorbyPuff"
|
||||
| get rusty_luck
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_to_json_text() {
|
||||
Playground::setup("filter_to_json_test", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"sample.txt",
|
||||
r#"
|
||||
JonAndrehudaTZ,3
|
||||
GorbyPuff,100
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.txt
|
||||
| lines
|
||||
| split column "," name luck
|
||||
| select name
|
||||
| to json
|
||||
| from json
|
||||
| nth 0
|
||||
| get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "JonAndrehudaTZ");
|
||||
})
|
||||
}
|
98
crates/nu-command/tests/format_conversions/markdown.rs
Normal file
98
crates/nu-command/tests/format_conversions/markdown.rs
Normal file
@ -0,0 +1,98 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn md_empty() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[]; []] | from json | to md
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_empty_pretty() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "{}" | from json | to md -p
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_simple() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 3 | to md
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_simple_pretty() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo 3 | to md -p
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[name]; [jason]] | to md
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "|name||-||jason|");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_table_pretty() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[name]; [joseph]] | to md -p
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "| name || ------ || joseph |");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn md_combined() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def title [] {
|
||||
echo [[H1]; ["Nu top meals"]]
|
||||
};
|
||||
|
||||
def meals [] {
|
||||
echo [[dish]; [Arepa] [Taco] [Pizza]]
|
||||
};
|
||||
|
||||
title
|
||||
| append (meals)
|
||||
| to md --per-element --pretty
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"# Nu top meals| dish || ----- || Arepa || Taco || Pizza |"
|
||||
);
|
||||
}
|
17
crates/nu-command/tests/format_conversions/mod.rs
Normal file
17
crates/nu-command/tests/format_conversions/mod.rs
Normal file
@ -0,0 +1,17 @@
|
||||
mod bson;
|
||||
mod csv;
|
||||
mod eml;
|
||||
mod html;
|
||||
mod ics;
|
||||
mod json;
|
||||
mod markdown;
|
||||
mod ods;
|
||||
mod sqlite;
|
||||
mod ssv;
|
||||
mod toml;
|
||||
mod tsv;
|
||||
mod url;
|
||||
mod vcf;
|
||||
mod xlsx;
|
||||
mod xml;
|
||||
mod yaml;
|
@ -22,12 +22,8 @@ fn from_ods_file_to_table_select_sheet() {
|
||||
r#"
|
||||
open sample_data.ods --raw
|
||||
| from ods -s ["SalesOrders"]
|
||||
<<<<<<< HEAD
|
||||
| get
|
||||
=======
|
||||
| columns
|
||||
| get 0
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
"#
|
||||
));
|
||||
|
||||
|
36
crates/nu-command/tests/format_conversions/sqlite.rs
Normal file
36
crates/nu-command/tests/format_conversions/sqlite.rs
Normal file
@ -0,0 +1,36 @@
|
||||
#[cfg(feature = "sqlite")]
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn table_to_sqlite_and_back_into_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| to sqlite
|
||||
| from sqlite
|
||||
| get table_values
|
||||
| nth 2
|
||||
| get x
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "hello");
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[test]
|
||||
fn table_to_sqlite_and_back_into_table_select_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.db
|
||||
| to sqlite
|
||||
| from sqlite -t [strings]
|
||||
| get table_names
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "strings");
|
||||
}
|
95
crates/nu-command/tests/format_conversions/ssv.rs
Normal file
95
crates/nu-command/tests/format_conversions/ssv.rs
Normal file
@ -0,0 +1,95 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn from_ssv_text_to_table() {
|
||||
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(), pipeline(
|
||||
r#"
|
||||
open oc_get_svc.txt
|
||||
| from ssv
|
||||
| nth 0
|
||||
| get IP
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "172.30.78.158");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_ssv_text_to_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(), pipeline(
|
||||
r#"
|
||||
open oc_get_svc.txt
|
||||
| from ssv --minimum-spaces 3
|
||||
| nth 0
|
||||
| get IP
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "172.30.78.158");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_ssv_text_treating_first_line_as_data_with_flag() {
|
||||
Playground::setup("filter_from_ssv_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"oc_get_svc.txt",
|
||||
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
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let aligned_columns = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open oc_get_svc.txt
|
||||
| from ssv --noheaders -a
|
||||
| first
|
||||
| get Column1
|
||||
"#
|
||||
));
|
||||
|
||||
let separator_based = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open oc_get_svc.txt
|
||||
| from ssv --noheaders
|
||||
| first
|
||||
| get Column1
|
||||
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(aligned_columns.out, separator_based.out);
|
||||
assert_eq!(separator_based.out, "docker-registry");
|
||||
})
|
||||
}
|
16
crates/nu-command/tests/format_conversions/toml.rs
Normal file
16
crates/nu-command/tests/format_conversions/toml.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn table_to_toml_text_and_from_toml_text_back_into_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml
|
||||
| to toml
|
||||
| from toml
|
||||
| get package.name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nu");
|
||||
}
|
132
crates/nu-command/tests/format_conversions/tsv.rs
Normal file
132
crates/nu-command/tests/format_conversions/tsv.rs
Normal file
@ -0,0 +1,132 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn 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"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "SPAIN");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn 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"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "SPAIN");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_to_tsv_text() {
|
||||
Playground::setup("filter_to_tsv_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"tsv_text_sample.txt",
|
||||
r#"
|
||||
importer shipper tariff_item name origin
|
||||
Plasticos Rival Reverte 2509000000 Calcium carbonate Spain
|
||||
Tigre Ecuador OMYA Andina 3824909999 Calcium carbonate Colombia
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open tsv_text_sample.txt
|
||||
| lines
|
||||
| split column "\t" a b c d origin
|
||||
| last 1
|
||||
| to tsv
|
||||
| lines
|
||||
| nth 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("Colombia"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_to_tsv_text_skipping_headers_after_conversion() {
|
||||
Playground::setup("filter_to_tsv_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"tsv_text_sample.txt",
|
||||
r#"
|
||||
importer shipper tariff_item name origin
|
||||
Plasticos Rival Reverte 2509000000 Calcium carbonate Spain
|
||||
Tigre Ecuador OMYA Andina 3824909999 Calcium carbonate Colombia
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open tsv_text_sample.txt
|
||||
| lines
|
||||
| split column "\t" a b c d origin
|
||||
| last 1
|
||||
| to tsv --noheaders
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("Colombia"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_tsv_text_to_table() {
|
||||
Playground::setup("filter_from_tsv_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_amigos.txt",
|
||||
r#"
|
||||
first Name Last Name rusty_luck
|
||||
Andrés Robalino 1
|
||||
Jonathan Turner 1
|
||||
Yehuda Katz 1
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.txt
|
||||
| from tsv
|
||||
| get rusty_luck
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_tsv_text_skipping_headers_to_table() {
|
||||
Playground::setup("filter_from_tsv_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_amigos.txt",
|
||||
r#"
|
||||
Andrés Robalino 1
|
||||
Jonathan Turner 1
|
||||
Yehuda Katz 1
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_amigos.txt
|
||||
| from tsv --noheaders
|
||||
| get Column3
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
})
|
||||
}
|
16
crates/nu-command/tests/format_conversions/url.rs
Normal file
16
crates/nu-command/tests/format_conversions/url.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn can_encode_and_decode_urlencoding() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open sample.url
|
||||
| to url
|
||||
| from url
|
||||
| get cheese
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "comté");
|
||||
}
|
@ -70,11 +70,7 @@ fn from_vcf_text_to_table() {
|
||||
r#"
|
||||
open contacts.txt
|
||||
| from vcf
|
||||
<<<<<<< HEAD
|
||||
| get properties
|
||||
=======
|
||||
| get properties.0
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
| where name == "EMAIL"
|
||||
| first
|
||||
| get value
|
||||
|
@ -22,12 +22,8 @@ fn from_excel_file_to_table_select_sheet() {
|
||||
r#"
|
||||
open sample_data.xlsx --raw
|
||||
| from xlsx -s ["SalesOrders"]
|
||||
<<<<<<< HEAD
|
||||
| get
|
||||
=======
|
||||
| columns
|
||||
| get 0
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -8,11 +8,7 @@ fn table_to_xml_text_and_from_xml_text_back_into_table() {
|
||||
open jonathan.xml
|
||||
| to xml
|
||||
| from xml
|
||||
<<<<<<< HEAD
|
||||
| get rss.children.channel.children.0.item.children.0.guid.attributes.isPermaLink
|
||||
=======
|
||||
| get rss.children.channel.children.0.3.item.children.guid.4.attributes.isPermaLink
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
"#
|
||||
));
|
||||
|
||||
|
16
crates/nu-command/tests/format_conversions/yaml.rs
Normal file
16
crates/nu-command/tests/format_conversions/yaml.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn table_to_yaml_text_and_from_yaml_text_back_into_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open appveyor.yml
|
||||
| to yaml
|
||||
| from yaml
|
||||
| get environment.global.PROJECT_NAME
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "nushell");
|
||||
}
|
Reference in New Issue
Block a user