3 use std::path::PathBuf;
5 use crate::file_handler::{File, FileType, FileHandlerStrategy};
7 impl FileHandlerStrategy for Strategy {
8 fn is(&self, path: &PathBuf) -> bool {
9 return !path.is_dir() && path.ends_with("_layout.html");
12 fn identify(&self) -> FileType {
16 fn can_handle(&self, file_type: &FileType) -> bool {
18 FileType::Layout => true,
23 // We don't implement handling for layout, as we assume there's only one
24 // and it got handled before.
25 fn handle_html(&self, _s: &PathBuf, _d: &PathBuf, _f: &File, _l: &str) {}
26 fn handle_gemini(&self, _s: &PathBuf, _d: &PathBuf, _f: &File) {}
32 use std::path::PathBuf;
34 fn setup() -> Strategy {
42 fn identifies_layout_file() {
43 let strategy = setup();
44 let path = PathBuf::from("_layout.html");
45 assert!(strategy.is(&path));
49 fn rejects_non_layout_html() {
50 let strategy = setup();
51 let path = PathBuf::from("regular.html");
52 assert!(!strategy.is(&path));
56 fn rejects_layout_with_different_extension() {
57 let strategy = setup();
58 let path = PathBuf::from("_layout.txt");
59 assert!(!strategy.is(&path));
63 fn rejects_layout_with_prefix() {
64 let strategy = setup();
65 let path = PathBuf::from("prefix_layout.html");
66 assert!(!strategy.is(&path));
70 fn rejects_directory_named_layout() {
71 let strategy = setup();
72 let path = PathBuf::from("tests/fixtures");
74 assert!(!strategy.is(&path));
82 fn returns_layout_type() {
83 let strategy = setup();
84 assert!(matches!(strategy.identify(), FileType::Layout));
88 mod can_handle_tests {
92 fn handles_layout_type() {
93 let strategy = setup();
94 assert!(strategy.can_handle(&FileType::Layout));
98 fn rejects_non_layout_types() {
99 let strategy = setup();
100 assert!(!strategy.can_handle(&FileType::File));
101 assert!(!strategy.can_handle(&FileType::Gemini));
102 assert!(!strategy.can_handle(&FileType::Unknown));
110 fn handle_html_does_nothing() {
111 let strategy = setup();
113 path: PathBuf::from("test.html"),
114 file_type: FileType::Layout,
118 strategy.handle_html(
119 &PathBuf::from("source"),
120 &PathBuf::from("dest"),
127 fn handle_gemini_does_nothing() {
128 let strategy = setup();
130 path: PathBuf::from("test.gmi"),
131 file_type: FileType::Layout,
135 strategy.handle_gemini(
136 &PathBuf::from("source"),
137 &PathBuf::from("dest"),