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 clear = helpers.clear
local eq, ok = helpers.eq, helpers.ok
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg
local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err
@ -24,7 +24,7 @@ local function expectn(name, args)
end
local function sendkeys(keys)
meths.nvim_input(keys)
api.nvim_input(keys)
-- give nvim some time to process msgpack requests before possibly sending
-- more key presses - otherwise they all pile up in the queue and get
-- processed at once
@ -37,7 +37,7 @@ local function open(activate, lines)
local filename = helpers.tmpname()
write_file(filename, table.concat(lines, '\n') .. '\n', true)
command('edit ' .. filename)
local b = meths.nvim_get_current_buf()
local b = api.nvim_get_current_buf()
-- what is the value of b:changedtick?
local tick = eval('b:changedtick')
@ -45,7 +45,7 @@ local function open(activate, lines)
-- arrive as expected
if activate then
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 })
end
@ -62,12 +62,12 @@ local function editoriginal(activate, lines)
end
local function reopen(buf, expectedlines)
ok(meths.nvim_buf_detach(buf))
ok(api.nvim_buf_detach(buf))
expectn('nvim_buf_detach_event', { buf })
-- for some reason the :edit! increments tick by 2
command('edit!')
local tick = eval('b:changedtick')
ok(meths.nvim_buf_attach(buf, true, {}))
ok(api.nvim_buf_attach(buf, true, {}))
local firstline = 0
expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false })
command('normal! gg')
@ -197,21 +197,21 @@ describe('API: buffer events:', function()
-- add a line at the start of an empty file
command('enew')
tick = eval('b:changedtick')
local b2 = meths.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b2, true, {}))
local b2 = api.nvim_get_current_buf()
ok(api.nvim_buf_attach(b2, true, {}))
expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false })
eval('append(0, ["new line 1"])')
tick = tick + 1
expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false })
-- turn off buffer events manually
meths.nvim_buf_detach(b2)
api.nvim_buf_detach(b2)
expectn('nvim_buf_detach_event', { b2 })
-- add multiple lines to a blank file
command('enew!')
local b3 = meths.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b3, true, {}))
local b3 = api.nvim_get_current_buf()
ok(api.nvim_buf_attach(b3, true, {}))
tick = eval('b:changedtick')
expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false })
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
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
expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false })
end)
@ -306,8 +306,8 @@ describe('API: buffer events:', function()
command('bdelete!')
tick = 2
expectn('nvim_buf_detach_event', { b })
local bnew = meths.nvim_get_current_buf()
ok(meths.nvim_buf_attach(bnew, true, {}))
local bnew = api.nvim_get_current_buf()
ok(api.nvim_buf_attach(bnew, true, {}))
expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false })
sendkeys('i')
sendkeys('h')
@ -472,25 +472,25 @@ describe('API: buffer events:', function()
end)
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)
-- Enable buffer events many times.
ok(meths.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {}))
ok(meths.nvim_buf_attach(b, true, {}))
ok(api.nvim_buf_attach(b, true, {}))
ok(api.nvim_buf_attach(b, true, {}))
ok(api.nvim_buf_attach(b, true, {}))
ok(api.nvim_buf_attach(b, true, {}))
ok(api.nvim_buf_attach(b, true, {}))
expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false })
eval('rpcnotify(' .. channel .. ', "Hello There")')
expectn('Hello There', {})
-- Disable buffer events many times.
ok(meths.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b))
ok(meths.nvim_buf_detach(b))
ok(api.nvim_buf_detach(b))
ok(api.nvim_buf_detach(b))
ok(api.nvim_buf_detach(b))
ok(api.nvim_buf_detach(b))
ok(api.nvim_buf_detach(b))
expectn('nvim_buf_detach_event', { b })
eval('rpcnotify(' .. channel .. ', "Hello Again")')
expectn('Hello Again', {})
@ -573,7 +573,7 @@ describe('API: buffer events:', function()
it('works with :diffput and :diffget', function()
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('rightbelow vsplit')
local b2, tick2 = open(true, { 'BBB', 'CCC' })
@ -690,7 +690,7 @@ describe('API: buffer events:', function()
it('detaches if the buffer is closed', function()
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.
command('normal! x')
@ -729,7 +729,7 @@ describe('API: buffer events:', function()
it(':enew! does not detach hidden buffer', function()
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('normal! x')
@ -743,7 +743,7 @@ describe('API: buffer events:', function()
it('stays attached if the buffer is hidden', function()
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.
command('normal! x')
@ -790,14 +790,14 @@ describe('API: buffer events:', function()
it('does not send the buffer content if not requested', function()
clear()
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 })
end)
it('returns a proper error on nonempty options dict', function()
clear()
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)
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()
local buffer_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') },
})
local b = meths.nvim_get_current_buf()
ok(meths.nvim_buf_attach(b, true, {}))
local b = api.nvim_get_current_buf()
ok(api.nvim_buf_attach(b, true, {}))
for _ = 1, 22 do
table.insert(expected_lines, '~')

View File

@ -4,14 +4,14 @@ local NIL = vim.NIL
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local meths = helpers.meths
local api = helpers.api
local matches = helpers.matches
local source = helpers.source
local pcall_err = helpers.pcall_err
local exec_lua = helpers.exec_lua
local assert_alive = helpers.assert_alive
local feed = helpers.feed
local funcs = helpers.funcs
local fn = helpers.fn
describe('nvim_get_commands', function()
local cmd_dict = {
@ -49,39 +49,39 @@ describe('nvim_get_commands', function()
before_each(clear)
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)
it('validation', function()
eq('builtin=true not implemented', pcall_err(meths.nvim_get_commands, { builtin = true }))
eq("Invalid key: 'foo'", pcall_err(meths.nvim_get_commands, { foo = 'blah' }))
eq('builtin=true not implemented', pcall_err(api.nvim_get_commands, { builtin = true }))
eq("Invalid key: 'foo'", pcall_err(api.nvim_get_commands, { foo = 'blah' }))
end)
it('gets global user-defined commands', function()
-- Define a command.
command('command -nargs=1 Hello echo "Hello World"')
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false }))
eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
-- Define another command.
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.
command('delcommand Pwd')
eq({ Hello = cmd_dict }, meths.nvim_get_commands({ builtin = false }))
eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
end)
it('gets buffer-local user-defined commands', function()
-- Define a buffer-local command.
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.
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.
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.
eq({}, meths.nvim_buf_get_commands(0, { builtin = true }))
eq({}, api.nvim_buf_get_commands(0, { builtin = true }))
end)
it('gets various command attributes', function()
@ -169,9 +169,9 @@ describe('nvim_get_commands', function()
let s:foo = 1
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>')
eq({ Finger = cmd1, TestCmd = cmd0 }, meths.nvim_get_commands({ builtin = false }))
eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false }))
source([[
function! s:foo() abort
@ -191,7 +191,7 @@ describe('nvim_get_commands', function()
-- TODO(justinmk): Order is stable but undefined. Sort before return?
eq(
{ Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 },
meths.nvim_get_commands({ builtin = false })
api.nvim_get_commands({ builtin = false })
)
end)
end)
@ -200,9 +200,9 @@ describe('nvim_create_user_command', function()
before_each(clear)
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')
eq(42, meths.nvim_eval('g:command_fired'))
eq(42, api.nvim_eval('g:command_fired'))
end)
it('works with Lua functions', function()
@ -644,10 +644,10 @@ describe('nvim_create_user_command', function()
end)
it('can define buffer-local commands', function()
local bufnr = meths.nvim_create_buf(false, false)
meths.nvim_buf_create_user_command(bufnr, 'Hello', '', {})
local bufnr = api.nvim_create_buf(false, false)
api.nvim_buf_create_user_command(bufnr, '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')
assert_alive()
end)
@ -670,9 +670,9 @@ describe('nvim_create_user_command', function()
]]
feed(':Test a<Tab>')
eq('Test aaa', funcs.getcmdline())
eq('Test aaa', fn.getcmdline())
feed('<C-U>Test b<Tab>')
eq('Test bbb', funcs.getcmdline())
eq('Test bbb', fn.getcmdline())
end)
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 }, {})
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 [[
vim.api.nvim_create_user_command('MySplit', function(opts)
vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {})
end, {})
]]
meths.nvim_cmd({ cmd = 'MySplit' }, {})
eq(1, #meths.nvim_list_tabpages())
eq(2, #meths.nvim_list_wins())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(2, #meths.nvim_list_tabpages())
eq(2, funcs.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(3, #meths.nvim_list_tabpages())
eq(2, funcs.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
eq(4, #meths.nvim_list_tabpages())
eq(4, funcs.tabpagenr())
meths.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
eq(5, #meths.nvim_list_tabpages())
eq(1, funcs.tabpagenr())
api.nvim_cmd({ cmd = 'MySplit' }, {})
eq(1, #api.nvim_list_tabpages())
eq(2, #api.nvim_list_wins())
api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(2, #api.nvim_list_tabpages())
eq(2, fn.tabpagenr())
api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
eq(3, #api.nvim_list_tabpages())
eq(2, fn.tabpagenr())
api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
eq(4, #api.nvim_list_tabpages())
eq(4, fn.tabpagenr())
api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
eq(5, #api.nvim_list_tabpages())
eq(1, fn.tabpagenr())
end)
end)
@ -759,16 +759,16 @@ describe('nvim_del_user_command', function()
before_each(clear)
it('can delete global commands', function()
meths.nvim_create_user_command('Hello', 'echo "Hi"', {})
api.nvim_create_user_command('Hello', 'echo "Hi"', {})
command('Hello')
meths.nvim_del_user_command('Hello')
api.nvim_del_user_command('Hello')
matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
end)
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')
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'))
end)
end)

View File

@ -10,7 +10,7 @@ local feed = helpers.feed
local clear = helpers.clear
local command = helpers.command
local exec = helpers.exec
local meths = helpers.meths
local api = helpers.api
local assert_alive = helpers.assert_alive
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
opts.id = id
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
local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then
opts = {}
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
local function get_extmark_by_id(ns_id, id, opts)
if opts == nil then
opts = {}
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
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)
-- remove the test marks
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[1]))
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[1]))
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[2]))
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[3]))
eq(false, meths.nvim_buf_del_extmark(0, ns, 1000))
eq(true, api.nvim_buf_del_extmark(0, ns, marks[1]))
eq(false, api.nvim_buf_del_extmark(0, ns, marks[1]))
eq(true, api.nvim_buf_del_extmark(0, ns, marks[2]))
eq(false, api.nvim_buf_del_extmark(0, ns, marks[3]))
eq(false, api.nvim_buf_del_extmark(0, ns, 1000))
end)
it('can clear a specific namespace range', function()
@ -208,7 +208,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer
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({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u')
@ -224,7 +224,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer
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(ns2, { 0, 0 }, { -1, -1 }))
feed('u')
@ -242,14 +242,14 @@ describe('API/extmarks', function()
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('dd')
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 }))
set_extmark(ns, 1, 0, 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 }))
feed('u')
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)
it('querying for information and ranges', function()
@ -931,7 +931,7 @@ describe('API/extmarks', function()
-- Test unset
feed('o<esc>')
meths.nvim_buf_del_extmark(0, ns, marks[3])
api.nvim_buf_del_extmark(0, ns, marks[3])
feed('u')
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
-- undo does NOT restore deleted marks
@ -987,10 +987,10 @@ describe('API/extmarks', function()
rv = get_extmarks(ns2, positions[2], positions[1])
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 })
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 })
eq(2, #rv)
end)
@ -1427,7 +1427,7 @@ describe('API/extmarks', function()
"Invalid 'ns_id': 3",
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_extmark_by_id, ns_invalid, marks[1]))
end)
@ -1470,7 +1470,7 @@ describe('API/extmarks', function()
it('in read-only buffer', function()
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)
eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
end)
@ -1478,8 +1478,8 @@ describe('API/extmarks', function()
it('can set a mark to other buffer', function()
local buf = request('nvim_create_buf', 0, 1)
request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
local id = meths.nvim_buf_set_extmark(buf, ns, 1, 0, {})
eq({ { id, 1, 0 } }, meths.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
local id = api.nvim_buf_set_extmark(buf, ns, 1, 0, {})
eq({ { id, 1, 0 } }, api.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
end)
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()
-- right gravity should move with inserted text, while
-- left gravity should stay in place.
meths.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 = false })
api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
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
feed([[<esc>Iasdf<esc>]])
-- eq({}, meths.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({}, api.nvim_buf_get_lines(0, 0, -1, true))
eq({ { 1, 0, 9 }, { 2, 0, 17 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
-- 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
eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
meths.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, 0 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
api.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
feed('u')
-- handles pasting
exec([[let @a='asdfasdf']])
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)
it('can accept "end_row" or "end_line" #16548', function()
@ -1545,7 +1545,7 @@ describe('API/extmarks', function()
it('in prompt buffer', function()
feed('dd')
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>')
eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
end)
@ -1639,7 +1639,7 @@ describe('API/extmarks', function()
right_gravity = 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
command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
command('sign place 1 name=sign1 line=1')
@ -1693,7 +1693,7 @@ describe('API/extmarks', function()
screen = Screen.new(40, 6)
screen:attach()
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, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 })
-- mark with invalidate is removed
@ -1768,7 +1768,7 @@ describe('Extmarks buffer api with many marks', function()
for i = 1, 30 do
lines[#lines + 1] = string.rep('x ', i)
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 q = 0
for i = 0, 29 do
@ -1802,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function()
end)
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(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(ns2))
end)
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
if 10 <= mark[1] and mark[1] < 20 then
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 command = helpers.command
local exec_capture = helpers.exec_capture
local meths = helpers.meths
local funcs = helpers.funcs
local api = helpers.api
local fn = helpers.fn
local pcall_err = helpers.pcall_err
local ok = helpers.ok
local assert_alive = helpers.assert_alive
@ -52,128 +52,125 @@ describe('API: highlight', function()
it('nvim_get_hl_by_id', function()
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')")
-- 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.
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.
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
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.
eq(
'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.
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.
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.
command('hi Normal ctermfg=red ctermbg=yellow')
command('hi NewConstant ctermfg=green guifg=white guibg=blue')
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.
command('hi clear NewConstant')
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.
command('hi clear NewConstant')
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)
it('nvim_get_hl_by_name', function()
local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red }
-- 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_rgb, meths.nvim_get_hl_by_name('NewHighlight', true))
eq(expected_cterm, api.nvim_get_hl_by_name('NewHighlight', false))
eq(expected_rgb, api.nvim_get_hl_by_name('NewHighlight', true))
-- Test `Normal` modified values.
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.
eq(
"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.
eq(
'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.
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
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('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
-- Ensure Normal, and groups that match Normal return their fg & bg cterm values
meths.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, 'Normal', { ctermfg = 17, ctermbg = 213 })
api.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true })
-- 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(
{ foreground = 17, background = 213, nocombine = true },
meths.nvim_get_hl_by_name('NotNormal', false)
api.nvim_get_hl_by_name('NotNormal', false)
)
end)
it('nvim_get_hl_id_by_name', function()
-- precondition: use a hl group that does not yet exist
eq(
"Invalid highlight name: 'Shrubbery'",
pcall_err(meths.nvim_get_hl_by_name, 'Shrubbery', true)
)
eq(0, funcs.hlID('Shrubbery'))
eq("Invalid highlight name: 'Shrubbery'", pcall_err(api.nvim_get_hl_by_name, 'Shrubbery', true))
eq(0, fn.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)
eq(hl_id, funcs.hlID('Shrubbery'))
eq(hl_id, fn.hlID('Shrubbery'))
command('hi Shrubbery guifg=#888888 guibg=#888888')
eq(
{ 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(
{ foreground = tonumber('0x888888'), background = tonumber('0x888888') },
meths.nvim_get_hl_by_name('Shrubbery', true)
api.nvim_get_hl_by_name('Shrubbery', true)
)
end)
it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function()
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)
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)
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)
assert_alive()
end)
@ -244,8 +241,8 @@ describe('API: set highlight', function()
}
local function get_ns()
local ns = meths.nvim_create_namespace('Test_set_hl')
meths.nvim_set_hl_ns(ns)
local ns = api.nvim_create_namespace('Test_set_hl')
api.nvim_set_hl_ns(ns)
return ns
end
@ -254,51 +251,51 @@ describe('API: set highlight', function()
it('validation', function()
eq(
"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(
"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)
it('can set gui highlight', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl_by_name('Test_hl', true))
api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, api.nvim_get_hl_by_name('Test_hl', true))
end)
it('can set cterm highlight', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight2_config)
eq(highlight2_result, meths.nvim_get_hl_by_name('Test_hl', false))
api.nvim_set_hl(ns, 'Test_hl', highlight2_config)
eq(highlight2_result, api.nvim_get_hl_by_name('Test_hl', false))
end)
it('can set empty cterm attr', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.nvim_get_hl_by_name('Test_hl', false))
api.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, api.nvim_get_hl_by_name('Test_hl', false))
end)
it('cterm attr defaults to gui attr', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1)
api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq({
bold = true,
italic = true,
}, meths.nvim_get_hl_by_name('Test_hl', false))
}, api.nvim_get_hl_by_name('Test_hl', false))
end)
it('can overwrite attr for cterm', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result_gui, meths.nvim_get_hl_by_name('Test_hl', true))
eq(highlight3_result_cterm, meths.nvim_get_hl_by_name('Test_hl', false))
api.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result_gui, api.nvim_get_hl_by_name('Test_hl', true))
eq(highlight3_result_cterm, api.nvim_get_hl_by_name('Test_hl', false))
end)
it('only allows one underline attribute #22371', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', {
api.nvim_set_hl(ns, 'Test_hl', {
underdouble = true,
underdotted = true,
cterm = {
@ -306,21 +303,21 @@ describe('API: set highlight', function()
undercurl = true,
},
})
eq({ undercurl = true }, meths.nvim_get_hl_by_name('Test_hl', false))
eq({ underdotted = true }, meths.nvim_get_hl_by_name('Test_hl', true))
eq({ undercurl = true }, api.nvim_get_hl_by_name('Test_hl', false))
eq({ underdotted = true }, api.nvim_get_hl_by_name('Test_hl', true))
end)
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(
'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse',
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'))
meths.nvim_set_hl(0, 'Test_hl2', highlight3_config)
api.nvim_set_hl(0, 'Test_hl2', highlight3_config)
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',
exec_capture('highlight Test_hl2')
@ -328,63 +325,63 @@ describe('API: set highlight', function()
-- Colors are stored with the name they are defined, but
-- 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'))
end)
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'))
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'))
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'))
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'))
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(
"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(
"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(
"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
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'))
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'))
end)
it("correctly sets 'Normal' internal properties", function()
-- Normal has some special handling internally. #18024
meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' })
eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true))
api.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' })
eq({ foreground = 131, background = 243 }, api.nvim_get_hl_by_name('Normal', true))
end)
it('does not segfault on invalid group name #20009', function()
eq(
"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()
end)
@ -452,14 +449,14 @@ describe('API: get highlight', function()
local function get_ns()
-- Test namespace filtering behavior
local ns2 = meths.nvim_create_namespace('Another_namespace')
meths.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 })
meths.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' })
meths.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' })
meths.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' })
local ns2 = api.nvim_create_namespace('Another_namespace')
api.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 })
api.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' })
api.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' })
api.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' })
local ns = meths.nvim_create_namespace('Test_set_hl')
meths.nvim_set_hl_ns(ns)
local ns = api.nvim_create_namespace('Test_set_hl')
api.nvim_set_hl_ns(ns)
return ns
end
@ -469,24 +466,24 @@ describe('API: get highlight', function()
it('validation', function()
eq(
"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)
it('nvim_get_hl with create flag', function()
eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false }))
eq(0, funcs.hlexists('Foo'))
meths.nvim_get_hl(0, { name = 'Bar', create = true })
eq(1, funcs.hlexists('Bar'))
meths.nvim_get_hl(0, { name = 'FooBar' })
eq(1, funcs.hlexists('FooBar'))
eq({}, api.nvim_get_hl(0, { name = 'Foo', create = false }))
eq(0, fn.hlexists('Foo'))
api.nvim_get_hl(0, { name = 'Bar', create = true })
eq(1, fn.hlexists('Bar'))
api.nvim_get_hl(0, { name = 'FooBar' })
eq(1, fn.hlexists('FooBar'))
end)
it('can get all highlights in current namespace', function()
local ns = get_ns()
meths.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', { bg = '#B4BEFE' })
api.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' })
eq({
Test_hl = {
bg = 11845374,
@ -494,42 +491,42 @@ describe('API: get highlight', function()
Test_hl_link = {
link = 'Test_hl',
},
}, meths.nvim_get_hl(ns, {}))
}, api.nvim_get_hl(ns, {}))
end)
it('can get gui highlight', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' }))
api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end)
it('can get cterm highlight', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight2)
eq(highlight2, meths.nvim_get_hl(ns, { name = 'Test_hl' }))
api.nvim_set_hl(ns, 'Test_hl', highlight2)
eq(highlight2, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end)
it('can get empty cterm attr', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.nvim_get_hl(ns, { name = 'Test_hl' }))
api.nvim_set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end)
it('cterm attr defaults to gui attr', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' }))
api.nvim_set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end)
it('can overwrite attr for cterm', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result, meths.nvim_get_hl(ns, { name = 'Test_hl' }))
api.nvim_set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result, api.nvim_get_hl(ns, { name = 'Test_hl' }))
end)
it('only allows one underline attribute #22371', function()
local ns = get_ns()
meths.nvim_set_hl(ns, 'Test_hl', {
api.nvim_set_hl(ns, 'Test_hl', {
underdouble = true,
underdotted = true,
cterm = {
@ -539,33 +536,33 @@ describe('API: get highlight', function()
})
eq(
{ underdotted = true, cterm = { undercurl = true } },
meths.nvim_get_hl(ns, { name = 'Test_hl' })
api.nvim_get_hl(ns, { name = 'Test_hl' })
)
end)
it('can get a highlight in the global namespace', function()
meths.nvim_set_hl(0, 'Test_hl', highlight2)
eq(highlight2, meths.nvim_get_hl(0, { name = 'Test_hl' }))
api.nvim_set_hl(0, 'Test_hl', highlight2)
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({
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)
eq(highlight3_result, meths.nvim_get_hl(0, { name = 'Test_hl2' }))
api.nvim_set_hl(0, 'Test_hl2', highlight3_config)
eq(highlight3_result, api.nvim_get_hl(0, { name = 'Test_hl2' }))
-- Colors are stored with the name they are defined, but
-- 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({
bg = 16711680,
fg = 255,
}, meths.nvim_get_hl(0, { name = 'Test_hl3' }))
}, api.nvim_get_hl(0, { name = 'Test_hl3' }))
end)
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(
'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,
ctermbg = 10,
cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id }))
}, api.nvim_get_hl(0, { id = hl_id }))
-- 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(
"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.
@ -602,7 +599,7 @@ describe('API: get highlight', function()
underline = true,
ctermbg = 10,
cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id }))
}, api.nvim_get_hl(0, { id = hl_id }))
-- Test undercurl
command('hi NewHighlight gui=undercurl')
@ -613,16 +610,16 @@ describe('API: get highlight', function()
undercurl = true,
ctermbg = 10,
cterm = { underline = true },
}, meths.nvim_get_hl(0, { id = hl_id }))
}, api.nvim_get_hl(0, { id = hl_id }))
end)
it('can correctly detect links', function()
command('hi String guifg=#a6e3a1 ctermfg=NONE')
command('hi link @string string')
command('hi link @string.cpp @string')
eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = 'String' }))
eq({ link = 'String' }, meths.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' }))
eq({ link = 'String' }, api.nvim_get_hl(0, { name = '@string' }))
eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = '@string.cpp', link = false }))
end)
it('can get all attributes for a linked group', function()
@ -631,55 +628,55 @@ describe('API: get highlight', function()
command('hi! link Foo Bar')
eq(
{ 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)
it('can set link as well as other attributes', function()
command('hi Bar guifg=red')
local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } }
meths.nvim_set_hl(0, 'Foo', hl)
eq(hl, meths.nvim_get_hl(0, { name = 'Foo', link = true }))
api.nvim_set_hl(0, 'Foo', hl)
eq(hl, api.nvim_get_hl(0, { name = 'Foo', link = true }))
end)
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)
local data = meths.nvim_get_hl(0, {})
local data = api.nvim_get_hl(0, {})
eq(nil, data['@foobar.hubbabubba'])
eq(nil, data['@foobar'])
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(nil, data['@foobar'])
-- @foobar.hubbabubba was explicitly cleared and thus shows up
-- but @foobar was never touched, and thus doesn't
command 'hi clear @foobar.hubbabubba'
data = meths.nvim_get_hl(0, {})
data = api.nvim_get_hl(0, {})
eq({}, data['@foobar.hubbabubba'])
eq(nil, data['@foobar'])
end)
it('should return default flag', function()
meths.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true })
eq({ fg = tonumber('00ff00', 16), default = true }, meths.nvim_get_hl(0, { name = 'Tried' }))
api.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true })
eq({ fg = tonumber('00ff00', 16), default = true }, api.nvim_get_hl(0, { name = 'Tried' }))
end)
it('should not output empty gui and cterm #23474', function()
meths.nvim_set_hl(0, 'Foo', { default = true })
meths.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' })
meths.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } })
meths.nvim_set_hl(
api.nvim_set_hl(0, 'Foo', { default = true })
api.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' })
api.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } })
api.nvim_set_hl(
0,
'FooBarA',
{ default = true, fg = '#ffffff', cterm = { bold = true, italic = true } }
)
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('FooBar xxx cterm=bold guifg=#ffffff', exec_capture('highlight FooBar'))
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()
local white = tonumber('ffffff', 16)
local green = tonumber('00ff00', 16)
meths.nvim_set_hl(0, 'Foo', { fg = white })
meths.nvim_set_hl(0, 'Foo', { fg = green, force = true })
eq({ fg = green }, meths.nvim_get_hl(0, { name = 'Foo' }))
meths.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true })
meths.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true })
eq({ link = 'Foo', default = true }, meths.nvim_get_hl(0, { name = 'Bar' }))
api.nvim_set_hl(0, 'Foo', { fg = white })
api.nvim_set_hl(0, 'Foo', { fg = green, force = true })
eq({ fg = green }, api.nvim_get_hl(0, { name = 'Foo' }))
api.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true })
api.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true })
eq({ link = 'Foo', default = true }, api.nvim_get_hl(0, { name = 'Bar' }))
end)
end)
describe('API: set/get highlight namespace', function()
it('set/get highlight namespace', function()
eq(0, meths.nvim_get_hl_ns({}))
local ns = meths.nvim_create_namespace('')
meths.nvim_set_hl_ns(ns)
eq(ns, meths.nvim_get_hl_ns({}))
eq(0, api.nvim_get_hl_ns({}))
local ns = api.nvim_create_namespace('')
api.nvim_set_hl_ns(ns)
eq(ns, api.nvim_get_hl_ns({}))
end)
it('set/get window highlight namespace', function()
eq(-1, meths.nvim_get_hl_ns({ winid = 0 }))
local ns = meths.nvim_create_namespace('')
meths.nvim_win_set_hl_ns(0, ns)
eq(ns, meths.nvim_get_hl_ns({ winid = 0 }))
eq(-1, api.nvim_get_hl_ns({ winid = 0 }))
local ns = api.nvim_create_namespace('')
api.nvim_win_set_hl_ns(0, ns)
eq(ns, api.nvim_get_hl_ns({ winid = 0 }))
end)
end)

View File

@ -6,8 +6,8 @@ local eq, neq = helpers.eq, helpers.neq
local exec_lua = helpers.exec_lua
local exec = helpers.exec
local feed = helpers.feed
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local source = helpers.source
local pcall_err = helpers.pcall_err
@ -55,7 +55,7 @@ describe('nvim_get_keymap', function()
}
it('returns empty list when no map', function()
eq({}, meths.nvim_get_keymap('n'))
eq({}, api.nvim_get_keymap('n'))
end)
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
-- and the dictionary you would get from maparg
-- since this is a global map, and not script local
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n'))
eq({ funcs.maparg('foo', 'n', false, true) }, meths.nvim_get_keymap('n'))
eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
eq({ fn.maparg('foo', 'n', false, true) }, api.nvim_get_keymap('n'))
-- Add another mapping
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['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
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)
it('works for other modes', function()
@ -92,7 +92,7 @@ describe('nvim_get_keymap', function()
insert_table['mode'] = 'i'
insert_table['mode_bits'] = 0x10
eq({ insert_table }, meths.nvim_get_keymap('i'))
eq({ insert_table }, api.nvim_get_keymap('i'))
end)
it('considers scope', function()
@ -109,8 +109,8 @@ describe('nvim_get_keymap', function()
command('nnoremap <buffer> foo bar')
-- The buffer mapping should not show up
eq({ foolong_bar_map_table }, meths.nvim_get_keymap('n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n'))
eq({ foolong_bar_map_table }, api.nvim_get_keymap('n'))
eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
end)
it('considers scope for overlapping maps', function()
@ -121,12 +121,12 @@ describe('nvim_get_keymap', function()
command('nnoremap <buffer> foo bar')
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n'))
eq({ foo_bar_map_table }, api.nvim_get_keymap('n'))
eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
end)
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
-- and set hidden so we can leave them
command('set hidden')
@ -135,21 +135,21 @@ describe('nvim_get_keymap', function()
command('new')
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')
-- Final buffer will have buffer mappings
local buffer_table = shallowcopy(foo_bar_map_table)
buffer_table['buffer'] = final_buffer
eq({ buffer_table }, meths.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(final_buffer, 'n'))
eq({ buffer_table }, api.nvim_buf_get_keymap(0, 'n'))
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
eq({}, meths.nvim_get_keymap('n'))
eq({}, meths.nvim_buf_get_keymap(0, 'n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n'))
eq({}, api.nvim_get_keymap('n'))
eq({}, api.nvim_buf_get_keymap(0, 'n'))
eq({ buffer_table }, api.nvim_buf_get_keymap(final_buffer, 'n'))
end)
-- Test toggle switches for basic options
@ -189,7 +189,7 @@ describe('nvim_get_keymap', function()
function()
make_new_windows(new_windows)
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)
end
)
@ -207,7 +207,7 @@ describe('nvim_get_keymap', function()
function()
make_new_windows(new_windows)
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)
end
)
@ -226,7 +226,7 @@ describe('nvim_get_keymap', function()
function()
make_new_windows(new_windows)
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)
end
)
@ -244,7 +244,7 @@ describe('nvim_get_keymap', function()
make_new_windows(new_windows)
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)
end
)
@ -275,9 +275,9 @@ describe('nvim_get_keymap', function()
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('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
end)
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>
]])
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('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
eq('testing', api.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
end)
it('works with <F12> and others', function()
command('nnoremap <F12> :let g:maparg_test_var = 1<CR>')
eq('<F12>', meths.nvim_get_keymap('n')[1]['lhs'])
eq(':let g:maparg_test_var = 1<CR>', meths.nvim_get_keymap('n')[1]['rhs'])
eq('<F12>', api.nvim_get_keymap('n')[1]['lhs'])
eq(':let g:maparg_test_var = 1<CR>', api.nvim_get_keymap('n')[1]['rhs'])
end)
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
local function get_keymap_noraw(...)
local ret = meths.nvim_get_keymap(...)
local ret = api.nvim_get_keymap(...)
for _, item in ipairs(ret) do
item.lhsraw = nil
item.lhsrawalt = nil
@ -390,7 +390,7 @@ describe('nvim_get_keymap', function()
lnum = 0,
}
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)
it('can handle lua mappings', function()
@ -419,7 +419,7 @@ describe('nvim_get_keymap', function()
]])
eq(3, exec_lua([[return GlobalCount]]))
local mapargs = meths.nvim_get_keymap('n')
local mapargs = api.nvim_get_keymap('n')
mapargs[1].callback = nil
eq({
lhs = 'asdf',
@ -440,7 +440,7 @@ describe('nvim_get_keymap', function()
end)
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({
lhs = 'lhs',
lhsraw = 'lhs',
@ -458,7 +458,7 @@ describe('nvim_get_keymap', function()
noremap = 0,
lnum = 0,
desc = 'map description',
}, meths.nvim_get_keymap('n')[1])
}, api.nvim_get_keymap('n')[1])
end)
end)
@ -511,7 +511,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Gets a maparg() dict from Nvim, if one exists.
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
mapargs.lhsraw = nil
mapargs.lhsrawalt = nil
@ -520,9 +520,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('error on empty LHS', function()
-- 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(meths.nvim_set_keymap, '', '', '', {}))
eq('Invalid (empty) LHS', pcall_err(meths.nvim_del_keymap, '', ''))
eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', 'rhs', {}))
eq('Invalid (empty) LHS', pcall_err(api.nvim_set_keymap, '', '', '', {}))
eq('Invalid (empty) LHS', pcall_err(api.nvim_del_keymap, '', ''))
end)
it('error if LHS longer than MAXMAPLEN', function()
@ -534,19 +534,19 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end
-- exactly 50 chars should be fine
meths.nvim_set_keymap('', lhs, 'rhs', {})
api.nvim_set_keymap('', lhs, 'rhs', {})
-- del_keymap should unmap successfully
meths.nvim_del_keymap('', lhs)
api.nvim_del_keymap('', lhs)
eq({}, get_mapargs('', lhs))
-- 51 chars should produce an error
lhs = lhs .. '1'
eq(
'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)
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)
end
rhs = rhs .. '1'
meths.nvim_set_keymap('', 'lhs', rhs, {})
api.nvim_set_keymap('', 'lhs', rhs, {})
eq(generate_mapargs('', 'lhs', rhs), get_mapargs('', 'lhs'))
end)
it('error on invalid mode shortname', function()
eq('Invalid mode shortname: " "', pcall_err(meths.nvim_set_keymap, ' ', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "m"', pcall_err(meths.nvim_set_keymap, 'm', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "?"', pcall_err(meths.nvim_set_keymap, '?', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "y"', pcall_err(meths.nvim_set_keymap, 'y', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "p"', pcall_err(meths.nvim_set_keymap, 'p', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "a"', pcall_err(meths.nvim_set_keymap, 'a', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "oa"', pcall_err(meths.nvim_set_keymap, 'oa', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!o"', pcall_err(meths.nvim_set_keymap, '!o', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!i"', pcall_err(meths.nvim_set_keymap, '!i', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!!"', pcall_err(meths.nvim_set_keymap, '!!', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "map"', pcall_err(meths.nvim_set_keymap, 'map', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "vmap"', pcall_err(meths.nvim_set_keymap, 'vmap', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: " "', pcall_err(api.nvim_set_keymap, ' ', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "m"', pcall_err(api.nvim_set_keymap, 'm', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "?"', pcall_err(api.nvim_set_keymap, '?', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "y"', pcall_err(api.nvim_set_keymap, 'y', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "p"', pcall_err(api.nvim_set_keymap, 'p', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "a"', pcall_err(api.nvim_set_keymap, 'a', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_set_keymap, 'oa', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_set_keymap, '!o', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_set_keymap, '!i', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_set_keymap, '!!', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "map"', pcall_err(api.nvim_set_keymap, 'map', 'lhs', 'rhs', {}))
eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_set_keymap, 'vmap', 'lhs', 'rhs', {}))
eq(
'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: "m"', pcall_err(meths.nvim_del_keymap, 'm', 'lhs'))
eq('Invalid mode shortname: "?"', pcall_err(meths.nvim_del_keymap, '?', 'lhs'))
eq('Invalid mode shortname: "y"', pcall_err(meths.nvim_del_keymap, 'y', 'lhs'))
eq('Invalid mode shortname: "p"', pcall_err(meths.nvim_del_keymap, 'p', 'lhs'))
eq('Invalid mode shortname: "a"', pcall_err(meths.nvim_del_keymap, 'a', 'lhs'))
eq('Invalid mode shortname: "oa"', pcall_err(meths.nvim_del_keymap, 'oa', 'lhs'))
eq('Invalid mode shortname: "!o"', pcall_err(meths.nvim_del_keymap, '!o', 'lhs'))
eq('Invalid mode shortname: "!i"', pcall_err(meths.nvim_del_keymap, '!i', 'lhs'))
eq('Invalid mode shortname: "!!"', pcall_err(meths.nvim_del_keymap, '!!', 'lhs'))
eq('Invalid mode shortname: "map"', pcall_err(meths.nvim_del_keymap, 'map', 'lhs'))
eq('Invalid mode shortname: "vmap"', pcall_err(meths.nvim_del_keymap, 'vmap', 'lhs'))
eq('Invalid mode shortname: "xnoremap"', pcall_err(meths.nvim_del_keymap, 'xnoremap', 'lhs'))
eq('Invalid mode shortname: " "', pcall_err(api.nvim_del_keymap, ' ', 'lhs'))
eq('Invalid mode shortname: "m"', pcall_err(api.nvim_del_keymap, 'm', 'lhs'))
eq('Invalid mode shortname: "?"', pcall_err(api.nvim_del_keymap, '?', 'lhs'))
eq('Invalid mode shortname: "y"', pcall_err(api.nvim_del_keymap, 'y', 'lhs'))
eq('Invalid mode shortname: "p"', pcall_err(api.nvim_del_keymap, 'p', 'lhs'))
eq('Invalid mode shortname: "a"', pcall_err(api.nvim_del_keymap, 'a', 'lhs'))
eq('Invalid mode shortname: "oa"', pcall_err(api.nvim_del_keymap, 'oa', 'lhs'))
eq('Invalid mode shortname: "!o"', pcall_err(api.nvim_del_keymap, '!o', 'lhs'))
eq('Invalid mode shortname: "!i"', pcall_err(api.nvim_del_keymap, '!i', 'lhs'))
eq('Invalid mode shortname: "!!"', pcall_err(api.nvim_del_keymap, '!!', 'lhs'))
eq('Invalid mode shortname: "map"', pcall_err(api.nvim_del_keymap, 'map', 'lhs'))
eq('Invalid mode shortname: "vmap"', pcall_err(api.nvim_del_keymap, 'vmap', 'lhs'))
eq('Invalid mode shortname: "xnoremap"', pcall_err(api.nvim_del_keymap, 'xnoremap', 'lhs'))
end)
it('error on invalid optnames', function()
eq(
"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(
"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)
it('error on <buffer> option key', function()
eq(
"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)
it('error when "replace_keycodes" is used without "expr"', function()
eq(
'"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)
@ -624,45 +624,45 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('throws an error when given non-boolean value for ' .. opt, function()
local opts = {}
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
-- Perform tests of basic functionality
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'))
meths.nvim_set_keymap('v', 'lhs', 'rhs', {})
api.nvim_set_keymap('v', 'lhs', 'rhs', {})
eq(generate_mapargs('v', 'lhs', 'rhs'), get_mapargs('v', 'lhs'))
end)
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'))
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 '))
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 '))
end)
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'))
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'))
end)
it('can unmap mappings', function()
meths.nvim_set_keymap('v', 'lhs', 'rhs', {})
meths.nvim_del_keymap('v', 'lhs')
api.nvim_set_keymap('v', 'lhs', 'rhs', {})
api.nvim_del_keymap('v', 'lhs')
eq({}, get_mapargs('v', 'lhs'))
meths.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true })
meths.nvim_del_keymap('t', 'lhs')
api.nvim_set_keymap('t', 'lhs', 'rhs', { noremap = true })
api.nvim_del_keymap('t', 'lhs')
eq({}, get_mapargs('t', 'lhs'))
end)
@ -670,8 +670,8 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('"!" and empty string are synonyms for mapmode-nvo', function()
local nvo_shortnames = { '', '!' }
for _, name in ipairs(nvo_shortnames) do
meths.nvim_set_keymap(name, 'lhs', 'rhs', {})
meths.nvim_del_keymap(name, 'lhs')
api.nvim_set_keymap(name, 'lhs', 'rhs', {})
api.nvim_del_keymap(name, 'lhs')
eq({}, get_mapargs(name, 'lhs'))
end
end)
@ -681,48 +681,48 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
for _, rhs in ipairs(special_chars) do
local mapmode = '!'
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))
end)
end
end
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')
eq(expected, get_mapargs('n', '<NL><CR><NL>'))
end)
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')
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'))
-- also test for case insensitivity
meths.nvim_set_keymap('i', 'lhs', '<nOp>', {})
api.nvim_set_keymap('i', 'lhs', '<nOp>', {})
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
-- provided by the user
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')
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'))
-- 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')
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'))
end)
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')
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'))
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
-- replace_termcodes changes the length of the mapping's LHS, but
-- do_map continues to use the *old* length of LHS.
meths.nvim_set_keymap('i', '<M-">', 'foo', {})
meths.nvim_del_keymap('i', '<M-">')
api.nvim_set_keymap('i', '<M-">', 'foo', {})
api.nvim_del_keymap('i', '<M-">')
eq({}, get_mapargs('i', '<M-">'))
end)
@ -741,18 +741,18 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]])
eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>'))
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
)
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(
'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
meths.nvim_set_keymap('t', 'lhs', 'rhs', { unique = true })
api.nvim_set_keymap('t', 'lhs', 'rhs', { unique = true })
end)
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
endfunction
]])
eq(1, meths.nvim_call_function('FlipFlop', {}))
eq(0, meths.nvim_call_function('FlipFlop', {}))
eq(1, meths.nvim_call_function('FlipFlop', {}))
eq(0, meths.nvim_call_function('FlipFlop', {}))
eq(1, api.nvim_call_function('FlipFlop', {}))
eq(0, api.nvim_call_function('FlipFlop', {}))
eq(1, api.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')
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 ilhs')
eq({ '0' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq({ '0' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end)
it('can set mappings that do trigger other mappings', function()
meths.nvim_set_keymap('i', 'mhs', 'rhs', {})
meths.nvim_set_keymap('i', 'lhs', 'mhs', {})
api.nvim_set_keymap('i', 'mhs', 'rhs', {})
api.nvim_set_keymap('i', 'lhs', 'mhs', {})
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 ilhs')
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq({ 'rhs' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end)
it("can set noremap mappings that don't trigger other mappings", function()
meths.nvim_set_keymap('i', 'mhs', 'rhs', {})
meths.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true })
api.nvim_set_keymap('i', 'mhs', 'rhs', {})
api.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true })
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 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)
it('can set nowait mappings that fire without waiting', function()
meths.nvim_set_keymap('i', '123456', 'longer', {})
meths.nvim_set_keymap('i', '123', 'shorter', { nowait = true })
api.nvim_set_keymap('i', '123456', 'longer', {})
api.nvim_set_keymap('i', '123', 'shorter', { nowait = true })
-- feed keys one at a time; if all keys arrive atomically, the longer
-- mapping will trigger
@ -815,29 +815,29 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed(c)
sleep(5)
end
eq({ 'shorter456' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq({ 'shorter456' }, api.nvim_buf_get_lines(0, 0, -1, 0))
end)
-- Perform exhaustive tests of basic functionality
local mapmodes = { 'n', 'v', 'x', 's', 'o', '!', 'i', 'l', 'c', 't', '', 'ia', 'ca', '!a' }
for _, mapmode in ipairs(mapmodes) do
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'))
-- some mapmodes (like 'o') will prevent other mapmodes (like '!') from
-- taking effect, so unmap after each mapping
meths.nvim_del_keymap(mapmode, 'lhs')
api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end)
end
for _, mapmode in ipairs(mapmodes) do
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'))
meths.nvim_del_keymap(mapmode, 'lhs')
api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end)
end
@ -849,12 +849,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
-- Test with single mappings
for _, maparg in ipairs(optnames) do
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(
generate_mapargs(mapmode, 'lhs', 'rhs', { [maparg] = true }),
get_mapargs(mapmode, 'lhs')
)
meths.nvim_del_keymap(mapmode, 'lhs')
api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end)
it(
@ -864,9 +864,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
.. maparg
.. ', whose value is false',
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'))
meths.nvim_del_keymap(mapmode, 'lhs')
api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end
)
@ -886,9 +886,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
.. opt3,
function()
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'))
meths.nvim_del_keymap(mapmode, 'lhs')
api.nvim_del_keymap(mapmode, 'lhs')
eq({}, get_mapargs(mapmode, 'lhs'))
end
)
@ -926,7 +926,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
exec_lua [[
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)
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.lhsraw = nil
mapargs.lhsrawalt = nil
@ -968,7 +968,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
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)
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>')
eq({ '<space>' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
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>')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq({ '' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
it('does not reset pum in lua mapping', function()
@ -1091,7 +1091,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end)
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('\nn lhs rhs\n map description', helpers.exec_capture('nmap lhs'))
end)
@ -1106,10 +1106,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
]]
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>'
eq('The 3 is the one', meths.nvim_eval 'x')
eq('The 3 is the one', api.nvim_eval 'x')
end)
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>'
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>'
eq('The foo is the one', meths.nvim_eval 'x')
eq('The foo is the one', api.nvim_eval 'x')
end)
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>'
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>'
eq('The 1 is the one', meths.nvim_eval 'x')
eq('The 1 is the one', api.nvim_eval 'x')
end)
end)
@ -1164,9 +1164,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
local function make_two_buffers(start_from_first)
command('set hidden')
local first_buf = meths.nvim_call_function('bufnr', { '%' })
local first_buf = api.nvim_call_function('bufnr', { '%' })
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
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()
eq(
'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)
it('can set mappings active in the current buffer but not others', function()
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')
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
switch_to_buf(second)
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
switch_to_buf(first)
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)
it('can set local mappings in buffer other than current', function()
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
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
switch_to_buf(first)
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)
it('can disable mappings made in another buffer, inside that buffer', function()
local first = make_two_buffers(false)
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
meths.nvim_buf_del_keymap(first, '', 'lhs')
api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
api.nvim_buf_del_keymap(first, '', 'lhs')
switch_to_buf(first)
-- shouldn't do anything
command('normal lhs')
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
eq({ '' }, api.nvim_buf_get_lines(0, 0, 1, 1))
end)
it("can't disable mappings given wrong buffer handle", function()
local first, second = make_two_buffers(false)
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
eq('E31: No such mapping', pcall_err(meths.nvim_buf_del_keymap, second, '', 'lhs'))
api.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
eq('E31: No such mapping', pcall_err(api.nvim_buf_del_keymap, second, '', 'lhs'))
-- should still work
switch_to_buf(first)
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)
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()
end)
@ -1264,7 +1264,7 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
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)
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>')
eq({ '<space>' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq({ '<space>' }, api.nvim_buf_get_lines(0, 0, -1, false))
end)
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 eq = helpers.eq
local funcs = helpers.funcs
local fn = helpers.fn
local neq = helpers.neq
local nvim_argv = helpers.nvim_argv
local request = helpers.request
@ -15,28 +15,28 @@ describe('API', function()
describe('nvim_get_proc_children', 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?),
-- but this is not what is tested here.
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()
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
end)
local job2 = funcs.jobstart(nvim_argv)
local job2 = fn.jobstart(nvim_argv)
retry(nil, nil, function()
eq(#initial_children + 2, #request('nvim_get_proc_children', this_pid))
end)
funcs.jobstop(job1)
fn.jobstop(job1)
retry(nil, nil, function()
eq(#initial_children + 1, #request('nvim_get_proc_children', this_pid))
end)
funcs.jobstop(job2)
fn.jobstop(job2)
retry(nil, nil, function()
eq(#initial_children, #request('nvim_get_proc_children', this_pid))
end)
@ -60,7 +60,7 @@ describe('API', function()
describe('nvim_get_proc', function()
it('returns process info', function()
local pid = funcs.getpid()
local pid = fn.getpid()
local pinfo = request('nvim_get_proc', pid)
eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name)
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 eq, clear, eval, command, 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 retry = helpers.retry
local assert_alive = helpers.assert_alive
@ -14,7 +14,7 @@ describe('notify', function()
before_each(function()
clear()
channel = meths.nvim_get_api_info()[1]
channel = api.nvim_get_api_info()[1]
end)
after_each(function()
@ -33,21 +33,21 @@ describe('notify', function()
describe('passing 0 as the channel id', 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, "event2", 4, 5, 6)')
eval('rpcnotify(0, "event2", 7, 8, 9)')
eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg())
eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg())
meths.nvim_unsubscribe('event2')
meths.nvim_subscribe('event1')
api.nvim_unsubscribe('event2')
api.nvim_subscribe('event1')
eval('rpcnotify(0, "event2", 10, 11, 12)')
eval('rpcnotify(0, "event1", 13, 14, 15)')
eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg())
end)
it('does not crash for deeply nested variable', function()
meths.nvim_set_var('l', {})
api.nvim_set_var('l', {})
local nest_level = 1000
command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1))
eval('rpcnotify(' .. channel .. ', "event", g:l)')
@ -79,10 +79,10 @@ describe('notify', function()
clear { env = {
NVIM_LOG_FILE = testlog,
} }
meths.nvim_subscribe('event1')
meths.nvim_unsubscribe('doesnotexist')
api.nvim_subscribe('event1')
api.nvim_unsubscribe('doesnotexist')
assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10)
meths.nvim_unsubscribe('event1')
api.nvim_unsubscribe('event1')
assert_alive()
end)
@ -106,7 +106,7 @@ describe('notify', function()
exec_lua([[ return {pcall(vim.rpcrequest, ..., 'nvim_eval', '1+1')}]], catchan)
)
retry(nil, 3000, function()
eq({}, meths.nvim_get_chan_info(catchan))
eq({}, api.nvim_get_chan_info(catchan))
end) -- cat be dead :(
end)
end)

View File

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

View File

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

View File

@ -6,7 +6,7 @@ local eq = helpers.eq
local eval = helpers.eval
local exec = helpers.exec
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local request = helpers.request
local pcall_err = helpers.pcall_err
@ -23,39 +23,39 @@ describe('nvim_ui_attach()', function()
end)
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(
"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(
"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(
"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(
"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(
"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(
"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(
"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(
"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))
@ -117,17 +117,17 @@ it('autocmds VimSuspend/VimResume #22041', function()
end)
eq({ 's', 'r', 's' }, eval('g:ev'))
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'))
feed('<C-Z><C-Z><C-Z>')
screen:expect(function()
eq(true, screen.suspended)
end)
meths.nvim_ui_set_focus(false)
api.nvim_ui_set_focus(false)
eq({ 's', 'r', 's', 'r', 's' }, eval('g:ev'))
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'))
command('suspend | suspend | suspend')

View File

@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq
local call = helpers.call
local meths = helpers.meths
local clear, fn, eq = helpers.clear, helpers.fn, helpers.eq
local api = helpers.api
local function read_mpack_file(fname)
local fd = io.open(fname, 'rb')
@ -19,7 +18,7 @@ describe("api_info()['version']", function()
before_each(clear)
it('returns API level', function()
local version = call('api_info')['version']
local version = fn.api_info()['version']
local current = version['api_level']
local compat = version['api_compatible']
eq('number', type(current))
@ -28,7 +27,7 @@ describe("api_info()['version']", function()
end)
it('returns Nvim version', function()
local version = call('api_info')['version']
local version = fn.api_info()['version']
local major = version['major']
local minor = version['minor']
local patch = version['patch']
@ -38,10 +37,10 @@ describe("api_info()['version']", function()
eq('number', type(minor))
eq('number', type(patch))
eq('boolean', type(prerelease))
eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch))
eq(0, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1)))
eq(0, funcs.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch))
eq(0, funcs.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch))
eq(1, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. patch))
eq(0, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1)))
eq(0, fn.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch))
eq(0, fn.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch))
assert(build == nil or type(build) == 'string')
end)
end)
@ -90,14 +89,14 @@ describe('api metadata', function()
end
end
local api, compat, stable, api_level
local api_info, compat, stable, api_level
local old_api = {}
setup(function()
clear() -- Ensure a session before requesting api_info.
api = meths.nvim_get_api_info()[2]
compat = api.version.api_compatible
api_level = api.version.api_level
if api.version.api_prerelease then
api_info = api.nvim_get_api_info()[2]
compat = api_info.version.api_compatible
api_level = api_info.version.api_level
if api_info.version.api_prerelease then
stable = api_level - 1
else
stable = api_level
@ -108,7 +107,7 @@ describe('api metadata', function()
old_api[level] = read_mpack_file(path)
if old_api[level] == nil then
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
.. 'If NVIM_API_CURRENT was bumped, '
@ -125,7 +124,7 @@ describe('api metadata', function()
end)
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 = {}
for level = compat, stable 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)
end
for _, f in ipairs(api.functions) do
for _, f in ipairs(api_info.functions) do
if f.since <= stable then
local f_old = funcs_compat[f.since][f.name]
if f_old == nil then
@ -159,7 +158,7 @@ describe('api metadata', function()
.. (stable + 1)
.. '.'
)
if not api.version.api_prerelease then
if not api_info.version.api_prerelease then
errstr = (
errstr
.. ' Also bump NVIM_API_CURRENT and set '
@ -172,7 +171,7 @@ describe('api metadata', function()
end
end
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)
else
error(
@ -188,7 +187,7 @@ describe('api metadata', function()
end)
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 = {}
-- 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)
end
for _, e in ipairs(api.ui_events) do
for _, e in ipairs(api_info.ui_events) do
if e.since <= stable then
local e_old = ui_events_compat[e.since][e.name]
if e_old == nil then
@ -214,7 +213,7 @@ describe('api metadata', function()
.. (stable + 1)
.. '.'
)
if not api.version.api_prerelease then
if not api_info.version.api_prerelease then
errstr = (
errstr
.. ' Also bump NVIM_API_CURRENT and set '
@ -224,7 +223,7 @@ describe('api metadata', function()
error(errstr)
end
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)
else
error(
@ -241,7 +240,7 @@ describe('api metadata', function()
it('ui_options are preserved from older levels', function()
local available_options = {}
for _, option in ipairs(api.ui_options) do
for _, option in ipairs(api_info.ui_options) do
available_options[option] = true
end
-- 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 eq = helpers.eq
local meths = helpers.meths
local funcs = helpers.funcs
local api = helpers.api
local fn = helpers.fn
local exec = helpers.exec
local feed = helpers.feed
@ -12,7 +12,7 @@ describe('oldtests', function()
before_each(clear)
local exec_lines = function(str)
return funcs.split(funcs.execute(str), '\n')
return fn.split(fn.execute(str), '\n')
end
local add_an_autocmd = function()
@ -23,7 +23,7 @@ describe('oldtests', function()
]]
eq(3, #exec_lines('au vimBarTest'))
eq(1, #meths.nvim_get_autocmds({ group = 'vimBarTest' }))
eq(1, #api.nvim_get_autocmds({ group = 'vimBarTest' }))
end
it('should recognize a bar before the {event}', function()
@ -31,7 +31,7 @@ describe('oldtests', function()
add_an_autocmd()
exec [[ augroup vimBarTest | au! | augroup END ]]
eq(1, #exec_lines('au vimBarTest'))
eq({}, meths.nvim_get_autocmds({ group = 'vimBarTest' }))
eq({}, api.nvim_get_autocmds({ group = 'vimBarTest' }))
-- Sad spacing
add_an_autocmd()
@ -49,8 +49,8 @@ describe('oldtests', function()
end)
it('should fire on unload buf', function()
funcs.writefile({ 'Test file Xxx1' }, 'Xxx1')
funcs.writefile({ 'Test file Xxx2' }, 'Xxx2')
fn.writefile({ 'Test file Xxx1' }, 'Xxx1')
fn.writefile({ 'Test file Xxx2' }, 'Xxx2')
local fname = 'Xtest_functional_autocmd_unload'
local content = [[
@ -71,16 +71,16 @@ describe('oldtests', function()
q
]]
funcs.writefile(funcs.split(content, '\n'), fname)
fn.writefile(fn.split(content, '\n'), fname)
funcs.delete('Xout')
funcs.system(string.format('%s --clean -N -S %s', meths.nvim_get_vvar('progpath'), fname))
eq(1, funcs.filereadable('Xout'))
fn.delete('Xout')
fn.system(string.format('%s --clean -N -S %s', api.nvim_get_vvar('progpath'), fname))
eq(1, fn.filereadable('Xout'))
funcs.delete('Xxx1')
funcs.delete('Xxx2')
funcs.delete(fname)
funcs.delete('Xout')
fn.delete('Xxx1')
fn.delete('Xxx2')
fn.delete(fname)
fn.delete('Xout')
end)
-- oldtest: Test_delete_ml_get_errors()

View File

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

View File

@ -8,14 +8,14 @@ local expect = helpers.expect
local eval = helpers.eval
local next_msg = helpers.next_msg
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
describe('cmdline autocommands', function()
local channel
before_each(function()
clear()
channel = meths.nvim_get_api_info()[1]
meths.nvim_set_var('channel', channel)
channel = api.nvim_get_api_info()[1]
api.nvim_set_var('channel', channel)
command("autocmd CmdlineEnter * call rpcnotify(g:channel, 'CmdlineEnter', v:event)")
command("autocmd CmdlineLeave * call rpcnotify(g:channel, 'CmdlineLeave', 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 exec = helpers.source
local sleep = vim.uv.sleep
local meths = helpers.meths
local api = helpers.api
before_each(clear)
@ -26,47 +26,47 @@ describe('CursorHold', function()
-- if testing with small 'updatetime' fails, double its value and test again
retry(10, nil, function()
ut = ut * 2
meths.nvim_set_option_value('updatetime', ut, {})
api.nvim_set_option_value('updatetime', ut, {})
feed('0') -- reset did_cursorhold
meths.nvim_set_var('cursorhold', 0)
api.nvim_set_var('cursorhold', 0)
sleep(ut / 4)
fn()
eq(0, meths.nvim_get_var('cursorhold'))
eq(0, api.nvim_get_var('cursorhold'))
sleep(ut / 2)
fn()
eq(0, meths.nvim_get_var('cursorhold'))
eq(0, api.nvim_get_var('cursorhold'))
sleep(ut / 2)
eq(early, meths.nvim_get_var('cursorhold'))
eq(early, api.nvim_get_var('cursorhold'))
sleep(ut / 4 * 3)
eq(1, meths.nvim_get_var('cursorhold'))
eq(1, api.nvim_get_var('cursorhold'))
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()
feed('')
end, 1)
test_cursorhold(function()
meths.nvim_feedkeys('', 'n', true)
api.nvim_feedkeys('', 'n', true)
end, 1)
test_cursorhold(function()
feed('<Ignore>')
end, 0)
test_cursorhold(function()
meths.nvim_feedkeys(ignore_key, 'n', true)
api.nvim_feedkeys(ignore_key, 'n', true)
end, 0)
end)
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
meths.nvim_set_var('cursorhold', 0)
api.nvim_set_var('cursorhold', 0)
sleep(50)
eq(0, meths.nvim_get_var('cursorhold'))
meths.nvim_set_option_value('updatetime', 20, {})
eq(0, api.nvim_get_var('cursorhold'))
api.nvim_set_option_value('updatetime', 20, {})
sleep(10)
eq(1, meths.nvim_get_var('cursorhold'))
eq(1, api.nvim_get_var('cursorhold'))
end)
end)
@ -85,7 +85,7 @@ describe('CursorHoldI', function()
feed('ifoo')
retry(5, nil, function()
sleep(1)
eq(1, meths.nvim_get_var('cursorhold'))
eq(1, api.nvim_get_var('cursorhold'))
end)
end)
end)

View File

@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local meths = helpers.meths
local api = helpers.api
local source = helpers.source
local command = helpers.command
@ -41,9 +41,9 @@ describe('CursorMoved', function()
vsplit foo
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({ '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'))
end)

View File

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

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local meths = helpers.meths
local api = helpers.api
local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
@ -13,7 +13,7 @@ describe('autocmd SearchWrapped', function()
command('set ignorecase')
command('let g:test = 0')
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',
'jumps over the lazy dog',
})

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ local dedent = helpers.dedent
local eval = helpers.eval
local eq = helpers.eq
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local exec_capture = helpers.exec_capture
describe('TabNewEntered', function()
@ -15,15 +15,15 @@ describe('TabNewEntered', function()
it('matches when entering any new tab', function()
clear()
command('au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
eq('tabnewentered:2:2', meths.nvim_exec('tabnew', true))
eq('tabnewentered:3:3', meths.nvim_exec('tabnew test.x2', true))
eq('tabnewentered:2:2', api.nvim_exec('tabnew', true))
eq('tabnewentered:3:3', api.nvim_exec('tabnew test.x2', true))
end)
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
clear()
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)
describe('with CTRL-W T', function()
@ -32,7 +32,7 @@ describe('TabNewEntered', function()
command('au! TabNewEntered * echom "entered"')
command('tabnew test.x2')
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)
describe('with tab split #4334', function()
@ -40,7 +40,7 @@ describe('TabNewEntered', function()
clear()
command('au! TabNewEntered * let b:entered = "entered"')
command('tab split')
eq('entered', meths.nvim_exec('echo b:entered', true))
eq('entered', api.nvim_exec('echo b:entered', true))
end)
end)
end)
@ -52,8 +52,8 @@ describe('TabEnter', function()
command('augroup TEMP')
command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
command('augroup END')
eq('tabenter:2:1', meths.nvim_exec('tabnew', true))
eq('tabenter:3:2', meths.nvim_exec('tabnew test.x2', true))
eq('tabenter:2:1', api.nvim_exec('tabnew', true))
eq('tabenter:3:2', api.nvim_exec('tabnew test.x2', true))
command('augroup! TEMP')
end)
it('has correct previous tab when entering any preexisting tab', function()
@ -62,8 +62,8 @@ describe('TabEnter', function()
command('augroup TEMP')
command('au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
command('augroup END')
eq('tabenter:1:3', meths.nvim_exec('tabnext', true))
eq('tabenter:2:1', meths.nvim_exec('tabnext', true))
eq('tabenter:1:3', api.nvim_exec('tabnext', true))
eq('tabenter:2:1', api.nvim_exec('tabnext', true))
command('augroup! TEMP')
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 ok = helpers.ok
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
local skip = helpers.skip
@ -16,13 +16,13 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function()
before_each(function()
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=')
end)
local function test_termclose_delete_own_buf()
-- 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('terminal')
matches(
@ -56,7 +56,7 @@ describe('autocmd TermClose', function()
it('triggers when long-running terminal job gets stopped', function()
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('terminal')
command('call jobstop(b:terminal_job_id)')
@ -67,8 +67,8 @@ describe('autocmd TermClose', function()
it('kills job trapping SIGTERM', function()
skip(is_os('win'))
meths.nvim_set_option_value('shell', 'sh', {})
meths.nvim_set_option_value('shellcmdflag', '-c', {})
api.nvim_set_option_value('shell', 'sh', {})
api.nvim_set_option_value('shellcmdflag', '-c', {})
command(
[[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
.. [[ '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()
skip(is_os('win'))
meths.nvim_set_option_value('shell', 'sh', {})
meths.nvim_set_option_value('shellcmdflag', '-c', {})
api.nvim_set_option_value('shell', 'sh', {})
api.nvim_set_option_value('shellcmdflag', '-c', {})
command(
[[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
.. [[ 'pty': 1,]]
@ -204,7 +204,7 @@ describe('autocmd TextChangedT', function()
command('autocmd TextChangedT * ++once let g:called = 1')
thelpers.feed_data('a')
retry(nil, nil, function()
eq(1, meths.nvim_get_var('called'))
eq(1, api.nvim_get_var('called'))
end)
end)
@ -214,7 +214,7 @@ describe('autocmd TextChangedT', function()
screen:expect({ any = 'E937: ' })
matches(
'^E937: Attempt to delete a buffer that is in use: term://',
meths.nvim_get_vvar('errmsg')
api.nvim_get_vvar('errmsg')
)
end)
end)

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
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()
before_each(function()
@ -14,7 +14,7 @@ describe('TextYankPost', function()
command('autocmd TextYankPost * let g:event = copy(v:event)')
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',
'baz text',
})
@ -100,7 +100,7 @@ describe('TextYankPost', function()
visual = false,
}, eval('g:event'))
eq(1, eval('g:count'))
eq({ 'foo\nbar' }, funcs.getreg('+', 1, 1))
eq({ 'foo\nbar' }, fn.getreg('+', 1, 1))
end)
it('is executed after delete and change', function()

View File

@ -7,7 +7,7 @@ local eval = helpers.eval
local exec = helpers.exec
local command = helpers.command
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local assert_alive = helpers.assert_alive
before_each(clear)
@ -45,7 +45,7 @@ describe('WinScrolled', function()
local win_id
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))
exec([[
let g:scrolled = 0
@ -64,7 +64,7 @@ describe('WinScrolled', function()
it('is triggered by scrolling vertically', function()
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'))
feed('<C-E>')
@ -84,10 +84,10 @@ describe('WinScrolled', function()
it('is triggered by scrolling horizontally', function()
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 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'))
feed('zl')
@ -108,8 +108,8 @@ describe('WinScrolled', function()
it('is triggered by horizontal scrolling from cursor move', function()
command('set nowrap')
local lines = { '', '', 'Foo' }
meths.nvim_buf_set_lines(0, 0, -1, true, lines)
meths.nvim_win_set_cursor(0, { 3, 0 })
api.nvim_buf_set_lines(0, 0, -1, true, lines)
api.nvim_win_set_cursor(0, { 3, 0 })
eq(0, eval('g:scrolled'))
feed('zl')
@ -143,10 +143,10 @@ describe('WinScrolled', function()
-- oldtest: Test_WinScrolled_long_wrapped()
it('is triggered by scrolling on a long wrapped line #19968', function()
local height = meths.nvim_win_get_height(0)
local width = meths.nvim_win_get_width(0)
meths.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) })
meths.nvim_win_set_cursor(0, { 1, height * width - 1 })
local height = api.nvim_win_get_height(0)
local width = api.nvim_win_get_width(0)
api.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) })
api.nvim_win_set_cursor(0, { 1, height * width - 1 })
eq(0, eval('g:scrolled'))
feed('gj')
@ -168,12 +168,12 @@ describe('WinScrolled', function()
end)
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 = {}
for i = 1, height * 2 do
lines[i] = tostring(i)
end
meths.nvim_buf_set_lines(0, 0, -1, true, lines)
api.nvim_buf_set_lines(0, 0, -1, true, lines)
feed('M')
eq(0, eval('g:scrolled'))
@ -220,12 +220,12 @@ describe('WinScrolled', function()
eq(0, eval('g:scrolled'))
-- 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'))
-- Again, but this time while we're in insert mode.
feed('i')
meths.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
feed('<Esc>')
eq(2, eval('g:scrolled'))
end)
@ -296,15 +296,15 @@ describe('WinScrolled', function()
]])
eq(0, eval('g:scrolled'))
local buf = meths.nvim_create_buf(true, true)
meths.nvim_buf_set_lines(
local buf = api.nvim_create_buf(true, true)
api.nvim_buf_set_lines(
buf,
0,
-1,
false,
{ '@', '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,
width = 10,
col = 0,
@ -317,7 +317,7 @@ describe('WinScrolled', function()
-- WinScrolled should not be triggered when creating a new floating window
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(winid_str, eval('g:amatch'))
eq({
@ -325,7 +325,7 @@ describe('WinScrolled', function()
[winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, 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(tostring(win.id), eval('g:amatch'))
eq({

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear, eq, eval, next_msg, ok, 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 spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
local set_session = helpers.set_session
@ -33,12 +33,12 @@ describe('channels', function()
pending('can connect to socket', function()
local server = spawn(nvim_argv, nil, nil, true)
set_session(server)
local address = funcs.serverlist()[1]
local address = fn.serverlist()[1]
local client = spawn(nvim_argv, nil, nil, true)
set_session(client)
source(init)
meths.nvim_set_var('address', address)
api.nvim_set_var('address', address)
command("let g:id = sockconnect('pipe', address, {'on_data':'OnEvent'})")
local id = eval('g:id')
ok(id > 0)
@ -46,7 +46,7 @@ describe('channels', function()
command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))")
set_session(server)
retry(nil, 1000, function()
eq(23, meths.nvim_get_var('code'))
eq(23, api.nvim_get_var('code'))
end)
set_session(client)
@ -67,8 +67,8 @@ describe('channels', function()
\ 'on_exit': function('OnEvent'),
\ }
]])
meths.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var(
api.nvim_set_var('nvim_prog', nvim_prog)
api.nvim_set_var(
'code',
[[
function! OnEvent(id, data, event) dict
@ -117,8 +117,8 @@ describe('channels', function()
\ 'on_exit': function('OnEvent'),
\ }
]])
meths.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var(
api.nvim_set_var('nvim_prog', nvim_prog)
api.nvim_set_var(
'code',
[[
function! OnStdin(id, data, event) dict
@ -165,8 +165,8 @@ describe('channels', function()
\ 'pty': v:true,
\ }
]])
meths.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var(
api.nvim_set_var('nvim_prog', nvim_prog)
api.nvim_set_var(
'code',
[[
function! OnEvent(id, data, event) dict
@ -220,8 +220,8 @@ describe('channels', function()
\ 'rpc': v:true,
\ }
]])
meths.nvim_set_var('nvim_prog', nvim_prog)
meths.nvim_set_var(
api.nvim_set_var('nvim_prog', nvim_prog)
api.nvim_set_var(
'code',
[[
let id = stdioopen({'rpc':v:true})
@ -250,7 +250,7 @@ describe('channels', function()
end)
it('can use buffered output mode', function()
skip(funcs.executable('grep') == 0, 'missing "grep" command')
skip(fn.executable('grep') == 0, 'missing "grep" command')
source([[
let g:job_opts = {
\ 'on_stdout': function('OnEvent'),
@ -285,7 +285,7 @@ describe('channels', function()
end)
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([[
function! OnEvent(id, data, event) dict
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 eq = helpers.eq
local run = helpers.run
local funcs = helpers.funcs
local fn = helpers.fn
local nvim_prog = helpers.nvim_prog
local pcall_err = helpers.pcall_err
local exec_capture = helpers.exec_capture
@ -18,7 +18,7 @@ describe('v:exiting', function()
before_each(function()
helpers.clear()
cid = helpers.meths.nvim_get_api_info()[1]
cid = helpers.api.nvim_get_api_info()[1]
end)
it('defaults to v:null', function()
@ -68,7 +68,7 @@ describe(':cquit', function()
poke_eventloop()
assert_alive()
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'))
end
end

View File

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

View File

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

View File

@ -7,7 +7,7 @@ local matches = helpers.matches
local feed = helpers.feed
local eval = helpers.eval
local clear = helpers.clear
local funcs = helpers.funcs
local fn = helpers.fn
local nvim_prog_abs = helpers.nvim_prog_abs
local write_file = helpers.write_file
local is_os = helpers.is_os
@ -33,7 +33,7 @@ describe('command-line option', function()
it('treats - as stdin', function()
eq(nil, uv.fs_stat(fname))
funcs.system({
fn.system({
nvim_prog_abs(),
'-u',
'NONE',
@ -55,7 +55,7 @@ describe('command-line option', function()
eq(nil, uv.fs_stat(fname))
eq(true, not not dollar_fname:find('%$%w+'))
write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n')
funcs.system({
fn.system({
nvim_prog_abs(),
'-u',
'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
-- 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') },
})
screen:expect(
@ -128,7 +128,7 @@ describe('command-line option', function()
it('errors out when trying to use nonexistent file with -s', function()
eq(
'Cannot open for reading: "' .. nonexistent_fname .. '": no such file or directory\n',
funcs.system({
fn.system({
nvim_prog_abs(),
'-u',
'NONE',
@ -151,7 +151,7 @@ describe('command-line option', function()
write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
eq(
'Attempt to open script file again: "-s ' .. dollar_fname .. '"\n',
funcs.system({
fn.system({
nvim_prog_abs(),
'-u',
'NONE',
@ -175,9 +175,9 @@ describe('command-line option', function()
end)
it('nvim -v, :version', function()
matches('Run ":verbose version"', funcs.execute(':version'))
matches('Compilation: .*Run :checkhealth', funcs.execute(':verbose version'))
matches('Run "nvim %-V1 %-v"', funcs.system({ nvim_prog_abs(), '-v' }))
matches('Compilation: .*Run :checkhealth', funcs.system({ nvim_prog_abs(), '-V1', '-v' }))
matches('Run ":verbose version"', fn.execute(':version'))
matches('Compilation: .*Run :checkhealth', fn.execute(':verbose version'))
matches('Run "nvim %-V1 %-v"', fn.system({ nvim_prog_abs(), '-v' }))
matches('Compilation: .*Run :checkhealth', fn.system({ nvim_prog_abs(), '-V1', '-v' }))
end)
end)

View File

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

View File

@ -6,7 +6,7 @@ local eq = helpers.eq
local exec_capture = helpers.exec_capture
local exec_lua = helpers.exec_lua
local expect = helpers.expect
local funcs = helpers.funcs
local fn = helpers.fn
local insert = helpers.insert
local nvim_prog = helpers.nvim_prog
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
local function run_remote(...)
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
-- 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()
eq({ '', '' }, run_remote('--remote', fname))
expect(contents)
eq(2, #funcs.getbufinfo())
eq(2, #fn.getbufinfo())
end)
it('tab edit a single file with a non-changed buffer', function()
eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents)
eq(1, #funcs.gettabinfo())
eq(1, #fn.gettabinfo())
end)
it('tab edit a single file with a changed buffer', function()
insert('hello')
eq({ '', '' }, run_remote('--remote-tab', fname))
expect(contents)
eq(2, #funcs.gettabinfo())
eq(2, #fn.gettabinfo())
end)
it('edit multiple files', function()
@ -102,15 +102,15 @@ describe('Remote', function()
expect(contents)
command('next')
expect(other_contents)
eq(3, #funcs.getbufinfo())
eq(3, #fn.getbufinfo())
end)
it('send keys', function()
eq({ '', '' }, run_remote('--remote-send', ':edit ' .. fname .. '<CR><C-W>v'))
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
eq(1, #funcs.getbufinfo())
eq(1, #fn.getbufinfo())
end)
it('evaluate expressions', function()
@ -127,7 +127,7 @@ describe('Remote', function()
it('creates server if not found', function()
clear('--remote', fname)
expect(contents)
eq(1, #funcs.getbufinfo())
eq(1, #fn.getbufinfo())
-- Since we didn't pass silent, we should get a complaint
neq(nil, string.find(exec_capture('messages'), 'E247:'))
end)
@ -135,8 +135,8 @@ describe('Remote', function()
it('creates server if not found with tabs', function()
clear('--remote-tab-silent', fname, other_fname)
expect(contents)
eq(2, #funcs.gettabinfo())
eq(2, #funcs.getbufinfo())
eq(2, #fn.gettabinfo())
eq(2, #fn.getbufinfo())
-- We passed silent, so no message should be issued about the server not being found
eq(nil, string.find(exec_capture('messages'), 'E247:'))
end)

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local clear = helpers.clear
local meths = helpers.meths
local api = helpers.api
local exc_exec = helpers.exc_exec
local rmdir = helpers.rmdir
local write_file = helpers.write_file
@ -24,7 +24,7 @@ describe('spellfile', function()
-- │ ┌ Spell file version (#VIMSPELLVERSION)
local spellheader = 'VIMspell\050'
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
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND)
@ -35,11 +35,11 @@ describe('spellfile', function()
-- │ ┌ Condition length (1 byte)
-- │ │ ┌ Condition regex (missing!)
.. '\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'))
end)
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
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND)
@ -55,11 +55,11 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\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'))
end)
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
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_REGION)
@ -72,11 +72,11 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\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'))
end)
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
write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_SAL)
@ -96,13 +96,13 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length
.. '\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'))
end)
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')
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'))
end)
end)

View File

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

View File

@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local eq, clear, eval, feed, meths, retry =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.meths, helpers.retry
local eq, clear, eval, feed, api, retry =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.api, helpers.retry
describe('K', function()
local test_file = 'K_spec_out'
@ -61,9 +61,9 @@ describe('K', function()
end)
it('empty string falls back to :help #19298', function()
meths.nvim_set_option_value('keywordprg', '', {})
meths.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' })
api.nvim_set_option_value('keywordprg', '', {})
api.nvim_buf_set_lines(0, 0, -1, true, { 'doesnotexist' })
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)

View File

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

View File

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

View File

@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local funcs = helpers.funcs
local fn = helpers.fn
local feed = helpers.feed
local exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local meths = helpers.meths
local api = helpers.api
describe('jumplist', function()
local fname1 = 'Xtest-functional-normal-jump'
@ -20,7 +20,7 @@ describe('jumplist', function()
end)
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)
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')
command('args ' .. fname1 .. ' ' .. fname2)
local buf1 = funcs.bufnr(fname1)
local buf2 = funcs.bufnr(fname2)
local buf1 = fn.bufnr(fname1)
local buf2 = fn.bufnr(fname2)
command('next')
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
eq(buf1, fn.bufnr('%'))
command('first')
command('snext')
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
eq(buf1, fn.bufnr('%'))
feed('<C-I>')
eq(buf2, funcs.bufnr('%'))
eq(buf2, fn.bufnr('%'))
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
eq(buf1, fn.bufnr('%'))
command('drop ' .. fname2)
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
eq(buf1, fn.bufnr('%'))
end)
it('<C-O> scrolls cursor halfway when switching buffer #25763', function()
@ -284,7 +284,7 @@ describe('jumpoptions=view', function()
screen:attach()
command('edit ' .. file1)
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
-- 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.

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 command, insert, expect = helpers.command, helpers.insert, helpers.expect
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()
before_each(function()
@ -215,7 +215,7 @@ describe("'langmap'", function()
feed('qa' .. command_string .. 'q')
expect(expect_string)
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')
)
if setup_function then

View File

@ -6,8 +6,8 @@ local feed = helpers.feed
local clear = helpers.clear
local expect = helpers.expect
local command = helpers.command
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local insert = helpers.insert
describe('macros', function()
@ -40,18 +40,18 @@ hello]]
feed [[gg]]
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]]
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]]
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]]
eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false)
api.nvim_buf_get_lines(0, 0, -1, false)
)
end)
@ -62,18 +62,18 @@ hello]]
feed [[gg]]
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]]
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@@]]
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@@]]
eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false)
api.nvim_buf_get_lines(0, 0, -1, false)
)
end)
@ -84,17 +84,17 @@ hello]]
feed [[gg]]
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]]
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]]
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 [[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)
it('can be replayed with @q and @w visual-block', function()
@ -104,17 +104,17 @@ hello]]
feed [[gg]]
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]]
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]]
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 [[<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)
@ -127,13 +127,13 @@ describe('immediately after a macro has finished executing,', function()
describe('reg_executing() from RPC returns an empty string', function()
it('if the macro does not end with a <Nop> mapping', function()
feed('@a')
eq('', funcs.reg_executing())
eq('', fn.reg_executing())
end)
it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>')
feed('@a')
eq('', funcs.reg_executing())
eq('', fn.reg_executing())
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()
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('')
eq('', eval('@a'))
end)
@ -152,7 +152,7 @@ describe('immediately after a macro has finished executing,', function()
it('if the macro ends with a <Nop> mapping', function()
command('nnoremap 0 <Nop>')
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('')
eq('', eval('@a'))
end)

View File

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

View File

@ -4,7 +4,7 @@ local command = helpers.command
local exec_lua = helpers.exec_lua
local eval = helpers.eval
local expect = helpers.expect
local funcs = helpers.funcs
local fn = helpers.fn
local eq = helpers.eq
describe('meta-keys #8226 #13042', function()
@ -66,11 +66,11 @@ describe('meta-keys #8226 #13042', function()
command('inoremap <A-j> alt-j')
feed('i<M-l> xxx <A-j><M-h>a<A-h>')
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.
command('iunmap <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>
command('0,$d')
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('t', eval('mode(1)'))
feed('<Esc>j')
eq({ 0, 2, 1, 0 }, funcs.getpos('.'))
eq({ 0, 2, 1, 0 }, fn.getpos('.'))
eq('nt', eval('mode(1)'))
end)

View File

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

View File

@ -11,7 +11,7 @@ local filter = vim.tbl_filter
local feed_command = helpers.feed_command
local command = helpers.command
local curbuf_contents = helpers.curbuf_contents
local funcs = helpers.funcs
local fn = helpers.fn
local dedent = helpers.dedent
local function reset()
@ -21,9 +21,9 @@ local function reset()
Line of words 2]])
command('goto 1')
feed('itest_string.<esc>u')
funcs.setreg('a', 'test_stringa', 'V')
funcs.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b')
funcs.setreg('"', 'test_string"', 'v')
fn.setreg('a', 'test_stringa', 'V')
fn.setreg('b', 'test_stringb\ntest_stringb\ntest_stringb', 'b')
fn.setreg('"', 'test_string"', 'v')
end
-- 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)
local function visual_marks_zero()
for _, v in pairs(funcs.getpos("'<")) do
for _, v in pairs(fn.getpos("'<")) do
if v ~= 0 then
return false
end
end
for _, v in pairs(funcs.getpos("'>")) do
for _, v in pairs(fn.getpos("'>")) do
if v ~= 0 then
return false
end
@ -55,7 +55,7 @@ describe('put command', function()
extra_setup()
end
local init_contents = curbuf_contents()
local init_cursorpos = funcs.getcurpos()
local init_cursorpos = fn.getcurpos()
local assert_no_change = function(exception_table, after_undo)
expect(init_contents)
-- 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
-- line when we pasted).
if not (exception_table.undo_position and after_undo) then
eq(init_cursorpos, funcs.getcurpos())
eq(init_cursorpos, fn.getcurpos())
end
end
@ -74,7 +74,7 @@ describe('put command', function()
if extra_setup then
extra_setup()
end
local orig_dotstr = funcs.getreg('.')
local orig_dotstr = fn.getreg('.')
helpers.ok(visual_marks_zero())
-- Make sure every test starts from the same conditions
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
-- changing this register, hence avoid this check.
if not test.exception_table.dot_reg_changed then
eq(orig_dotstr, funcs.getreg('.'))
eq(orig_dotstr, fn.getreg('.'))
end
-- Doing something, undoing it, and then redoing it should
@ -105,7 +105,7 @@ describe('put command', function()
end
if test.exception_table.undo_position then
funcs.setpos('.', init_cursorpos)
fn.setpos('.', init_cursorpos)
end
if was_cli then
feed('@:')
@ -151,7 +151,7 @@ describe('put command', function()
-- it was in.
-- This returns the cursor position that would leave the 'x' in that
-- 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')
if column then
return { linenum, column }, expect_string:gsub('x', '')
@ -184,16 +184,16 @@ describe('put command', function()
return function(exception_table, after_redo)
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.
-- We always want the curswant element in getcurpos(), which is
-- 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
-- when running, but does not when the command is redone with the
-- '.' command.
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] })
end
end
@ -349,7 +349,7 @@ describe('put command', function()
local prev_line
local rettab = {}
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
string_found = true
table.insert(rettab, line)
@ -476,7 +476,7 @@ describe('put command', function()
local prev_line
local rettab = {}
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 prev_line then
prev_line = prev_line:gsub('x', '')
@ -524,10 +524,10 @@ describe('put command', function()
test_expect(exception_table, after_redo)
if selection_string then
if not conversion_table.put_backwards then
eq(selection_string, funcs.getreg('"'))
eq(selection_string, fn.getreg('"'))
end
else
eq('test_string"', funcs.getreg('"'))
eq('test_string"', fn.getreg('"'))
end
end
end
@ -657,10 +657,10 @@ describe('put command', function()
xtest_string"]],
'put',
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
-- 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')
end
)
@ -671,9 +671,9 @@ describe('put command', function()
Line of words 1
test_stringx" Line of words 2]]
run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2')
fn.setline('$', ' Line of words 2')
command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 2, 1, 2, 3 })
fn.setpos('.', { 0, 2, 1, 2, 3 })
end)
end)
@ -683,9 +683,9 @@ describe('put command', function()
Line of words 1 test_stringx"
Line of words 2]]
run_normal_mode_tests(test_string, 'p', function()
funcs.setline('$', ' Line of words 2')
fn.setline('$', ' Line of words 2')
command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 1, 16, 1, 17 })
fn.setpos('.', { 0, 1, 16, 1, 17 })
end, true)
end)
@ -699,7 +699,7 @@ describe('put command', function()
describe('over trailing newline', function()
local test_string = 'Line of test_stringx"Line of words 2'
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)
describe('linewise mode', function()
@ -720,7 +720,7 @@ describe('put command', function()
expect_vis_linewise
),
function()
funcs.setpos('.', { 0, 1, 1, 0, 1 })
fn.setpos('.', { 0, 1, 1, 0, 1 })
end
)
@ -732,7 +732,7 @@ describe('put command', function()
return function(exception_table, after_redo)
test_expect(exception_table, after_redo)
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
@ -749,7 +749,7 @@ describe('put command', function()
),
function()
feed('i test_string.<esc>u')
funcs.setreg('"', ' test_string"', 'v')
fn.setreg('"', ' test_string"', 'v')
end
)
end)
@ -767,7 +767,7 @@ describe('put command', function()
return function(e, c)
test_expect(e, c)
if not conversion_table.put_backwards then
eq('Lin\nLin', funcs.getreg('"'))
eq('Lin\nLin', fn.getreg('"'))
end
end
end
@ -804,7 +804,7 @@ describe('put command', function()
expect_block_creator
),
function()
funcs.setpos('.', { 0, 2, 1, 0, 1 })
fn.setpos('.', { 0, 2, 1, 0, 1 })
end
)
@ -820,16 +820,16 @@ describe('put command', function()
feed('u')
-- Have to use feed('u') here to set curswant, because
-- 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>')
eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos())
eq({ 0, 1, 1, 0, 1 }, fn.getcurpos())
end
end
run_test_variations(
create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator),
function()
funcs.setpos('.', { 0, 2, 1, 0, 1 })
fn.setpos('.', { 0, 2, 1, 0, 1 })
end
)
end)
@ -841,9 +841,9 @@ describe('put command', function()
Line of words 1
test_stringx" Line of words 2]]
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')
funcs.setpos('.', { 0, 2, 1, 2, 3 })
fn.setpos('.', { 0, 2, 1, 2, 3 })
end, nil, ' ')
end)
describe('after end of line', function()
@ -852,7 +852,7 @@ describe('put command', function()
Line of words 2]]
run_normal_mode_tests(base_expect_string, 'vp', function()
command('setlocal virtualedit=all')
funcs.setpos('.', { 0, 1, 16, 2, 18 })
fn.setpos('.', { 0, 1, 16, 2, 18 })
end, true, ' ')
end)
end)
@ -917,14 +917,14 @@ describe('put command', function()
-- Even if the last character is a multibyte character.
reset()
funcs.setline(1, 'helloม')
fn.setline(1, 'helloม')
bell_test(function()
feed('$".gp')
end)
end)
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()
feed('$vl".gp')
end)
@ -942,9 +942,9 @@ describe('put command', function()
end)
it('should restore cursor position after undo of ".p', function()
local origpos = funcs.getcurpos()
local origpos = fn.getcurpos()
feed('".pu')
eq(origpos, funcs.getcurpos())
eq(origpos, fn.getcurpos())
end)
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 eval = helpers.eval
local exec = helpers.exec
local funcs = helpers.funcs
local meths = helpers.meths
local curwin = helpers.meths.nvim_get_current_win
local fn = helpers.fn
local api = helpers.api
local curwin = helpers.api.nvim_get_current_win
local assert_alive = helpers.assert_alive
describe('tabpage', function()
@ -74,29 +74,29 @@ describe('tabpage', function()
end)
it('nvim_win_close and nvim_win_hide update tabline #20285', function()
eq(1, #meths.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0))
eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, fn.win_screenpos(0))
local win1 = curwin().id
command('tabnew')
eq(2, #meths.nvim_list_tabpages())
eq({ 2, 1 }, funcs.win_screenpos(0))
eq(2, #api.nvim_list_tabpages())
eq({ 2, 1 }, fn.win_screenpos(0))
local win2 = curwin().id
meths.nvim_win_close(win1, true)
api.nvim_win_close(win1, true)
eq(win2, curwin().id)
eq(1, #meths.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0))
eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, fn.win_screenpos(0))
command('tabnew')
eq(2, #meths.nvim_list_tabpages())
eq({ 2, 1 }, funcs.win_screenpos(0))
eq(2, #api.nvim_list_tabpages())
eq({ 2, 1 }, fn.win_screenpos(0))
local win3 = curwin().id
meths.nvim_win_hide(win2)
api.nvim_win_hide(win2)
eq(win3, curwin().id)
eq(1, #meths.nvim_list_tabpages())
eq({ 1, 1 }, funcs.win_screenpos(0))
eq(1, #api.nvim_list_tabpages())
eq({ 1, 1 }, fn.win_screenpos(0))
end)
it('switching tabpage after setting laststatus=3 #19591', function()
@ -135,15 +135,15 @@ describe('tabpage', function()
it(':tabmove handles modifiers and addr', function()
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')
eq(3, funcs.nvim_tabpage_get_number(0))
eq(3, fn.nvim_tabpage_get_number(0))
command(' silent :keepalt :: ::: silent! -2 tabmove')
eq(1, funcs.nvim_tabpage_get_number(0))
eq(1, fn.nvim_tabpage_get_number(0))
end)
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')
assert_alive()
end)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local testprg = helpers.testprg
local retry = helpers.retry
@ -14,7 +14,7 @@ describe(':ls', function()
end)
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('set hidden')

View File

@ -3,7 +3,7 @@ local clear = helpers.clear
local eval = helpers.eval
local has_powershell = helpers.has_powershell
local matches = helpers.matches
local meths = helpers.meths
local api = helpers.api
local testprg = helpers.testprg
describe(':make', function()
@ -22,7 +22,7 @@ describe(':make', function()
end)
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")')
-- Error message is captured in the file and printed in the footer
matches(
@ -32,7 +32,7 @@ describe(':make', function()
end)
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")')
-- Ensure there are no "shell returned X" messages between
-- command and last line (indicating zero exit)

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ local clear = helpers.clear
local command = helpers.command
local get_pathsep = helpers.get_pathsep
local eq = helpers.eq
local funcs = helpers.funcs
local fn = helpers.fn
local rmdir = helpers.rmdir
local mkdir = helpers.mkdir
@ -28,7 +28,7 @@ describe(':mkview', function()
end)
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
-- By default the local current directory should save
@ -55,11 +55,11 @@ describe(':mkview', function()
command('edit ' .. tmp_file_base .. '2')
command('loadview')
-- 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
command('edit ' .. tmp_file_base .. '1')
command('loadview')
-- 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)

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local funcs = helpers.funcs
local fn = helpers.fn
local feed = helpers.feed
local expect = helpers.expect
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()
feed('q:')
feed('v')
eq('v', funcs.mode(1))
eq(':', funcs.getcmdwintype())
eq('v', fn.mode(1))
eq(':', fn.getcmdwintype())
command('normal! \027')
eq('n', funcs.mode(1))
eq(':', funcs.getcmdwintype())
eq('n', fn.mode(1))
eq(':', fn.getcmdwintype())
end)
end)

View File

@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
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 ok = helpers.ok
local eval = helpers.eval
@ -42,7 +42,7 @@ describe(':oldfiles', function()
feed_command('edit testfile2')
feed_command('wshada')
feed_command('rshada!')
local oldfiles = meths.nvim_get_vvar('oldfiles')
local oldfiles = api.nvim_get_vvar('oldfiles')
feed_command('oldfiles')
screen:expect([[
|
@ -56,11 +56,11 @@ describe(':oldfiles', function()
it('can be filtered with :filter', function()
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')
local file2 = meths.nvim_buf_get_name(0)
local file2 = api.nvim_buf_get_name(0)
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('rshada!')
@ -95,9 +95,9 @@ describe(':browse oldfiles', function()
before_each(function()
_clear()
feed_command('edit testfile1')
filename = meths.nvim_buf_get_name(0)
filename = api.nvim_buf_get_name(0)
feed_command('edit testfile2')
filename2 = meths.nvim_buf_get_name(0)
filename2 = api.nvim_buf_get_name(0)
feed_command('wshada')
poke_eventloop()
_clear()
@ -108,7 +108,7 @@ describe(':browse oldfiles', function()
-- Ensure v:oldfiles isn't busted. Since things happen so fast,
-- 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.
oldfiles = helpers.meths.nvim_get_vvar('oldfiles')
oldfiles = helpers.api.nvim_get_vvar('oldfiles')
eq(2, #oldfiles)
ok(filename == oldfiles[1] or filename == 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()
feed('2<cr>')
eq(oldfiles[2], meths.nvim_buf_get_name(0))
eq(oldfiles[2], api.nvim_buf_get_name(0))
end)
it('provides a prompt and does nothing on <cr>', function()
feed('<cr>')
eq('', meths.nvim_buf_get_name(0))
eq('', api.nvim_buf_get_name(0))
end)
it('provides a prompt and does nothing if choice is out-of-bounds', function()
feed('3<cr>')
eq('', meths.nvim_buf_get_name(0))
eq('', api.nvim_buf_get_name(0))
end)
end)

View File

@ -1,11 +1,11 @@
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()
before_each(clear)
it('correctly sets the cursor after :z^', function()
command('z^')
eq(1, funcs.line('.'))
eq(1, fn.line('.'))
end)
end)

View File

@ -4,11 +4,11 @@ local Screen = require('test.functional.ui.screen')
local feed = helpers.feed
local eq = helpers.eq
local clear = helpers.clear
local funcs = helpers.funcs
local fn = helpers.fn
local command = helpers.command
local exc_exec = helpers.exc_exec
local write_file = helpers.write_file
local meths = helpers.meths
local api = helpers.api
local source = helpers.source
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 getfcmd = c .. 'getfile'
local addfcmd = c .. 'addfile'
local getlist = (c == 'c') and funcs.getqflist or function()
return funcs.getloclist(0)
local getlist = (c == 'c') and fn.getqflist or function()
return fn.getloclist(0)
end
describe((':%s*file commands'):format(c), function()
@ -73,13 +73,13 @@ for _, c in ipairs({ 'l', 'c' }) do
},
}
eq(list, getlist())
eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr))
eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
-- Run cfile/lfile from a modified buffer
command('set nohidden')
command('enew!')
meths.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
eq(
('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd),
exc_exec(('%s %s'):format(filecmd, file))
@ -107,7 +107,7 @@ for _, c in ipairs({ 'l', 'c' }) do
['type'] = '',
}
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(
file,
@ -149,8 +149,8 @@ for _, c in ipairs({ 'l', 'c' }) do
},
}
eq(list, getlist())
eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr))
eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr))
eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr))
end)
end)
end
@ -178,7 +178,7 @@ describe('quickfix', function()
call append(0, ['New line 1', 'New line 2', 'New line 3'])
silent ll
]])
eq({ 0, 6, 1, 0, 1 }, funcs.getcurpos())
eq({ 0, 6, 1, 0, 1 }, fn.getcurpos())
end)
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 exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local meths = helpers.meths
local api = helpers.api
local clear = helpers.clear
local dedent = helpers.dedent
local exc_exec = helpers.exc_exec
@ -83,7 +83,7 @@ describe('script_get-based command', function()
]])):format(cmd, garbage)
)
)
neq(0, meths.nvim_get_var('exc'))
neq(0, api.nvim_get_var('exc'))
end
end)
end)

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture
local matches = helpers.matches
local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os
local funcs = helpers.funcs
local fn = helpers.fn
describe(':trust', function()
local xstate = 'Xstate'
@ -30,53 +30,53 @@ describe(':trust', function()
end)
it('trust then deny then remove a file using current buffer', function()
local cwd = funcs.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file'))
local cwd = fn.getcwd()
local hash = fn.sha256(helpers.read_file('test_file'))
command('edit test_file')
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))
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))
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))
end)
it('deny then trust then remove a file using current buffer', function()
local cwd = funcs.getcwd()
local hash = funcs.sha256(helpers.read_file('test_file'))
local cwd = fn.getcwd()
local hash = fn.sha256(helpers.read_file('test_file'))
command('edit test_file')
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))
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))
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))
end)
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'))
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))
matches(
'^Removed ".*test_file" from trust database%.$',
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))
end)
end)

View File

@ -5,7 +5,7 @@ local eq = helpers.eq
local exec = helpers.exec
local exec_capture = helpers.exec_capture
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 script_location, script_file

View File

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

View File

@ -4,8 +4,8 @@ local eq, eval, clear, write_file, source, insert =
local pcall_err = helpers.pcall_err
local command = helpers.command
local feed_command = helpers.feed_command
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local skip = helpers.skip
local is_os = helpers.is_os
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/'))
if not is_os('win') then
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 .')
)
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 ./')
)
end
@ -125,26 +125,26 @@ describe(':write', function()
it('errors out correctly', function()
skip(is_ci('cirrus'))
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
if not is_os('win') then
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 .')
)
end
meths.nvim_set_option_value('writeany', true, {})
api.nvim_set_option_value('writeany', true, {})
-- Message from buf_write
eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .'))
funcs.mkdir(fname_bak)
meths.nvim_set_option_value('backupdir', '.', {})
meths.nvim_set_option_value('backup', true, {})
fn.mkdir(fname_bak)
api.nvim_set_option_value('backupdir', '.', {})
api.nvim_set_option_value('backup', true, {})
write_file(fname, 'content0')
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'))
meths.nvim_set_option_value('backup', false, {})
funcs.setfperm(fname, 'r--------')
api.nvim_set_option_value('backup', false, {})
fn.setfperm(fname, 'r--------')
eq(
'Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)',
pcall_err(command, 'write')

View File

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

View File

@ -8,8 +8,8 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local neq = helpers.neq
local poke_eventloop = helpers.poke_eventloop
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local clear = helpers.clear
local insert = helpers.insert
local command = helpers.command
@ -56,21 +56,21 @@ describe("'directory' option", function()
line 3 Abcdefghij
end of testfile]])
meths.nvim_set_option_value('swapfile', true, {})
meths.nvim_set_option_value('swapfile', true, {})
meths.nvim_set_option_value('directory', '.', {})
api.nvim_set_option_value('swapfile', true, {})
api.nvim_set_option_value('swapfile', true, {})
api.nvim_set_option_value('directory', '.', {})
-- sanity check: files should not exist yet.
eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
command('edit! Xtest1')
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
-- reading the output from :!ls.
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')
poke_eventloop()
@ -79,10 +79,10 @@ describe("'directory' option", function()
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('edit Xtest2/Xtest3')
eq(true, meths.nvim_get_option_value('swapfile', {}))
eq(true, api.nvim_get_option_value('swapfile', {}))
poke_eventloop()
eq({ 'Xtest3' }, ls_dir_sorted('Xtest2'))

View File

@ -2,7 +2,7 @@
-- And test "U" in Visual mode, also on German sharp S.
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 clear, expect = helpers.clear, helpers.expect
local feed_command = helpers.feed_command

View File

@ -1,5 +1,5 @@
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 source, command = helpers.source, helpers.command
local exc_exec = helpers.exc_exec

View File

@ -1,11 +1,11 @@
local helpers = require('test.functional.helpers')(after_each)
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 mkdir = helpers.mkdir
local function expected_empty()
eq({}, meths.nvim_get_vvar('errors'))
eq({}, api.nvim_get_vvar('errors'))
end
describe('autochdir behavior', function()

View File

@ -1,9 +1,9 @@
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 meths = helpers.meths
local curbuf = helpers.meths.nvim_get_current_buf
local curwin = helpers.meths.nvim_get_current_win
local api = helpers.api
local curbuf = helpers.api.nvim_get_current_buf
local curwin = helpers.api.nvim_get_current_win
local exec_capture = helpers.exec_capture
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()
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")')
expected_combination({
@ -648,7 +648,7 @@ describe('au OptionSet', function()
set_hook('buftype')
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")')
expected_combination({

View File

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

View File

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

View File

@ -5,7 +5,7 @@ local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local meths = helpers.meths
local api = helpers.api
local poke_eventloop = helpers.poke_eventloop
before_each(clear)
@ -16,7 +16,7 @@ describe('Ex mode', function()
feed('gQ' .. cmd .. '<C-b>"<CR>')
local ret = eval('@:[1:]') -- Remove leading quote.
feed('visual<CR>')
eq(meths.nvim_replace_termcodes(expected, true, true, true), ret)
eq(api.nvim_replace_termcodes(expected, true, true, true), ret)
end
command('set sw=2')
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 expect_exit = helpers.expect_exit
local feed = helpers.feed
local funcs = helpers.funcs
local meths = helpers.meths
local fn = helpers.fn
local api = helpers.api
local read_file = helpers.read_file
local source = helpers.source
local eq = helpers.eq
@ -24,7 +24,7 @@ end
describe('Ex command', function()
before_each(clear)
after_each(function()
eq({}, meths.nvim_get_vvar('errors'))
eq({}, api.nvim_get_vvar('errors'))
end)
it('checks for address line overflow', function()
@ -340,7 +340,7 @@ describe(':confirm command dialog', function()
feed('<CR>') -- suppress hit-enter prompt
-- 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')
screen:expect([[
foobar |

View File

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

View File

@ -2,7 +2,7 @@
local helpers = require('test.functional.helpers')(after_each)
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()
eq({}, nvim.nvim_get_vvar('errors'))

View File

@ -3,7 +3,7 @@
local helpers = require('test.functional.helpers')(after_each)
local source, command = helpers.source, helpers.command
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()
before_each(function()

View File

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

View File

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

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local command = helpers.command
local funcs = helpers.funcs
local fn = helpers.fn
local eq = helpers.eq
describe('mksession', function()
@ -18,7 +18,7 @@ describe('mksession', function()
command('mksession! Xtest_mks.out')
local found_rtp = 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
found_rtp = found_rtp + 1
end
@ -32,7 +32,7 @@ describe('mksession', function()
command('set sessionoptions+=skiprtp')
command('mksession! Xtest_mks.out')
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
found_rtp_or_pp = found_rtp_or_pp + 1
end

View File

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

View File

@ -5,7 +5,7 @@ local source = helpers.source
local clear = helpers.clear
local command = helpers.command
local poke_eventloop = helpers.poke_eventloop
local meths = helpers.meths
local api = helpers.api
local eq = helpers.eq
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'])})
]]
poke_eventloop()
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
end)
-- oldtest: Test_prompt_appending_while_hidden()
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([[
new prompt
set buftype=prompt
@ -205,16 +205,16 @@ describe('prompt buffer', function()
endfunc
]])
feed('asomething<CR>')
eq('something', meths.nvim_get_var('entered'))
neq(prev_win, meths.nvim_get_current_win())
eq('something', api.nvim_get_var('entered'))
neq(prev_win, api.nvim_get_current_win())
feed('exit<CR>')
eq(prev_win, meths.nvim_get_current_win())
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq(prev_win, api.nvim_get_current_win())
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
command('call DoAppend()')
eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
feed('i')
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
command('call DoAppend()')
eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
end)
end)

View File

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

View File

@ -5,7 +5,7 @@ local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local funcs = helpers.funcs
local fn = helpers.fn
local poke_eventloop = helpers.poke_eventloop
local exec = helpers.exec
@ -27,7 +27,7 @@ describe('search cmdline', function()
end)
local function tenlines()
funcs.setline(1, {
fn.setline(1, {
' 1',
' 2 these',
' 3 the',
@ -68,7 +68,7 @@ describe('search cmdline', function()
3 {inc:the} |
/the^ |
]])
eq({ 0, 0, 0, 0 }, funcs.getpos('"'))
eq({ 0, 0, 0, 0 }, fn.getpos('"'))
feed('<C-G>')
screen:expect([[
3 the |
@ -125,7 +125,7 @@ describe('search cmdline', function()
end,
}
feed('<CR>')
eq({ 0, 0, 0, 0 }, funcs.getpos('"'))
eq({ 0, 0, 0, 0 }, fn.getpos('"'))
end
end
@ -368,7 +368,7 @@ describe('search cmdline', function()
end)
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('set incsearch')
@ -465,7 +465,7 @@ describe('search cmdline', function()
coladd = 0,
skipcol = 0,
curswant = 4,
}, funcs.winsaveview())
}, fn.winsaveview())
end)
it('restores original view after failed search', function()
@ -500,14 +500,14 @@ describe('search cmdline', function()
coladd = 0,
skipcol = 0,
curswant = 0,
}, funcs.winsaveview())
}, fn.winsaveview())
end)
-- oldtest: Test_search_cmdline4().
it("CTRL-G with 'incsearch' and ? goes in the right direction", function()
screen:try_resize(40, 4)
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 incsearch')
command('$')
@ -608,7 +608,7 @@ describe('search cmdline', function()
it('incsearch works with :sort', function()
screen:try_resize(20, 4)
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')
screen:expect([[
@ -624,7 +624,7 @@ describe('search cmdline', function()
it('incsearch works with :vimgrep family', function()
screen:try_resize(30, 4)
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')
screen:expect([[

View File

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

View File

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

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