2020-07-06 17:27:01 +02:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn moves_a_column_before() {
|
|
|
|
Playground::setup("move_column_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"sample.csv",
|
|
|
|
r#"
|
|
|
|
column1,column2,column3,...,column98,column99,column100
|
|
|
|
-------,-------,-------,---,--------, A ,---------
|
|
|
|
-------,-------,-------,---,--------, N ,---------
|
|
|
|
-------,-------,-------,---,--------, D ,---------
|
|
|
|
-------,-------,-------,---,--------, R ,---------
|
|
|
|
-------,-------,-------,---,--------, E ,---------
|
|
|
|
-------,-------,-------,---,--------, S ,---------
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.csv
|
2020-10-20 11:07:13 +02:00
|
|
|
| move column99 --before column1
|
2020-07-06 17:27:01 +02:00
|
|
|
| rename chars
|
|
|
|
| get chars
|
2020-09-16 21:59:32 +02:00
|
|
|
| str trim
|
2022-09-11 10:48:27 +02:00
|
|
|
| str join
|
2020-07-06 17:27:01 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("ANDRES"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn moves_columns_before() {
|
|
|
|
Playground::setup("move_column_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"sample.csv",
|
|
|
|
r#"
|
|
|
|
column1,column2,column3,...,column98,column99,column100
|
|
|
|
-------,-------, A ,---,--------, N ,---------
|
|
|
|
-------,-------, D ,---,--------, R ,---------
|
|
|
|
-------,-------, E ,---,--------, S ,---------
|
|
|
|
-------,-------, : ,---,--------, : ,---------
|
2023-03-15 06:54:55 +01:00
|
|
|
-------,-------, J ,---,--------, T ,---------
|
2020-07-06 17:27:01 +02:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.csv
|
2020-10-20 11:07:13 +02:00
|
|
|
| move column99 column3 --before column2
|
2020-07-06 17:27:01 +02:00
|
|
|
| rename _ chars_1 chars_2
|
2022-05-18 13:18:21 +02:00
|
|
|
| select chars_2 chars_1
|
2022-09-11 10:48:27 +02:00
|
|
|
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
|
2022-05-18 13:18:21 +02:00
|
|
|
| get new_col
|
2022-09-11 10:48:27 +02:00
|
|
|
| str join
|
2020-07-06 17:27:01 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2023-03-15 06:54:55 +01:00
|
|
|
assert!(actual.out.contains("ANDRES::JT"));
|
2020-07-06 17:27:01 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn moves_a_column_after() {
|
|
|
|
Playground::setup("move_column_test_3", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"sample.csv",
|
|
|
|
r#"
|
|
|
|
column1,column2,letters,...,column98,and_more,column100
|
|
|
|
-------,-------, A ,---,--------, N ,---------
|
|
|
|
-------,-------, D ,---,--------, R ,---------
|
|
|
|
-------,-------, E ,---,--------, S ,---------
|
|
|
|
-------,-------, : ,---,--------, : ,---------
|
2023-03-15 06:54:55 +01:00
|
|
|
-------,-------, J ,---,--------, T ,---------
|
2020-07-06 17:27:01 +02:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.csv
|
2020-10-20 11:07:13 +02:00
|
|
|
| move letters --after and_more
|
|
|
|
| move letters and_more --before column2
|
2020-07-06 17:27:01 +02:00
|
|
|
| rename _ chars_1 chars_2
|
2022-05-18 13:18:21 +02:00
|
|
|
| select chars_1 chars_2
|
2022-09-11 10:48:27 +02:00
|
|
|
| upsert new_col {|f| $f | transpose | get column1 | str trim | str join}
|
2022-05-18 13:18:21 +02:00
|
|
|
| get new_col
|
2022-09-11 10:48:27 +02:00
|
|
|
| str join
|
2020-07-06 17:27:01 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2023-03-15 06:54:55 +01:00
|
|
|
assert!(actual.out.contains("ANDRES::JT"));
|
2020-07-06 17:27:01 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn moves_columns_after() {
|
|
|
|
Playground::setup("move_column_test_4", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
|
|
"sample.csv",
|
|
|
|
r#"
|
|
|
|
column1,column2,letters,...,column98,and_more,column100
|
|
|
|
-------,-------, A ,---,--------, N ,---------
|
|
|
|
-------,-------, D ,---,--------, R ,---------
|
|
|
|
-------,-------, E ,---,--------, S ,---------
|
|
|
|
-------,-------, : ,---,--------, : ,---------
|
2023-03-15 06:54:55 +01:00
|
|
|
-------,-------, J ,---,--------, T ,---------
|
2020-07-06 17:27:01 +02:00
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.csv
|
2020-10-20 11:07:13 +02:00
|
|
|
| move letters and_more --after column1
|
2022-02-22 17:32:29 +01:00
|
|
|
| columns
|
2022-02-09 15:59:40 +01:00
|
|
|
| select 1 2
|
2022-09-11 10:48:27 +02:00
|
|
|
| str join
|
2020-07-06 17:27:01 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("lettersand_more"));
|
|
|
|
})
|
|
|
|
}
|