Skip to content

Commit 6ca14cc

Browse files
committed
Add more next/previous tests
1 parent 7ffb4ab commit 6ca14cc

File tree

1 file changed

+65
-7
lines changed

1 file changed

+65
-7
lines changed

src/renderer/html_handlebars/helpers/navigation.rs

+65-7
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
140140
mod tests {
141141
use super::*;
142142

143+
static TEMPLATE: &'static str =
144+
"{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}";
145+
143146
#[test]
144147
fn test_next_previous() {
145-
let template = "
146-
{{#previous}}{{title}}: {{link}}{{/previous}}
147-
{{#next}}{{title}}: {{link}}{{/next}}";
148-
149148
let data = json!({
150149
"name": "two",
151150
"path": "two.path",
@@ -169,8 +168,67 @@ mod tests {
169168
h.register_helper("previous", Box::new(previous));
170169
h.register_helper("next", Box::new(next));
171170

172-
assert_eq!(h.template_render(template, &data).unwrap(), "
173-
one: one.html
174-
three: three.html");
171+
assert_eq!(
172+
h.template_render(TEMPLATE, &data).unwrap(),
173+
"one: one.html|three: three.html");
174+
}
175+
176+
#[test]
177+
fn test_first() {
178+
let data = json!({
179+
"name": "one",
180+
"path": "one.path",
181+
"chapters": [
182+
{
183+
"name": "one",
184+
"path": "one.path"
185+
},
186+
{
187+
"name": "two",
188+
"path": "two.path",
189+
},
190+
{
191+
"name": "three",
192+
"path": "three.path"
193+
}
194+
]
195+
});
196+
197+
let mut h = Handlebars::new();
198+
h.register_helper("previous", Box::new(previous));
199+
h.register_helper("next", Box::new(next));
200+
201+
assert_eq!(
202+
h.template_render(TEMPLATE, &data).unwrap(),
203+
"|two: two.html");
204+
}
205+
#[test]
206+
fn test_last() {
207+
let data = json!({
208+
"name": "three",
209+
"path": "three.path",
210+
"chapters": [
211+
{
212+
"name": "one",
213+
"path": "one.path"
214+
},
215+
{
216+
"name": "two",
217+
"path": "two.path",
218+
},
219+
{
220+
"name": "three",
221+
"path": "three.path"
222+
}
223+
]
224+
});
225+
226+
let mut h = Handlebars::new();
227+
h.register_helper("previous", Box::new(previous));
228+
h.register_helper("next", Box::new(next));
229+
230+
assert_eq!(
231+
h.template_render(TEMPLATE, &data).unwrap(),
232+
"two: two.html|");
175233
}
176234
}

0 commit comments

Comments
 (0)