diff options
| author | David Smith <smithdc@gmail.com> | 2021-01-29 19:21:26 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-26 10:25:08 +0100 |
| commit | 179ee13eb37348cd87169a198aec18fedccc8668 (patch) | |
| tree | b7fb8bd4e824e66de1913bfbdc97c901ea6a7f52 /tests | |
| parent | 0c7e880e13b837dd76276c04ebdc338bb76d1379 (diff) | |
Refs #24121 -- Added __repr__() to FilterExpression, Lexer, Parser, and Token.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/template_tests/test_parser.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py index 2370e0263e..6c8b70d16f 100644 --- a/tests/template_tests/test_parser.py +++ b/tests/template_tests/test_parser.py @@ -3,7 +3,7 @@ Testing some internals of the template processing. These are *not* examples to b """ from django.template import Library, TemplateSyntaxError from django.template.base import ( - FilterExpression, Parser, Token, TokenType, Variable, + FilterExpression, Lexer, Parser, Token, TokenType, Variable, ) from django.template.defaultfilters import register as filter_library from django.test import SimpleTestCase @@ -19,6 +19,22 @@ class ParserTests(SimpleTestCase): split = token.split_contents() self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")']) + def test_repr(self): + token = Token(TokenType.BLOCK, 'some text') + self.assertEqual(repr(token), '<Block token: "some text...">') + parser = Parser([token], builtins=[filter_library]) + self.assertEqual( + repr(parser), + '<Parser tokens=[<Block token: "some text...">]>', + ) + filter_expression = FilterExpression('news|upper', parser) + self.assertEqual(repr(filter_expression), "<FilterExpression 'news|upper'>") + lexer = Lexer('{% for i in 1 %}{{ a }}\n{% endfor %}') + self.assertEqual( + repr(lexer), + '<Lexer template_string="{% for i in 1 %}{{ a...", verbatim=False>', + ) + def test_filter_parsing(self): c = {"article": {"section": "News"}} p = Parser("", builtins=[filter_library]) |
