mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
lua: vim.deepcopy uses empty_dict() instead of {} for empty_dict()
fix: https://github.com/neovim/nvim-lsp/issues/94
This commit is contained in:
parent
68de6b17b8
commit
417fc6ccf7
@ -20,6 +20,11 @@ vim.deepcopy = (function()
|
||||
local deepcopy_funcs = {
|
||||
table = function(orig)
|
||||
local copy = {}
|
||||
|
||||
if getmetatable(orig) == vim._empty_dict_mt then
|
||||
copy = vim.empty_dict()
|
||||
end
|
||||
|
||||
for k, v in pairs(orig) do
|
||||
copy[vim.deepcopy(k)] = vim.deepcopy(v)
|
||||
end
|
||||
|
@ -322,6 +322,48 @@ describe('lua stdlib', function()
|
||||
]])
|
||||
|
||||
assert(is_dc)
|
||||
|
||||
local is_empty_list = exec_lua([[
|
||||
local a = {}
|
||||
local b = vim.deepcopy(a)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(b) do count = count + 1 end
|
||||
|
||||
return getmetatable(b) ~= vim._empty_dict_mt
|
||||
and count == 0
|
||||
and tostring(a) ~= tostring(b)
|
||||
]])
|
||||
|
||||
assert(is_empty_list)
|
||||
|
||||
local is_empty_dic = exec_lua([[
|
||||
local a = vim.empty_dict()
|
||||
local b = vim.deepcopy(a)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(b) do count = count + 1 end
|
||||
|
||||
return getmetatable(b) == vim._empty_dict_mt
|
||||
and count == 0
|
||||
]])
|
||||
|
||||
assert(is_empty_dic)
|
||||
|
||||
local include_empty_dic = exec_lua([[
|
||||
local a = {x = vim.empty_dict(), y = {}}
|
||||
local b = vim.deepcopy(a)
|
||||
|
||||
local count = 0
|
||||
for _ in pairs(b) do count = count + 1 end
|
||||
|
||||
return getmetatable(b.x) == vim._empty_dict_mt
|
||||
and getmetatable(b.y) ~= vim._empty_dict_mt
|
||||
and count == 2
|
||||
and tostring(a) ~= tostring(b)
|
||||
]])
|
||||
|
||||
assert(include_empty_dic)
|
||||
end)
|
||||
|
||||
it('vim.pesc', function()
|
||||
|
Loading…
Reference in New Issue
Block a user