aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-04-21 16:13:39 -0600
committerGitHub <noreply@github.com>2023-04-21 16:13:39 -0600
commitf68af3c3bc92c12f7dbbd32f44df8ab57a58ac98 (patch)
tree2e50afffb1a3b6e6d32f95df55b83fb0eadd24fb /test/functional/lua/vim_spec.lua
parentef92b5a9948f2fb6042ae0c842bfb4301b1894c3 (diff)
downloadrneovim-f68af3c3bc92c12f7dbbd32f44df8ab57a58ac98.tar.gz
rneovim-f68af3c3bc92c12f7dbbd32f44df8ab57a58ac98.tar.bz2
rneovim-f68af3c3bc92c12f7dbbd32f44df8ab57a58ac98.zip
refactor(iter): use metatable as packed table tag (#23254)
This is a more robust method for tagging a packed table as it completely eliminates the possibility of mistaking an actual table key as the packed table tag.
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index b8cc15b2ca..42927f7e1b 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -3416,6 +3416,41 @@ describe('lua stdlib', 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)
end)