From e518ae2b8766ea9835329ad39deedb947bf50f90 Mon Sep 17 00:00:00 2001 From: Armin Grodon Date: Mon, 1 Feb 2021 10:14:10 +0100 Subject: [PATCH] wip: add integration tests --- src/util.rs | 29 +++++++++++++++++++++++++++++ tests/data/empty.txt | 0 tests/data/lines.txt | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 tests/data/empty.txt create mode 100644 tests/data/lines.txt diff --git a/src/util.rs b/src/util.rs index ac0dc59..12d03e2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,3 +15,32 @@ pub fn write_file(path: &PathBuf, contents: &str) -> Result<()> { file.write_all(contents.as_bytes())?; Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn read_files() { + assert_eq!( + read_file(&PathBuf::from("tests/data/empty.txt")).unwrap(), + String::from("") + ); + assert_eq!( + read_file(&PathBuf::from("tests/data/lines.txt")).unwrap(), + String::from("foo\nbar baz\n") + ); + } + + #[test] + fn write_files() { + assert_eq!( + write_file(&PathBuf::from("tests/data/empty.txt")), + String::from("") + ); + assert_eq!( + write_file(&PathBuf::from("tests/data/lines.txt")), + String::from("foo\nbar baz\n") + ); + } +} diff --git a/tests/data/empty.txt b/tests/data/empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/lines.txt b/tests/data/lines.txt new file mode 100644 index 0000000..089eeac --- /dev/null +++ b/tests/data/lines.txt @@ -0,0 +1,2 @@ +foo +bar baz