X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/dd0a540c2002f479ac56a7e0169e86d0f6f14d85..2cbae13cfd94f48dfe9a8c903e05aea49106b778:/src/file_handler/file_strategies/layout.rs diff --git a/src/file_handler/file_strategies/layout.rs b/src/file_handler/file_strategies/layout.rs index f51bf7a..41acde1 100644 --- a/src/file_handler/file_strategies/layout.rs +++ b/src/file_handler/file_strategies/layout.rs @@ -22,6 +22,109 @@ impl FileHandlerStrategy for Strategy { // We don't implement handling for layout, as we assume there's only one // and it got handled before. - fn handle_html(&self, _s: &PathBuf, _d: &PathBuf, _f: &File, _l: &String) {} + fn handle_html(&self, _s: &PathBuf, _d: &PathBuf, _f: &File, _l: &str) {} fn handle_gemini(&self, _s: &PathBuf, _d: &PathBuf, _f: &File) {} } + +#[cfg(test)] +mod tests { + use std::fs::create_dir_all; + + use super::*; + + use test_utilities::*; + + #[test] + fn identifies_layout_file() { + let test_dir = setup_test_dir(); + create_test_file(&test_dir.join("_layout.html"), ""); + let strategy = Strategy {}; + assert!(strategy.is(&test_dir.join("_layout.html"))); + } + + #[test] + fn rejects_non_layout_html() { + let test_dir = setup_test_dir(); + create_test_file(&test_dir.join("regular.html"), ""); + let strategy = Strategy {}; + assert!(!strategy.is(&test_dir.join("regular.html"))); + } + + #[test] + fn rejects_layout_with_different_extension() { + let test_dir = setup_test_dir(); + create_test_file(&test_dir.join("_layout.txt"), ""); + let strategy = Strategy {}; + assert!(!strategy.is(&test_dir.join("_layout.txt"))); + } + + #[test] + fn rejects_layout_with_prefix() { + let test_dir = setup_test_dir(); + create_test_file(&test_dir.join("prefix_layout.txt"), ""); + let strategy = Strategy {}; + assert!(!strategy.is(&test_dir.join("prefix_layout.txt"))); + } + + #[test] + fn rejects_directory_named_layout() { + let test_dir = setup_test_dir(); + let layout_dir = test_dir.join("_layout"); + create_dir_all(&layout_dir) + .expect("Could not create _layout test directory"); + let strategy = Strategy {}; + assert!(!strategy.is(&layout_dir)); + } + + #[test] + fn identifies_layout_type() { + let strategy = Strategy {}; + assert!(matches!(strategy.identify(), FileType::Layout)); + } + + #[test] + fn handles_layout_type() { + let strategy = Strategy {}; + assert!(strategy.can_handle(&FileType::Layout)); + } + + #[test] + fn rejects_non_layout_types() { + let strategy = Strategy {}; + assert!(!strategy.can_handle(&FileType::File)); + assert!(!strategy.can_handle(&FileType::Gemini)); + assert!(!strategy.can_handle(&FileType::Unknown)); + } + + #[test] + fn handle_html_does_nothing() { + let strategy = Strategy {}; + let file = File { + path: PathBuf::from("_layout.html"), + file_type: FileType::Layout, + }; + + strategy.handle_html( + &PathBuf::from("source"), + &PathBuf::from("dest"), + &file, + "layout content" + ); + } + + #[test] + fn handle_gemini_does_nothing() { + let strategy = Strategy {}; + let file = File { + path: PathBuf::from("test.gmi"), + file_type: FileType::Layout, + }; + + // Should not panic + strategy.handle_gemini( + &PathBuf::from("source"), + &PathBuf::from("dest"), + &file + ); + } +}