|
@@ -36,7 +36,7 @@ pub fn render_post_listing(
|
36
|
36
|
|
37
|
37
|
mod tests {
|
38
|
38
|
#[allow(unused_imports)]
|
39
|
|
- use super::render_post;
|
|
39
|
+ use super::{render_post, render_post_listing, Post};
|
40
|
40
|
|
41
|
41
|
#[test]
|
42
|
42
|
fn test_render_post() {
|
|
@@ -57,4 +57,39 @@ mod tests {
|
57
|
57
|
&output,
|
58
|
58
|
);
|
59
|
59
|
}
|
|
60
|
+
|
|
61
|
+ #[test]
|
|
62
|
+ fn test_render_post_listing() {
|
|
63
|
+ let posts = vec![
|
|
64
|
+ Post {
|
|
65
|
+ title: String::from("First post"),
|
|
66
|
+ body: String::from("lorem ipsum dolor sit amet"),
|
|
67
|
+ slug: String::from("first-post"),
|
|
68
|
+ },
|
|
69
|
+ Post {
|
|
70
|
+ title: String::from("Second post"),
|
|
71
|
+ body: String::from("lorem ipsum dolor sit amet"),
|
|
72
|
+ slug: String::from("second-post"),
|
|
73
|
+ },
|
|
74
|
+ Post {
|
|
75
|
+ title: String::from("Third post"),
|
|
76
|
+ body: String::from("lorem ipsum dolor sit amet"),
|
|
77
|
+ slug: String::from("third-post"),
|
|
78
|
+ },
|
|
79
|
+ ];
|
|
80
|
+ let output = render_post_listing(
|
|
81
|
+ "<html><head><title>Test</title></head><body>{{ contents }}</body></html>",
|
|
82
|
+ "<ul>{{ post_listing }}</ul>",
|
|
83
|
+ "<li><a href=\"/{{ slug }}\">{{ title }}</a></li>",
|
|
84
|
+ &posts,
|
|
85
|
+ ).replace("\n", "");
|
|
86
|
+
|
|
87
|
+ assert_eq!(
|
|
88
|
+ "<html><head><title>Test</title></head><body><ul><li><a href=\"/fir\
|
|
89
|
+ st-post\">First post</a></li><li><a href=\"/second-post\">Second po\
|
|
90
|
+ st</a></li><li><a href=\"/third-post\">Third post</a></li></ul></bo\
|
|
91
|
+ dy></html>",
|
|
92
|
+ &output,
|
|
93
|
+ );
|
|
94
|
+ }
|
60
|
95
|
}
|