2023-08-21 08:49:27 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2022-05-31 09:44:47 +00:00
|
|
|
use uucore::display::Quotable;
|
2021-07-31 08:38:32 +00:00
|
|
|
// spell-checker:ignore (ToDO) taaaa tbbbb tcccc
|
2020-05-15 12:21:23 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:21:23 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_tab() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-tab.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains(" ")
|
|
|
|
.stdout_does_not_contain("\t");
|
2020-05-15 12:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_trailing_tab() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-trailing-tab.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("with tabs=> ")
|
|
|
|
.stdout_does_not_contain("\t");
|
2020-05-15 12:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_trailing_tab_i() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-trailing-tab.txt")
|
|
|
|
.arg("-i")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains(" // with tabs=>\t");
|
2020-05-15 12:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_tab_size() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-tab.txt")
|
|
|
|
.arg("--tabs=10")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains(" ");
|
2020-05-15 12:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_space() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-spaces.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains(" return");
|
2020-05-15 12:21:23 +00:00
|
|
|
}
|
2021-03-15 13:29:28 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_multiple_files() {
|
2021-04-05 20:03:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("with-spaces.txt")
|
|
|
|
.arg("with-tab.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains(" return")
|
|
|
|
.stdout_contains(" ");
|
2021-03-15 13:29:28 +00:00
|
|
|
}
|
expand: expand support for --tabs arguments
Add support for
* space-separated list of tab stops, like `--tabs="2 4 6"`,
* mixed comma- and space-separated lists, like `--tabs="2,4 6"`,
* the slash specifier in the last tab stop, like `--tabs=1,/5`,
* the plus specifier in the last tab stop, like `--tabs=1,+5`.
2021-07-31 03:23:58 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_space_separated_list() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", "3 6 9"])
|
|
|
|
.pipe_in("a\tb\tc\td\te")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c d e");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_mixed_style_list() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", ", 3,6 9"])
|
|
|
|
.pipe_in("a\tb\tc\td\te")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c d e");
|
|
|
|
}
|
|
|
|
|
2022-06-01 14:18:57 +00:00
|
|
|
#[test]
|
|
|
|
fn test_multiple_tabs_args() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=3", "--tabs=6", "--tabs=9"])
|
|
|
|
.pipe_in("a\tb\tc\td\te")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c d e");
|
|
|
|
}
|
|
|
|
|
expand: expand support for --tabs arguments
Add support for
* space-separated list of tab stops, like `--tabs="2 4 6"`,
* mixed comma- and space-separated lists, like `--tabs="2,4 6"`,
* the slash specifier in the last tab stop, like `--tabs=1,/5`,
* the plus specifier in the last tab stop, like `--tabs=1,+5`.
2021-07-31 03:23:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tabs_empty_string() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", ""])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_comma_only() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", ","])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_space_only() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", " "])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_slash() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", "/"])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_plus() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs", "+"])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_trailing_slash() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,/5")
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
// 0 1
|
|
|
|
// 01234567890
|
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_trailing_slash_long_columns() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,/3")
|
|
|
|
.pipe_in("\taaaa\tbbbb\tcccc")
|
|
|
|
.succeeds()
|
|
|
|
// 0 1
|
|
|
|
// 01234567890123456
|
|
|
|
.stdout_is(" aaaa bbbb cccc");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_trailing_plus() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,+5")
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
// 0 1
|
|
|
|
// 012345678901
|
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_trailing_plus_long_columns() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,+3")
|
|
|
|
.pipe_in("\taaaa\tbbbb\tcccc")
|
|
|
|
.succeeds()
|
|
|
|
// 0 1
|
|
|
|
// 012345678901234567
|
|
|
|
.stdout_is(" aaaa bbbb cccc");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_must_be_ascending() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,1")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tab sizes must be ascending");
|
|
|
|
}
|
|
|
|
|
2022-05-31 09:44:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tabs_cannot_be_zero() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=0")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tab size cannot be 0");
|
|
|
|
}
|
|
|
|
|
expand: expand support for --tabs arguments
Add support for
* space-separated list of tab stops, like `--tabs="2 4 6"`,
* mixed comma- and space-separated lists, like `--tabs="2,4 6"`,
* the slash specifier in the last tab stop, like `--tabs=1,/5`,
* the plus specifier in the last tab stop, like `--tabs=1,+5`.
2021-07-31 03:23:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tabs_keep_last_trailing_specifier() {
|
|
|
|
// If there are multiple trailing specifiers, use only the last one
|
|
|
|
// before the number.
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1,+/+/5")
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
// 0 1
|
|
|
|
// 01234567890
|
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_comma_separated_no_numbers() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=+,/,+,/")
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
2022-05-31 09:44:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_with_specifier_not_at_start() {
|
|
|
|
fn run_cmd(arg: &str, expected_prefix: &str, expected_suffix: &str) {
|
|
|
|
let expected_msg = format!(
|
|
|
|
"{} specifier not at start of number: {}",
|
|
|
|
expected_prefix.quote(),
|
|
|
|
expected_suffix.quote()
|
|
|
|
);
|
|
|
|
new_ucmd!().arg(arg).fails().stderr_contains(expected_msg);
|
|
|
|
}
|
|
|
|
run_cmd("--tabs=1/", "/", "/");
|
|
|
|
run_cmd("--tabs=1/2", "/", "/2");
|
|
|
|
run_cmd("--tabs=1+", "+", "+");
|
|
|
|
run_cmd("--tabs=1+2", "+", "+2");
|
|
|
|
}
|
|
|
|
|
2022-06-05 13:16:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tabs_with_specifier_only_allowed_with_last_value() {
|
|
|
|
fn run_cmd(arg: &str, specifier: &str) {
|
|
|
|
let expected_msg = format!(
|
|
|
|
"{} specifier only allowed with the last value",
|
|
|
|
specifier.quote()
|
|
|
|
);
|
|
|
|
new_ucmd!().arg(arg).fails().stderr_contains(expected_msg);
|
|
|
|
}
|
|
|
|
run_cmd("--tabs=/1,2,3", "/");
|
|
|
|
run_cmd("--tabs=1,/2,3", "/");
|
|
|
|
new_ucmd!().arg("--tabs=1,2,/3").succeeds();
|
|
|
|
|
|
|
|
run_cmd("--tabs=+1,2,3", "+");
|
|
|
|
run_cmd("--tabs=1,+2,3", "+");
|
|
|
|
new_ucmd!().arg("--tabs=1,2,+3").succeeds();
|
|
|
|
}
|
|
|
|
|
2022-05-31 09:44:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_tabs_with_invalid_chars() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=x")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tab size contains invalid character(s): 'x'");
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--tabs=1x2")
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tab size contains invalid character(s): 'x2'");
|
|
|
|
}
|
2022-06-05 11:49:11 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_with_too_large_size() {
|
|
|
|
let arg = format!("--tabs={}", u128::MAX);
|
|
|
|
let expected_error = format!("tab stop is too large '{}'", u128::MAX);
|
|
|
|
|
|
|
|
new_ucmd!().arg(arg).fails().stderr_contains(expected_error);
|
|
|
|
}
|
2022-06-10 06:52:59 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_shortcut() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-2", "-5", "-7"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2022-06-10 06:52:59 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_comma_separated_tabs_shortcut() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-2,5", "-7"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2022-06-10 06:52:59 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tabs_and_tabs_shortcut_mixed() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-2", "--tabs=5", "-7"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2022-06-10 06:52:59 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
2023-01-03 18:23:28 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_initial_plus() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=+3"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 18:23:28 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_initial_pluses() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=++3"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 18:23:28 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_initial_slash() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=/3"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 18:23:28 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_initial_slashes() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=//3"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 18:23:28 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_initial_plus_slash_combination() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=+/3"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 18:23:28 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-01-03 21:27:20 +00:00
|
|
|
fn test_comma_with_plus_1() {
|
2023-01-03 18:23:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=3,+6"])
|
2023-01-03 21:27:20 +00:00
|
|
|
.pipe_in("\t111\t222\t333")
|
2023-01-03 20:49:20 +00:00
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 21:27:20 +00:00
|
|
|
.stdout_is(" 111 222 333");
|
2023-01-03 20:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-01-03 21:27:20 +00:00
|
|
|
fn test_comma_with_plus_2() {
|
2023-01-03 20:49:20 +00:00
|
|
|
new_ucmd!()
|
2023-01-03 21:27:20 +00:00
|
|
|
.args(&["--tabs=1,+5"])
|
|
|
|
.pipe_in("\ta\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 21:27:20 +00:00
|
|
|
.stdout_is(" a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_comma_with_plus_3() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=2,+5"])
|
|
|
|
.pipe_in("a\tb\tc")
|
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 21:27:20 +00:00
|
|
|
.stdout_is("a b c");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_comma_with_plus_4() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--tabs=1,3,+5"])
|
|
|
|
.pipe_in("a\tb\tc")
|
2023-01-03 18:23:28 +00:00
|
|
|
.succeeds()
|
2023-01-03 22:06:40 +00:00
|
|
|
// 01234567890
|
2023-01-03 21:27:20 +00:00
|
|
|
.stdout_is("a b c");
|
2023-01-03 18:23:28 +00:00
|
|
|
}
|