]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add test cases for quotes and expand coverage to include Markup input
authorErik Johnson <palehose@gmail.com>
Mon, 19 Mar 2018 19:18:27 +0000 (14:18 -0500)
committerErik Johnson <palehose@gmail.com>
Mon, 19 Mar 2018 19:18:27 +0000 (14:18 -0500)
tests/test_filters.py

index 8962ced30028a4dd333ed3c65c7e020a894b185a..eee5d35acc03aa8fa63f3bbf9d4560ca5d8f55ac 100644 (file)
@@ -135,17 +135,22 @@ class TestFilter(object):
         out = tmpl.render()
         assert out == 'a|b'
 
-    def test_indent(self, env):
-        text = '\n'.join(['', 'foo bar', ''])
+    @staticmethod
+    def _test_indent_multiline_template(env, markup=False):
+        text = '\n'.join(['', 'foo bar', '"baz"', ''])
+        if markup:
+            text = Markup(text)
         t = env.from_string('{{ foo|indent(2, false, false) }}')
-        assert t.render(foo=text) == '\n  foo bar\n'
+        assert t.render(foo=text) == '\n  foo bar\n  "baz"\n'
         t = env.from_string('{{ foo|indent(2, false, true) }}')
-        assert t.render(foo=text) == '\n  foo bar\n  '
+        assert t.render(foo=text) == '\n  foo bar\n  "baz"\n  '
         t = env.from_string('{{ foo|indent(2, true, false) }}')
-        assert t.render(foo=text) == '  \n  foo bar\n'
+        assert t.render(foo=text) == '  \n  foo bar\n  "baz"\n'
         t = env.from_string('{{ foo|indent(2, true, true) }}')
-        assert t.render(foo=text) == '  \n  foo bar\n  '
+        assert t.render(foo=text) == '  \n  foo bar\n  "baz"\n  '
 
+    def test_indent(self, env):
+        self._test_indent_multiline_template(env)
         t = env.from_string('{{ "jinja"|indent }}')
         assert t.render() == 'jinja'
         t = env.from_string('{{ "jinja"|indent(first=true) }}')
@@ -153,6 +158,12 @@ class TestFilter(object):
         t = env.from_string('{{ "jinja"|indent(blank=true) }}')
         assert t.render() == 'jinja'
 
+    def test_indent_markup_input(self, env):
+        '''
+        Tests casses where the filter input is a Markup type
+        '''
+        self._test_indent_multiline_template(env, markup=True)
+
     def test_indentfirst_deprecated(self, env):
         with pytest.warns(DeprecationWarning):
             env.from_string('{{ "jinja"|indent(indentfirst=true) }}').render()