summaryrefslogtreecommitdiff
path: root/tests/regressiontests/templates/parser.py
blob: 6ad301d9c361847dbe48c48d9b4b456bff0aff32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Testing some internals of the template processing. These are *not* examples to be copied in user code.
"""

filter_parsing = r"""
>>> from django.template import FilterExpression, Parser

>>> c = {'article': {'section': u'News'}}
>>> p = Parser("")
>>> def fe_test(s): return FilterExpression(s, p).resolve(c)

>>> fe_test('article.section')
u'News'
>>> fe_test('article.section|upper')
u'NEWS'
>>> fe_test(u'"News"')
u'News'
>>> fe_test(u"'News'")
u'News'
>>> fe_test(ur'"Some \"Good\" News"')
u'Some "Good" News'
>>> fe_test(ur"'Some \'Bad\' News'")
u"Some 'Bad' News"

>>> fe = FilterExpression(ur'"Some \"Good\" News"', p)
>>> fe.filters
[]
>>> fe.var
u'Some "Good" News'
"""

variable_parsing = r"""
>>> from django.template import Variable

>>> c = {'article': {'section': u'News'}}
>>> Variable('article.section').resolve(c)
u'News'
>>> Variable(u'"News"').resolve(c)
u'News'
>>> Variable(u"'News'").resolve(c)
u'News'

Translated strings are handled correctly.

>>> Variable('_(article.section)').resolve(c)
u'News'
>>> Variable('_("Good News")').resolve(c)
u'Good News'
>>> Variable("_('Better News')").resolve(c)
u'Better News'

Escaped quotes work correctly as well.

>>> Variable(ur'"Some \"Good\" News"').resolve(c)
u'Some "Good" News'
>>> Variable(ur"'Some \'Better\' News'").resolve(c)
u"Some 'Better' News"

"""