From 5be6479f2c4fc68b9a62f9359dda673be76ada15 Mon Sep 17 00:00:00 2001 From: Qian Linfeng Date: Sat, 20 Oct 2018 13:46:48 +0800 Subject: Add test for unescaped variable expressions (see #132) --- testing/templates/simple-no-escape.txt | 5 +++++ testing/tests/simple.rs | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 testing/templates/simple-no-escape.txt diff --git a/testing/templates/simple-no-escape.txt b/testing/templates/simple-no-escape.txt new file mode 100644 index 0000000..cc839dc --- /dev/null +++ b/testing/templates/simple-no-escape.txt @@ -0,0 +1,5 @@ +{# our very first test! #} +hello world, {{ strvar }} +with number: {{ num }} +Iñtërnâtiônàlizætiøn is important +in vars too: {{ i18n }} diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index e19b32e..d4d2964 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -30,6 +30,30 @@ fn test_variables() { assert_eq!(VariablesTemplate::extension(), Some("html")); } +#[derive(Template)] +#[template(path = "simple-no-escape.txt")] +struct VariablesTemplateNoEscape<'a> { + strvar: &'a str, + num: i64, + i18n: String, +} + +#[test] +fn test_variables_no_escape() { + let s = VariablesTemplateNoEscape { + strvar: "foo", + num: 42, + i18n: "Iñtërnâtiônàlizætiøn".to_string(), + }; + assert_eq!( + s.render().unwrap(), + "\nhello world, foo\n\ + with number: 42\n\ + Iñtërnâtiônàlizætiøn is important\n\ + in vars too: Iñtërnâtiônàlizætiøn" + ); +} + #[derive(Template)] #[template(path = "if.html")] struct IfTemplate { -- cgit