Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
}
Empty file added tests/data/empty.txt
Empty file.
2 changes: 2 additions & 0 deletions tests/data/lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo
bar baz