summaryrefslogtreecommitdiff
path: root/tests/regressiontests/templates
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-23 09:40:25 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-23 09:40:25 +0000
commita6f429e37e7fe9cf8801c8fbce4c40af7e0cec0c (patch)
treebf9ef8eb5f7ccb98258d09391e996d89aab6532b /tests/regressiontests/templates
parentf5c07f89e3f69672f94d1863e6559c78a40d1688 (diff)
Added consistent support for double- and single-quote delimiters in templates.
Some template filters and tags understood single-quoted arguments, others didn't. This makes everything consistent. Based on a patch from akaihola. Fixed #7295. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/templates')
-rw-r--r--tests/regressiontests/templates/parser.py59
-rw-r--r--tests/regressiontests/templates/tests.py4
2 files changed, 62 insertions, 1 deletions
diff --git a/tests/regressiontests/templates/parser.py b/tests/regressiontests/templates/parser.py
new file mode 100644
index 0000000000..6ad301d9c3
--- /dev/null
+++ b/tests/regressiontests/templates/parser.py
@@ -0,0 +1,59 @@
+"""
+Testing some internals of the template processing. These are *not* examples to be copied in user code.
+"""
+
+filter_parsing = r"""
+>>> from django.template import FilterExpression, Parser
+
+>>> c = {'article': {'section': u'News'}}
+>>> p = Parser("")
+>>> def fe_test(s): return FilterExpression(s, p).resolve(c)
+
+>>> fe_test('article.section')
+u'News'
+>>> fe_test('article.section|upper')
+u'NEWS'
+>>> fe_test(u'"News"')
+u'News'
+>>> fe_test(u"'News'")
+u'News'
+>>> fe_test(ur'"Some \"Good\" News"')
+u'Some "Good" News'
+>>> fe_test(ur"'Some \'Bad\' News'")
+u"Some 'Bad' News"
+
+>>> fe = FilterExpression(ur'"Some \"Good\" News"', p)
+>>> fe.filters
+[]
+>>> fe.var
+u'Some "Good" News'
+"""
+
+variable_parsing = r"""
+>>> from django.template import Variable
+
+>>> c = {'article': {'section': u'News'}}
+>>> Variable('article.section').resolve(c)
+u'News'
+>>> Variable(u'"News"').resolve(c)
+u'News'
+>>> Variable(u"'News'").resolve(c)
+u'News'
+
+Translated strings are handled correctly.
+
+>>> Variable('_(article.section)').resolve(c)
+u'News'
+>>> Variable('_("Good News")').resolve(c)
+u'Good News'
+>>> Variable("_('Better News')").resolve(c)
+u'Better News'
+
+Escaped quotes work correctly as well.
+
+>>> Variable(ur'"Some \"Good\" News"').resolve(c)
+u'Some "Good" News'
+>>> Variable(ur"'Some \'Better\' News'").resolve(c)
+u"Some 'Better' News"
+
+"""
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index a68f1e8f67..7bb37b9fd0 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -20,6 +20,7 @@ from django.utils.tzinfo import LocalTimezone
from unicode import unicode_tests
from context import context_tests
+from parser import filter_parsing, variable_parsing
try:
from loaders import *
@@ -31,7 +32,8 @@ import filters
# Some other tests we would like to run
__test__ = {
'unicode': unicode_tests,
- 'context': context_tests
+ 'context': context_tests,
+ 'filter_parsing': filter_parsing,
}
#################################