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