2020-05-24 06:41:30 +00:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-12-15 16:15:06 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-24 06:41:30 +00:00
|
|
|
fn to_column() {
|
|
|
|
Playground::setup("split_column_test_1", |dirs, sandbox| {
|
2024-05-04 00:53:15 +00:00
|
|
|
sandbox.with_files(&[
|
2023-04-07 11:46:11 +00:00
|
|
|
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
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
]);
|
2019-12-15 16:15:06 +00:00
|
|
|
|
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 column ","
|
2022-02-20 00:26:47 +00:00
|
|
|
| get column2
|
2020-05-24 06:41:30 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("shipper"));
|
2023-04-07 11:46:11 +00:00
|
|
|
|
2024-09-12 12:16:33 +00:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.txt
|
|
|
|
| lines
|
|
|
|
| str trim
|
|
|
|
| split column -n 3 ","
|
|
|
|
| get column3
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("tariff_item,name,origin"));
|
|
|
|
|
2023-04-07 11:46:11 +00:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-08-31 22:08:27 +00:00
|
|
|
r"
|
2023-04-07 11:46:11 +00:00
|
|
|
open sample2.txt
|
|
|
|
| lines
|
|
|
|
| str trim
|
2023-10-19 20:08:09 +00:00
|
|
|
| split column --regex '\s*,\s*'
|
2023-04-07 11:46:11 +00:00
|
|
|
| get column2
|
2023-08-31 22:08:27 +00:00
|
|
|
"
|
2023-04-07 11:46:11 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("shipper"));
|
2020-05-24 06:41:30 +00:00
|
|
|
})
|
2019-12-15 16:15:06 +00:00
|
|
|
}
|