|
@@ -164,4 +164,81 @@ mod tests {
|
164
|
164
|
|
165
|
165
|
fs::remove_dir_all(project_dir).unwrap();
|
166
|
166
|
}
|
|
167
|
+
|
|
168
|
+ #[test]
|
|
169
|
+ fn test_build() {
|
|
170
|
+ let temp_dir = env::temp_dir();
|
|
171
|
+ let uuid = Uuid::new_v4().to_string();
|
|
172
|
+ let project_dir = temp_dir.join(&uuid);
|
|
173
|
+ fs::create_dir(&project_dir).unwrap();
|
|
174
|
+ env::set_current_dir(&project_dir).unwrap();
|
|
175
|
+
|
|
176
|
+ fs::create_dir(project_dir.join("posts")).unwrap();
|
|
177
|
+ fs::create_dir(project_dir.join("public")).unwrap();
|
|
178
|
+ fs::create_dir(project_dir.join("templates")).unwrap();
|
|
179
|
+ fs::create_dir(project_dir.join("css")).unwrap();
|
|
180
|
+ fs::create_dir(project_dir.join("js")).unwrap();
|
|
181
|
+
|
|
182
|
+ fs::write(
|
|
183
|
+ project_dir.join("css").join("style.css"),
|
|
184
|
+ "body { background: blue; }",
|
|
185
|
+ ).unwrap();
|
|
186
|
+ fs::write(
|
|
187
|
+ project_dir.join("js").join("index.js"),
|
|
188
|
+ "window.onload = function () { alert() }",
|
|
189
|
+ ).unwrap();
|
|
190
|
+ fs::write(
|
|
191
|
+ project_dir.join("templates").join("layout.html"),
|
|
192
|
+ "<html><head><title>Test</title></head><body>{{ contents }}</body></html>",
|
|
193
|
+ ).unwrap();
|
|
194
|
+ fs::write(
|
|
195
|
+ project_dir.join("templates").join("post.html"),
|
|
196
|
+ "<article><h1>{{ title }}</h1><div>{{ body }}</div></article>",
|
|
197
|
+ ).unwrap();
|
|
198
|
+ fs::write(
|
|
199
|
+ project_dir.join("templates").join("post_listing.html"),
|
|
200
|
+ "<ul>{{ post_listing }}</ul>",
|
|
201
|
+ ).unwrap();
|
|
202
|
+ fs::write(
|
|
203
|
+ project_dir.join("templates").join("post_listing_item.html"),
|
|
204
|
+ "<li><a href=\"/{{ slug }}\">{{ title }}</a></li>",
|
|
205
|
+ ).unwrap();
|
|
206
|
+ fs::write(
|
|
207
|
+ project_dir.join("posts").join("first-post.md"),
|
|
208
|
+ "# First post\n\nThis is the first post\n\nIt has multiple paragraphs",
|
|
209
|
+ ).unwrap();
|
|
210
|
+
|
|
211
|
+ build();
|
|
212
|
+
|
|
213
|
+ assert_eq!(
|
|
214
|
+ "<html><head><title>Test</title></head><body><ul><li><a href=\"/fir\
|
|
215
|
+ st-post\">First post</a></li></ul></body></html>",
|
|
216
|
+ fs::read_to_string(project_dir.join("public").join("index.html")).unwrap(),
|
|
217
|
+ );
|
|
218
|
+
|
|
219
|
+ assert_eq!(
|
|
220
|
+ "<html><head><title>Test</title></head><body><article><h1>First pos\
|
|
221
|
+ t</h1><div><p>This is the first post</p><p>It has multiple paragra\
|
|
222
|
+ phs</p></div></article></body></html>",
|
|
223
|
+ fs::read_to_string(
|
|
224
|
+ project_dir
|
|
225
|
+ .join("public")
|
|
226
|
+ .join("first-post")
|
|
227
|
+ .join("index.html")
|
|
228
|
+ ).unwrap()
|
|
229
|
+ .replace("\n", ""),
|
|
230
|
+ );
|
|
231
|
+
|
|
232
|
+ assert_eq!(
|
|
233
|
+ "body { background: blue; }",
|
|
234
|
+ fs::read_to_string(project_dir.join("public").join("css").join("style.css")).unwrap()
|
|
235
|
+ );
|
|
236
|
+
|
|
237
|
+ assert_eq!(
|
|
238
|
+ "window.onload = function () { alert() }",
|
|
239
|
+ fs::read_to_string(project_dir.join("public").join("js").join("index.js")).unwrap()
|
|
240
|
+ );
|
|
241
|
+
|
|
242
|
+ fs::remove_dir_all(project_dir).unwrap();
|
|
243
|
+ }
|
167
|
244
|
}
|