From 2d6785b71414cc70adfb24ee742e3defa5841bbb Mon Sep 17 00:00:00 2001 From: Anthony Nowell Date: Sun, 13 Aug 2017 00:46:04 -0600 Subject: Adding optional json filter --- testing/tests/simple.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'testing/tests/simple.rs') diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index 896e082..93faf50 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -1,7 +1,10 @@ #[macro_use] extern crate askama; +#[macro_use] +extern crate serde_json; use askama::Template; +use serde_json::Value; #[derive(Template)] #[template(path = "simple.html")] @@ -146,16 +149,27 @@ fn test_generics() { #[template(path = "json.html")] struct JsonTemplate<'a> { foo: &'a str, - bar: &'a str, + bar: &'a Value, } #[test] fn test_json() { - let t = JsonTemplate { foo: "a", bar: "b" }; - assert_eq!(t.render().unwrap(), "{\"foo\": \"a\", \"bar\": \"b\"}"); + let val = json!({"arr": [ "one", 2, true, null ]}); + let t = JsonTemplate { foo: "a", bar: &val }; + // Note: the json filter lacks a way to specify initial indentation + assert_eq!(t.render().unwrap(), r#"{ + "foo": "a", + "bar": { + "arr": [ + "one", + 2, + true, + null + ] +} +}"#); } - #[derive(Template)] #[template(path = "composition.html")] struct CompositionTemplate { -- cgit