aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/vim_spec.lua
diff options
context:
space:
mode:
authorTyler Miller <tmillr@proton.me>2024-07-03 15:36:00 -0700
committerGitHub <noreply@github.com>2024-07-04 06:36:00 +0800
commit7f33c1967b78ca8fda11fb0ad4c7f57d563e6ede (patch)
tree647eeb832c5fd0de361c20119e00857fdf34b3dd /test/functional/lua/vim_spec.lua
parent12c9791e0fef7ee0d6cf6d3b828caa488d6347ea (diff)
downloadrneovim-7f33c1967b78ca8fda11fb0ad4c7f57d563e6ede.tar.gz
rneovim-7f33c1967b78ca8fda11fb0ad4c7f57d563e6ede.tar.bz2
rneovim-7f33c1967b78ca8fda11fb0ad4c7f57d563e6ede.zip
fix(lua): use rawget() to get __call in vim.is_callable() (#29536)
Lua 5.1 uses a "raw get" to retrieve `__call` from a metatable to determine if a table is callable. Mirror this behavior in `vim.is_callable()`.
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r--test/functional/lua/vim_spec.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 23bb9f0a2e..03c743c9ae 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -1495,6 +1495,60 @@ describe('lua stdlib', function()
]])
)
+ eq(
+ { false, false },
+ exec_lua([[
+ local meta = { __call = {} }
+ assert(meta.__call)
+ local function new()
+ return setmetatable({}, meta)
+ end
+ local not_callable = new()
+ return { pcall(function() not_callable() end), vim.is_callable(not_callable) }
+ ]])
+ )
+ eq(
+ { false, false },
+ exec_lua([[
+ local function new()
+ return { __call = function()end }
+ end
+ local not_callable = new()
+ assert(not_callable.__call)
+ return { pcall(function() not_callable() end), vim.is_callable(not_callable) }
+ ]])
+ )
+ eq(
+ { false, false },
+ exec_lua([[
+ local meta = setmetatable(
+ { __index = { __call = function() end } },
+ { __index = { __call = function() end } }
+ )
+ assert(meta.__call)
+ local not_callable = setmetatable({}, meta)
+ assert(not_callable.__call)
+ return { pcall(function() not_callable() end), vim.is_callable(not_callable) }
+ ]])
+ )
+ eq(
+ { false, false },
+ exec_lua([[
+ local meta = setmetatable({
+ __index = function()
+ return function() end
+ end,
+ }, {
+ __index = function()
+ return function() end
+ end,
+ })
+ assert(meta.__call)
+ local not_callable = setmetatable({}, meta)
+ assert(not_callable.__call)
+ return { pcall(function() not_callable() end), vim.is_callable(not_callable) }
+ ]])
+ )
eq(false, exec_lua('return vim.is_callable(1)'))
eq(false, exec_lua("return vim.is_callable('foo')"))
eq(false, exec_lua('return vim.is_callable({})'))