~ubuntu-branches/ubuntu/oneiric/python-django/oneiric-201108291626

« back to all changes in this revision

Viewing changes to tests/regressiontests/templates/parser.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.1.10 upstream) (4.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100521075255-i1zpeyc0k8512pd7
Tags: 1.2-1
New upstream stable release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Testing some internals of the template processing. These are *not* examples to be copied in user code.
3
3
"""
4
4
 
 
5
token_parsing=r"""
 
6
Tests for TokenParser behavior in the face of quoted strings with spaces.
 
7
 
 
8
>>> from django.template import TokenParser
 
9
 
 
10
 
 
11
Test case 1: {% tag thevar|filter sometag %}
 
12
 
 
13
>>> p = TokenParser("tag thevar|filter sometag")
 
14
>>> p.tagname
 
15
'tag'
 
16
>>> p.value()
 
17
'thevar|filter'
 
18
>>> p.more()
 
19
True
 
20
>>> p.tag()
 
21
'sometag'
 
22
>>> p.more()
 
23
False
 
24
 
 
25
Test case 2: {% tag "a value"|filter sometag %}
 
26
 
 
27
>>> p = TokenParser('tag "a value"|filter sometag')
 
28
>>> p.tagname
 
29
'tag'
 
30
>>> p.value()
 
31
'"a value"|filter'
 
32
>>> p.more()
 
33
True
 
34
>>> p.tag()
 
35
'sometag'
 
36
>>> p.more()
 
37
False
 
38
 
 
39
Test case 3: {% tag 'a value'|filter sometag %}
 
40
 
 
41
>>> p = TokenParser("tag 'a value'|filter sometag")
 
42
>>> p.tagname
 
43
'tag'
 
44
>>> p.value()
 
45
"'a value'|filter"
 
46
>>> p.more()
 
47
True
 
48
>>> p.tag()
 
49
'sometag'
 
50
>>> p.more()
 
51
False
 
52
"""
 
53
 
5
54
filter_parsing = r"""
6
55
>>> from django.template import FilterExpression, Parser
7
56
 
27
76
[]
28
77
>>> fe.var
29
78
u'Some "Good" News'
 
79
 
 
80
Filtered variables should reject access of attributes beginning with underscores.
 
81
 
 
82
>>> FilterExpression('article._hidden|upper', p)
 
83
Traceback (most recent call last):
 
84
...
 
85
TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden'
30
86
"""
31
87
 
32
88
variable_parsing = r"""
56
112
>>> Variable(ur"'Some \'Better\' News'").resolve(c)
57
113
u"Some 'Better' News"
58
114
 
 
115
Variables should reject access of attributes beginning with underscores.
 
116
 
 
117
>>> Variable('article._hidden')
 
118
Traceback (most recent call last):
 
119
...
 
120
TemplateSyntaxError: Variables and attributes may not begin with underscores: 'article._hidden'
59
121
"""