| 159 | ### CYCLE TAG ############################################################# |
| 160 | #'cycleXX': ('', {}, ''), |
| 161 | 'cycle01': ('{% cycle a, %}', {}, 'a'), |
| 162 | 'cycle02': ('{% cycle a,b,c as abc %}{% cycle abc %}', {}, 'ab'), |
| 163 | 'cycle03': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}', {}, 'abc'), |
| 164 | 'cycle04': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}', {}, 'abca'), |
| 165 | 'cycle05': ('{% cycle %}', {}, template.TemplateSyntaxError), |
| 166 | 'cycle06': ('{% cycle a %}', {}, template.TemplateSyntaxError), |
| 167 | 'cycle07': ('{% cycle a,b,c as foo %}{% cycle bar %}', {}, template.TemplateSyntaxError), |
| 168 | |
| 169 | ### EXCEPTIONS ############################################################ |
| 170 | |
| 171 | # Raise exception for invalid template name |
| 172 | 'exception01': ("{% extends 'nonexistent' %}", {}, template.TemplateSyntaxError), |
| 173 | |
| 174 | # Raise exception for invalid template name (in variable) |
| 175 | 'exception02': ("{% extends nonexistent %}", {}, template.TemplateSyntaxError), |
| 176 | |
| 177 | # Raise exception for extra {% extends %} tags |
| 178 | 'exception03': ("{% extends 'inheritance01' %}{% block first %}2{% endblock %}{% extends 'inheritance16' %}", {}, template.TemplateSyntaxError), |
| 179 | |
| 180 | # Raise exception for custom tags used in child with {% load %} tag in parent, not in child |
| 181 | 'exception04': ("{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}", {}, template.TemplateSyntaxError), |
| 182 | |
| 183 | ### FILTER TAG ############################################################ |
| 184 | #'filterXX': ('', {}, ''), |
| 185 | 'filter01': ('{% filter upper %}{% endfilter %}', {}, ''), |
| 186 | 'filter02': ('{% filter upper %}django{% endfilter %}', {}, 'DJANGO'), |
| 187 | 'filter03': ('{% filter upper|lower %}django{% endfilter %}', {}, 'django'), |
| 188 | |
| 189 | ### FIRSTOF TAG ########################################################### |
| 190 | #'firstofXX': ('', {}, ''), |
| 191 | 'firstof01': ('{% firstof a b c %}', {'a':0,'b':0,'c':0}, ''), |
| 192 | 'firstof02': ('{% firstof a b c %}', {'a':1,'b':0,'c':0}, '1'), |
| 193 | 'firstof03': ('{% firstof a b c %}', {'a':0,'b':2,'c':0}, '2'), |
| 194 | 'firstof04': ('{% firstof a b c %}', {'a':0,'b':0,'c':3}, '3'), |
| 195 | 'firstof05': ('{% firstof a b c %}', {'a':1,'b':2,'c':3}, '1'), |
| 196 | 'firstof06': ('{% firstof %}', {}, template.TemplateSyntaxError), |
| 197 | |
| 206 | ### IF TAG ################################################################ |
| 207 | 'if-tag01': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": True}, "yes"), |
| 208 | 'if-tag02': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": False}, "no"), |
| 209 | 'if-tag03': ("{% if foo %}yes{% else %}no{% endif %}", {}, "no"), |
| 210 | |
| 211 | ### IFCHANGED TAG ######################################################### |
| 212 | #'ifchangedXX': ('', {}, ''), |
| 213 | 'ifchanged01': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,2,3) }, '123'), |
| 214 | 'ifchanged02': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,1,3) }, '13'), |
| 215 | 'ifchanged03': ('{% for n in num %}{% ifchanged %}{{ n }}{% endifchanged %}{% endfor %}', { 'num': (1,1,1) }, '1'), |
| 216 | |
269 | | # Raise exception for invalid template name |
270 | | 'exception01': ("{% extends 'nonexistent' %}", {}, template.TemplateSyntaxError), |
271 | | |
272 | | # Raise exception for invalid template name (in variable) |
273 | | 'exception02': ("{% extends nonexistent %}", {}, template.TemplateSyntaxError), |
274 | | |
275 | | # Raise exception for extra {% extends %} tags |
276 | | 'exception03': ("{% extends 'inheritance01' %}{% block first %}2{% endblock %}{% extends 'inheritance16' %}", {}, template.TemplateSyntaxError), |
277 | | |
278 | | # Raise exception for custom tags used in child with {% load %} tag in parent, not in child |
279 | | 'exception04': ("{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}", {}, template.TemplateSyntaxError), |
280 | | |
281 | | 'multiline01': (""" |
282 | | Hello, |
283 | | boys. |
284 | | How |
285 | | are |
286 | | you |
287 | | gentlemen. |
288 | | """, |
289 | | {}, |
290 | | """ |
291 | | Hello, |
292 | | boys. |
293 | | How |
294 | | are |
295 | | you |
296 | | gentlemen. |
297 | | """), |
298 | | |
| 352 | |
| 353 | ### MULTILINE ############################################################# |
| 354 | |
| 355 | 'multiline01': (""" |
| 356 | Hello, |
| 357 | boys. |
| 358 | How |
| 359 | are |
| 360 | you |
| 361 | gentlemen. |
| 362 | """, |
| 363 | {}, |
| 364 | """ |
| 365 | Hello, |
| 366 | boys. |
| 367 | How |
| 368 | are |
| 369 | you |
| 370 | gentlemen. |
| 371 | """), |
| 372 | |
| 373 | ### REGROUP TAG ########################################################### |
| 374 | #'regroupXX': ('', {}, ''), |
| 375 | 'regroup01': ('{% regroup data by bar as grouped %}' + \ |
| 376 | '{% for group in grouped %}' + \ |
| 377 | '{{ group.grouper }}:' + \ |
| 378 | '{% for item in group.list %}' + \ |
| 379 | '{{ item.foo }}' + \ |
| 380 | '{% endfor %},' + \ |
| 381 | '{% endfor %}', |
| 382 | {'data': [ {'foo':'c', 'bar':1}, |
| 383 | {'foo':'d', 'bar':1}, |
| 384 | {'foo':'a', 'bar':2}, |
| 385 | {'foo':'b', 'bar':2}, |
| 386 | {'foo':'x', 'bar':3} ]}, |
| 387 | '1:cd,2:ab,3:x,'), |
| 388 | |
| 389 | # Test for silent failure when target variable isn't found |
| 390 | 'regroup02': ('{% regroup data by bar as grouped %}' + \ |
| 391 | '{% for group in grouped %}' + \ |
| 392 | '{{ group.grouper }}:' + \ |
| 393 | '{% for item in group.list %}' + \ |
| 394 | '{{ item.foo }}' + \ |
| 395 | '{% endfor %},' + \ |
| 396 | '{% endfor %}', |
| 397 | {}, ''), |
| 398 | |
| 399 | ### TEMPLATETAG TAG ####################################################### |
| 400 | #'templatetagXX': ('', {}, ''), |
| 401 | 'templatetag01': ('{% templatetag openblock %}', {}, '{%'), |
| 402 | 'templatetag02': ('{% templatetag closeblock %}', {}, '%}'), |
| 403 | 'templatetag03': ('{% templatetag openvariable %}', {}, '{{'), |
| 404 | 'templatetag04': ('{% templatetag closevariable %}', {}, '}}'), |
| 405 | 'templatetag05': ('{% templatetag %}', {}, template.TemplateSyntaxError), |
| 406 | 'templatetag06': ('{% templatetag foo %}', {}, template.TemplateSyntaxError), |
| 407 | |
| 408 | ### WIDTHRATIO TAG ######################################################## |
| 409 | #'widthratioXX': ('', {}, ''), |
| 410 | 'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'), |
| 411 | 'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, ''), |
| 412 | 'widthratio03': ('{% widthratio a b 100 %}', {'a':0,'b':100}, '0'), |
| 413 | 'widthratio04': ('{% widthratio a b 100 %}', {'a':50,'b':100}, '50'), |
| 414 | 'widthratio05': ('{% widthratio a b 100 %}', {'a':100,'b':100}, '100'), |
| 415 | |
| 416 | # 62.5 should round to 63 |
| 417 | 'widthratio06': ('{% widthratio a b 100 %}', {'a':50,'b':80}, '63'), |
| 418 | |
| 419 | # 71.4 should round to 71 |
| 420 | 'widthratio07': ('{% widthratio a b 100 %}', {'a':50,'b':70}, '71'), |
| 421 | |
| 422 | # Raise exception if we don't have 3 args, last one an integer |
| 423 | 'widthratio08': ('{% widthratio %}', {}, template.TemplateSyntaxError), |
| 424 | 'widthratio09': ('{% widthratio a b %}', {'a':50,'b':100}, template.TemplateSyntaxError), |
| 425 | 'widthratio10': ('{% widthratio a b 100.0 %}', {'a':50,'b':100}, template.TemplateSyntaxError), |