1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
pub struct Strategy {}
use std::path::PathBuf;
use crate::file_handler::{File, FileType, FileHandlerStrategy};
impl FileHandlerStrategy for Strategy {
fn is(&self, path: &PathBuf) -> bool {
return !path.is_dir() && path.ends_with("_layout.html");
}
fn identify(&self) -> FileType {
FileType::Layout
}
fn can_handle(&self, file_type: &FileType) -> bool {
match file_type {
FileType::Layout => true,
_ => false,
}
}
// 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: &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
);
}
}
}
|