Skip to content
Myr

Added unittests for meta.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent a1704eb · Browse files · 1 file+38 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+38 added−0 removed

  • tests:+38 added−0 removed

1 file+38 added−0 removed

added:tests/test_meta.py+38 added
1# -*- coding: utf-8 -*-2"""3 unit test for the meta module4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~56 :copyright: (c) 2009 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9from jinja2 import Environment, meta101112def test_find_undeclared_variables():13 env = Environment()14 ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')15 x = meta.find_undeclared_variables(ast)16 assert x == set(['bar'])1718 ast = env.parse('{% set foo = 42 %}{{ bar + foo }}'19 '{% macro meh(x) %}{{ x }}{% endmacro %}'20 '{% for item in seq %}{{ muh(item) + meh(seq) }}{% endfor %}')21 x = meta.find_undeclared_variables(ast)22 assert x == set(['bar', 'seq', 'muh'])232425def test_find_refererenced_templates():26 env = Environment()27 ast = env.parse('{% extends "layout.html" %}{% include helper %}')28 i = meta.find_referenced_templates(ast)29 assert i.next() == 'layout.html'30 assert i.next() is None31 assert list(i) == []3233 ast = env.parse('{% extends "layout.html" %}'34 '{% from "test.html" import a, b as c %}'35 '{% import "meh.html" as meh %}'36 '{% include "muh.html" %}')37 i = meta.find_referenced_templates(ast)38 assert list(i) == ['layout.html', 'test.html', 'meh.html', 'muh.html']