From dcfc23498e6a6c835b05771ef59a6d66bb44290f Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 6 Jun 2015 22:33:56 -0400 Subject: [PATCH] Add tests for tac. --- Makefile | 1 + test/fixtures/tac/delimited_primes.expected | 1 + test/fixtures/tac/delimited_primes.txt | 1 + .../tac/delimited_primes_before.expected | 1 + test/fixtures/tac/prime_per_line.expected | 25 ++++++++++ test/fixtures/tac/prime_per_line.txt | 25 ++++++++++ test/tac.rs | 50 +++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 test/fixtures/tac/delimited_primes.expected create mode 100644 test/fixtures/tac/delimited_primes.txt create mode 100644 test/fixtures/tac/delimited_primes_before.expected create mode 100644 test/fixtures/tac/prime_per_line.expected create mode 100644 test/fixtures/tac/prime_per_line.txt create mode 100644 test/tac.rs diff --git a/Makefile b/Makefile index a15425d91..ff8adc843 100644 --- a/Makefile +++ b/Makefile @@ -183,6 +183,7 @@ TEST_PROGS := \ seq \ sort \ split \ + tac \ test \ tr \ true \ diff --git a/test/fixtures/tac/delimited_primes.expected b/test/fixtures/tac/delimited_primes.expected new file mode 100644 index 000000000..cf58c9015 --- /dev/null +++ b/test/fixtures/tac/delimited_primes.expected @@ -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: \ No newline at end of file diff --git a/test/fixtures/tac/delimited_primes.txt b/test/fixtures/tac/delimited_primes.txt new file mode 100644 index 000000000..867a26610 --- /dev/null +++ b/test/fixtures/tac/delimited_primes.txt @@ -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 \ No newline at end of file diff --git a/test/fixtures/tac/delimited_primes_before.expected b/test/fixtures/tac/delimited_primes_before.expected new file mode 100644 index 000000000..13cb1be06 --- /dev/null +++ b/test/fixtures/tac/delimited_primes_before.expected @@ -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 \ No newline at end of file diff --git a/test/fixtures/tac/prime_per_line.expected b/test/fixtures/tac/prime_per_line.expected new file mode 100644 index 000000000..72413442f --- /dev/null +++ b/test/fixtures/tac/prime_per_line.expected @@ -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 diff --git a/test/fixtures/tac/prime_per_line.txt b/test/fixtures/tac/prime_per_line.txt new file mode 100644 index 000000000..afc67fd93 --- /dev/null +++ b/test/fixtures/tac/prime_per_line.txt @@ -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 diff --git a/test/tac.rs b/test/tac.rs new file mode 100644 index 000000000..5ec5a26b4 --- /dev/null +++ b/test/tac.rs @@ -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")); +}