From 88f62bb583b0b0acb48318a0b988d4382cb5617b Mon Sep 17 00:00:00 2001 From: Gerardo Arriaga Rendon Date: Sun, 14 Nov 2021 10:17:21 -0500 Subject: [PATCH 1/2] Add test case for file name checking --- src/html_page.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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()); + } +} From fe2b459365699fd8dbc7ede1d06a02b3e13ad8e7 Mon Sep 17 00:00:00 2001 From: Gerardo Arriaga Rendon Date: Sun, 14 Nov 2021 10:42:03 -0500 Subject: [PATCH 2/2] Update CONTRIBUTING --- CONTRIBUTING.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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