aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorHirokazu Hata <h.hata.ai.t@gmail.com>2020-05-18 02:24:34 +0900
committerGitHub <noreply@github.com>2020-05-17 13:24:34 -0400
commitae5bd0454ee4ed3bdbf22e953a216449ca34dd46 (patch)
tree8574c14ded61039af4064bf04764f4d4c68b28de /test/functional/lua/vim_spec.lua
parent090d3c2813a2fbe6a0407d9f51c2206a713e4dc3 (diff)
downloadrneovim-ae5bd0454ee4ed3bdbf22e953a216449ca34dd46.tar.gz
rneovim-ae5bd0454ee4ed3bdbf22e953a216449ca34dd46.tar.bz2
rneovim-ae5bd0454ee4ed3bdbf22e953a216449ca34dd46.zip
lua: add tbl_deep_extend (#11969)
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 79d523b5c6..46ae56955b 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -478,6 +478,17 @@ describe('lua stdlib', function()
return vim.tbl_islist(c) and vim.tbl_count(c) == 0
]]))
+ ok(exec_lua([[
+ local a = {x = {a = 1, b = 2}}
+ local b = {x = {a = 2, c = {y = 3}}}
+ local c = vim.tbl_extend("keep", a, b)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1
+ ]]))
+
eq('Error executing lua: .../shared.lua: invalid "behavior": nil',
pcall_err(exec_lua, [[
return vim.tbl_extend()
@@ -497,6 +508,94 @@ describe('lua stdlib', function()
)
end)
+ it('vim.tbl_deep_extend', function()
+ ok(exec_lua([[
+ local a = {x = {a = 1, b = 2}}
+ local b = {x = {a = 2, c = {y = 3}}}
+ local c = vim.tbl_deep_extend("keep", a, b)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return c.x.a == 1 and c.x.b == 2 and c.x.c.y == 3 and count == 1
+ ]]))
+
+ ok(exec_lua([[
+ local a = {x = {a = 1, b = 2}}
+ local b = {x = {a = 2, c = {y = 3}}}
+ local c = vim.tbl_deep_extend("force", a, b)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return c.x.a == 2 and c.x.b == 2 and c.x.c.y == 3 and count == 1
+ ]]))
+
+ ok(exec_lua([[
+ local a = {x = {a = 1, b = 2}}
+ local b = {x = {a = 2, c = {y = 3}}}
+ local c = {x = {c = 4, d = {y = 4}}}
+ local d = vim.tbl_deep_extend("keep", a, b, c)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return d.x.a == 1 and d.x.b == 2 and d.x.c.y == 3 and d.x.d.y == 4 and count == 1
+ ]]))
+
+ ok(exec_lua([[
+ local a = {x = {a = 1, b = 2}}
+ local b = {x = {a = 2, c = {y = 3}}}
+ local c = {x = {c = 4, d = {y = 4}}}
+ local d = vim.tbl_deep_extend("force", a, b, c)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return d.x.a == 2 and d.x.b == 2 and d.x.c == 4 and d.x.d.y == 4 and count == 1
+ ]]))
+
+ ok(exec_lua([[
+ local a = vim.empty_dict()
+ local b = {}
+ local c = vim.tbl_deep_extend("keep", a, b)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return not vim.tbl_islist(c) and count == 0
+ ]]))
+
+ ok(exec_lua([[
+ local a = {}
+ local b = vim.empty_dict()
+ local c = vim.tbl_deep_extend("keep", a, b)
+
+ local count = 0
+ for _ in pairs(c) do count = count + 1 end
+
+ return vim.tbl_islist(c) and count == 0
+ ]]))
+
+ eq('Error executing lua: .../shared.lua: invalid "behavior": nil',
+ pcall_err(exec_lua, [[
+ return vim.tbl_deep_extend()
+ ]])
+ )
+
+ eq('Error executing lua: .../shared.lua: wrong number of arguments (given 1, expected at least 3)',
+ pcall_err(exec_lua, [[
+ return vim.tbl_deep_extend("keep")
+ ]])
+ )
+
+ eq('Error executing lua: .../shared.lua: wrong number of arguments (given 2, expected at least 3)',
+ pcall_err(exec_lua, [[
+ return vim.tbl_deep_extend("keep", {})
+ ]])
+ )
+ end)
+
it('vim.tbl_count', function()
eq(0, exec_lua [[ return vim.tbl_count({}) ]])
eq(0, exec_lua [[ return vim.tbl_count(vim.empty_dict()) ]])