From 69f1de86dca28d6e339351082df1309ef4fbb6a6 Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Thu, 24 Mar 2022 12:01:04 -0700 Subject: feat: add vim.tbl_get (#17831) vim.tbl_get takes a table with subsequent string arguments (variadic) that index into the table. If the value pointed to by the set of keys exists, the function returns the value. If the set of keys does not exist, the function returns nil. --- test/functional/lua/vim_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/lua') diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 38cb54fbc6..1547f3244e 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -490,6 +490,12 @@ describe('lua stdlib', function() eq(false, exec_lua("return vim.tbl_isempty({a=1, b=2, c=3})")) end) + it('vim.tbl_get', function() + eq(true, exec_lua("return vim.tbl_get({ test = { nested_test = true }}, 'test', 'nested_test')")) + eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')")) + eq(NIL, exec_lua("return vim.tbl_get({})")) + end) + it('vim.tbl_extend', function() ok(exec_lua([[ local a = {x = 1} -- cgit