mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Add tests for cut.
This commit is contained in:
parent
ab5a5ba9e9
commit
929474040b
10 changed files with 91 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -166,6 +166,7 @@ TEST_PROGS := \
|
|||
basename \
|
||||
cat \
|
||||
cp \
|
||||
cut \
|
||||
env \
|
||||
dirname \
|
||||
echo \
|
||||
|
|
58
test/cut.rs
Normal file
58
test/cut.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use std::process::Command;
|
||||
use util::*;
|
||||
|
||||
static PROGNAME: &'static str = "./cut";
|
||||
static INPUT: &'static str = "lists.txt";
|
||||
|
||||
#[path = "common/util.rs"]
|
||||
#[macro_use]
|
||||
mod util;
|
||||
|
||||
#[test]
|
||||
fn test_prefix() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-c", "-10", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_prefix.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_range() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-c", "4-10", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_char_range.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_column_to_end_of_line() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-d", ":", "-f", "5-", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_column_to_end_of_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_specific_field() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-d", " ", "-f", "3", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_specific_field.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_fields() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-d", ":", "-f", "1,3", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_multiple_fields.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tail() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-d", ":", "--complement", "-f", "1", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_tail.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_change_delimiter() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT]));
|
||||
assert_eq!(result.stdout, get_file_contents("lists_change_delimiter.expected"));
|
||||
}
|
4
test/fixtures/cut/lists.txt
vendored
Normal file
4
test/fixtures/cut/lists.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
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
|
4
test/fixtures/cut/lists_change_delimiter.expected
vendored
Normal file
4
test/fixtures/cut/lists_change_delimiter.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
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
|
4
test/fixtures/cut/lists_char_range.expected
vendored
Normal file
4
test/fixtures/cut/lists_char_range.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
:bar:ba
|
||||
:two:th
|
||||
ha:beta
|
||||
quick
|
4
test/fixtures/cut/lists_column_to_end_of_line.expected
vendored
Normal file
4
test/fixtures/cut/lists_column_to_end_of_line.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
quux
|
||||
five:six:seven
|
||||
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
the quick brown fox jumps over the lazy dog
|
4
test/fixtures/cut/lists_multiple_fields.expected
vendored
Normal file
4
test/fixtures/cut/lists_multiple_fields.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:baz
|
||||
one:three
|
||||
alpha:gamma
|
||||
the quick brown fox jumps over the lazy dog
|
4
test/fixtures/cut/lists_prefix.expected
vendored
Normal file
4
test/fixtures/cut/lists_prefix.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:bar:ba
|
||||
one:two:th
|
||||
alpha:beta
|
||||
the quick
|
4
test/fixtures/cut/lists_specific_field.expected
vendored
Normal file
4
test/fixtures/cut/lists_specific_field.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:bar:baz:qux:quux
|
||||
one:two:three:four:five:six:seven
|
||||
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
brown
|
4
test/fixtures/cut/lists_tail.expected
vendored
Normal file
4
test/fixtures/cut/lists_tail.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue