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