5 use crate::file_handler::{File, FileType, Strategy as FileHandlerStrategy};
7 impl FileHandlerStrategy for Strategy {
8 fn is(&self, path: &Path) -> bool {
9 !path.is_dir() && path.ends_with("_layout.html")
12 fn identify(&self) -> FileType {
16 fn can_handle(&self, file_type: &FileType) -> bool {
17 matches!(file_type, FileType::Layout)
20 // We don't implement handling for layout, as we assume there's only one
21 // and it got handled before.
22 fn handle_html(&self, _s: &Path, _d: &Path, _f: &File, _l: &str) {}
23 fn handle_gemini(&self, _s: &Path, _d: &Path, _f: &File) {}
28 use std::fs::create_dir_all;
29 use std::path::PathBuf;
33 use test_utilities::*;
36 fn identifies_layout_file() {
37 let test_dir = setup_test_dir();
38 create_test_file(&test_dir.join("_layout.html"), "");
39 let strategy = Strategy {};
40 assert!(strategy.is(&test_dir.join("_layout.html")));
44 fn rejects_non_layout_html() {
45 let test_dir = setup_test_dir();
46 create_test_file(&test_dir.join("regular.html"), "");
47 let strategy = Strategy {};
48 assert!(!strategy.is(&test_dir.join("regular.html")));
52 fn rejects_layout_with_different_extension() {
53 let test_dir = setup_test_dir();
54 create_test_file(&test_dir.join("_layout.txt"), "");
55 let strategy = Strategy {};
56 assert!(!strategy.is(&test_dir.join("_layout.txt")));
60 fn rejects_layout_with_prefix() {
61 let test_dir = setup_test_dir();
62 create_test_file(&test_dir.join("prefix_layout.txt"), "");
63 let strategy = Strategy {};
64 assert!(!strategy.is(&test_dir.join("prefix_layout.txt")));
68 fn rejects_directory_named_layout() {
69 let test_dir = setup_test_dir();
70 let layout_dir = test_dir.join("_layout");
71 create_dir_all(&layout_dir).expect("Could not create _layout test directory");
72 let strategy = Strategy {};
73 assert!(!strategy.is(&layout_dir));
77 fn identifies_layout_type() {
78 let strategy = Strategy {};
79 assert!(matches!(strategy.identify(), FileType::Layout));
83 fn handles_layout_type() {
84 let strategy = Strategy {};
85 assert!(strategy.can_handle(&FileType::Layout));
89 fn rejects_non_layout_types() {
90 let strategy = Strategy {};
91 assert!(!strategy.can_handle(&FileType::File));
92 assert!(!strategy.can_handle(&FileType::Gemini));
93 assert!(!strategy.can_handle(&FileType::Unknown));
97 fn handle_html_does_nothing() {
98 let strategy = Strategy {};
100 path: PathBuf::from("_layout.html"),
101 file_type: FileType::Layout,
104 strategy.handle_html(
105 &PathBuf::from("source"),
106 &PathBuf::from("dest"),
113 fn handle_gemini_does_nothing() {
114 let strategy = Strategy {};
116 path: PathBuf::from("test.gmi"),
117 file_type: FileType::Layout,
121 strategy.handle_gemini(&PathBuf::from("source"), &PathBuf::from("dest"), &file);