Django

Code

Ticket #7806: tplrf-tests.diff

File tplrf-tests.diff, 6.3 kB (added by emulbreh, 2 years ago)
  • tests/regressiontests/templates/tests.py

    old new  
    280280            'basic-syntax25': ('{{ "fred" }}', {}, "fred"), 
    281281            'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""), 
    282282            'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""), 
     283            'basic-syntax28': ("{{ 'fred' }}", {}, "fred"), 
     284            'basic-syntax29': (r"{{ '\'fred\'' }}", {}, "'fred'"), 
     285            'basic-syntax30': (r"{{ _('\'fred\'') }}", {}, "'fred'"), 
    283286 
     287 
    284288            # List-index syntax allows a template to access a certain item of a subscriptable object. 
    285289            'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"), 
    286290 
     
    364368 
    365369            # Numbers as filter arguments should work 
    366370            'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."), 
     371             
     372            # Single quoted argument 
     373            'filter-syntax20': (r"{{ var|yesno:'yup,nup,mup' }} {{ var|yesno }}", {"var": True}, 'yup yes'),             
    367374 
    368375            ### COMMENT SYNTAX ######################################################## 
    369376            'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"), 
     
    407414            'cycle13': ("{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'), 
    408415            'cycle14': ("{% cycle one two as foo %}{% cycle foo %}", {'one': '1','two': '2'}, '12'), 
    409416            'cycle13': ("{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}", {'test': range(5), 'aye': 'a', 'bee': 'b'}, 'a0,b1,a2,b3,a4,'), 
     417             
     418            ### EMPTY STRINGS ######################################################### 
     419            'emptystring01': ("{{ '' }}", {}, ""), 
     420            'emptystring02': ("{% ifequal foo '' %}x{% endifequal %}", {'foo': ''}, 'x'), 
     421            'emptystring03': ("{% ifequal foo|default:'' foo %}x{% endifequal %}", {'foo': ''}, 'x'), 
    410422 
    411423            ### EXCEPTIONS ############################################################ 
    412424 
     
    576588            'ifequal08': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {"a": "no"}, "no"), 
    577589            'ifequal09': ('{% ifequal a "test" %}yes{% else %}no{% endifequal %}', {}, "no"), 
    578590            'ifequal10': ('{% ifequal a b %}yes{% else %}no{% endifequal %}', {}, "yes"), 
     591             
     592            ## FILTER EXPRESSIONS AS ARGUMENTS ######################################## 
     593            'ifequal-filter01': ('{% ifequal a|upper "A" %}x{% endifequal %}', {'a': 'a'}, 'x'), 
     594            'ifequal-filter02': ('{% ifequal "A" a|upper %}x{% endifequal %}', {'a': 'a'}, 'x'), 
     595            'ifequal-filter03': ('{% ifequal a|upper b|upper %}x{% endifequal %}', {'a': 'x', 'b': 'X'}, 'x'), 
     596            'ifequal-filter04': ('{% ifequal x|slice:"1" "a" %}x{% endifequal %}', {'x': 'aaa'}, 'x'), 
     597            'ifequal-filter05': ('{% ifequal x|slice:"1"|upper "A" %}x{% endifequal %}', {'x': 'aaa'}, 'x'), 
    579598 
    580599            # SMART SPLITTING 
    581600            'ifequal-split01': ('{% ifequal a "test man" %}yes{% else %}no{% endifequal %}', {}, "no"), 
     
    796815                            you 
    797816                            gentlemen. 
    798817                            """), 
     818            ### NEGATIVE NUMERIC LITERALS #############################################                             
     819            'negative-numeric-literal01': ('{{ -1 }}', {}, '-1'), 
     820            'negative-numeric-literal02': ('{{ -2.01 }}', {}, '-2.01'), 
     821            'negative-numeric-literal03': ('{{ -0.1 }}', {}, '-0.1'), 
     822            'negative-numeric-literal04': ('{% ifequal -1 -1 %}x{% endifequal %}', {}, 'x'), 
     823            'negative-numeric-literal05': ('{{ foo|default:-1 }}', {'foo': None}, '-1'), 
    799824 
    800825            ### REGROUP TAG ########################################################### 
    801826            'regroup01': ('{% regroup data by bar as grouped %}' + \ 
     
    821846                          '{% endfor %},' + \ 
    822847                          '{% endfor %}', 
    823848                          {}, ''), 
     849                           
     850            'regroup03': ('{% regroup data by created|date:"F Y" as grouped %}' + \ 
     851                          '{% for group in grouped %}' + \ 
     852                          '{{ group.grouper }}' + \ 
     853                          '({% for item in group.list %}' + \ 
     854                          '{{ item.created|date:"d" }}' + \ 
     855                          '{% endfor %})' + \ 
     856                          '{% endfor %}',                           
     857                          {'data': [ 
     858                              {'created': datetime(2008, 1, 1)}, 
     859                              {'created': datetime(2008, 2, 2)}, 
     860                              {'created': datetime(2008, 3, 3)}, 
     861                              {'created': datetime(2008, 4, 4)}, 
     862                          ]}, 'January 2008(01)February 2008(02)March 2008(03)April 2008(04)'), 
    824863 
    825864            ### TEMPLATETAG TAG ####################################################### 
    826865            'templatetag01': ('{% templatetag openblock %}', {}, '{%'), 
     
    860899 
    861900            'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError), 
    862901            'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError), 
    863  
     902                         
    864903            ### NOW TAG ######################################################## 
    865904            # Simple case 
    866905            'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)), 
     
    877916            'url03': ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'), 
    878917            'url04': ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'), 
    879918            'url05': (u'{% url метка_оператора v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
     919            'url06': (u'{% url "метка_оператора" v %}', {'v': u'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 
    880920 
    881921            # Failures 
    882922            'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError),