From 929474040b7eae035ac86c08f1e3a83dfc5b1046 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 31 Jul 2015 00:14:58 -0400 Subject: [PATCH] Add tests for cut. --- Makefile | 1 + test/cut.rs | 58 +++++++++++++++++++ test/fixtures/cut/lists.txt | 4 ++ .../cut/lists_change_delimiter.expected | 4 ++ test/fixtures/cut/lists_char_range.expected | 4 ++ .../cut/lists_column_to_end_of_line.expected | 4 ++ .../cut/lists_multiple_fields.expected | 4 ++ test/fixtures/cut/lists_prefix.expected | 4 ++ .../cut/lists_specific_field.expected | 4 ++ test/fixtures/cut/lists_tail.expected | 4 ++ 10 files changed, 91 insertions(+) create mode 100644 test/cut.rs create mode 100644 test/fixtures/cut/lists.txt create mode 100644 test/fixtures/cut/lists_change_delimiter.expected create mode 100644 test/fixtures/cut/lists_char_range.expected create mode 100644 test/fixtures/cut/lists_column_to_end_of_line.expected create mode 100644 test/fixtures/cut/lists_multiple_fields.expected create mode 100644 test/fixtures/cut/lists_prefix.expected create mode 100644 test/fixtures/cut/lists_specific_field.expected create mode 100644 test/fixtures/cut/lists_tail.expected diff --git a/Makefile b/Makefile index 9aa9d139d..e6312c2a1 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,7 @@ TEST_PROGS := \ basename \ cat \ cp \ + cut \ env \ dirname \ echo \ diff --git a/test/cut.rs b/test/cut.rs new file mode 100644 index 000000000..baf32b9f0 --- /dev/null +++ b/test/cut.rs @@ -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")); +} diff --git a/test/fixtures/cut/lists.txt b/test/fixtures/cut/lists.txt new file mode 100644 index 000000000..bc31b9a8d --- /dev/null +++ b/test/fixtures/cut/lists.txt @@ -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 diff --git a/test/fixtures/cut/lists_change_delimiter.expected b/test/fixtures/cut/lists_change_delimiter.expected new file mode 100644 index 000000000..3f695b26c --- /dev/null +++ b/test/fixtures/cut/lists_change_delimiter.expected @@ -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 diff --git a/test/fixtures/cut/lists_char_range.expected b/test/fixtures/cut/lists_char_range.expected new file mode 100644 index 000000000..185c87346 --- /dev/null +++ b/test/fixtures/cut/lists_char_range.expected @@ -0,0 +1,4 @@ +:bar:ba +:two:th +ha:beta + quick diff --git a/test/fixtures/cut/lists_column_to_end_of_line.expected b/test/fixtures/cut/lists_column_to_end_of_line.expected new file mode 100644 index 000000000..f93071e7d --- /dev/null +++ b/test/fixtures/cut/lists_column_to_end_of_line.expected @@ -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 diff --git a/test/fixtures/cut/lists_multiple_fields.expected b/test/fixtures/cut/lists_multiple_fields.expected new file mode 100644 index 000000000..2ded1424b --- /dev/null +++ b/test/fixtures/cut/lists_multiple_fields.expected @@ -0,0 +1,4 @@ +foo:baz +one:three +alpha:gamma +the quick brown fox jumps over the lazy dog diff --git a/test/fixtures/cut/lists_prefix.expected b/test/fixtures/cut/lists_prefix.expected new file mode 100644 index 000000000..29b3f2e3e --- /dev/null +++ b/test/fixtures/cut/lists_prefix.expected @@ -0,0 +1,4 @@ +foo:bar:ba +one:two:th +alpha:beta +the quick diff --git a/test/fixtures/cut/lists_specific_field.expected b/test/fixtures/cut/lists_specific_field.expected new file mode 100644 index 000000000..657258fcb --- /dev/null +++ b/test/fixtures/cut/lists_specific_field.expected @@ -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 diff --git a/test/fixtures/cut/lists_tail.expected b/test/fixtures/cut/lists_tail.expected new file mode 100644 index 000000000..f20335c90 --- /dev/null +++ b/test/fixtures/cut/lists_tail.expected @@ -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