diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9625dbe..57b5788 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,4 +90,11 @@ cargo clippy However, since `clippy` produces a compilation of the project, I wouldn't recommend running every time you save a file, since it would slow down -your productivity. \ No newline at end of file +your productivity. + +#### Testing the code + +If your PR is addressing a new feature, then writing unit tests would be +necessary. The unit test cases should both test private and public methods, +so you will place them inside the same file as your code, in a `tests` module +inside that file. \ No newline at end of file diff --git a/src/html_page.rs b/src/html_page.rs index 796fe3c..804f10d 100644 --- a/src/html_page.rs +++ b/src/html_page.rs @@ -189,3 +189,31 @@ impl HtmlPage { } } } + +#[cfg(test)] +mod tests { + use super::*; + use std::io::Result as IoResult; + + #[test] + fn file_name_refers_to_text_file() -> IoResult<()> { + let file_name = "file.txt"; + HtmlPage::is_path_to_text_file(&file_name) + } + + #[test] + fn file_name_does_not_refer_to_text_file() { + let file_name = "file.html"; + let error = HtmlPage::is_path_to_text_file(&file_name); + + assert!(error.is_err()); + } + + #[test] + fn file_name_does_not_have_extension() { + let file_name = "file"; + let error = HtmlPage::is_path_to_text_file(&file_name); + + assert!(error.is_err()); + } +}