nushell/crates/nu-command/tests/commands/detect_columns.rs

97 lines
2.6 KiB
Rust
Raw Normal View History

use nu_test_support::{nu, pipeline, playground::Playground};
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
#[test]
fn detect_columns_with_legacy() {
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
let cases = [(
"$\"c1 c2 c3 c4 c5(char nl)a b c d e\"",
"[[c1,c2,c3,c4,c5]; [a,b,c,d,e]]",
)];
Playground::setup("detect_columns_test_1", |dirs, _| {
for case in cases.into_iter() {
let out = nu!(
cwd: dirs.test(),
"({} | detect columns) == {}",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
case.0,
case.1
);
assert_eq!(
out.out, "true",
"({} | detect columns) == {}",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
case.0, case.1
);
}
});
}
#[test]
fn detect_columns_with_legacy_and_flag_c() {
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
let cases = [
(
"$\"c1 c2 c3 c4 c5(char nl)a b c d e\"",
"[[c1,c3,c4,c5]; ['a b',c,d,e]]",
"0..1",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
),
(
"$\"c1 c2 c3 c4 c5(char nl)a b c d e\"",
"[[c1,c2,c3,c4]; [a,b,c,'d e']]",
"(-2)..(-1)",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
),
(
"$\"c1 c2 c3 c4 c5(char nl)a b c d e\"",
"[[c1,c2,c3]; [a,b,'c d e']]",
"2..",
),
];
Playground::setup("detect_columns_test_1", |dirs, _| {
for case in cases.into_iter() {
let out = nu!(
cwd: dirs.test(),
"({} | detect columns --combine-columns {}) == {}",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
case.0,
case.2,
case.1,
);
assert_eq!(
out.out, "true",
"({} | detect columns --combine-columns {}) == {}",
fix #9653 the cmd `detect columns` with the flag `-c` (#9667) fix `detect columns` with flag `-c, --combine-columns` run failed when using some range - fixes #9653 fix #9653 the cmd detect columns with the flag -c, --combine-columns run failed when using some range. add unit test for the command `detect columns` ```text Attempt to automatically split text into multiple columns. Usage: > detect columns {flags} Flags: -h, --help - Display the help message for this command -s, --skip <Int> - number of rows to skip before detecting -n, --no-headers - don't detect headers -c, --combine-columns <Range> - columns to be combined; listed as a range Signatures: <string> | detect columns -> <table> Examples: Splits string across multiple columns > 'a b c' | detect columns -n ╭───┬─────────┬─────────┬─────────╮ │ # │ column0 │ column1 │ column2 │ ├───┼─────────┼─────────┼─────────┤ │ 0 │ a │ b │ c │ ╰───┴─────────┴─────────┴─────────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns ╭───┬────┬────┬────┬────┬────╮ │ # │ c1 │ c2 │ c3 │ c4 │ c5 │ ├───┼────┼────┼────┼────┼────┤ │ 0 │ a │ b │ c │ d │ e │ ╰───┴────┴────┴────┴────┴────╯ > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 0..1 ╭───┬─────┬────┬────┬────╮ │ # │ c1 │ c3 │ c4 │ c5 │ ├───┼─────┼────┼────┼────┤ │ 0 │ a b │ c │ d │ e │ ╰───┴─────┴────┴────┴────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c -2..-1 ╭───┬────┬────┬────┬─────╮ │ # │ c1 │ c2 │ c3 │ c4 │ ├───┼────┼────┼────┼─────┤ │ 0 │ a │ b │ c │ d e │ ╰───┴────┴────┴────┴─────╯ Splits a multi-line string into columns with headers detected > $'c1 c2 c3 c4 c5(char nl)a b c d e' | detect columns -c 2.. ╭───┬────┬────┬───────╮ │ # │ c1 │ c2 │ c3 │ ├───┼────┼────┼───────┤ │ 0 │ a │ b │ c d e │ ╰───┴────┴────┴───────╯ Parse external ls command and combine columns for datetime > ^ls -lh | detect columns --no-headers --skip 1 --combine-columns 5..7 ```
2023-07-21 15:25:06 +02:00
case.0, case.2, case.1
);
}
});
}
#[test]
fn detect_columns_with_flag_c() {
let body = "$\"
total 284K(char nl)
drwxr-xr-x 2 root root 4.0K Mar 20 08:28 =(char nl)
drwxr-xr-x 4 root root 4.0K Mar 20 08:18 ~(char nl)
-rw-r--r-- 1 root root 3.0K Mar 20 07:23 ~asdf(char nl)\"";
let expected = "[
['column0', 'column1', 'column2', 'column3', 'column4', 'column5', 'column7', 'column8'];
['drwxr-xr-x', '2', 'root', 'root', '4.0K', 'Mar 20', '08:28', '='],
['drwxr-xr-x', '4', 'root', 'root', '4.0K', 'Mar 20', '08:18', '~'],
['-rw-r--r--', '1', 'root', 'root', '3.0K', 'Mar 20', '07:23', '~asdf']
]";
let range = "5..6";
let cmd = format!(
"({} | detect columns -c {} -s 1 --no-headers) == {}",
pipeline(body),
range,
pipeline(expected),
);
println!("debug cmd: {cmd}");
Playground::setup("detect_columns_test_1", |dirs, _| {
let out = nu!(
cwd: dirs.test(),
cmd,
);
println!("{}", out.out);
assert_eq!(out.out, "true");
})
}