extern crate rustache;
use rustache::{HashBuilder, Render, VecBuilder};
use std::io::Cursor;
#[test]
fn test_spec_partials_basic_behavior() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render("\"{{>test_data/test_spec_partials_basic}}\"", &mut rv).unwrap();
assert_eq!("\"from partial\"".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_failed_lookup() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render("\"{{>text}}\"", &mut rv).unwrap();
assert_eq!("\"\"".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_context() {
let data = HashBuilder::new().insert("text", "content");
let mut rv = Cursor::new(Vec::new());
data.render("\"{{>test_data/test_spec_partials_context}}\"", &mut rv).unwrap();
assert_eq!("\"*content*\"".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_recursion() {
let data = HashBuilder::new()
.insert("content", "X")
.insert("nodes", VecBuilder::new()
.push(HashBuilder::new()
.insert("content", "Y")
.insert("nodes", VecBuilder::new()
)
)
);
let mut rv = Cursor::new(Vec::new());
data.render("{{>test_data/test_spec_partials_recursion}}", &mut rv).unwrap();
assert_eq!("X<Y<>>".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_surrounding_whitespace() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render("| {{>test_data/test_spec_partials_whitespace}} |", &mut rv).unwrap();
assert_eq!("| \t|\t |".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_inline_indentation() {
let data = HashBuilder::new().insert("data", "|");
let mut rv = Cursor::new(Vec::new());
data.render(" {{data}} {{> test_data/test_spec_partials_inline_indentation}}\n", &mut rv).unwrap();
assert_eq!(" | >\n>\n".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
#[ignore]
fn test_spec_partials_standalone_line_endings() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render("|\r\n{{>partial}}\r\n|", &mut rv).unwrap();
assert_eq!("|\r\n>|".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_standalone_without_previous_line() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render(" {{>test_data/test_spec_partials_standalone_without_previous_line}}\n>", &mut rv).unwrap();
assert_eq!(" >\n>\n>".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_standalone_without_newline() {
let data = HashBuilder::new();
let mut rv = Cursor::new(Vec::new());
data.render(">\n {{>test_data/test_spec_partials_standalone_without_newline}}", &mut rv).unwrap();
assert_eq!(">\n >\n>".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
#[ignore]
fn test_spec_partials_standalone_indentation() {
let data = HashBuilder::new().insert("content", "<\n->");
let mut rv = Cursor::new(Vec::new());
data.render("|\n\\\n {{>test_data/test_spec_partials_standalone_indentation}}\n/\n", &mut rv).unwrap();
assert_eq!("|\n\\\n |\n <\n ->\n |\n/\n".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}
#[test]
fn test_spec_partials_padding_whitespace() {
let data = HashBuilder::new()
.insert("boolean", true);
let mut rv = Cursor::new(Vec::new());
data.render("|{{> test_data/test_spec_partials_padding_whitespace }}|", &mut rv).unwrap();
assert_eq!("|[]|".to_string(), String::from_utf8(rv.into_inner()).unwrap());
}