Fixed a bug with the loop context of a for loop if the iterator passed has a volatile `__len__` like the listreverseiterator. `else` in inline if-expressions is optional now.
--HG--
branch : trunk
diff --git a/tests/test_forloop.py b/tests/test_forloop.py
index b8d3ae6..f7e4d68 100644
--- a/tests/test_forloop.py
+++ b/tests/test_forloop.py
@@ -116,6 +116,12 @@
assert tmpl.render(table=['ab', 'cd']) == '[1|1][1|2][2|1][2|2]'
+def test_reversed_bug(env):
+ tmpl = env.from_string('{% for i in items %}{{ i }}{% if not loop.last %}'
+ ',{% endif %}{% endfor %}')
+ assert tmpl.render(items=reversed([3, 2, 1])) == '1,2,3'
+
+
def test_loop_errors(env):
tmpl = env.from_string(LOOPERROR1)
raises(UndefinedError, tmpl.render)