aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorShadman <13149513+shadmansaleh@users.noreply.github.com>2021-11-26 16:06:43 +0600
committerGitHub <noreply@github.com>2021-11-26 11:06:43 +0100
commiteb876a0a6f5efb4706625723a8dd45b0c6c133a4 (patch)
tree97d966ef8e3666593bf496ea9414c5981ba8868f /test/functional/lua/vim_spec.lua
parent3451121a4e517b42f1df73caed35c3663f57e5eb (diff)
downloadrneovim-eb876a0a6f5efb4706625723a8dd45b0c6c133a4.tar.gz
rneovim-eb876a0a6f5efb4706625723a8dd45b0c6c133a4.tar.bz2
rneovim-eb876a0a6f5efb4706625723a8dd45b0c6c133a4.zip
fix(lua): fix vim.deepcopy for metatables & cycled tables (#16435)
vim.deepcopy previously didn't retain metatables in copies and caused stackoverflow on recursive tables/cycled tables this fixes these issues
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 3832d27a22..28471bdd46 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -396,6 +396,20 @@ describe('lua stdlib', function()
return t1.f() ~= t2.f()
]]))
+ ok(exec_lua([[
+ local t1 = {a = 5}
+ t1.self = t1
+ local t2 = vim.deepcopy(t1)
+ return t2.self == t2 and t2.self ~= t1
+ ]]))
+
+ ok(exec_lua([[
+ local mt = {mt=true}
+ local t1 = setmetatable({a = 5}, mt)
+ local t2 = vim.deepcopy(t1)
+ return getmetatable(t2) == mt
+ ]]))
+
eq('Error executing lua: vim/shared.lua:0: Cannot deepcopy object of type thread',
pcall_err(exec_lua, [[
local thread = coroutine.create(function () return 0 end)