aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests
diff options
context:
space:
mode:
authorLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2022-04-21 16:44:10 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-04-26 10:15:34 +0200
commit07cee10876a9b299a586bbb50f7029f0f1bba6fc (patch)
treef5e373b408454783c58b7bcc98695e6f65a3e11d /testing/tests
parentf6423a2be4cb62edd7189842c59c6ec903a4d900 (diff)
downloadaskama-07cee10876a9b299a586bbb50f7029f0f1bba6fc.tar.gz
askama-07cee10876a9b299a586bbb50f7029f0f1bba6fc.tar.bz2
askama-07cee10876a9b299a586bbb50f7029f0f1bba6fc.zip
Add test for "minimize" config
Diffstat (limited to 'testing/tests')
-rw-r--r--testing/tests/whitespace.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/tests/whitespace.rs b/testing/tests/whitespace.rs
index cbcddd7..d38fdaa 100644
--- a/testing/tests/whitespace.rs
+++ b/testing/tests/whitespace.rs
@@ -41,3 +41,46 @@ fn test_extra_whitespace() {
template.nested_1.nested_2.hash.insert("key", "value");
assert_eq!(template.render().unwrap(), "\n0\n0\n0\n0\n\n\n\n0\n0\n0\n0\n0\n\na0\na1\nvalue\n\n\n\n\n\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n][\n &quot;a0&quot;,\n &quot;a1&quot;,\n &quot;a2&quot;,\n &quot;a3&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]\n[\n &quot;a1&quot;,\n &quot;a2&quot;\n][\n &quot;a1&quot;,\n &quot;a2&quot;\n]\n[\n &quot;a1&quot;\n][\n &quot;a1&quot;\n]1-1-1\n3333 3\n2222 2\n0000 0\n3333 3\n\ntruefalse\nfalsefalsefalse\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}
+
+macro_rules! test_template_minimize {
+ ($source:literal, $rendered:expr) => {{
+ #[derive(Template)]
+ #[template(source = $source, ext = "txt", config = "test_minimize.toml")]
+ struct CondWs;
+
+ assert_eq!(CondWs.render().unwrap(), $rendered);
+ }};
+}
+
+macro_rules! test_template {
+ ($source:literal, $rendered:expr) => {{
+ #[derive(Template)]
+ #[template(source = $source, ext = "txt")]
+ struct CondWs;
+
+ assert_eq!(CondWs.render().unwrap(), $rendered);
+ }};
+}
+
+#[test]
+fn test_minimize_whitespace() {
+ test_template_minimize!(
+ "\n1\r\n{% if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n",
+ "\n1\n\n2\n 3"
+ );
+ test_template_minimize!(
+ "\n1\r\n{%+ if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n",
+ "\n1\r\n\n2\n 3"
+ );
+ test_template_minimize!(
+ "\n1\r\n{%- if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n",
+ "\n1\n2\n 3"
+ );
+ test_template_minimize!(" \n1 \n{% if true %} 2 {% endif %}3 ", " \n1\n 2 3");
+
+ test_template!(
+ "\n1\r\n{%~ if true ~%}\n\n2\r\n\r\n{%~ endif ~%} 3\r\n\r\n\r\n",
+ "\n1\n\n2\n 3"
+ );
+ test_template!(" \n1 \n{%~ if true ~%} 2 {%~ endif ~%}3 ", " \n1\n 2 3");
+}