use kitamura::render_template;
use serde_json::json;
use std::collections::HashMap;
#[test]
fn variable_formatting_incorrect() {
let html = "${{first_name}";
let params = HashMap::new();
let rendered_html = render_template(html.to_string(), params);
assert!(rendered_html.is_err())
}
#[test]
fn variable_extra_open_brace() {
let html = "${{first_name}";
let params = HashMap::new();
let rendered_html = render_template(html.to_string(), params);
assert!(rendered_html.is_err())
}
#[test]
fn nested_loops_correctly_get_children_nodes() {
let html = "
{#for continent of continents#}
- ${continent.name}
{#for country of countries#}
- ${country.name}
{#endfor#}
{#endfor#}
";
let expected_rendered_html = "
";
let mut params = HashMap::new();
params.insert(
"continents".to_string(),
json!([
{
"countries": [
{
"name": "Australia"
},
{
"name": "New Zealand"
}
],
"name": "Oceania"
}
]
),
);
let rendered_html = render_template(html.to_string(), params).unwrap();
assert_eq!(rendered_html, expected_rendered_html);
}
#[test]
fn whitespace_after_control_flow_statement_removed() {
let html = "
{#for person of persons#}
- ${person.first_name}
{#endfor#}
";
let expected_rendered_html = "
";
let mut params = HashMap::new();
params.insert(
"persons".to_string(),
json!({"persons":[{"first_name": "Joel"}]}),
);
let rendered_html = render_template(html.to_string(), params);
assert_eq!(rendered_html.unwrap(), expected_rendered_html);
}