test: typing for helpers.meths

This commit is contained in:
Lewis Russell
2024-01-12 12:44:54 +00:00
parent 284e0ad26d
commit c30f2e3182
141 changed files with 3342 additions and 3137 deletions

View File

@@ -51,24 +51,24 @@ describe('nvim_get_commands', function()
before_each(clear)
it('gets empty list if no commands were defined', function()
eq({}, meths.get_commands({ builtin = false }))
eq({}, meths.nvim_get_commands({ builtin = false }))
end)
it('validation', function()
eq('builtin=true not implemented', pcall_err(meths.get_commands, { builtin = true }))
eq("Invalid key: 'foo'", pcall_err(meths.get_commands, { foo = 'blah' }))
eq('builtin=true not implemented', pcall_err(meths.nvim_get_commands, { builtin = true }))
eq("Invalid key: 'foo'", pcall_err(meths.nvim_get_commands, { foo = 'blah' }))
end)
it('gets global user-defined commands', function()
-- Define a command.
command('command -nargs=1 Hello echo "Hello World"')
eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false }))
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false }))
-- Define another command.
command('command -nargs=? Pwd pwd')
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.get_commands({ builtin = false }))
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_get_commands({ builtin = false }))
-- Delete a command.
command('delcommand Pwd')
eq({ Hello = cmd_dict }, meths.get_commands({ builtin = false }))
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false }))
end)
it('gets buffer-local user-defined commands', function()
@@ -171,9 +171,9 @@ describe('nvim_get_commands', function()
let s:foo = 1
command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
]])
eq({ Finger = cmd1 }, meths.get_commands({ builtin = false }))
eq({ Finger = cmd1 }, meths.nvim_get_commands({ builtin = false }))
command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
eq({ Finger = cmd1, TestCmd = cmd0 }, meths.get_commands({ builtin = false }))
eq({ Finger = cmd1, TestCmd = cmd0 }, meths.nvim_get_commands({ builtin = false }))
source([[
function! s:foo() abort
@@ -193,7 +193,7 @@ describe('nvim_get_commands', function()
-- TODO(justinmk): Order is stable but undefined. Sort before return?
eq(
{ Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 },
meths.get_commands({ builtin = false })
meths.nvim_get_commands({ builtin = false })
)
end)
end)
@@ -202,9 +202,9 @@ describe('nvim_create_user_command', function()
before_each(clear)
it('works with strings', function()
meths.create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 })
meths.command('SomeCommand 42')
eq(42, meths.eval('g:command_fired'))
meths.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 })
meths.nvim_command('SomeCommand 42')
eq(42, meths.nvim_eval('g:command_fired'))
end)
it('works with Lua functions', function()
@@ -646,11 +646,11 @@ describe('nvim_create_user_command', function()
end)
it('can define buffer-local commands', function()
local bufnr = meths.create_buf(false, false)
local bufnr = meths.nvim_create_buf(false, false)
bufmeths.create_user_command(bufnr, 'Hello', '', {})
matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello'))
meths.set_current_buf(bufnr)
meths.command('Hello')
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello'))
meths.nvim_set_current_buf(bufnr)
meths.nvim_command('Hello')
assert_alive()
end)
@@ -731,28 +731,28 @@ describe('nvim_create_user_command', function()
vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
end, {})
]]
eq('3', meths.cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
eq('3', meths.nvim_cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
eq(1, #meths.list_tabpages())
eq(1, #meths.nvim_list_tabpages())
exec_lua [[
vim.api.nvim_create_user_command('MySplit', function(opts)
vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {})
end, {})
]]
meths.cmd({ cmd = 'MySplit' }, {})
eq(1, #meths.list_tabpages())
eq(2, #meths.list_wins())
meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(2, #meths.list_tabpages())
meths.nvim_cmd({ cmd = 'MySplit' }, {})
eq(1, #meths.nvim_list_tabpages())
eq(2, #meths.nvim_list_wins())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(2, #meths.nvim_list_tabpages())
eq(2, funcs.tabpagenr())
meths.cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(3, #meths.list_tabpages())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(3, #meths.nvim_list_tabpages())
eq(2, funcs.tabpagenr())
meths.cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
eq(4, #meths.list_tabpages())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
eq(4, #meths.nvim_list_tabpages())
eq(4, funcs.tabpagenr())
meths.cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
eq(5, #meths.list_tabpages())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
eq(5, #meths.nvim_list_tabpages())
eq(1, funcs.tabpagenr())
end)
end)
@@ -761,16 +761,16 @@ describe('nvim_del_user_command', function()
before_each(clear)
it('can delete global commands', function()
meths.create_user_command('Hello', 'echo "Hi"', {})
meths.command('Hello')
meths.del_user_command('Hello')
matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello'))
meths.nvim_create_user_command('Hello', 'echo "Hi"', {})
meths.nvim_command('Hello')
meths.nvim_del_user_command('Hello')
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello'))
end)
it('can delete buffer-local commands', function()
bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {})
meths.command('Hello')
meths.nvim_command('Hello')
bufmeths.del_user_command(0, 'Hello')
matches('Not an editor command: Hello', pcall_err(meths.command, 'Hello'))
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello'))
end)
end)