1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #944 from nathanross/tests-cut-incr-feature-coverage

tests/cut: positive testcases for feature complete
This commit is contained in:
mpkh 2016-08-07 02:06:52 +04:00 committed by GitHub
commit b290ab2ca5
22 changed files with 142 additions and 41 deletions

View file

@ -0,0 +1,5 @@
foo:bar:qux
one:two:four:six:seven
alpha:beta:delta:zeta:eta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sally sells seashells down by the seashore where are the seashells sally sells

View file

@ -2,3 +2,4 @@ foo:bar:baz:qux:quux
one:two:three:four:five:six:seven one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog
sally sells seashells down by the seashore where are the seashells sally sells

View file

@ -1,4 +0,0 @@
bar#baz#qux#quux
two#three#four#five#six#seven
beta#gamma#delta#epsilon#zeta#eta#theta#iota#kappa#lambda#mu
the quick brown fox jumps over the lazy dog

View file

@ -1,4 +0,0 @@
:bar:ba
:two:th
ha:beta
quick

View file

@ -1,4 +0,0 @@
quux
five:six:seven
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

View file

@ -1,4 +0,0 @@
foo:baz
one:three
alpha:gamma
the quick brown fox jumps over the lazy dog

View file

@ -1,4 +0,0 @@
foo:bar:ba
one:two:th
alpha:beta
the quick

View file

@ -1,4 +0,0 @@
bar:baz:qux:quux
two:three:four:five:six:seven
beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

View file

@ -0,0 +1,5 @@
foo@bar@qux
one@two@four@six@seven
alpha@beta@delta@zeta@eta@iota@kappa@lambda@mu
the quick brown fox jumps over the lazy dog
sally sells seashells down by the seashore where are the seashells sally sells

View file

@ -0,0 +1,5 @@
fo:arbaz:qux:quux
on:wothree:four:five:six:seven
alh:bta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
th uik brown fox jumps over the lazy dog
sal slls seashells down by the seashore where are the seashells sally sells

View file

@ -0,0 +1,5 @@
fo
on
al
th
sa

View file

@ -0,0 +1,5 @@
oo:
ne:
lph
he
all

View file

@ -0,0 +1,5 @@
o
n
l
h
a

View file

@ -0,0 +1,5 @@
oo:bar:baz:qux:quux
ne:two:three:four:five:six:seven
lpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
he quick brown fox jumps over the lazy dog
ally sells seashells down by the seashore where are the seashells sally sells

View file

@ -0,0 +1,5 @@
oo:bar:baz:qux:quux
ne:two:three:four:five:six:seven
lpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
he quick brown fox jumps over the lazy dog
ally sells seashells down by the seashore where are the seashells sally sells

View file

@ -0,0 +1,5 @@
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sally sells down the seashore are the seashells sally sells

View file

@ -0,0 +1,5 @@
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sally sells

View file

@ -0,0 +1,5 @@
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sells seashells down

View file

@ -1,4 +1,5 @@
foo:bar:baz:qux:quux foo:bar:baz:qux:quux
one:two:three:four:five:six:seven one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
brown the quick brown fox jumps over the lazy dog
sells

View file

@ -0,0 +1,5 @@
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sells seashells down by the seashore where are the seashells sally sells

View file

@ -0,0 +1,5 @@
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
sells seashells down by the seashore where are the seashells sally sells

View file

@ -7,40 +7,98 @@ fn new_ucmd() -> UCommand {
static INPUT: &'static str = "lists.txt"; static INPUT: &'static str = "lists.txt";
struct TestedSequence<'b> {
name : &'b str,
sequence: &'b str
}
static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[
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" }
];
static COMPLEX_SEQUENCE: &'static TestedSequence<'static> = &TestedSequence{ name: "", sequence: "9-,6-7,-2,4" };
#[test] #[test]
fn test_prefix() { fn test_byte_sequence() {
new_ucmd().args(&["-c", "-10", INPUT]).run().stdout_is_fixture("lists_prefix.expected"); for param in vec!["-b", "--bytes"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
}
}
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_char_sequence() {
for param in vec!["-c", "--characters"] {
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.
new_ucmd().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/byte_{}.expected", example_seq.name));
}
}
} }
#[test] #[test]
fn test_char_range() { fn test_field_sequence() {
new_ucmd().args(&["-c", "4-10", INPUT]).run().stdout_is_fixture("lists_char_range.expected"); for param in vec!["-f", "--fields"] {
for example_seq in EXAMPLE_SEQUENCES {
new_ucmd().args(&[param, example_seq.sequence, INPUT])
.succeeds().stdout_only_fixture(format!("sequences/field_{}.expected", example_seq.name));
}
}
} }
#[test] #[test]
fn test_column_to_end_of_line() { fn test_specify_delimiter() {
new_ucmd().args(&["-d", ":", "-f", "5-", INPUT]).run().stdout_is_fixture("lists_column_to_end_of_line.expected"); for param in vec!["-d", "--delimiter"] {
new_ucmd().args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds().stdout_only_fixture("delimiter_specified.expected");
}
} }
#[test] #[test]
fn test_specific_field() { fn test_output_delimiter() {
new_ucmd().args(&["-d", " ", "-f", "3", INPUT]).run().stdout_is_fixture("lists_specific_field.expected"); // we use -d here to ensure output delimiter
// is applied to the current, and not just the default, input delimiter
new_ucmd().args(&["-d:", "--output-delimiter=@", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds().stdout_only_fixture("output_delimiter.expected");
} }
#[test] #[test]
fn test_multiple_fields() { fn test_complement() {
new_ucmd().args(&["-d", ":", "-f", "1,3", INPUT]).run().stdout_is_fixture("lists_multiple_fields.expected"); new_ucmd().args(&["-d_","--complement", "-f", "2"])
.pipe_in("9_1\n8_2\n7_3")
.succeeds().stdout_only("9\n8\n7\n");
}
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_zero_terminated() {
new_ucmd().args(&["-d_","-z", "-f", "1"])
.pipe_in("9_1\n8_2\n\07_3")
.succeeds().stdout_only("9\07\0");
} }
#[test] #[test]
fn test_tail() { fn test_only_delimited() {
new_ucmd().args(&["-d", ":", "--complement", "-f", "1", INPUT]).run().stdout_is_fixture("lists_tail.expected"); for param in vec!["-s", "--only-delimited"] {
new_ucmd().args(&["-d_", param, "-f", "1"])
.pipe_in("91\n82\n7_3")
.succeeds().stdout_only("7\n");
}
} }
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test] #[test]
fn test_change_delimiter() { fn test_zero_terminated_only_delimited() {
new_ucmd() new_ucmd().args(&["-d_","-z", "-s", "-f", "1"])
.args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT]) .pipe_in("91\n\082\n7_3")
.run().stdout_is_fixture("lists_change_delimiter.expected"); .succeeds().stdout_only("82\n7\0");
} }