Code

Ticket #7799: tplrf-tests.diff

File tplrf-tests.diff, 8.6 KB (added by emulbreh, 6 years ago)
Line 
1Index: tests/regressiontests/templates/tests.py
2===================================================================
3--- tests/regressiontests/templates/tests.py    (revision 7884)
4+++ tests/regressiontests/templates/tests.py    (working copy)
5@@ -17,6 +17,7 @@
6 from django.utils.safestring import mark_safe
7 from django.utils.tzinfo import LocalTimezone
8 
9+#from decorators import DecoratorsTest
10 from unicode import unicode_tests
11 from context import context_tests
12 
13@@ -407,6 +408,11 @@
14             'cycle13': ("{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'),
15             'cycle14': ("{% cycle one two as foo %}{% cycle foo %}", {'one': '1','two': '2'}, '12'),
16             'cycle13': ("{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}", {'test': range(5), 'aye': 'a', 'bee': 'b'}, 'a0,b1,a2,b3,a4,'),
17+           
18+            ### EMPTY STRINGS #########################################################
19+            'emptystring01': ("{{ '' }}", {}, ""),
20+            'emptystring02': ("{% ifequal foo '' %}x{% endifequal %}", {'foo': ''}, 'x'),
21+            'emptystring03': ("{% ifequal foo|default:'' foo %}x{% endifequal %}", {'foo': ''}, 'x'),
22 
23             ### EXCEPTIONS ############################################################
24 
25@@ -576,6 +582,13 @@
26             'ifequal08': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {"a": "no"}, "no"),
27             'ifequal09': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {}, "no"),
28             'ifequal10': ('{% ifequal a b %}yes{% else %}no{% endifequal %}', {}, "yes"),
29+           
30+            ## FILTER EXPRESSIONS AS ARGUMENTS ########################################
31+            'ifequal-filter01': ('{% ifequal a|upper "A" %}x{% endifequal %}', {'a': 'a'}, 'x'),
32+            'ifequal-filter02': ('{% ifequal "A" a|upper %}x{% endifequal %}', {'a': 'a'}, 'x'),
33+            'ifequal-filter03': ('{% ifequal a|upper b|upper %}x{% endifequal %}', {'a': 'x', 'b': 'X'}, 'x'),
34+            'ifequal-filter04': ('{% ifequal x|slice:"1" "a" %}x{% endifequal %}', {'x': 'aaa'}, 'x'),
35+            'ifequal-filter05': ('{% ifequal x|slice:"1"|upper "A" %}x{% endifequal %}', {'x': 'aaa'}, 'x'),
36 
37             # SMART SPLITTING
38             'ifequal-split01': ('{% ifequal a "test man" %}yes{% else %}no{% endifequal %}', {}, "no"),
39@@ -614,6 +627,26 @@
40             'include02': ('{% include "basic-syntax02" %}', {'headline': 'Included'}, "Included"),
41             'include03': ('{% include template_name %}', {'template_name': 'basic-syntax02', 'headline': 'Included'}, "Included"),
42             'include04': ('a{% include "nonexistent" %}b', {}, "ab"),
43+            'include-with01': ('{% include "basic-syntax02" with foo as headline %}', {'foo': 'Included'}, "Included"),
44+            'include-with02': ('{% include "basic-syntax03" with foo as first, bar as second %}', {"foo" : 1, "bar" : 2}, "1 --- 2"),
45+            'recursive-include': ('{% for item in items %}{{ item.label }}{% if not item.children|length_is:0 %}{% with item.children as items %}({% include "recursive-include" %}){% endwith %}{% endif %}{% endfor %}', {
46+                'items': [
47+                    {'label': 1, 'children': [
48+                        {'label': 2, 'children': [
49+                            {'label': 3, 'children': []},
50+                            {'label': 4, 'children': []},
51+                        ]},
52+                        {'label': 5, 'children': [
53+                             {'label': 6, 'children': [
54+                                 {'label': 7, 'children': [
55+                                     {'label': 8, 'children': []},     
56+                                 ]},
57+                                {'label': 9, 'children': []}, 
58+                             ]},
59+                        ]},
60+                    ]},
61+                ],
62+            }, '1(2(34)5(6(7(8)9)))'),
63 
64             ### NAMED ENDBLOCKS #######################################################
65 
66@@ -796,6 +829,12 @@
67                             you
68                             gentlemen.
69                             """),
70+            ### NEGATIVE NUMERIC LITERALS #############################################                           
71+            'negative-numeric-literal01': ('{{ -1 }}', {}, '-1'),
72+            'negative-numeric-literal02': ('{{ -2.01 }}', {}, '-2.01'),
73+            'negative-numeric-literal03': ('{{ -0.1 }}', {}, '-0.1'),
74+            'negative-numeric-literal04': ('{% ifequal -1 -1 %}x{% endifequal %}', {}, 'x'),
75+            'negative-numeric-literal05': ('{{ foo|default:-1 }}', {'foo': None}, '-1'),
76 
77             ### REGROUP TAG ###########################################################
78             'regroup01': ('{% regroup data by bar as grouped %}' + \
79@@ -821,6 +860,20 @@
80                           '{% endfor %},' + \
81                           '{% endfor %}',
82                           {}, ''),
83+                         
84+            'regroup03': ('{% regroup data by created|date:"F Y" as grouped %}' + \
85+                          '{% for group in grouped %}' + \
86+                          '{{ group.grouper }}' + \
87+                          '({% for item in group.list %}' + \
88+                          '{{ item.created|date:"d" }}' + \
89+                          '{% endfor %})' + \
90+                          '{% endfor %}',                         
91+                          {'data': [
92+                              {'created': datetime(2008, 1, 1)},
93+                              {'created': datetime(2008, 2, 2)},
94+                              {'created': datetime(2008, 3, 3)},
95+                              {'created': datetime(2008, 4, 4)},
96+                          ]}, 'January 2008(01)February 2008(02)March 2008(03)April 2008(04)'),
97 
98             ### TEMPLATETAG TAG #######################################################
99             'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
100@@ -857,10 +910,20 @@
101             ### WITH TAG ########################################################
102             'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'),
103             'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')),
104+            'with03': ('{% with a as b, b as a %}{{ a }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'BA'),
105+            'with04': ('{% with a as b , b as a %}{{ a }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'BA'),
106+            'with05': ('{% with a as b, b as a, "," as s %}{{ a }}{{ s }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'B,A'),
107+            'with06': ('{% with a as b, \',\' as s, b as a %}{{ a }}{{ s }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'B,A'),
108 
109             'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
110             'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
111-
112+            'with-error03': ('{% with a as x, as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
113+            'with-error04': ('{% with a as x, b as %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
114+            'with-error05': ('{% with as x, b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),                       
115+            'with-error06': ('{% with a as x | b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
116+            'with-error07': ('{% with a as x xxx b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
117+            'with-error08': ('{% with a xx x, b xx y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
118+                       
119             ### NOW TAG ########################################################
120             # Simple case
121             'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
122@@ -877,6 +940,7 @@
123             'url03': ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
124             'url04': ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
125             'url05': (u'{% url метка_оператора v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
126+            'url06': (u'{% url "метка_оператора" v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
127 
128             # Failures
129             'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError),