aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/iter_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-08-09 15:41:45 -0500
committerGitHub <noreply@github.com>2023-08-09 15:41:45 -0500
commit2ee8ace217b8e4405822d3ab1bed5a20bedc4b04 (patch)
treefdee6f6d0e87ebe9a3c8689866e2c2530b79dd43 /test/functional/lua/iter_spec.lua
parentcc4540ebce6b719e735ef314b4acc5460aa1aeae (diff)
downloadrneovim-2ee8ace217b8e4405822d3ab1bed5a20bedc4b04.tar.gz
rneovim-2ee8ace217b8e4405822d3ab1bed5a20bedc4b04.tar.bz2
rneovim-2ee8ace217b8e4405822d3ab1bed5a20bedc4b04.zip
fix(iter): make pipeline termination conditions consistent (#24614)
If an iterator pipeline stage returns nil as its first return value, the other return values are ignored and it is treated as if that stage returned only nil (the semantics of returning nil are different between different stages). This is consistent with how for loops work in Lua more generally, where the for loop breaks when the first return value from the function iterator is nil (see :h for-in for details).
Diffstat (limited to 'test/functional/lua/iter_spec.lua')
-rw-r--r--test/functional/lua/iter_spec.lua38
1 files changed, 3 insertions, 35 deletions
diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua
index 3b603c9911..ffa28e7b11 100644
--- a/test/functional/lua/iter_spec.lua
+++ b/test/functional/lua/iter_spec.lua
@@ -154,6 +154,9 @@ describe('vim.iter', function()
eq({1, 2}, vim.iter(t):slice(1, 2):totable())
eq({10}, vim.iter(t):slice(10, 10):totable())
eq({8, 9, 10}, vim.iter(t):slice(8, 11):totable())
+
+ local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
+ matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3))
end)
it('nth()', function()
@@ -396,39 +399,4 @@ describe('vim.iter', function()
{ item_3 = 'test' },
}, output)
end)
-
- it('handles nil values', function()
- local t = {1, 2, 3, 4, 5}
- do
- local it = vim.iter(t):enumerate():map(function(i, v)
- if i % 2 == 0 then
- return nil, v*v
- end
- return v, nil
- end)
- eq({
- { [1] = 1 },
- { [2] = 4 },
- { [1] = 3 },
- { [2] = 16 },
- { [1] = 5 },
- }, it:totable())
- end
-
- do
- local it = vim.iter(ipairs(t)):map(function(i, v)
- if i % 2 == 0 then
- return nil, v*v
- end
- return v, nil
- end)
- eq({
- { [1] = 1 },
- { [2] = 4 },
- { [1] = 3 },
- { [2] = 16 },
- { [1] = 5 },
- }, it:totable())
- end
- end)
end)