From 0ea0e7504a3a17f61255508d6cd63fd5751926de Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Thu, 7 May 2015 16:51:55 -0400 Subject: [PATCH] Add test for paste. --- Makefile | 1 + test/fixtures/paste/html_colors.expected | 16 ++++++++++++ test/fixtures/paste/html_colors.txt | 32 ++++++++++++++++++++++++ test/paste.rs | 27 ++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 test/fixtures/paste/html_colors.expected create mode 100644 test/fixtures/paste/html_colors.txt create mode 100644 test/paste.rs diff --git a/Makefile b/Makefile index 3b6b635ca..a1c47e0bf 100644 --- a/Makefile +++ b/Makefile @@ -164,6 +164,7 @@ TEST_PROGS := \ mkdir \ mv \ nl \ + paste \ seq \ sort \ test \ diff --git a/test/fixtures/paste/html_colors.expected b/test/fixtures/paste/html_colors.expected new file mode 100644 index 000000000..4fb65d6aa --- /dev/null +++ b/test/fixtures/paste/html_colors.expected @@ -0,0 +1,16 @@ +white #FFFFFF +silver #C0C0C0 +gray #808080 +black #000000 +red #FF0000 +maroon #800000 +yellow #FFFF00 +olive #808000 +lime #00FF00 +green #008000 +aqua #00FFFF +teal #008080 +blue #0000FF +navy #000080 +fuchsia #FF00FF +purple #800080 diff --git a/test/fixtures/paste/html_colors.txt b/test/fixtures/paste/html_colors.txt new file mode 100644 index 000000000..290303ff0 --- /dev/null +++ b/test/fixtures/paste/html_colors.txt @@ -0,0 +1,32 @@ +white +#FFFFFF +silver +#C0C0C0 +gray +#808080 +black +#000000 +red +#FF0000 +maroon +#800000 +yellow +#FFFF00 +olive +#808000 +lime +#00FF00 +green +#008000 +aqua +#00FFFF +teal +#008080 +blue +#0000FF +navy +#000080 +fuchsia +#FF00FF +purple +#800080 diff --git a/test/paste.rs b/test/paste.rs new file mode 100644 index 000000000..b66ed01e7 --- /dev/null +++ b/test/paste.rs @@ -0,0 +1,27 @@ +use std::fs::File; +use std::io::Read; +use std::path::Path; +use std::process::Command; + +static PROGNAME: &'static str = "./paste"; + +#[test] +fn test_combine_pairs_of_lines() { + let po = Command::new(PROGNAME) + .arg("-s") + .arg("-d") + .arg("\t\n") + .arg("html_colors.txt") + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let mut f = File::open(Path::new("html_colors.expected")).unwrap_or_else(|err| { + panic!("{}", err) + }); + let mut expected = vec!(); + match f.read_to_end(&mut expected) { + Ok(_) => {}, + Err(err) => panic!("{}", err) + } + assert_eq!(String::from_utf8(po.stdout).unwrap(), String::from_utf8(expected).unwrap()); +}