]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a test with newlines in template tags to control whitespace in output.
authorBen Darnell <ben@bendarnell.com>
Thu, 8 May 2014 03:06:01 +0000 (23:06 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 8 May 2014 03:06:01 +0000 (23:06 -0400)
tornado/test/template_test.py

index 32bbe42170680191f958f677ac8b13e9cf286226..e9291d16d0f72dd5ff1f0cf1afc53a5441ec03b5 100644 (file)
@@ -387,6 +387,20 @@ raw: {% raw name %}""",
         self.assertEqual(render("foo.py", ["not a string"]),
                          b"""s = "['not a string']"\n""")
 
+    def test_minimize_whitespace(self):
+        # Whitespace including newlines is allowed within template tags
+        # and directives, and this is one way to avoid long lines while
+        # keeping extra whitespace out of the rendered output.
+        loader = DictLoader({'foo.txt': """\
+{% for i in items
+  %}{% if i > 0 %}, {% end %}{#
+  #}{{i
+  }}{% end
+%}""",
+                         })
+        self.assertEqual(loader.load("foo.txt").generate(items=range(5)),
+                         b"0, 1, 2, 3, 4")
+
 
 class TemplateLoaderTest(unittest.TestCase):
     def setUp(self):