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) {}
31 use std::fs::create_dir_all;
35 use test_utilities::*;
38 fn identifies_layout_file() {
39 let test_dir = setup_test_dir();
40 create_test_file(&test_dir.join("_layout.html"), "");
41 let strategy = Strategy {};
42 assert!(strategy.is(&test_dir.join("_layout.html")));
46 fn rejects_non_layout_html() {
47 let test_dir = setup_test_dir();
48 create_test_file(&test_dir.join("regular.html"), "");
49 let strategy = Strategy {};
50 assert!(!strategy.is(&test_dir.join("regular.html")));
54 fn rejects_layout_with_different_extension() {
55 let test_dir = setup_test_dir();
56 create_test_file(&test_dir.join("_layout.txt"), "");
57 let strategy = Strategy {};
58 assert!(!strategy.is(&test_dir.join("_layout.txt")));
62 fn rejects_layout_with_prefix() {
63 let test_dir = setup_test_dir();
64 create_test_file(&test_dir.join("prefix_layout.txt"), "");
65 let strategy = Strategy {};
66 assert!(!strategy.is(&test_dir.join("prefix_layout.txt")));
70 fn rejects_directory_named_layout() {
71 let test_dir = setup_test_dir();
72 let layout_dir = test_dir.join("_layout");
73 create_dir_all(&layout_dir)
74 .expect("Could not create _layout test directory");
75 let strategy = Strategy {};
76 assert!(!strategy.is(&layout_dir));
80 fn identifies_layout_type() {
81 let strategy = Strategy {};
82 assert!(matches!(strategy.identify(), FileType::Layout));
86 fn handles_layout_type() {
87 let strategy = Strategy {};
88 assert!(strategy.can_handle(&FileType::Layout));
92 fn rejects_non_layout_types() {
93 let strategy = Strategy {};
94 assert!(!strategy.can_handle(&FileType::File));
95 assert!(!strategy.can_handle(&FileType::Gemini));
96 assert!(!strategy.can_handle(&FileType::Unknown));
100 fn handle_html_does_nothing() {
101 let strategy = Strategy {};
103 path: PathBuf::from("_layout.html"),
104 file_type: FileType::Layout,
107 strategy.handle_html(
108 &PathBuf::from("source"),
109 &PathBuf::from("dest"),
116 fn handle_gemini_does_nothing() {
117 let strategy = Strategy {};
119 path: PathBuf::from("test.gmi"),
120 file_type: FileType::Layout,
124 strategy.handle_gemini(
125 &PathBuf::from("source"),
126 &PathBuf::from("dest"),