Merge pull request #638 from jbcrail/add-tac-tests

Add tests for tac.
This commit is contained in:
Heather 2015-06-07 09:44:32 +03:00
commit ad8724e84e
7 changed files with 104 additions and 0 deletions

View file

@ -183,6 +183,7 @@ TEST_PROGS := \
seq \ seq \
sort \ sort \
split \ split \
tac \
test \ test \
tr \ tr \
true \ true \

View file

@ -0,0 +1 @@
9789:83:79:73:71:67:61:59:53:47:43:41:37:31:29:23:19:17:13:11:7:5:3:2:

View file

@ -0,0 +1 @@
2:3:5:7:11:13:17:19:23:29:31:37:41:43:47:53:59:61:67:71:73:79:83:89:97

View file

@ -0,0 +1 @@
97:89:83:79:73:71:67:61:59:53:47:43:41:37:31:29:23:19:17:13:11:7:5:3:2

View file

@ -0,0 +1,25 @@
97
89
83
79
73
71
67
61
59
53
47
43
41
37
31
29
23
19
17
13
11
7
5
3
2

25
test/fixtures/tac/prime_per_line.txt vendored Normal file
View file

@ -0,0 +1,25 @@
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

50
test/tac.rs Normal file
View file

@ -0,0 +1,50 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./tac";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_stdin_default() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, "100\n200\n300\n400\n500");
assert_eq!(result.stdout, "500400\n300\n200\n100\n");
}
#[test]
fn test_stdin_non_newline_separator() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.args(&["-s", ":"]), "100:200:300:400:500");
assert_eq!(result.stdout, "500400:300:200:100:");
}
#[test]
fn test_stdin_non_newline_separator_before() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.args(&["-b", "-s", ":"]), "100:200:300:400:500");
assert_eq!(result.stdout, "500:400:300:200:100");
}
#[test]
fn test_single_default() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("prime_per_line.txt"));
assert_eq!(result.stdout, get_file_contents("prime_per_line.expected"));
}
#[test]
fn test_single_non_newline_separator() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-s", ":", "delimited_primes.txt"]));
assert_eq!(result.stdout, get_file_contents("delimited_primes.expected"));
}
#[test]
fn test_single_non_newline_separator_before() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-b", "-s", ":", "delimited_primes.txt"]));
assert_eq!(result.stdout, get_file_contents("delimited_primes_before.expected"));
}