diff options
author | Folke Lemaitre <folke.lemaitre@gmail.com> | 2021-07-19 17:52:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-19 08:52:44 -0700 |
commit | 526fc609b83742430ff952f95ab3b56ef9f4951b (patch) | |
tree | ad6fd4f6ca9243585b56914edeaab494ca481ea9 /test/functional/lua/vim_spec.lua | |
parent | 3b2a85ff76c464ff317459672ce7d46417dd06a0 (diff) | |
download | rneovim-526fc609b83742430ff952f95ab3b56ef9f4951b.tar.gz rneovim-526fc609b83742430ff952f95ab3b56ef9f4951b.tar.bz2 rneovim-526fc609b83742430ff952f95ab3b56ef9f4951b.zip |
fix(shared): do not treat empty tables as list in deep extend (#15094)
An empty table was previously always treated as a list, which means that
while merging tables, whenever an empty table was encountered it would
always truncate any table on the left.
`vim.tbl_deep_extend("force", { b = { a = 1 } }, { b = {} })`
Before: `{ b = {} }`
After: `{ b = { a = 1 } }`
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 976e63b44d..4e2bed4deb 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -603,6 +603,31 @@ describe('lua stdlib', function() return vim.tbl_islist(c) and count == 0 ]])) + eq(exec_lua([[ + local a = { a = { b = 1 } } + local b = { a = {} } + return vim.tbl_deep_extend("force", a, b) + ]]), {a = {b = 1}}) + + eq(exec_lua([[ + local a = { a = 123 } + local b = { a = { b = 1} } + return vim.tbl_deep_extend("force", a, b) + ]]), {a = {b = 1}}) + + ok(exec_lua([[ + local a = { a = {[2] = 3} } + local b = { a = {[3] = 3} } + local c = vim.tbl_deep_extend("force", a, b) + return vim.deep_equal(c, {a = {[3] = 3}}) + ]])) + + eq(exec_lua([[ + local a = { a = { b = 1} } + local b = { a = 123 } + return vim.tbl_deep_extend("force", a, b) + ]]), {a = 123 }) + eq('Error executing lua: vim/shared.lua:0: invalid "behavior": nil', pcall_err(exec_lua, [[ return vim.tbl_deep_extend() |