mirror of
https://github.com/neovim/neovim.git
synced 2026-06-16 08:41:15 +00:00
fix(api): nvim_clear_autocmds() "event" type check
Problem: nvim_clear_autocmds() does not type check "event" correctly. Solution: fix it.
This commit is contained in:
@@ -753,7 +753,8 @@ static Array unpack_string_or_array(Object v, char *k, bool required, Arena *are
|
||||
}
|
||||
return v.data.array;
|
||||
} else {
|
||||
VALIDATE_EXP(!required, k, "Array or String", api_typename(v.type), {
|
||||
VALIDATE_EXP(!required && v.type == kObjectTypeNil, k, "Array or String", api_typename(v.type),
|
||||
{
|
||||
return (Array)ARRAY_DICT_INIT;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@ describe('autocmd api', function()
|
||||
command = 'ls',
|
||||
})
|
||||
)
|
||||
matches(
|
||||
"Invalid 'event': expected Array or String, got nil$",
|
||||
pcall_err(exec_lua, function()
|
||||
vim.api.nvim_create_autocmd(nil, {})
|
||||
end)
|
||||
)
|
||||
eq("Required: 'command' or 'callback'", pcall_err(api.nvim_create_autocmd, 'FileType', {}))
|
||||
eq(
|
||||
"Invalid 'desc': expected String, got Integer",
|
||||
@@ -1020,6 +1026,12 @@ describe('autocmd api', function()
|
||||
"Invalid 'event' item: expected String, got Array",
|
||||
pcall_err(api.nvim_exec_autocmds, { 'FileType', {} }, {})
|
||||
)
|
||||
matches(
|
||||
"Invalid 'event': expected Array or String, got nil$",
|
||||
pcall_err(exec_lua, function()
|
||||
vim.api.nvim_exec_autocmds(nil, {})
|
||||
end)
|
||||
)
|
||||
end)
|
||||
|
||||
it('can trigger builtin autocmds', function()
|
||||
@@ -1554,6 +1566,16 @@ describe('autocmd api', function()
|
||||
event = { 'FileType', {} },
|
||||
})
|
||||
)
|
||||
eq(
|
||||
"Invalid 'event': expected Array or String, got Integer",
|
||||
pcall_err(api.nvim_clear_autocmds, { event = 1337 })
|
||||
)
|
||||
matches(
|
||||
"Invalid 'event': expected Array or String, got Function$",
|
||||
pcall_err(exec_lua, function()
|
||||
vim.api.nvim_clear_autocmds({ event = function() end })
|
||||
end)
|
||||
)
|
||||
eq("Invalid 'group': 0", pcall_err(api.nvim_clear_autocmds, { group = 0 }))
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user