Skip to content

Commit

Permalink
Merge pull request #14 from JerryHue/testing
Browse files Browse the repository at this point in the history
Add test case for file name checking
  • Loading branch information
JerryHue authored Nov 14, 2021
2 parents 32b3783 + fe2b459 commit e9e2465
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
28 changes: 28 additions & 0 deletions src/html_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit e9e2465

Please sign in to comment.