2020-05-24 06:41:30 +00:00
|
|
|
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| {
|
2023-04-07 11:46:11 +00:00
|
|
|
sandbox.with_files(vec![
|
|
|
|
FileWithContentToBeTrimmed(
|
|
|
|
"sample.txt",
|
|
|
|
r#"
|
2020-05-24 06:41:30 +00:00
|
|
|
importer,shipper,tariff_item,name,origin
|
|
|
|
"#,
|
2023-04-07 11:46:11 +00:00
|
|
|
),
|
|
|
|
FileWithContentToBeTrimmed(
|
|
|
|
"sample2.txt",
|
|
|
|
r#"
|
|
|
|
importer , shipper , tariff_item,name , origin
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
]);
|
2020-05-24 06:41:30 +00:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.txt
|
|
|
|
| lines
|
2020-09-16 19:59:32 +00:00
|
|
|
| str trim
|
2020-05-24 06:41:30 +00:00
|
|
|
| split row ","
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-05-24 06:41:30 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-27 04:50:26 +00:00
|
|
|
assert!(actual.out.contains('5'));
|
2023-04-07 11:46:11 +00:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample2.txt
|
|
|
|
| lines
|
|
|
|
| str trim
|
|
|
|
| split row -r '\s*,\s*'
|
|
|
|
| length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains('5'));
|
2023-07-27 19:32:25 +00:00
|
|
|
|
|
|
|
let actual = nu!(r#"
|
|
|
|
def foo [a: list<string>] {
|
|
|
|
$a | describe
|
|
|
|
}
|
|
|
|
foo (["a b", "c d"] | split row " ")
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert!(actual.out.contains("list<string>"));
|
2020-05-24 06:41:30 +00:00
|
|
|
})
|
|
|
|
}
|