]> git.r.bdr.sh - rbdr/page/blobdiff - src/file_handler/file_strategies/layout.rs
Add first tests
[rbdr/page] / src / file_handler / file_strategies / layout.rs
index 21ce9ba66aa4f520cfc6c2fd804bf6ef66c5fc40..44b5000052dea5941a9d75c6b2ca8c1ef1e371cc 100644 (file)
@@ -22,5 +22,121 @@ 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(&self, _s: &PathBuf, _d: &PathBuf, _f: &File) {}
+    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 super::*;
+    use std::path::PathBuf;
+
+    fn setup() -> Strategy {
+        Strategy {}
+    }
+
+    mod is_tests {
+        use super::*;
+
+        #[test]
+        fn identifies_layout_file() {
+            let strategy = setup();
+            let path = PathBuf::from("_layout.html");
+            assert!(strategy.is(&path));
+        }
+
+        #[test]
+        fn rejects_non_layout_html() {
+            let strategy = setup();
+            let path = PathBuf::from("regular.html");
+            assert!(!strategy.is(&path));
+        }
+
+        #[test]
+        fn rejects_layout_with_different_extension() {
+            let strategy = setup();
+            let path = PathBuf::from("_layout.txt");
+            assert!(!strategy.is(&path));
+        }
+
+        #[test]
+        fn rejects_layout_with_prefix() {
+            let strategy = setup();
+            let path = PathBuf::from("prefix_layout.html");
+            assert!(!strategy.is(&path));
+        }
+
+        #[test]
+        fn rejects_directory_named_layout() {
+            let strategy = setup();
+            let path = PathBuf::from("tests/fixtures");
+
+            assert!(!strategy.is(&path));
+        }
+    }
+
+    mod identify_tests {
+        use super::*;
+
+        #[test]
+        fn returns_layout_type() {
+            let strategy = setup();
+            assert!(matches!(strategy.identify(), FileType::Layout));
+        }
+    }
+
+    mod can_handle_tests {
+        use super::*;
+
+        #[test]
+        fn handles_layout_type() {
+            let strategy = setup();
+            assert!(strategy.can_handle(&FileType::Layout));
+        }
+
+        #[test]
+        fn rejects_non_layout_types() {
+            let strategy = setup();
+            assert!(!strategy.can_handle(&FileType::File));
+            assert!(!strategy.can_handle(&FileType::Gemini));
+            assert!(!strategy.can_handle(&FileType::Unknown));
+        }
+    }
+
+    mod handle_methods {
+        use super::*;
+
+        #[test]
+        fn handle_html_does_nothing() {
+            let strategy = setup();
+            let file = File {
+                path: PathBuf::from("test.html"),
+                file_type: FileType::Layout,
+            };
+
+            // Should not panic
+            strategy.handle_html(
+                &PathBuf::from("source"),
+                &PathBuf::from("dest"),
+                &file,
+                "layout content"
+            );
+        }
+
+        #[test]
+        fn handle_gemini_does_nothing() {
+            let strategy = setup();
+            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
+            );
+        }
+    }
 }