fix(lua): make vim.deepcopy work with vim.NIL

style: changed double quotes to single quotes

feat: add tests

fix tests
This commit is contained in:
Max 2022-11-14 20:26:27 +01:00
parent f8c6718277
commit e15f61b1bd
2 changed files with 9 additions and 0 deletions

View File

@ -49,6 +49,9 @@ vim.deepcopy = (function()
if f then if f then
return f(orig, cache or {}) return f(orig, cache or {})
else else
if type(orig) == 'userdata' and orig == vim.NIL then
return vim.NIL
end
error('Cannot deepcopy object of type ' .. type(orig)) error('Cannot deepcopy object of type ' .. type(orig))
end end
end end

View File

@ -419,6 +419,12 @@ describe('lua stdlib', function()
return getmetatable(t2) == mt return getmetatable(t2) == mt
]])) ]]))
ok(exec_lua([[
local t1 = {a = vim.NIL}
local t2 = vim.deepcopy(t1)
return t2.a == vim.NIL
]]))
matches('Cannot deepcopy object of type thread', matches('Cannot deepcopy object of type thread',
pcall_err(exec_lua, [[ pcall_err(exec_lua, [[
local thread = coroutine.create(function () return 0 end) local thread = coroutine.create(function () return 0 end)