Skip to content

Commit

Permalink
Add more next/previous tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacwah committed Nov 13, 2017
1 parent 7ffb4ab commit 6ca14cc
Showing 1 changed file with 65 additions and 7 deletions.
72 changes: 65 additions & 7 deletions src/renderer/html_handlebars/helpers/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
mod tests {
use super::*;

static TEMPLATE: &'static str =
"{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}";

#[test]
fn test_next_previous() {
let template = "
{{#previous}}{{title}}: {{link}}{{/previous}}
{{#next}}{{title}}: {{link}}{{/next}}";

let data = json!({
"name": "two",
"path": "two.path",
Expand All @@ -169,8 +168,67 @@ mod tests {
h.register_helper("previous", Box::new(previous));
h.register_helper("next", Box::new(next));

assert_eq!(h.template_render(template, &data).unwrap(), "
one: one.html
three: three.html");
assert_eq!(
h.template_render(TEMPLATE, &data).unwrap(),
"one: one.html|three: three.html");
}

#[test]
fn test_first() {
let data = json!({
"name": "one",
"path": "one.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});

let mut h = Handlebars::new();
h.register_helper("previous", Box::new(previous));
h.register_helper("next", Box::new(next));

assert_eq!(
h.template_render(TEMPLATE, &data).unwrap(),
"|two: two.html");
}
#[test]
fn test_last() {
let data = json!({
"name": "three",
"path": "three.path",
"chapters": [
{
"name": "one",
"path": "one.path"
},
{
"name": "two",
"path": "two.path",
},
{
"name": "three",
"path": "three.path"
}
]
});

let mut h = Handlebars::new();
h.register_helper("previous", Box::new(previous));
h.register_helper("next", Box::new(next));

assert_eq!(
h.template_render(TEMPLATE, &data).unwrap(),
"two: two.html|");
}
}

0 comments on commit 6ca14cc

Please sign in to comment.