2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2021-05-29 12:32:35 +00:00
|
|
|
static INPUT: &str = "lists.txt";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2016-08-06 18:58:46 +00:00
|
|
|
struct TestedSequence<'b> {
|
2020-04-13 18:36:03 +00:00
|
|
|
name: &'b str,
|
|
|
|
sequence: &'b str,
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 12:32:35 +00:00
|
|
|
static EXAMPLE_SEQUENCES: &[TestedSequence] = &[
|
2020-04-13 18:36:03 +00:00
|
|
|
TestedSequence {
|
|
|
|
name: "singular",
|
|
|
|
sequence: "2",
|
|
|
|
},
|
|
|
|
TestedSequence {
|
|
|
|
name: "prefix",
|
|
|
|
sequence: "-2",
|
|
|
|
},
|
|
|
|
TestedSequence {
|
|
|
|
name: "suffix",
|
|
|
|
sequence: "2-",
|
|
|
|
},
|
|
|
|
TestedSequence {
|
|
|
|
name: "range",
|
|
|
|
sequence: "2-4",
|
|
|
|
},
|
|
|
|
TestedSequence {
|
|
|
|
name: "aggregate",
|
|
|
|
sequence: "9-,6-7,-2,4",
|
|
|
|
},
|
|
|
|
TestedSequence {
|
|
|
|
name: "subsumed",
|
|
|
|
sequence: "2-,3",
|
|
|
|
},
|
2016-08-06 18:58:46 +00:00
|
|
|
];
|
|
|
|
|
2021-05-29 12:32:35 +00:00
|
|
|
static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence {
|
2020-04-13 18:36:03 +00:00
|
|
|
name: "",
|
|
|
|
sequence: "9-,6-7,-2,4",
|
|
|
|
};
|
2016-08-06 18:58:46 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_byte_sequence() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["-b", "--bytes", "--byt"] {
|
2016-08-06 18:58:46 +00:00
|
|
|
for example_seq in EXAMPLE_SEQUENCES {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[param, example_seq.sequence, INPUT])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_char_sequence() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["-c", "--characters", "--char"] {
|
2016-08-06 18:58:46 +00:00
|
|
|
for example_seq in EXAMPLE_SEQUENCES {
|
|
|
|
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[param, example_seq.sequence, INPUT])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_field_sequence() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["-f", "--fields", "--fie"] {
|
2016-08-06 18:58:46 +00:00
|
|
|
for example_seq in EXAMPLE_SEQUENCES {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[param, example_seq.sequence, INPUT])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_specify_delimiter() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["-d", "--delimiter", "--del"] {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("delimiter_specified.expected");
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_output_delimiter() {
|
2020-04-13 18:36:03 +00:00
|
|
|
// we use -d here to ensure output delimiter
|
2016-08-06 18:58:46 +00:00
|
|
|
// is applied to the current, and not just the default, input delimiter
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"-d:",
|
|
|
|
"--output-delimiter=@",
|
|
|
|
"-f",
|
|
|
|
COMPLEX_SEQUENCE.sequence,
|
|
|
|
INPUT,
|
|
|
|
])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("output_delimiter.expected");
|
2022-01-29 00:03:28 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"-d:",
|
|
|
|
"--output-del=@",
|
|
|
|
"-f",
|
|
|
|
COMPLEX_SEQUENCE.sequence,
|
|
|
|
INPUT,
|
|
|
|
])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("output_delimiter.expected");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_complement() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["--complement", "--com"] {
|
2022-01-29 00:03:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d_", param, "-f", "2"])
|
|
|
|
.pipe_in("9_1\n8_2\n7_3")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("9\n8\n7\n");
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_zero_terminated() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d_", "-z", "-f", "1"])
|
2022-02-11 13:02:06 +00:00
|
|
|
.pipe_in("9_1\n8_2\n\x007_3")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
2022-02-11 13:02:06 +00:00
|
|
|
.stdout_only("9\x007\0");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_only_delimited() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for param in ["-s", "--only-delimited", "--only-del"] {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d_", param, "-f", "1"])
|
2016-08-06 18:58:46 +00:00
|
|
|
.pipe_in("91\n82\n7_3")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("7\n");
|
2016-08-06 18:58:46 +00:00
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-06 18:58:46 +00:00
|
|
|
fn test_zero_terminated_only_delimited() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d_", "-z", "-s", "-f", "1"])
|
2016-08-06 18:58:46 +00:00
|
|
|
.pipe_in("91\n\082\n7_3")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("82\n7\0");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2021-04-03 17:55:10 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_directory_and_no_such_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.mkdir("some");
|
|
|
|
|
|
|
|
ucmd.arg("-b1")
|
|
|
|
.arg("some")
|
|
|
|
.run()
|
2021-05-25 23:45:53 +00:00
|
|
|
.stderr_is("cut: some: Is a directory\n");
|
2021-04-03 17:55:10 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-b1")
|
|
|
|
.arg("some")
|
|
|
|
.run()
|
2021-05-25 23:45:53 +00:00
|
|
|
.stderr_is("cut: some: No such file or directory\n");
|
2021-04-03 17:55:10 +00:00
|
|
|
}
|
2021-06-18 10:10:40 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-06-09 20:14:43 +00:00
|
|
|
fn test_equal_as_delimiter1() {
|
2021-06-18 10:10:40 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-f", "2", "-d="])
|
2021-06-19 15:53:06 +00:00
|
|
|
.pipe_in("--dir=./out/lib")
|
2021-06-18 10:10:40 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("./out/lib\n");
|
|
|
|
}
|
2022-06-09 20:14:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_equal_as_delimiter2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-f2", "--delimiter="])
|
|
|
|
.pipe_in("a=b\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("a=b\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_equal_as_delimiter3() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-f", "1,2", "-d", "''", "--output-delimiter=Z"])
|
|
|
|
.pipe_in("ab\0cd\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only_bytes("abZcd\n");
|
|
|
|
}
|