Skip to content
Snippets Groups Projects
Commit 2f2d94d0 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

Templates: 'split' filter allows omission of separator (same as Python 'split')

parent 57f6f21b
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,11 @@ Global
* TODO: Porting to python3
Templates
---------
* 'split' filter allows omission of separator (same as Python 'split')
Version 1.1.1rc2
================
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
No preview for this file type
......@@ -333,7 +333,7 @@ def match(s, regexp, default=''):
return default
template_env.filters['match'] = match
# - There's a join but no split operation...
template_env.filters['split'] = lambda x, s, m=-1: x.split(s, m)
template_env.filters['split'] = lambda x, s=None, m=-1: x.split(s, m)
# - Add list operation filter
template_env.filters['filter'] = lambda x, f=None: filter(f, x)
......
......@@ -744,6 +744,24 @@ class SplitTestCase(MkexpSimpleTestCase):
['Douglas', 'Noel Adams']
""")
def test_default_separator(self):
self.run_test("""
%{'Douglas Noel Adams'|split()}
%{'Douglas Noel Adams'|split(none)}
""","""
['Douglas', 'Noel', 'Adams']
['Douglas', 'Noel', 'Adams']
""")
def test_max_split_and_default_separator(self):
self.run_test("""
%{'Douglas Noel Adams'|split(m=2)}
%{'Douglas Noel Adams'|split(m=1)}
""","""
['Douglas', 'Noel', 'Adams']
['Douglas', 'Noel Adams']
""")
class FilterTestCase(MkexpSimpleTestCase):
def test_basic(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment