2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
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
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|