diff options
| author | Maria José Solano <majosolano99@gmail.com> | 2025-05-03 16:53:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-03 14:53:44 -0700 |
| commit | 047a10bfde531f433b9c8a07e6b380f376a7ec70 (patch) | |
| tree | 781850b6f4f5ad128be6793ac24a51ca6df3d8b9 /test/functional/lua/vim_spec.lua | |
| parent | 8305af9bd2eb645d4a0be39d32bea5dc81fe69a1 (diff) | |
| download | rneovim-047a10bfde531f433b9c8a07e6b380f376a7ec70.tar.gz rneovim-047a10bfde531f433b9c8a07e6b380f376a7ec70.tar.bz2 rneovim-047a10bfde531f433b9c8a07e6b380f376a7ec70.zip | |
feat(lua): function `behavior` for tbl_extend, tbl_deep_extend #33819
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
| -rw-r--r-- | test/functional/lua/vim_spec.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index c499f8bf25..9693beb242 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -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( |