diff options
author | David Lord <davidism@gmail.com> | 2019-11-07 18:57:21 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2019-11-07 19:05:16 -0800 |
commit | 4d0949b3087e10c5bd183e7b7f22b15a74b95f68 (patch) | |
tree | da55a6740db12d7d4869d9c245fb10391a73777a /tests/test_runtime.py | |
parent | 24d86a9615404221a23ecedc15bd818e72026b2e (diff) | |
download | jinja2-refactor-loop-context.tar.gz |
async templates await attribute accessrefactor-loop-context
Diffstat (limited to 'tests/test_runtime.py')
-rw-r--r-- | tests/test_runtime.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/test_runtime.py b/tests/test_runtime.py index 1b24b40..1afcb3f 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -1,3 +1,5 @@ +import itertools + from jinja2 import Template from jinja2.runtime import LoopContext @@ -46,3 +48,13 @@ def test_loopcontext2(): in_lst = [10, 11] l = LoopContext(reversed(in_lst), None) assert l.length == len(in_lst) + + +def test_iterator_not_advanced_early(): + t = Template("{% for _, g in gs %}{{ loop.index }} {{ g|list }}\n{% endfor %}") + out = t.render(gs=itertools.groupby( + [(1, "a"), (1, "b"), (2, "c"), (3, "d")], lambda x: x[0] + )) + # groupby groups depend on the current position of the iterator. If + # it was advanced early, the lists would appear empty. + assert out == "1 [(1, 'a'), (1, 'b')]\n2 [(2, 'c')]\n3 [(3, 'd')]\n" |