Ticket #7799: tplrf-tests.diff

File tplrf-tests.diff, 8.6 KB (added by Johannes Dollinger, 16 years ago)
  • tests/regressiontests/templates/tests.py

     
    1717from django.utils.safestring import mark_safe
    1818from django.utils.tzinfo import LocalTimezone
    1919
     20#from decorators import DecoratorsTest
    2021from unicode import unicode_tests
    2122from context import context_tests
    2223
     
    407408            'cycle13': ("{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'),
    408409            'cycle14': ("{% cycle one two as foo %}{% cycle foo %}", {'one': '1','two': '2'}, '12'),
    409410            'cycle13': ("{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}", {'test': range(5), 'aye': 'a', 'bee': 'b'}, 'a0,b1,a2,b3,a4,'),
     411           
     412            ### EMPTY STRINGS #########################################################
     413            'emptystring01': ("{{ '' }}", {}, ""),
     414            'emptystring02': ("{% ifequal foo '' %}x{% endifequal %}", {'foo': ''}, 'x'),
     415            'emptystring03': ("{% ifequal foo|default:'' foo %}x{% endifequal %}", {'foo': ''}, 'x'),
    410416
    411417            ### EXCEPTIONS ############################################################
    412418
     
    576582            'ifequal08': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {"a": "no"}, "no"),
    577583            'ifequal09': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {}, "no"),
    578584            'ifequal10': ('{% ifequal a b %}yes{% else %}no{% endifequal %}', {}, "yes"),
     585           
     586            ## FILTER EXPRESSIONS AS ARGUMENTS ########################################
     587            'ifequal-filter01': ('{% ifequal a|upper "A" %}x{% endifequal %}', {'a': 'a'}, 'x'),
     588            'ifequal-filter02': ('{% ifequal "A" a|upper %}x{% endifequal %}', {'a': 'a'}, 'x'),
     589            'ifequal-filter03': ('{% ifequal a|upper b|upper %}x{% endifequal %}', {'a': 'x', 'b': 'X'}, 'x'),
     590            'ifequal-filter04': ('{% ifequal x|slice:"1" "a" %}x{% endifequal %}', {'x': 'aaa'}, 'x'),
     591            'ifequal-filter05': ('{% ifequal x|slice:"1"|upper "A" %}x{% endifequal %}', {'x': 'aaa'}, 'x'),
    579592
    580593            # SMART SPLITTING
    581594            'ifequal-split01': ('{% ifequal a "test man" %}yes{% else %}no{% endifequal %}', {}, "no"),
     
    614627            'include02': ('{% include "basic-syntax02" %}', {'headline': 'Included'}, "Included"),
    615628            'include03': ('{% include template_name %}', {'template_name': 'basic-syntax02', 'headline': 'Included'}, "Included"),
    616629            'include04': ('a{% include "nonexistent" %}b', {}, "ab"),
     630            'include-with01': ('{% include "basic-syntax02" with foo as headline %}', {'foo': 'Included'}, "Included"),
     631            'include-with02': ('{% include "basic-syntax03" with foo as first, bar as second %}', {"foo" : 1, "bar" : 2}, "1 --- 2"),
     632            '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 %}', {
     633                'items': [
     634                    {'label': 1, 'children': [
     635                        {'label': 2, 'children': [
     636                            {'label': 3, 'children': []},
     637                            {'label': 4, 'children': []},
     638                        ]},
     639                        {'label': 5, 'children': [
     640                             {'label': 6, 'children': [
     641                                 {'label': 7, 'children': [
     642                                     {'label': 8, 'children': []},     
     643                                 ]},
     644                                {'label': 9, 'children': []},   
     645                             ]},
     646                        ]},
     647                    ]},
     648                ],
     649            }, '1(2(34)5(6(7(8)9)))'),
    617650
    618651            ### NAMED ENDBLOCKS #######################################################
    619652
     
    796829                            you
    797830                            gentlemen.
    798831                            """),
     832            ### NEGATIVE NUMERIC LITERALS #############################################                           
     833            'negative-numeric-literal01': ('{{ -1 }}', {}, '-1'),
     834            'negative-numeric-literal02': ('{{ -2.01 }}', {}, '-2.01'),
     835            'negative-numeric-literal03': ('{{ -0.1 }}', {}, '-0.1'),
     836            'negative-numeric-literal04': ('{% ifequal -1 -1 %}x{% endifequal %}', {}, 'x'),
     837            'negative-numeric-literal05': ('{{ foo|default:-1 }}', {'foo': None}, '-1'),
    799838
    800839            ### REGROUP TAG ###########################################################
    801840            'regroup01': ('{% regroup data by bar as grouped %}' + \
     
    821860                          '{% endfor %},' + \
    822861                          '{% endfor %}',
    823862                          {}, ''),
     863                         
     864            'regroup03': ('{% regroup data by created|date:"F Y" as grouped %}' + \
     865                          '{% for group in grouped %}' + \
     866                          '{{ group.grouper }}' + \
     867                          '({% for item in group.list %}' + \
     868                          '{{ item.created|date:"d" }}' + \
     869                          '{% endfor %})' + \
     870                          '{% endfor %}',                         
     871                          {'data': [
     872                              {'created': datetime(2008, 1, 1)},
     873                              {'created': datetime(2008, 2, 2)},
     874                              {'created': datetime(2008, 3, 3)},
     875                              {'created': datetime(2008, 4, 4)},
     876                          ]}, 'January 2008(01)February 2008(02)March 2008(03)April 2008(04)'),
    824877
    825878            ### TEMPLATETAG TAG #######################################################
    826879            'templatetag01': ('{% templatetag openblock %}', {}, '{%'),
     
    857910            ### WITH TAG ########################################################
    858911            'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'),
    859912            'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')),
     913            'with03': ('{% with a as b, b as a %}{{ a }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'BA'),
     914            'with04': ('{% with a as b , b as a %}{{ a }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'BA'),
     915            'with05': ('{% with a as b, b as a, "," as s %}{{ a }}{{ s }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'B,A'),
     916            'with06': ('{% with a as b, \',\' as s, b as a %}{{ a }}{{ s }}{{ b }}{% endwith %}', {'a': 'A', 'b': 'B'}, 'B,A'),
    860917
    861918            'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
    862919            'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
    863 
     920            'with-error03': ('{% with a as x, as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
     921            'with-error04': ('{% with a as x, b as %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
     922            'with-error05': ('{% with as x, b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),                       
     923            'with-error06': ('{% with a as x | b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
     924            'with-error07': ('{% with a as x xxx b as y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
     925            'with-error08': ('{% with a xx x, b xx y %}x{% endwith %}', {'a': 'A', 'b': 'B'}, template.TemplateSyntaxError),
     926                       
    864927            ### NOW TAG ########################################################
    865928            # Simple case
    866929            'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
     
    877940            'url03': ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
    878941            'url04': ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
    879942            'url05': (u'{% url метка_оператора v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
     943            'url06': (u'{% url "метка_оператора" v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
    880944
    881945            # Failures
    882946            'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError),
Back to Top