Fix slice fill behavior for even divisions
This commit is contained in:
parent
5ef70112a1
commit
fe450c06cf
@ -1089,7 +1089,11 @@ def sync_do_slice(
|
||||
end = offset + (slice_number + 1) * items_per_slice
|
||||
tmp = seq[start:end]
|
||||
|
||||
if fill_with is not None and slice_number >= slices_with_extra:
|
||||
if (
|
||||
fill_with is not None
|
||||
and slices_with_extra > 0
|
||||
and slice_number >= slices_with_extra
|
||||
):
|
||||
tmp.append(fill_with)
|
||||
|
||||
yield tmp
|
||||
|
||||
@ -266,6 +266,12 @@ def test_slice(env_async, items):
|
||||
)
|
||||
|
||||
|
||||
@mark_dualiter("items", lambda: [1, 2, 3, 4])
|
||||
def test_slice_fill_with_even_division(env_async, items):
|
||||
tmpl = env_async.from_string("{{ items()|slice(4, 'X')|list }}")
|
||||
assert tmpl.render(items=items) == "[[1], [2], [3], [4]]"
|
||||
|
||||
|
||||
def test_unique_with_async_gen(env_async):
|
||||
items = ["a", "b", "c", "c", "a", "d", "z"]
|
||||
tmpl = env_async.from_string("{{ items|reject('==', 'z')|unique|list }}")
|
||||
|
||||
@ -78,6 +78,11 @@ class TestFilter:
|
||||
"[[0, 1, 2, 3], [4, 5, 6, 'X'], [7, 8, 9, 'X']]"
|
||||
)
|
||||
|
||||
def test_slice_fill_with_even_division(self, env):
|
||||
tmpl = env.from_string("{{ foo|slice(4, 'X')|list }}")
|
||||
out = tmpl.render(foo=[1, 2, 3, 4])
|
||||
assert out == "[[1], [2], [3], [4]]"
|
||||
|
||||
def test_escape(self, env):
|
||||
tmpl = env.from_string("""{{ '<">&'|escape }}""")
|
||||
out = tmpl.render()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user