From: Ben Darnell Date: Thu, 8 May 2014 03:06:01 +0000 (-0400) Subject: Add a test with newlines in template tags to control whitespace in output. X-Git-Tag: v4.0.0b1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7849162cfcbe378f4098af845e0e8e7941b88448;p=thirdparty%2Ftornado.git Add a test with newlines in template tags to control whitespace in output. --- diff --git a/tornado/test/template_test.py b/tornado/test/template_test.py index 32bbe4217..e9291d16d 100644 --- a/tornado/test/template_test.py +++ b/tornado/test/template_test.py @@ -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):