test: rename (meths, funcs) -> (api, fn)

This commit is contained in:
Lewis Russell
2024-01-12 17:59:57 +00:00
parent 4f81f506f9
commit 795f896a57
214 changed files with 6443 additions and 6560 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq, ok = helpers.eq, helpers.ok local eq, ok = helpers.eq, helpers.ok
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@@ -24,7 +24,7 @@ local function expectn(name, args)
end end
local function sendkeys(keys) local function sendkeys(keys)
meths.nvim_input(keys) api.nvim_input(keys)
-- give nvim some time to process msgpack requests before possibly sending -- give nvim some time to process msgpack requests before possibly sending
-- more key presses - otherwise they all pile up in the queue and get -- more key presses - otherwise they all pile up in the queue and get
-- processed at once -- processed at once
@@ -37,7 +37,7 @@ local function open(activate, lines)
local filename = helpers.tmpname() local filename = helpers.tmpname()
write_file(filename, table.concat(lines, '\n') .. '\n', true) write_file(filename, table.concat(lines, '\n') .. '\n', true)
command('edit ' .. filename) command('edit ' .. filename)
local b = meths.nvim_get_current_buf() local b = api.nvim_get_current_buf()
-- what is the value of b:changedtick? -- what is the value of b:changedtick?
local tick = eval('b:changedtick') local tick = eval('b:changedtick')
@@ -45,7 +45,7 @@ local function open(activate, lines)
-- arrive as expected -- arrive as expected
if activate then if activate then
local firstline = 0 local firstline = 0
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false }) expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false })
end end
@@ -62,12 +62,12 @@ local function editoriginal(activate, lines)
end end
local function reopen(buf, expectedlines) local function reopen(buf, expectedlines)
ok(meths.nvim_buf_detach(buf)) ok(api.nvim_buf_detach(buf))
expectn('nvim_buf_detach_event', { buf }) expectn('nvim_buf_detach_event', { buf })
-- for some reason the :edit! increments tick by 2 -- for some reason the :edit! increments tick by 2
command('edit!') command('edit!')
local tick = eval('b:changedtick') local tick = eval('b:changedtick')
ok(meths.nvim_buf_attach(buf, true, {})) ok(api.nvim_buf_attach(buf, true, {}))
local firstline = 0 local firstline = 0
expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false }) expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false })
command('normal! gg') command('normal! gg')
@@ -197,21 +197,21 @@ describe('API: buffer events:', function()
-- add a line at the start of an empty file -- add a line at the start of an empty file
command('enew') command('enew')
tick = eval('b:changedtick') tick = eval('b:changedtick')
local b2 = meths.nvim_get_current_buf() local b2 = api.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b2, true, {})) ok(api.nvim_buf_attach(b2, true, {}))
expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false }) expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false })
eval('append(0, ["new line 1"])') eval('append(0, ["new line 1"])')
tick = tick + 1 tick = tick + 1
expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false }) expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false })
-- turn off buffer events manually -- turn off buffer events manually
meths.nvim_buf_detach(b2) api.nvim_buf_detach(b2)
expectn('nvim_buf_detach_event', { b2 }) expectn('nvim_buf_detach_event', { b2 })
-- add multiple lines to a blank file -- add multiple lines to a blank file
command('enew!') command('enew!')
local b3 = meths.nvim_get_current_buf() local b3 = api.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b3, true, {})) ok(api.nvim_buf_attach(b3, true, {}))
tick = eval('b:changedtick') tick = eval('b:changedtick')
expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false }) expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false })
eval('append(0, ["new line 1", "new line 2", "new line 3"])') eval('append(0, ["new line 1", "new line 2", "new line 3"])')
@@ -222,7 +222,7 @@ describe('API: buffer events:', function()
) )
-- use the API itself to add a line to the start of the buffer -- use the API itself to add a line to the start of the buffer
meths.nvim_buf_set_lines(b3, 0, 0, true, { 'New First Line' }) api.nvim_buf_set_lines(b3, 0, 0, true, { 'New First Line' })
tick = tick + 1 tick = tick + 1
expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false }) expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false })
end) end)
@@ -306,8 +306,8 @@ describe('API: buffer events:', function()
command('bdelete!') command('bdelete!')
tick = 2 tick = 2
expectn('nvim_buf_detach_event', { b }) expectn('nvim_buf_detach_event', { b })
local bnew = meths.nvim_get_current_buf() local bnew = api.nvim_get_current_buf()
ok(meths.nvim_buf_attach(bnew, true, {})) ok(api.nvim_buf_attach(bnew, true, {}))
expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false }) expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false })
sendkeys('i') sendkeys('i')
sendkeys('h') sendkeys('h')
@@ -472,25 +472,25 @@ describe('API: buffer events:', function()
end) end)
it('does not get confused if enabled/disabled many times', function() it('does not get confused if enabled/disabled many times', function()
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
local b, tick = editoriginal(false) local b, tick = editoriginal(false)
-- Enable buffer events many times. -- Enable buffer events many times.
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false }) expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false })
eval('rpcnotify(' .. channel .. ', "Hello There")') eval('rpcnotify(' .. channel .. ', "Hello There")')
expectn('Hello There', {}) expectn('Hello There', {})
-- Disable buffer events many times. -- Disable buffer events many times.
ok(meths.nvim_buf_detach(b)) ok(api.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b)) ok(api.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b)) ok(api.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b)) ok(api.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b)) ok(api.nvim_buf_detach(b))
expectn('nvim_buf_detach_event', { b }) expectn('nvim_buf_detach_event', { b })
eval('rpcnotify(' .. channel .. ', "Hello Again")') eval('rpcnotify(' .. channel .. ', "Hello Again")')
expectn('Hello Again', {}) expectn('Hello Again', {})
@@ -573,7 +573,7 @@ describe('API: buffer events:', function()
it('works with :diffput and :diffget', function() it('works with :diffput and :diffget', function()
local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' }) local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' })
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
command('diffthis') command('diffthis')
command('rightbelow vsplit') command('rightbelow vsplit')
local b2, tick2 = open(true, { 'BBB', 'CCC' }) local b2, tick2 = open(true, { 'BBB', 'CCC' })
@@ -690,7 +690,7 @@ describe('API: buffer events:', function()
it('detaches if the buffer is closed', function() it('detaches if the buffer is closed', function()
local b, tick = editoriginal(true, { 'AAA' }) local b, tick = editoriginal(true, { 'AAA' })
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
-- Test that buffer events are working. -- Test that buffer events are working.
command('normal! x') command('normal! x')
@@ -729,7 +729,7 @@ describe('API: buffer events:', function()
it(':enew! does not detach hidden buffer', function() it(':enew! does not detach hidden buffer', function()
local b, tick = editoriginal(true, { 'AAA', 'BBB' }) local b, tick = editoriginal(true, { 'AAA', 'BBB' })
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
command('set undoreload=1 hidden') command('set undoreload=1 hidden')
command('normal! x') command('normal! x')
@@ -743,7 +743,7 @@ describe('API: buffer events:', function()
it('stays attached if the buffer is hidden', function() it('stays attached if the buffer is hidden', function()
local b, tick = editoriginal(true, { 'AAA' }) local b, tick = editoriginal(true, { 'AAA' })
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
-- Test that buffer events are working. -- Test that buffer events are working.
command('normal! x') command('normal! x')
@@ -790,14 +790,14 @@ describe('API: buffer events:', function()
it('does not send the buffer content if not requested', function() it('does not send the buffer content if not requested', function()
clear() clear()
local b, tick = editoriginal(false) local b, tick = editoriginal(false)
ok(meths.nvim_buf_attach(b, false, {})) ok(api.nvim_buf_attach(b, false, {}))
expectn('nvim_buf_changedtick_event', { b, tick }) expectn('nvim_buf_changedtick_event', { b, tick })
end) end)
it('returns a proper error on nonempty options dict', function() it('returns a proper error on nonempty options dict', function()
clear() clear()
local b = editoriginal(false) local b = editoriginal(false)
eq("Invalid key: 'builtin'", pcall_err(meths.nvim_buf_attach, b, false, { builtin = 'asfd' })) eq("Invalid key: 'builtin'", pcall_err(api.nvim_buf_attach, b, false, { builtin = 'asfd' }))
end) end)
it('nvim_buf_attach returns response after delay #8634', function() it('nvim_buf_attach returns response after delay #8634', function()
@@ -869,12 +869,12 @@ describe('API: buffer events:', function()
it('when :terminal lines change', function() it('when :terminal lines change', function()
local buffer_lines = {} local buffer_lines = {}
local expected_lines = {} local expected_lines = {}
funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, { fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '-n', '-c', 'set shortmess+=A' }, {
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
}) })
local b = meths.nvim_get_current_buf() local b = api.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b, true, {})) ok(api.nvim_buf_attach(b, true, {}))
for _ = 1, 22 do for _ = 1, 22 do
table.insert(expected_lines, '~') table.insert(expected_lines, '~')

View File

@@ -4,14 +4,14 @@ local NIL = vim.NIL
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local meths = helpers.meths local api = helpers.api
local matches = helpers.matches local matches = helpers.matches
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
describe('nvim_get_commands', function() describe('nvim_get_commands', function()
local cmd_dict = { local cmd_dict = {
@@ -49,39 +49,39 @@ describe('nvim_get_commands', function()
before_each(clear) before_each(clear)
it('gets empty list if no commands were defined', function() it('gets empty list if no commands were defined', function()
eq({}, meths.nvim_get_commands({ builtin = false })) eq({}, api.nvim_get_commands({ builtin = false }))
end) end)
it('validation', function() it('validation', function()
eq('builtin=true not implemented', pcall_err(meths.nvim_get_commands, { builtin = true })) eq('builtin=true not implemented', pcall_err(api.nvim_get_commands, { builtin = true }))
eq("Invalid key: 'foo'", pcall_err(meths.nvim_get_commands, { foo = 'blah' })) eq("Invalid key: 'foo'", pcall_err(api.nvim_get_commands, { foo = 'blah' }))
end) end)
it('gets global user-defined commands', function() it('gets global user-defined commands', function()
-- Define a command. -- Define a command.
command('command -nargs=1 Hello echo "Hello World"') command('command -nargs=1 Hello echo "Hello World"')
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false })) eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
-- Define another command. -- Define another command.
command('command -nargs=? Pwd pwd') command('command -nargs=? Pwd pwd')
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_get_commands({ builtin = false })) eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_get_commands({ builtin = false }))
-- Delete a command. -- Delete a command.
command('delcommand Pwd') command('delcommand Pwd')
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false })) eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
end) end)
it('gets buffer-local user-defined commands', function() it('gets buffer-local user-defined commands', function()
-- Define a buffer-local command. -- Define a buffer-local command.
command('command -buffer -nargs=1 Hello echo "Hello World"') command('command -buffer -nargs=1 Hello echo "Hello World"')
eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false })) eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false }))
-- Define another buffer-local command. -- Define another buffer-local command.
command('command -buffer -nargs=? Pwd pwd') command('command -buffer -nargs=? Pwd pwd')
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_buf_get_commands(0, { builtin = false })) eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_buf_get_commands(0, { builtin = false }))
-- Delete a command. -- Delete a command.
command('delcommand Pwd') command('delcommand Pwd')
eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false })) eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false }))
-- {builtin=true} always returns empty for buffer-local case. -- {builtin=true} always returns empty for buffer-local case.
eq({}, meths.nvim_buf_get_commands(0, { builtin = true })) eq({}, api.nvim_buf_get_commands(0, { builtin = true }))
end) end)
it('gets various command attributes', function() it('gets various command attributes', function()
@@ -169,9 +169,9 @@ describe('nvim_get_commands', function()
let s:foo = 1 let s:foo = 1
command -complete=custom,ListUsers -nargs=+ Finger !finger <args> command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
]]) ]])
eq({ Finger = cmd1 }, meths.nvim_get_commands({ builtin = false })) eq({ Finger = cmd1 }, api.nvim_get_commands({ builtin = false }))
command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>') command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
eq({ Finger = cmd1, TestCmd = cmd0 }, meths.nvim_get_commands({ builtin = false })) eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false }))
source([[ source([[
function! s:foo() abort function! s:foo() abort
@@ -191,7 +191,7 @@ describe('nvim_get_commands', function()
-- TODO(justinmk): Order is stable but undefined. Sort before return? -- TODO(justinmk): Order is stable but undefined. Sort before return?
eq( eq(
{ Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 }, { Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 },
meths.nvim_get_commands({ builtin = false }) api.nvim_get_commands({ builtin = false })
) )
end) end)
end) end)
@@ -200,9 +200,9 @@ describe('nvim_create_user_command', function()
before_each(clear) before_each(clear)
it('works with strings', function() it('works with strings', function()
meths.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 }) api.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 })
command('SomeCommand 42') command('SomeCommand 42')
eq(42, meths.nvim_eval('g:command_fired')) eq(42, api.nvim_eval('g:command_fired'))
end) end)
it('works with Lua functions', function() it('works with Lua functions', function()
@@ -644,10 +644,10 @@ describe('nvim_create_user_command', function()
end) end)
it('can define buffer-local commands', function() it('can define buffer-local commands', function()
local bufnr = meths.nvim_create_buf(false, false) local bufnr = api.nvim_create_buf(false, false)
meths.nvim_buf_create_user_command(bufnr, 'Hello', '', {}) api.nvim_buf_create_user_command(bufnr, 'Hello', '', {})
matches('Not an editor command: Hello', pcall_err(command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
meths.nvim_set_current_buf(bufnr) api.nvim_set_current_buf(bufnr)
command('Hello') command('Hello')
assert_alive() assert_alive()
end) end)
@@ -670,9 +670,9 @@ describe('nvim_create_user_command', function()
]] ]]
feed(':Test a<Tab>') feed(':Test a<Tab>')
eq('Test aaa', funcs.getcmdline()) eq('Test aaa', fn.getcmdline())
feed('<C-U>Test b<Tab>') feed('<C-U>Test b<Tab>')
eq('Test bbb', funcs.getcmdline()) eq('Test bbb', fn.getcmdline())
end) end)
it('does not allow invalid command names', function() it('does not allow invalid command names', function()
@@ -729,29 +729,29 @@ describe('nvim_create_user_command', function()
vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {}) vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
end, {}) end, {})
]] ]]
eq('3', meths.nvim_cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true })) eq('3', api.nvim_cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
eq(1, #meths.nvim_list_tabpages()) eq(1, #api.nvim_list_tabpages())
exec_lua [[ exec_lua [[
vim.api.nvim_create_user_command('MySplit', function(opts) vim.api.nvim_create_user_command('MySplit', function(opts)
vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {}) vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {})
end, {}) end, {})
]] ]]
meths.nvim_cmd({ cmd = 'MySplit' }, {}) api.nvim_cmd({ cmd = 'MySplit' }, {})
eq(1, #meths.nvim_list_tabpages()) eq(1, #api.nvim_list_tabpages())
eq(2, #meths.nvim_list_wins()) eq(2, #api.nvim_list_wins())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(2, #meths.nvim_list_tabpages()) eq(2, #api.nvim_list_tabpages())
eq(2, funcs.tabpagenr()) eq(2, fn.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {}) api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(3, #meths.nvim_list_tabpages()) eq(3, #api.nvim_list_tabpages())
eq(2, funcs.tabpagenr()) eq(2, fn.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {}) api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
eq(4, #meths.nvim_list_tabpages()) eq(4, #api.nvim_list_tabpages())
eq(4, funcs.tabpagenr()) eq(4, fn.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {}) api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
eq(5, #meths.nvim_list_tabpages()) eq(5, #api.nvim_list_tabpages())
eq(1, funcs.tabpagenr()) eq(1, fn.tabpagenr())
end) end)
end) end)
@@ -759,16 +759,16 @@ describe('nvim_del_user_command', function()
before_each(clear) before_each(clear)
it('can delete global commands', function() it('can delete global commands', function()
meths.nvim_create_user_command('Hello', 'echo "Hi"', {}) api.nvim_create_user_command('Hello', 'echo "Hi"', {})
command('Hello') command('Hello')
meths.nvim_del_user_command('Hello') api.nvim_del_user_command('Hello')
matches('Not an editor command: Hello', pcall_err(command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
end) end)
it('can delete buffer-local commands', function() it('can delete buffer-local commands', function()
meths.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {}) api.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {})
command('Hello') command('Hello')
meths.nvim_buf_del_user_command(0, 'Hello') api.nvim_buf_del_user_command(0, 'Hello')
matches('Not an editor command: Hello', pcall_err(command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
end) end)
end) end)

View File

@@ -10,7 +10,7 @@ local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local exec = helpers.exec local exec = helpers.exec
local meths = helpers.meths local api = helpers.api
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local function expect(contents) local function expect(contents)
@@ -24,21 +24,21 @@ local function set_extmark(ns_id, id, line, col, opts)
if id ~= nil and id ~= 0 then if id ~= nil and id ~= 0 then
opts.id = id opts.id = id
end end
return meths.nvim_buf_set_extmark(0, ns_id, line, col, opts) return api.nvim_buf_set_extmark(0, ns_id, line, col, opts)
end end
local function get_extmarks(ns_id, start, end_, opts) local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then if opts == nil then
opts = {} opts = {}
end end
return meths.nvim_buf_get_extmarks(0, ns_id, start, end_, opts) return api.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
end end
local function get_extmark_by_id(ns_id, id, opts) local function get_extmark_by_id(ns_id, id, opts)
if opts == nil then if opts == nil then
opts = {} opts = {}
end end
return meths.nvim_buf_get_extmark_by_id(0, ns_id, id, opts) return api.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
end end
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
@@ -196,11 +196,11 @@ describe('API/extmarks', function()
eq({ row, col }, rv) eq({ row, col }, rv)
-- remove the test marks -- remove the test marks
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[1])) eq(true, api.nvim_buf_del_extmark(0, ns, marks[1]))
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[1])) eq(false, api.nvim_buf_del_extmark(0, ns, marks[1]))
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[2])) eq(true, api.nvim_buf_del_extmark(0, ns, marks[2]))
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[3])) eq(false, api.nvim_buf_del_extmark(0, ns, marks[3]))
eq(false, meths.nvim_buf_del_extmark(0, ns, 1000)) eq(false, api.nvim_buf_del_extmark(0, ns, 1000))
end) end)
it('can clear a specific namespace range', function() it('can clear a specific namespace range', function()
@@ -208,7 +208,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1) set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer -- force a new undo buffer
feed('o<esc>') feed('o<esc>')
meths.nvim_buf_clear_namespace(0, ns2, 0, -1) api.nvim_buf_clear_namespace(0, ns2, 0, -1)
eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
@@ -224,7 +224,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1) set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer -- force a new undo buffer
feed('o<esc>') feed('o<esc>')
meths.nvim_buf_clear_namespace(0, -1, 0, -1) api.nvim_buf_clear_namespace(0, -1, 0, -1)
eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
@@ -242,14 +242,14 @@ describe('API/extmarks', function()
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('dd') feed('dd')
eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
meths.nvim_buf_clear_namespace(0, ns, 0, -1) api.nvim_buf_clear_namespace(0, ns, 0, -1)
eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
set_extmark(ns, 1, 0, 0, { right_gravity = false }) set_extmark(ns, 1, 0, 0, { right_gravity = false })
set_extmark(ns, 2, 1, 0, { right_gravity = false }) set_extmark(ns, 2, 1, 0, { right_gravity = false })
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
meths.nvim_buf_clear_namespace(0, ns, 0, -1) api.nvim_buf_clear_namespace(0, ns, 0, -1)
end) end)
it('querying for information and ranges', function() it('querying for information and ranges', function()
@@ -931,7 +931,7 @@ describe('API/extmarks', function()
-- Test unset -- Test unset
feed('o<esc>') feed('o<esc>')
meths.nvim_buf_del_extmark(0, ns, marks[3]) api.nvim_buf_del_extmark(0, ns, marks[3])
feed('u') feed('u')
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
-- undo does NOT restore deleted marks -- undo does NOT restore deleted marks
@@ -987,10 +987,10 @@ describe('API/extmarks', function()
rv = get_extmarks(ns2, positions[2], positions[1]) rv = get_extmarks(ns2, positions[2], positions[1])
eq(2, #rv) eq(2, #rv)
meths.nvim_buf_del_extmark(0, ns, marks[1]) api.nvim_buf_del_extmark(0, ns, marks[1])
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(2, #rv) eq(2, #rv)
meths.nvim_buf_del_extmark(0, ns2, marks[1]) api.nvim_buf_del_extmark(0, ns2, marks[1])
rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
eq(2, #rv) eq(2, #rv)
end) end)
@@ -1427,7 +1427,7 @@ describe('API/extmarks', function()
"Invalid 'ns_id': 3", "Invalid 'ns_id': 3",
pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]) pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
) )
eq("Invalid 'ns_id': 3", pcall_err(meths.nvim_buf_del_extmark, 0, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2])) eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end) end)
@@ -1470,7 +1470,7 @@ describe('API/extmarks', function()
it('in read-only buffer', function() it('in read-only buffer', function()
command('view! runtime/doc/help.txt') command('view! runtime/doc/help.txt')
eq(true, meths.nvim_get_option_value('ro', {})) eq(true, api.nvim_get_option_value('ro', {}))
local id = set_extmark(ns, 0, 0, 2) local id = set_extmark(ns, 0, 0, 2)
eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
end) end)
@@ -1478,8 +1478,8 @@ describe('API/extmarks', function()
it('can set a mark to other buffer', function() it('can set a mark to other buffer', function()
local buf = request('nvim_create_buf', 0, 1) local buf = request('nvim_create_buf', 0, 1)
request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' }) request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
local id = meths.nvim_buf_set_extmark(buf, ns, 1, 0, {}) local id = api.nvim_buf_set_extmark(buf, ns, 1, 0, {})
eq({ { id, 1, 0 } }, meths.nvim_buf_get_extmarks(buf, ns, 0, -1, {})) eq({ { id, 1, 0 } }, api.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
end) end)
it('does not crash with append/delete/undo sequence', function() it('does not crash with append/delete/undo sequence', function()
@@ -1495,30 +1495,30 @@ describe('API/extmarks', function()
it('works with left and right gravity', function() it('works with left and right gravity', function()
-- right gravity should move with inserted text, while -- right gravity should move with inserted text, while
-- left gravity should stay in place. -- left gravity should stay in place.
meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false }) api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false })
meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true }) api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
feed([[Aasdfasdf]]) feed([[Aasdfasdf]])
eq({ { 1, 0, 5 }, { 2, 0, 13 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 5 }, { 2, 0, 13 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
-- but both move when text is inserted before -- but both move when text is inserted before
feed([[<esc>Iasdf<esc>]]) feed([[<esc>Iasdf<esc>]])
-- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true)) -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true))
eq({ { 1, 0, 9 }, { 2, 0, 17 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 9 }, { 2, 0, 17 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
-- clear text -- clear text
meths.nvim_buf_set_text(0, 0, 0, 0, 17, {}) api.nvim_buf_set_text(0, 0, 0, 0, 17, {})
-- handles set_text correctly as well -- handles set_text correctly as well
eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 0 }, { 2, 0, 0 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
meths.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' }) api.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
feed('u') feed('u')
-- handles pasting -- handles pasting
exec([[let @a='asdfasdf']]) exec([[let @a='asdfasdf']])
feed([["ap]]) feed([["ap]])
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
end) end)
it('can accept "end_row" or "end_line" #16548', function() it('can accept "end_row" or "end_line" #16548', function()
@@ -1545,7 +1545,7 @@ describe('API/extmarks', function()
it('in prompt buffer', function() it('in prompt buffer', function()
feed('dd') feed('dd')
local id = set_extmark(ns, marks[1], 0, 0, {}) local id = set_extmark(ns, marks[1], 0, 0, {})
meths.nvim_set_option_value('buftype', 'prompt', {}) api.nvim_set_option_value('buftype', 'prompt', {})
feed('i<esc>') feed('i<esc>')
eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
end) end)
@@ -1639,7 +1639,7 @@ describe('API/extmarks', function()
right_gravity = true, right_gravity = true,
}, },
}, get_extmark_by_id(ns, marks[3], { details = true })) }, get_extmark_by_id(ns, marks[3], { details = true }))
meths.nvim_buf_clear_namespace(0, ns, 0, -1) api.nvim_buf_clear_namespace(0, ns, 0, -1)
-- legacy sign mark includes sign name -- legacy sign mark includes sign name
command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine') command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
command('sign place 1 name=sign1 line=1') command('sign place 1 name=sign1 line=1')
@@ -1693,7 +1693,7 @@ describe('API/extmarks', function()
screen = Screen.new(40, 6) screen = Screen.new(40, 6)
screen:attach() screen:attach()
feed('dd6iaaa bbb ccc<CR><ESC>gg') feed('dd6iaaa bbb ccc<CR><ESC>gg')
meths.nvim_set_option_value('signcolumn', 'auto:2', {}) api.nvim_set_option_value('signcolumn', 'auto:2', {})
set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 }) set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 })
set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 }) set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 })
-- mark with invalidate is removed -- mark with invalidate is removed
@@ -1768,7 +1768,7 @@ describe('Extmarks buffer api with many marks', function()
for i = 1, 30 do for i = 1, 30 do
lines[#lines + 1] = string.rep('x ', i) lines[#lines + 1] = string.rep('x ', i)
end end
meths.nvim_buf_set_lines(0, 0, -1, true, lines) api.nvim_buf_set_lines(0, 0, -1, true, lines)
local ns = ns1 local ns = ns1
local q = 0 local q = 0
for i = 0, 29 do for i = 0, 29 do
@@ -1802,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function()
end) end)
it('can clear all marks in ns', function() it('can clear all marks in ns', function()
meths.nvim_buf_clear_namespace(0, ns1, 0, -1) api.nvim_buf_clear_namespace(0, ns1, 0, -1)
eq({}, get_marks(ns1)) eq({}, get_marks(ns1))
eq(ns_marks[ns2], get_marks(ns2)) eq(ns_marks[ns2], get_marks(ns2))
meths.nvim_buf_clear_namespace(0, ns2, 0, -1) api.nvim_buf_clear_namespace(0, ns2, 0, -1)
eq({}, get_marks(ns1)) eq({}, get_marks(ns1))
eq({}, get_marks(ns2)) eq({}, get_marks(ns2))
end) end)
it('can clear line range', function() it('can clear line range', function()
meths.nvim_buf_clear_namespace(0, ns1, 10, 20) api.nvim_buf_clear_namespace(0, ns1, 10, 20)
for id, mark in pairs(ns_marks[ns1]) do for id, mark in pairs(ns_marks[ns1]) do
if 10 <= mark[1] and mark[1] < 20 then if 10 <= mark[1] and mark[1] < 20 then
ns_marks[ns1][id] = nil ns_marks[ns1][id] = nil

View File

@@ -4,8 +4,8 @@ local Screen = require('test.functional.ui.screen')
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local command = helpers.command local command = helpers.command
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local meths = helpers.meths local api = helpers.api
local funcs = helpers.funcs local fn = helpers.fn
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local ok = helpers.ok local ok = helpers.ok
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@@ -52,128 +52,125 @@ describe('API: highlight', function()
it('nvim_get_hl_by_id', function() it('nvim_get_hl_by_id', function()
local hl_id = eval("hlID('NewHighlight')") local hl_id = eval("hlID('NewHighlight')")
eq(expected_cterm, meths.nvim_get_hl_by_id(hl_id, false)) eq(expected_cterm, api.nvim_get_hl_by_id(hl_id, false))
hl_id = eval("hlID('NewHighlight')") hl_id = eval("hlID('NewHighlight')")
-- Test valid id. -- Test valid id.
eq(expected_rgb, meths.nvim_get_hl_by_id(hl_id, true)) eq(expected_rgb, api.nvim_get_hl_by_id(hl_id, true))
-- Test invalid id. -- Test invalid id.
eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) eq('Invalid highlight id: 30000', pcall_err(api.nvim_get_hl_by_id, 30000, false))
-- Test all highlight properties. -- Test all highlight properties.
command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true)) eq(expected_rgb2, api.nvim_get_hl_by_id(hl_id, true))
-- Test undercurl -- Test undercurl
command('hi NewHighlight gui=undercurl') command('hi NewHighlight gui=undercurl')
eq(expected_undercurl, meths.nvim_get_hl_by_id(hl_id, true)) eq(expected_undercurl, api.nvim_get_hl_by_id(hl_id, true))
-- Test nil argument. -- Test nil argument.
eq( eq(
'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer',
pcall_err(meths.nvim_get_hl_by_id, { nil }, false) pcall_err(api.nvim_get_hl_by_id, { nil }, false)
) )
-- Test 0 argument. -- Test 0 argument.
eq('Invalid highlight id: 0', pcall_err(meths.nvim_get_hl_by_id, 0, false)) eq('Invalid highlight id: 0', pcall_err(api.nvim_get_hl_by_id, 0, false))
-- Test -1 argument. -- Test -1 argument.
eq('Invalid highlight id: -1', pcall_err(meths.nvim_get_hl_by_id, -1, false)) eq('Invalid highlight id: -1', pcall_err(api.nvim_get_hl_by_id, -1, false))
-- Test highlight group without ctermbg value. -- Test highlight group without ctermbg value.
command('hi Normal ctermfg=red ctermbg=yellow') command('hi Normal ctermfg=red ctermbg=yellow')
command('hi NewConstant ctermfg=green guifg=white guibg=blue') command('hi NewConstant ctermfg=green guifg=white guibg=blue')
hl_id = eval("hlID('NewConstant')") hl_id = eval("hlID('NewConstant')")
eq({ foreground = 10 }, meths.nvim_get_hl_by_id(hl_id, false)) eq({ foreground = 10 }, api.nvim_get_hl_by_id(hl_id, false))
-- Test highlight group without ctermfg value. -- Test highlight group without ctermfg value.
command('hi clear NewConstant') command('hi clear NewConstant')
command('hi NewConstant ctermbg=Magenta guifg=white guibg=blue') command('hi NewConstant ctermbg=Magenta guifg=white guibg=blue')
eq({ background = 13 }, meths.nvim_get_hl_by_id(hl_id, false)) eq({ background = 13 }, api.nvim_get_hl_by_id(hl_id, false))
-- Test highlight group with ctermfg and ctermbg values. -- Test highlight group with ctermfg and ctermbg values.
command('hi clear NewConstant') command('hi clear NewConstant')
command('hi NewConstant ctermfg=green ctermbg=Magenta guifg=white guibg=blue') command('hi NewConstant ctermfg=green ctermbg=Magenta guifg=white guibg=blue')
eq({ foreground = 10, background = 13 }, meths.nvim_get_hl_by_id(hl_id, false)) eq({ foreground = 10, background = 13 }, api.nvim_get_hl_by_id(hl_id, false))
end) end)
it('nvim_get_hl_by_name', function() it('nvim_get_hl_by_name', function()
local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red }
-- Test `Normal` default values. -- Test `Normal` default values.
eq({}, meths.nvim_get_hl_by_name('Normal', true)) eq({}, api.nvim_get_hl_by_name('Normal', true))
eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false)) eq(expected_cterm, api.nvim_get_hl_by_name('NewHighlight', false))
eq(expected_rgb, meths.nvim_get_hl_by_name('NewHighlight', true)) eq(expected_rgb, api.nvim_get_hl_by_name('NewHighlight', true))
-- Test `Normal` modified values. -- Test `Normal` modified values.
command('hi Normal guifg=red guibg=yellow') command('hi Normal guifg=red guibg=yellow')
eq(expected_normal, meths.nvim_get_hl_by_name('Normal', true)) eq(expected_normal, api.nvim_get_hl_by_name('Normal', true))
-- Test invalid name. -- Test invalid name.
eq( eq(
"Invalid highlight name: 'unknown_highlight'", "Invalid highlight name: 'unknown_highlight'",
pcall_err(meths.nvim_get_hl_by_name, 'unknown_highlight', false) pcall_err(api.nvim_get_hl_by_name, 'unknown_highlight', false)
) )
-- Test nil argument. -- Test nil argument.
eq( eq(
'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String',
pcall_err(meths.nvim_get_hl_by_name, { nil }, false) pcall_err(api.nvim_get_hl_by_name, { nil }, false)
) )
-- Test empty string argument. -- Test empty string argument.
eq('Invalid highlight name', pcall_err(meths.nvim_get_hl_by_name, '', false)) eq('Invalid highlight name', pcall_err(api.nvim_get_hl_by_name, '', false))
-- Test "standout" attribute. #8054 -- Test "standout" attribute. #8054
eq({ underline = true }, meths.nvim_get_hl_by_name('cursorline', 0)) eq({ underline = true }, api.nvim_get_hl_by_name('cursorline', 0))
command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline')
command('set cursorline') command('set cursorline')
eq({ underline = true, standout = true }, meths.nvim_get_hl_by_name('cursorline', 0)) eq({ underline = true, standout = true }, api.nvim_get_hl_by_name('cursorline', 0))
-- Test cterm & Normal values. #18024 (tail) & #18980 -- Test cterm & Normal values. #18024 (tail) & #18980
-- Ensure Normal, and groups that match Normal return their fg & bg cterm values -- Ensure Normal, and groups that match Normal return their fg & bg cterm values
meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) api.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 })
meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) api.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true })
-- Note colors are "cterm" values, not rgb-as-ints -- Note colors are "cterm" values, not rgb-as-ints
eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false)) eq({ foreground = 17, background = 213 }, api.nvim_get_hl_by_name('Normal', false))
eq( eq(
{ foreground = 17, background = 213, nocombine = true }, { foreground = 17, background = 213, nocombine = true },
meths.nvim_get_hl_by_name('NotNormal', false) api.nvim_get_hl_by_name('NotNormal', false)
) )
end) end)
it('nvim_get_hl_id_by_name', function() it('nvim_get_hl_id_by_name', function()
-- precondition: use a hl group that does not yet exist -- precondition: use a hl group that does not yet exist
eq( eq("Invalid highlight name: 'Shrubbery'", pcall_err(api.nvim_get_hl_by_name, 'Shrubbery', true))
"Invalid highlight name: 'Shrubbery'", eq(0, fn.hlID('Shrubbery'))
pcall_err(meths.nvim_get_hl_by_name, 'Shrubbery', true)
)
eq(0, funcs.hlID('Shrubbery'))
local hl_id = meths.nvim_get_hl_id_by_name('Shrubbery') local hl_id = api.nvim_get_hl_id_by_name('Shrubbery')
ok(hl_id > 0) ok(hl_id > 0)
eq(hl_id, funcs.hlID('Shrubbery')) eq(hl_id, fn.hlID('Shrubbery'))
command('hi Shrubbery guifg=#888888 guibg=#888888') command('hi Shrubbery guifg=#888888 guibg=#888888')
eq( eq(
{ foreground = tonumber('0x888888'), background = tonumber('0x888888') }, { foreground = tonumber('0x888888'), background = tonumber('0x888888') },
meths.nvim_get_hl_by_id(hl_id, true) api.nvim_get_hl_by_id(hl_id, true)
) )
eq( eq(
{ foreground = tonumber('0x888888'), background = tonumber('0x888888') }, { foreground = tonumber('0x888888'), background = tonumber('0x888888') },
meths.nvim_get_hl_by_name('Shrubbery', true) api.nvim_get_hl_by_name('Shrubbery', true)
) )
end) end)
it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function()
command('vsplit file') command('vsplit file')
local err, _ = pcall(meths.nvim_set_option_value, 'undofile', false, { buf = 1 }) local err, _ = pcall(api.nvim_set_option_value, 'undofile', false, { buf = 1 })
eq(true, err) eq(true, err)
err, _ = pcall(meths.nvim_set_option_value, 'undolevels', -1, { buf = 1 }) err, _ = pcall(api.nvim_set_option_value, 'undolevels', -1, { buf = 1 })
eq(true, err) eq(true, err)
err, _ = pcall(meths.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1) err, _ = pcall(api.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1)
eq(true, err) eq(true, err)
assert_alive() assert_alive()
end) end)
@@ -244,8 +241,8 @@ describe('API: set highlight', function()
} }
local function get_ns() local function get_ns()
local ns = meths.nvim_create_namespace('Test_set_hl') local ns = api.nvim_create_namespace('Test_set_hl')
meths.nvim_set_hl_ns(ns) api.nvim_set_hl_ns(ns)
return ns return ns
end end
@@ -254,51 +251,51 @@ describe('API: set highlight', function()
it('validation', function() it('validation', function()
eq( eq(
"Invalid 'blend': out of range", "Invalid 'blend': out of range",
pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 }) pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 })
) )
eq( eq(
"Invalid 'blend': expected Integer, got Array", "Invalid 'blend': expected Integer, got Array",
pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} }) pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} })
) )
end) end)
it('can set gui highlight', function() it('can set gui highlight', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1) api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl_by_name('Test_hl', true)) eq(highlight1, api.nvim_get_hl_by_name('Test_hl', true))
end) end)
it('can set cterm highlight', function() it('can set cterm highlight', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight2_config) api.nvim_set_hl(ns, 'Test_hl', highlight2_config)
eq(highlight2_result, meths.nvim_get_hl_by_name('Test_hl', false)) eq(highlight2_result, api.nvim_get_hl_by_name('Test_hl', false))
end) end)
it('can set empty cterm attr', function() it('can set empty cterm attr', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) api.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.nvim_get_hl_by_name('Test_hl', false)) eq({}, api.nvim_get_hl_by_name('Test_hl', false))
end) end)
it('cterm attr defaults to gui attr', function() it('cterm attr defaults to gui attr', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1) api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq({ eq({
bold = true, bold = true,
italic = true, italic = true,
}, meths.nvim_get_hl_by_name('Test_hl', false)) }, api.nvim_get_hl_by_name('Test_hl', false))
end) end)
it('can overwrite attr for cterm', function() it('can overwrite attr for cterm', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) api.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result_gui, meths.nvim_get_hl_by_name('Test_hl', true)) eq(highlight3_result_gui, api.nvim_get_hl_by_name('Test_hl', true))
eq(highlight3_result_cterm, meths.nvim_get_hl_by_name('Test_hl', false)) eq(highlight3_result_cterm, api.nvim_get_hl_by_name('Test_hl', false))
end) end)
it('only allows one underline attribute #22371', function() it('only allows one underline attribute #22371', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { api.nvim_set_hl(ns, 'Test_hl', {
underdouble = true, underdouble = true,
underdotted = true, underdotted = true,
cterm = { cterm = {
@@ -306,21 +303,21 @@ describe('API: set highlight', function()
undercurl = true, undercurl = true,
}, },
}) })
eq({ undercurl = true }, meths.nvim_get_hl_by_name('Test_hl', false)) eq({ undercurl = true }, api.nvim_get_hl_by_name('Test_hl', false))
eq({ underdotted = true }, meths.nvim_get_hl_by_name('Test_hl', true)) eq({ underdotted = true }, api.nvim_get_hl_by_name('Test_hl', true))
end) end)
it('can set a highlight in the global namespace', function() it('can set a highlight in the global namespace', function()
meths.nvim_set_hl(0, 'Test_hl', highlight2_config) api.nvim_set_hl(0, 'Test_hl', highlight2_config)
eq( eq(
'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', 'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse',
exec_capture('highlight Test_hl') exec_capture('highlight Test_hl')
) )
meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg })
eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl')) eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl'))
meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) api.nvim_set_hl(0, 'Test_hl2', highlight3_config)
eq( eq(
'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', 'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa',
exec_capture('highlight Test_hl2') exec_capture('highlight Test_hl2')
@@ -328,63 +325,63 @@ describe('API: set highlight', function()
-- Colors are stored with the name they are defined, but -- Colors are stored with the name they are defined, but
-- with canonical casing -- with canonical casing
meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' })
eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3'))
end) end)
it('can modify a highlight in the global namespace', function() it('can modify a highlight in the global namespace', function()
meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) api.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' })
eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3'))
meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red' }) api.nvim_set_hl(0, 'Test_hl3', { bg = 'red' })
eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3'))
meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 })
eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3'))
meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' })
eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3'))
meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 }) api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 })
eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3'))
eq( eq(
"Invalid highlight color: 'redd'", "Invalid highlight color: 'redd'",
pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' }) pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' })
) )
eq( eq(
"Invalid highlight color: 'bleu'", "Invalid highlight color: 'bleu'",
pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' })
) )
meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' })
eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3'))
eq( eq(
"Invalid highlight color: '#FF00FF'", "Invalid highlight color: '#FF00FF'",
pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' })
) )
for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do
meths.nvim_set_hl(0, 'Test_hl3', { fg = fg_val }) api.nvim_set_hl(0, 'Test_hl3', { fg = fg_val })
eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3'))
end end
meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 })
eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3'))
end) end)
it("correctly sets 'Normal' internal properties", function() it("correctly sets 'Normal' internal properties", function()
-- Normal has some special handling internally. #18024 -- Normal has some special handling internally. #18024
meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) api.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' })
eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true)) eq({ foreground = 131, background = 243 }, api.nvim_get_hl_by_name('Normal', true))
end) end)
it('does not segfault on invalid group name #20009', function() it('does not segfault on invalid group name #20009', function()
eq( eq(
"Invalid highlight name: 'foo bar'", "Invalid highlight name: 'foo bar'",
pcall_err(meths.nvim_set_hl, 0, 'foo bar', { bold = true }) pcall_err(api.nvim_set_hl, 0, 'foo bar', { bold = true })
) )
assert_alive() assert_alive()
end) end)
@@ -452,14 +449,14 @@ describe('API: get highlight', function()
local function get_ns() local function get_ns()
-- Test namespace filtering behavior -- Test namespace filtering behavior
local ns2 = meths.nvim_create_namespace('Another_namespace') local ns2 = api.nvim_create_namespace('Another_namespace')
meths.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 }) api.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 })
meths.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) api.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' })
meths.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) api.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' })
meths.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) api.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' })
local ns = meths.nvim_create_namespace('Test_set_hl') local ns = api.nvim_create_namespace('Test_set_hl')
meths.nvim_set_hl_ns(ns) api.nvim_set_hl_ns(ns)
return ns return ns
end end
@@ -469,24 +466,24 @@ describe('API: get highlight', function()
it('validation', function() it('validation', function()
eq( eq(
"Invalid 'name': expected String, got Integer", "Invalid 'name': expected String, got Integer",
pcall_err(meths.nvim_get_hl, 0, { name = 177 }) pcall_err(api.nvim_get_hl, 0, { name = 177 })
) )
eq('Highlight id out of bounds', pcall_err(meths.nvim_get_hl, 0, { name = 'Test set hl' })) eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { name = 'Test set hl' }))
end) end)
it('nvim_get_hl with create flag', function() it('nvim_get_hl with create flag', function()
eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false })) eq({}, api.nvim_get_hl(0, { name = 'Foo', create = false }))
eq(0, funcs.hlexists('Foo')) eq(0, fn.hlexists('Foo'))
meths.nvim_get_hl(0, { name = 'Bar', create = true }) api.nvim_get_hl(0, { name = 'Bar', create = true })
eq(1, funcs.hlexists('Bar')) eq(1, fn.hlexists('Bar'))
meths.nvim_get_hl(0, { name = 'FooBar' }) api.nvim_get_hl(0, { name = 'FooBar' })
eq(1, funcs.hlexists('FooBar')) eq(1, fn.hlexists('FooBar'))
end) end)
it('can get all highlights in current namespace', function() it('can get all highlights in current namespace', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) api.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' })
meths.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) api.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' })
eq({ eq({
Test_hl = { Test_hl = {
bg = 11845374, bg = 11845374,
@@ -494,42 +491,42 @@ describe('API: get highlight', function()
Test_hl_link = { Test_hl_link = {
link = 'Test_hl', link = 'Test_hl',
}, },
}, meths.nvim_get_hl(ns, {})) }, api.nvim_get_hl(ns, {}))
end) end)
it('can get gui highlight', function() it('can get gui highlight', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1) api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' })) eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end) end)
it('can get cterm highlight', function() it('can get cterm highlight', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight2) api.nvim_set_hl(ns, 'Test_hl', highlight2)
eq(highlight2, meths.nvim_get_hl(ns, { name = 'Test_hl' })) eq(highlight2, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end) end)
it('can get empty cterm attr', function() it('can get empty cterm attr', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) api.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.nvim_get_hl(ns, { name = 'Test_hl' })) eq({}, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end) end)
it('cterm attr defaults to gui attr', function() it('cterm attr defaults to gui attr', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1) api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' })) eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end) end)
it('can overwrite attr for cterm', function() it('can overwrite attr for cterm', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) api.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result, meths.nvim_get_hl(ns, { name = 'Test_hl' })) eq(highlight3_result, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end) end)
it('only allows one underline attribute #22371', function() it('only allows one underline attribute #22371', function()
local ns = get_ns() local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { api.nvim_set_hl(ns, 'Test_hl', {
underdouble = true, underdouble = true,
underdotted = true, underdotted = true,
cterm = { cterm = {
@@ -539,33 +536,33 @@ describe('API: get highlight', function()
}) })
eq( eq(
{ underdotted = true, cterm = { undercurl = true } }, { underdotted = true, cterm = { undercurl = true } },
meths.nvim_get_hl(ns, { name = 'Test_hl' }) api.nvim_get_hl(ns, { name = 'Test_hl' })
) )
end) end)
it('can get a highlight in the global namespace', function() it('can get a highlight in the global namespace', function()
meths.nvim_set_hl(0, 'Test_hl', highlight2) api.nvim_set_hl(0, 'Test_hl', highlight2)
eq(highlight2, meths.nvim_get_hl(0, { name = 'Test_hl' })) eq(highlight2, api.nvim_get_hl(0, { name = 'Test_hl' }))
meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg })
eq({ eq({
bg = 12970, bg = 12970,
}, meths.nvim_get_hl(0, { name = 'Test_hl' })) }, api.nvim_get_hl(0, { name = 'Test_hl' }))
meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) api.nvim_set_hl(0, 'Test_hl2', highlight3_config)
eq(highlight3_result, meths.nvim_get_hl(0, { name = 'Test_hl2' })) eq(highlight3_result, api.nvim_get_hl(0, { name = 'Test_hl2' }))
-- Colors are stored with the name they are defined, but -- Colors are stored with the name they are defined, but
-- with canonical casing -- with canonical casing
meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' })
eq({ eq({
bg = 16711680, bg = 16711680,
fg = 255, fg = 255,
}, meths.nvim_get_hl(0, { name = 'Test_hl3' })) }, api.nvim_get_hl(0, { name = 'Test_hl3' }))
end) end)
it('nvim_get_hl by id', function() it('nvim_get_hl by id', function()
local hl_id = meths.nvim_get_hl_id_by_name('NewHighlight') local hl_id = api.nvim_get_hl_id_by_name('NewHighlight')
command( command(
'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold'
@@ -577,14 +574,14 @@ describe('API: get highlight', function()
bold = true, bold = true,
ctermbg = 10, ctermbg = 10,
cterm = { underline = true }, cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id })) }, api.nvim_get_hl(0, { id = hl_id }))
-- Test 0 argument -- Test 0 argument
eq('Highlight id out of bounds', pcall_err(meths.nvim_get_hl, 0, { id = 0 })) eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { id = 0 }))
eq( eq(
"Invalid 'id': expected Integer, got String", "Invalid 'id': expected Integer, got String",
pcall_err(meths.nvim_get_hl, 0, { id = 'Test_set_hl' }) pcall_err(api.nvim_get_hl, 0, { id = 'Test_set_hl' })
) )
-- Test all highlight properties. -- Test all highlight properties.
@@ -602,7 +599,7 @@ describe('API: get highlight', function()
underline = true, underline = true,
ctermbg = 10, ctermbg = 10,
cterm = { underline = true }, cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id })) }, api.nvim_get_hl(0, { id = hl_id }))
-- Test undercurl -- Test undercurl
command('hi NewHighlight gui=undercurl') command('hi NewHighlight gui=undercurl')
@@ -613,16 +610,16 @@ describe('API: get highlight', function()
undercurl = true, undercurl = true,
ctermbg = 10, ctermbg = 10,
cterm = { underline = true }, cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id })) }, api.nvim_get_hl(0, { id = hl_id }))
end) end)
it('can correctly detect links', function() it('can correctly detect links', function()
command('hi String guifg=#a6e3a1 ctermfg=NONE') command('hi String guifg=#a6e3a1 ctermfg=NONE')
command('hi link @string string') command('hi link @string string')
command('hi link @string.cpp @string') command('hi link @string.cpp @string')
eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = 'String' })) eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = 'String' }))
eq({ link = 'String' }, meths.nvim_get_hl(0, { name = '@string' })) eq({ link = 'String' }, api.nvim_get_hl(0, { name = '@string' }))
eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = '@string.cpp', link = false })) eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = '@string.cpp', link = false }))
end) end)
it('can get all attributes for a linked group', function() it('can get all attributes for a linked group', function()
@@ -631,55 +628,55 @@ describe('API: get highlight', function()
command('hi! link Foo Bar') command('hi! link Foo Bar')
eq( eq(
{ link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true },
meths.nvim_get_hl(0, { name = 'Foo', link = true }) api.nvim_get_hl(0, { name = 'Foo', link = true })
) )
end) end)
it('can set link as well as other attributes', function() it('can set link as well as other attributes', function()
command('hi Bar guifg=red') command('hi Bar guifg=red')
local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } } local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } }
meths.nvim_set_hl(0, 'Foo', hl) api.nvim_set_hl(0, 'Foo', hl)
eq(hl, meths.nvim_get_hl(0, { name = 'Foo', link = true })) eq(hl, api.nvim_get_hl(0, { name = 'Foo', link = true }))
end) end)
it("doesn't contain unset groups", function() it("doesn't contain unset groups", function()
local id = meths.nvim_get_hl_id_by_name '@foobar.hubbabubba' local id = api.nvim_get_hl_id_by_name '@foobar.hubbabubba'
ok(id > 0) ok(id > 0)
local data = meths.nvim_get_hl(0, {}) local data = api.nvim_get_hl(0, {})
eq(nil, data['@foobar.hubbabubba']) eq(nil, data['@foobar.hubbabubba'])
eq(nil, data['@foobar']) eq(nil, data['@foobar'])
command 'hi @foobar.hubbabubba gui=bold' command 'hi @foobar.hubbabubba gui=bold'
data = meths.nvim_get_hl(0, {}) data = api.nvim_get_hl(0, {})
eq({ bold = true }, data['@foobar.hubbabubba']) eq({ bold = true }, data['@foobar.hubbabubba'])
eq(nil, data['@foobar']) eq(nil, data['@foobar'])
-- @foobar.hubbabubba was explicitly cleared and thus shows up -- @foobar.hubbabubba was explicitly cleared and thus shows up
-- but @foobar was never touched, and thus doesn't -- but @foobar was never touched, and thus doesn't
command 'hi clear @foobar.hubbabubba' command 'hi clear @foobar.hubbabubba'
data = meths.nvim_get_hl(0, {}) data = api.nvim_get_hl(0, {})
eq({}, data['@foobar.hubbabubba']) eq({}, data['@foobar.hubbabubba'])
eq(nil, data['@foobar']) eq(nil, data['@foobar'])
end) end)
it('should return default flag', function() it('should return default flag', function()
meths.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true }) api.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true })
eq({ fg = tonumber('00ff00', 16), default = true }, meths.nvim_get_hl(0, { name = 'Tried' })) eq({ fg = tonumber('00ff00', 16), default = true }, api.nvim_get_hl(0, { name = 'Tried' }))
end) end)
it('should not output empty gui and cterm #23474', function() it('should not output empty gui and cterm #23474', function()
meths.nvim_set_hl(0, 'Foo', { default = true }) api.nvim_set_hl(0, 'Foo', { default = true })
meths.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) api.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' })
meths.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) api.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } })
meths.nvim_set_hl( api.nvim_set_hl(
0, 0,
'FooBarA', 'FooBarA',
{ default = true, fg = '#ffffff', cterm = { bold = true, italic = true } } { default = true, fg = '#ffffff', cterm = { bold = true, italic = true } }
) )
eq('Foo xxx cleared', exec_capture('highlight Foo')) eq('Foo xxx cleared', exec_capture('highlight Foo'))
eq({ default = true }, meths.nvim_get_hl(0, { name = 'Foo' })) eq({ default = true }, api.nvim_get_hl(0, { name = 'Foo' }))
eq('Bar xxx guifg=#ffffff', exec_capture('highlight Bar')) eq('Bar xxx guifg=#ffffff', exec_capture('highlight Bar'))
eq('FooBar xxx cterm=bold guifg=#ffffff', exec_capture('highlight FooBar')) eq('FooBar xxx cterm=bold guifg=#ffffff', exec_capture('highlight FooBar'))
eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', exec_capture('highlight FooBarA')) eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', exec_capture('highlight FooBarA'))
@@ -688,27 +685,27 @@ describe('API: get highlight', function()
it('can override exist highlight group by force #20323', function() it('can override exist highlight group by force #20323', function()
local white = tonumber('ffffff', 16) local white = tonumber('ffffff', 16)
local green = tonumber('00ff00', 16) local green = tonumber('00ff00', 16)
meths.nvim_set_hl(0, 'Foo', { fg = white }) api.nvim_set_hl(0, 'Foo', { fg = white })
meths.nvim_set_hl(0, 'Foo', { fg = green, force = true }) api.nvim_set_hl(0, 'Foo', { fg = green, force = true })
eq({ fg = green }, meths.nvim_get_hl(0, { name = 'Foo' })) eq({ fg = green }, api.nvim_get_hl(0, { name = 'Foo' }))
meths.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true }) api.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true })
meths.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) api.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true })
eq({ link = 'Foo', default = true }, meths.nvim_get_hl(0, { name = 'Bar' })) eq({ link = 'Foo', default = true }, api.nvim_get_hl(0, { name = 'Bar' }))
end) end)
end) end)
describe('API: set/get highlight namespace', function() describe('API: set/get highlight namespace', function()
it('set/get highlight namespace', function() it('set/get highlight namespace', function()
eq(0, meths.nvim_get_hl_ns({})) eq(0, api.nvim_get_hl_ns({}))
local ns = meths.nvim_create_namespace('') local ns = api.nvim_create_namespace('')
meths.nvim_set_hl_ns(ns) api.nvim_set_hl_ns(ns)
eq(ns, meths.nvim_get_hl_ns({})) eq(ns, api.nvim_get_hl_ns({}))
end) end)
it('set/get window highlight namespace', function() it('set/get window highlight namespace', function()
eq(-1, meths.nvim_get_hl_ns({ winid = 0 })) eq(-1, api.nvim_get_hl_ns({ winid = 0 }))
local ns = meths.nvim_create_namespace('') local ns = api.nvim_create_namespace('')
meths.nvim_win_set_hl_ns(0, ns) api.nvim_win_set_hl_ns(0, ns)
eq(ns, meths.nvim_get_hl_ns({ winid = 0 })) eq(ns, api.nvim_get_hl_ns({ winid = 0 }))
end) end)
end) end)

View File

@@ -6,8 +6,8 @@ local eq, neq = helpers.eq, helpers.neq
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@@ -55,7 +55,7 @@ describe('nvim_get_keymap', function()
} }
it('returns empty list when no map', function() it('returns empty list when no map', function()
eq({}, meths.nvim_get_keymap('n')) eq({}, api.nvim_get_keymap('n'))
end) end)
it('returns list of all applicable mappings', function() it('returns list of all applicable mappings', function()
@@ -64,8 +64,8 @@ describe('nvim_get_keymap', function()
-- Should be the same as the dictionary we supplied earlier -- Should be the same as the dictionary we supplied earlier
-- and the dictionary you would get from maparg -- and the dictionary you would get from maparg
-- since this is a global map, and not script local -- since this is a global map, and not script local
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
eq({ funcs.maparg('foo', 'n', false, true) }, meths.nvim_get_keymap('n')) eq({ fn.maparg('foo', 'n', false, true) }, api.nvim_get_keymap('n'))
-- Add another mapping -- Add another mapping
command('nnoremap foo_longer bar_longer') command('nnoremap foo_longer bar_longer')
@@ -74,11 +74,11 @@ describe('nvim_get_keymap', function()
foolong_bar_map_table['lhsraw'] = 'foo_longer' foolong_bar_map_table['lhsraw'] = 'foo_longer'
foolong_bar_map_table['rhs'] = 'bar_longer' foolong_bar_map_table['rhs'] = 'bar_longer'
eq({ foolong_bar_map_table, foo_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foolong_bar_map_table, foo_bar_map_table }, api.nvim_get_keymap('n'))
-- Remove a mapping -- Remove a mapping
command('unmap foo_longer') command('unmap foo_longer')
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
end) end)
it('works for other modes', function() it('works for other modes', function()
@@ -92,7 +92,7 @@ describe('nvim_get_keymap', function()
insert_table['mode'] = 'i' insert_table['mode'] = 'i'
insert_table['mode_bits'] = 0x10 insert_table['mode_bits'] = 0x10
eq({ insert_table }, meths.nvim_get_keymap('i')) eq({ insert_table }, api.nvim_get_keymap('i'))
end) end)
it('considers scope', function() it('considers scope', function()
@@ -109,8 +109,8 @@ describe('nvim_get_keymap', function()
command('nnoremap <buffer> foo bar') command('nnoremap <buffer> foo bar')
-- The buffer mapping should not show up -- The buffer mapping should not show up
eq({ foolong_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foolong_bar_map_table }, api.nvim_get_keymap('n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
end) end)
it('considers scope for overlapping maps', function() it('considers scope for overlapping maps', function()
@@ -121,12 +121,12 @@ describe('nvim_get_keymap', function()
command('nnoremap <buffer> foo bar') command('nnoremap <buffer> foo bar')
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
end) end)
it('can retrieve mapping for different buffers', function() it('can retrieve mapping for different buffers', function()
local original_buffer = meths.nvim_buf_get_number(0) local original_buffer = api.nvim_buf_get_number(0)
-- Place something in each of the buffers to make sure they stick around -- Place something in each of the buffers to make sure they stick around
-- and set hidden so we can leave them -- and set hidden so we can leave them
command('set hidden') command('set hidden')
@@ -135,21 +135,21 @@ describe('nvim_get_keymap', function()
command('new') command('new')
command('normal! ihello 3') command('normal! ihello 3')
local final_buffer = meths.nvim_buf_get_number(0) local final_buffer = api.nvim_buf_get_number(0)
command('nnoremap <buffer> foo bar') command('nnoremap <buffer> foo bar')
-- Final buffer will have buffer mappings -- Final buffer will have buffer mappings
local buffer_table = shallowcopy(foo_bar_map_table) local buffer_table = shallowcopy(foo_bar_map_table)
buffer_table['buffer'] = final_buffer buffer_table['buffer'] = final_buffer
eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n')) eq({ buffer_table }, api.nvim_buf_get_keymap(final_buffer, 'n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
command('buffer ' .. original_buffer) command('buffer ' .. original_buffer)
eq(original_buffer, meths.nvim_buf_get_number(0)) eq(original_buffer, api.nvim_buf_get_number(0))
-- Original buffer won't have any mappings -- Original buffer won't have any mappings
eq({}, meths.nvim_get_keymap('n')) eq({}, api.nvim_get_keymap('n'))
eq({}, meths.nvim_buf_get_keymap(0, 'n')) eq({}, api.nvim_buf_get_keymap(0, 'n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n')) eq({ buffer_table }, api.nvim_buf_get_keymap(final_buffer, 'n'))
end) end)
-- Test toggle switches for basic options -- Test toggle switches for basic options
@@ -189,7 +189,7 @@ describe('nvim_get_keymap', function()
function() function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' ' .. option_token .. ' foo bar') command(map .. ' ' .. option_token .. ' foo bar')
local result = meths.nvim_get_keymap(mode)[1][option] local result = api.nvim_get_keymap(mode)[1][option]
eq(global_on_result, result) eq(global_on_result, result)
end end
) )
@@ -207,7 +207,7 @@ describe('nvim_get_keymap', function()
function() function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' <buffer> ' .. option_token .. ' foo bar') command(map .. ' <buffer> ' .. option_token .. ' foo bar')
local result = meths.nvim_buf_get_keymap(0, mode)[1][option] local result = api.nvim_buf_get_keymap(0, mode)[1][option]
eq(buffer_on_result, result) eq(buffer_on_result, result)
end end
) )
@@ -226,7 +226,7 @@ describe('nvim_get_keymap', function()
function() function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' baz bat') command(map .. ' baz bat')
local result = meths.nvim_get_keymap(mode)[1][option] local result = api.nvim_get_keymap(mode)[1][option]
eq(global_off_result, result) eq(global_off_result, result)
end end
) )
@@ -244,7 +244,7 @@ describe('nvim_get_keymap', function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' <buffer> foo bar') command(map .. ' <buffer> foo bar')
local result = meths.nvim_buf_get_keymap(0, mode)[1][option] local result = api.nvim_buf_get_keymap(0, mode)[1][option]
eq(buffer_off_result, result) eq(buffer_off_result, result)
end end
) )
@@ -275,9 +275,9 @@ describe('nvim_get_keymap', function()
nnoremap fizz :call <SID>maparg_test_function()<CR> nnoremap fizz :call <SID>maparg_test_function()<CR>
]]) ]])
local sid_result = meths.nvim_get_keymap('n')[1]['sid'] local sid_result = api.nvim_get_keymap('n')[1]['sid']
eq(1, sid_result) eq(1, sid_result)
eq('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
end) end)
it('returns script numbers for buffer maps', function() it('returns script numbers for buffer maps', function()
@@ -288,15 +288,15 @@ describe('nvim_get_keymap', function()
nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR> nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR>
]]) ]])
local sid_result = meths.nvim_buf_get_keymap(0, 'n')[1]['sid'] local sid_result = api.nvim_buf_get_keymap(0, 'n')[1]['sid']
eq(1, sid_result) eq(1, sid_result)
eq('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
end) end)
it('works with <F12> and others', function() it('works with <F12> and others', function()
command('nnoremap <F12> :let g:maparg_test_var = 1<CR>') command('nnoremap <F12> :let g:maparg_test_var = 1<CR>')
eq('<F12>', meths.nvim_get_keymap('n')[1]['lhs']) eq('<F12>', api.nvim_get_keymap('n')[1]['lhs'])
eq(':let g:maparg_test_var = 1<CR>', meths.nvim_get_keymap('n')[1]['rhs']) eq(':let g:maparg_test_var = 1<CR>', api.nvim_get_keymap('n')[1]['rhs'])
end) end)
it('works correctly despite various &cpo settings', function() it('works correctly despite various &cpo settings', function()
@@ -339,7 +339,7 @@ describe('nvim_get_keymap', function()
-- wrapper around get_keymap() that drops "lhsraw" and "lhsrawalt" which are hard to check -- wrapper around get_keymap() that drops "lhsraw" and "lhsrawalt" which are hard to check
local function get_keymap_noraw(...) local function get_keymap_noraw(...)
local ret = meths.nvim_get_keymap(...) local ret = api.nvim_get_keymap(...)
for _, item in ipairs(ret) do for _, item in ipairs(ret) do
item.lhsraw = nil item.lhsraw = nil
item.lhsrawalt = nil item.lhsrawalt = nil
@@ -390,7 +390,7 @@ describe('nvim_get_keymap', function()
lnum = 0, lnum = 0,
} }
command('nnoremap \\|<Char-0x20><Char-32><Space><Bar> \\|<Char-0x20><Char-32><Space> <Bar>') command('nnoremap \\|<Char-0x20><Char-32><Space><Bar> \\|<Char-0x20><Char-32><Space> <Bar>')
eq({ space_table }, meths.nvim_get_keymap('n')) eq({ space_table }, api.nvim_get_keymap('n'))
end) end)
it('can handle lua mappings', function() it('can handle lua mappings', function()
@@ -419,7 +419,7 @@ describe('nvim_get_keymap', function()
]]) ]])
eq(3, exec_lua([[return GlobalCount]])) eq(3, exec_lua([[return GlobalCount]]))
local mapargs = meths.nvim_get_keymap('n') local mapargs = api.nvim_get_keymap('n')
mapargs[1].callback = nil mapargs[1].callback = nil
eq({ eq({
lhs = 'asdf', lhs = 'asdf',
@@ -440,7 +440,7 @@ describe('nvim_get_keymap', function()
end) end)
it('can handle map descriptions', function() it('can handle map descriptions', function()
meths.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' })
eq({ eq({
lhs = 'lhs', lhs = 'lhs',
lhsraw = 'lhs', lhsraw = 'lhs',
@@ -458,7 +458,7 @@ describe('nvim_get_keymap', function()
noremap = 0, noremap = 0,
lnum = 0, lnum = 0,
desc = 'map description', desc = 'map description',
}, meths.nvim_get_keymap('n')[1]) }, api.nvim_get_keymap('n')[1])
end) end)
end) end)
@@ -511,7 +511,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Gets a maparg() dict from Nvim, if one exists. -- Gets a maparg() dict from Nvim, if one exists.
local function get_mapargs(mode, lhs) local function get_mapargs(mode, lhs)
local mapargs = funcs.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true) local mapargs = fn.maparg(lhs, normalize_mapmode(mode), mode:sub(-1) == 'a', true)
-- drop "lhsraw" and "lhsrawalt" which are hard to check -- drop "lhsraw" and "lhsrawalt" which are hard to check
mapargs.lhsraw = nil mapargs.lhsraw = nil
mapargs.lhsrawalt = nil mapargs.lhsrawalt = nil
@@ -520,9 +520,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('error on empty LHS', function() it('error on empty LHS', function()
-- escape parentheses in lua string, else comparison fails erroneously -- escape parentheses in lua string, else comparison fails erroneously
eq('Invalid (empty) LHS', pcall_err(meths.nvim_set_keymap, '', '', 'rhs', {})) eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', 'rhs', {}))
eq('Invalid (empty) LHS', pcall_err(meths.nvim_set_keymap, '', '', '', {})) eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', '', {}))
eq('Invalid (empty) LHS', pcall_err(meths.nvim_del_keymap, '', '')) eq('Invalid (empty) LHS', pcall_err(api.nvim_del_keymap, '', ''))
end) end)
it('error if LHS longer than MAXMAPLEN', function() it('error if LHS longer than MAXMAPLEN', function()
@@ -534,19 +534,19 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end end
-- exactly 50 chars should be fine -- exactly 50 chars should be fine
meths.nvim_set_keymap('', lhs, 'rhs', {}) api.nvim_set_keymap('', lhs, 'rhs', {})
-- del_keymap should unmap successfully -- del_keymap should unmap successfully
meths.nvim_del_keymap('', lhs) api.nvim_del_keymap('', lhs)
eq({}, get_mapargs('', lhs)) eq({}, get_mapargs('', lhs))
-- 51 chars should produce an error -- 51 chars should produce an error
lhs = lhs .. '1' lhs = lhs .. '1'
eq( eq(
'LHS exceeds maximum map length: ' .. lhs, 'LHS exceeds maximum map length: ' .. lhs,
pcall_err(meths.nvim_set_keymap, '', lhs, 'rhs', {}) pcall_err(api.nvim_set_keymap, '', lhs, 'rhs', {})
) )
eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(meths.nvim_del_keymap, '', lhs)) eq('LHS exceeds maximum map length: ' .. lhs, pcall_err(api.nvim_del_keymap, '', lhs))
end) end)
it('does not throw errors when rhs is longer than MAXMAPLEN', function() it('does not throw errors when rhs is longer than MAXMAPLEN', function()
@@ -556,65 +556,65 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
rhs = rhs .. (i % 10) rhs = rhs .. (i % 10)
end end
rhs = rhs .. '1' rhs = rhs .. '1'
meths.nvim_set_keymap('', 'lhs', rhs, {}) api.nvim_set_keymap('', 'lhs', rhs, {})
eq(generate_mapargs('', 'lhs', rhs), get_mapargs('', 'lhs')) eq(generate_mapargs('', 'lhs', rhs), get_mapargs('', 'lhs'))
end) end)
it('error on invalid mode shortname', function() it('error on invalid mode shortname', function()
eq('Invalid mode shortname: " "', pcall_err(meths.nvim_set_keymap, ' ', 'lhs', 'rhs', {})) eq('Invalid mode shortname: " "', pcall_err(api.nvim_set_keymap, ' ', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "m"', pcall_err(meths.nvim_set_keymap, 'm', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "m"', pcall_err(api.nvim_set_keymap, 'm', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "?"', pcall_err(meths.nvim_set_keymap, '?', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "?"', pcall_err(api.nvim_set_keymap, '?', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "y"', pcall_err(meths.nvim_set_keymap, 'y', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "y"', pcall_err(api.nvim_set_keymap, 'y', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "p"', pcall_err(meths.nvim_set_keymap, 'p', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "p"', pcall_err(api.nvim_set_keymap, 'p', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "a"', pcall_err(meths.nvim_set_keymap, 'a', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "a"', pcall_err(api.nvim_set_keymap, 'a', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "oa"', pcall_err(meths.nvim_set_keymap, 'oa', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_set_keymap, 'oa', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!o"', pcall_err(meths.nvim_set_keymap, '!o', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_set_keymap, '!o', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!i"', pcall_err(meths.nvim_set_keymap, '!i', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_set_keymap, '!i', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!!"', pcall_err(meths.nvim_set_keymap, '!!', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_set_keymap, '!!', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "map"', pcall_err(meths.nvim_set_keymap, 'map', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "map"', pcall_err(api.nvim_set_keymap, 'map', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "vmap"', pcall_err(meths.nvim_set_keymap, 'vmap', 'lhs', 'rhs', {})) eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_set_keymap, 'vmap', 'lhs', 'rhs', {}))
eq( eq(
'Invalid mode shortname: "xnoremap"', 'Invalid mode shortname: "xnoremap"',
pcall_err(meths.nvim_set_keymap, 'xnoremap', 'lhs', 'rhs', {}) pcall_err(api.nvim_set_keymap, 'xnoremap', 'lhs', 'rhs', {})
) )
eq('Invalid mode shortname: " "', pcall_err(meths.nvim_del_keymap, ' ', 'lhs')) eq('Invalid mode shortname: " "', pcall_err(api.nvim_del_keymap, ' ', 'lhs'))
eq('Invalid mode shortname: "m"', pcall_err(meths.nvim_del_keymap, 'm', 'lhs')) eq('Invalid mode shortname: "m"', pcall_err(api.nvim_del_keymap, 'm', 'lhs'))
eq('Invalid mode shortname: "?"', pcall_err(meths.nvim_del_keymap, '?', 'lhs')) eq('Invalid mode shortname: "?"', pcall_err(api.nvim_del_keymap, '?', 'lhs'))
eq('Invalid mode shortname: "y"', pcall_err(meths.nvim_del_keymap, 'y', 'lhs')) eq('Invalid mode shortname: "y"', pcall_err(api.nvim_del_keymap, 'y', 'lhs'))
eq('Invalid mode shortname: "p"', pcall_err(meths.nvim_del_keymap, 'p', 'lhs')) eq('Invalid mode shortname: "p"', pcall_err(api.nvim_del_keymap, 'p', 'lhs'))
eq('Invalid mode shortname: "a"', pcall_err(meths.nvim_del_keymap, 'a', 'lhs')) eq('Invalid mode shortname: "a"', pcall_err(api.nvim_del_keymap, 'a', 'lhs'))
eq('Invalid mode shortname: "oa"', pcall_err(meths.nvim_del_keymap, 'oa', 'lhs')) eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_del_keymap, 'oa', 'lhs'))
eq('Invalid mode shortname: "!o"', pcall_err(meths.nvim_del_keymap, '!o', 'lhs')) eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_del_keymap, '!o', 'lhs'))
eq('Invalid mode shortname: "!i"', pcall_err(meths.nvim_del_keymap, '!i', 'lhs')) eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_del_keymap, '!i', 'lhs'))
eq('Invalid mode shortname: "!!"', pcall_err(meths.nvim_del_keymap, '!!', 'lhs')) eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_del_keymap, '!!', 'lhs'))
eq('Invalid mode shortname: "map"', pcall_err(meths.nvim_del_keymap, 'map', 'lhs')) eq('Invalid mode shortname: "map"', pcall_err(api.nvim_del_keymap, 'map', 'lhs'))
eq('Invalid mode shortname: "vmap"', pcall_err(meths.nvim_del_keymap, 'vmap', 'lhs')) eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_del_keymap, 'vmap', 'lhs'))
eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.nvim_del_keymap, 'xnoremap', 'lhs')) eq('Invalid mode shortname: "xnoremap"', pcall_err(api.nvim_del_keymap, 'xnoremap', 'lhs'))
end) end)
it('error on invalid optnames', function() it('error on invalid optnames', function()
eq( eq(
"Invalid key: 'silentt'", "Invalid key: 'silentt'",
pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', { silentt = true }) pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { silentt = true })
) )
eq("Invalid key: 'sidd'", pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', { sidd = false })) eq("Invalid key: 'sidd'", pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { sidd = false }))
eq( eq(
"Invalid key: 'nowaiT'", "Invalid key: 'nowaiT'",
pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', { nowaiT = false }) pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { nowaiT = false })
) )
end) end)
it('error on <buffer> option key', function() it('error on <buffer> option key', function()
eq( eq(
"Invalid key: 'buffer'", "Invalid key: 'buffer'",
pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', { buffer = true }) pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { buffer = true })
) )
end) end)
it('error when "replace_keycodes" is used without "expr"', function() it('error when "replace_keycodes" is used without "expr"', function()
eq( eq(
'"replace_keycodes" requires "expr"', '"replace_keycodes" requires "expr"',
pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', { replace_keycodes = true }) pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', { replace_keycodes = true })
) )
end) end)
@@ -624,45 +624,45 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('throws an error when given non-boolean value for ' .. opt, function() it('throws an error when given non-boolean value for ' .. opt, function()
local opts = {} local opts = {}
opts[opt] = 'fooo' opts[opt] = 'fooo'
eq(opt .. ' is not a boolean', pcall_err(meths.nvim_set_keymap, 'n', 'lhs', 'rhs', opts)) eq(opt .. ' is not a boolean', pcall_err(api.nvim_set_keymap, 'n', 'lhs', 'rhs', opts))
end) end)
end end
-- Perform tests of basic functionality -- Perform tests of basic functionality
it('sets ordinary mappings', function() it('sets ordinary mappings', function()
meths.nvim_set_keymap('n', 'lhs', 'rhs', {}) api.nvim_set_keymap('n', 'lhs', 'rhs', {})
eq(generate_mapargs('n', 'lhs', 'rhs'), get_mapargs('n', 'lhs')) eq(generate_mapargs('n', 'lhs', 'rhs'), get_mapargs('n', 'lhs'))
meths.nvim_set_keymap('v', 'lhs', 'rhs', {}) api.nvim_set_keymap('v', 'lhs', 'rhs', {})
eq(generate_mapargs('v', 'lhs', 'rhs'), get_mapargs('v', 'lhs')) eq(generate_mapargs('v', 'lhs', 'rhs'), get_mapargs('v', 'lhs'))
end) end)
it('does not throw when LHS or RHS have leading/trailing whitespace', function() it('does not throw when LHS or RHS have leading/trailing whitespace', function()
meths.nvim_set_keymap('n', ' lhs', 'rhs', {}) api.nvim_set_keymap('n', ' lhs', 'rhs', {})
eq(generate_mapargs('n', '<Space><Space><Space>lhs', 'rhs'), get_mapargs('n', ' lhs')) eq(generate_mapargs('n', '<Space><Space><Space>lhs', 'rhs'), get_mapargs('n', ' lhs'))
meths.nvim_set_keymap('n', 'lhs ', 'rhs', {}) api.nvim_set_keymap('n', 'lhs ', 'rhs', {})
eq(generate_mapargs('n', 'lhs<Space><Space><Space><Space>', 'rhs'), get_mapargs('n', 'lhs ')) eq(generate_mapargs('n', 'lhs<Space><Space><Space><Space>', 'rhs'), get_mapargs('n', 'lhs '))
meths.nvim_set_keymap('v', ' lhs ', '\trhs\t\f', {}) api.nvim_set_keymap('v', ' lhs ', '\trhs\t\f', {})
eq(generate_mapargs('v', '<Space>lhs<Space><Space>', '\trhs\t\f'), get_mapargs('v', ' lhs ')) eq(generate_mapargs('v', '<Space>lhs<Space><Space>', '\trhs\t\f'), get_mapargs('v', ' lhs '))
end) end)
it('can set noremap mappings', function() it('can set noremap mappings', function()
meths.nvim_set_keymap('x', 'lhs', 'rhs', { noremap = true }) api.nvim_set_keymap('x', 'lhs', 'rhs', { noremap = true })
eq(generate_mapargs('x', 'lhs', 'rhs', { noremap = true }), get_mapargs('x', 'lhs')) eq(generate_mapargs('x', 'lhs', 'rhs', { noremap = true }), get_mapargs('x', 'lhs'))
meths.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true }) api.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true })
eq(generate_mapargs('t', 'lhs', 'rhs', { noremap = true }), get_mapargs('t', 'lhs')) eq(generate_mapargs('t', 'lhs', 'rhs', { noremap = true }), get_mapargs('t', 'lhs'))
end) end)
it('can unmap mappings', function() it('can unmap mappings', function()
meths.nvim_set_keymap('v', 'lhs', 'rhs', {}) api.nvim_set_keymap('v', 'lhs', 'rhs', {})
meths.nvim_del_keymap('v', 'lhs') api.nvim_del_keymap('v', 'lhs')
eq({}, get_mapargs('v', 'lhs')) eq({}, get_mapargs('v', 'lhs'))
meths.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true }) api.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true })
meths.nvim_del_keymap('t', 'lhs') api.nvim_del_keymap('t', 'lhs')
eq({}, get_mapargs('t', 'lhs')) eq({}, get_mapargs('t', 'lhs'))
end) end)
@@ -670,8 +670,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('"!" and empty string are synonyms for mapmode-nvo', function() it('"!" and empty string are synonyms for mapmode-nvo', function()
local nvo_shortnames = { '', '!' } local nvo_shortnames = { '', '!' }
for _, name in ipairs(nvo_shortnames) do for _, name in ipairs(nvo_shortnames) do
meths.nvim_set_keymap(name, 'lhs', 'rhs', {}) api.nvim_set_keymap(name, 'lhs', 'rhs', {})
meths.nvim_del_keymap(name, 'lhs') api.nvim_del_keymap(name, 'lhs')
eq({}, get_mapargs(name, 'lhs')) eq({}, get_mapargs(name, 'lhs'))
end end
end) end)
@@ -681,48 +681,48 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
for _, rhs in ipairs(special_chars) do for _, rhs in ipairs(special_chars) do
local mapmode = '!' local mapmode = '!'
it('can set mappings with special characters, lhs: ' .. lhs .. ', rhs: ' .. rhs, function() it('can set mappings with special characters, lhs: ' .. lhs .. ', rhs: ' .. rhs, function()
meths.nvim_set_keymap(mapmode, lhs, rhs, {}) api.nvim_set_keymap(mapmode, lhs, rhs, {})
eq(generate_mapargs(mapmode, lhs, rhs), get_mapargs(mapmode, lhs)) eq(generate_mapargs(mapmode, lhs, rhs), get_mapargs(mapmode, lhs))
end) end)
end end
end end
it('can set mappings containing literal keycodes', function() it('can set mappings containing literal keycodes', function()
meths.nvim_set_keymap('n', '\n\r\n', 'rhs', {}) api.nvim_set_keymap('n', '\n\r\n', 'rhs', {})
local expected = generate_mapargs('n', '<NL><CR><NL>', 'rhs') local expected = generate_mapargs('n', '<NL><CR><NL>', 'rhs')
eq(expected, get_mapargs('n', '<NL><CR><NL>')) eq(expected, get_mapargs('n', '<NL><CR><NL>'))
end) end)
it('can set mappings whose RHS is a <Nop>', function() it('can set mappings whose RHS is a <Nop>', function()
meths.nvim_set_keymap('i', 'lhs', '<Nop>', {}) api.nvim_set_keymap('i', 'lhs', '<Nop>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) -- imap to <Nop> does nothing eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0)) -- imap to <Nop> does nothing
eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs'))
-- also test for case insensitivity -- also test for case insensitivity
meths.nvim_set_keymap('i', 'lhs', '<nOp>', {}) api.nvim_set_keymap('i', 'lhs', '<nOp>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0))
-- note: RHS in returned mapargs() dict reflects the original RHS -- note: RHS in returned mapargs() dict reflects the original RHS
-- provided by the user -- provided by the user
eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs'))
meths.nvim_set_keymap('i', 'lhs', '<NOP>', {}) api.nvim_set_keymap('i', 'lhs', '<NOP>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs'))
-- a single ^V in RHS is also <Nop> (see :h map-empty-rhs) -- a single ^V in RHS is also <Nop> (see :h map-empty-rhs)
meths.nvim_set_keymap('i', 'lhs', '\022', {}) api.nvim_set_keymap('i', 'lhs', '\022', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs'))
end) end)
it('treats an empty RHS in a mapping like a <Nop>', function() it('treats an empty RHS in a mapping like a <Nop>', function()
meths.nvim_set_keymap('i', 'lhs', '', {}) api.nvim_set_keymap('i', 'lhs', '', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs'))
end) end)
@@ -730,8 +730,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Taken from the legacy test: test_mapping.vim. Exposes a bug in which -- Taken from the legacy test: test_mapping.vim. Exposes a bug in which
-- replace_termcodes changes the length of the mapping's LHS, but -- replace_termcodes changes the length of the mapping's LHS, but
-- do_map continues to use the *old* length of LHS. -- do_map continues to use the *old* length of LHS.
meths.nvim_set_keymap('i', '<M-">', 'foo', {}) api.nvim_set_keymap('i', '<M-">', 'foo', {})
meths.nvim_del_keymap('i', '<M-">') api.nvim_del_keymap('i', '<M-">')
eq({}, get_mapargs('i', '<M-">')) eq({}, get_mapargs('i', '<M-">'))
end) end)
@@ -741,18 +741,18 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]]) command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]])
eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>')) eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>'))
feed('i ') feed('i ')
eq({ '\t' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '\t' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end end
) )
it('throws appropriate error messages when setting <unique> maps', function() it('throws appropriate error messages when setting <unique> maps', function()
meths.nvim_set_keymap('l', 'lhs', 'rhs', {}) api.nvim_set_keymap('l', 'lhs', 'rhs', {})
eq( eq(
'E227: mapping already exists for lhs', 'E227: mapping already exists for lhs',
pcall_err(meths.nvim_set_keymap, 'l', 'lhs', 'rhs', { unique = true }) pcall_err(api.nvim_set_keymap, 'l', 'lhs', 'rhs', { unique = true })
) )
-- different mapmode, no error should be thrown -- different mapmode, no error should be thrown
meths.nvim_set_keymap('t', 'lhs', 'rhs', { unique = true }) api.nvim_set_keymap('t', 'lhs', 'rhs', { unique = true })
end) end)
it('can set <expr> mappings whose RHS change dynamically', function() it('can set <expr> mappings whose RHS change dynamically', function()
@@ -763,50 +763,50 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
return g:flip return g:flip
endfunction endfunction
]]) ]])
eq(1, meths.nvim_call_function('FlipFlop', {})) eq(1, api.nvim_call_function('FlipFlop', {}))
eq(0, meths.nvim_call_function('FlipFlop', {})) eq(0, api.nvim_call_function('FlipFlop', {}))
eq(1, meths.nvim_call_function('FlipFlop', {})) eq(1, api.nvim_call_function('FlipFlop', {}))
eq(0, meths.nvim_call_function('FlipFlop', {})) eq(0, api.nvim_call_function('FlipFlop', {}))
meths.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) api.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true })
command('normal ilhs') command('normal ilhs')
eq({ '1' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '1' }, api.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') command('normal ilhs')
eq({ '0' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ '0' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it('can set mappings that do trigger other mappings', function() it('can set mappings that do trigger other mappings', function()
meths.nvim_set_keymap('i', 'mhs', 'rhs', {}) api.nvim_set_keymap('i', 'mhs', 'rhs', {})
meths.nvim_set_keymap('i', 'lhs', 'mhs', {}) api.nvim_set_keymap('i', 'lhs', 'mhs', {})
command('normal imhs') command('normal imhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') command('normal ilhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it("can set noremap mappings that don't trigger other mappings", function() it("can set noremap mappings that don't trigger other mappings", function()
meths.nvim_set_keymap('i', 'mhs', 'rhs', {}) api.nvim_set_keymap('i', 'mhs', 'rhs', {})
meths.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true }) api.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true })
command('normal imhs') command('normal imhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping
eq({ 'mhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ 'mhs' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it('can set nowait mappings that fire without waiting', function() it('can set nowait mappings that fire without waiting', function()
meths.nvim_set_keymap('i', '123456', 'longer', {}) api.nvim_set_keymap('i', '123456', 'longer', {})
meths.nvim_set_keymap('i', '123', 'shorter', { nowait = true }) api.nvim_set_keymap('i', '123', 'shorter', { nowait = true })
-- feed keys one at a time; if all keys arrive atomically, the longer -- feed keys one at a time; if all keys arrive atomically, the longer
-- mapping will trigger -- mapping will trigger
@@ -815,29 +815,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed(c) feed(c)
sleep(5) sleep(5)
end end
eq({ 'shorter456' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) eq({ 'shorter456' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
-- Perform exhaustive tests of basic functionality -- Perform exhaustive tests of basic functionality
local mapmodes = { 'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a' } local mapmodes = { 'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a' }
for _, mapmode in ipairs(mapmodes) do for _, mapmode in ipairs(mapmodes) do
it('can set/unset normal mappings in mapmode ' .. mapmode, function() it('can set/unset normal mappings in mapmode ' .. mapmode, function()
meths.nvim_set_keymap(mapmode, 'lhs', 'rhs', {}) api.nvim_set_keymap(mapmode, 'lhs', 'rhs', {})
eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs')) eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs'))
-- some mapmodes (like 'o') will prevent other mapmodes (like '!') from -- some mapmodes (like 'o') will prevent other mapmodes (like '!') from
-- taking effect, so unmap after each mapping -- taking effect, so unmap after each mapping
meths.nvim_del_keymap(mapmode, 'lhs') api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs')) eq({}, get_mapargs(mapmode, 'lhs'))
end) end)
end end
for _, mapmode in ipairs(mapmodes) do for _, mapmode in ipairs(mapmodes) do
it('can set/unset noremap mappings using mapmode ' .. mapmode, function() it('can set/unset noremap mappings using mapmode ' .. mapmode, function()
meths.nvim_set_keymap(mapmode, 'lhs', 'rhs', { noremap = true }) api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { noremap = true })
eq(generate_mapargs(mapmode, 'lhs', 'rhs', { noremap = true }), get_mapargs(mapmode, 'lhs')) eq(generate_mapargs(mapmode, 'lhs', 'rhs', { noremap = true }), get_mapargs(mapmode, 'lhs'))
meths.nvim_del_keymap(mapmode, 'lhs') api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs')) eq({}, get_mapargs(mapmode, 'lhs'))
end) end)
end end
@@ -849,12 +849,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Test with single mappings -- Test with single mappings
for _, maparg in ipairs(optnames) do for _, maparg in ipairs(optnames) do
it('can set/unset ' .. mapmode .. '-mappings with maparg: ' .. maparg, function() it('can set/unset ' .. mapmode .. '-mappings with maparg: ' .. maparg, function()
meths.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = true }) api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = true })
eq( eq(
generate_mapargs(mapmode, 'lhs', 'rhs', { [maparg] = true }), generate_mapargs(mapmode, 'lhs', 'rhs', { [maparg] = true }),
get_mapargs(mapmode, 'lhs') get_mapargs(mapmode, 'lhs')
) )
meths.nvim_del_keymap(mapmode, 'lhs') api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs')) eq({}, get_mapargs(mapmode, 'lhs'))
end) end)
it( it(
@@ -864,9 +864,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
.. maparg .. maparg
.. ', whose value is false', .. ', whose value is false',
function() function()
meths.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = false }) api.nvim_set_keymap(mapmode, 'lhs', 'rhs', { [maparg] = false })
eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs')) eq(generate_mapargs(mapmode, 'lhs', 'rhs'), get_mapargs(mapmode, 'lhs'))
meths.nvim_del_keymap(mapmode, 'lhs') api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs')) eq({}, get_mapargs(mapmode, 'lhs'))
end end
) )
@@ -886,9 +886,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
.. opt3, .. opt3,
function() function()
local opts = { [opt1] = true, [opt2] = false, [opt3] = true } local opts = { [opt1] = true, [opt2] = false, [opt3] = true }
meths.nvim_set_keymap(mapmode, 'lhs', 'rhs', opts) api.nvim_set_keymap(mapmode, 'lhs', 'rhs', opts)
eq(generate_mapargs(mapmode, 'lhs', 'rhs', opts), get_mapargs(mapmode, 'lhs')) eq(generate_mapargs(mapmode, 'lhs', 'rhs', opts), get_mapargs(mapmode, 'lhs'))
meths.nvim_del_keymap(mapmode, 'lhs') api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs')) eq({}, get_mapargs(mapmode, 'lhs'))
end end
) )
@@ -926,7 +926,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
exec_lua [[ exec_lua [[
vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end }) vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end })
]] ]]
assert.truthy(string.match(funcs.mapcheck('asdf', 'n'), '^<Lua %d+>')) assert.truthy(string.match(fn.mapcheck('asdf', 'n'), '^<Lua %d+>'))
end) end)
it('maparg() returns lua mapping correctly', function() it('maparg() returns lua mapping correctly', function()
@@ -939,9 +939,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
]]) ]])
) )
assert.truthy(string.match(funcs.maparg('asdf', 'n'), '^<Lua %d+>')) assert.truthy(string.match(fn.maparg('asdf', 'n'), '^<Lua %d+>'))
local mapargs = funcs.maparg('asdf', 'n', false, true) local mapargs = fn.maparg('asdf', 'n', false, true)
mapargs.callback = nil mapargs.callback = nil
mapargs.lhsraw = nil mapargs.lhsraw = nil
mapargs.lhsrawalt = nil mapargs.lhsrawalt = nil
@@ -968,7 +968,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed('aa') feed('aa')
eq({ 'π<M-π>foo<' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can make lua expr mappings without replacing keycodes', function() it('can make lua expr mappings without replacing keycodes', function()
@@ -978,7 +978,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed('iaa<esc>') feed('iaa<esc>')
eq({ '<space>' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('lua expr mapping returning nil is equivalent to returning an empty string', function() it('lua expr mapping returning nil is equivalent to returning an empty string', function()
@@ -988,7 +988,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed('iaa<esc>') feed('iaa<esc>')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('does not reset pum in lua mapping', function() it('does not reset pum in lua mapping', function()
@@ -1091,7 +1091,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end) end)
it('can set descriptions on mappings', function() it('can set descriptions on mappings', function()
meths.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' }) api.nvim_set_keymap('n', 'lhs', 'rhs', { desc = 'map description' })
eq(generate_mapargs('n', 'lhs', 'rhs', { desc = 'map description' }), get_mapargs('n', 'lhs')) eq(generate_mapargs('n', 'lhs', 'rhs', { desc = 'map description' }), get_mapargs('n', 'lhs'))
eq('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs')) eq('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs'))
end) end)
@@ -1106,10 +1106,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
]] ]]
feed 'iThe foo and the bar and the foo again<esc>' feed 'iThe foo and the bar and the foo again<esc>'
eq('The 1 and the bar and the 2 again', meths.nvim_get_current_line()) eq('The 1 and the bar and the 2 again', api.nvim_get_current_line())
feed ':let x = "The foo is the one"<cr>' feed ':let x = "The foo is the one"<cr>'
eq('The 3 is the one', meths.nvim_eval 'x') eq('The 3 is the one', api.nvim_eval 'x')
end) end)
it('can define insert mode abbreviations with lua callbacks', function() it('can define insert mode abbreviations with lua callbacks', function()
@@ -1122,10 +1122,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
]] ]]
feed 'iThe foo and the bar and the foo again<esc>' feed 'iThe foo and the bar and the foo again<esc>'
eq('The 1 and the bar and the 2 again', meths.nvim_get_current_line()) eq('The 1 and the bar and the 2 again', api.nvim_get_current_line())
feed ':let x = "The foo is the one"<cr>' feed ':let x = "The foo is the one"<cr>'
eq('The foo is the one', meths.nvim_eval 'x') eq('The foo is the one', api.nvim_eval 'x')
end) end)
it('can define cmdline mode abbreviations with lua callbacks', function() it('can define cmdline mode abbreviations with lua callbacks', function()
@@ -1138,10 +1138,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
]] ]]
feed 'iThe foo and the bar and the foo again<esc>' feed 'iThe foo and the bar and the foo again<esc>'
eq('The foo and the bar and the foo again', meths.nvim_get_current_line()) eq('The foo and the bar and the foo again', api.nvim_get_current_line())
feed ':let x = "The foo is the one"<cr>' feed ':let x = "The foo is the one"<cr>'
eq('The 1 is the one', meths.nvim_eval 'x') eq('The 1 is the one', api.nvim_eval 'x')
end) end)
end) end)
@@ -1164,9 +1164,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
local function make_two_buffers(start_from_first) local function make_two_buffers(start_from_first)
command('set hidden') command('set hidden')
local first_buf = meths.nvim_call_function('bufnr', { '%' }) local first_buf = api.nvim_call_function('bufnr', { '%' })
command('new') command('new')
local second_buf = meths.nvim_call_function('bufnr', { '%' }) local second_buf = api.nvim_call_function('bufnr', { '%' })
neq(second_buf, first_buf) -- sanity check neq(second_buf, first_buf) -- sanity check
if start_from_first then if start_from_first then
@@ -1179,66 +1179,66 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('rejects negative bufnr values', function() it('rejects negative bufnr values', function()
eq( eq(
'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', 'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer',
pcall_err(meths.nvim_buf_set_keymap, -1, '', 'lhs', 'rhs', {}) pcall_err(api.nvim_buf_set_keymap, -1, '', 'lhs', 'rhs', {})
) )
end) end)
it('can set mappings active in the current buffer but not others', function() it('can set mappings active in the current buffer but not others', function()
local first, second = make_two_buffers(true) local first, second = make_two_buffers(true)
meths.nvim_buf_set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) api.nvim_buf_set_keymap(0, '', 'lhs', 'irhs<Esc>', {})
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1))
-- mapping should have no effect in new buffer -- mapping should have no effect in new buffer
switch_to_buf(second) switch_to_buf(second)
command('normal lhs') command('normal lhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1))
-- mapping should remain active in old buffer -- mapping should remain active in old buffer
switch_to_buf(first) switch_to_buf(first)
command('normal ^lhs') command('normal ^lhs')
eq({ 'rhsrhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ 'rhsrhs' }, api.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('can set local mappings in buffer other than current', function() it('can set local mappings in buffer other than current', function()
local first = make_two_buffers(false) local first = make_two_buffers(false)
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
-- shouldn't do anything -- shouldn't do anything
command('normal lhs') command('normal lhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1))
-- should take effect -- should take effect
switch_to_buf(first) switch_to_buf(first)
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('can disable mappings made in another buffer, inside that buffer', function() it('can disable mappings made in another buffer, inside that buffer', function()
local first = make_two_buffers(false) local first = make_two_buffers(false)
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
meths.nvim_buf_del_keymap(first, '', 'lhs') api.nvim_buf_del_keymap(first, '', 'lhs')
switch_to_buf(first) switch_to_buf(first)
-- shouldn't do anything -- shouldn't do anything
command('normal lhs') command('normal lhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it("can't disable mappings given wrong buffer handle", function() it("can't disable mappings given wrong buffer handle", function()
local first, second = make_two_buffers(false) local first, second = make_two_buffers(false)
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
eq('E31: No such mapping', pcall_err(meths.nvim_buf_del_keymap, second, '', 'lhs')) eq('E31: No such mapping', pcall_err(api.nvim_buf_del_keymap, second, '', 'lhs'))
-- should still work -- should still work
switch_to_buf(first) switch_to_buf(first)
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1)) eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('does not crash when setting mapping in a non-existing buffer #13541', function() it('does not crash when setting mapping in a non-existing buffer #13541', function()
pcall_err(meths.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) pcall_err(api.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
helpers.assert_alive() helpers.assert_alive()
end) end)
@@ -1264,7 +1264,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
feed('aa') feed('aa')
eq({ 'π<M-π>foo<' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can make lua expr mappings without replacing keycodes', function() it('can make lua expr mappings without replacing keycodes', function()
@@ -1274,7 +1274,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
feed('iaa<esc>') feed('iaa<esc>')
eq({ '<space>' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can overwrite lua mappings', function() it('can overwrite lua mappings', function()

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local neq = helpers.neq local neq = helpers.neq
local nvim_argv = helpers.nvim_argv local nvim_argv = helpers.nvim_argv
local request = helpers.request local request = helpers.request
@@ -15,28 +15,28 @@ describe('API', function()
describe('nvim_get_proc_children', function() describe('nvim_get_proc_children', function()
it('returns child process ids', function() it('returns child process ids', function()
local this_pid = funcs.getpid() local this_pid = fn.getpid()
-- Might be non-zero already (left-over from some other test?), -- Might be non-zero already (left-over from some other test?),
-- but this is not what is tested here. -- but this is not what is tested here.
local initial_children = request('nvim_get_proc_children', this_pid) local initial_children = request('nvim_get_proc_children', this_pid)
local job1 = funcs.jobstart(nvim_argv) local job1 = fn.jobstart(nvim_argv)
retry(nil, nil, function() retry(nil, nil, function()
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
end) end)
local job2 = funcs.jobstart(nvim_argv) local job2 = fn.jobstart(nvim_argv)
retry(nil, nil, function() retry(nil, nil, function()
eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid)) eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid))
end) end)
funcs.jobstop(job1) fn.jobstop(job1)
retry(nil, nil, function() retry(nil, nil, function()
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid)) eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
end) end)
funcs.jobstop(job2) fn.jobstop(job2)
retry(nil, nil, function() retry(nil, nil, function()
eq(#initial_children, #request('nvim_get_proc_children', this_pid)) eq(#initial_children, #request('nvim_get_proc_children', this_pid))
end) end)
@@ -60,7 +60,7 @@ describe('API', function()
describe('nvim_get_proc', function() describe('nvim_get_proc', function()
it('returns process info', function() it('returns process info', function()
local pid = funcs.getpid() local pid = fn.getpid()
local pinfo = request('nvim_get_proc', pid) local pinfo = request('nvim_get_proc', pid)
eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name) eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name)
eq(pid, pinfo.pid) eq(pid, pinfo.pid)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local assert_log = helpers.assert_log local assert_log = helpers.assert_log
local eq, clear, eval, command, next_msg = local eq, clear, eval, command, next_msg =
helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg
local meths = helpers.meths local api = helpers.api
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local retry = helpers.retry local retry = helpers.retry
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@@ -14,7 +14,7 @@ describe('notify', function()
before_each(function() before_each(function()
clear() clear()
channel = meths.nvim_get_api_info()[1] channel = api.nvim_get_api_info()[1]
end) end)
after_each(function() after_each(function()
@@ -33,21 +33,21 @@ describe('notify', function()
describe('passing 0 as the channel id', function() describe('passing 0 as the channel id', function()
it('sends the notification/args to all subscribed channels', function() it('sends the notification/args to all subscribed channels', function()
meths.nvim_subscribe('event2') api.nvim_subscribe('event2')
eval('rpcnotify(0, "event1", 1, 2, 3)') eval('rpcnotify(0, "event1", 1, 2, 3)')
eval('rpcnotify(0, "event2", 4, 5, 6)') eval('rpcnotify(0, "event2", 4, 5, 6)')
eval('rpcnotify(0, "event2", 7, 8, 9)') eval('rpcnotify(0, "event2", 7, 8, 9)')
eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg()) eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg())
eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg()) eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg())
meths.nvim_unsubscribe('event2') api.nvim_unsubscribe('event2')
meths.nvim_subscribe('event1') api.nvim_subscribe('event1')
eval('rpcnotify(0, "event2", 10, 11, 12)') eval('rpcnotify(0, "event2", 10, 11, 12)')
eval('rpcnotify(0, "event1", 13, 14, 15)') eval('rpcnotify(0, "event1", 13, 14, 15)')
eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg()) eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg())
end) end)
it('does not crash for deeply nested variable', function() it('does not crash for deeply nested variable', function()
meths.nvim_set_var('l', {}) api.nvim_set_var('l', {})
local nest_level = 1000 local nest_level = 1000
command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)) command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1))
eval('rpcnotify(' .. channel .. ', "event", g:l)') eval('rpcnotify(' .. channel .. ', "event", g:l)')
@@ -79,10 +79,10 @@ describe('notify', function()
clear { env = { clear { env = {
NVIM_LOG_FILE = testlog, NVIM_LOG_FILE = testlog,
} } } }
meths.nvim_subscribe('event1') api.nvim_subscribe('event1')
meths.nvim_unsubscribe('doesnotexist') api.nvim_unsubscribe('doesnotexist')
assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10) assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10)
meths.nvim_unsubscribe('event1') api.nvim_unsubscribe('event1')
assert_alive() assert_alive()
end) end)
@@ -106,7 +106,7 @@ describe('notify', function()
exec_lua([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan) exec_lua([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan)
) )
retry(nil, 3000, function() retry(nil, 3000, function()
eq({}, meths.nvim_get_chan_info(catchan)) eq({}, api.nvim_get_chan_info(catchan))
end) -- cat be dead :( end) -- cat be dead :(
end) end)
end) end)

View File

@@ -4,10 +4,10 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, eval = helpers.clear, helpers.eval local clear, eval = helpers.clear, helpers.eval
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn
local source, next_msg = helpers.source, helpers.next_msg local source, next_msg = helpers.source, helpers.next_msg
local ok = helpers.ok local ok = helpers.ok
local meths = helpers.meths local api = helpers.api
local spawn, merge_args = helpers.spawn, helpers.merge_args local spawn, merge_args = helpers.spawn, helpers.merge_args
local set_session = helpers.set_session local set_session = helpers.set_session
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@@ -18,7 +18,7 @@ describe('server -> client', function()
before_each(function() before_each(function()
clear() clear()
cid = meths.nvim_get_api_info()[1] cid = api.nvim_get_api_info()[1]
end) end)
it('handles unexpected closed stream while preparing RPC response', function() it('handles unexpected closed stream while preparing RPC response', function()
@@ -77,15 +77,15 @@ describe('server -> client', function()
describe('recursive call', function() describe('recursive call', function()
it('works', function() it('works', function()
local function on_setup() local function on_setup()
meths.nvim_set_var('result1', 0) api.nvim_set_var('result1', 0)
meths.nvim_set_var('result2', 0) api.nvim_set_var('result2', 0)
meths.nvim_set_var('result3', 0) api.nvim_set_var('result3', 0)
meths.nvim_set_var('result4', 0) api.nvim_set_var('result4', 0)
command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)')
eq(4, meths.nvim_get_var('result1')) eq(4, api.nvim_get_var('result1'))
eq(8, meths.nvim_get_var('result2')) eq(8, api.nvim_get_var('result2'))
eq(16, meths.nvim_get_var('result3')) eq(16, api.nvim_get_var('result3'))
eq(32, meths.nvim_get_var('result4')) eq(32, api.nvim_get_var('result4'))
stop() stop()
end end
@@ -113,12 +113,12 @@ describe('server -> client', function()
it('does not delay notifications during pending request', function() it('does not delay notifications during pending request', function()
local received = false local received = false
local function on_setup() local function on_setup()
eq('retval', funcs.rpcrequest(cid, 'doit')) eq('retval', fn.rpcrequest(cid, 'doit'))
stop() stop()
end end
local function on_request(method) local function on_request(method)
if method == 'doit' then if method == 'doit' then
funcs.rpcnotify(cid, 'headsup') fn.rpcnotify(cid, 'headsup')
eq(true, received) eq(true, received)
return 'retval' return 'retval'
end end
@@ -231,8 +231,8 @@ describe('server -> client', function()
describe('jobstart()', function() describe('jobstart()', function()
local jobid local jobid
before_each(function() before_each(function()
local channel = meths.nvim_get_api_info()[1] local channel = api.nvim_get_api_info()[1]
meths.nvim_set_var('channel', channel) api.nvim_set_var('channel', channel)
source([[ source([[
function! s:OnEvent(id, data, event) function! s:OnEvent(id, data, event)
call rpcnotify(g:channel, a:event, 0, a:data) call rpcnotify(g:channel, a:event, 0, a:data)
@@ -244,7 +244,7 @@ describe('server -> client', function()
\ 'rpc': v:true \ 'rpc': v:true
\ } \ }
]]) ]])
meths.nvim_set_var('args', { api.nvim_set_var('args', {
nvim_prog, nvim_prog,
'-ll', '-ll',
'test/functional/api/rpc_fixture.lua', 'test/functional/api/rpc_fixture.lua',
@@ -256,7 +256,7 @@ describe('server -> client', function()
end) end)
after_each(function() after_each(function()
pcall(funcs.jobstop, jobid) pcall(fn.jobstop, jobid)
end) end)
if helpers.skip(helpers.is_os('win')) then if helpers.skip(helpers.is_os('win')) then
@@ -264,16 +264,16 @@ describe('server -> client', function()
end end
it('rpc and text stderr can be combined', function() it('rpc and text stderr can be combined', function()
local status, rv = pcall(funcs.rpcrequest, jobid, 'poll') local status, rv = pcall(fn.rpcrequest, jobid, 'poll')
if not status then if not status then
error(string.format('missing nvim Lua module? (%s)', rv)) error(string.format('missing nvim Lua module? (%s)', rv))
end end
eq('ok', rv) eq('ok', rv)
funcs.rpcnotify(jobid, 'ping') fn.rpcnotify(jobid, 'ping')
eq({ 'notification', 'pong', {} }, next_msg()) eq({ 'notification', 'pong', {} }, next_msg())
eq('done!', funcs.rpcrequest(jobid, 'write_stderr', 'fluff\n')) eq('done!', fn.rpcrequest(jobid, 'write_stderr', 'fluff\n'))
eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg()) eq({ 'notification', 'stderr', { 0, { 'fluff', '' } } }, next_msg())
pcall(funcs.rpcrequest, jobid, 'exit') pcall(fn.rpcrequest, jobid, 'exit')
eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stderr', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg())
end) end)
@@ -282,29 +282,29 @@ describe('server -> client', function()
describe('connecting to another (peer) nvim', function() describe('connecting to another (peer) nvim', function()
local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' })
local function connect_test(server, mode, address) local function connect_test(server, mode, address)
local serverpid = funcs.getpid() local serverpid = fn.getpid()
local client = spawn(nvim_argv, false, nil, true) local client = spawn(nvim_argv, false, nil, true)
set_session(client) set_session(client)
local clientpid = funcs.getpid() local clientpid = fn.getpid()
neq(serverpid, clientpid) neq(serverpid, clientpid)
local id = funcs.sockconnect(mode, address, { rpc = true }) local id = fn.sockconnect(mode, address, { rpc = true })
ok(id > 0) ok(id > 0)
funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') fn.rpcrequest(id, 'nvim_set_current_line', 'hello')
local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1] local client_id = fn.rpcrequest(id, 'nvim_get_api_info')[1]
set_session(server) set_session(server)
eq(serverpid, funcs.getpid()) eq(serverpid, fn.getpid())
eq('hello', meths.nvim_get_current_line()) eq('hello', api.nvim_get_current_line())
-- method calls work both ways -- method calls work both ways
funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!') fn.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!')
eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1]) eq(id, fn.rpcrequest(client_id, 'nvim_get_api_info')[1])
set_session(client) set_session(client)
eq(clientpid, funcs.getpid()) eq(clientpid, fn.getpid())
eq('howdy!', meths.nvim_get_current_line()) eq('howdy!', api.nvim_get_current_line())
server:close() server:close()
client:close() client:close()
@@ -313,7 +313,7 @@ describe('server -> client', function()
it('via named pipe', function() it('via named pipe', function()
local server = spawn(nvim_argv) local server = spawn(nvim_argv)
set_session(server) set_session(server)
local address = funcs.serverlist()[1] local address = fn.serverlist()[1]
local first = string.sub(address, 1, 1) local first = string.sub(address, 1, 1)
ok(first == '/' or first == '\\') ok(first == '/' or first == '\\')
connect_test(server, 'pipe', address) connect_test(server, 'pipe', address)
@@ -322,7 +322,7 @@ describe('server -> client', function()
it('via ipv4 address', function() it('via ipv4 address', function()
local server = spawn(nvim_argv) local server = spawn(nvim_argv)
set_session(server) set_session(server)
local status, address = pcall(funcs.serverstart, '127.0.0.1:') local status, address = pcall(fn.serverstart, '127.0.0.1:')
if not status then if not status then
pending('no ipv4 stack') pending('no ipv4 stack')
end end
@@ -333,7 +333,7 @@ describe('server -> client', function()
it('via ipv6 address', function() it('via ipv6 address', function()
local server = spawn(nvim_argv) local server = spawn(nvim_argv)
set_session(server) set_session(server)
local status, address = pcall(funcs.serverstart, '::1:') local status, address = pcall(fn.serverstart, '::1:')
if not status then if not status then
pending('no ipv6 stack') pending('no ipv6 stack')
end end
@@ -344,7 +344,7 @@ describe('server -> client', function()
it('via hostname', function() it('via hostname', function()
local server = spawn(nvim_argv) local server = spawn(nvim_argv)
set_session(server) set_session(server)
local address = funcs.serverstart('localhost:') local address = fn.serverstart('localhost:')
eq('localhost:', string.sub(address, 1, 10)) eq('localhost:', string.sub(address, 1, 10))
connect_test(server, 'tcp', address) connect_test(server, 'tcp', address)
end) end)
@@ -352,12 +352,12 @@ describe('server -> client', function()
it('does not crash on receiving UI events', function() it('does not crash on receiving UI events', function()
local server = spawn(nvim_argv) local server = spawn(nvim_argv)
set_session(server) set_session(server)
local address = funcs.serverlist()[1] local address = fn.serverlist()[1]
local client = spawn(nvim_argv, false, nil, true) local client = spawn(nvim_argv, false, nil, true)
set_session(client) set_session(client)
local id = funcs.sockconnect('pipe', address, { rpc = true }) local id = fn.sockconnect('pipe', address, { rpc = true })
funcs.rpcrequest(id, 'nvim_ui_attach', 80, 24, {}) fn.rpcrequest(id, 'nvim_ui_attach', 80, 24, {})
assert_alive() assert_alive()
server:close() server:close()
@@ -367,18 +367,18 @@ describe('server -> client', function()
describe('connecting to its own pipe address', function() describe('connecting to its own pipe address', function()
it('does not deadlock', function() it('does not deadlock', function()
local address = funcs.serverlist()[1] local address = fn.serverlist()[1]
local first = string.sub(address, 1, 1) local first = string.sub(address, 1, 1)
ok(first == '/' or first == '\\') ok(first == '/' or first == '\\')
local serverpid = funcs.getpid() local serverpid = fn.getpid()
local id = funcs.sockconnect('pipe', address, { rpc = true }) local id = fn.sockconnect('pipe', address, { rpc = true })
funcs.rpcrequest(id, 'nvim_set_current_line', 'hello') fn.rpcrequest(id, 'nvim_set_current_line', 'hello')
eq('hello', meths.nvim_get_current_line()) eq('hello', api.nvim_get_current_line())
eq(serverpid, funcs.rpcrequest(id, 'nvim_eval', 'getpid()')) eq(serverpid, fn.rpcrequest(id, 'nvim_eval', 'getpid()'))
eq(id, funcs.rpcrequest(id, 'nvim_get_api_info')[1]) eq(id, fn.rpcrequest(id, 'nvim_get_api_info')[1])
end) end)
end) end)
end) end)

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok
local meths = helpers.meths local api = helpers.api
local funcs = helpers.funcs local fn = helpers.fn
local request = helpers.request local request = helpers.request
local NIL = vim.NIL local NIL = vim.NIL
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@@ -14,33 +14,33 @@ describe('api/tabpage', function()
it('works', function() it('works', function()
helpers.command('tabnew') helpers.command('tabnew')
helpers.command('vsplit') helpers.command('vsplit')
local tab1, tab2 = unpack(meths.nvim_list_tabpages()) local tab1, tab2 = unpack(api.nvim_list_tabpages())
local win1, win2, win3 = unpack(meths.nvim_list_wins()) local win1, win2, win3 = unpack(api.nvim_list_wins())
eq({ win1 }, meths.nvim_tabpage_list_wins(tab1)) eq({ win1 }, api.nvim_tabpage_list_wins(tab1))
eq({ win2, win3 }, meths.nvim_tabpage_list_wins(tab2)) eq({ win2, win3 }, api.nvim_tabpage_list_wins(tab2))
eq(win2, meths.nvim_tabpage_get_win(tab2)) eq(win2, api.nvim_tabpage_get_win(tab2))
meths.nvim_set_current_win(win3) api.nvim_set_current_win(win3)
eq(win3, meths.nvim_tabpage_get_win(tab2)) eq(win3, api.nvim_tabpage_get_win(tab2))
end) end)
it('validates args', function() it('validates args', function()
eq('Invalid tabpage id: 23', pcall_err(meths.nvim_tabpage_list_wins, 23)) eq('Invalid tabpage id: 23', pcall_err(api.nvim_tabpage_list_wins, 23))
end) end)
end) end)
describe('{get,set,del}_var', function() describe('{get,set,del}_var', function()
it('works', function() it('works', function()
meths.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } }) api.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_tabpage_get_var(0, 'lua')) eq({ 1, 2, { ['3'] = 1 } }, api.nvim_tabpage_get_var(0, 'lua'))
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('t:lua')) eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('t:lua'))
eq(1, funcs.exists('t:lua')) eq(1, fn.exists('t:lua'))
meths.nvim_tabpage_del_var(0, 'lua') api.nvim_tabpage_del_var(0, 'lua')
eq(0, funcs.exists('t:lua')) eq(0, fn.exists('t:lua'))
eq('Key not found: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua')) eq('Key not found: lua', pcall_err(api.nvim_tabpage_del_var, 0, 'lua'))
meths.nvim_tabpage_set_var(0, 'lua', 1) api.nvim_tabpage_set_var(0, 'lua', 1)
command('lockvar t:lua') command('lockvar t:lua')
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua')) eq('Key is locked: lua', pcall_err(api.nvim_tabpage_del_var, 0, 'lua'))
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_set_var, 0, 'lua', 1)) eq('Key is locked: lua', pcall_err(api.nvim_tabpage_set_var, 0, 'lua', 1))
end) end)
it('tabpage_set_var returns the old value', function() it('tabpage_set_var returns the old value', function()
@@ -61,28 +61,28 @@ describe('api/tabpage', function()
describe('get_number', function() describe('get_number', function()
it('works', function() it('works', function()
local tabs = meths.nvim_list_tabpages() local tabs = api.nvim_list_tabpages()
eq(1, meths.nvim_tabpage_get_number(tabs[1])) eq(1, api.nvim_tabpage_get_number(tabs[1]))
helpers.command('tabnew') helpers.command('tabnew')
local tab1, tab2 = unpack(meths.nvim_list_tabpages()) local tab1, tab2 = unpack(api.nvim_list_tabpages())
eq(1, meths.nvim_tabpage_get_number(tab1)) eq(1, api.nvim_tabpage_get_number(tab1))
eq(2, meths.nvim_tabpage_get_number(tab2)) eq(2, api.nvim_tabpage_get_number(tab2))
helpers.command('-tabmove') helpers.command('-tabmove')
eq(2, meths.nvim_tabpage_get_number(tab1)) eq(2, api.nvim_tabpage_get_number(tab1))
eq(1, meths.nvim_tabpage_get_number(tab2)) eq(1, api.nvim_tabpage_get_number(tab2))
end) end)
end) end)
describe('is_valid', function() describe('is_valid', function()
it('works', function() it('works', function()
helpers.command('tabnew') helpers.command('tabnew')
local tab = meths.nvim_list_tabpages()[2] local tab = api.nvim_list_tabpages()[2]
meths.nvim_set_current_tabpage(tab) api.nvim_set_current_tabpage(tab)
ok(meths.nvim_tabpage_is_valid(tab)) ok(api.nvim_tabpage_is_valid(tab))
helpers.command('tabclose') helpers.command('tabclose')
ok(not meths.nvim_tabpage_is_valid(tab)) ok(not api.nvim_tabpage_is_valid(tab))
end) end)
end) end)
end) end)

View File

@@ -6,7 +6,7 @@ local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local request = helpers.request local request = helpers.request
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@@ -23,39 +23,39 @@ describe('nvim_ui_attach()', function()
end) end)
it('validation', function() it('validation', function()
eq('No such UI option: foo', pcall_err(meths.nvim_ui_attach, 80, 24, { foo = { 'foo' } })) eq('No such UI option: foo', pcall_err(api.nvim_ui_attach, 80, 24, { foo = { 'foo' } }))
eq( eq(
"Invalid 'ext_linegrid': expected Boolean, got Array", "Invalid 'ext_linegrid': expected Boolean, got Array",
pcall_err(meths.nvim_ui_attach, 80, 24, { ext_linegrid = {} }) pcall_err(api.nvim_ui_attach, 80, 24, { ext_linegrid = {} })
) )
eq( eq(
"Invalid 'override': expected Boolean, got Array", "Invalid 'override': expected Boolean, got Array",
pcall_err(meths.nvim_ui_attach, 80, 24, { override = {} }) pcall_err(api.nvim_ui_attach, 80, 24, { override = {} })
) )
eq( eq(
"Invalid 'rgb': expected Boolean, got Array", "Invalid 'rgb': expected Boolean, got Array",
pcall_err(meths.nvim_ui_attach, 80, 24, { rgb = {} }) pcall_err(api.nvim_ui_attach, 80, 24, { rgb = {} })
) )
eq( eq(
"Invalid 'term_name': expected String, got Boolean", "Invalid 'term_name': expected String, got Boolean",
pcall_err(meths.nvim_ui_attach, 80, 24, { term_name = true }) pcall_err(api.nvim_ui_attach, 80, 24, { term_name = true })
) )
eq( eq(
"Invalid 'term_colors': expected Integer, got Boolean", "Invalid 'term_colors': expected Integer, got Boolean",
pcall_err(meths.nvim_ui_attach, 80, 24, { term_colors = true }) pcall_err(api.nvim_ui_attach, 80, 24, { term_colors = true })
) )
eq( eq(
"Invalid 'stdin_fd': expected Integer, got String", "Invalid 'stdin_fd': expected Integer, got String",
pcall_err(meths.nvim_ui_attach, 80, 24, { stdin_fd = 'foo' }) pcall_err(api.nvim_ui_attach, 80, 24, { stdin_fd = 'foo' })
) )
eq( eq(
"Invalid 'stdin_tty': expected Boolean, got String", "Invalid 'stdin_tty': expected Boolean, got String",
pcall_err(meths.nvim_ui_attach, 80, 24, { stdin_tty = 'foo' }) pcall_err(api.nvim_ui_attach, 80, 24, { stdin_tty = 'foo' })
) )
eq( eq(
"Invalid 'stdout_tty': expected Boolean, got String", "Invalid 'stdout_tty': expected Boolean, got String",
pcall_err(meths.nvim_ui_attach, 80, 24, { stdout_tty = 'foo' }) pcall_err(api.nvim_ui_attach, 80, 24, { stdout_tty = 'foo' })
) )
eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10)) eq('UI not attached to channel: 1', pcall_err(request, 'nvim_ui_try_resize', 40, 10))
@@ -117,17 +117,17 @@ it('autocmds VimSuspend/VimResume #22041', function()
end) end)
eq({ 's', 'r', 's' }, eval('g:ev')) eq({ 's', 'r', 's' }, eval('g:ev'))
screen.suspended = false screen.suspended = false
meths.nvim_input_mouse('move', '', '', 0, 0, 0) api.nvim_input_mouse('move', '', '', 0, 0, 0)
eq({ 's', 'r', 's', 'r' }, eval('g:ev')) eq({ 's', 'r', 's', 'r' }, eval('g:ev'))
feed('<C-Z><C-Z><C-Z>') feed('<C-Z><C-Z><C-Z>')
screen:expect(function() screen:expect(function()
eq(true, screen.suspended) eq(true, screen.suspended)
end) end)
meths.nvim_ui_set_focus(false) api.nvim_ui_set_focus(false)
eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev')) eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev'))
screen.suspended = false screen.suspended = false
meths.nvim_ui_set_focus(true) api.nvim_ui_set_focus(true)
eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev')) eq({ 's', 'r', 's', 'r', 's', 'r' }, eval('g:ev'))
command('suspend | suspend | suspend') command('suspend | suspend | suspend')

View File

@@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq local clear, fn, eq = helpers.clear, helpers.fn, helpers.eq
local call = helpers.call local api = helpers.api
local meths = helpers.meths
local function read_mpack_file(fname) local function read_mpack_file(fname)
local fd = io.open(fname, 'rb') local fd = io.open(fname, 'rb')
@@ -19,7 +18,7 @@ describe("api_info()['version']", function()
before_each(clear) before_each(clear)
it('returns API level', function() it('returns API level', function()
local version = call('api_info')['version'] local version = fn.api_info()['version']
local current = version['api_level'] local current = version['api_level']
local compat = version['api_compatible'] local compat = version['api_compatible']
eq('number', type(current)) eq('number', type(current))
@@ -28,7 +27,7 @@ describe("api_info()['version']", function()
end) end)
it('returns Nvim version', function() it('returns Nvim version', function()
local version = call('api_info')['version'] local version = fn.api_info()['version']
local major = version['major'] local major = version['major']
local minor = version['minor'] local minor = version['minor']
local patch = version['patch'] local patch = version['patch']
@@ -38,10 +37,10 @@ describe("api_info()['version']", function()
eq('number', type(minor)) eq('number', type(minor))
eq('number', type(patch)) eq('number', type(patch))
eq('boolean', type(prerelease)) eq('boolean', type(prerelease))
eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) eq(1, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. patch))
eq(0, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) eq(0, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1)))
eq(0, funcs.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) eq(0, fn.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch))
eq(0, funcs.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) eq(0, fn.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch))
assert(build == nil or type(build) == 'string') assert(build == nil or type(build) == 'string')
end) end)
end) end)
@@ -90,14 +89,14 @@ describe('api metadata', function()
end end
end end
local api, compat, stable, api_level local api_info, compat, stable, api_level
local old_api = {} local old_api = {}
setup(function() setup(function()
clear() -- Ensure a session before requesting api_info. clear() -- Ensure a session before requesting api_info.
api = meths.nvim_get_api_info()[2] api_info = api.nvim_get_api_info()[2]
compat = api.version.api_compatible compat = api_info.version.api_compatible
api_level = api.version.api_level api_level = api_info.version.api_level
if api.version.api_prerelease then if api_info.version.api_prerelease then
stable = api_level - 1 stable = api_level - 1
else else
stable = api_level stable = api_level
@@ -108,7 +107,7 @@ describe('api metadata', function()
old_api[level] = read_mpack_file(path) old_api[level] = read_mpack_file(path)
if old_api[level] == nil then if old_api[level] == nil then
local errstr = 'missing metadata fixture for stable level ' .. level .. '. ' local errstr = 'missing metadata fixture for stable level ' .. level .. '. '
if level == api_level and not api.version.api_prerelease then if level == api_level and not api_info.version.api_prerelease then
errstr = ( errstr = (
errstr errstr
.. 'If NVIM_API_CURRENT was bumped, ' .. 'If NVIM_API_CURRENT was bumped, '
@@ -125,7 +124,7 @@ describe('api metadata', function()
end) end)
it('functions are compatible with old metadata or have new level', function() it('functions are compatible with old metadata or have new level', function()
local funcs_new = name_table(api.functions) local funcs_new = name_table(api_info.functions)
local funcs_compat = {} local funcs_compat = {}
for level = compat, stable do for level = compat, stable do
for _, f in ipairs(old_api[level].functions) do for _, f in ipairs(old_api[level].functions) do
@@ -146,7 +145,7 @@ describe('api metadata', function()
funcs_compat[level] = name_table(old_api[level].functions) funcs_compat[level] = name_table(old_api[level].functions)
end end
for _, f in ipairs(api.functions) do for _, f in ipairs(api_info.functions) do
if f.since <= stable then if f.since <= stable then
local f_old = funcs_compat[f.since][f.name] local f_old = funcs_compat[f.since][f.name]
if f_old == nil then if f_old == nil then
@@ -159,7 +158,7 @@ describe('api metadata', function()
.. (stable + 1) .. (stable + 1)
.. '.' .. '.'
) )
if not api.version.api_prerelease then if not api_info.version.api_prerelease then
errstr = ( errstr = (
errstr errstr
.. ' Also bump NVIM_API_CURRENT and set ' .. ' Also bump NVIM_API_CURRENT and set '
@@ -172,7 +171,7 @@ describe('api metadata', function()
end end
end end
elseif f.since > api_level then elseif f.since > api_level then
if api.version.api_prerelease then if api_info.version.api_prerelease then
error('New function ' .. f.name .. ' should use since value ' .. api_level) error('New function ' .. f.name .. ' should use since value ' .. api_level)
else else
error( error(
@@ -188,7 +187,7 @@ describe('api metadata', function()
end) end)
it('UI events are compatible with old metadata or have new level', function() it('UI events are compatible with old metadata or have new level', function()
local ui_events_new = name_table(api.ui_events) local ui_events_new = name_table(api_info.ui_events)
local ui_events_compat = {} local ui_events_compat = {}
-- UI events were formalized in level 3 -- UI events were formalized in level 3
@@ -202,7 +201,7 @@ describe('api metadata', function()
ui_events_compat[level] = name_table(old_api[level].ui_events) ui_events_compat[level] = name_table(old_api[level].ui_events)
end end
for _, e in ipairs(api.ui_events) do for _, e in ipairs(api_info.ui_events) do
if e.since <= stable then if e.since <= stable then
local e_old = ui_events_compat[e.since][e.name] local e_old = ui_events_compat[e.since][e.name]
if e_old == nil then if e_old == nil then
@@ -214,7 +213,7 @@ describe('api metadata', function()
.. (stable + 1) .. (stable + 1)
.. '.' .. '.'
) )
if not api.version.api_prerelease then if not api_info.version.api_prerelease then
errstr = ( errstr = (
errstr errstr
.. ' Also bump NVIM_API_CURRENT and set ' .. ' Also bump NVIM_API_CURRENT and set '
@@ -224,7 +223,7 @@ describe('api metadata', function()
error(errstr) error(errstr)
end end
elseif e.since > api_level then elseif e.since > api_level then
if api.version.api_prerelease then if api_info.version.api_prerelease then
error('New UI event ' .. e.name .. ' should use since value ' .. api_level) error('New UI event ' .. e.name .. ' should use since value ' .. api_level)
else else
error( error(
@@ -241,7 +240,7 @@ describe('api metadata', function()
it('ui_options are preserved from older levels', function() it('ui_options are preserved from older levels', function()
local available_options = {} local available_options = {}
for _, option in ipairs(api.ui_options) do for _, option in ipairs(api_info.ui_options) do
available_options[option] = true available_options[option] = true
end end
-- UI options were versioned from level 4 -- UI options were versioned from level 4

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,8 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local meths = helpers.meths local api = helpers.api
local funcs = helpers.funcs local fn = helpers.fn
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
@@ -12,7 +12,7 @@ describe('oldtests', function()
before_each(clear) before_each(clear)
local exec_lines = function(str) local exec_lines = function(str)
return funcs.split(funcs.execute(str), '\n') return fn.split(fn.execute(str), '\n')
end end
local add_an_autocmd = function() local add_an_autocmd = function()
@@ -23,7 +23,7 @@ describe('oldtests', function()
]] ]]
eq(3, #exec_lines('au vimBarTest')) eq(3, #exec_lines('au vimBarTest'))
eq(1, #meths.nvim_get_autocmds({ group = 'vimBarTest' })) eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' }))
end end
it('should recognize a bar before the {event}', function() it('should recognize a bar before the {event}', function()
@@ -31,7 +31,7 @@ describe('oldtests', function()
add_an_autocmd() add_an_autocmd()
exec [[ augroup vimBarTest | au! | augroup END ]] exec [[ augroup vimBarTest | au! | augroup END ]]
eq(1, #exec_lines('au vimBarTest')) eq(1, #exec_lines('au vimBarTest'))
eq({}, meths.nvim_get_autocmds({ group = 'vimBarTest' })) eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' }))
-- Sad spacing -- Sad spacing
add_an_autocmd() add_an_autocmd()
@@ -49,8 +49,8 @@ describe('oldtests', function()
end) end)
it('should fire on unload buf', function() it('should fire on unload buf', function()
funcs.writefile({ 'Test file Xxx1' }, 'Xxx1') fn.writefile({ 'Test file Xxx1' }, 'Xxx1')
funcs.writefile({ 'Test file Xxx2' }, 'Xxx2') fn.writefile({ 'Test file Xxx2' }, 'Xxx2')
local fname = 'Xtest_functional_autocmd_unload' local fname = 'Xtest_functional_autocmd_unload'
local content = [[ local content = [[
@@ -71,16 +71,16 @@ describe('oldtests', function()
q q
]] ]]
funcs.writefile(funcs.split(content, '\n'), fname) fn.writefile(fn.split(content, '\n'), fname)
funcs.delete('Xout') fn.delete('Xout')
funcs.system(string.format('%s --clean -N -S %s', meths.nvim_get_vvar('progpath'), fname)) fn.system(string.format('%s --clean -N -S %s', api.nvim_get_vvar('progpath'), fname))
eq(1, funcs.filereadable('Xout')) eq(1, fn.filereadable('Xout'))
funcs.delete('Xxx1') fn.delete('Xxx1')
funcs.delete('Xxx2') fn.delete('Xxx2')
funcs.delete(fname) fn.delete(fname)
funcs.delete('Xout') fn.delete('Xout')
end) end)
-- oldtest: Test_delete_ml_get_errors() -- oldtest: Test_delete_ml_get_errors()

View File

@@ -10,9 +10,9 @@ local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local matches = helpers.matches local matches = helpers.matches
local meths = helpers.meths local api = helpers.api
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local funcs = helpers.funcs local fn = helpers.fn
local expect = helpers.expect local expect = helpers.expect
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
@@ -142,8 +142,8 @@ describe('autocmd', function()
describe('BufLeave autocommand', function() describe('BufLeave autocommand', function()
it('can wipe out the buffer created by :edit which triggered autocmd', function() it('can wipe out the buffer created by :edit which triggered autocmd', function()
meths.nvim_set_option_value('hidden', true, {}) api.nvim_set_option_value('hidden', true, {})
meths.nvim_buf_set_lines(0, 0, 1, false, { api.nvim_buf_set_lines(0, 0, 1, false, {
'start of test file xx', 'start of test file xx',
'end of test file xx', 'end of test file xx',
}) })
@@ -188,7 +188,7 @@ describe('autocmd', function()
:call add(g:foo, "Once2") :call add(g:foo, "Once2")
:call add(g:foo, "Many2") :call add(g:foo, "Many2")
:call add(g:foo, "Once3")]]), :call add(g:foo, "Once3")]]),
funcs.execute('autocmd Tabnew') fn.execute('autocmd Tabnew')
) )
command('tabnew') command('tabnew')
command('tabnew') command('tabnew')
@@ -201,7 +201,7 @@ describe('autocmd', function()
TabNew TabNew
* :call add(g:foo, "Many1") * :call add(g:foo, "Many1")
:call add(g:foo, "Many2")]]), :call add(g:foo, "Many2")]]),
funcs.execute('autocmd Tabnew') fn.execute('autocmd Tabnew')
) )
-- --
@@ -247,7 +247,7 @@ describe('autocmd', function()
dedent([[ dedent([[
--- Autocommands ---]]), --- Autocommands ---]]),
funcs.execute('autocmd Tabnew') fn.execute('autocmd Tabnew')
) )
end) end)
@@ -415,7 +415,7 @@ describe('autocmd', function()
end) end)
it('gives E814 when there are other floating windows', function() it('gives E814 when there are other floating windows', function()
meths.nvim_open_win( api.nvim_open_win(
0, 0,
true, true,
{ width = 10, height = 10, relative = 'editor', row = 10, col = 10 } { width = 10, height = 10, relative = 'editor', row = 10, col = 10 }
@@ -513,17 +513,17 @@ describe('autocmd', function()
describe('v:event is readonly #18063', function() describe('v:event is readonly #18063', function()
it('during ChanOpen event', function() it('during ChanOpen event', function()
command('autocmd ChanOpen * let v:event.info.id = 0') command('autocmd ChanOpen * let v:event.info.id = 0')
funcs.jobstart({ 'cat' }) fn.jobstart({ 'cat' })
retry(nil, nil, function() retry(nil, nil, function()
eq('E46: Cannot change read-only variable "v:event.info"', meths.nvim_get_vvar('errmsg')) eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg'))
end) end)
end) end)
it('during ChanOpen event', function() it('during ChanOpen event', function()
command('autocmd ChanInfo * let v:event.info.id = 0') command('autocmd ChanInfo * let v:event.info.id = 0')
meths.nvim_set_client_info('foo', {}, 'remote', {}, {}) api.nvim_set_client_info('foo', {}, 'remote', {}, {})
retry(nil, nil, function() retry(nil, nil, function()
eq('E46: Cannot change read-only variable "v:event.info"', meths.nvim_get_vvar('errmsg')) eq('E46: Cannot change read-only variable "v:event.info"', api.nvim_get_vvar('errmsg'))
end) end)
end) end)
@@ -577,7 +577,7 @@ describe('autocmd', function()
call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') call assert_fails('au WinNew * ++once ++once echo bad', 'E983:')
]] ]]
meths.nvim_set_var('did_split', 0) api.nvim_set_var('did_split', 0)
source [[ source [[
augroup Testing augroup Testing
@@ -589,11 +589,11 @@ describe('autocmd', function()
split split
]] ]]
eq(2, meths.nvim_get_var('did_split')) eq(2, api.nvim_get_var('did_split'))
eq(1, funcs.exists('#WinNew')) eq(1, fn.exists('#WinNew'))
-- Now with once -- Now with once
meths.nvim_set_var('did_split', 0) api.nvim_set_var('did_split', 0)
source [[ source [[
augroup Testing augroup Testing
@@ -605,8 +605,8 @@ describe('autocmd', function()
split split
]] ]]
eq(1, meths.nvim_get_var('did_split')) eq(1, api.nvim_get_var('did_split'))
eq(0, funcs.exists('#WinNew')) eq(0, fn.exists('#WinNew'))
-- call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') -- call assert_fails('au WinNew * ++once ++once echo bad', 'E983:')
local ok, msg = pcall( local ok, msg = pcall(
@@ -622,7 +622,7 @@ describe('autocmd', function()
it('should have autocmds in filetypedetect group', function() it('should have autocmds in filetypedetect group', function()
source [[filetype on]] source [[filetype on]]
neq({}, meths.nvim_get_autocmds { group = 'filetypedetect' }) neq({}, api.nvim_get_autocmds { group = 'filetypedetect' })
end) end)
it('should allow comma-separated patterns', function() it('should allow comma-separated patterns', function()
@@ -634,7 +634,7 @@ describe('autocmd', function()
augroup END augroup END
]] ]]
eq(4, #meths.nvim_get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' }) eq(4, #api.nvim_get_autocmds { event = 'BufReadCmd', group = 'TestingPatterns' })
end) end)
end) end)

View File

@@ -8,14 +8,14 @@ local expect = helpers.expect
local eval = helpers.eval local eval = helpers.eval
local next_msg = helpers.next_msg local next_msg = helpers.next_msg
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
describe('cmdline autocommands', function() describe('cmdline autocommands', function()
local channel local channel
before_each(function() before_each(function()
clear() clear()
channel = meths.nvim_get_api_info()[1] channel = api.nvim_get_api_info()[1]
meths.nvim_set_var('channel', channel) api.nvim_set_var('channel', channel)
command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)") command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)")
command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)") command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', v:event)")
command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)") command("autocmd CmdWinEnter * call rpcnotify(g:channel, 'CmdWinEnter', v:event)")

View File

@@ -6,7 +6,7 @@ local feed = helpers.feed
local retry = helpers.retry local retry = helpers.retry
local exec = helpers.source local exec = helpers.source
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local meths = helpers.meths local api = helpers.api
before_each(clear) before_each(clear)
@@ -26,47 +26,47 @@ describe('CursorHold', function()
-- if testing with small 'updatetime' fails, double its value and test again -- if testing with small 'updatetime' fails, double its value and test again
retry(10, nil, function() retry(10, nil, function()
ut = ut * 2 ut = ut * 2
meths.nvim_set_option_value('updatetime', ut, {}) api.nvim_set_option_value('updatetime', ut, {})
feed('0') -- reset did_cursorhold feed('0') -- reset did_cursorhold
meths.nvim_set_var('cursorhold', 0) api.nvim_set_var('cursorhold', 0)
sleep(ut / 4) sleep(ut / 4)
fn() fn()
eq(0, meths.nvim_get_var('cursorhold')) eq(0, api.nvim_get_var('cursorhold'))
sleep(ut / 2) sleep(ut / 2)
fn() fn()
eq(0, meths.nvim_get_var('cursorhold')) eq(0, api.nvim_get_var('cursorhold'))
sleep(ut / 2) sleep(ut / 2)
eq(early, meths.nvim_get_var('cursorhold')) eq(early, api.nvim_get_var('cursorhold'))
sleep(ut / 4 * 3) sleep(ut / 4 * 3)
eq(1, meths.nvim_get_var('cursorhold')) eq(1, api.nvim_get_var('cursorhold'))
end) end)
end end
local ignore_key = meths.nvim_replace_termcodes('<Ignore>', true, true, true) local ignore_key = api.nvim_replace_termcodes('<Ignore>', true, true, true)
test_cursorhold(function() end, 1) test_cursorhold(function() end, 1)
test_cursorhold(function() test_cursorhold(function()
feed('') feed('')
end, 1) end, 1)
test_cursorhold(function() test_cursorhold(function()
meths.nvim_feedkeys('', 'n', true) api.nvim_feedkeys('', 'n', true)
end, 1) end, 1)
test_cursorhold(function() test_cursorhold(function()
feed('<Ignore>') feed('<Ignore>')
end, 0) end, 0)
test_cursorhold(function() test_cursorhold(function()
meths.nvim_feedkeys(ignore_key, 'n', true) api.nvim_feedkeys(ignore_key, 'n', true)
end, 0) end, 0)
end) end)
it("reducing 'updatetime' while waiting for CursorHold #20241", function() it("reducing 'updatetime' while waiting for CursorHold #20241", function()
meths.nvim_set_option_value('updatetime', 10000, {}) api.nvim_set_option_value('updatetime', 10000, {})
feed('0') -- reset did_cursorhold feed('0') -- reset did_cursorhold
meths.nvim_set_var('cursorhold', 0) api.nvim_set_var('cursorhold', 0)
sleep(50) sleep(50)
eq(0, meths.nvim_get_var('cursorhold')) eq(0, api.nvim_get_var('cursorhold'))
meths.nvim_set_option_value('updatetime', 20, {}) api.nvim_set_option_value('updatetime', 20, {})
sleep(10) sleep(10)
eq(1, meths.nvim_get_var('cursorhold')) eq(1, api.nvim_get_var('cursorhold'))
end) end)
end) end)
@@ -85,7 +85,7 @@ describe('CursorHoldI', function()
feed('ifoo') feed('ifoo')
retry(5, nil, function() retry(5, nil, function()
sleep(1) sleep(1)
eq(1, meths.nvim_get_var('cursorhold')) eq(1, api.nvim_get_var('cursorhold'))
end) end)
end) end)
end) end)

View File

@@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local meths = helpers.meths local api = helpers.api
local source = helpers.source local source = helpers.source
local command = helpers.command local command = helpers.command
@@ -41,9 +41,9 @@ describe('CursorMoved', function()
vsplit foo vsplit foo
autocmd CursorMoved * let g:cursormoved += 1 autocmd CursorMoved * let g:cursormoved += 1
]]) ]])
meths.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' }) api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' })
eq(0, eval('g:cursormoved')) eq(0, eval('g:cursormoved'))
eq({ 'aaa' }, meths.nvim_buf_get_lines(eval('g:buf'), 0, -1, true)) eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
eq(0, eval('g:cursormoved')) eq(0, eval('g:cursormoved'))
end) end)

View File

@@ -3,7 +3,7 @@ local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
before_each(clear) before_each(clear)
@@ -18,40 +18,40 @@ describe('SafeState autocommand', function()
it('with pending operator', function() it('with pending operator', function()
feed('d') feed('d')
create_autocmd() create_autocmd()
eq(0, meths.nvim_get_var('safe')) eq(0, api.nvim_get_var('safe'))
feed('d') feed('d')
eq(1, meths.nvim_get_var('safe')) eq(1, api.nvim_get_var('safe'))
end) end)
it('with specified register', function() it('with specified register', function()
feed('"r') feed('"r')
create_autocmd() create_autocmd()
eq(0, meths.nvim_get_var('safe')) eq(0, api.nvim_get_var('safe'))
feed('x') feed('x')
eq(1, meths.nvim_get_var('safe')) eq(1, api.nvim_get_var('safe'))
end) end)
it('with i_CTRL-O', function() it('with i_CTRL-O', function()
feed('i<C-O>') feed('i<C-O>')
create_autocmd() create_autocmd()
eq(0, meths.nvim_get_var('safe')) eq(0, api.nvim_get_var('safe'))
feed('x') feed('x')
eq(1, meths.nvim_get_var('safe')) eq(1, api.nvim_get_var('safe'))
end) end)
it('with Insert mode completion', function() it('with Insert mode completion', function()
feed('i<C-X><C-V>') feed('i<C-X><C-V>')
create_autocmd() create_autocmd()
eq(0, meths.nvim_get_var('safe')) eq(0, api.nvim_get_var('safe'))
feed('<C-X><C-Z>') feed('<C-X><C-Z>')
eq(1, meths.nvim_get_var('safe')) eq(1, api.nvim_get_var('safe'))
end) end)
it('with Cmdline completion', function() it('with Cmdline completion', function()
feed(':<Tab>') feed(':<Tab>')
create_autocmd() create_autocmd()
eq(0, meths.nvim_get_var('safe')) eq(0, api.nvim_get_var('safe'))
feed('<C-E>') feed('<C-E>')
eq(1, meths.nvim_get_var('safe')) eq(1, api.nvim_get_var('safe'))
end) end)
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local meths = helpers.meths local api = helpers.api
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
@@ -13,7 +13,7 @@ describe('autocmd SearchWrapped', function()
command('set ignorecase') command('set ignorecase')
command('let g:test = 0') command('let g:test = 0')
command('autocmd! SearchWrapped * let g:test += 1') command('autocmd! SearchWrapped * let g:test += 1')
meths.nvim_buf_set_lines(0, 0, 1, false, { api.nvim_buf_set_lines(0, 0, 1, false, {
'The quick brown fox', 'The quick brown fox',
'jumps over the lazy dog', 'jumps over the lazy dog',
}) })

View File

@@ -5,7 +5,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local dedent = helpers.dedent local dedent = helpers.dedent
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local eval = helpers.eval local eval = helpers.eval
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
@@ -36,7 +36,7 @@ describe(':autocmd', function()
TestingOne BufEnter TestingOne BufEnter
* :echo "Line 1" * :echo "Line 1"
:echo "Line 2"]]), :echo "Line 2"]]),
funcs.execute('autocmd BufEnter') fn.execute('autocmd BufEnter')
) )
end) end)
@@ -160,7 +160,7 @@ describe(':autocmd', function()
A echo "A2" A echo "A2"
test_3 User test_3 User
A echo "A3"]]), A echo "A3"]]),
funcs.execute('autocmd User A') fn.execute('autocmd User A')
) )
eq( eq(
dedent([[ dedent([[
@@ -178,7 +178,7 @@ describe(':autocmd', function()
B echo "B2" B echo "B2"
test_3 User test_3 User
B echo "B3"]]), B echo "B3"]]),
funcs.execute('autocmd * B') fn.execute('autocmd * B')
) )
eq( eq(
dedent([[ dedent([[
@@ -188,7 +188,7 @@ describe(':autocmd', function()
B echo "B3" B echo "B3"
test_3 User test_3 User
B echo "B3"]]), B echo "B3"]]),
funcs.execute('autocmd test_3 * B') fn.execute('autocmd test_3 * B')
) )
end) end)

View File

@@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local next_msg = helpers.next_msg local next_msg = helpers.next_msg
local is_os = helpers.is_os local is_os = helpers.is_os
local skip = helpers.skip local skip = helpers.skip
@@ -21,25 +21,25 @@ describe('autocmd Signal', function()
it('matches *', function() it('matches *', function()
command('autocmd Signal * call rpcnotify(1, "foo")') command('autocmd Signal * call rpcnotify(1, "foo")')
posix_kill('USR1', funcs.getpid()) posix_kill('USR1', fn.getpid())
eq({ 'notification', 'foo', {} }, next_msg()) eq({ 'notification', 'foo', {} }, next_msg())
end) end)
it('matches SIGUSR1', function() it('matches SIGUSR1', function()
command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")') command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")')
posix_kill('USR1', funcs.getpid()) posix_kill('USR1', fn.getpid())
eq({ 'notification', 'foo', {} }, next_msg()) eq({ 'notification', 'foo', {} }, next_msg())
end) end)
it('matches SIGWINCH', function() it('matches SIGWINCH', function()
command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")') command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")')
posix_kill('WINCH', funcs.getpid()) posix_kill('WINCH', fn.getpid())
eq({ 'notification', 'foo', {} }, next_msg()) eq({ 'notification', 'foo', {} }, next_msg())
end) end)
it('does not match unknown patterns', function() it('does not match unknown patterns', function()
command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")') command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")')
posix_kill('USR1', funcs.getpid()) posix_kill('USR1', fn.getpid())
eq(nil, next_msg(500)) eq(nil, next_msg(500))
end) end)
end) end)

View File

@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq = helpers.clear, helpers.eq local clear, eq = helpers.clear, helpers.eq
local meths = helpers.meths local api = helpers.api
local command = helpers.command local command = helpers.command
describe('TabClosed', function() describe('TabClosed', function()
@@ -14,11 +14,11 @@ describe('TabClosed', function()
) )
repeat repeat
command('tabnew') command('tabnew')
until meths.nvim_eval('tabpagenr()') == 6 -- current tab is now 6 until api.nvim_eval('tabpagenr()') == 6 -- current tab is now 6
eq('tabclosed:6:6:5', meths.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5 eq('tabclosed:6:6:5', api.nvim_exec('tabclose', true)) -- close last 6, current tab is now 5
eq('tabclosed:5:5:4', meths.nvim_exec('close', true)) -- close last window on tab, closes tab eq('tabclosed:5:5:4', api.nvim_exec('close', true)) -- close last window on tab, closes tab
eq('tabclosed:2:2:3', meths.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3 eq('tabclosed:2:2:3', api.nvim_exec('2tabclose', true)) -- close tab 2, current tab is now 3
eq('tabclosed:1:1:2\ntabclosed:1:1:1', meths.nvim_exec('tabonly', true)) -- close tabs 1 and 2 eq('tabclosed:1:1:2\ntabclosed:1:1:1', api.nvim_exec('tabonly', true)) -- close tabs 1 and 2
end) end)
it('is triggered when closing a window via bdelete from another tab', function() it('is triggered when closing a window via bdelete from another tab', function()
@@ -28,9 +28,9 @@ describe('TabClosed', function()
command('1tabedit Xtestfile') command('1tabedit Xtestfile')
command('1tabedit Xtestfile') command('1tabedit Xtestfile')
command('normal! 1gt') command('normal! 1gt')
eq({ 1, 3 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:1\ntabclosed:2:2:1', meths.nvim_exec('bdelete Xtestfile', true)) eq('tabclosed:2:2:1\ntabclosed:2:2:1', api.nvim_exec('bdelete Xtestfile', true))
eq({ 1, 1 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
end) end)
it('is triggered when closing a window via bdelete from current tab', function() it('is triggered when closing a window via bdelete from current tab', function()
@@ -42,9 +42,9 @@ describe('TabClosed', function()
command('1tabedit Xtestfile2') command('1tabedit Xtestfile2')
-- Only one tab is closed, and the alternate file is used for the other. -- Only one tab is closed, and the alternate file is used for the other.
eq({ 2, 3 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:2', meths.nvim_exec('bdelete Xtestfile2', true)) eq('tabclosed:2:2:2', api.nvim_exec('bdelete Xtestfile2', true))
eq('Xtestfile1', meths.nvim_eval('bufname("")')) eq('Xtestfile1', api.nvim_eval('bufname("")'))
end) end)
end) end)
@@ -56,11 +56,11 @@ describe('TabClosed', function()
command('au! TabClosed 2 echom "tabclosed:match"') command('au! TabClosed 2 echom "tabclosed:match"')
repeat repeat
command('tabnew') command('tabnew')
until meths.nvim_eval('tabpagenr()') == 7 -- current tab is now 7 until api.nvim_eval('tabpagenr()') == 7 -- current tab is now 7
-- sanity check, we shouldn't match on tabs with numbers other than 2 -- sanity check, we shouldn't match on tabs with numbers other than 2
eq('tabclosed:7:7:6', meths.nvim_exec('tabclose', true)) eq('tabclosed:7:7:6', api.nvim_exec('tabclose', true))
-- close tab page 2, current tab is now 5 -- close tab page 2, current tab is now 5
eq('tabclosed:2:2:5\ntabclosed:match', meths.nvim_exec('2tabclose', true)) eq('tabclosed:2:2:5\ntabclosed:match', api.nvim_exec('2tabclose', true))
end) end)
end) end)
@@ -70,9 +70,9 @@ describe('TabClosed', function()
'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()' 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()'
) )
command('tabedit Xtestfile') command('tabedit Xtestfile')
eq({ 2, 2 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
eq('tabclosed:2:2:1', meths.nvim_exec('close', true)) eq('tabclosed:2:2:1', api.nvim_exec('close', true))
eq({ 1, 1 }, meths.nvim_eval('[tabpagenr(), tabpagenr("$")]')) eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
end) end)
end) end)
end) end)

View File

@@ -6,7 +6,7 @@ local dedent = helpers.dedent
local eval = helpers.eval local eval = helpers.eval
local eq = helpers.eq local eq = helpers.eq
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
describe('TabNewEntered', function() describe('TabNewEntered', function()
@@ -15,15 +15,15 @@ describe('TabNewEntered', function()
it('matches when entering any new tab', function() it('matches when entering any new tab', function()
clear() clear()
command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")') command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
eq('tabnewentered:2:2', meths.nvim_exec('tabnew', true)) eq('tabnewentered:2:2', api.nvim_exec('tabnew', true))
eq('tabnewentered:3:3', meths.nvim_exec('tabnew test.x2', true)) eq('tabnewentered:3:3', api.nvim_exec('tabnew test.x2', true))
end) end)
end) end)
describe('with FILE as <afile>', function() describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function() it('matches when opening a new tab for FILE', function()
clear() clear()
command('au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"') command('au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
eq('tabnewentered:match', meths.nvim_exec('tabnew Xtest-tabnewentered', true)) eq('tabnewentered:match', api.nvim_exec('tabnew Xtest-tabnewentered', true))
end) end)
end) end)
describe('with CTRL-W T', function() describe('with CTRL-W T', function()
@@ -32,7 +32,7 @@ describe('TabNewEntered', function()
command('au! TabNewEntered * echom "entered"') command('au! TabNewEntered * echom "entered"')
command('tabnew test.x2') command('tabnew test.x2')
command('split') command('split')
eq('entered', meths.nvim_exec('execute "normal \\<C-W>T"', true)) eq('entered', api.nvim_exec('execute "normal \\<C-W>T"', true))
end) end)
end) end)
describe('with tab split #4334', function() describe('with tab split #4334', function()
@@ -40,7 +40,7 @@ describe('TabNewEntered', function()
clear() clear()
command('au! TabNewEntered * let b:entered = "entered"') command('au! TabNewEntered * let b:entered = "entered"')
command('tab split') command('tab split')
eq('entered', meths.nvim_exec('echo b:entered', true)) eq('entered', api.nvim_exec('echo b:entered', true))
end) end)
end) end)
end) end)
@@ -52,8 +52,8 @@ describe('TabEnter', function()
command('augroup TEMP') command('augroup TEMP')
command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
command('augroup END') command('augroup END')
eq('tabenter:2:1', meths.nvim_exec('tabnew', true)) eq('tabenter:2:1', api.nvim_exec('tabnew', true))
eq('tabenter:3:2', meths.nvim_exec('tabnew test.x2', true)) eq('tabenter:3:2', api.nvim_exec('tabnew test.x2', true))
command('augroup! TEMP') command('augroup! TEMP')
end) end)
it('has correct previous tab when entering any preexisting tab', function() it('has correct previous tab when entering any preexisting tab', function()
@@ -62,8 +62,8 @@ describe('TabEnter', function()
command('augroup TEMP') command('augroup TEMP')
command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')') command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
command('augroup END') command('augroup END')
eq('tabenter:1:3', meths.nvim_exec('tabnext', true)) eq('tabenter:1:3', api.nvim_exec('tabnext', true))
eq('tabenter:2:1', meths.nvim_exec('tabnext', true)) eq('tabenter:2:1', api.nvim_exec('tabnext', true))
command('augroup! TEMP') command('augroup! TEMP')
end) end)
end) end)

View File

@@ -7,7 +7,7 @@ local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retr
local matches = helpers.matches local matches = helpers.matches
local ok = helpers.ok local ok = helpers.ok
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local skip = helpers.skip local skip = helpers.skip
@@ -16,13 +16,13 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function() describe('autocmd TermClose', function()
before_each(function() before_each(function()
clear() clear()
meths.nvim_set_option_value('shell', testprg('shell-test'), {}) api.nvim_set_option_value('shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
end) end)
local function test_termclose_delete_own_buf() local function test_termclose_delete_own_buf()
-- The terminal process needs to keep running so that TermClose isn't triggered immediately. -- The terminal process needs to keep running so that TermClose isn't triggered immediately.
meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!') command('autocmd TermClose * bdelete!')
command('terminal') command('terminal')
matches( matches(
@@ -56,7 +56,7 @@ describe('autocmd TermClose', function()
it('triggers when long-running terminal job gets stopped', function() it('triggers when long-running terminal job gets stopped', function()
skip(is_os('win')) skip(is_os('win'))
meths.nvim_set_option_value('shell', is_os('win') and 'cmd.exe' or 'sh', {}) api.nvim_set_option_value('shell', is_os('win') and 'cmd.exe' or 'sh', {})
command('autocmd TermClose * let g:test_termclose = 23') command('autocmd TermClose * let g:test_termclose = 23')
command('terminal') command('terminal')
command('call jobstop(b:terminal_job_id)') command('call jobstop(b:terminal_job_id)')
@@ -67,8 +67,8 @@ describe('autocmd TermClose', function()
it('kills job trapping SIGTERM', function() it('kills job trapping SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
meths.nvim_set_option_value('shell', 'sh', {}) api.nvim_set_option_value('shell', 'sh', {})
meths.nvim_set_option_value('shellcmdflag', '-c', {}) api.nvim_set_option_value('shellcmdflag', '-c', {})
command( command(
[[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] [[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
@@ -93,8 +93,8 @@ describe('autocmd TermClose', function()
it('kills PTY job trapping SIGHUP and SIGTERM', function() it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
meths.nvim_set_option_value('shell', 'sh', {}) api.nvim_set_option_value('shell', 'sh', {})
meths.nvim_set_option_value('shellcmdflag', '-c', {}) api.nvim_set_option_value('shellcmdflag', '-c', {})
command( command(
[[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
.. [[ 'pty': 1,]] .. [[ 'pty': 1,]]
@@ -204,7 +204,7 @@ describe('autocmd TextChangedT', function()
command('autocmd TextChangedT * ++once let g:called = 1') command('autocmd TextChangedT * ++once let g:called = 1')
thelpers.feed_data('a') thelpers.feed_data('a')
retry(nil, nil, function() retry(nil, nil, function()
eq(1, meths.nvim_get_var('called')) eq(1, api.nvim_get_var('called'))
end) end)
end) end)
@@ -214,7 +214,7 @@ describe('autocmd TextChangedT', function()
screen:expect({ any = 'E937: ' }) screen:expect({ any = 'E937: ' })
matches( matches(
'^E937: Attempt to delete a buffer that is in use: term://', '^E937: Attempt to delete a buffer that is in use: term://',
meths.nvim_get_vvar('errmsg') api.nvim_get_vvar('errmsg')
) )
end) end)
end) end)

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
local feed, command, expect = helpers.feed, helpers.command, helpers.expect local feed, command, expect = helpers.feed, helpers.command, helpers.expect
local meths, funcs, neq = helpers.meths, helpers.funcs, helpers.neq local api, fn, neq = helpers.api, helpers.fn, helpers.neq
describe('TextYankPost', function() describe('TextYankPost', function()
before_each(function() before_each(function()
@@ -14,7 +14,7 @@ describe('TextYankPost', function()
command('autocmd TextYankPost * let g:event = copy(v:event)') command('autocmd TextYankPost * let g:event = copy(v:event)')
command('autocmd TextYankPost * let g:count += 1') command('autocmd TextYankPost * let g:count += 1')
meths.nvim_buf_set_lines(0, 0, -1, true, { api.nvim_buf_set_lines(0, 0, -1, true, {
'foo\0bar', 'foo\0bar',
'baz text', 'baz text',
}) })
@@ -100,7 +100,7 @@ describe('TextYankPost', function()
visual = false, visual = false,
}, eval('g:event')) }, eval('g:event'))
eq(1, eval('g:count')) eq(1, eval('g:count'))
eq({ 'foo\nbar' }, funcs.getreg('+', 1, 1)) eq({ 'foo\nbar' }, fn.getreg('+', 1, 1))
end) end)
it('is executed after delete and change', function() it('is executed after delete and change', function()

View File

@@ -7,7 +7,7 @@ local eval = helpers.eval
local exec = helpers.exec local exec = helpers.exec
local command = helpers.command local command = helpers.command
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
before_each(clear) before_each(clear)
@@ -45,7 +45,7 @@ describe('WinScrolled', function()
local win_id local win_id
before_each(function() before_each(function()
win_id = meths.nvim_get_current_win().id win_id = api.nvim_get_current_win().id
command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id)) command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id))
exec([[ exec([[
let g:scrolled = 0 let g:scrolled = 0
@@ -64,7 +64,7 @@ describe('WinScrolled', function()
it('is triggered by scrolling vertically', function() it('is triggered by scrolling vertically', function()
local lines = { '123', '123' } local lines = { '123', '123' }
meths.nvim_buf_set_lines(0, 0, -1, true, lines) api.nvim_buf_set_lines(0, 0, -1, true, lines)
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
feed('<C-E>') feed('<C-E>')
@@ -84,10 +84,10 @@ describe('WinScrolled', function()
it('is triggered by scrolling horizontally', function() it('is triggered by scrolling horizontally', function()
command('set nowrap') command('set nowrap')
local width = meths.nvim_win_get_width(0) local width = api.nvim_win_get_width(0)
local line = '123' .. ('*'):rep(width * 2) local line = '123' .. ('*'):rep(width * 2)
local lines = { line, line } local lines = { line, line }
meths.nvim_buf_set_lines(0, 0, -1, true, lines) api.nvim_buf_set_lines(0, 0, -1, true, lines)
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
feed('zl') feed('zl')
@@ -108,8 +108,8 @@ describe('WinScrolled', function()
it('is triggered by horizontal scrolling from cursor move', function() it('is triggered by horizontal scrolling from cursor move', function()
command('set nowrap') command('set nowrap')
local lines = { '', '', 'Foo' } local lines = { '', '', 'Foo' }
meths.nvim_buf_set_lines(0, 0, -1, true, lines) api.nvim_buf_set_lines(0, 0, -1, true, lines)
meths.nvim_win_set_cursor(0, { 3, 0 }) api.nvim_win_set_cursor(0, { 3, 0 })
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
feed('zl') feed('zl')
@@ -143,10 +143,10 @@ describe('WinScrolled', function()
-- oldtest: Test_WinScrolled_long_wrapped() -- oldtest: Test_WinScrolled_long_wrapped()
it('is triggered by scrolling on a long wrapped line #19968', function() it('is triggered by scrolling on a long wrapped line #19968', function()
local height = meths.nvim_win_get_height(0) local height = api.nvim_win_get_height(0)
local width = meths.nvim_win_get_width(0) local width = api.nvim_win_get_width(0)
meths.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) }) api.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) })
meths.nvim_win_set_cursor(0, { 1, height * width - 1 }) api.nvim_win_set_cursor(0, { 1, height * width - 1 })
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
feed('gj') feed('gj')
@@ -168,12 +168,12 @@ describe('WinScrolled', function()
end) end)
it('is triggered when the window scrolls in Insert mode', function() it('is triggered when the window scrolls in Insert mode', function()
local height = meths.nvim_win_get_height(0) local height = api.nvim_win_get_height(0)
local lines = {} local lines = {}
for i = 1, height * 2 do for i = 1, height * 2 do
lines[i] = tostring(i) lines[i] = tostring(i)
end end
meths.nvim_buf_set_lines(0, 0, -1, true, lines) api.nvim_buf_set_lines(0, 0, -1, true, lines)
feed('M') feed('M')
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
@@ -220,12 +220,12 @@ describe('WinScrolled', function()
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
-- With the upper split focused, send a scroll-down event to the unfocused one. -- With the upper split focused, send a scroll-down event to the unfocused one.
meths.nvim_input_mouse('wheel', 'down', '', 0, 6, 0) api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
eq(1, eval('g:scrolled')) eq(1, eval('g:scrolled'))
-- Again, but this time while we're in insert mode. -- Again, but this time while we're in insert mode.
feed('i') feed('i')
meths.nvim_input_mouse('wheel', 'down', '', 0, 6, 0) api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
feed('<Esc>') feed('<Esc>')
eq(2, eval('g:scrolled')) eq(2, eval('g:scrolled'))
end) end)
@@ -296,15 +296,15 @@ describe('WinScrolled', function()
]]) ]])
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
local buf = meths.nvim_create_buf(true, true) local buf = api.nvim_create_buf(true, true)
meths.nvim_buf_set_lines( api.nvim_buf_set_lines(
buf, buf,
0, 0,
-1, -1,
false, false,
{ '@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' } { '@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' }
) )
local win = meths.nvim_open_win(buf, false, { local win = api.nvim_open_win(buf, false, {
height = 5, height = 5,
width = 10, width = 10,
col = 0, col = 0,
@@ -317,7 +317,7 @@ describe('WinScrolled', function()
-- WinScrolled should not be triggered when creating a new floating window -- WinScrolled should not be triggered when creating a new floating window
eq(0, eval('g:scrolled')) eq(0, eval('g:scrolled'))
meths.nvim_input_mouse('wheel', 'down', '', 0, 3, 3) api.nvim_input_mouse('wheel', 'down', '', 0, 3, 3)
eq(1, eval('g:scrolled')) eq(1, eval('g:scrolled'))
eq(winid_str, eval('g:amatch')) eq(winid_str, eval('g:amatch'))
eq({ eq({
@@ -325,7 +325,7 @@ describe('WinScrolled', function()
[winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 }, [winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event')) }, eval('g:v_event'))
meths.nvim_input_mouse('wheel', 'up', '', 0, 3, 3) api.nvim_input_mouse('wheel', 'up', '', 0, 3, 3)
eq(2, eval('g:scrolled')) eq(2, eval('g:scrolled'))
eq(tostring(win.id), eval('g:amatch')) eq(tostring(win.id), eval('g:amatch'))
eq({ eq({

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq, eval, next_msg, ok, source = local clear, eq, eval, next_msg, ok, source =
helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths local command, fn, api = helpers.command, helpers.fn, helpers.api
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
local set_session = helpers.set_session local set_session = helpers.set_session
@@ -33,12 +33,12 @@ describe('channels', function()
pending('can connect to socket', function() pending('can connect to socket', function()
local server = spawn(nvim_argv, nil, nil, true) local server = spawn(nvim_argv, nil, nil, true)
set_session(server) set_session(server)
local address = funcs.serverlist()[1] local address = fn.serverlist()[1]
local client = spawn(nvim_argv, nil, nil, true) local client = spawn(nvim_argv, nil, nil, true)
set_session(client) set_session(client)
source(init) source(init)
meths.nvim_set_var('address', address) api.nvim_set_var('address', address)
command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})") command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})")
local id = eval('g:id') local id = eval('g:id')
ok(id > 0) ok(id > 0)
@@ -46,7 +46,7 @@ describe('channels', function()
command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))") command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))")
set_session(server) set_session(server)
retry(nil, 1000, function() retry(nil, 1000, function()
eq(23, meths.nvim_get_var('code')) eq(23, api.nvim_get_var('code'))
end) end)
set_session(client) set_session(client)
@@ -67,8 +67,8 @@ describe('channels', function()
\ 'on_exit': function('OnEvent'), \ 'on_exit': function('OnEvent'),
\ } \ }
]]) ]])
meths.nvim_set_var('nvim_prog', nvim_prog) api.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var( api.nvim_set_var(
'code', 'code',
[[ [[
function! OnEvent(id, data, event) dict function! OnEvent(id, data, event) dict
@@ -117,8 +117,8 @@ describe('channels', function()
\ 'on_exit': function('OnEvent'), \ 'on_exit': function('OnEvent'),
\ } \ }
]]) ]])
meths.nvim_set_var('nvim_prog', nvim_prog) api.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var( api.nvim_set_var(
'code', 'code',
[[ [[
function! OnStdin(id, data, event) dict function! OnStdin(id, data, event) dict
@@ -165,8 +165,8 @@ describe('channels', function()
\ 'pty': v:true, \ 'pty': v:true,
\ } \ }
]]) ]])
meths.nvim_set_var('nvim_prog', nvim_prog) api.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var( api.nvim_set_var(
'code', 'code',
[[ [[
function! OnEvent(id, data, event) dict function! OnEvent(id, data, event) dict
@@ -220,8 +220,8 @@ describe('channels', function()
\ 'rpc': v:true, \ 'rpc': v:true,
\ } \ }
]]) ]])
meths.nvim_set_var('nvim_prog', nvim_prog) api.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var( api.nvim_set_var(
'code', 'code',
[[ [[
let id = stdioopen({'rpc':v:true}) let id = stdioopen({'rpc':v:true})
@@ -250,7 +250,7 @@ describe('channels', function()
end) end)
it('can use buffered output mode', function() it('can use buffered output mode', function()
skip(funcs.executable('grep') == 0, 'missing "grep" command') skip(fn.executable('grep') == 0, 'missing "grep" command')
source([[ source([[
let g:job_opts = { let g:job_opts = {
\ 'on_stdout': function('OnEvent'), \ 'on_stdout': function('OnEvent'),
@@ -285,7 +285,7 @@ describe('channels', function()
end) end)
it('can use buffered output mode with no stream callback', function() it('can use buffered output mode with no stream callback', function()
skip(funcs.executable('grep') == 0, 'missing "grep" command') skip(fn.executable('grep') == 0, 'missing "grep" command')
source([[ source([[
function! OnEvent(id, data, event) dict function! OnEvent(id, data, event) dict
call rpcnotify(1, a:event, a:id, a:data, self.stdout) call rpcnotify(1, a:event, a:id, a:data, self.stdout)

View File

@@ -7,7 +7,7 @@ local feed = helpers.feed
local eval = helpers.eval local eval = helpers.eval
local eq = helpers.eq local eq = helpers.eq
local run = helpers.run local run = helpers.run
local funcs = helpers.funcs local fn = helpers.fn
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
@@ -18,7 +18,7 @@ describe('v:exiting', function()
before_each(function() before_each(function()
helpers.clear() helpers.clear()
cid = helpers.meths.nvim_get_api_info()[1] cid = helpers.api.nvim_get_api_info()[1]
end) end)
it('defaults to v:null', function() it('defaults to v:null', function()
@@ -68,7 +68,7 @@ describe(':cquit', function()
poke_eventloop() poke_eventloop()
assert_alive() assert_alive()
else else
funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline }) fn.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline })
eq(exit_code, eval('v:shell_error')) eq(exit_code, eval('v:shell_error'))
end end
end end

View File

@@ -9,18 +9,18 @@ local eq = helpers.eq
local neq = helpers.neq local neq = helpers.neq
local ok = helpers.ok local ok = helpers.ok
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local request = helpers.request local request = helpers.request
local retry = helpers.retry local retry = helpers.retry
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local matches = helpers.matches local matches = helpers.matches
local meths = helpers.meths local api = helpers.api
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local read_file = helpers.read_file local read_file = helpers.read_file
local trim = vim.trim local trim = vim.trim
local currentdir = helpers.funcs.getcwd local currentdir = helpers.fn.getcwd
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local check_close = helpers.check_close local check_close = helpers.check_close
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
@@ -100,8 +100,8 @@ describe('fileio', function()
eq('foozubbaz', trim(read_file('Xtest_startup_file1'))) eq('foozubbaz', trim(read_file('Xtest_startup_file1')))
-- 4. Exit caused by deadly signal (+ 'swapfile'). -- 4. Exit caused by deadly signal (+ 'swapfile').
local j = funcs.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true }) local j = fn.jobstart(vim.tbl_flatten({ args, '--embed' }), { rpc = true })
funcs.rpcrequest( fn.rpcrequest(
j, j,
'nvim_exec2', 'nvim_exec2',
[[ [[
@@ -112,8 +112,8 @@ describe('fileio', function()
]], ]],
{} {}
) )
eq('Xtest_startup_swapdir', funcs.rpcrequest(j, 'nvim_eval', '&directory')) eq('Xtest_startup_swapdir', fn.rpcrequest(j, 'nvim_eval', '&directory'))
funcs.jobstop(j) -- Send deadly signal. fn.jobstop(j) -- Send deadly signal.
local screen = startup() local screen = startup()
feed(':recover Xtest_startup_file2<cr>') feed(':recover Xtest_startup_file2<cr>')
@@ -258,9 +258,9 @@ describe('fileio', function()
'', '',
} }
local fname = 'Xtest_тест.md' local fname = 'Xtest_тест.md'
funcs.writefile(text, fname, 's') fn.writefile(text, fname, 's')
table.insert(text, '') table.insert(text, '')
eq(text, funcs.readfile(fname, 'b')) eq(text, fn.readfile(fname, 'b'))
end) end)
it("read invalid u8 over INT_MAX doesn't segfault", function() it("read invalid u8 over INT_MAX doesn't segfault", function()
clear() clear()
@@ -341,7 +341,7 @@ describe('tmpdir', function()
-- Tempfiles typically look like: "…/nvim.<user>/xxx/0". -- Tempfiles typically look like: "…/nvim.<user>/xxx/0".
-- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims. -- - "…/nvim.<user>/xxx/" is the per-process tmpdir, not shared with other Nvims.
-- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally). -- - "…/nvim.<user>/" is the tmpdir root, shared by all Nvims (normally).
local tmproot = (funcs.tempname()):match(tmproot_pat) local tmproot = (fn.tempname()):match(tmproot_pat)
ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot) ok(tmproot:len() > 4, 'tmproot like "nvim.foo"', tmproot)
return tmproot return tmproot
end end
@@ -360,7 +360,7 @@ describe('tmpdir', function()
rmdir(tmproot) rmdir(tmproot)
write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it. write_file(tmproot, '') -- Not a directory, vim_mktempdir() should skip it.
clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled. -- Assert that broken tmpdir root was handled.
assert_log('tempdir root not a directory', testlog, 100) assert_log('tempdir root not a directory', testlog, 100)
@@ -369,9 +369,9 @@ describe('tmpdir', function()
os.remove(testlog) os.remove(testlog)
os.remove(tmproot) os.remove(tmproot)
mkdir(tmproot) mkdir(tmproot)
funcs.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it. fn.setfperm(tmproot, 'rwxr--r--') -- Invalid permissions, vim_mktempdir() should skip it.
clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } }) clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = os_tmpdir } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir().
-- Assert that broken tmpdir root was handled. -- Assert that broken tmpdir root was handled.
assert_log('tempdir root has invalid permissions', testlog, 100) assert_log('tempdir root has invalid permissions', testlog, 100)
end) end)
@@ -380,8 +380,8 @@ describe('tmpdir', function()
local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666)) local bigname = ('%s/%s'):format(os_tmpdir, ('x'):rep(666))
mkdir(bigname) mkdir(bigname)
clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = bigname } }) clear({ env = { NVIM_LOG_FILE = testlog, TMPDIR = bigname } })
matches(tmproot_pat, funcs.stdpath('run')) -- Tickle vim_mktempdir(). matches(tmproot_pat, fn.stdpath('run')) -- Tickle vim_mktempdir().
local len = (funcs.tempname()):len() local len = (fn.tempname()):len()
ok(len > 4 and len < 256, '4 < len < 256', tostring(len)) ok(len > 4 and len < 256, '4 < len < 256', tostring(len))
end) end)
@@ -390,33 +390,33 @@ describe('tmpdir', function()
assert_nolog('tempdir disappeared', testlog) assert_nolog('tempdir disappeared', testlog)
local function rm_tmpdir() local function rm_tmpdir()
local tmpname1 = funcs.tempname() local tmpname1 = fn.tempname()
local tmpdir1 = funcs.fnamemodify(tmpname1, ':h') local tmpdir1 = fn.fnamemodify(tmpname1, ':h')
eq(funcs.stdpath('run'), tmpdir1) eq(fn.stdpath('run'), tmpdir1)
rmdir(tmpdir1) rmdir(tmpdir1)
retry(nil, 1000, function() retry(nil, 1000, function()
eq(0, funcs.isdirectory(tmpdir1)) eq(0, fn.isdirectory(tmpdir1))
end) end)
local tmpname2 = funcs.tempname() local tmpname2 = fn.tempname()
local tmpdir2 = funcs.fnamemodify(tmpname2, ':h') local tmpdir2 = fn.fnamemodify(tmpname2, ':h')
neq(tmpdir1, tmpdir2) neq(tmpdir1, tmpdir2)
end end
-- Your antivirus hates you... -- Your antivirus hates you...
rm_tmpdir() rm_tmpdir()
assert_log('tempdir disappeared', testlog, 100) assert_log('tempdir disappeared', testlog, 100)
funcs.tempname() fn.tempname()
funcs.tempname() fn.tempname()
funcs.tempname() fn.tempname()
eq('', meths.nvim_get_vvar('errmsg')) eq('', api.nvim_get_vvar('errmsg'))
rm_tmpdir() rm_tmpdir()
funcs.tempname() fn.tempname()
funcs.tempname() fn.tempname()
funcs.tempname() fn.tempname()
eq('E5431: tempdir disappeared (2 times)', meths.nvim_get_vvar('errmsg')) eq('E5431: tempdir disappeared (2 times)', api.nvim_get_vvar('errmsg'))
rm_tmpdir() rm_tmpdir()
eq('E5431: tempdir disappeared (3 times)', meths.nvim_get_vvar('errmsg')) eq('E5431: tempdir disappeared (3 times)', api.nvim_get_vvar('errmsg'))
end) end)
it('$NVIM_APPNAME relative path', function() it('$NVIM_APPNAME relative path', function()
@@ -427,6 +427,6 @@ describe('tmpdir', function()
TMPDIR = os_tmpdir, TMPDIR = os_tmpdir,
}, },
}) })
matches([=[.*[/\\]a%%b%.[^/\\]+]=], funcs.tempname()) matches([=[.*[/\\]a%%b%.[^/\\]+]=], fn.tempname())
end) end)
end) end)

View File

@@ -18,10 +18,10 @@ local mkdir = helpers.mkdir
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local os_kill = helpers.os_kill local os_kill = helpers.os_kill
local retry = helpers.retry local retry = helpers.retry
local meths = helpers.meths local api = helpers.api
local NIL = vim.NIL local NIL = vim.NIL
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local get_pathsep = helpers.get_pathsep local get_pathsep = helpers.get_pathsep
@@ -42,8 +42,8 @@ describe('jobs', function()
before_each(function() before_each(function()
clear() clear()
channel = meths.nvim_get_api_info()[1] channel = api.nvim_get_api_info()[1]
meths.nvim_set_var('channel', channel) api.nvim_set_var('channel', channel)
source([[ source([[
function! Normalize(data) abort function! Normalize(data) abort
" Windows: remove ^M and term escape sequences " Windows: remove ^M and term escape sequences
@@ -235,7 +235,7 @@ describe('jobs', function()
local dir = 'Xtest_not_executable_dir' local dir = 'Xtest_not_executable_dir'
mkdir(dir) mkdir(dir)
funcs.setfperm(dir, 'rw-------') fn.setfperm(dir, 'rw-------')
matches( matches(
'^Vim%(call%):E903: Process failed to start: permission denied: .*', '^Vim%(call%):E903: Process failed to start: permission denied: .*',
pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})")
@@ -402,11 +402,11 @@ describe('jobs', function()
it('can get the pid value using getpid', function() it('can get the pid value using getpid', function()
command("let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
local pid = eval('jobpid(j)') local pid = eval('jobpid(j)')
neq(NIL, meths.nvim_get_proc(pid)) neq(NIL, api.nvim_get_proc(pid))
command('call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
eq(NIL, meths.nvim_get_proc(pid)) eq(NIL, api.nvim_get_proc(pid))
end) end)
it('disposed on Nvim exit', function() it('disposed on Nvim exit', function()
@@ -415,9 +415,9 @@ describe('jobs', function()
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
) )
local pid = eval('jobpid(g:j)') local pid = eval('jobpid(g:j)')
neq(NIL, meths.nvim_get_proc(pid)) neq(NIL, api.nvim_get_proc(pid))
clear() clear()
eq(NIL, meths.nvim_get_proc(pid)) eq(NIL, api.nvim_get_proc(pid))
end) end)
it('can survive the exit of nvim with "detach"', function() it('can survive the exit of nvim with "detach"', function()
@@ -426,9 +426,9 @@ describe('jobs', function()
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
) )
local pid = eval('jobpid(g:j)') local pid = eval('jobpid(g:j)')
neq(NIL, meths.nvim_get_proc(pid)) neq(NIL, api.nvim_get_proc(pid))
clear() clear()
neq(NIL, meths.nvim_get_proc(pid)) neq(NIL, api.nvim_get_proc(pid))
-- clean up after ourselves -- clean up after ourselves
eq(0, os_kill(pid)) eq(0, os_kill(pid))
end) end)
@@ -880,7 +880,7 @@ describe('jobs', function()
r = next_msg() r = next_msg()
eq('job ' .. i .. ' exited', r[3][1]) eq('job ' .. i .. ' exited', r[3][1])
end end
eq(10, meths.nvim_eval('g:counter')) eq(10, api.nvim_eval('g:counter'))
end) end)
describe('with timeout argument', function() describe('with timeout argument', function()
@@ -945,15 +945,15 @@ describe('jobs', function()
]], ]],
} }
feed('<CR>') feed('<CR>')
funcs.jobstop(meths.nvim_get_var('id')) fn.jobstop(api.nvim_get_var('id'))
end) end)
end) end)
pending('exit event follows stdout, stderr', function() pending('exit event follows stdout, stderr', function()
command("let g:job_opts.on_stderr = function('OnEvent')") command("let g:job_opts.on_stderr = function('OnEvent')")
command("let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
meths.nvim_eval('jobsend(j, "abcdef")') api.nvim_eval('jobsend(j, "abcdef")')
meths.nvim_eval('jobstop(j)') api.nvim_eval('jobstop(j)')
expect_msg_seq( expect_msg_seq(
{ {
{ 'notification', 'stdout', { 0, { 'abcdef' } } }, { 'notification', 'stdout', { 0, { 'abcdef' } } },
@@ -1059,11 +1059,11 @@ describe('jobs', function()
end end
local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30') local sleep_cmd = (is_os('win') and 'ping -n 31 127.0.0.1' or 'sleep 30')
local j = eval("jobstart('" .. sleep_cmd .. ' | ' .. sleep_cmd .. ' | ' .. sleep_cmd .. "')") local j = eval("jobstart('" .. sleep_cmd .. ' | ' .. sleep_cmd .. ' | ' .. sleep_cmd .. "')")
local ppid = funcs.jobpid(j) local ppid = fn.jobpid(j)
local children local children
if is_os('win') then if is_os('win') then
local status, result = pcall(retry, nil, nil, function() local status, result = pcall(retry, nil, nil, function()
children = meths.nvim_get_proc_children(ppid) children = api.nvim_get_proc_children(ppid)
-- On Windows conhost.exe may exist, and -- On Windows conhost.exe may exist, and
-- e.g. vctip.exe might appear. #10783 -- e.g. vctip.exe might appear. #10783
ok(#children >= 3 and #children <= 5) ok(#children >= 3 and #children <= 5)
@@ -1075,22 +1075,22 @@ describe('jobs', function()
end end
else else
retry(nil, nil, function() retry(nil, nil, function()
children = meths.nvim_get_proc_children(ppid) children = api.nvim_get_proc_children(ppid)
eq(3, #children) eq(3, #children)
end) end)
end end
-- Assert that nvim_get_proc() sees the children. -- Assert that nvim_get_proc() sees the children.
for _, child_pid in ipairs(children) do for _, child_pid in ipairs(children) do
local info = meths.nvim_get_proc(child_pid) local info = api.nvim_get_proc(child_pid)
-- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name) -- eq((is_os('win') and 'nvim.exe' or 'nvim'), info.name)
eq(ppid, info.ppid) eq(ppid, info.ppid)
end end
-- Kill the root of the tree. -- Kill the root of the tree.
eq(1, funcs.jobstop(j)) eq(1, fn.jobstop(j))
-- Assert that the children were killed. -- Assert that the children were killed.
retry(nil, nil, function() retry(nil, nil, function()
for _, child_pid in ipairs(children) do for _, child_pid in ipairs(children) do
eq(NIL, meths.nvim_get_proc(child_pid)) eq(NIL, api.nvim_get_proc(child_pid))
end end
end) end)
end) end)
@@ -1126,7 +1126,7 @@ describe('jobs', function()
local j local j
local function send(str) local function send(str)
-- check no nvim_chan_free double free with pty job (#14198) -- check no nvim_chan_free double free with pty job (#14198)
meths.nvim_chan_send(j, str) api.nvim_chan_send(j, str)
end end
before_each(function() before_each(function()
@@ -1241,7 +1241,7 @@ describe('pty process teardown', function()
it('does not prevent/delay exit. #4798 #4900', function() it('does not prevent/delay exit. #4798 #4900', function()
skip(is_os('win')) skip(is_os('win'))
-- Use a nested nvim (in :term) to test without --headless. -- Use a nested nvim (in :term) to test without --headless.
funcs.termopen({ fn.termopen({
helpers.nvim_prog, helpers.nvim_prog,
'-u', '-u',
'NONE', 'NONE',

View File

@@ -7,7 +7,7 @@ local matches = helpers.matches
local feed = helpers.feed local feed = helpers.feed
local eval = helpers.eval local eval = helpers.eval
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local fn = helpers.fn
local nvim_prog_abs = helpers.nvim_prog_abs local nvim_prog_abs = helpers.nvim_prog_abs
local write_file = helpers.write_file local write_file = helpers.write_file
local is_os = helpers.is_os local is_os = helpers.is_os
@@ -33,7 +33,7 @@ describe('command-line option', function()
it('treats - as stdin', function() it('treats - as stdin', function()
eq(nil, uv.fs_stat(fname)) eq(nil, uv.fs_stat(fname))
funcs.system({ fn.system({
nvim_prog_abs(), nvim_prog_abs(),
'-u', '-u',
'NONE', 'NONE',
@@ -55,7 +55,7 @@ describe('command-line option', function()
eq(nil, uv.fs_stat(fname)) eq(nil, uv.fs_stat(fname))
eq(true, not not dollar_fname:find('%$%w+')) eq(true, not not dollar_fname:find('%$%w+'))
write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n') write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n')
funcs.system({ fn.system({
nvim_prog_abs(), nvim_prog_abs(),
'-u', '-u',
'NONE', 'NONE',
@@ -91,7 +91,7 @@ describe('command-line option', function()
-- Need to explicitly pipe to stdin so that the embedded Nvim instance doesn't try to read -- Need to explicitly pipe to stdin so that the embedded Nvim instance doesn't try to read
-- data from the terminal #18181 -- data from the terminal #18181
funcs.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), { fn.termopen(string.format([[echo "" | %s]], table.concat(args, ' ')), {
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
}) })
screen:expect( screen:expect(
@@ -128,7 +128,7 @@ describe('command-line option', function()
it('errors out when trying to use nonexistent file with -s', function() it('errors out when trying to use nonexistent file with -s', function()
eq( eq(
'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n', 'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n',
funcs.system({ fn.system({
nvim_prog_abs(), nvim_prog_abs(),
'-u', '-u',
'NONE', 'NONE',
@@ -151,7 +151,7 @@ describe('command-line option', function()
write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n') write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
eq( eq(
'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n', 'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n',
funcs.system({ fn.system({
nvim_prog_abs(), nvim_prog_abs(),
'-u', '-u',
'NONE', 'NONE',
@@ -175,9 +175,9 @@ describe('command-line option', function()
end) end)
it('nvim -v, :version', function() it('nvim -v, :version', function()
matches('Run ":verbose version"', funcs.execute(':version')) matches('Run ":verbose version"', fn.execute(':version'))
matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version')) matches('Compilation: .*Run :checkhealth', fn.execute(':verbose version'))
matches('Run "nvim %-V1 %-v"', funcs.system({ nvim_prog_abs(), '-v' })) matches('Run "nvim %-V1 %-v"', fn.system({ nvim_prog_abs(), '-v' }))
matches('Compilation: .*Run :checkhealth', funcs.system({ nvim_prog_abs(), '-V1', '-v' })) matches('Compilation: .*Run :checkhealth', fn.system({ nvim_prog_abs(), '-V1', '-v' }))
end) end)
end) end)

View File

@@ -4,7 +4,7 @@ local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local insert = helpers.insert local insert = helpers.insert
local is_os = helpers.is_os local is_os = helpers.is_os
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
@@ -167,7 +167,7 @@ describe('file search', function()
else else
write_file(expected, '') write_file(expected, '')
end end
eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]]))) eq(expected, fn[funcname](item, d:gsub(' ', [[\ ]])))
end end
it('finddir()', function() it('finddir()', function()

View File

@@ -6,7 +6,7 @@ local eq = helpers.eq
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local expect = helpers.expect local expect = helpers.expect
local funcs = helpers.funcs local fn = helpers.fn
local insert = helpers.insert local insert = helpers.insert
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local new_argv = helpers.new_argv local new_argv = helpers.new_argv
@@ -42,7 +42,7 @@ describe('Remote', function()
-- Run a `nvim --remote*` command and return { stdout, stderr } of the process -- Run a `nvim --remote*` command and return { stdout, stderr } of the process
local function run_remote(...) local function run_remote(...)
set_session(server) set_session(server)
local addr = funcs.serverlist()[1] local addr = fn.serverlist()[1]
-- Create an nvim instance just to run the remote-invoking nvim. We want -- Create an nvim instance just to run the remote-invoking nvim. We want
-- to wait for the remote instance to exit and calling jobwait blocks -- to wait for the remote instance to exit and calling jobwait blocks
@@ -81,20 +81,20 @@ describe('Remote', function()
it('edit a single file', function() it('edit a single file', function()
eq({ '', '' }, run_remote('--remote', fname)) eq({ '', '' }, run_remote('--remote', fname))
expect(contents) expect(contents)
eq(2, #funcs.getbufinfo()) eq(2, #fn.getbufinfo())
end) end)
it('tab edit a single file with a non-changed buffer', function() it('tab edit a single file with a non-changed buffer', function()
eq({ '', '' }, run_remote('--remote-tab', fname)) eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents) expect(contents)
eq(1, #funcs.gettabinfo()) eq(1, #fn.gettabinfo())
end) end)
it('tab edit a single file with a changed buffer', function() it('tab edit a single file with a changed buffer', function()
insert('hello') insert('hello')
eq({ '', '' }, run_remote('--remote-tab', fname)) eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents) expect(contents)
eq(2, #funcs.gettabinfo()) eq(2, #fn.gettabinfo())
end) end)
it('edit multiple files', function() it('edit multiple files', function()
@@ -102,15 +102,15 @@ describe('Remote', function()
expect(contents) expect(contents)
command('next') command('next')
expect(other_contents) expect(other_contents)
eq(3, #funcs.getbufinfo()) eq(3, #fn.getbufinfo())
end) end)
it('send keys', function() it('send keys', function()
eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v')) eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v'))
expect(contents) expect(contents)
eq(2, #funcs.getwininfo()) eq(2, #fn.getwininfo())
-- Only a single buffer as we're using edit and not drop like --remote does -- Only a single buffer as we're using edit and not drop like --remote does
eq(1, #funcs.getbufinfo()) eq(1, #fn.getbufinfo())
end) end)
it('evaluate expressions', function() it('evaluate expressions', function()
@@ -127,7 +127,7 @@ describe('Remote', function()
it('creates server if not found', function() it('creates server if not found', function()
clear('--remote', fname) clear('--remote', fname)
expect(contents) expect(contents)
eq(1, #funcs.getbufinfo()) eq(1, #fn.getbufinfo())
-- Since we didn't pass silent, we should get a complaint -- Since we didn't pass silent, we should get a complaint
neq(nil, string.find(exec_capture('messages'), 'E247:')) neq(nil, string.find(exec_capture('messages'), 'E247:'))
end) end)
@@ -135,8 +135,8 @@ describe('Remote', function()
it('creates server if not found with tabs', function() it('creates server if not found with tabs', function()
clear('--remote-tab-silent', fname, other_fname) clear('--remote-tab-silent', fname, other_fname)
expect(contents) expect(contents)
eq(2, #funcs.gettabinfo()) eq(2, #fn.gettabinfo())
eq(2, #funcs.getbufinfo()) eq(2, #fn.getbufinfo())
-- We passed silent, so no message should be issued about the server not being found -- We passed silent, so no message should be issued about the server not being found
eq(nil, string.find(exec_capture('messages'), 'E247:')) eq(nil, string.find(exec_capture('messages'), 'E247:'))
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq local eq = helpers.eq
local clear = helpers.clear local clear = helpers.clear
local meths = helpers.meths local api = helpers.api
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local write_file = helpers.write_file local write_file = helpers.write_file
@@ -24,7 +24,7 @@ describe('spellfile', function()
-- │ ┌ Spell file version (#VIMSPELLVERSION) -- │ ┌ Spell file version (#VIMSPELLVERSION)
local spellheader = 'VIMspell\050' local spellheader = 'VIMspell\050'
it('errors out when prefcond section is truncated', function() it('errors out when prefcond section is truncated', function()
meths.nvim_set_option_value('runtimepath', testdir, {}) api.nvim_set_option_value('runtimepath', testdir, {})
-- stylua: ignore -- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
@@ -35,11 +35,11 @@ describe('spellfile', function()
-- │ ┌ Condition length (1 byte) -- │ ┌ Condition length (1 byte)
-- │ │ ┌ Condition regex (missing!) -- │ │ ┌ Condition regex (missing!)
.. '\000\001\001') .. '\000\001\001')
meths.nvim_set_option_value('spelllang', 'en', {}) api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E758: Truncated spell file', exc_exec('set spell')) eq('Vim(set):E758: Truncated spell file', exc_exec('set spell'))
end) end)
it('errors out when prefcond regexp contains NUL byte', function() it('errors out when prefcond regexp contains NUL byte', function()
meths.nvim_set_option_value('runtimepath', testdir, {}) api.nvim_set_option_value('runtimepath', testdir, {})
-- stylua: ignore -- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
@@ -55,11 +55,11 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.nvim_set_option_value('spelllang', 'en', {}) api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
end) end)
it('errors out when region contains NUL byte', function() it('errors out when region contains NUL byte', function()
meths.nvim_set_option_value('runtimepath', testdir, {}) api.nvim_set_option_value('runtimepath', testdir, {})
-- stylua: ignore -- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_REGION) -- ┌ Section identifier (#SN_REGION)
@@ -72,11 +72,11 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.nvim_set_option_value('spelllang', 'en', {}) api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
end) end)
it('errors out when SAL section contains NUL byte', function() it('errors out when SAL section contains NUL byte', function()
meths.nvim_set_option_value('runtimepath', testdir, {}) api.nvim_set_option_value('runtimepath', testdir, {})
-- stylua: ignore -- stylua: ignore
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_SAL) -- ┌ Section identifier (#SN_SAL)
@@ -96,13 +96,13 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.nvim_set_option_value('spelllang', 'en', {}) api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', exc_exec('set spell')) eq('Vim(set):E759: Format error in spell file', exc_exec('set spell'))
end) end)
it('errors out when spell header contains NUL bytes', function() it('errors out when spell header contains NUL bytes', function()
meths.nvim_set_option_value('runtimepath', testdir, {}) api.nvim_set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000') write_file(testdir .. '/spell/en.ascii.spl', spellheader:sub(1, -3) .. '\000\000')
meths.nvim_set_option_value('spelllang', 'en', {}) api.nvim_set_option_value('spelllang', 'en', {})
eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell')) eq('Vim(set):E757: This does not look like a spell file', exc_exec('set spell'))
end) end)
end) end)

View File

@@ -13,7 +13,7 @@ local exec = helpers.exec
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local pesc = vim.pesc local pesc = vim.pesc
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local mkdir_p = helpers.mkdir_p local mkdir_p = helpers.mkdir_p
@@ -25,7 +25,7 @@ local rmdir = helpers.rmdir
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local startswith = vim.startswith local startswith = vim.startswith
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local api = helpers.api
local alter_slashes = helpers.alter_slashes local alter_slashes = helpers.alter_slashes
local is_os = helpers.is_os local is_os = helpers.is_os
local dedent = helpers.dedent local dedent = helpers.dedent
@@ -38,8 +38,8 @@ describe('startup', function()
clear() clear()
ok( ok(
string.find( string.find(
alter_slashes(meths.nvim_get_option_value('runtimepath', {})), alter_slashes(api.nvim_get_option_value('runtimepath', {})),
funcs.stdpath('config'), fn.stdpath('config'),
1, 1,
true true
) ~= nil ) ~= nil
@@ -47,8 +47,8 @@ describe('startup', function()
clear('--clean') clear('--clean')
ok( ok(
string.find( string.find(
alter_slashes(meths.nvim_get_option_value('runtimepath', {})), alter_slashes(api.nvim_get_option_value('runtimepath', {})),
funcs.stdpath('config'), fn.stdpath('config'),
1, 1,
true true
) == nil ) == nil
@@ -60,7 +60,7 @@ describe('startup', function()
local screen local screen
screen = Screen.new(84, 3) screen = Screen.new(84, 3)
screen:attach() screen:attach()
funcs.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) fn.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' })
screen:expect([[ screen:expect([[
^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) | ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) |
|*2 |*2
@@ -82,7 +82,7 @@ describe('startup', function()
local screen local screen
screen = Screen.new(60, 7) screen = Screen.new(60, 7)
screen:attach() screen:attach()
local id = funcs.termopen({ local id = fn.termopen({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -105,7 +105,7 @@ describe('startup', function()
> | > |
| |
]]) ]])
funcs.chansend(id, 'cont\n') fn.chansend(id, 'cont\n')
screen:expect([[ screen:expect([[
^ | ^ |
~ |*3 ~ |*3
@@ -124,13 +124,13 @@ describe('startup', function()
vim.list_extend(args, nvim_args or {}) vim.list_extend(args, nvim_args or {})
vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') })
vim.list_extend(args, lua_args or {}) vim.list_extend(args, lua_args or {})
local out = funcs.system(args, input):gsub('\r\n', '\n') local out = fn.system(args, input):gsub('\r\n', '\n')
return eq(dedent(expected), out) return eq(dedent(expected), out)
end end
it('failure modes', function() it('failure modes', function()
-- nvim -l <empty> -- nvim -l <empty>
matches('nvim%.?e?x?e?: Argument missing after: "%-l"', funcs.system({ nvim_prog, '-l' })) matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' }))
eq(1, eval('v:shell_error')) eq(1, eval('v:shell_error'))
end) end)
@@ -161,12 +161,12 @@ describe('startup', function()
eq(0, eval('v:shell_error')) eq(0, eval('v:shell_error'))
matches( matches(
'E5113: .* my pearls!!', 'E5113: .* my pearls!!',
funcs.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' })
) )
eq(1, eval('v:shell_error')) eq(1, eval('v:shell_error'))
matches( matches(
'E5113: .* %[string "error%("whoa"%)"%]:1: whoa', 'E5113: .* %[string "error%("whoa"%)"%]:1: whoa',
funcs.system({ nvim_prog, '-l', '-' }, 'error("whoa")') fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")')
) )
eq(1, eval('v:shell_error')) eq(1, eval('v:shell_error'))
end) end)
@@ -286,7 +286,7 @@ describe('startup', function()
end) end)
it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function() it('--cmd/-c/+ do not truncate long Lua print() message with --headless', function()
local out = funcs.system({ local out = fn.system({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -305,7 +305,7 @@ describe('startup', function()
it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function()
-- system() puts a pipe at both ends. -- system() puts a pipe at both ends.
local out = funcs.system({ local out = fn.system({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -340,7 +340,7 @@ describe('startup', function()
command([[set shellcmdflag=/s\ /c shellxquote=\"]]) command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end end
-- Running in :terminal -- Running in :terminal
funcs.termopen({ fn.termopen({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -372,7 +372,7 @@ describe('startup', function()
os.remove('Xtest_startup_ttyout') os.remove('Xtest_startup_ttyout')
end) end)
-- Running in :terminal -- Running in :terminal
funcs.termopen( fn.termopen(
( (
[["%s" -u NONE -i NONE --cmd "%s"]] [["%s" -u NONE -i NONE --cmd "%s"]]
.. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]]
@@ -402,7 +402,7 @@ describe('startup', function()
os.remove('Xtest_startup_ttyout') os.remove('Xtest_startup_ttyout')
end) end)
-- Running in :terminal -- Running in :terminal
funcs.termopen( fn.termopen(
( (
[[echo foo | ]] -- Input from a pipe. [[echo foo | ]] -- Input from a pipe.
.. [["%s" -u NONE -i NONE --cmd "%s"]] .. [["%s" -u NONE -i NONE --cmd "%s"]]
@@ -431,7 +431,7 @@ describe('startup', function()
command([[set shellcmdflag=/s\ /c shellxquote=\"]]) command([[set shellcmdflag=/s\ /c shellxquote=\"]])
end end
-- Running in :terminal -- Running in :terminal
funcs.termopen( fn.termopen(
( (
[[echo foo | ]] [[echo foo | ]]
.. [["%s" -u NONE -i NONE --cmd "%s"]] .. [["%s" -u NONE -i NONE --cmd "%s"]]
@@ -454,7 +454,7 @@ describe('startup', function()
it('input from pipe + file args #7679', function() it('input from pipe + file args #7679', function()
eq( eq(
'ohyeah\r\n0 0 bufs=3', 'ohyeah\r\n0 0 bufs=3',
funcs.system({ fn.system({
nvim_prog, nvim_prog,
'-n', '-n',
'-u', '-u',
@@ -475,7 +475,7 @@ describe('startup', function()
it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function() it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function()
eq( eq(
'\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', '\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0',
funcs.system({ fn.system({
nvim_prog, nvim_prog,
'-n', '-n',
'-u', '-u',
@@ -501,7 +501,7 @@ describe('startup', function()
-- --
eq( eq(
'partylikeits1999\n', 'partylikeits1999\n',
funcs.system({ fn.system({
nvim_prog, nvim_prog,
'-n', '-n',
'-u', '-u',
@@ -513,16 +513,16 @@ describe('startup', function()
'test/functional/fixtures/tty-test.c', 'test/functional/fixtures/tty-test.c',
}, { 'partylikeits1999', '' }) }, { 'partylikeits1999', '' })
) )
eq(inputstr, funcs.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) eq(inputstr, fn.system({ nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input))
-- with `-u NORC` -- with `-u NORC`
eq( eq(
'thepartycontinues\n', 'thepartycontinues\n',
funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' }) fn.system({ nvim_prog, '-n', '-u', 'NORC', '-Es', '+.print' }, { 'thepartycontinues', '' })
) )
-- without `-u` -- without `-u`
eq( eq(
'thepartycontinues\n', 'thepartycontinues\n',
funcs.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' }) fn.system({ nvim_prog, '-n', '-Es', '+.print' }, { 'thepartycontinues', '' })
) )
-- --
@@ -530,7 +530,7 @@ describe('startup', function()
-- --
eq( eq(
' encoding=utf-8\n', ' encoding=utf-8\n',
funcs.system({ fn.system({
nvim_prog, nvim_prog,
'-n', '-n',
'-u', '-u',
@@ -541,19 +541,19 @@ describe('startup', function()
'test/functional/fixtures/tty-test.c', 'test/functional/fixtures/tty-test.c',
}, { 'set encoding', '' }) }, { 'set encoding', '' })
) )
eq('line1\nline2\n', funcs.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input)) eq('line1\nline2\n', fn.system({ nvim_prog, '-i', 'NONE', '-es', '-' }, input))
-- with `-u NORC` -- with `-u NORC`
eq( eq(
' encoding=utf-8\n', ' encoding=utf-8\n',
funcs.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' }) fn.system({ nvim_prog, '-n', '-u', 'NORC', '-es' }, { 'set encoding', '' })
) )
-- without `-u` -- without `-u`
eq(' encoding=utf-8\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) eq(' encoding=utf-8\n', fn.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' }))
end) end)
it('-es/-Es disables swapfile, user config #8540', function() it('-es/-Es disables swapfile, user config #8540', function()
for _, arg in ipairs({ '-es', '-Es' }) do for _, arg in ipairs({ '-es', '-Es' }) do
local out = funcs.system({ local out = fn.system({
nvim_prog, nvim_prog,
arg, arg,
'+set swapfile? updatecount? shadafile?', '+set swapfile? updatecount? shadafile?',
@@ -572,15 +572,15 @@ describe('startup', function()
it('fails on --embed with -es/-Es/-l', function() it('fails on --embed with -es/-Es/-l', function()
matches( matches(
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
funcs.system({ nvim_prog, '--embed', '-es' }) fn.system({ nvim_prog, '--embed', '-es' })
) )
matches( matches(
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
funcs.system({ nvim_prog, '--embed', '-Es' }) fn.system({ nvim_prog, '--embed', '-Es' })
) )
matches( matches(
'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l',
funcs.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) fn.system({ nvim_prog, '--embed', '-l', 'foo.lua' })
) )
end) end)
@@ -588,7 +588,7 @@ describe('startup', function()
local screen local screen
screen = Screen.new(60, 6) screen = Screen.new(60, 6)
screen:attach() screen:attach()
local id = funcs.termopen({ local id = fn.termopen({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -611,7 +611,7 @@ describe('startup', function()
Press ENTER or type command to continue | Press ENTER or type command to continue |
| |
]]) ]])
funcs.chansend(id, '\n') fn.chansend(id, '\n')
screen:expect([[ screen:expect([[
^ | ^ |
~ |*2 ~ |*2
@@ -651,7 +651,7 @@ describe('startup', function()
expected, expected,
-- FIXME(codehex): We should really set a timeout for the system function. -- FIXME(codehex): We should really set a timeout for the system function.
-- If this test fails, there will be a waiting input state. -- If this test fails, there will be a waiting input state.
funcs.system({ fn.system({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -663,7 +663,7 @@ describe('startup', function()
end) end)
it('get command line arguments from v:argv', function() it('get command line arguments from v:argv', function()
local out = funcs.system({ local out = fn.system({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -715,7 +715,7 @@ describe('startup', function()
:put =mode(1) | :put =mode(1) |
]]) ]])
eq('cv\n', funcs.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' })) eq('cv\n', fn.system({ nvim_prog, '-n', '-es' }, { 'put =mode(1)', 'print', '' }))
end) end)
it('-d does not diff non-arglist windows #13720 #21289', function() it('-d does not diff non-arglist windows #13720 #21289', function()
@@ -737,11 +737,11 @@ describe('startup', function()
os.remove('Xdiff.vim') os.remove('Xdiff.vim')
end) end)
clear { args = { '-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim' } } clear { args = { '-u', 'Xdiff.vim', '-d', 'Xdiff.vim', 'Xdiff.vim' } }
eq(true, meths.nvim_get_option_value('diff', { win = funcs.win_getid(1) })) eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(1) }))
eq(true, meths.nvim_get_option_value('diff', { win = funcs.win_getid(2) })) eq(true, api.nvim_get_option_value('diff', { win = fn.win_getid(2) }))
local float_win = funcs.win_getid(3) local float_win = fn.win_getid(3)
eq('editor', meths.nvim_win_get_config(float_win).relative) eq('editor', api.nvim_win_get_config(float_win).relative)
eq(false, meths.nvim_get_option_value('diff', { win = float_win })) eq(false, api.nvim_get_option_value('diff', { win = float_win }))
end) end)
it('does not crash if --embed is given twice', function() it('does not crash if --embed is given twice', function()
@@ -870,7 +870,7 @@ describe('startup', function()
exec_lua [[ return _G.test_loadorder ]] exec_lua [[ return _G.test_loadorder ]]
) )
local rtp = meths.nvim_get_option_value('rtp', {}) local rtp = api.nvim_get_option_value('rtp', {})
ok( ok(
startswith( startswith(
rtp, rtp,
@@ -963,9 +963,9 @@ describe('startup', function()
os.remove('Xtab2.noft') os.remove('Xtab2.noft')
end) end)
clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } }) clear({ args = { '-p', 'Xtab1.noft', 'Xtab2.noft' } })
eq(81, meths.nvim_win_get_width(0)) eq(81, api.nvim_win_get_width(0))
command('tabnext') command('tabnext')
eq(81, meths.nvim_win_get_width(0)) eq(81, api.nvim_win_get_width(0))
end) end)
end) end)
@@ -1062,7 +1062,7 @@ describe('user config init', function()
clear { args_rm = { '-u' }, env = xenv } clear { args_rm = { '-u' }, env = xenv }
eq(1, eval('g:lua_rc')) eq(1, eval('g:lua_rc'))
eq(funcs.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC')) eq(fn.fnamemodify(init_lua_path, ':p'), eval('$MYVIMRC'))
end) end)
describe('loads existing', function() describe('loads existing', function()
@@ -1122,7 +1122,7 @@ describe('user config init', function()
local screen = Screen.new(50, 8) local screen = Screen.new(50, 8)
screen:attach() screen:attach()
funcs.termopen({ nvim_prog }, { fn.termopen({ nvim_prog }, {
env = { env = {
VIMRUNTIME = os.getenv('VIMRUNTIME'), VIMRUNTIME = os.getenv('VIMRUNTIME'),
}, },
@@ -1245,7 +1245,7 @@ describe('runtime:', function()
-- Check if plugin_file_path is listed in getscriptinfo() -- Check if plugin_file_path is listed in getscriptinfo()
local scripts = tbl_map(function(s) local scripts = tbl_map(function(s)
return s.name return s.name
end, funcs.getscriptinfo()) end, fn.getscriptinfo())
ok(#tbl_filter(function(s) ok(#tbl_filter(function(s)
return endswith(s, plugin_file_path) return endswith(s, plugin_file_path)
end, scripts) > 0) end, scripts) > 0)
@@ -1369,13 +1369,13 @@ describe('inccommand on ex mode', function()
local screen local screen
screen = Screen.new(60, 10) screen = Screen.new(60, 10)
screen:attach() screen:attach()
local id = funcs.termopen( local id = fn.termopen(
{ nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' }, { nvim_prog, '-u', 'NONE', '-c', 'set termguicolors', '-E', 'test/README.md' },
{ {
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
} }
) )
funcs.chansend(id, '%s/N') fn.chansend(id, '%s/N')
screen:expect { screen:expect {
grid = [[ grid = [[
{1:^ }| {1:^ }|

View File

@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eq, clear, eval, feed, meths, retry = local eq, clear, eval, feed, api, retry =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.meths, helpers.retry helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.api, helpers.retry
describe('K', function() describe('K', function()
local test_file = 'K_spec_out' local test_file = 'K_spec_out'
@@ -61,9 +61,9 @@ describe('K', function()
end) end)
it('empty string falls back to :help #19298', function() it('empty string falls back to :help #19298', function()
meths.nvim_set_option_value('keywordprg', '', {}) api.nvim_set_option_value('keywordprg', '', {})
meths.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' }) api.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' })
feed('K') feed('K')
eq('E149: Sorry, no help for doesnotexist', meths.nvim_get_vvar('errmsg')) eq('E149: Sorry, no help for doesnotexist', api.nvim_get_vvar('errmsg'))
end) end)
end) end)

View File

@@ -4,9 +4,9 @@ local assert_alive = helpers.assert_alive
local clear, feed = helpers.clear, helpers.feed local clear, feed = helpers.clear, helpers.feed
local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq
local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect
local funcs = helpers.funcs local fn = helpers.fn
local command = helpers.command local command = helpers.command
local meths = helpers.meths local api = helpers.api
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
describe('completion', function() describe('completion', function()
@@ -820,23 +820,23 @@ describe('completion', function()
end) end)
it('provides completion from `getcompletion()`', function() it('provides completion from `getcompletion()`', function()
eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) eq({ 'vim' }, fn.getcompletion('vi', 'lua'))
eq({ 'api' }, funcs.getcompletion('vim.ap', 'lua')) eq({ 'api' }, fn.getcompletion('vim.ap', 'lua'))
eq({ 'tbl_filter' }, funcs.getcompletion('vim.tbl_fil', 'lua')) eq({ 'tbl_filter' }, fn.getcompletion('vim.tbl_fil', 'lua'))
eq({ 'vim' }, funcs.getcompletion('print(vi', 'lua')) eq({ 'vim' }, fn.getcompletion('print(vi', 'lua'))
-- fuzzy completion is not supported, so the result should be the same -- fuzzy completion is not supported, so the result should be the same
command('set wildoptions+=fuzzy') command('set wildoptions+=fuzzy')
eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) eq({ 'vim' }, fn.getcompletion('vi', 'lua'))
end) end)
end) end)
it('cmdline completion supports various string options', function() it('cmdline completion supports various string options', function()
eq('auto', funcs.getcompletion('set foldcolumn=', 'cmdline')[2]) eq('auto', fn.getcompletion('set foldcolumn=', 'cmdline')[2])
eq({ 'nosplit', 'split' }, funcs.getcompletion('set inccommand=', 'cmdline')) eq({ 'nosplit', 'split' }, fn.getcompletion('set inccommand=', 'cmdline'))
eq({ 'ver:3,hor:6', 'hor:', 'ver:' }, funcs.getcompletion('set mousescroll=', 'cmdline')) eq({ 'ver:3,hor:6', 'hor:', 'ver:' }, fn.getcompletion('set mousescroll=', 'cmdline'))
eq('BS', funcs.getcompletion('set termpastefilter=', 'cmdline')[2]) eq('BS', fn.getcompletion('set termpastefilter=', 'cmdline')[2])
eq('SpecialKey', funcs.getcompletion('set winhighlight=', 'cmdline')[1]) eq('SpecialKey', fn.getcompletion('set winhighlight=', 'cmdline')[1])
eq('SpecialKey', funcs.getcompletion('set winhighlight=NonText:', 'cmdline')[1]) eq('SpecialKey', fn.getcompletion('set winhighlight=NonText:', 'cmdline')[1])
end) end)
describe('from the commandline window', function() describe('from the commandline window', function()
@@ -882,8 +882,8 @@ describe('completion', function()
return '' return ''
endfunction endfunction
]]) ]])
meths.nvim_set_option_value('completeopt', 'menuone,noselect', {}) api.nvim_set_option_value('completeopt', 'menuone,noselect', {})
meths.nvim_set_var('_complist', { api.nvim_set_var('_complist', {
{ {
word = 0, word = 0,
abbr = 1, abbr = 1,
@@ -927,7 +927,7 @@ describe('completion', function()
end) end)
it('CompleteChanged autocommand', function() it('CompleteChanged autocommand', function()
meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'foobar', '' }) api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'foobar', '' })
source([[ source([[
set complete=. completeopt=noinsert,noselect,menuone set complete=. completeopt=noinsert,noselect,menuone
function! OnPumChange() function! OnPumChange()

View File

@@ -5,7 +5,7 @@ local insert = helpers.insert
local feed = helpers.feed local feed = helpers.feed
local expect = helpers.expect local expect = helpers.expect
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local eq = helpers.eq local eq = helpers.eq
local neq = helpers.neq local neq = helpers.neq
@@ -75,8 +75,8 @@ describe('Folds', function()
local function get_folds() local function get_folds()
local rettab = {} local rettab = {}
for i = 1, funcs.line('$') do for i = 1, fn.line('$') do
table.insert(rettab, funcs.foldlevel(i)) table.insert(rettab, fn.foldlevel(i))
end end
return rettab return rettab
end end
@@ -140,21 +140,21 @@ a
a a
a]]) a]])
-- lines are not closed, folds are correct -- lines are not closed, folds are correct
for i = 1, funcs.line('$') do for i = 1, fn.line('$') do
eq(-1, funcs.foldclosed(i)) eq(-1, fn.foldclosed(i))
if i == 1 or i == 7 or i == 13 then if i == 1 or i == 7 or i == 13 then
eq(0, funcs.foldlevel(i)) eq(0, fn.foldlevel(i))
elseif i == 4 then elseif i == 4 then
eq(2, funcs.foldlevel(i)) eq(2, fn.foldlevel(i))
else else
eq(1, funcs.foldlevel(i)) eq(1, fn.foldlevel(i))
end end
end end
-- folds are not corrupted -- folds are not corrupted
feed('zM') feed('zM')
eq(6, funcs.foldclosedend(2)) eq(6, fn.foldclosedend(2))
eq(12, funcs.foldclosedend(8)) eq(12, fn.foldclosedend(8))
eq(18, funcs.foldclosedend(14)) eq(18, fn.foldclosedend(14))
end) end)
it("doesn't split a fold when the move is within it", function() it("doesn't split a fold when the move is within it", function()
@@ -330,13 +330,13 @@ a]],
a a
]]) ]])
for i = 1, 2 do for i = 1, 2 do
eq(1, funcs.foldlevel(i)) eq(1, fn.foldlevel(i))
end end
for i = 3, 5 do for i = 3, 5 do
eq(0, funcs.foldlevel(i)) eq(0, fn.foldlevel(i))
end end
for i = 6, 8 do for i = 6, 8 do
eq(1, funcs.foldlevel(i)) eq(1, fn.foldlevel(i))
end end
end) end)
@@ -354,7 +354,7 @@ a]],
]]) ]])
command('setlocal foldmethod=indent') command('setlocal foldmethod=indent')
command('3,5d') command('3,5d')
eq(5, funcs.foldclosedend(1)) eq(5, fn.foldclosedend(1))
end) end)
it("doesn't combine folds that have a specified end", function() it("doesn't combine folds that have a specified end", function()
@@ -371,7 +371,7 @@ a]],
command('setlocal foldmethod=marker') command('setlocal foldmethod=marker')
command('3,5d') command('3,5d')
command('%foldclose') command('%foldclose')
eq(2, funcs.foldclosedend(1)) eq(2, fn.foldclosedend(1))
end) end)
it('splits folds according to >N and <N with foldexpr', function() it('splits folds according to >N and <N with foldexpr', function()
@@ -415,20 +415,20 @@ a]],
command('foldopen') command('foldopen')
command('read ' .. tempfname) command('read ' .. tempfname)
command('%foldclose') command('%foldclose')
eq(2, funcs.foldclosedend(1)) eq(2, fn.foldclosedend(1))
eq(0, funcs.foldlevel(3)) eq(0, fn.foldlevel(3))
eq(0, funcs.foldlevel(4)) eq(0, fn.foldlevel(4))
eq(6, funcs.foldclosedend(5)) eq(6, fn.foldclosedend(5))
eq(10, funcs.foldclosedend(7)) eq(10, fn.foldclosedend(7))
eq(14, funcs.foldclosedend(11)) eq(14, fn.foldclosedend(11))
end) end)
it('no folds remain if :delete makes buffer empty #19671', function() it('no folds remain if :delete makes buffer empty #19671', function()
command('setlocal foldmethod=manual') command('setlocal foldmethod=manual')
funcs.setline(1, { 'foo', 'bar', 'baz' }) fn.setline(1, { 'foo', 'bar', 'baz' })
command('2,3fold') command('2,3fold')
command('%delete') command('%delete')
eq(0, funcs.foldlevel(1)) eq(0, fn.foldlevel(1))
end) end)
it('multibyte fold markers work #20438', function() it('multibyte fold markers work #20438', function()
@@ -442,7 +442,7 @@ a]],
bbbbb/*«*/ bbbbb/*«*/
bbbbb bbbbb
bbbbb/*»*/]]) bbbbb/*»*/]])
eq(1, funcs.foldlevel(1)) eq(1, fn.foldlevel(1))
end) end)
it('updates correctly with indent method and visual blockwise insertion #22898', function() it('updates correctly with indent method and visual blockwise insertion #22898', function()
@@ -452,8 +452,8 @@ a]],
]]) ]])
command('setlocal foldmethod=indent shiftwidth=2') command('setlocal foldmethod=indent shiftwidth=2')
feed('gg0<C-v>jI <Esc>') -- indent both lines using visual blockwise mode feed('gg0<C-v>jI <Esc>') -- indent both lines using visual blockwise mode
eq(1, funcs.foldlevel(1)) eq(1, fn.foldlevel(1))
eq(1, funcs.foldlevel(2)) eq(1, fn.foldlevel(2))
end) end)
it("doesn't open folds with indent method when inserting lower foldlevel line", function() it("doesn't open folds with indent method when inserting lower foldlevel line", function()
@@ -464,22 +464,22 @@ a]],
keep this line folded 2 keep this line folded 2
]]) ]])
command('set foldmethod=indent shiftwidth=2 noautoindent') command('set foldmethod=indent shiftwidth=2 noautoindent')
eq(1, funcs.foldlevel(1)) eq(1, fn.foldlevel(1))
eq(1, funcs.foldlevel(2)) eq(1, fn.foldlevel(2))
eq(2, funcs.foldlevel(3)) eq(2, fn.foldlevel(3))
eq(2, funcs.foldlevel(4)) eq(2, fn.foldlevel(4))
feed('zo') -- open the outer fold feed('zo') -- open the outer fold
neq(-1, funcs.foldclosed(3)) -- make sure the inner fold is not open neq(-1, fn.foldclosed(3)) -- make sure the inner fold is not open
feed('gg0oa<Esc>') -- insert unindented line feed('gg0oa<Esc>') -- insert unindented line
eq(1, funcs.foldlevel(1)) --| insert an unindented line under this line eq(1, fn.foldlevel(1)) --| insert an unindented line under this line
eq(0, funcs.foldlevel(2)) --|a eq(0, fn.foldlevel(2)) --|a
eq(1, funcs.foldlevel(3)) --| keep the lines under this line folded eq(1, fn.foldlevel(3)) --| keep the lines under this line folded
eq(2, funcs.foldlevel(4)) --| keep this line folded 1 eq(2, fn.foldlevel(4)) --| keep this line folded 1
eq(2, funcs.foldlevel(5)) --| keep this line folded 2 eq(2, fn.foldlevel(5)) --| keep this line folded 2
neq(-1, funcs.foldclosed(4)) -- make sure the inner fold is still not open neq(-1, fn.foldclosed(4)) -- make sure the inner fold is still not open
end) end)
end) end)

View File

@@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local feed = helpers.feed local feed = helpers.feed
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local api = helpers.api
describe('jumplist', function() describe('jumplist', function()
local fname1 = 'Xtest-functional-normal-jump' local fname1 = 'Xtest-functional-normal-jump'
@@ -20,7 +20,7 @@ describe('jumplist', function()
end) end)
it('does not add a new entry on startup', function() it('does not add a new entry on startup', function()
eq('\n jump line col file/text\n>', funcs.execute('jumps')) eq('\n jump line col file/text\n>', fn.execute('jumps'))
end) end)
it('does not require two <C-O> strokes to jump back', function() it('does not require two <C-O> strokes to jump back', function()
@@ -28,25 +28,25 @@ describe('jumplist', function()
write_file(fname2, 'second file contents') write_file(fname2, 'second file contents')
command('args ' .. fname1 .. ' ' .. fname2) command('args ' .. fname1 .. ' ' .. fname2)
local buf1 = funcs.bufnr(fname1) local buf1 = fn.bufnr(fname1)
local buf2 = funcs.bufnr(fname2) local buf2 = fn.bufnr(fname2)
command('next') command('next')
feed('<C-O>') feed('<C-O>')
eq(buf1, funcs.bufnr('%')) eq(buf1, fn.bufnr('%'))
command('first') command('first')
command('snext') command('snext')
feed('<C-O>') feed('<C-O>')
eq(buf1, funcs.bufnr('%')) eq(buf1, fn.bufnr('%'))
feed('<C-I>') feed('<C-I>')
eq(buf2, funcs.bufnr('%')) eq(buf2, fn.bufnr('%'))
feed('<C-O>') feed('<C-O>')
eq(buf1, funcs.bufnr('%')) eq(buf1, fn.bufnr('%'))
command('drop ' .. fname2) command('drop ' .. fname2)
feed('<C-O>') feed('<C-O>')
eq(buf1, funcs.bufnr('%')) eq(buf1, fn.bufnr('%'))
end) end)
it('<C-O> scrolls cursor halfway when switching buffer #25763', function() it('<C-O> scrolls cursor halfway when switching buffer #25763', function()
@@ -284,7 +284,7 @@ describe('jumpoptions=view', function()
screen:attach() screen:attach()
command('edit ' .. file1) command('edit ' .. file1)
feed('7GzbG') feed('7GzbG')
meths.nvim_buf_set_lines(0, 0, 2, true, {}) api.nvim_buf_set_lines(0, 0, 2, true, {})
-- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover
-- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the
-- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5. -- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5.

View File

@@ -4,7 +4,7 @@ local eq, neq, call = helpers.eq, helpers.neq, helpers.call
local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear
local command, insert, expect = helpers.command, helpers.insert, helpers.expect local command, insert, expect = helpers.command, helpers.insert, helpers.expect
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local curwin = helpers.meths.nvim_get_current_win local curwin = helpers.api.nvim_get_current_win
describe("'langmap'", function() describe("'langmap'", function()
before_each(function() before_each(function()
@@ -215,7 +215,7 @@ describe("'langmap'", function()
feed('qa' .. command_string .. 'q') feed('qa' .. command_string .. 'q')
expect(expect_string) expect(expect_string)
eq( eq(
expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), expect_macro or helpers.fn.nvim_replace_termcodes(command_string, true, true, true),
eval('@a') eval('@a')
) )
if setup_function then if setup_function then

View File

@@ -6,8 +6,8 @@ local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local expect = helpers.expect local expect = helpers.expect
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local insert = helpers.insert local insert = helpers.insert
describe('macros', function() describe('macros', function()
@@ -40,18 +40,18 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[G3Q]] feed [[G3Q]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[ggV3jQ]] feed [[ggV3jQ]]
eq( eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false) api.nvim_buf_get_lines(0, 0, -1, false)
) )
end) end)
@@ -62,18 +62,18 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[G3@@]] feed [[G3@@]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[ggV2j@@]] feed [[ggV2j@@]]
eq( eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false) api.nvim_buf_get_lines(0, 0, -1, false)
) )
end) end)
@@ -84,17 +84,17 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[V3j@q]] feed [[V3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[gg]] feed [[gg]]
feed [[Vj@w]] feed [[Vj@w]]
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can be replayed with @q and @w visual-block', function() it('can be replayed with @q and @w visual-block', function()
@@ -104,17 +104,17 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[<C-v>3j@q]] feed [[<C-v>3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
feed [[gg]] feed [[gg]]
feed [[<C-v>j@w]] feed [[<C-v>j@w]]
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false)) eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false))
end) end)
end) end)
@@ -127,13 +127,13 @@ describe('immediately after a macro has finished executing,', function()
describe('reg_executing() from RPC returns an empty string', function() describe('reg_executing() from RPC returns an empty string', function()
it('if the macro does not end with a <Nop> mapping', function() it('if the macro does not end with a <Nop> mapping', function()
feed('@a') feed('@a')
eq('', funcs.reg_executing()) eq('', fn.reg_executing())
end) end)
it('if the macro ends with a <Nop> mapping', function() it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>') command('nnoremap 0 <Nop>')
feed('@a') feed('@a')
eq('', funcs.reg_executing()) eq('', fn.reg_executing())
end) end)
end) end)
@@ -144,7 +144,7 @@ describe('immediately after a macro has finished executing,', function()
it('if the macro does not end with a <Nop> mapping', function() it('if the macro does not end with a <Nop> mapping', function()
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
expect('') expect('')
eq('', eval('@a')) eq('', eval('@a'))
end) end)
@@ -152,7 +152,7 @@ describe('immediately after a macro has finished executing,', function()
it('if the macro ends with a <Nop> mapping', function() it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>') command('nnoremap 0 <Nop>')
feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
expect('') expect('')
eq('', eval('@a')) eq('', eval('@a'))
end) end)

View File

@@ -1,15 +1,15 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local meths = helpers.meths local api = helpers.api
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local eq = helpers.eq local eq = helpers.eq
local feed = helpers.feed local feed = helpers.feed
local write_file = helpers.write_file local write_file = helpers.write_file
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local cursor = function() local cursor = function()
return helpers.meths.nvim_win_get_cursor(0) return helpers.api.nvim_win_get_cursor(0)
end end
describe('named marks', function() describe('named marks', function()
@@ -28,13 +28,13 @@ describe('named marks', function()
it('can be set', function() it('can be set', function()
command('edit ' .. file1) command('edit ' .. file1)
command('mark a') command('mark a')
eq({ 1, 0 }, meths.nvim_buf_get_mark(0, 'a')) eq({ 1, 0 }, api.nvim_buf_get_mark(0, 'a'))
feed('jmb') feed('jmb')
eq({ 2, 0 }, meths.nvim_buf_get_mark(0, 'b')) eq({ 2, 0 }, api.nvim_buf_get_mark(0, 'b'))
feed('jmB') feed('jmB')
eq({ 3, 0 }, meths.nvim_buf_get_mark(0, 'B')) eq({ 3, 0 }, api.nvim_buf_get_mark(0, 'B'))
command('4kc') command('4kc')
eq({ 4, 0 }, meths.nvim_buf_get_mark(0, 'c')) eq({ 4, 0 }, api.nvim_buf_get_mark(0, 'c'))
end) end)
it('errors when set out of range with :mark', function() it('errors when set out of range with :mark', function()
@@ -104,7 +104,7 @@ describe('named marks', function()
feed('mA') feed('mA')
command('next') command('next')
feed("'A") feed("'A")
eq(1, meths.nvim_get_current_buf().id) eq(1, api.nvim_get_current_buf().id)
eq({ 2, 0 }, cursor()) eq({ 2, 0 }, cursor())
end) end)
@@ -117,7 +117,7 @@ describe('named marks', function()
feed('mA') feed('mA')
command('next') command('next')
feed('`A') feed('`A')
eq(1, meths.nvim_get_current_buf().id) eq(1, api.nvim_get_current_buf().id)
eq({ 2, 2 }, cursor()) eq({ 2, 2 }, cursor())
end) end)
@@ -130,7 +130,7 @@ describe('named marks', function()
feed('mA') feed('mA')
command('next') command('next')
feed("g'A") feed("g'A")
eq(1, meths.nvim_get_current_buf().id) eq(1, api.nvim_get_current_buf().id)
eq({ 2, 0 }, cursor()) eq({ 2, 0 }, cursor())
end) end)
@@ -143,7 +143,7 @@ describe('named marks', function()
feed('mA') feed('mA')
command('next') command('next')
feed('g`A') feed('g`A')
eq(1, meths.nvim_get_current_buf().id) eq(1, api.nvim_get_current_buf().id)
eq({ 2, 2 }, cursor()) eq({ 2, 2 }, cursor())
end) end)
@@ -157,7 +157,7 @@ describe('named marks', function()
feed('mA') feed('mA')
command('next') command('next')
command("'A") command("'A")
eq(1, meths.nvim_get_current_buf().id) eq(1, api.nvim_get_current_buf().id)
eq({ 2, 0 }, cursor()) eq({ 2, 0 }, cursor())
end) end)
@@ -267,59 +267,59 @@ describe('named marks', function()
feed('jzfG') -- Fold from the second line to the end feed('jzfG') -- Fold from the second line to the end
command('3mark a') command('3mark a')
feed('G') -- On top of the fold feed('G') -- On top of the fold
assert(funcs.foldclosed('.') ~= -1) -- folded assert(fn.foldclosed('.') ~= -1) -- folded
feed("'a") feed("'a")
eq(-1, funcs.foldclosed('.')) eq(-1, fn.foldclosed('.'))
feed('zc') feed('zc')
assert(funcs.foldclosed('.') ~= -1) -- folded assert(fn.foldclosed('.') ~= -1) -- folded
-- TODO: remove this workaround after fixing #15873 -- TODO: remove this workaround after fixing #15873
feed('k`a') feed('k`a')
eq(-1, funcs.foldclosed('.')) eq(-1, fn.foldclosed('.'))
feed('zc') feed('zc')
assert(funcs.foldclosed('.') ~= -1) -- folded assert(fn.foldclosed('.') ~= -1) -- folded
feed("kg'a") feed("kg'a")
eq(-1, funcs.foldclosed('.')) eq(-1, fn.foldclosed('.'))
feed('zc') feed('zc')
assert(funcs.foldclosed('.') ~= -1) -- folded assert(fn.foldclosed('.') ~= -1) -- folded
feed('kg`a') feed('kg`a')
eq(-1, funcs.foldclosed('.')) eq(-1, fn.foldclosed('.'))
end) end)
it("do not open folds when moving to them doesn't move the cursor", function() it("do not open folds when moving to them doesn't move the cursor", function()
command('edit ' .. file1) command('edit ' .. file1)
feed('jzfG') -- Fold from the second line to the end feed('jzfG') -- Fold from the second line to the end
assert(funcs.foldclosed('.') == 2) -- folded assert(fn.foldclosed('.') == 2) -- folded
feed('ma') feed('ma')
feed("'a") feed("'a")
feed('`a') feed('`a')
feed("g'a") feed("g'a")
feed('g`a') feed('g`a')
-- should still be folded -- should still be folded
eq(2, funcs.foldclosed('.')) eq(2, fn.foldclosed('.'))
end) end)
it("getting '{ '} '( ') does not move cursor", function() it("getting '{ '} '( ') does not move cursor", function()
meths.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) api.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' })
meths.nvim_win_set_cursor(0, { 2, 0 }) api.nvim_win_set_cursor(0, { 2, 0 })
funcs.getpos("'{") fn.getpos("'{")
eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) eq({ 2, 0 }, api.nvim_win_get_cursor(0))
funcs.getpos("'}") fn.getpos("'}")
eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) eq({ 2, 0 }, api.nvim_win_get_cursor(0))
funcs.getpos("'(") fn.getpos("'(")
eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) eq({ 2, 0 }, api.nvim_win_get_cursor(0))
funcs.getpos("')") fn.getpos("')")
eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) eq({ 2, 0 }, api.nvim_win_get_cursor(0))
end) end)
it('in command range does not move cursor #19248', function() it('in command range does not move cursor #19248', function()
meths.nvim_create_user_command('Test', ':', { range = true }) api.nvim_create_user_command('Test', ':', { range = true })
meths.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) api.nvim_buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' })
meths.nvim_win_set_cursor(0, { 2, 0 }) api.nvim_win_set_cursor(0, { 2, 0 })
command([['{,'}Test]]) command([['{,'}Test]])
eq({ 2, 0 }, meths.nvim_win_get_cursor(0)) eq({ 2, 0 }, api.nvim_win_get_cursor(0))
end) end)
end) end)

View File

@@ -4,7 +4,7 @@ local command = helpers.command
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local eval = helpers.eval local eval = helpers.eval
local expect = helpers.expect local expect = helpers.expect
local funcs = helpers.funcs local fn = helpers.fn
local eq = helpers.eq local eq = helpers.eq
describe('meta-keys #8226 #13042', function() describe('meta-keys #8226 #13042', function()
@@ -66,11 +66,11 @@ describe('meta-keys #8226 #13042', function()
command('inoremap <A-j> alt-j') command('inoremap <A-j> alt-j')
feed('i<M-l> xxx <A-j><M-h>a<A-h>') feed('i<M-l> xxx <A-j><M-h>a<A-h>')
expect('meta-l xxx alt-j') expect('meta-l xxx alt-j')
eq({ 0, 1, 14, 0 }, funcs.getpos('.')) eq({ 0, 1, 14, 0 }, fn.getpos('.'))
-- Unmapped ALT-chord behaves as ESC+c. -- Unmapped ALT-chord behaves as ESC+c.
command('iunmap <M-l>') command('iunmap <M-l>')
feed('0i<M-l>') feed('0i<M-l>')
eq({ 0, 1, 2, 0 }, funcs.getpos('.')) eq({ 0, 1, 2, 0 }, fn.getpos('.'))
-- Unmapped ALT-chord has same `undo` characteristics as ESC+<key> -- Unmapped ALT-chord has same `undo` characteristics as ESC+<key>
command('0,$d') command('0,$d')
feed('ahello<M-.>') feed('ahello<M-.>')
@@ -101,7 +101,7 @@ describe('meta-keys #8226 #13042', function()
eq(meta_l_seq .. 'yyy' .. meta_l_seq .. 'alt-j', exec_lua([[return _G.input_data]])) eq(meta_l_seq .. 'yyy' .. meta_l_seq .. 'alt-j', exec_lua([[return _G.input_data]]))
eq('t', eval('mode(1)')) eq('t', eval('mode(1)'))
feed('<Esc>j') feed('<Esc>j')
eq({ 0, 2, 1, 0 }, funcs.getpos('.')) eq({ 0, 2, 1, 0 }, fn.getpos('.'))
eq('nt', eval('mode(1)')) eq('nt', eval('mode(1)'))
end) end)

View File

@@ -2,11 +2,11 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear, insert, funcs, eq, feed = local clear, insert, fn, eq, feed =
helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed helpers.clear, helpers.insert, helpers.fn, helpers.eq, helpers.feed
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local meths = helpers.meths local api = helpers.api
describe('cmdline', function() describe('cmdline', function()
before_each(clear) before_each(clear)
@@ -20,22 +20,22 @@ describe('cmdline', function()
-- Yank 2 lines linewise, then paste to cmdline. -- Yank 2 lines linewise, then paste to cmdline.
feed([[<C-\><C-N>gg0yj:<C-R>0]]) feed([[<C-\><C-N>gg0yj:<C-R>0]])
-- <CR> inserted between lines, NOT after the final line. -- <CR> inserted between lines, NOT after the final line.
eq('line1abc\rline2somemoretext', funcs.getcmdline()) eq('line1abc\rline2somemoretext', fn.getcmdline())
-- Yank 2 lines charwise, then paste to cmdline. -- Yank 2 lines charwise, then paste to cmdline.
feed([[<C-\><C-N>gg05lyvj:<C-R>0]]) feed([[<C-\><C-N>gg05lyvj:<C-R>0]])
-- <CR> inserted between lines, NOT after the final line. -- <CR> inserted between lines, NOT after the final line.
eq('abc\rline2', funcs.getcmdline()) eq('abc\rline2', fn.getcmdline())
-- Yank 1 line linewise, then paste to cmdline. -- Yank 1 line linewise, then paste to cmdline.
feed([[<C-\><C-N>ggyy:<C-R>0]]) feed([[<C-\><C-N>ggyy:<C-R>0]])
-- No <CR> inserted. -- No <CR> inserted.
eq('line1abc', funcs.getcmdline()) eq('line1abc', fn.getcmdline())
end) end)
it('pasting special register inserts <CR>, <NL>', function() it('pasting special register inserts <CR>, <NL>', function()
feed([[:<C-R>="foo\nbar\rbaz"<CR>]]) feed([[:<C-R>="foo\nbar\rbaz"<CR>]])
eq('foo\nbar\rbaz', funcs.getcmdline()) eq('foo\nbar\rbaz', fn.getcmdline())
end) end)
end) end)
@@ -77,30 +77,30 @@ describe('cmdline', function()
it('correctly clears start of the history', function() it('correctly clears start of the history', function()
-- Regression test: check absence of the memory leak when clearing start of -- Regression test: check absence of the memory leak when clearing start of
-- the history using cmdhist.c/clr_history(). -- the history using cmdhist.c/clr_history().
eq(1, funcs.histadd(':', 'foo')) eq(1, fn.histadd(':', 'foo'))
eq(1, funcs.histdel(':')) eq(1, fn.histdel(':'))
eq('', funcs.histget(':', -1)) eq('', fn.histget(':', -1))
end) end)
it('correctly clears end of the history', function() it('correctly clears end of the history', function()
-- Regression test: check absence of the memory leak when clearing end of -- Regression test: check absence of the memory leak when clearing end of
-- the history using cmdhist.c/clr_history(). -- the history using cmdhist.c/clr_history().
meths.nvim_set_option_value('history', 1, {}) api.nvim_set_option_value('history', 1, {})
eq(1, funcs.histadd(':', 'foo')) eq(1, fn.histadd(':', 'foo'))
eq(1, funcs.histdel(':')) eq(1, fn.histdel(':'))
eq('', funcs.histget(':', -1)) eq('', fn.histget(':', -1))
end) end)
it('correctly removes item from history', function() it('correctly removes item from history', function()
-- Regression test: check that cmdhist.c/del_history_idx() correctly clears -- Regression test: check that cmdhist.c/del_history_idx() correctly clears
-- history index after removing history entry. If it does not then deleting -- history index after removing history entry. If it does not then deleting
-- history will result in a double free. -- history will result in a double free.
eq(1, funcs.histadd(':', 'foo')) eq(1, fn.histadd(':', 'foo'))
eq(1, funcs.histadd(':', 'bar')) eq(1, fn.histadd(':', 'bar'))
eq(1, funcs.histadd(':', 'baz')) eq(1, fn.histadd(':', 'baz'))
eq(1, funcs.histdel(':', -2)) eq(1, fn.histdel(':', -2))
eq(1, funcs.histdel(':')) eq(1, fn.histdel(':'))
eq('', funcs.histget(':', -1)) eq('', fn.histget(':', -1))
end) end)
end) end)
end) end)

View File

@@ -11,7 +11,7 @@ local filter = vim.tbl_filter
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local command = helpers.command local command = helpers.command
local curbuf_contents = helpers.curbuf_contents local curbuf_contents = helpers.curbuf_contents
local funcs = helpers.funcs local fn = helpers.fn
local dedent = helpers.dedent local dedent = helpers.dedent
local function reset() local function reset()
@@ -21,9 +21,9 @@ local function reset()
Line of words 2]]) Line of words 2]])
command('goto 1') command('goto 1')
feed('itest_string.<esc>u') feed('itest_string.<esc>u')
funcs.setreg('a', 'test_stringa', 'V') fn.setreg('a', 'test_stringa', 'V')
funcs.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b') fn.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b')
funcs.setreg('"', 'test_string"', 'v') fn.setreg('"', 'test_string"', 'v')
end end
-- We check the last inserted register ". in each of these tests because it is -- We check the last inserted register ". in each of these tests because it is
@@ -35,12 +35,12 @@ describe('put command', function()
before_each(reset) before_each(reset)
local function visual_marks_zero() local function visual_marks_zero()
for _, v in pairs(funcs.getpos("'<")) do for _, v in pairs(fn.getpos("'<")) do
if v ~= 0 then if v ~= 0 then
return false return false
end end
end end
for _, v in pairs(funcs.getpos("'>")) do for _, v in pairs(fn.getpos("'>")) do
if v ~= 0 then if v ~= 0 then
return false return false
end end
@@ -55,7 +55,7 @@ describe('put command', function()
extra_setup() extra_setup()
end end
local init_contents = curbuf_contents() local init_contents = curbuf_contents()
local init_cursorpos = funcs.getcurpos() local init_cursorpos = fn.getcurpos()
local assert_no_change = function(exception_table, after_undo) local assert_no_change = function(exception_table, after_undo)
expect(init_contents) expect(init_contents)
-- When putting the ". register forwards, undo doesn't move -- When putting the ". register forwards, undo doesn't move
@@ -65,7 +65,7 @@ describe('put command', function()
-- one place to the right (unless we were at the end of the -- one place to the right (unless we were at the end of the
-- line when we pasted). -- line when we pasted).
if not (exception_table.undo_position and after_undo) then if not (exception_table.undo_position and after_undo) then
eq(init_cursorpos, funcs.getcurpos()) eq(init_cursorpos, fn.getcurpos())
end end
end end
@@ -74,7 +74,7 @@ describe('put command', function()
if extra_setup then if extra_setup then
extra_setup() extra_setup()
end end
local orig_dotstr = funcs.getreg('.') local orig_dotstr = fn.getreg('.')
helpers.ok(visual_marks_zero()) helpers.ok(visual_marks_zero())
-- Make sure every test starts from the same conditions -- Make sure every test starts from the same conditions
assert_no_change(test.exception_table, false) assert_no_change(test.exception_table, false)
@@ -89,7 +89,7 @@ describe('put command', function()
-- If we paste the ". register with a count we can't avoid -- If we paste the ". register with a count we can't avoid
-- changing this register, hence avoid this check. -- changing this register, hence avoid this check.
if not test.exception_table.dot_reg_changed then if not test.exception_table.dot_reg_changed then
eq(orig_dotstr, funcs.getreg('.')) eq(orig_dotstr, fn.getreg('.'))
end end
-- Doing something, undoing it, and then redoing it should -- Doing something, undoing it, and then redoing it should
@@ -105,7 +105,7 @@ describe('put command', function()
end end
if test.exception_table.undo_position then if test.exception_table.undo_position then
funcs.setpos('.', init_cursorpos) fn.setpos('.', init_cursorpos)
end end
if was_cli then if was_cli then
feed('@:') feed('@:')
@@ -151,7 +151,7 @@ describe('put command', function()
-- it was in. -- it was in.
-- This returns the cursor position that would leave the 'x' in that -- This returns the cursor position that would leave the 'x' in that
-- place if we feed 'ix<esc>' and the string existed before it. -- place if we feed 'ix<esc>' and the string existed before it.
for linenum, line in pairs(funcs.split(expect_string, '\n', 1)) do for linenum, line in pairs(fn.split(expect_string, '\n', 1)) do
local column = line:find('x') local column = line:find('x')
if column then if column then
return { linenum, column }, expect_string:gsub('x', '') return { linenum, column }, expect_string:gsub('x', '')
@@ -184,16 +184,16 @@ describe('put command', function()
return function(exception_table, after_redo) return function(exception_table, after_redo)
expect(expect_string) expect(expect_string)
-- Have to use getcurpos() instead of meths.nvim_win_get_cursor(0) in -- Have to use getcurpos() instead of api.nvim_win_get_cursor(0) in
-- order to account for virtualedit. -- order to account for virtualedit.
-- We always want the curswant element in getcurpos(), which is -- We always want the curswant element in getcurpos(), which is
-- sometimes different to the column element in -- sometimes different to the column element in
-- meths.nvim_win_get_cursor(0). -- api.nvim_win_get_cursor(0).
-- NOTE: The ".gp command leaves the cursor after the pasted text -- NOTE: The ".gp command leaves the cursor after the pasted text
-- when running, but does not when the command is redone with the -- when running, but does not when the command is redone with the
-- '.' command. -- '.' command.
if not (exception_table.redo_position and after_redo) then if not (exception_table.redo_position and after_redo) then
local actual_position = funcs.getcurpos() local actual_position = fn.getcurpos()
eq(cursor_position, { actual_position[2], actual_position[5] }) eq(cursor_position, { actual_position[2], actual_position[5] })
end end
end end
@@ -349,7 +349,7 @@ describe('put command', function()
local prev_line local prev_line
local rettab = {} local rettab = {}
local string_found = false local string_found = false
for _, line in pairs(funcs.split(string, '\n', 1)) do for _, line in pairs(fn.split(string, '\n', 1)) do
if line:find('test_string') then if line:find('test_string') then
string_found = true string_found = true
table.insert(rettab, line) table.insert(rettab, line)
@@ -476,7 +476,7 @@ describe('put command', function()
local prev_line local prev_line
local rettab = {} local rettab = {}
local prev_in_block = false local prev_in_block = false
for _, line in pairs(funcs.split(expect_base, '\n', 1)) do for _, line in pairs(fn.split(expect_base, '\n', 1)) do
if line:find('test_string') then if line:find('test_string') then
if prev_line then if prev_line then
prev_line = prev_line:gsub('x', '') prev_line = prev_line:gsub('x', '')
@@ -524,10 +524,10 @@ describe('put command', function()
test_expect(exception_table, after_redo) test_expect(exception_table, after_redo)
if selection_string then if selection_string then
if not conversion_table.put_backwards then if not conversion_table.put_backwards then
eq(selection_string, funcs.getreg('"')) eq(selection_string, fn.getreg('"'))
end end
else else
eq('test_string"', funcs.getreg('"')) eq('test_string"', fn.getreg('"'))
end end
end end
end end
@@ -657,10 +657,10 @@ describe('put command', function()
xtest_string"]], xtest_string"]],
'put', 'put',
function() function()
funcs.setline('$', ' Line of words 2') fn.setline('$', ' Line of words 2')
-- Set curswant to '8' to be at the end of the tab character -- Set curswant to '8' to be at the end of the tab character
-- This is where the cursor is put back after the 'u' command. -- This is where the cursor is put back after the 'u' command.
funcs.setpos('.', { 0, 2, 1, 0, 8 }) fn.setpos('.', { 0, 2, 1, 0, 8 })
command('set autoindent') command('set autoindent')
end end
) )
@@ -671,9 +671,9 @@ describe('put command', function()
Line of words 1 Line of words 1
test_stringx" Line of words 2]] test_stringx" Line of words 2]]
run_normal_mode_tests(test_string, 'p', function() run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2') fn.setline('$', ' Line of words 2')
command('setlocal virtualedit=all') command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 2, 1, 2, 3 }) fn.setpos('.', { 0, 2, 1, 2, 3 })
end) end)
end) end)
@@ -683,9 +683,9 @@ describe('put command', function()
Line of words 1 test_stringx" Line of words 1 test_stringx"
Line of words 2]] Line of words 2]]
run_normal_mode_tests(test_string, 'p', function() run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2') fn.setline('$', ' Line of words 2')
command('setlocal virtualedit=all') command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 1, 16, 1, 17 }) fn.setpos('.', { 0, 1, 16, 1, 17 })
end, true) end, true)
end) end)
@@ -699,7 +699,7 @@ describe('put command', function()
describe('over trailing newline', function() describe('over trailing newline', function()
local test_string = 'Line of test_stringx"Line of words 2' local test_string = 'Line of test_stringx"Line of words 2'
run_normal_mode_tests(test_string, 'v$p', function() run_normal_mode_tests(test_string, 'v$p', function()
funcs.setpos('.', { 0, 1, 9, 0, 9 }) fn.setpos('.', { 0, 1, 9, 0, 9 })
end, nil, 'words 1\n') end, nil, 'words 1\n')
end) end)
describe('linewise mode', function() describe('linewise mode', function()
@@ -720,7 +720,7 @@ describe('put command', function()
expect_vis_linewise expect_vis_linewise
), ),
function() function()
funcs.setpos('.', { 0, 1, 1, 0, 1 }) fn.setpos('.', { 0, 1, 1, 0, 1 })
end end
) )
@@ -732,7 +732,7 @@ describe('put command', function()
return function(exception_table, after_redo) return function(exception_table, after_redo)
test_expect(exception_table, after_redo) test_expect(exception_table, after_redo)
if not conversion_table.put_backwards then if not conversion_table.put_backwards then
eq('Line of words 1\n', funcs.getreg('"')) eq('Line of words 1\n', fn.getreg('"'))
end end
end end
end end
@@ -749,7 +749,7 @@ describe('put command', function()
), ),
function() function()
feed('i test_string.<esc>u') feed('i test_string.<esc>u')
funcs.setreg('"', ' test_string"', 'v') fn.setreg('"', ' test_string"', 'v')
end end
) )
end) end)
@@ -767,7 +767,7 @@ describe('put command', function()
return function(e, c) return function(e, c)
test_expect(e, c) test_expect(e, c)
if not conversion_table.put_backwards then if not conversion_table.put_backwards then
eq('Lin\nLin', funcs.getreg('"')) eq('Lin\nLin', fn.getreg('"'))
end end
end end
end end
@@ -804,7 +804,7 @@ describe('put command', function()
expect_block_creator expect_block_creator
), ),
function() function()
funcs.setpos('.', { 0, 2, 1, 0, 1 }) fn.setpos('.', { 0, 2, 1, 0, 1 })
end end
) )
@@ -820,16 +820,16 @@ describe('put command', function()
feed('u') feed('u')
-- Have to use feed('u') here to set curswant, because -- Have to use feed('u') here to set curswant, because
-- ex_undo() doesn't do that. -- ex_undo() doesn't do that.
eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) eq({ 0, 1, 1, 0, 1 }, fn.getcurpos())
feed('<C-r>') feed('<C-r>')
eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) eq({ 0, 1, 1, 0, 1 }, fn.getcurpos())
end end
end end
run_test_variations( run_test_variations(
create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator), create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator),
function() function()
funcs.setpos('.', { 0, 2, 1, 0, 1 }) fn.setpos('.', { 0, 2, 1, 0, 1 })
end end
) )
end) end)
@@ -841,9 +841,9 @@ describe('put command', function()
Line of words 1 Line of words 1
test_stringx" Line of words 2]] test_stringx" Line of words 2]]
run_normal_mode_tests(base_expect_string, 'vp', function() run_normal_mode_tests(base_expect_string, 'vp', function()
funcs.setline('$', ' Line of words 2') fn.setline('$', ' Line of words 2')
command('setlocal virtualedit=all') command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 2, 1, 2, 3 }) fn.setpos('.', { 0, 2, 1, 2, 3 })
end, nil, ' ') end, nil, ' ')
end) end)
describe('after end of line', function() describe('after end of line', function()
@@ -852,7 +852,7 @@ describe('put command', function()
Line of words 2]] Line of words 2]]
run_normal_mode_tests(base_expect_string, 'vp', function() run_normal_mode_tests(base_expect_string, 'vp', function()
command('setlocal virtualedit=all') command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 1, 16, 2, 18 }) fn.setpos('.', { 0, 1, 16, 2, 18 })
end, true, ' ') end, true, ' ')
end) end)
end) end)
@@ -917,14 +917,14 @@ describe('put command', function()
-- Even if the last character is a multibyte character. -- Even if the last character is a multibyte character.
reset() reset()
funcs.setline(1, 'helloม') fn.setline(1, 'helloม')
bell_test(function() bell_test(function()
feed('$".gp') feed('$".gp')
end) end)
end) end)
it('should not ring the bell with gp and end of file', function() it('should not ring the bell with gp and end of file', function()
funcs.setpos('.', { 0, 2, 1, 0 }) fn.setpos('.', { 0, 2, 1, 0 })
bell_test(function() bell_test(function()
feed('$vl".gp') feed('$vl".gp')
end) end)
@@ -942,9 +942,9 @@ describe('put command', function()
end) end)
it('should restore cursor position after undo of ".p', function() it('should restore cursor position after undo of ".p', function()
local origpos = funcs.getcurpos() local origpos = fn.getcurpos()
feed('".pu') feed('".pu')
eq(origpos, funcs.getcurpos()) eq(origpos, fn.getcurpos())
end) end)
it("should be unaffected by 'autoindent' with V\".2p", function() it("should be unaffected by 'autoindent' with V\".2p", function()

View File

@@ -8,9 +8,9 @@ local neq = helpers.neq
local feed = helpers.feed local feed = helpers.feed
local eval = helpers.eval local eval = helpers.eval
local exec = helpers.exec local exec = helpers.exec
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local curwin = helpers.meths.nvim_get_current_win local curwin = helpers.api.nvim_get_current_win
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
describe('tabpage', function() describe('tabpage', function()
@@ -74,29 +74,29 @@ describe('tabpage', function()
end) end)
it('nvim_win_close and nvim_win_hide update tabline #20285', function() it('nvim_win_close and nvim_win_hide update tabline #20285', function()
eq(1, #meths.nvim_list_tabpages()) eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0)) eq({ 1, 1 }, fn.win_screenpos(0))
local win1 = curwin().id local win1 = curwin().id
command('tabnew') command('tabnew')
eq(2, #meths.nvim_list_tabpages()) eq(2, #api.nvim_list_tabpages())
eq({ 2, 1 }, funcs.win_screenpos(0)) eq({ 2, 1 }, fn.win_screenpos(0))
local win2 = curwin().id local win2 = curwin().id
meths.nvim_win_close(win1, true) api.nvim_win_close(win1, true)
eq(win2, curwin().id) eq(win2, curwin().id)
eq(1, #meths.nvim_list_tabpages()) eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0)) eq({ 1, 1 }, fn.win_screenpos(0))
command('tabnew') command('tabnew')
eq(2, #meths.nvim_list_tabpages()) eq(2, #api.nvim_list_tabpages())
eq({ 2, 1 }, funcs.win_screenpos(0)) eq({ 2, 1 }, fn.win_screenpos(0))
local win3 = curwin().id local win3 = curwin().id
meths.nvim_win_hide(win2) api.nvim_win_hide(win2)
eq(win3, curwin().id) eq(win3, curwin().id)
eq(1, #meths.nvim_list_tabpages()) eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0)) eq({ 1, 1 }, fn.win_screenpos(0))
end) end)
it('switching tabpage after setting laststatus=3 #19591', function() it('switching tabpage after setting laststatus=3 #19591', function()
@@ -135,15 +135,15 @@ describe('tabpage', function()
it(':tabmove handles modifiers and addr', function() it(':tabmove handles modifiers and addr', function()
command('tabnew | tabnew | tabnew') command('tabnew | tabnew | tabnew')
eq(4, funcs.nvim_tabpage_get_number(0)) eq(4, fn.nvim_tabpage_get_number(0))
command(' silent :keepalt :: ::: silent! - tabmove') command(' silent :keepalt :: ::: silent! - tabmove')
eq(3, funcs.nvim_tabpage_get_number(0)) eq(3, fn.nvim_tabpage_get_number(0))
command(' silent :keepalt :: ::: silent! -2 tabmove') command(' silent :keepalt :: ::: silent! -2 tabmove')
eq(1, funcs.nvim_tabpage_get_number(0)) eq(1, fn.nvim_tabpage_get_number(0))
end) end)
it(':tabs does not overflow IObuff with long path with comma #20850', function() it(':tabs does not overflow IObuff with long path with comma #20850', function()
meths.nvim_buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024)) api.nvim_buf_set_name(0, ('x'):rep(1024) .. ',' .. ('x'):rep(1024))
command('tabs') command('tabs')
assert_alive() assert_alive()
end) end)

View File

@@ -8,12 +8,12 @@ local eq = helpers.eq
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local insert = helpers.insert local insert = helpers.insert
local funcs = helpers.funcs local fn = helpers.fn
local exec = helpers.exec local exec = helpers.exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local function lastmessage() local function lastmessage()
local messages = funcs.split(funcs.execute('messages'), '\n') local messages = fn.split(fn.execute('messages'), '\n')
return messages[#messages] return messages[#messages]
end end

View File

@@ -5,20 +5,20 @@ local dedent = helpers.dedent
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local fn = helpers.fn
local command = helpers.command local command = helpers.command
local meths = helpers.meths local api = helpers.api
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local cmdtest = function(cmd, prep, ret1) local cmdtest = function(cmd, prep, ret1)
describe(':' .. cmd, function() describe(':' .. cmd, function()
before_each(function() before_each(function()
clear() clear()
meths.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' }) api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' })
end) end)
local buffer_contents = function() local buffer_contents = function()
return meths.nvim_buf_get_lines(0, 0, -1, false) return api.nvim_buf_get_lines(0, 0, -1, false)
end end
it(cmd .. 's' .. prep .. ' the current line by default', function() it(cmd .. 's' .. prep .. ' the current line by default', function()
@@ -38,15 +38,15 @@ local cmdtest = function(cmd, prep, ret1)
feed(':' .. hisline .. '<CR>') feed(':' .. hisline .. '<CR>')
feed(':' .. cmd .. '<CR>abc<CR>def<C-f>') feed(':' .. cmd .. '<CR>abc<CR>def<C-f>')
eq({ 'def' }, buffer_contents()) eq({ 'def' }, buffer_contents())
eq(hisline, funcs.histget(':', -2)) eq(hisline, fn.histget(':', -2))
eq(cmd, funcs.histget(':')) eq(cmd, fn.histget(':'))
-- Test that command-line window was launched -- Test that command-line window was launched
eq('nofile', meths.nvim_get_option_value('buftype', {})) eq('nofile', api.nvim_get_option_value('buftype', {}))
eq('n', funcs.mode(1)) eq('n', fn.mode(1))
feed('<CR>') feed('<CR>')
eq('c', funcs.mode(1)) eq('c', fn.mode(1))
feed('.<CR>') feed('.<CR>')
eq('n', funcs.mode(1)) eq('n', fn.mode(1))
eq(ret1, buffer_contents()) eq(ret1, buffer_contents())
end) end)
end) end)

View File

@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local eq, command, fn = helpers.eq, helpers.command, helpers.fn
local ok = helpers.ok local ok = helpers.ok
local clear = helpers.clear local clear = helpers.clear
@@ -13,17 +13,17 @@ describe(':argument', function()
helpers.feed([[<C-\><C-N>]]) helpers.feed([[<C-\><C-N>]])
command('argadd') command('argadd')
helpers.feed([[<C-\><C-N>]]) helpers.feed([[<C-\><C-N>]])
local bufname_before = funcs.bufname('%') local bufname_before = fn.bufname('%')
local bufnr_before = funcs.bufnr('%') local bufnr_before = fn.bufnr('%')
helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity
command('argument 1') command('argument 1')
helpers.feed([[<C-\><C-N>]]) helpers.feed([[<C-\><C-N>]])
local bufname_after = funcs.bufname('%') local bufname_after = fn.bufname('%')
local bufnr_after = funcs.bufnr('%') local bufnr_after = fn.bufnr('%')
eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))')) eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))'))
ok(funcs.line('$') > 1) ok(fn.line('$') > 1)
eq(bufname_before, bufname_after) eq(bufname_before, bufname_after)
eq(bufnr_before, bufnr_after) eq(bufnr_before, bufnr_after)
end) end)

View File

@@ -4,7 +4,7 @@ local feed = helpers.feed
local eq = helpers.eq local eq = helpers.eq
local expect = helpers.expect local expect = helpers.expect
local eval = helpers.eval local eval = helpers.eval
local funcs = helpers.funcs local fn = helpers.fn
local insert = helpers.insert local insert = helpers.insert
local write_file = helpers.write_file local write_file = helpers.write_file
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
@@ -329,12 +329,12 @@ describe('mappings with <Cmd>', function()
{1:~ }|*5 {1:~ }|*5
{4:-- VISUAL --} | {4:-- VISUAL --} |
]]) ]])
eq('v', funcs.mode(1)) eq('v', fn.mode(1))
-- can invoke operator, ending visual mode -- can invoke operator, ending visual mode
feed('<F5>') feed('<F5>')
eq('n', funcs.mode(1)) eq('n', fn.mode(1))
eq({ 'some short l' }, funcs.getreg('a', 1, 1)) eq({ 'some short l' }, fn.getreg('a', 1, 1))
-- error doesn't interrupt visual mode -- error doesn't interrupt visual mode
feed('ggvw<F6>') feed('ggvw<F6>')
@@ -356,7 +356,7 @@ describe('mappings with <Cmd>', function()
{1:~ }|*5 {1:~ }|*5
{4:-- VISUAL --} | {4:-- VISUAL --} |
]]) ]])
eq('v', funcs.mode(1)) eq('v', fn.mode(1))
feed('<F7>') feed('<F7>')
screen:expect([[ screen:expect([[
so{5:me short lines} | so{5:me short lines} |
@@ -364,7 +364,7 @@ describe('mappings with <Cmd>', function()
{1:~ }|*5 {1:~ }|*5
{4:-- VISUAL --} | {4:-- VISUAL --} |
]]) ]])
eq('v', funcs.mode(1)) eq('v', fn.mode(1))
-- startinsert gives "-- (insert) VISUAL --" mode -- startinsert gives "-- (insert) VISUAL --" mode
feed('<F8>') feed('<F8>')
@@ -390,17 +390,17 @@ describe('mappings with <Cmd>', function()
{1:~ }|*5 {1:~ }|*5
{4:-- SELECT --} | {4:-- SELECT --} |
]]) ]])
eq('s', funcs.mode(1)) eq('s', fn.mode(1))
-- visual mapping in select mode restart select mode after operator -- visual mapping in select mode restart select mode after operator
feed('<F5>') feed('<F5>')
eq('s', funcs.mode(1)) eq('s', fn.mode(1))
eq({ 'some short l' }, funcs.getreg('a', 1, 1)) eq({ 'some short l' }, fn.getreg('a', 1, 1))
-- select mode mapping works, and does not restart select mode -- select mode mapping works, and does not restart select mode
feed('<F2>') feed('<F2>')
eq('n', funcs.mode(1)) eq('n', fn.mode(1))
eq({ 'some short l' }, funcs.getreg('b', 1, 1)) eq({ 'some short l' }, fn.getreg('b', 1, 1))
-- error doesn't interrupt temporary visual mode -- error doesn't interrupt temporary visual mode
feed('<esc>ggvw<c-g><F6>') feed('<esc>ggvw<c-g><F6>')
@@ -423,7 +423,7 @@ describe('mappings with <Cmd>', function()
{4:-- VISUAL --} | {4:-- VISUAL --} |
]]) ]])
-- quirk: restoration of select mode is not performed -- quirk: restoration of select mode is not performed
eq('v', funcs.mode(1)) eq('v', fn.mode(1))
-- error doesn't interrupt select mode -- error doesn't interrupt select mode
feed('<esc>ggvw<c-g><F1>') feed('<esc>ggvw<c-g><F1>')
@@ -446,7 +446,7 @@ describe('mappings with <Cmd>', function()
{4:-- SELECT --} | {4:-- SELECT --} |
]]) ]])
-- quirk: restoration of select mode is not performed -- quirk: restoration of select mode is not performed
eq('s', funcs.mode(1)) eq('s', fn.mode(1))
feed('<F7>') feed('<F7>')
screen:expect([[ screen:expect([[
@@ -455,7 +455,7 @@ describe('mappings with <Cmd>', function()
{1:~ }|*5 {1:~ }|*5
{4:-- SELECT --} | {4:-- SELECT --} |
]]) ]])
eq('s', funcs.mode(1)) eq('s', fn.mode(1))
-- startinsert gives "-- SELECT (insert) --" mode -- startinsert gives "-- SELECT (insert) --" mode
feed('<F8>') feed('<F8>')
@@ -475,11 +475,11 @@ describe('mappings with <Cmd>', function()
expect([[ expect([[
lines lines
of test text]]) of test text]])
eq({ 'some short ' }, funcs.getreg('"', 1, 1)) eq({ 'some short ' }, fn.getreg('"', 1, 1))
feed('.') feed('.')
expect([[ expect([[
test text]]) test text]])
eq({ 'lines', 'of ' }, funcs.getreg('"', 1, 1)) eq({ 'lines', 'of ' }, fn.getreg('"', 1, 1))
feed('uu') feed('uu')
expect([[ expect([[
some short lines some short lines
@@ -505,7 +505,7 @@ describe('mappings with <Cmd>', function()
feed('"bd<F7>') feed('"bd<F7>')
expect([[ expect([[
soest text]]) soest text]])
eq(funcs.getreg('b', 1, 1), { 'me short lines', 'of t' }) eq(fn.getreg('b', 1, 1), { 'me short lines', 'of t' })
-- startinsert aborts operator -- startinsert aborts operator
feed('d<F8>') feed('d<F8>')
@@ -561,7 +561,7 @@ describe('mappings with <Cmd>', function()
of stuff test text]]) of stuff test text]])
feed('<F5>') feed('<F5>')
eq(funcs.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' }) eq(fn.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' })
-- still in insert -- still in insert
screen:expect([[ screen:expect([[

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local clear, source = helpers.clear, helpers.source local clear, source = helpers.clear, helpers.source
local meths = helpers.meths local api = helpers.api
local insert = helpers.insert local insert = helpers.insert
local eq, next_msg = helpers.eq, helpers.next_msg local eq, next_msg = helpers.eq, helpers.next_msg
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
@@ -14,8 +14,8 @@ describe('Vimscript dictionary notifications', function()
before_each(function() before_each(function()
clear() clear()
channel = meths.nvim_get_api_info()[1] channel = api.nvim_get_api_info()[1]
meths.nvim_set_var('channel', channel) api.nvim_set_var('channel', channel)
end) end)
-- the same set of tests are applied to top-level dictionaries(g:, b:, w: and -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and

View File

@@ -4,8 +4,8 @@ local eq = helpers.eq
local NIL = vim.NIL local NIL = vim.NIL
local eval = helpers.eval local eval = helpers.eval
local clear = helpers.clear local clear = helpers.clear
local meths = helpers.meths local api = helpers.api
local funcs = helpers.funcs local fn = helpers.fn
local source = helpers.source local source = helpers.source
local dedent = helpers.dedent local dedent = helpers.dedent
local command = helpers.command local command = helpers.command
@@ -17,12 +17,12 @@ describe(':echo :echon :echomsg :echoerr', function()
local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' } local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' }
local function assert_same_echo_dump(expected, input, use_eval) local function assert_same_echo_dump(expected, input, use_eval)
for _, v in pairs(fn_tbl) do for _, v in pairs(fn_tbl) do
eq(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) eq(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input))
end end
end end
local function assert_matches_echo_dump(expected, input, use_eval) local function assert_matches_echo_dump(expected, input, use_eval)
for _, v in pairs(fn_tbl) do for _, v in pairs(fn_tbl) do
matches(expected, use_eval and eval(v .. '(' .. input .. ')') or funcs[v](input)) matches(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input))
end end
end end
@@ -68,21 +68,21 @@ describe(':echo :echon :echomsg :echoerr', function()
eq('v:true', eval('String(v:true)')) eq('v:true', eval('String(v:true)'))
eq('v:false', eval('String(v:false)')) eq('v:false', eval('String(v:false)'))
eq('v:null', eval('String(v:null)')) eq('v:null', eval('String(v:null)'))
eq('v:true', funcs.String(true)) eq('v:true', fn.String(true))
eq('v:false', funcs.String(false)) eq('v:false', fn.String(false))
eq('v:null', funcs.String(NIL)) eq('v:null', fn.String(NIL))
eq('v:true', eval('StringMsg(v:true)')) eq('v:true', eval('StringMsg(v:true)'))
eq('v:false', eval('StringMsg(v:false)')) eq('v:false', eval('StringMsg(v:false)'))
eq('v:null', eval('StringMsg(v:null)')) eq('v:null', eval('StringMsg(v:null)'))
eq('v:true', funcs.StringMsg(true)) eq('v:true', fn.StringMsg(true))
eq('v:false', funcs.StringMsg(false)) eq('v:false', fn.StringMsg(false))
eq('v:null', funcs.StringMsg(NIL)) eq('v:null', fn.StringMsg(NIL))
eq('v:true', eval('StringErr(v:true)')) eq('v:true', eval('StringErr(v:true)'))
eq('v:false', eval('StringErr(v:false)')) eq('v:false', eval('StringErr(v:false)'))
eq('v:null', eval('StringErr(v:null)')) eq('v:null', eval('StringErr(v:null)'))
eq('v:true', funcs.StringErr(true)) eq('v:true', fn.StringErr(true))
eq('v:false', funcs.StringErr(false)) eq('v:false', fn.StringErr(false))
eq('v:null', funcs.StringErr(NIL)) eq('v:null', fn.StringErr(NIL))
end) end)
it('dumps values with at most six digits after the decimal point', function() it('dumps values with at most six digits after the decimal point', function()
@@ -223,7 +223,7 @@ describe(':echo :echon :echomsg :echoerr', function()
end) end)
it('does not crash or halt when dumping partials with reference cycles in self', function() it('does not crash or halt when dumping partials with reference cycles in self', function()
meths.nvim_set_var('d', { v = true }) api.nvim_set_var('d', { v = true })
eq( eq(
dedent( dedent(
[[ [[
@@ -251,7 +251,7 @@ describe(':echo :echon :echomsg :echoerr', function()
end) end)
it('does not crash or halt when dumping partials with reference cycles in arguments', function() it('does not crash or halt when dumping partials with reference cycles in arguments', function()
meths.nvim_set_var('l', {}) api.nvim_set_var('l', {})
eval('add(l, l)') eval('add(l, l)')
-- Regression: the below line used to crash (add returns original list and -- Regression: the below line used to crash (add returns original list and
-- there was error in dumping partials). Tested explicitly in -- there was error in dumping partials). Tested explicitly in
@@ -269,8 +269,8 @@ describe(':echo :echon :echomsg :echoerr', function()
it( it(
'does not crash or halt when dumping partials with reference cycles in self and arguments', 'does not crash or halt when dumping partials with reference cycles in self and arguments',
function() function()
meths.nvim_set_var('d', { v = true }) api.nvim_set_var('d', { v = true })
meths.nvim_set_var('l', {}) api.nvim_set_var('l', {})
eval('add(l, l)') eval('add(l, l)')
eval('add(l, function("Test1", l))') eval('add(l, function("Test1", l))')
eval('add(l, function("Test1", d))') eval('add(l, function("Test1", d))')
@@ -305,13 +305,13 @@ describe(':echo :echon :echomsg :echoerr', function()
end) end)
it('does not error when dumping recursive lists', function() it('does not error when dumping recursive lists', function()
meths.nvim_set_var('l', {}) api.nvim_set_var('l', {})
eval('add(l, l)') eval('add(l, l)')
eq(0, exc_exec('echo String(l)')) eq(0, exc_exec('echo String(l)'))
end) end)
it('dumps recursive lists without error', function() it('dumps recursive lists without error', function()
meths.nvim_set_var('l', {}) api.nvim_set_var('l', {})
eval('add(l, l)') eval('add(l, l)')
eq('[[...@0]]', exec_capture('echo String(l)')) eq('[[...@0]]', exec_capture('echo String(l)'))
eq('[[[...@1]]]', exec_capture('echo String([l])')) eq('[[[...@1]]]', exec_capture('echo String([l])'))
@@ -335,13 +335,13 @@ describe(':echo :echon :echomsg :echoerr', function()
end) end)
it('does not error when dumping recursive dictionaries', function() it('does not error when dumping recursive dictionaries', function()
meths.nvim_set_var('d', { d = 1 }) api.nvim_set_var('d', { d = 1 })
eval('extend(d, {"d": d})') eval('extend(d, {"d": d})')
eq(0, exc_exec('echo String(d)')) eq(0, exc_exec('echo String(d)'))
end) end)
it('dumps recursive dictionaries without the error', function() it('dumps recursive dictionaries without the error', function()
meths.nvim_set_var('d', { d = 1 }) api.nvim_set_var('d', { d = 1 })
eval('extend(d, {"d": d})') eval('extend(d, {"d": d})')
eq("{'d': {...@0}}", exec_capture('echo String(d)')) eq("{'d': {...@0}}", exec_capture('echo String(d)'))
eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})')) eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})'))
@@ -358,43 +358,43 @@ describe(':echo :echon :echomsg :echoerr', function()
it('displays hex as hex', function() it('displays hex as hex', function()
-- Regression: due to missing (uint8_t) cast \x80 was represented as -- Regression: due to missing (uint8_t) cast \x80 was represented as
-- ~@<80>. -- ~@<80>.
eq('<80>', funcs.String(chr(0x80))) eq('<80>', fn.String(chr(0x80)))
eq('<81>', funcs.String(chr(0x81))) eq('<81>', fn.String(chr(0x81)))
eq('<8e>', funcs.String(chr(0x8e))) eq('<8e>', fn.String(chr(0x8e)))
eq('<c2>', funcs.String(('«'):sub(1, 1))) eq('<c2>', fn.String(('«'):sub(1, 1)))
eq('«', funcs.String(('«'):sub(1, 2))) eq('«', fn.String(('«'):sub(1, 2)))
eq('<80>', funcs.StringMsg(chr(0x80))) eq('<80>', fn.StringMsg(chr(0x80)))
eq('<81>', funcs.StringMsg(chr(0x81))) eq('<81>', fn.StringMsg(chr(0x81)))
eq('<8e>', funcs.StringMsg(chr(0x8e))) eq('<8e>', fn.StringMsg(chr(0x8e)))
eq('<c2>', funcs.StringMsg(('«'):sub(1, 1))) eq('<c2>', fn.StringMsg(('«'):sub(1, 1)))
eq('«', funcs.StringMsg(('«'):sub(1, 2))) eq('«', fn.StringMsg(('«'):sub(1, 2)))
end) end)
it('displays ASCII control characters using ^X notation', function() it('displays ASCII control characters using ^X notation', function()
eq('^C', funcs.String(ctrl('c'))) eq('^C', fn.String(ctrl('c')))
eq('^A', funcs.String(ctrl('a'))) eq('^A', fn.String(ctrl('a')))
eq('^F', funcs.String(ctrl('f'))) eq('^F', fn.String(ctrl('f')))
eq('^C', funcs.StringMsg(ctrl('c'))) eq('^C', fn.StringMsg(ctrl('c')))
eq('^A', funcs.StringMsg(ctrl('a'))) eq('^A', fn.StringMsg(ctrl('a')))
eq('^F', funcs.StringMsg(ctrl('f'))) eq('^F', fn.StringMsg(ctrl('f')))
end) end)
it('prints CR, NL and tab as-is', function() it('prints CR, NL and tab as-is', function()
eq('\n', funcs.String('\n')) eq('\n', fn.String('\n'))
eq('\r', funcs.String('\r')) eq('\r', fn.String('\r'))
eq('\t', funcs.String('\t')) eq('\t', fn.String('\t'))
end) end)
it('prints non-printable UTF-8 in <> notation', function() it('prints non-printable UTF-8 in <> notation', function()
-- SINGLE SHIFT TWO, unicode control -- SINGLE SHIFT TWO, unicode control
eq('<8e>', funcs.String(funcs.nr2char(0x8E))) eq('<8e>', fn.String(fn.nr2char(0x8E)))
eq('<8e>', funcs.StringMsg(funcs.nr2char(0x8E))) eq('<8e>', fn.StringMsg(fn.nr2char(0x8E)))
-- Surrogate pair: U+1F0A0 PLAYING CARD BACK is represented in UTF-16 as -- Surrogate pair: U+1F0A0 PLAYING CARD BACK is represented in UTF-16 as
-- 0xD83C 0xDCA0. This is not valid in UTF-8. -- 0xD83C 0xDCA0. This is not valid in UTF-8.
eq('<d83c>', funcs.String(funcs.nr2char(0xD83C))) eq('<d83c>', fn.String(fn.nr2char(0xD83C)))
eq('<dca0>', funcs.String(funcs.nr2char(0xDCA0))) eq('<dca0>', fn.String(fn.nr2char(0xDCA0)))
eq('<d83c><dca0>', funcs.String(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) eq('<d83c><dca0>', fn.String(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0)))
eq('<d83c>', funcs.StringMsg(funcs.nr2char(0xD83C))) eq('<d83c>', fn.StringMsg(fn.nr2char(0xD83C)))
eq('<dca0>', funcs.StringMsg(funcs.nr2char(0xDCA0))) eq('<dca0>', fn.StringMsg(fn.nr2char(0xDCA0)))
eq('<d83c><dca0>', funcs.StringMsg(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) eq('<d83c><dca0>', fn.StringMsg(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0)))
end) end)
end) end)
end) end)

View File

@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs local eq, command, fn = helpers.eq, helpers.command, helpers.fn
local ok = helpers.ok local ok = helpers.ok
local clear = helpers.clear local clear = helpers.clear
local feed = helpers.feed local feed = helpers.feed
@@ -12,15 +12,15 @@ describe(':edit', function()
it('without arguments does not restart :terminal buffer', function() it('without arguments does not restart :terminal buffer', function()
command('terminal') command('terminal')
feed([[<C-\><C-N>]]) feed([[<C-\><C-N>]])
local bufname_before = funcs.bufname('%') local bufname_before = fn.bufname('%')
local bufnr_before = funcs.bufnr('%') local bufnr_before = fn.bufnr('%')
helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity
command('edit') command('edit')
local bufname_after = funcs.bufname('%') local bufname_after = fn.bufname('%')
local bufnr_after = funcs.bufnr('%') local bufnr_after = fn.bufnr('%')
ok(funcs.line('$') > 1) ok(fn.line('$') > 1)
eq(bufname_before, bufname_after) eq(bufname_before, bufname_after)
eq(bufnr_before, bufnr_after) eq(bufnr_before, bufnr_after)
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local fn = helpers.fn
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@@ -49,15 +49,15 @@ describe('Ex cmds', function()
it(':def is an unknown command #23149', function() it(':def is an unknown command #23149', function()
eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
eq(1, funcs.exists(':d')) eq(1, fn.exists(':d'))
eq('delete', funcs.fullcommand('d')) eq('delete', fn.fullcommand('d'))
eq(1, funcs.exists(':de')) eq(1, fn.exists(':de'))
eq('delete', funcs.fullcommand('de')) eq('delete', fn.fullcommand('de'))
eq(0, funcs.exists(':def')) eq(0, fn.exists(':def'))
eq('', funcs.fullcommand('def')) eq('', fn.fullcommand('def'))
eq(1, funcs.exists(':defe')) eq(1, fn.exists(':defe'))
eq('defer', funcs.fullcommand('defe')) eq('defer', fn.fullcommand('defe'))
eq(2, funcs.exists(':defer')) eq(2, fn.exists(':defer'))
eq('defer', funcs.fullcommand('defer')) eq('defer', fn.fullcommand('defer'))
end) end)
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
@@ -29,6 +29,6 @@ describe(':file', function()
command('edit! ' .. testfile) command('edit! ' .. testfile)
-- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows.
command('file ' .. testfile_renamed) command('file ' .. testfile_renamed)
eq(testfile_renamed .. '.swp', string.match(funcs.execute('swapname'), '[^%%]+$')) eq(testfile_renamed .. '.swp', string.match(fn.execute('swapname'), '[^%%]+$'))
end) end)
end) end)

View File

@@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local write_file = helpers.write_file local write_file = helpers.write_file
@@ -15,19 +15,19 @@ describe(':help', function()
it('window closed makes cursor return to a valid win/buf #9773', function() it('window closed makes cursor return to a valid win/buf #9773', function()
helpers.add_builddir_to_rtp() helpers.add_builddir_to_rtp()
command('help help') command('help help')
eq(1001, funcs.win_getid()) eq(1001, fn.win_getid())
command('quit') command('quit')
eq(1000, funcs.win_getid()) eq(1000, fn.win_getid())
command('autocmd WinNew * wincmd p') command('autocmd WinNew * wincmd p')
command('help help') command('help help')
-- Window 1002 is opened, but the autocmd switches back to 1000 and -- Window 1002 is opened, but the autocmd switches back to 1000 and
-- creates the help buffer there instead. -- creates the help buffer there instead.
eq(1000, funcs.win_getid()) eq(1000, fn.win_getid())
command('quit') command('quit')
-- Before #9773, Nvim would crash on quitting the help window. -- Before #9773, Nvim would crash on quitting the help window.
eq(1002, funcs.win_getid()) eq(1002, fn.win_getid())
end) end)
it('multibyte help tags work #23975', function() it('multibyte help tags work #23975', function()
@@ -40,6 +40,6 @@ describe(':help', function()
command('helptags Xhelptags/doc') command('helptags Xhelptags/doc')
command('set rtp+=Xhelptags') command('set rtp+=Xhelptags')
command('help …') command('help …')
eq('*…*', meths.nvim_get_current_line()) eq('*…*', api.nvim_get_current_line())
end) end)
end) end)

View File

@@ -4,8 +4,8 @@ local eq, command = helpers.eq, helpers.command
local clear = helpers.clear local clear = helpers.clear
local eval, exc_exec = helpers.eval, helpers.exc_exec local eval, exc_exec = helpers.eval, helpers.exc_exec
local exec = helpers.exec local exec = helpers.exec
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
describe(':highlight', function() describe(':highlight', function()
local screen local screen
@@ -53,18 +53,18 @@ describe(':highlight', function()
end) end)
it('clear', function() it('clear', function()
meths.nvim_set_var('colors_name', 'foo') api.nvim_set_var('colors_name', 'foo')
eq(1, funcs.exists('g:colors_name')) eq(1, fn.exists('g:colors_name'))
command('hi clear') command('hi clear')
eq(0, funcs.exists('g:colors_name')) eq(0, fn.exists('g:colors_name'))
meths.nvim_set_var('colors_name', 'foo') api.nvim_set_var('colors_name', 'foo')
eq(1, funcs.exists('g:colors_name')) eq(1, fn.exists('g:colors_name'))
exec([[ exec([[
func HiClear() func HiClear()
hi clear hi clear
endfunc endfunc
]]) ]])
funcs.HiClear() fn.HiClear()
eq(0, funcs.exists('g:colors_name')) eq(0, fn.exists('g:colors_name'))
end) end)
end) end)

View File

@@ -4,7 +4,7 @@ local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local testprg = helpers.testprg local testprg = helpers.testprg
local retry = helpers.retry local retry = helpers.retry
@@ -14,7 +14,7 @@ describe(':ls', function()
end) end)
it('R, F for :terminal buffers', function() it('R, F for :terminal buffers', function()
meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('edit foo') command('edit foo')
command('set hidden') command('set hidden')

View File

@@ -3,7 +3,7 @@ local clear = helpers.clear
local eval = helpers.eval local eval = helpers.eval
local has_powershell = helpers.has_powershell local has_powershell = helpers.has_powershell
local matches = helpers.matches local matches = helpers.matches
local meths = helpers.meths local api = helpers.api
local testprg = helpers.testprg local testprg = helpers.testprg
describe(':make', function() describe(':make', function()
@@ -22,7 +22,7 @@ describe(':make', function()
end) end)
it('captures stderr & non zero exit code #14349', function() it('captures stderr & non zero exit code #14349', function()
meths.nvim_set_option_value('makeprg', testprg('shell-test') .. ' foo', {}) api.nvim_set_option_value('makeprg', testprg('shell-test') .. ' foo', {})
local out = eval('execute("make")') local out = eval('execute("make")')
-- Error message is captured in the file and printed in the footer -- Error message is captured in the file and printed in the footer
matches( matches(
@@ -32,7 +32,7 @@ describe(':make', function()
end) end)
it('captures stderr & zero exit code #14349', function() it('captures stderr & zero exit code #14349', function()
meths.nvim_set_option_value('makeprg', testprg('shell-test'), {}) api.nvim_set_option_value('makeprg', testprg('shell-test'), {})
local out = eval('execute("make")') local out = eval('execute("make")')
-- Ensure there are no "shell returned X" messages between -- Ensure there are no "shell returned X" messages between
-- command and last line (indicating zero exit) -- command and last line (indicating zero exit)

View File

@@ -5,7 +5,7 @@ local eq = helpers.eq
local exec = helpers.exec local exec = helpers.exec
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect = helpers.expect local expect = helpers.expect
@@ -16,13 +16,13 @@ describe(':*map', function()
before_each(clear) before_each(clear)
it('are not affected by &isident', function() it('are not affected by &isident', function()
meths.nvim_set_var('counter', 0) api.nvim_set_var('counter', 0)
command('nnoremap <C-x> :let counter+=1<CR>') command('nnoremap <C-x> :let counter+=1<CR>')
meths.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {}) api.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {})
command('nnoremap <C-y> :let counter+=1<CR>') command('nnoremap <C-y> :let counter+=1<CR>')
-- &isident used to disable keycode parsing here as well -- &isident used to disable keycode parsing here as well
feed('\24\25<C-x><C-y>') feed('\24\25<C-x><C-y>')
eq(4, meths.nvim_get_var('counter')) eq(4, api.nvim_get_var('counter'))
end) end)
it(':imap <M-">', function() it(':imap <M-">', function()
@@ -42,9 +42,9 @@ n asdf <Nop>]],
end) end)
it('mappings with description can be filtered', function() it('mappings with description can be filtered', function()
meths.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' }) api.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' })
meths.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' }) api.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' })
meths.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' }) api.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' })
eq( eq(
[[ [[
@@ -58,21 +58,21 @@ n asdf1 qwert
it('<Plug> mappings ignore nore', function() it('<Plug> mappings ignore nore', function()
command('let x = 0') command('let x = 0')
eq(0, meths.nvim_eval('x')) eq(0, api.nvim_eval('x'))
command [[ command [[
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
nmap increase_x_remap <Plug>(Increase_x) nmap increase_x_remap <Plug>(Increase_x)
nnoremap increase_x_noremap <Plug>(Increase_x) nnoremap increase_x_noremap <Plug>(Increase_x)
]] ]]
feed('increase_x_remap') feed('increase_x_remap')
eq(1, meths.nvim_eval('x')) eq(1, api.nvim_eval('x'))
feed('increase_x_noremap') feed('increase_x_noremap')
eq(2, meths.nvim_eval('x')) eq(2, api.nvim_eval('x'))
end) end)
it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function() it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function()
command('let x = 0') command('let x = 0')
eq(0, meths.nvim_eval('x')) eq(0, api.nvim_eval('x'))
command [[ command [[
nnoremap x <nop> nnoremap x <nop>
nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
@@ -83,10 +83,10 @@ n asdf1 qwert
eq('Some text', eval("getline('.')")) eq('Some text', eval("getline('.')"))
feed('increase_x_remap') feed('increase_x_remap')
eq(1, meths.nvim_eval('x')) eq(1, api.nvim_eval('x'))
eq('Some text', eval("getline('.')")) eq('Some text', eval("getline('.')"))
feed('increase_x_noremap') feed('increase_x_noremap')
eq(2, meths.nvim_eval('x')) eq(2, api.nvim_eval('x'))
eq('Some te', eval("getline('.')")) eq('Some te', eval("getline('.')"))
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear, command = helpers.clear, helpers.command local clear, command = helpers.clear, helpers.command
local expect, feed = helpers.expect, helpers.feed local expect, feed = helpers.expect, helpers.feed
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local funcs = helpers.funcs local fn = helpers.fn
describe(':emenu', function() describe(':emenu', function()
before_each(function() before_each(function()
@@ -80,7 +80,7 @@ describe('menu_get', function()
end) end)
it("path='', modes='a'", function() it("path='', modes='a'", function()
local m = funcs.menu_get('', 'a') local m = fn.menu_get('', 'a')
-- HINT: To print the expected table and regenerate the tests: -- HINT: To print the expected table and regenerate the tests:
-- print(require('vim.inspect')(m)) -- print(require('vim.inspect')(m))
local expected = { local expected = {
@@ -308,7 +308,7 @@ describe('menu_get', function()
end) end)
it('matching path, all modes', function() it('matching path, all modes', function()
local m = funcs.menu_get('Export', 'a') local m = fn.menu_get('Export', 'a')
local expected = { local expected = {
{ {
hidden = 0, hidden = 0,
@@ -337,7 +337,7 @@ describe('menu_get', function()
end) end)
it('no path, matching modes', function() it('no path, matching modes', function()
local m = funcs.menu_get('', 'i') local m = fn.menu_get('', 'i')
local expected = { local expected = {
{ {
shortcut = 'T', shortcut = 'T',
@@ -366,7 +366,7 @@ describe('menu_get', function()
end) end)
it('matching path and modes', function() it('matching path and modes', function()
local m = funcs.menu_get('Test', 'i') local m = fn.menu_get('Test', 'i')
local expected = { local expected = {
{ {
shortcut = 'T', shortcut = 'T',
@@ -412,7 +412,7 @@ describe('menu_get', function()
command('nnoremenu &Test.Test8 <NoP>') command('nnoremenu &Test.Test8 <NoP>')
command('nnoremenu &Test.Test9 ""') command('nnoremenu &Test.Test9 ""')
local m = funcs.menu_get('') local m = fn.menu_get('')
local expected = { local expected = {
{ {
shortcut = 'T', shortcut = 'T',
@@ -565,7 +565,7 @@ describe('menu_get', function()
command('nnoremenu &Test\\ 1.Test\\ 2 Wargl') command('nnoremenu &Test\\ 1.Test\\ 2 Wargl')
command('nnoremenu &Test4.Test<Tab>3 i space<Esc>') command('nnoremenu &Test4.Test<Tab>3 i space<Esc>')
local m = funcs.menu_get('') local m = fn.menu_get('')
local expected = { local expected = {
{ {
shortcut = 'T', shortcut = 'T',

View File

@@ -6,12 +6,12 @@ local command = helpers.command
local get_pathsep = helpers.get_pathsep local get_pathsep = helpers.get_pathsep
local eq = helpers.eq local eq = helpers.eq
local neq = helpers.neq local neq = helpers.neq
local funcs = helpers.funcs local fn = helpers.fn
local matches = helpers.matches local matches = helpers.matches
local pesc = vim.pesc local pesc = vim.pesc
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local meths = helpers.meths local api = helpers.api
local skip = helpers.skip local skip = helpers.skip
local is_os = helpers.is_os local is_os = helpers.is_os
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
@@ -54,8 +54,8 @@ describe(':mksession', function()
-- Restore session. -- Restore session.
command('source ' .. session_file) command('source ' .. session_file)
eq(funcs.winbufnr(1), funcs.winbufnr(2)) eq(fn.winbufnr(1), fn.winbufnr(2))
neq(funcs.winbufnr(1), funcs.winbufnr(3)) neq(fn.winbufnr(1), fn.winbufnr(3))
end) end)
-- common testing procedure for testing "sessionoptions-=terminal" -- common testing procedure for testing "sessionoptions-=terminal"
@@ -70,7 +70,7 @@ describe(':mksession', function()
-- Restore session. -- Restore session.
command('source ' .. session_file) command('source ' .. session_file)
eq(expected_buf_count, #meths.nvim_list_bufs()) eq(expected_buf_count, #api.nvim_list_bufs())
end end
it( it(
@@ -80,54 +80,54 @@ describe(':mksession', function()
command('edit ' .. tmpfile_base) command('edit ' .. tmpfile_base)
command('terminal') command('terminal')
local buf_count = #meths.nvim_list_bufs() local buf_count = #api.nvim_list_bufs()
eq(2, buf_count) eq(2, buf_count)
eq('terminal', meths.nvim_get_option_value('buftype', {})) eq('terminal', api.nvim_get_option_value('buftype', {}))
test_terminal_session_disabled(2) test_terminal_session_disabled(2)
-- no terminal should be set. As a side effect we end up with a blank buffer -- no terminal should be set. As a side effect we end up with a blank buffer
eq('', meths.nvim_get_option_value('buftype', { buf = meths.nvim_list_bufs()[1] })) eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[1] }))
eq('', meths.nvim_get_option_value('buftype', { buf = meths.nvim_list_bufs()[2] })) eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[2] }))
end end
) )
it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078', function() it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078', function()
command('terminal') command('terminal')
local terminal_bufnr = meths.nvim_get_current_buf() local terminal_bufnr = api.nvim_get_current_buf()
local tmpfile_base = file_prefix .. '-tmpfile' local tmpfile_base = file_prefix .. '-tmpfile'
-- make terminal hidden by opening a new file -- make terminal hidden by opening a new file
command('edit ' .. tmpfile_base .. '1') command('edit ' .. tmpfile_base .. '1')
local buf_count = #meths.nvim_list_bufs() local buf_count = #api.nvim_list_bufs()
eq(2, buf_count) eq(2, buf_count)
eq(1, funcs.getbufinfo(terminal_bufnr)[1].hidden) eq(1, fn.getbufinfo(terminal_bufnr)[1].hidden)
test_terminal_session_disabled(1) test_terminal_session_disabled(1)
-- no terminal should exist here -- no terminal should exist here
neq('', meths.nvim_buf_get_name(meths.nvim_list_bufs()[1])) neq('', api.nvim_buf_get_name(api.nvim_list_bufs()[1]))
end) end)
it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function()
command('terminal') command('terminal')
eq('terminal', meths.nvim_get_option_value('buftype', {})) eq('terminal', api.nvim_get_option_value('buftype', {}))
local buf_count = #meths.nvim_list_bufs() local buf_count = #api.nvim_list_bufs()
eq(1, buf_count) eq(1, buf_count)
test_terminal_session_disabled(1) test_terminal_session_disabled(1)
-- no terminal should be set -- no terminal should be set
eq('', meths.nvim_get_option_value('buftype', {})) eq('', api.nvim_get_option_value('buftype', {}))
end) end)
it('restores tab-local working directories', function() it('restores tab-local working directories', function()
local tmpfile_base = file_prefix .. '-tmpfile' local tmpfile_base = file_prefix .. '-tmpfile'
local cwd_dir = funcs.getcwd() local cwd_dir = fn.getcwd()
-- :mksession does not save empty tabs, so create some buffers. -- :mksession does not save empty tabs, so create some buffers.
command('edit ' .. tmpfile_base .. '1') command('edit ' .. tmpfile_base .. '1')
@@ -143,15 +143,15 @@ describe(':mksession', function()
command('source ' .. session_file) command('source ' .. session_file)
-- First tab should have the original working directory. -- First tab should have the original working directory.
command('tabnext 1') command('tabnext 1')
eq(cwd_dir, funcs.getcwd()) eq(cwd_dir, fn.getcwd())
-- Second tab should have the tab-local working directory. -- Second tab should have the tab-local working directory.
command('tabnext 2') command('tabnext 2')
eq(cwd_dir .. get_pathsep() .. tab_dir, funcs.getcwd()) eq(cwd_dir .. get_pathsep() .. tab_dir, fn.getcwd())
end) end)
it('restores buffers with tab-local CWD', function() it('restores buffers with tab-local CWD', function()
local tmpfile_base = file_prefix .. '-tmpfile' local tmpfile_base = file_prefix .. '-tmpfile'
local cwd_dir = funcs.getcwd() local cwd_dir = fn.getcwd()
local session_path = cwd_dir .. get_pathsep() .. session_file local session_path = cwd_dir .. get_pathsep() .. session_file
command('edit ' .. tmpfile_base .. '1') command('edit ' .. tmpfile_base .. '1')
@@ -167,13 +167,13 @@ describe(':mksession', function()
-- Use :silent to avoid press-enter prompt due to long path -- Use :silent to avoid press-enter prompt due to long path
command('silent source ' .. session_path) command('silent source ' .. session_path)
command('tabnext 1') command('tabnext 1')
eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', funcs.expand('%:p')) eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', fn.expand('%:p'))
command('tabnext 2') command('tabnext 2')
eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', funcs.expand('%:p')) eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', fn.expand('%:p'))
end) end)
it('restores CWD for :terminal buffers #11288', function() it('restores CWD for :terminal buffers #11288', function()
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes. cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes.
local session_path = cwd_dir .. '/' .. session_file local session_path = cwd_dir .. '/' .. session_file
@@ -191,7 +191,7 @@ describe(':mksession', function()
command('silent source ' .. session_path) command('silent source ' .. session_path)
local expected_cwd = cwd_dir .. '/' .. tab_dir local expected_cwd = cwd_dir .. '/' .. tab_dir
matches('^term://' .. pesc(expected_cwd) .. '//%d+:', funcs.expand('%')) matches('^term://' .. pesc(expected_cwd) .. '//%d+:', fn.expand('%'))
command('%bwipeout!') command('%bwipeout!')
if is_os('win') then if is_os('win') then
sleep(100) -- Make sure all child processes have exited. sleep(100) -- Make sure all child processes have exited.
@@ -202,7 +202,7 @@ describe(':mksession', function()
skip(is_os('win'), 'N/A for Windows') skip(is_os('win'), 'N/A for Windows')
local screen local screen
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
local session_path = cwd_dir .. '/' .. session_file local session_path = cwd_dir .. '/' .. session_file
screen = Screen.new(50, 6) screen = Screen.new(50, 6)
@@ -238,7 +238,7 @@ describe(':mksession', function()
local tmpfile = file_prefix .. '-tmpfile-float' local tmpfile = file_prefix .. '-tmpfile-float'
command('edit ' .. tmpfile) command('edit ' .. tmpfile)
local buf = meths.nvim_create_buf(false, true) local buf = api.nvim_create_buf(false, true)
local config = { local config = {
relative = 'editor', relative = 'editor',
focusable = false, focusable = false,
@@ -248,8 +248,8 @@ describe(':mksession', function()
col = 1, col = 1,
style = 'minimal', style = 'minimal',
} }
meths.nvim_open_win(buf, false, config) api.nvim_open_win(buf, false, config)
local cmdheight = meths.nvim_get_option_value('cmdheight', {}) local cmdheight = api.nvim_get_option_value('cmdheight', {})
command('mksession ' .. session_file) command('mksession ' .. session_file)
-- Create a new test instance of Nvim. -- Create a new test instance of Nvim.
@@ -257,12 +257,12 @@ describe(':mksession', function()
command('source ' .. session_file) command('source ' .. session_file)
eq(tmpfile, funcs.expand('%')) eq(tmpfile, fn.expand('%'))
-- Check that there is only a single window, which indicates the floating -- Check that there is only a single window, which indicates the floating
-- window was not restored. -- window was not restored.
eq(1, funcs.winnr('$')) eq(1, fn.winnr('$'))
-- The command-line height should remain the same as it was. -- The command-line height should remain the same as it was.
eq(cmdheight, meths.nvim_get_option_value('cmdheight', {})) eq(cmdheight, api.nvim_get_option_value('cmdheight', {}))
os.remove(tmpfile) os.remove(tmpfile)
end) end)

View File

@@ -4,7 +4,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local get_pathsep = helpers.get_pathsep local get_pathsep = helpers.get_pathsep
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
@@ -28,7 +28,7 @@ describe(':mkview', function()
end) end)
it('viewoption curdir restores local current directory', function() it('viewoption curdir restores local current directory', function()
local cwd_dir = funcs.getcwd() local cwd_dir = fn.getcwd()
local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir
-- By default the local current directory should save -- By default the local current directory should save
@@ -55,11 +55,11 @@ describe(':mkview', function()
command('edit ' .. tmp_file_base .. '2') command('edit ' .. tmp_file_base .. '2')
command('loadview') command('loadview')
-- The view's current directory should not have changed -- The view's current directory should not have changed
eq(cwd_dir, funcs.getcwd()) eq(cwd_dir, fn.getcwd())
-- Load the view with a saved local current directory -- Load the view with a saved local current directory
command('edit ' .. tmp_file_base .. '1') command('edit ' .. tmp_file_base .. '1')
command('loadview') command('loadview')
-- The view's local directory should have been saved -- The view's local directory should have been saved
eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd()) eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd())
end) end)
end) end)

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local feed = helpers.feed local feed = helpers.feed
local expect = helpers.expect local expect = helpers.expect
local eq = helpers.eq local eq = helpers.eq
@@ -29,10 +29,10 @@ describe(':normal!', function()
it('can stop Visual mode without closing cmdwin vim-patch:9.0.0234', function() it('can stop Visual mode without closing cmdwin vim-patch:9.0.0234', function()
feed('q:') feed('q:')
feed('v') feed('v')
eq('v', funcs.mode(1)) eq('v', fn.mode(1))
eq(':', funcs.getcmdwintype()) eq(':', fn.getcmdwintype())
command('normal! \027') command('normal! \027')
eq('n', funcs.mode(1)) eq('n', fn.mode(1))
eq(':', funcs.getcmdwintype()) eq(':', fn.getcmdwintype())
end) end)
end) end)

View File

@@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local meths, eq, feed_command = helpers.meths, helpers.eq, helpers.feed_command local api, eq, feed_command = helpers.api, helpers.eq, helpers.feed_command
local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop
local ok = helpers.ok local ok = helpers.ok
local eval = helpers.eval local eval = helpers.eval
@@ -42,7 +42,7 @@ describe(':oldfiles', function()
feed_command('edit testfile2') feed_command('edit testfile2')
feed_command('wshada') feed_command('wshada')
feed_command('rshada!') feed_command('rshada!')
local oldfiles = meths.nvim_get_vvar('oldfiles') local oldfiles = api.nvim_get_vvar('oldfiles')
feed_command('oldfiles') feed_command('oldfiles')
screen:expect([[ screen:expect([[
| |
@@ -56,11 +56,11 @@ describe(':oldfiles', function()
it('can be filtered with :filter', function() it('can be filtered with :filter', function()
feed_command('edit file_one.txt') feed_command('edit file_one.txt')
local file1 = meths.nvim_buf_get_name(0) local file1 = api.nvim_buf_get_name(0)
feed_command('edit file_two.txt') feed_command('edit file_two.txt')
local file2 = meths.nvim_buf_get_name(0) local file2 = api.nvim_buf_get_name(0)
feed_command('edit another.txt') feed_command('edit another.txt')
local another = meths.nvim_buf_get_name(0) local another = api.nvim_buf_get_name(0)
feed_command('wshada') feed_command('wshada')
feed_command('rshada!') feed_command('rshada!')
@@ -95,9 +95,9 @@ describe(':browse oldfiles', function()
before_each(function() before_each(function()
_clear() _clear()
feed_command('edit testfile1') feed_command('edit testfile1')
filename = meths.nvim_buf_get_name(0) filename = api.nvim_buf_get_name(0)
feed_command('edit testfile2') feed_command('edit testfile2')
filename2 = meths.nvim_buf_get_name(0) filename2 = api.nvim_buf_get_name(0)
feed_command('wshada') feed_command('wshada')
poke_eventloop() poke_eventloop()
_clear() _clear()
@@ -108,7 +108,7 @@ describe(':browse oldfiles', function()
-- Ensure v:oldfiles isn't busted. Since things happen so fast, -- Ensure v:oldfiles isn't busted. Since things happen so fast,
-- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood). -- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood).
-- Let's verify the contents and the length of v:oldfiles before moving on. -- Let's verify the contents and the length of v:oldfiles before moving on.
oldfiles = helpers.meths.nvim_get_vvar('oldfiles') oldfiles = helpers.api.nvim_get_vvar('oldfiles')
eq(2, #oldfiles) eq(2, #oldfiles)
ok(filename == oldfiles[1] or filename == oldfiles[2]) ok(filename == oldfiles[1] or filename == oldfiles[2])
ok(filename2 == oldfiles[1] or filename2 == oldfiles[2]) ok(filename2 == oldfiles[1] or filename2 == oldfiles[2])
@@ -123,16 +123,16 @@ describe(':browse oldfiles', function()
it('provides a prompt and edits the chosen file', function() it('provides a prompt and edits the chosen file', function()
feed('2<cr>') feed('2<cr>')
eq(oldfiles[2], meths.nvim_buf_get_name(0)) eq(oldfiles[2], api.nvim_buf_get_name(0))
end) end)
it('provides a prompt and does nothing on <cr>', function() it('provides a prompt and does nothing on <cr>', function()
feed('<cr>') feed('<cr>')
eq('', meths.nvim_buf_get_name(0)) eq('', api.nvim_buf_get_name(0))
end) end)
it('provides a prompt and does nothing if choice is out-of-bounds', function() it('provides a prompt and does nothing if choice is out-of-bounds', function()
feed('3<cr>') feed('3<cr>')
eq('', meths.nvim_buf_get_name(0)) eq('', api.nvim_buf_get_name(0))
end) end)
end) end)

View File

@@ -1,11 +1,11 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq, command, funcs = helpers.clear, helpers.eq, helpers.command, helpers.funcs local clear, eq, command, fn = helpers.clear, helpers.eq, helpers.command, helpers.fn
describe(':z^', function() describe(':z^', function()
before_each(clear) before_each(clear)
it('correctly sets the cursor after :z^', function() it('correctly sets the cursor after :z^', function()
command('z^') command('z^')
eq(1, funcs.line('.')) eq(1, fn.line('.'))
end) end)
end) end)

View File

@@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen')
local feed = helpers.feed local feed = helpers.feed
local eq = helpers.eq local eq = helpers.eq
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local fn = helpers.fn
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local api = helpers.api
local source = helpers.source local source = helpers.source
local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' local file_base = 'Xtest-functional-ex_cmds-quickfix_commands'
@@ -20,8 +20,8 @@ for _, c in ipairs({ 'l', 'c' }) do
local filecmd = c .. 'file' local filecmd = c .. 'file'
local getfcmd = c .. 'getfile' local getfcmd = c .. 'getfile'
local addfcmd = c .. 'addfile' local addfcmd = c .. 'addfile'
local getlist = (c == 'c') and funcs.getqflist or function() local getlist = (c == 'c') and fn.getqflist or function()
return funcs.getloclist(0) return fn.getloclist(0)
end end
describe((':%s*file commands'):format(c), function() describe((':%s*file commands'):format(c), function()
@@ -73,13 +73,13 @@ for _, c in ipairs({ 'l', 'c' }) do
}, },
} }
eq(list, getlist()) eq(list, getlist())
eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
-- Run cfile/lfile from a modified buffer -- Run cfile/lfile from a modified buffer
command('set nohidden') command('set nohidden')
command('enew!') command('enew!')
meths.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' }) api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
eq( eq(
('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd),
exc_exec(('%s %s'):format(filecmd, file)) exc_exec(('%s %s'):format(filecmd, file))
@@ -107,7 +107,7 @@ for _, c in ipairs({ 'l', 'c' }) do
['type'] = '', ['type'] = '',
} }
eq(list, getlist()) eq(list, getlist())
eq(('%s-3.res'):format(file), funcs.bufname(list[3].bufnr)) eq(('%s-3.res'):format(file), fn.bufname(list[3].bufnr))
write_file( write_file(
file, file,
@@ -149,8 +149,8 @@ for _, c in ipairs({ 'l', 'c' }) do
}, },
} }
eq(list, getlist()) eq(list, getlist())
eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
end) end)
end) end)
end end
@@ -178,7 +178,7 @@ describe('quickfix', function()
call append(0, ['New line 1', 'New line 2', 'New line 3']) call append(0, ['New line 1', 'New line 2', 'New line 3'])
silent ll silent ll
]]) ]])
eq({ 0, 6, 1, 0, 1 }, funcs.getcurpos()) eq({ 0, 6, 1, 0, 1 }, fn.getcurpos())
end) end)
it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function() it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function()

View File

@@ -5,7 +5,7 @@ local neq = helpers.neq
local command = helpers.command local command = helpers.command
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local write_file = helpers.write_file local write_file = helpers.write_file
local meths = helpers.meths local api = helpers.api
local clear = helpers.clear local clear = helpers.clear
local dedent = helpers.dedent local dedent = helpers.dedent
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
@@ -83,7 +83,7 @@ describe('script_get-based command', function()
]])):format(cmd, garbage) ]])):format(cmd, garbage)
) )
) )
neq(0, meths.nvim_get_var('exc')) neq(0, api.nvim_get_var('exc'))
end end
end) end)
end) end)

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive
local command = helpers.command local command = helpers.command
local meths = helpers.meths local api = helpers.api
describe('sign', function() describe('sign', function()
before_each(clear) before_each(clear)
@@ -10,16 +10,16 @@ describe('sign', function()
it('deletes the sign from all buffers', function() it('deletes the sign from all buffers', function()
-- place a sign with id 34 to first buffer -- place a sign with id 34 to first buffer
command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number')
local buf1 = meths.nvim_eval('bufnr("%")') local buf1 = api.nvim_eval('bufnr("%")')
command('sign place 34 line=3 name=Foo buffer=' .. buf1) command('sign place 34 line=3 name=Foo buffer=' .. buf1)
-- create a second buffer and place the sign on it as well -- create a second buffer and place the sign on it as well
command('new') command('new')
local buf2 = meths.nvim_eval('bufnr("%")') local buf2 = api.nvim_eval('bufnr("%")')
command('sign place 34 line=3 name=Foo buffer=' .. buf2) command('sign place 34 line=3 name=Foo buffer=' .. buf2)
-- now unplace without specifying a buffer -- now unplace without specifying a buffer
command('sign unplace 34') command('sign unplace 34')
eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf1, true)) eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf1, true))
eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf2, true)) eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf2, true))
end) end)
end) end)
end) end)

View File

@@ -3,7 +3,7 @@ local command = helpers.command
local insert = helpers.insert local insert = helpers.insert
local eq = helpers.eq local eq = helpers.eq
local clear = helpers.clear local clear = helpers.clear
local meths = helpers.meths local api = helpers.api
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local write_file = helpers.write_file local write_file = helpers.write_file
@@ -49,7 +49,7 @@ describe(':source', function()
pending("'shellslash' only works on Windows") pending("'shellslash' only works on Windows")
return return
end end
meths.nvim_set_option_value('shellslash', false, {}) api.nvim_set_option_value('shellslash', false, {})
mkdir('Xshellslash') mkdir('Xshellslash')
write_file( write_file(
@@ -65,9 +65,9 @@ describe(':source', function()
for _ = 1, 2 do for _ = 1, 2 do
command([[source Xshellslash/Xstack.vim]]) command([[source Xshellslash/Xstack.vim]])
matches([[Xshellslash\Xstack%.vim]], meths.nvim_get_var('stack1')) matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack1'))
matches([[Xshellslash/Xstack%.vim]], meths.nvim_get_var('stack2')) matches([[Xshellslash/Xstack%.vim]], api.nvim_get_var('stack2'))
matches([[Xshellslash\Xstack%.vim]], meths.nvim_get_var('stack3')) matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack3'))
end end
write_file( write_file(
@@ -83,9 +83,9 @@ describe(':source', function()
for _ = 1, 2 do for _ = 1, 2 do
command([[source Xshellslash/Xstack.lua]]) command([[source Xshellslash/Xstack.lua]])
matches([[Xshellslash\Xstack%.lua]], meths.nvim_get_var('stack1')) matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack1'))
matches([[Xshellslash/Xstack%.lua]], meths.nvim_get_var('stack2')) matches([[Xshellslash/Xstack%.lua]], api.nvim_get_var('stack2'))
matches([[Xshellslash\Xstack%.lua]], meths.nvim_get_var('stack3')) matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack3'))
end end
rmdir('Xshellslash') rmdir('Xshellslash')
@@ -182,9 +182,9 @@ describe(':source', function()
command('set shellslash') command('set shellslash')
command('source ' .. test_file) command('source ' .. test_file)
eq(1, eval('g:sourced_lua')) eq(1, eval('g:sourced_lua'))
matches([[/test%.lua$]], meths.nvim_get_var('sfile_value')) matches([[/test%.lua$]], api.nvim_get_var('sfile_value'))
matches([[/test%.lua$]], meths.nvim_get_var('stack_value')) matches([[/test%.lua$]], api.nvim_get_var('stack_value'))
matches([[/test%.lua$]], meths.nvim_get_var('script_value')) matches([[/test%.lua$]], api.nvim_get_var('script_value'))
os.remove(test_file) os.remove(test_file)
end) end)
@@ -229,9 +229,9 @@ describe(':source', function()
eq(12, eval('g:c')) eq(12, eval('g:c'))
eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
eq(':source (no file)', meths.nvim_get_var('sfile_value')) eq(':source (no file)', api.nvim_get_var('sfile_value'))
eq(':source (no file)', meths.nvim_get_var('stack_value')) eq(':source (no file)', api.nvim_get_var('stack_value'))
eq(':source (no file)', meths.nvim_get_var('script_value')) eq(':source (no file)', api.nvim_get_var('script_value'))
end) end)
end end

View File

@@ -6,7 +6,7 @@ local assert_alive = helpers.assert_alive
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local ok = helpers.ok local ok = helpers.ok
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
@@ -21,7 +21,7 @@ local expect_msg_seq = helpers.expect_msg_seq
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local meths = helpers.meths local api = helpers.api
local retry = helpers.retry local retry = helpers.retry
local write_file = helpers.write_file local write_file = helpers.write_file
@@ -114,7 +114,7 @@ describe("preserve and (R)ecover with custom 'directory'", function()
local screen0 = Screen.new() local screen0 = Screen.new()
screen0:attach() screen0:attach()
local child_server = new_pipename() local child_server = new_pipename()
funcs.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, { fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, {
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
}) })
screen0:expect({ any = pesc('[No Name]') }) -- Wait for the child process to start. screen0:expect({ any = pesc('[No Name]') }) -- Wait for the child process to start.
@@ -246,7 +246,7 @@ describe('swapfile detection', function()
command('edit Xfile1') command('edit Xfile1')
command("put ='some text...'") command("put ='some text...'")
command('preserve') -- Make sure the swap file exists. command('preserve') -- Make sure the swap file exists.
local nvimpid = funcs.getpid() local nvimpid = fn.getpid()
local nvim1 = spawn(new_argv(), true, nil, true) local nvim1 = spawn(new_argv(), true, nil, true)
set_session(nvim1) set_session(nvim1)
@@ -352,7 +352,7 @@ describe('swapfile detection', function()
edit Xswaptest edit Xswaptest
call setline(1, ['a', 'b', 'c']) call setline(1, ['a', 'b', 'c'])
]]) ]])
local swname = funcs.CopySwapfile() local swname = fn.CopySwapfile()
-- Forget we edited this file -- Forget we edited this file
exec([[ exec([[
@@ -438,7 +438,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
feed('Gisometext<esc>') feed('Gisometext<esc>')
poke_eventloop() poke_eventloop()
clear() -- Leaves a swap file behind clear() -- Leaves a swap file behind
meths.nvim_ui_attach(80, 30, {}) api.nvim_ui_attach(80, 30, {})
end) end)
after_each(function() after_each(function()
rmdir(swapdir) rmdir(swapdir)
@@ -447,7 +447,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
end) end)
it('(Q)uit at first file argument', function() it('(Q)uit at first file argument', function()
local chan = funcs.termopen( local chan = fn.termopen(
{ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', init_dir, '--cmd', init_set, testfile }, { nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', init_dir, '--cmd', init_set, testfile },
{ {
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
@@ -459,7 +459,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
eval("getline('$')->trim(' ', 2)") eval("getline('$')->trim(' ', 2)")
) )
end) end)
meths.nvim_chan_send(chan, 'q') api.nvim_chan_send(chan, 'q')
retry(nil, nil, function() retry(nil, nil, function()
eq( eq(
{ '', '[Process exited 1]', '' }, { '', '[Process exited 1]', '' },
@@ -469,7 +469,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
end) end)
it('(A)bort at second file argument with -p', function() it('(A)bort at second file argument with -p', function()
local chan = funcs.termopen({ local chan = fn.termopen({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -491,7 +491,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
eval("getline('$')->trim(' ', 2)") eval("getline('$')->trim(' ', 2)")
) )
end) end)
meths.nvim_chan_send(chan, 'a') api.nvim_chan_send(chan, 'a')
retry(nil, nil, function() retry(nil, nil, function()
eq( eq(
{ '', '[Process exited 1]', '' }, { '', '[Process exited 1]', '' },
@@ -509,7 +509,7 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
second %s /^ \zssecond$/ second %s /^ \zssecond$/
third %s /^ \zsthird$/]]):format(testfile, testfile, testfile) third %s /^ \zsthird$/]]):format(testfile, testfile, testfile)
) )
local chan = funcs.termopen({ local chan = fn.termopen({
nvim_prog, nvim_prog,
'-u', '-u',
'NONE', 'NONE',
@@ -531,11 +531,11 @@ describe('quitting swapfile dialog on startup stops TUI properly', function()
eval("getline('$')->trim(' ', 2)") eval("getline('$')->trim(' ', 2)")
) )
end) end)
meths.nvim_chan_send(chan, 'q') api.nvim_chan_send(chan, 'q')
retry(nil, nil, function() retry(nil, nil, function()
eq('Press ENTER or type command to continue', eval("getline('$')->trim(' ', 2)")) eq('Press ENTER or type command to continue', eval("getline('$')->trim(' ', 2)"))
end) end)
meths.nvim_chan_send(chan, '\r') api.nvim_chan_send(chan, '\r')
retry(nil, nil, function() retry(nil, nil, function()
eq( eq(
{ '', '[Process exited 1]', '' }, { '', '[Process exited 1]', '' },

View File

@@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture
local matches = helpers.matches local matches = helpers.matches
local pathsep = helpers.get_pathsep() local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os local is_os = helpers.is_os
local funcs = helpers.funcs local fn = helpers.fn
describe(':trust', function() describe(':trust', function()
local xstate = 'Xstate' local xstate = 'Xstate'
@@ -30,53 +30,53 @@ describe(':trust', function()
end) end)
it('trust then deny then remove a file using current buffer', function() it('trust then deny then remove a file using current buffer', function()
local cwd = funcs.getcwd() local cwd = fn.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file')) local hash = fn.sha256(helpers.read_file('test_file'))
command('edit test_file') command('edit test_file')
matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust)) eq(string.format(''), vim.trim(trust))
end) end)
it('deny then trust then remove a file using current buffer', function() it('deny then trust then remove a file using current buffer', function()
local cwd = funcs.getcwd() local cwd = fn.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file')) local hash = fn.sha256(helpers.read_file('test_file'))
command('edit test_file') command('edit test_file')
matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust)) eq(string.format(''), vim.trim(trust))
end) end)
it('deny then remove a file using file path', function() it('deny then remove a file using file path', function()
local cwd = funcs.getcwd() local cwd = fn.getcwd()
matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file'))
local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
matches( matches(
'^Removed ".*test_file" from trust database%.$', '^Removed ".*test_file" from trust database%.$',
exec_capture('trust ++remove test_file') exec_capture('trust ++remove test_file')
) )
trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust')
eq(string.format(''), vim.trim(trust)) eq(string.format(''), vim.trim(trust))
end) end)
end) end)

View File

@@ -5,7 +5,7 @@ local eq = helpers.eq
local exec = helpers.exec local exec = helpers.exec
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local write_file = helpers.write_file local write_file = helpers.write_file
local call_viml_function = helpers.meths.nvim_call_function local call_viml_function = helpers.api.nvim_call_function
local function last_set_tests(cmd) local function last_set_tests(cmd)
local script_location, script_file local script_location, script_file

View File

@@ -1,13 +1,13 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local fn = helpers.fn
local command = helpers.command local command = helpers.command
it(':wincmd accepts a count', function() it(':wincmd accepts a count', function()
clear() clear()
command('vsplit') command('vsplit')
eq(1, funcs.winnr()) eq(1, fn.winnr())
command('wincmd 2 w') command('wincmd 2 w')
eq(2, funcs.winnr()) eq(2, fn.winnr())
end) end)

View File

@@ -4,8 +4,8 @@ local eq, eval, clear, write_file, source, insert =
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local command = helpers.command local command = helpers.command
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local skip = helpers.skip local skip = helpers.skip
local is_os = helpers.is_os local is_os = helpers.is_os
local is_ci = helpers.is_ci local is_ci = helpers.is_ci
@@ -112,11 +112,11 @@ describe(':write', function()
eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p test_write/')) eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p test_write/'))
if not is_os('win') then if not is_os('win') then
eq( eq(
('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p .') pcall_err(command, 'write ++p .')
) )
eq( eq(
('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write ++p ./') pcall_err(command, 'write ++p ./')
) )
end end
@@ -125,26 +125,26 @@ describe(':write', function()
it('errors out correctly', function() it('errors out correctly', function()
skip(is_ci('cirrus')) skip(is_ci('cirrus'))
command('let $HOME=""') command('let $HOME=""')
eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) eq(fn.fnamemodify('.', ':p:h'), fn.fnamemodify('.', ':p:h:~'))
-- Message from check_overwrite -- Message from check_overwrite
if not is_os('win') then if not is_os('win') then
eq( eq(
('Vim(write):E17: "' .. funcs.fnamemodify('.', ':p:h') .. '" is a directory'), ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'),
pcall_err(command, 'write .') pcall_err(command, 'write .')
) )
end end
meths.nvim_set_option_value('writeany', true, {}) api.nvim_set_option_value('writeany', true, {})
-- Message from buf_write -- Message from buf_write
eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .')) eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .'))
funcs.mkdir(fname_bak) fn.mkdir(fname_bak)
meths.nvim_set_option_value('backupdir', '.', {}) api.nvim_set_option_value('backupdir', '.', {})
meths.nvim_set_option_value('backup', true, {}) api.nvim_set_option_value('backup', true, {})
write_file(fname, 'content0') write_file(fname, 'content0')
command('edit ' .. fname) command('edit ' .. fname)
funcs.setline(1, 'TTY') fn.setline(1, 'TTY')
eq("Vim(write):E510: Can't make backup file (add ! to override)", pcall_err(command, 'write')) eq("Vim(write):E510: Can't make backup file (add ! to override)", pcall_err(command, 'write'))
meths.nvim_set_option_value('backup', false, {}) api.nvim_set_option_value('backup', false, {})
funcs.setfperm(fname, 'r--------') fn.setfperm(fname, 'r--------')
eq( eq(
'Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', 'Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)',
pcall_err(command, 'write') pcall_err(command, 'write')

View File

@@ -622,7 +622,7 @@ end
module.async_meths = module.create_callindex(module.nvim_async) module.async_meths = module.create_callindex(module.nvim_async)
module.uimeths = module.create_callindex(ui) module.uimeths = module.create_callindex(ui)
local function create_api(request, call) local function create_bridge(request, call)
local function nvim(method, ...) local function nvim(method, ...)
if vim.startswith(method, 'nvim_') then if vim.startswith(method, 'nvim_') then
return request(method, ...) return request(method, ...)
@@ -631,18 +631,13 @@ local function create_api(request, call)
end end
return { return {
funcs = module.create_callindex(call), fn = module.create_callindex(call),
meths = module.create_callindex(nvim), api = module.create_callindex(nvim),
} }
end end
module.rpc = { module.rpc = create_bridge(module.request, module.call)
api = create_api(module.request, module.call), module.lua = create_bridge(module.request_lua, module.call_lua)
}
module.lua = {
api = create_api(module.request_lua, module.call_lua),
}
module.describe_lua_and_rpc = function(describe) module.describe_lua_and_rpc = function(describe)
return function(what, tests) return function(what, tests)
@@ -658,16 +653,16 @@ module.describe_lua_and_rpc = function(describe)
end end
--- add for typing. The for loop after will overwrite this --- add for typing. The for loop after will overwrite this
module.meths = vim.api module.api = vim.api
module.funcs = vim.fn module.fn = vim.fn
for name, fn in pairs(module.rpc.api) do for name, fns in pairs(module.rpc) do
module[name] = fn module[name] = fns
end end
-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but -- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but
-- v:errmsg will not be updated. -- v:errmsg will not be updated.
module.command = module.meths.nvim_command module.command = module.api.nvim_command
function module.poke_eventloop() function module.poke_eventloop()
-- Execute 'nvim_eval' (a deferred function) to -- Execute 'nvim_eval' (a deferred function) to
@@ -682,7 +677,7 @@ end
---@see buf_lines() ---@see buf_lines()
function module.curbuf_contents() function module.curbuf_contents()
module.poke_eventloop() -- Before inspecting the buffer, do whatever. module.poke_eventloop() -- Before inspecting the buffer, do whatever.
return table.concat(module.meths.nvim_buf_get_lines(0, 0, -1, true), '\n') return table.concat(module.api.nvim_buf_get_lines(0, 0, -1, true), '\n')
end end
function module.expect(contents) function module.expect(contents)
@@ -719,15 +714,15 @@ end
-- Asserts that buffer is loaded and visible in the current tabpage. -- Asserts that buffer is loaded and visible in the current tabpage.
function module.assert_visible(bufnr, visible) function module.assert_visible(bufnr, visible)
assert(type(visible) == 'boolean') assert(type(visible) == 'boolean')
eq(visible, module.meths.nvim_buf_is_loaded(bufnr)) eq(visible, module.api.nvim_buf_is_loaded(bufnr))
if visible then if visible then
assert( assert(
-1 ~= module.funcs.bufwinnr(bufnr), -1 ~= module.fn.bufwinnr(bufnr),
'expected buffer to be visible in current tabpage: ' .. tostring(bufnr) 'expected buffer to be visible in current tabpage: ' .. tostring(bufnr)
) )
else else
assert( assert(
-1 == module.funcs.bufwinnr(bufnr), -1 == module.fn.bufwinnr(bufnr),
'expected buffer NOT visible in current tabpage: ' .. tostring(bufnr) 'expected buffer NOT visible in current tabpage: ' .. tostring(bufnr)
) )
end end
@@ -827,17 +822,17 @@ function module.skip_fragile(pending_fn, cond)
end end
function module.exec(code) function module.exec(code)
module.meths.nvim_exec2(code, {}) module.api.nvim_exec2(code, {})
end end
function module.exec_capture(code) function module.exec_capture(code)
return module.meths.nvim_exec2(code, { output = true }).output return module.api.nvim_exec2(code, { output = true }).output
end end
--- @param code string --- @param code string
--- @return any --- @return any
function module.exec_lua(code, ...) function module.exec_lua(code, ...)
return module.meths.exec_lua(code, { ... }) return module.api.exec_lua(code, { ... })
end end
function module.get_pathsep() function module.get_pathsep()
@@ -869,7 +864,7 @@ end
function module.new_pipename() function module.new_pipename()
-- HACK: Start a server temporarily, get the name, then stop it. -- HACK: Start a server temporarily, get the name, then stop it.
local pipename = module.eval('serverstart()') local pipename = module.eval('serverstart()')
module.funcs.serverstop(pipename) module.fn.serverstop(pipename)
-- Remove the pipe so that trying to connect to it without a server listening -- Remove the pipe so that trying to connect to it without a server listening
-- will be an error instead of a hang. -- will be an error instead of a hang.
os.remove(pipename) os.remove(pipename)
@@ -878,11 +873,11 @@ end
function module.missing_provider(provider) function module.missing_provider(provider)
if provider == 'ruby' or provider == 'node' or provider == 'perl' then if provider == 'ruby' or provider == 'node' or provider == 'perl' then
local e = module.funcs['provider#' .. provider .. '#Detect']()[2] local e = module.fn['provider#' .. provider .. '#Detect']()[2]
return e ~= '' and e or false return e ~= '' and e or false
elseif provider == 'python' or provider == 'python3' then elseif provider == 'python' or provider == 'python3' then
local py_major_version = (provider == 'python3' and 3 or 2) local py_major_version = (provider == 'python3' and 3 or 2)
local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2] local e = module.fn['provider#pythonx#Detect'](py_major_version)[2]
return e ~= '' and e or false return e ~= '' and e or false
else else
assert(false, 'Unknown provider: ' .. provider) assert(false, 'Unknown provider: ' .. provider)

View File

@@ -8,8 +8,8 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq local eq = helpers.eq
local neq = helpers.neq local neq = helpers.neq
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local clear = helpers.clear local clear = helpers.clear
local insert = helpers.insert local insert = helpers.insert
local command = helpers.command local command = helpers.command
@@ -56,21 +56,21 @@ describe("'directory' option", function()
line 3 Abcdefghij line 3 Abcdefghij
end of testfile]]) end of testfile]])
meths.nvim_set_option_value('swapfile', true, {}) api.nvim_set_option_value('swapfile', true, {})
meths.nvim_set_option_value('swapfile', true, {}) api.nvim_set_option_value('swapfile', true, {})
meths.nvim_set_option_value('directory', '.', {}) api.nvim_set_option_value('directory', '.', {})
-- sanity check: files should not exist yet. -- sanity check: files should not exist yet.
eq(nil, vim.uv.fs_stat('.Xtest1.swp')) eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
command('edit! Xtest1') command('edit! Xtest1')
poke_eventloop() poke_eventloop()
eq('Xtest1', funcs.buffer_name('%')) eq('Xtest1', fn.buffer_name('%'))
-- Verify that the swapfile exists. In the legacy test this was done by -- Verify that the swapfile exists. In the legacy test this was done by
-- reading the output from :!ls. -- reading the output from :!ls.
neq(nil, vim.uv.fs_stat('.Xtest1.swp')) neq(nil, vim.uv.fs_stat('.Xtest1.swp'))
meths.nvim_set_option_value('directory', './Xtest2,.', {}) api.nvim_set_option_value('directory', './Xtest2,.', {})
command('edit Xtest1') command('edit Xtest1')
poke_eventloop() poke_eventloop()
@@ -79,10 +79,10 @@ describe("'directory' option", function()
eq({ 'Xtest1.swp', 'Xtest3' }, ls_dir_sorted('Xtest2')) eq({ 'Xtest1.swp', 'Xtest3' }, ls_dir_sorted('Xtest2'))
meths.nvim_set_option_value('directory', 'Xtest.je', {}) api.nvim_set_option_value('directory', 'Xtest.je', {})
command('bdelete') command('bdelete')
command('edit Xtest2/Xtest3') command('edit Xtest2/Xtest3')
eq(true, meths.nvim_get_option_value('swapfile', {})) eq(true, api.nvim_get_option_value('swapfile', {}))
poke_eventloop() poke_eventloop()
eq({ 'Xtest3' }, ls_dir_sorted('Xtest2')) eq({ 'Xtest3' }, ls_dir_sorted('Xtest2'))

View File

@@ -2,7 +2,7 @@
-- And test "U" in Visual mode, also on German sharp S. -- And test "U" in Visual mode, also on German sharp S.
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim, eq = helpers.meths, helpers.eq local nvim, eq = helpers.api, helpers.eq
local insert, feed = helpers.insert, helpers.feed local insert, feed = helpers.insert, helpers.feed
local clear, expect = helpers.clear, helpers.expect local clear, expect = helpers.clear, helpers.expect
local feed_command = helpers.feed_command local feed_command = helpers.feed_command

View File

@@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim, call = helpers.meths, helpers.call local nvim, call = helpers.api, helpers.call
local clear, eq = helpers.clear, helpers.eq local clear, eq = helpers.clear, helpers.eq
local source, command = helpers.source, helpers.command local source, command = helpers.source, helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec

View File

@@ -1,11 +1,11 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches local clear, eq, matches = helpers.clear, helpers.eq, helpers.matches
local eval, command, call, meths = helpers.eval, helpers.command, helpers.call, helpers.meths local eval, command, call, api = helpers.eval, helpers.command, helpers.call, helpers.api
local source, exec_capture = helpers.source, helpers.exec_capture local source, exec_capture = helpers.source, helpers.exec_capture
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
local function expected_empty() local function expected_empty()
eq({}, meths.nvim_get_vvar('errors')) eq({}, api.nvim_get_vvar('errors'))
end end
describe('autochdir behavior', function() describe('autochdir behavior', function()

View File

@@ -1,9 +1,9 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim = helpers.meths local nvim = helpers.api
local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval local clear, eq, neq, eval = helpers.clear, helpers.eq, helpers.neq, helpers.eval
local meths = helpers.meths local api = helpers.api
local curbuf = helpers.meths.nvim_get_current_buf local curbuf = helpers.api.nvim_get_current_buf
local curwin = helpers.meths.nvim_get_current_win local curwin = helpers.api.nvim_get_current_win
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local source, command = helpers.source, helpers.command local source, command = helpers.source, helpers.command
@@ -211,7 +211,7 @@ describe('au OptionSet', function()
it('should trigger if the current buffer is different from the targeted buffer', function() it('should trigger if the current buffer is different from the targeted buffer', function()
local new_buffer = make_buffer() local new_buffer = make_buffer()
local new_bufnr = meths.nvim_buf_get_number(new_buffer) local new_bufnr = api.nvim_buf_get_number(new_buffer)
command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
expected_combination({ expected_combination({
@@ -648,7 +648,7 @@ describe('au OptionSet', function()
set_hook('buftype') set_hook('buftype')
local new_buffer = make_buffer() local new_buffer = make_buffer()
local new_bufnr = meths.nvim_buf_get_number(new_buffer) local new_bufnr = api.nvim_buf_get_number(new_buffer)
command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")') command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
expected_combination({ expected_combination({

View File

@@ -1,16 +1,16 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source local clear, source = helpers.clear, helpers.source
local call, eq, meths = helpers.call, helpers.eq, helpers.meths local call, eq, api = helpers.call, helpers.eq, helpers.api
local function expected_empty() local function expected_empty()
eq({}, meths.nvim_get_vvar('errors')) eq({}, api.nvim_get_vvar('errors'))
end end
describe('buffer', function() describe('buffer', function()
before_each(function() before_each(function()
clear() clear()
meths.nvim_ui_attach(80, 24, {}) api.nvim_ui_attach(80, 24, {})
meths.nvim_set_option_value('hidden', false, {}) api.nvim_set_option_value('hidden', false, {})
end) end)
it('deleting a modified buffer with :confirm', function() it('deleting a modified buffer with :confirm', function()

View File

@@ -5,7 +5,7 @@ local command = helpers.command
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local exec = helpers.exec local exec = helpers.exec
local meths = helpers.meths local api = helpers.api
local pesc = vim.pesc local pesc = vim.pesc
describe('cmdline', function() describe('cmdline', function()
@@ -198,9 +198,9 @@ describe('cmdline', function()
[3] = { reverse = true }, -- TabLineFill [3] = { reverse = true }, -- TabLineFill
}) })
screen:attach() screen:attach()
meths.nvim_set_option_value('laststatus', 2, {}) api.nvim_set_option_value('laststatus', 2, {})
meths.nvim_set_option_value('showtabline', 2, {}) api.nvim_set_option_value('showtabline', 2, {})
meths.nvim_set_option_value('cmdheight', 1, {}) api.nvim_set_option_value('cmdheight', 1, {})
screen:expect([[ screen:expect([[
{2: [No Name] }{3: }| {2: [No Name] }{3: }|
^ | ^ |
@@ -217,10 +217,10 @@ describe('cmdline', function()
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
} }
screen:attach() screen:attach()
meths.nvim_set_option_value('ruler', true, {}) api.nvim_set_option_value('ruler', true, {})
meths.nvim_set_option_value('rulerformat', 'longish', {}) api.nvim_set_option_value('rulerformat', 'longish', {})
meths.nvim_set_option_value('laststatus', 0, {}) api.nvim_set_option_value('laststatus', 0, {})
meths.nvim_set_option_value('winwidth', 1, {}) api.nvim_set_option_value('winwidth', 1, {})
feed [[<C-W>v<C-W>|<C-W>p]] feed [[<C-W>v<C-W>|<C-W>p]]
screen:expect [[ screen:expect [[
│^ | │^ |

View File

@@ -5,7 +5,7 @@ local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
before_each(clear) before_each(clear)
@@ -16,7 +16,7 @@ describe('Ex mode', function()
feed('gQ' .. cmd .. '<C-b>"<CR>') feed('gQ' .. cmd .. '<C-b>"<CR>')
local ret = eval('@:[1:]') -- Remove leading quote. local ret = eval('@:[1:]') -- Remove leading quote.
feed('visual<CR>') feed('visual<CR>')
eq(meths.nvim_replace_termcodes(expected, true, true, true), ret) eq(api.nvim_replace_termcodes(expected, true, true, true), ret)
end end
command('set sw=2') command('set sw=2')
test_ex_edit('bar', 'foo bar<C-u>bar') test_ex_edit('bar', 'foo bar<C-u>bar')

View File

@@ -6,8 +6,8 @@ local exec = helpers.exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local meths = helpers.meths local api = helpers.api
local read_file = helpers.read_file local read_file = helpers.read_file
local source = helpers.source local source = helpers.source
local eq = helpers.eq local eq = helpers.eq
@@ -24,7 +24,7 @@ end
describe('Ex command', function() describe('Ex command', function()
before_each(clear) before_each(clear)
after_each(function() after_each(function()
eq({}, meths.nvim_get_vvar('errors')) eq({}, api.nvim_get_vvar('errors'))
end) end)
it('checks for address line overflow', function() it('checks for address line overflow', function()
@@ -340,7 +340,7 @@ describe(':confirm command dialog', function()
feed('<CR>') -- suppress hit-enter prompt feed('<CR>') -- suppress hit-enter prompt
-- Try to write with read-only file permissions. -- Try to write with read-only file permissions.
funcs.setfperm('Xconfirm_write_ro', 'r--r--r--') fn.setfperm('Xconfirm_write_ro', 'r--r--r--')
feed(':set noro | silent undo | confirm w\n') feed(':set noro | silent undo | confirm w\n')
screen:expect([[ screen:expect([[
foobar | foobar |

View File

@@ -1,19 +1,19 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source local clear, source = helpers.clear, helpers.source
local call, eq, meths = helpers.call, helpers.eq, helpers.meths local call, eq, api = helpers.call, helpers.eq, helpers.api
local is_os = helpers.is_os local is_os = helpers.is_os
local skip = helpers.skip local skip = helpers.skip
local function expected_empty() local function expected_empty()
eq({}, meths.nvim_get_vvar('errors')) eq({}, api.nvim_get_vvar('errors'))
end end
describe('file changed dialog', function() describe('file changed dialog', function()
before_each(function() before_each(function()
clear() clear()
meths.nvim_ui_attach(80, 24, {}) api.nvim_ui_attach(80, 24, {})
meths.nvim_set_option_value('autoread', false, {}) api.nvim_set_option_value('autoread', false, {})
meths.nvim_set_option_value('fsync', true, {}) api.nvim_set_option_value('fsync', true, {})
end) end)
it('works', function() it('works', function()

View File

@@ -2,7 +2,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, source = helpers.clear, helpers.source local clear, source = helpers.clear, helpers.source
local call, eq, nvim = helpers.call, helpers.eq, helpers.meths local call, eq, nvim = helpers.call, helpers.eq, helpers.api
local function expected_empty() local function expected_empty()
eq({}, nvim.nvim_get_vvar('errors')) eq({}, nvim.nvim_get_vvar('errors'))

View File

@@ -3,7 +3,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local source, command = helpers.source, helpers.command local source, command = helpers.source, helpers.command
local call, clear = helpers.call, helpers.clear local call, clear = helpers.call, helpers.clear
local eq, nvim = helpers.eq, helpers.meths local eq, nvim = helpers.eq, helpers.api
describe('Ctrl-A/Ctrl-X on visual selections', function() describe('Ctrl-A/Ctrl-X on visual selections', function()
before_each(function() before_each(function()

View File

@@ -3,7 +3,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop local expect, poke_eventloop = helpers.expect, helpers.poke_eventloop
local command, eq, eval, meths = helpers.command, helpers.eq, helpers.eval, helpers.meths local command, eq, eval, api = helpers.command, helpers.eq, helpers.eval, helpers.api
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
describe('mapping', function() describe('mapping', function()
@@ -134,9 +134,9 @@ describe('mapping', function()
command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>') command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>')
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'press', '', 0, 0, 0) api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'drag', '', 0, 0, 1) api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
poke_eventloop() poke_eventloop()
eq('s', eval('mode()')) eq('s', eval('mode()'))
end) end)
@@ -147,9 +147,9 @@ describe('mapping', function()
command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>') command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>')
feed('i') feed('i')
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'press', '', 0, 0, 0) api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'drag', '', 0, 0, 1) api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
poke_eventloop() poke_eventloop()
eq(1, eval('g:dragged')) eq(1, eval('g:dragged'))
eq('v', eval('mode()')) eq('v', eval('mode()'))
@@ -158,9 +158,9 @@ describe('mapping', function()
command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]]) command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]])
feed('i') feed('i')
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'press', '', 0, 0, 0) api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
poke_eventloop() poke_eventloop()
meths.nvim_input_mouse('left', 'drag', '', 0, 0, 1) api.nvim_input_mouse('left', 'drag', '', 0, 0, 1)
poke_eventloop() poke_eventloop()
eq('n', eval('mode()')) eq('n', eval('mode()'))
end) end)

View File

@@ -4,7 +4,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
local nvim_dir = helpers.nvim_dir local nvim_dir = helpers.nvim_dir
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@@ -410,9 +410,9 @@ describe('messages', function()
screen:attach() screen:attach()
command('cd ' .. nvim_dir) command('cd ' .. nvim_dir)
meths.nvim_set_option_value('shell', './shell-test', {}) api.nvim_set_option_value('shell', './shell-test', {})
meths.nvim_set_option_value('shellcmdflag', 'REP 20', {}) api.nvim_set_option_value('shellcmdflag', 'REP 20', {})
meths.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes api.nvim_set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
-- display a page and go back, results in exactly the same view -- display a page and go back, results in exactly the same view
feed([[:4 verbose echo system('foo')<CR>]]) feed([[:4 verbose echo system('foo')<CR>]])

View File

@@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local fn = helpers.fn
local eq = helpers.eq local eq = helpers.eq
describe('mksession', function() describe('mksession', function()
@@ -18,7 +18,7 @@ describe('mksession', function()
command('mksession! Xtest_mks.out') command('mksession! Xtest_mks.out')
local found_rtp = 0 local found_rtp = 0
local found_pp = 0 local found_pp = 0
for _, line in pairs(funcs.readfile('Xtest_mks.out', 'b')) do for _, line in pairs(fn.readfile('Xtest_mks.out', 'b')) do
if line:find('set runtimepath') then if line:find('set runtimepath') then
found_rtp = found_rtp + 1 found_rtp = found_rtp + 1
end end
@@ -32,7 +32,7 @@ describe('mksession', function()
command('set sessionoptions+=skiprtp') command('set sessionoptions+=skiprtp')
command('mksession! Xtest_mks.out') command('mksession! Xtest_mks.out')
local found_rtp_or_pp = 0 local found_rtp_or_pp = 0
for _, line in pairs(funcs.readfile('Xtest_mks.out', 'b')) do for _, line in pairs(fn.readfile('Xtest_mks.out', 'b')) do
if line:find('set runtimepath') or line:find('set packpath') then if line:find('set runtimepath') or line:find('set packpath') then
found_rtp_or_pp = found_rtp_or_pp + 1 found_rtp_or_pp = found_rtp_or_pp + 1
end end

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
before_each(clear) before_each(clear)
@@ -15,7 +15,7 @@ describe(':move', function()
}) })
screen:attach() screen:attach()
funcs.setline(1, { 'First', 'Second', 'Third', 'Fourth' }) fn.setline(1, { 'First', 'Second', 'Third', 'Fourth' })
feed('gg:move +1<CR>') feed('gg:move +1<CR>')
screen:expect([[ screen:expect([[
Second | Second |

View File

@@ -5,7 +5,7 @@ local source = helpers.source
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local meths = helpers.meths local api = helpers.api
local eq = helpers.eq local eq = helpers.eq
local neq = helpers.neq local neq = helpers.neq
@@ -180,12 +180,12 @@ describe('prompt buffer', function()
call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])}) call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])})
]] ]]
poke_eventloop() poke_eventloop()
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
end) end)
-- oldtest: Test_prompt_appending_while_hidden() -- oldtest: Test_prompt_appending_while_hidden()
it('accessing hidden prompt buffer does not start insert mode', function() it('accessing hidden prompt buffer does not start insert mode', function()
local prev_win = meths.nvim_get_current_win() local prev_win = api.nvim_get_current_win()
source([[ source([[
new prompt new prompt
set buftype=prompt set buftype=prompt
@@ -205,16 +205,16 @@ describe('prompt buffer', function()
endfunc endfunc
]]) ]])
feed('asomething<CR>') feed('asomething<CR>')
eq('something', meths.nvim_get_var('entered')) eq('something', api.nvim_get_var('entered'))
neq(prev_win, meths.nvim_get_current_win()) neq(prev_win, api.nvim_get_current_win())
feed('exit<CR>') feed('exit<CR>')
eq(prev_win, meths.nvim_get_current_win()) eq(prev_win, api.nvim_get_current_win())
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
command('call DoAppend()') command('call DoAppend()')
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
feed('i') feed('i')
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
command('call DoAppend()') command('call DoAppend()')
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
end) end)
end) end)

View File

@@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local meths = helpers.meths local api = helpers.api
local source = helpers.source local source = helpers.source
local eq = helpers.eq local eq = helpers.eq
@@ -16,7 +16,7 @@ end
describe('put', function() describe('put', function()
before_each(clear) before_each(clear)
after_each(function() after_each(function()
eq({}, meths.nvim_get_vvar('errors')) eq({}, api.nvim_get_vvar('errors'))
end) end)
it('very large count 64-bit', function() it('very large count 64-bit', function()

View File

@@ -5,7 +5,7 @@ local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local fn = helpers.fn
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local exec = helpers.exec local exec = helpers.exec
@@ -27,7 +27,7 @@ describe('search cmdline', function()
end) end)
local function tenlines() local function tenlines()
funcs.setline(1, { fn.setline(1, {
' 1', ' 1',
' 2 these', ' 2 these',
' 3 the', ' 3 the',
@@ -68,7 +68,7 @@ describe('search cmdline', function()
3 {inc:the} | 3 {inc:the} |
/the^ | /the^ |
]]) ]])
eq({ 0, 0, 0, 0 }, funcs.getpos('"')) eq({ 0, 0, 0, 0 }, fn.getpos('"'))
feed('<C-G>') feed('<C-G>')
screen:expect([[ screen:expect([[
3 the | 3 the |
@@ -125,7 +125,7 @@ describe('search cmdline', function()
end, end,
} }
feed('<CR>') feed('<CR>')
eq({ 0, 0, 0, 0 }, funcs.getpos('"')) eq({ 0, 0, 0, 0 }, fn.getpos('"'))
end end
end end
@@ -368,7 +368,7 @@ describe('search cmdline', function()
end) end)
it('can traverse matches in the same line with <C-G>/<C-T>', function() it('can traverse matches in the same line with <C-G>/<C-T>', function()
funcs.setline(1, { ' 1', ' 2 these', ' 3 the theother' }) fn.setline(1, { ' 1', ' 2 these', ' 3 the theother' })
command('1') command('1')
command('set incsearch') command('set incsearch')
@@ -465,7 +465,7 @@ describe('search cmdline', function()
coladd = 0, coladd = 0,
skipcol = 0, skipcol = 0,
curswant = 4, curswant = 4,
}, funcs.winsaveview()) }, fn.winsaveview())
end) end)
it('restores original view after failed search', function() it('restores original view after failed search', function()
@@ -500,14 +500,14 @@ describe('search cmdline', function()
coladd = 0, coladd = 0,
skipcol = 0, skipcol = 0,
curswant = 0, curswant = 0,
}, funcs.winsaveview()) }, fn.winsaveview())
end) end)
-- oldtest: Test_search_cmdline4(). -- oldtest: Test_search_cmdline4().
it("CTRL-G with 'incsearch' and ? goes in the right direction", function() it("CTRL-G with 'incsearch' and ? goes in the right direction", function()
screen:try_resize(40, 4) screen:try_resize(40, 4)
command('enew!') command('enew!')
funcs.setline(1, { ' 1 the first', ' 2 the second', ' 3 the third' }) fn.setline(1, { ' 1 the first', ' 2 the second', ' 3 the third' })
command('set laststatus=0 shortmess+=s') command('set laststatus=0 shortmess+=s')
command('set incsearch') command('set incsearch')
command('$') command('$')
@@ -608,7 +608,7 @@ describe('search cmdline', function()
it('incsearch works with :sort', function() it('incsearch works with :sort', function()
screen:try_resize(20, 4) screen:try_resize(20, 4)
command('set incsearch hlsearch scrolloff=0') command('set incsearch hlsearch scrolloff=0')
funcs.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' })
feed(':sort ni u /on') feed(':sort ni u /on')
screen:expect([[ screen:expect([[
@@ -624,7 +624,7 @@ describe('search cmdline', function()
it('incsearch works with :vimgrep family', function() it('incsearch works with :vimgrep family', function()
screen:try_resize(30, 4) screen:try_resize(30, 4)
command('set incsearch hlsearch scrolloff=0') command('set incsearch hlsearch scrolloff=0')
funcs.setline(1, { 'another one 2', 'that one 3', 'the one 1' }) fn.setline(1, { 'another one 2', 'that one 3', 'the one 1' })
feed(':vimgrep on') feed(':vimgrep on')
screen:expect([[ screen:expect([[

View File

@@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local source, clear = helpers.source, helpers.clear local source, clear = helpers.source, helpers.clear
local eq, nvim = helpers.eq, helpers.meths local eq, nvim = helpers.eq, helpers.api
describe('undolevel', function() describe('undolevel', function()
setup(clear) setup(clear)

View File

@@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local exec = helpers.exec local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths local api = helpers.api
before_each(clear) before_each(clear)
@@ -12,7 +12,7 @@ describe('Vim script', function()
it('Error when if/for/while/try/function is nested too deep', function() it('Error when if/for/while/try/function is nested too deep', function()
local screen = Screen.new(80, 24) local screen = Screen.new(80, 24)
screen:attach() screen:attach()
meths.nvim_set_option_value('laststatus', 2, {}) api.nvim_set_option_value('laststatus', 2, {})
exec([[ exec([[
" Deep nesting of if ... endif " Deep nesting of if ... endif
func Test1() func Test1()

Some files were not shown because too many files have changed in this diff Show More