feat(lua): function behavior for tbl_extend, tbl_deep_extend #33819

This commit is contained in:
Maria José Solano
2025-05-03 16:53:44 -05:00
committed by GitHub
parent 8305af9bd2
commit 047a10bfde
4 changed files with 57 additions and 9 deletions

View File

@@ -1036,6 +1036,20 @@ describe('lua stdlib', function()
return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1
]]))
ok(exec_lua([[
local a = { a = 1, b = 2, c = 1 }
local b = { a = -1, b = 5, c = 3, d = 4 }
-- Return the maximum value for each key.
local c = vim.tbl_extend(function(k, v, prev_v)
if prev_v then
return v > prev_v and v or prev_v
else
return v
end
end, a, b)
return vim.deep_equal(c, { a = 1, b = 5, c = 3, d = 4 })
]]))
matches(
'invalid "behavior": nil',
pcall_err(
@@ -1177,6 +1191,20 @@ describe('lua stdlib', function()
return vim.deep_equal(c, { sub = { 'b', 'c' } })
]]))
ok(exec_lua([[
local a = { a = 1, b = 2, c = { d = 1, e = -2} }
local b = { a = -1, b = 5, c = { d = 6 } }
-- Return the maximum value for each key.
local c = vim.tbl_deep_extend(function(k, v, prev_v)
if prev_v then
return v > prev_v and v or prev_v
else
return v
end
end, a, b)
return vim.deep_equal(c, { a = 1, b = 5, c = { d = 6, e = -2 } })
]]))
matches('invalid "behavior": nil', pcall_err(exec_lua, [[return vim.tbl_deep_extend()]]))
matches(