diff options
-rw-r--r-- | tests/test_inheritance.py | 24 | ||||
-rw-r--r-- | tests/test_lexer.py | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index ee8296a..8884b9f 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -107,3 +107,27 @@ def test_preserve_blocks(): })) tmpl = env.get_template('b') assert tmpl.render() == 'BA' + + +def test_dynamic_inheritance(): + env = Environment(loader=DictLoader({ + 'master1': 'MASTER1{% block x %}{% endblock %}', + 'master2': 'MASTER2{% block x %}{% endblock %}', + 'child': '{% extends master %}{% block x %}CHILD{% endblock %}' + })) + tmpl = env.get_template('child') + for m in range(1, 3): + assert tmpl.render(master='master%d' % m) == 'MASTER%dCHILD' % m + + +def test_multi_inheritance(): + env = Environment(loader=DictLoader({ + 'master1': 'MASTER1{% block x %}{% endblock %}', + 'master2': 'MASTER2{% block x %}{% endblock %}', + 'child': '''{% if master %}{% extends master %}{% else %}{% extends + 'master1' %}{% endif %}{% block x %}CHILD{% endblock %}''' + })) + tmpl = env.get_template('child') + assert tmpl.render(master='master2') == 'MASTER2CHILD' + assert tmpl.render(master='master1') == 'MASTER1CHILD' + assert tmpl.render() == 'MASTER1CHILD' diff --git a/tests/test_lexer.py b/tests/test_lexer.py index a6717e9..cb1e2dc 100644 --- a/tests/test_lexer.py +++ b/tests/test_lexer.py @@ -58,3 +58,12 @@ def test_operators(env): stream = env.lexer.tokenize('{{ %s }}' % test) stream.next() assert stream.current.type == expect + + +def test_normalizing(): + from jinja2 import Environment + for seq in '\r', '\r\n', '\n': + env = Environment(newline_sequence=seq) + tmpl = env.from_string('1\n2\r\n3\n4\n') + result = tmpl.render() + assert result.replace(seq, 'X') == '1X2X3X4' |