test: normalise nvim bridge functions

- remove helpers.cur*meths
- remove helpers.nvim
This commit is contained in:
Lewis Russell 2024-01-12 13:11:28 +00:00
parent c30f2e3182
commit 4f81f506f9
79 changed files with 1700 additions and 1753 deletions

View File

@ -109,12 +109,12 @@ describe('autocmd api', function()
buffer = 0, buffer = 0,
}) })
meths.nvim_command 'set filetype=txt' command 'set filetype=txt'
eq(1, meths.nvim_get_var('called')) eq(1, meths.nvim_get_var('called'))
-- switch to a new buffer -- switch to a new buffer
meths.nvim_command 'new' command 'new'
meths.nvim_command 'set filetype=python' command 'set filetype=python'
eq(1, meths.nvim_get_var('called')) eq(1, meths.nvim_get_var('called'))
end) end)
@ -938,7 +938,7 @@ describe('autocmd api', function()
meths.nvim_exec_autocmds('CursorHold', { buffer = 1 }) meths.nvim_exec_autocmds('CursorHold', { buffer = 1 })
eq('none', meths.nvim_get_var('filename_executed')) eq('none', meths.nvim_get_var('filename_executed'))
meths.nvim_command('edit __init__.py') command('edit __init__.py')
eq('__init__.py', meths.nvim_get_var('filename_executed')) eq('__init__.py', meths.nvim_get_var('filename_executed'))
end) end)
@ -955,8 +955,8 @@ describe('autocmd api', function()
meths.nvim_set_var('filename_executed', 'none') meths.nvim_set_var('filename_executed', 'none')
eq('none', meths.nvim_get_var('filename_executed')) eq('none', meths.nvim_get_var('filename_executed'))
meths.nvim_command('edit other_file.txt') command('edit other_file.txt')
meths.nvim_command('edit __init__.py') command('edit __init__.py')
eq('none', meths.nvim_get_var('filename_executed')) eq('none', meths.nvim_get_var('filename_executed'))
meths.nvim_create_autocmd('CursorHoldI', { meths.nvim_create_autocmd('CursorHoldI', {

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -3,10 +3,8 @@ local helpers = require('test.functional.helpers')(after_each)
local NIL = vim.NIL local NIL = vim.NIL
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local meths = helpers.meths local meths = helpers.meths
local bufmeths = helpers.bufmeths
local matches = helpers.matches local matches = helpers.matches
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@ -74,16 +72,16 @@ describe('nvim_get_commands', function()
it('gets buffer-local user-defined commands', function() it('gets buffer-local user-defined commands', function()
-- Define a buffer-local command. -- Define a buffer-local command.
command('command -buffer -nargs=1 Hello echo "Hello World"') command('command -buffer -nargs=1 Hello echo "Hello World"')
eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false }))
-- Define another buffer-local command. -- Define another buffer-local command.
command('command -buffer -nargs=? Pwd pwd') command('command -buffer -nargs=? Pwd pwd')
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, curbufmeths.get_commands({ builtin = false })) eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_buf_get_commands(0, { builtin = false }))
-- Delete a command. -- Delete a command.
command('delcommand Pwd') command('delcommand Pwd')
eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false })) eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false }))
-- {builtin=true} always returns empty for buffer-local case. -- {builtin=true} always returns empty for buffer-local case.
eq({}, curbufmeths.get_commands({ builtin = true })) eq({}, meths.nvim_buf_get_commands(0, { builtin = true }))
end) end)
it('gets various command attributes', function() it('gets various command attributes', function()
@ -203,7 +201,7 @@ describe('nvim_create_user_command', function()
it('works with strings', function() it('works with strings', function()
meths.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 }) meths.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 })
meths.nvim_command('SomeCommand 42') command('SomeCommand 42')
eq(42, meths.nvim_eval('g:command_fired')) eq(42, meths.nvim_eval('g:command_fired'))
end) end)
@ -647,10 +645,10 @@ describe('nvim_create_user_command', function()
it('can define buffer-local commands', function() it('can define buffer-local commands', function()
local bufnr = meths.nvim_create_buf(false, false) local bufnr = meths.nvim_create_buf(false, false)
bufmeths.create_user_command(bufnr, 'Hello', '', {}) meths.nvim_buf_create_user_command(bufnr, 'Hello', '', {})
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
meths.nvim_set_current_buf(bufnr) meths.nvim_set_current_buf(bufnr)
meths.nvim_command('Hello') command('Hello')
assert_alive() assert_alive()
end) end)
@ -762,15 +760,15 @@ describe('nvim_del_user_command', function()
it('can delete global commands', function() it('can delete global commands', function()
meths.nvim_create_user_command('Hello', 'echo "Hi"', {}) meths.nvim_create_user_command('Hello', 'echo "Hi"', {})
meths.nvim_command('Hello') command('Hello')
meths.nvim_del_user_command('Hello') meths.nvim_del_user_command('Hello')
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
end) end)
it('can delete buffer-local commands', function() it('can delete buffer-local commands', function()
bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {}) meths.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {})
meths.nvim_command('Hello') command('Hello')
bufmeths.del_user_command(0, 'Hello') meths.nvim_buf_del_user_command(0, 'Hello')
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello')) matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
end) end)
end) end)

View File

@ -4,8 +4,6 @@ local Screen = require('test.functional.ui.screen')
local request = helpers.request local request = helpers.request
local eq = helpers.eq local eq = helpers.eq
local ok = helpers.ok local ok = helpers.ok
local curbufmeths = helpers.curbufmeths
local bufmeths = helpers.bufmeths
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local insert = helpers.insert local insert = helpers.insert
local feed = helpers.feed local feed = helpers.feed
@ -26,21 +24,21 @@ local function set_extmark(ns_id, id, line, col, opts)
if id ~= nil and id ~= 0 then if id ~= nil and id ~= 0 then
opts.id = id opts.id = id
end end
return curbufmeths.set_extmark(ns_id, line, col, opts) return meths.nvim_buf_set_extmark(0, ns_id, line, col, opts)
end end
local function get_extmarks(ns_id, start, end_, opts) local function get_extmarks(ns_id, start, end_, opts)
if opts == nil then if opts == nil then
opts = {} opts = {}
end end
return curbufmeths.get_extmarks(ns_id, start, end_, opts) return meths.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
end end
local function get_extmark_by_id(ns_id, id, opts) local function get_extmark_by_id(ns_id, id, opts)
if opts == nil then if opts == nil then
opts = {} opts = {}
end end
return curbufmeths.get_extmark_by_id(ns_id, id, opts) return meths.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
end end
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
@ -198,11 +196,11 @@ describe('API/extmarks', function()
eq({ row, col }, rv) eq({ row, col }, rv)
-- remove the test marks -- remove the test marks
eq(true, curbufmeths.del_extmark(ns, marks[1])) eq(true, meths.nvim_buf_del_extmark(0, ns, marks[1]))
eq(false, curbufmeths.del_extmark(ns, marks[1])) eq(false, meths.nvim_buf_del_extmark(0, ns, marks[1]))
eq(true, curbufmeths.del_extmark(ns, marks[2])) eq(true, meths.nvim_buf_del_extmark(0, ns, marks[2]))
eq(false, curbufmeths.del_extmark(ns, marks[3])) eq(false, meths.nvim_buf_del_extmark(0, ns, marks[3]))
eq(false, curbufmeths.del_extmark(ns, 1000)) eq(false, meths.nvim_buf_del_extmark(0, ns, 1000))
end) end)
it('can clear a specific namespace range', function() it('can clear a specific namespace range', function()
@ -210,7 +208,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1) set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer -- force a new undo buffer
feed('o<esc>') feed('o<esc>')
curbufmeths.clear_namespace(ns2, 0, -1) meths.nvim_buf_clear_namespace(0, ns2, 0, -1)
eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
@ -226,7 +224,7 @@ describe('API/extmarks', function()
set_extmark(ns2, 1, 0, 1) set_extmark(ns2, 1, 0, 1)
-- force a new undo buffer -- force a new undo buffer
feed('o<esc>') feed('o<esc>')
curbufmeths.clear_namespace(-1, 0, -1) meths.nvim_buf_clear_namespace(0, -1, 0, -1)
eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
@ -244,14 +242,14 @@ describe('API/extmarks', function()
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('dd') feed('dd')
eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
curbufmeths.clear_namespace(ns, 0, -1) meths.nvim_buf_clear_namespace(0, ns, 0, -1)
eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
set_extmark(ns, 1, 0, 0, { right_gravity = false }) set_extmark(ns, 1, 0, 0, { right_gravity = false })
set_extmark(ns, 2, 1, 0, { right_gravity = false }) set_extmark(ns, 2, 1, 0, { right_gravity = false })
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
feed('u') feed('u')
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 })) eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
curbufmeths.clear_namespace(ns, 0, -1) meths.nvim_buf_clear_namespace(0, ns, 0, -1)
end) end)
it('querying for information and ranges', function() it('querying for information and ranges', function()
@ -933,7 +931,7 @@ describe('API/extmarks', function()
-- Test unset -- Test unset
feed('o<esc>') feed('o<esc>')
curbufmeths.del_extmark(ns, marks[3]) meths.nvim_buf_del_extmark(0, ns, marks[3])
feed('u') feed('u')
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
-- undo does NOT restore deleted marks -- undo does NOT restore deleted marks
@ -989,10 +987,10 @@ describe('API/extmarks', function()
rv = get_extmarks(ns2, positions[2], positions[1]) rv = get_extmarks(ns2, positions[2], positions[1])
eq(2, #rv) eq(2, #rv)
curbufmeths.del_extmark(ns, marks[1]) meths.nvim_buf_del_extmark(0, ns, marks[1])
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
eq(2, #rv) eq(2, #rv)
curbufmeths.del_extmark(ns2, marks[1]) meths.nvim_buf_del_extmark(0, ns2, marks[1])
rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 }) rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
eq(2, #rv) eq(2, #rv)
end) end)
@ -1429,7 +1427,7 @@ describe('API/extmarks', function()
"Invalid 'ns_id': 3", "Invalid 'ns_id': 3",
pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2]) pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
) )
eq("Invalid 'ns_id': 3", pcall_err(curbufmeths.del_extmark, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(meths.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2])) eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1])) eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
end) end)
@ -1480,8 +1478,8 @@ describe('API/extmarks', function()
it('can set a mark to other buffer', function() it('can set a mark to other buffer', function()
local buf = request('nvim_create_buf', 0, 1) local buf = request('nvim_create_buf', 0, 1)
request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' }) request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
local id = bufmeths.set_extmark(buf, ns, 1, 0, {}) local id = meths.nvim_buf_set_extmark(buf, ns, 1, 0, {})
eq({ { id, 1, 0 } }, bufmeths.get_extmarks(buf, ns, 0, -1, {})) eq({ { id, 1, 0 } }, meths.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
end) end)
it('does not crash with append/delete/undo sequence', function() it('does not crash with append/delete/undo sequence', function()
@ -1497,24 +1495,24 @@ describe('API/extmarks', function()
it('works with left and right gravity', function() it('works with left and right gravity', function()
-- right gravity should move with inserted text, while -- right gravity should move with inserted text, while
-- left gravity should stay in place. -- left gravity should stay in place.
curbufmeths.set_extmark(ns, 0, 5, { right_gravity = false }) meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false })
curbufmeths.set_extmark(ns, 0, 5, { right_gravity = true }) meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
feed([[Aasdfasdf]]) feed([[Aasdfasdf]])
eq({ { 1, 0, 5 }, { 2, 0, 13 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) eq({ { 1, 0, 5 }, { 2, 0, 13 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
-- but both move when text is inserted before -- but both move when text is inserted before
feed([[<esc>Iasdf<esc>]]) feed([[<esc>Iasdf<esc>]])
-- eq({}, curbufmeths.get_lines(0, -1, true)) -- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true))
eq({ { 1, 0, 9 }, { 2, 0, 17 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) eq({ { 1, 0, 9 }, { 2, 0, 17 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
-- clear text -- clear text
curbufmeths.set_text(0, 0, 0, 17, {}) meths.nvim_buf_set_text(0, 0, 0, 0, 17, {})
-- handles set_text correctly as well -- handles set_text correctly as well
eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {})) eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
curbufmeths.set_text(0, 0, 0, 0, { 'asdfasdf' }) meths.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, curbufmeths.get_extmarks(ns, 0, -1, {})) eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
feed('u') feed('u')
-- handles pasting -- handles pasting
@ -1641,7 +1639,7 @@ describe('API/extmarks', function()
right_gravity = true, right_gravity = true,
}, },
}, get_extmark_by_id(ns, marks[3], { details = true })) }, get_extmark_by_id(ns, marks[3], { details = true }))
curbufmeths.clear_namespace(ns, 0, -1) meths.nvim_buf_clear_namespace(0, ns, 0, -1)
-- legacy sign mark includes sign name -- legacy sign mark includes sign name
command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine') command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
command('sign place 1 name=sign1 line=1') command('sign place 1 name=sign1 line=1')
@ -1770,7 +1768,7 @@ describe('Extmarks buffer api with many marks', function()
for i = 1, 30 do for i = 1, 30 do
lines[#lines + 1] = string.rep('x ', i) lines[#lines + 1] = string.rep('x ', i)
end end
curbufmeths.set_lines(0, -1, true, lines) meths.nvim_buf_set_lines(0, 0, -1, true, lines)
local ns = ns1 local ns = ns1
local q = 0 local q = 0
for i = 0, 29 do for i = 0, 29 do
@ -1804,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function()
end) end)
it('can clear all marks in ns', function() it('can clear all marks in ns', function()
curbufmeths.clear_namespace(ns1, 0, -1) meths.nvim_buf_clear_namespace(0, ns1, 0, -1)
eq({}, get_marks(ns1)) eq({}, get_marks(ns1))
eq(ns_marks[ns2], get_marks(ns2)) eq(ns_marks[ns2], get_marks(ns2))
curbufmeths.clear_namespace(ns2, 0, -1) meths.nvim_buf_clear_namespace(0, ns2, 0, -1)
eq({}, get_marks(ns1)) eq({}, get_marks(ns1))
eq({}, get_marks(ns2)) eq({}, get_marks(ns2))
end) end)
it('can clear line range', function() it('can clear line range', function()
curbufmeths.clear_namespace(ns1, 10, 20) meths.nvim_buf_clear_namespace(0, ns1, 10, 20)
for id, mark in pairs(ns_marks[ns1]) do for id, mark in pairs(ns_marks[ns1]) do
if 10 <= mark[1] and mark[1] < 20 then if 10 <= mark[1] and mark[1] < 20 then
ns_marks[ns1][id] = nil ns_marks[ns1][id] = nil

View File

@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, nvim = helpers.clear, helpers.nvim local clear = helpers.clear
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local command = helpers.command local command = helpers.command
@ -52,22 +52,22 @@ describe('API: highlight', function()
it('nvim_get_hl_by_id', function() it('nvim_get_hl_by_id', function()
local hl_id = eval("hlID('NewHighlight')") local hl_id = eval("hlID('NewHighlight')")
eq(expected_cterm, nvim('get_hl_by_id', hl_id, false)) eq(expected_cterm, meths.nvim_get_hl_by_id(hl_id, false))
hl_id = eval("hlID('NewHighlight')") hl_id = eval("hlID('NewHighlight')")
-- Test valid id. -- Test valid id.
eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) eq(expected_rgb, meths.nvim_get_hl_by_id(hl_id, true))
-- Test invalid id. -- Test invalid id.
eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false))
-- Test all highlight properties. -- Test all highlight properties.
command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true))
-- Test undercurl -- Test undercurl
command('hi NewHighlight gui=undercurl') command('hi NewHighlight gui=undercurl')
eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) eq(expected_undercurl, meths.nvim_get_hl_by_id(hl_id, true))
-- Test nil argument. -- Test nil argument.
eq( eq(
@ -102,14 +102,14 @@ describe('API: highlight', function()
local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red }
-- Test `Normal` default values. -- Test `Normal` default values.
eq({}, nvim('get_hl_by_name', 'Normal', true)) eq({}, meths.nvim_get_hl_by_name('Normal', true))
eq(expected_cterm, nvim('get_hl_by_name', 'NewHighlight', false)) eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false))
eq(expected_rgb, nvim('get_hl_by_name', 'NewHighlight', true)) eq(expected_rgb, meths.nvim_get_hl_by_name('NewHighlight', true))
-- Test `Normal` modified values. -- Test `Normal` modified values.
command('hi Normal guifg=red guibg=yellow') command('hi Normal guifg=red guibg=yellow')
eq(expected_normal, nvim('get_hl_by_name', 'Normal', true)) eq(expected_normal, meths.nvim_get_hl_by_name('Normal', true))
-- Test invalid name. -- Test invalid name.
eq( eq(
@ -137,10 +137,10 @@ describe('API: highlight', function()
meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 })
meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true })
-- Note colors are "cterm" values, not rgb-as-ints -- Note colors are "cterm" values, not rgb-as-ints
eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false))
eq( eq(
{ foreground = 17, background = 213, nocombine = true }, { foreground = 17, background = 213, nocombine = true },
nvim('get_hl_by_name', 'NotNormal', false) meths.nvim_get_hl_by_name('NotNormal', false)
) )
end) end)
@ -378,7 +378,7 @@ describe('API: set highlight', function()
it("correctly sets 'Normal' internal properties", function() it("correctly sets 'Normal' internal properties", function()
-- Normal has some special handling internally. #18024 -- Normal has some special handling internally. #18024
meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' })
eq({ foreground = 131, background = 243 }, nvim('get_hl_by_name', 'Normal', true)) eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true))
end) end)
it('does not segfault on invalid group name #20009', function() it('does not segfault on invalid group name #20009', function()
@ -475,7 +475,7 @@ describe('API: get highlight', function()
end) end)
it('nvim_get_hl with create flag', function() it('nvim_get_hl with create flag', function()
eq({}, nvim('get_hl', 0, { name = 'Foo', create = false })) eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false }))
eq(0, funcs.hlexists('Foo')) eq(0, funcs.hlexists('Foo'))
meths.nvim_get_hl(0, { name = 'Bar', create = true }) meths.nvim_get_hl(0, { name = 'Bar', create = true })
eq(1, funcs.hlexists('Bar')) eq(1, funcs.hlexists('Bar'))

View File

@ -1,9 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local bufmeths = helpers.bufmeths
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq, neq = helpers.eq, helpers.neq local eq, neq = helpers.eq, helpers.neq
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local exec = helpers.exec local exec = helpers.exec
@ -112,7 +110,7 @@ describe('nvim_get_keymap', function()
-- The buffer mapping should not show up -- The buffer mapping should not show up
eq({ foolong_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foolong_bar_map_table }, meths.nvim_get_keymap('n'))
eq({ buffer_table }, curbufmeths.get_keymap('n')) eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n'))
end) end)
it('considers scope for overlapping maps', function() it('considers scope for overlapping maps', function()
@ -124,11 +122,11 @@ describe('nvim_get_keymap', function()
command('nnoremap <buffer> foo bar') command('nnoremap <buffer> foo bar')
eq({ foo_bar_map_table }, meths.nvim_get_keymap('n')) eq({ foo_bar_map_table }, meths.nvim_get_keymap('n'))
eq({ buffer_table }, curbufmeths.get_keymap('n')) eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n'))
end) end)
it('can retrieve mapping for different buffers', function() it('can retrieve mapping for different buffers', function()
local original_buffer = curbufmeths.get_number() local original_buffer = meths.nvim_buf_get_number(0)
-- Place something in each of the buffers to make sure they stick around -- Place something in each of the buffers to make sure they stick around
-- and set hidden so we can leave them -- and set hidden so we can leave them
command('set hidden') command('set hidden')
@ -137,7 +135,7 @@ describe('nvim_get_keymap', function()
command('new') command('new')
command('normal! ihello 3') command('normal! ihello 3')
local final_buffer = curbufmeths.get_number() local final_buffer = meths.nvim_buf_get_number(0)
command('nnoremap <buffer> foo bar') command('nnoremap <buffer> foo bar')
-- Final buffer will have buffer mappings -- Final buffer will have buffer mappings
@ -147,10 +145,10 @@ describe('nvim_get_keymap', function()
eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n')) eq({ buffer_table }, meths.nvim_buf_get_keymap(0, 'n'))
command('buffer ' .. original_buffer) command('buffer ' .. original_buffer)
eq(original_buffer, curbufmeths.get_number()) eq(original_buffer, meths.nvim_buf_get_number(0))
-- Original buffer won't have any mappings -- Original buffer won't have any mappings
eq({}, meths.nvim_get_keymap('n')) eq({}, meths.nvim_get_keymap('n'))
eq({}, curbufmeths.get_keymap('n')) eq({}, meths.nvim_buf_get_keymap(0, 'n'))
eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n')) eq({ buffer_table }, meths.nvim_buf_get_keymap(final_buffer, 'n'))
end) end)
@ -209,7 +207,7 @@ describe('nvim_get_keymap', function()
function() function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' <buffer> ' .. option_token .. ' foo bar') command(map .. ' <buffer> ' .. option_token .. ' foo bar')
local result = curbufmeths.get_keymap(mode)[1][option] local result = meths.nvim_buf_get_keymap(0, mode)[1][option]
eq(buffer_on_result, result) eq(buffer_on_result, result)
end end
) )
@ -246,7 +244,7 @@ describe('nvim_get_keymap', function()
make_new_windows(new_windows) make_new_windows(new_windows)
command(map .. ' <buffer> foo bar') command(map .. ' <buffer> foo bar')
local result = curbufmeths.get_keymap(mode)[1][option] local result = meths.nvim_buf_get_keymap(0, mode)[1][option]
eq(buffer_off_result, result) eq(buffer_off_result, result)
end end
) )
@ -290,7 +288,7 @@ describe('nvim_get_keymap', function()
nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR> nnoremap <buffer> fizz :call <SID>maparg_test_function()<CR>
]]) ]])
local sid_result = curbufmeths.get_keymap('n')[1]['sid'] local sid_result = meths.nvim_buf_get_keymap(0, 'n')[1]['sid']
eq(1, sid_result) eq(1, sid_result)
eq('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {})) eq('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
end) end)
@ -698,33 +696,33 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can set mappings whose RHS is a <Nop>', function() it('can set mappings whose RHS is a <Nop>', function()
meths.nvim_set_keymap('i', 'lhs', '<Nop>', {}) meths.nvim_set_keymap('i', 'lhs', '<Nop>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, curbufmeths.get_lines(0, -1, 0)) -- imap to <Nop> does nothing eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0)) -- imap to <Nop> does nothing
eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<Nop>', {}), get_mapargs('i', 'lhs'))
-- also test for case insensitivity -- also test for case insensitivity
meths.nvim_set_keymap('i', 'lhs', '<nOp>', {}) meths.nvim_set_keymap('i', 'lhs', '<nOp>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, curbufmeths.get_lines(0, -1, 0)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
-- note: RHS in returned mapargs() dict reflects the original RHS -- note: RHS in returned mapargs() dict reflects the original RHS
-- provided by the user -- provided by the user
eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs'))
meths.nvim_set_keymap('i', 'lhs', '<NOP>', {}) meths.nvim_set_keymap('i', 'lhs', '<NOP>', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, curbufmeths.get_lines(0, -1, 0)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '<NOP>', {}), get_mapargs('i', 'lhs'))
-- a single ^V in RHS is also <Nop> (see :h map-empty-rhs) -- a single ^V in RHS is also <Nop> (see :h map-empty-rhs)
meths.nvim_set_keymap('i', 'lhs', '\022', {}) meths.nvim_set_keymap('i', 'lhs', '\022', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, curbufmeths.get_lines(0, -1, 0)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '\022', {}), get_mapargs('i', 'lhs'))
end) end)
it('treats an empty RHS in a mapping like a <Nop>', function() it('treats an empty RHS in a mapping like a <Nop>', function()
meths.nvim_set_keymap('i', 'lhs', '', {}) meths.nvim_set_keymap('i', 'lhs', '', {})
command('normal ilhs') command('normal ilhs')
eq({ '' }, curbufmeths.get_lines(0, -1, 0)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs')) eq(generate_mapargs('i', 'lhs', '', {}), get_mapargs('i', 'lhs'))
end) end)
@ -743,7 +741,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]]) command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]])
eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>')) eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>'))
feed('i ') feed('i ')
eq({ '\t' }, curbufmeths.get_lines(0, -1, 0)) eq({ '\t' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
end end
) )
@ -772,12 +770,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
meths.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true }) meths.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true })
command('normal ilhs') command('normal ilhs')
eq({ '1' }, curbufmeths.get_lines(0, -1, 0)) eq({ '1' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') command('normal ilhs')
eq({ '0' }, curbufmeths.get_lines(0, -1, 0)) eq({ '0' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it('can set mappings that do trigger other mappings', function() it('can set mappings that do trigger other mappings', function()
@ -785,12 +783,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
meths.nvim_set_keymap('i', 'lhs', 'mhs', {}) meths.nvim_set_keymap('i', 'lhs', 'mhs', {})
command('normal imhs') command('normal imhs')
eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') command('normal ilhs')
eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it("can set noremap mappings that don't trigger other mappings", function() it("can set noremap mappings that don't trigger other mappings", function()
@ -798,12 +796,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
meths.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true }) meths.nvim_set_keymap('i', 'lhs', 'mhs', { noremap = true })
command('normal imhs') command('normal imhs')
eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
command('normal! ggVGd') command('normal! ggVGd')
command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping command('normal ilhs') -- shouldn't trigger mhs-to-rhs mapping
eq({ 'mhs' }, curbufmeths.get_lines(0, -1, 0)) eq({ 'mhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
it('can set nowait mappings that fire without waiting', function() it('can set nowait mappings that fire without waiting', function()
@ -817,7 +815,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
feed(c) feed(c)
sleep(5) sleep(5)
end end
eq({ 'shorter456' }, curbufmeths.get_lines(0, -1, 0)) eq({ 'shorter456' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
end) end)
-- Perform exhaustive tests of basic functionality -- Perform exhaustive tests of basic functionality
@ -1181,66 +1179,66 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
it('rejects negative bufnr values', function() it('rejects negative bufnr values', function()
eq( eq(
'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer', 'Wrong type for argument 1 when calling nvim_buf_set_keymap, expecting Buffer',
pcall_err(bufmeths.set_keymap, -1, '', 'lhs', 'rhs', {}) pcall_err(meths.nvim_buf_set_keymap, -1, '', 'lhs', 'rhs', {})
) )
end) end)
it('can set mappings active in the current buffer but not others', function() it('can set mappings active in the current buffer but not others', function()
local first, second = make_two_buffers(true) local first, second = make_two_buffers(true)
bufmeths.set_keymap(0, '', 'lhs', 'irhs<Esc>', {}) meths.nvim_buf_set_keymap(0, '', 'lhs', 'irhs<Esc>', {})
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
-- mapping should have no effect in new buffer -- mapping should have no effect in new buffer
switch_to_buf(second) switch_to_buf(second)
command('normal lhs') command('normal lhs')
eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
-- mapping should remain active in old buffer -- mapping should remain active in old buffer
switch_to_buf(first) switch_to_buf(first)
command('normal ^lhs') command('normal ^lhs')
eq({ 'rhsrhs' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ 'rhsrhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('can set local mappings in buffer other than current', function() it('can set local mappings in buffer other than current', function()
local first = make_two_buffers(false) local first = make_two_buffers(false)
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
-- shouldn't do anything -- shouldn't do anything
command('normal lhs') command('normal lhs')
eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
-- should take effect -- should take effect
switch_to_buf(first) switch_to_buf(first)
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('can disable mappings made in another buffer, inside that buffer', function() it('can disable mappings made in another buffer, inside that buffer', function()
local first = make_two_buffers(false) local first = make_two_buffers(false)
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
bufmeths.del_keymap(first, '', 'lhs') meths.nvim_buf_del_keymap(first, '', 'lhs')
switch_to_buf(first) switch_to_buf(first)
-- shouldn't do anything -- shouldn't do anything
command('normal lhs') command('normal lhs')
eq({ '' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it("can't disable mappings given wrong buffer handle", function() it("can't disable mappings given wrong buffer handle", function()
local first, second = make_two_buffers(false) local first, second = make_two_buffers(false)
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {}) meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
eq('E31: No such mapping', pcall_err(bufmeths.del_keymap, second, '', 'lhs')) eq('E31: No such mapping', pcall_err(meths.nvim_buf_del_keymap, second, '', 'lhs'))
-- should still work -- should still work
switch_to_buf(first) switch_to_buf(first)
command('normal lhs') command('normal lhs')
eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1)) eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
end) end)
it('does not crash when setting mapping in a non-existing buffer #13541', function() it('does not crash when setting mapping in a non-existing buffer #13541', function()
pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {}) pcall_err(meths.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
helpers.assert_alive() helpers.assert_alive()
end) end)

View File

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

View File

@ -2,7 +2,7 @@
-- `rpcrequest` calls we need the client event loop to be running. -- `rpcrequest` calls we need the client event loop to be running.
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval local clear, eval = helpers.clear, helpers.eval
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs
local source, next_msg = helpers.source, helpers.next_msg local source, next_msg = helpers.source, helpers.next_msg
@ -18,7 +18,7 @@ describe('server -> client', function()
before_each(function() before_each(function()
clear() clear()
cid = nvim('get_api_info')[1] cid = meths.nvim_get_api_info()[1]
end) end)
it('handles unexpected closed stream while preparing RPC response', function() it('handles unexpected closed stream while preparing RPC response', function()
@ -47,7 +47,7 @@ describe('server -> client', function()
local function on_request(method, args) local function on_request(method, args)
eq('scall', method) eq('scall', method)
eq({ 1, 2, 3 }, args) eq({ 1, 2, 3 }, args)
nvim('command', 'let g:result = [4, 5, 6]') command('let g:result = [4, 5, 6]')
return eval('g:result') return eval('g:result')
end end
run(on_request, nil, on_setup) run(on_request, nil, on_setup)
@ -77,15 +77,15 @@ describe('server -> client', function()
describe('recursive call', function() describe('recursive call', function()
it('works', function() it('works', function()
local function on_setup() local function on_setup()
nvim('set_var', 'result1', 0) meths.nvim_set_var('result1', 0)
nvim('set_var', 'result2', 0) meths.nvim_set_var('result2', 0)
nvim('set_var', 'result3', 0) meths.nvim_set_var('result3', 0)
nvim('set_var', 'result4', 0) meths.nvim_set_var('result4', 0)
nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)') command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)')
eq(4, nvim('get_var', 'result1')) eq(4, meths.nvim_get_var('result1'))
eq(8, nvim('get_var', 'result2')) eq(8, meths.nvim_get_var('result2'))
eq(16, nvim('get_var', 'result3')) eq(16, meths.nvim_get_var('result3'))
eq(32, nvim('get_var', 'result4')) eq(32, meths.nvim_get_var('result4'))
stop() stop()
end end
@ -101,7 +101,7 @@ describe('server -> client', function()
elseif n == 16 then elseif n == 16 then
cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')'
end end
nvim('command', cmd) command(cmd)
end end
return n return n
end end
@ -195,10 +195,10 @@ describe('server -> client', function()
end) end)
it('can send/receive notifications and make requests', function() it('can send/receive notifications and make requests', function()
nvim('command', "call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')") command("call rpcnotify(vim, 'vim_set_current_line', 'SOME TEXT')")
-- Wait for the notification to complete. -- Wait for the notification to complete.
nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") command("call rpcrequest(vim, 'vim_eval', '0')")
eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')")) eq('SOME TEXT', eval("rpcrequest(vim, 'vim_get_current_line')"))
end) end)
@ -212,7 +212,7 @@ describe('server -> client', function()
eq(1, buf) eq(1, buf)
eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')") eval("rpcnotify(vim, 'buffer_set_line', " .. buf .. ", 0, 'SOME TEXT')")
nvim('command', "call rpcrequest(vim, 'vim_eval', '0')") -- wait command("call rpcrequest(vim, 'vim_eval', '0')") -- wait
eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)')) eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', " .. buf .. ', 0)'))
@ -231,8 +231,8 @@ describe('server -> client', function()
describe('jobstart()', function() describe('jobstart()', function()
local jobid local jobid
before_each(function() before_each(function()
local channel = nvim('get_api_info')[1] local channel = meths.nvim_get_api_info()[1]
nvim('set_var', 'channel', channel) meths.nvim_set_var('channel', channel)
source([[ source([[
function! s:OnEvent(id, data, event) function! s:OnEvent(id, data, event)
call rpcnotify(g:channel, a:event, 0, a:data) call rpcnotify(g:channel, a:event, 0, a:data)

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,17 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval, tabpage = local clear, curbuf, curbuf_contents, curwin, eq, neq, ok, feed, insert, eval =
helpers.clear, helpers.clear,
helpers.nvim, helpers.meths.nvim_get_current_buf,
helpers.curbuf,
helpers.curbuf_contents, helpers.curbuf_contents,
helpers.window, helpers.meths.nvim_get_current_win,
helpers.curwin,
helpers.eq, helpers.eq,
helpers.neq, helpers.neq,
helpers.ok, helpers.ok,
helpers.feed, helpers.feed,
helpers.insert, helpers.insert,
helpers.eval, helpers.eval
helpers.tabpage
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local curwinmeths = helpers.curwinmeths
local exec = helpers.exec local exec = helpers.exec
local funcs = helpers.funcs local funcs = helpers.funcs
local request = helpers.request local request = helpers.request
@ -30,26 +26,35 @@ describe('API/win', function()
describe('get_buf', function() describe('get_buf', function()
it('works', function() it('works', function()
eq(curbuf(), window('get_buf', nvim('list_wins')[1])) eq(curbuf(), meths.nvim_win_get_buf(meths.nvim_list_wins()[1]))
nvim('command', 'new') command('new')
nvim('set_current_win', nvim('list_wins')[2]) meths.nvim_set_current_win(meths.nvim_list_wins()[2])
eq(curbuf(), window('get_buf', nvim('list_wins')[2])) eq(curbuf(), meths.nvim_win_get_buf(meths.nvim_list_wins()[2]))
neq(window('get_buf', nvim('list_wins')[1]), window('get_buf', nvim('list_wins')[2])) neq(
meths.nvim_win_get_buf(meths.nvim_list_wins()[1]),
meths.nvim_win_get_buf(meths.nvim_list_wins()[2])
)
end) end)
end) end)
describe('set_buf', function() describe('set_buf', function()
it('works', function() it('works', function()
nvim('command', 'new') command('new')
local windows = nvim('list_wins') local windows = meths.nvim_list_wins()
neq(window('get_buf', windows[2]), window('get_buf', windows[1])) neq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1]))
window('set_buf', windows[2], window('get_buf', windows[1])) meths.nvim_win_set_buf(windows[2], meths.nvim_win_get_buf(windows[1]))
eq(window('get_buf', windows[2]), window('get_buf', windows[1])) eq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1]))
end) end)
it('validates args', function() it('validates args', function()
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23)) eq(
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf'))) 'Invalid buffer id: 23',
pcall_err(meths.nvim_win_set_buf, meths.nvim_get_current_win(), 23)
)
eq(
'Invalid window id: 23',
pcall_err(meths.nvim_win_set_buf, 23, meths.nvim_get_current_buf())
)
end) end)
it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function()
@ -84,12 +89,12 @@ describe('API/win', function()
describe('{get,set}_cursor', function() describe('{get,set}_cursor', function()
it('works', function() it('works', function()
eq({ 1, 0 }, curwin('get_cursor')) eq({ 1, 0 }, meths.nvim_win_get_cursor(0))
nvim('command', 'normal ityping\027o some text') command('normal ityping\027o some text')
eq('typing\n some text', curbuf_contents()) eq('typing\n some text', curbuf_contents())
eq({ 2, 10 }, curwin('get_cursor')) eq({ 2, 10 }, meths.nvim_win_get_cursor(0))
curwin('set_cursor', { 2, 6 }) meths.nvim_win_set_cursor(0, { 2, 6 })
nvim('command', 'normal i dumb') command('normal i dumb')
eq('typing\n some dumb text', curbuf_contents()) eq('typing\n some dumb text', curbuf_contents())
end) end)
@ -119,10 +124,10 @@ describe('API/win', function()
]], ]],
} }
-- cursor position is at beginning -- cursor position is at beginning
eq({ 1, 0 }, window('get_cursor', win)) eq({ 1, 0 }, meths.nvim_win_get_cursor(win))
-- move cursor to end -- move cursor to end
window('set_cursor', win, { 101, 0 }) meths.nvim_win_set_cursor(win, { 101, 0 })
screen:expect { screen:expect {
grid = [[ grid = [[
|*7 |*7
@ -132,7 +137,7 @@ describe('API/win', function()
} }
-- move cursor to the beginning again -- move cursor to the beginning again
window('set_cursor', win, { 1, 0 }) meths.nvim_win_set_cursor(win, { 1, 0 })
screen:expect { screen:expect {
grid = [[ grid = [[
^prologue | ^prologue |
@ -141,11 +146,11 @@ describe('API/win', function()
} }
-- move focus to new window -- move focus to new window
nvim('command', 'new') command('new')
neq(win, curwin()) neq(win, curwin())
-- sanity check, cursor position is kept -- sanity check, cursor position is kept
eq({ 1, 0 }, window('get_cursor', win)) eq({ 1, 0 }, meths.nvim_win_get_cursor(win))
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
@ -159,7 +164,7 @@ describe('API/win', function()
} }
-- move cursor to end -- move cursor to end
window('set_cursor', win, { 101, 0 }) meths.nvim_win_set_cursor(win, { 101, 0 })
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
@ -173,7 +178,7 @@ describe('API/win', function()
} }
-- move cursor to the beginning again -- move cursor to the beginning again
window('set_cursor', win, { 1, 0 }) meths.nvim_win_set_cursor(win, { 1, 0 })
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
@ -200,17 +205,17 @@ describe('API/win', function()
-- cursor position is at beginning -- cursor position is at beginning
local win = curwin() local win = curwin()
eq({ 1, 0 }, window('get_cursor', win)) eq({ 1, 0 }, meths.nvim_win_get_cursor(win))
-- move cursor to column 5 -- move cursor to column 5
window('set_cursor', win, { 1, 5 }) meths.nvim_win_set_cursor(win, { 1, 5 })
-- move down a line -- move down a line
feed('j') feed('j')
poke_eventloop() -- let nvim process the 'j' command poke_eventloop() -- let nvim process the 'j' command
-- cursor is still in column 5 -- cursor is still in column 5
eq({ 2, 5 }, window('get_cursor', win)) eq({ 2, 5 }, meths.nvim_win_get_cursor(win))
end) end)
it('updates cursorline and statusline ruler in non-current window', function() it('updates cursorline and statusline ruler in non-current window', function()
@ -240,7 +245,7 @@ describe('API/win', function()
{3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}| {3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}|
| |
]]) ]])
window('set_cursor', oldwin, { 1, 0 }) meths.nvim_win_set_cursor(oldwin, { 1, 0 })
screen:expect([[ screen:expect([[
aaa {2:aaa }| aaa {2:aaa }|
bbb bbb | bbb bbb |
@ -278,7 +283,7 @@ describe('API/win', function()
{3:[No Name] [+] }{4:[No Name] [+] }| {3:[No Name] [+] }{4:[No Name] [+] }|
| |
]]) ]])
window('set_cursor', oldwin, { 2, 0 }) meths.nvim_win_set_cursor(oldwin, { 2, 0 })
screen:expect([[ screen:expect([[
aa{2:a} {2:a}aa | aa{2:a} {2:a}aa |
bb{2:b} bbb | bb{2:b} bbb |
@ -293,32 +298,35 @@ describe('API/win', function()
describe('{get,set}_height', function() describe('{get,set}_height', function()
it('works', function() it('works', function()
nvim('command', 'vsplit') command('vsplit')
eq(window('get_height', nvim('list_wins')[2]), window('get_height', nvim('list_wins')[1]))
nvim('set_current_win', nvim('list_wins')[2])
nvim('command', 'split')
eq( eq(
window('get_height', nvim('list_wins')[2]), meths.nvim_win_get_height(meths.nvim_list_wins()[2]),
math.floor(window('get_height', nvim('list_wins')[1]) / 2) meths.nvim_win_get_height(meths.nvim_list_wins()[1])
) )
window('set_height', nvim('list_wins')[2], 2) meths.nvim_set_current_win(meths.nvim_list_wins()[2])
eq(2, window('get_height', nvim('list_wins')[2])) command('split')
eq(
meths.nvim_win_get_height(meths.nvim_list_wins()[2]),
math.floor(meths.nvim_win_get_height(meths.nvim_list_wins()[1]) / 2)
)
meths.nvim_win_set_height(meths.nvim_list_wins()[2], 2)
eq(2, meths.nvim_win_get_height(meths.nvim_list_wins()[2]))
end) end)
it('correctly handles height=1', function() it('correctly handles height=1', function()
nvim('command', 'split') command('split')
nvim('set_current_win', nvim('list_wins')[1]) meths.nvim_set_current_win(meths.nvim_list_wins()[1])
window('set_height', nvim('list_wins')[2], 1) meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1)
eq(1, window('get_height', nvim('list_wins')[2])) eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2]))
end) end)
it('correctly handles height=1 with a winbar', function() it('correctly handles height=1 with a winbar', function()
nvim('command', 'set winbar=foobar') command('set winbar=foobar')
nvim('command', 'set winminheight=0') command('set winminheight=0')
nvim('command', 'split') command('split')
nvim('set_current_win', nvim('list_wins')[1]) meths.nvim_set_current_win(meths.nvim_list_wins()[1])
window('set_height', nvim('list_wins')[2], 1) meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1)
eq(1, window('get_height', nvim('list_wins')[2])) eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2]))
end) end)
it('do not cause ml_get errors with foldmethod=expr #19989', function() it('do not cause ml_get errors with foldmethod=expr #19989', function()
@ -340,16 +348,19 @@ describe('API/win', function()
describe('{get,set}_width', function() describe('{get,set}_width', function()
it('works', function() it('works', function()
nvim('command', 'split') command('split')
eq(window('get_width', nvim('list_wins')[2]), window('get_width', nvim('list_wins')[1]))
nvim('set_current_win', nvim('list_wins')[2])
nvim('command', 'vsplit')
eq( eq(
window('get_width', nvim('list_wins')[2]), meths.nvim_win_get_width(meths.nvim_list_wins()[2]),
math.floor(window('get_width', nvim('list_wins')[1]) / 2) meths.nvim_win_get_width(meths.nvim_list_wins()[1])
) )
window('set_width', nvim('list_wins')[2], 2) meths.nvim_set_current_win(meths.nvim_list_wins()[2])
eq(2, window('get_width', nvim('list_wins')[2])) command('vsplit')
eq(
meths.nvim_win_get_width(meths.nvim_list_wins()[2]),
math.floor(meths.nvim_win_get_width(meths.nvim_list_wins()[1]) / 2)
)
meths.nvim_win_set_width(meths.nvim_list_wins()[2], 2)
eq(2, meths.nvim_win_get_width(meths.nvim_list_wins()[2]))
end) end)
it('do not cause ml_get errors with foldmethod=expr #19989', function() it('do not cause ml_get errors with foldmethod=expr #19989', function()
@ -371,17 +382,17 @@ describe('API/win', function()
describe('{get,set,del}_var', function() describe('{get,set,del}_var', function()
it('works', function() it('works', function()
curwin('set_var', 'lua', { 1, 2, { ['3'] = 1 } }) meths.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
eq({ 1, 2, { ['3'] = 1 } }, curwin('get_var', 'lua')) eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_win_get_var(0, 'lua'))
eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'w:lua')) eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('w:lua'))
eq(1, funcs.exists('w:lua')) eq(1, funcs.exists('w:lua'))
curwinmeths.del_var('lua') meths.nvim_win_del_var(0, 'lua')
eq(0, funcs.exists('w:lua')) eq(0, funcs.exists('w:lua'))
eq('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua')) eq('Key not found: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua'))
curwinmeths.set_var('lua', 1) meths.nvim_win_set_var(0, 'lua', 1)
command('lockvar w:lua') command('lockvar w:lua')
eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua')) eq('Key is locked: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua'))
eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1)) eq('Key is locked: lua', pcall_err(meths.nvim_win_set_var, 0, 'lua', 1))
end) end)
it('window_set_var returns the old value', function() it('window_set_var returns the old value', function()
@ -402,51 +413,51 @@ describe('API/win', function()
describe('nvim_get_option_value, nvim_set_option_value', function() describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function() it('works', function()
nvim('set_option_value', 'colorcolumn', '4,3', {}) meths.nvim_set_option_value('colorcolumn', '4,3', {})
eq('4,3', nvim('get_option_value', 'colorcolumn', {})) eq('4,3', meths.nvim_get_option_value('colorcolumn', {}))
command('set modified hidden') command('set modified hidden')
command('enew') -- edit new buffer, window option is preserved command('enew') -- edit new buffer, window option is preserved
eq('4,3', nvim('get_option_value', 'colorcolumn', {})) eq('4,3', meths.nvim_get_option_value('colorcolumn', {}))
-- global-local option -- global-local option
nvim('set_option_value', 'statusline', 'window-status', { win = 0 }) meths.nvim_set_option_value('statusline', 'window-status', { win = 0 })
eq('window-status', nvim('get_option_value', 'statusline', { win = 0 })) eq('window-status', meths.nvim_get_option_value('statusline', { win = 0 }))
eq('', nvim('get_option_value', 'statusline', { scope = 'global' })) eq('', meths.nvim_get_option_value('statusline', { scope = 'global' }))
command('set modified') command('set modified')
command('enew') -- global-local: not preserved in new buffer command('enew') -- global-local: not preserved in new buffer
-- confirm local value was not copied -- confirm local value was not copied
eq('', nvim('get_option_value', 'statusline', { win = 0 })) eq('', meths.nvim_get_option_value('statusline', { win = 0 }))
eq('', eval('&l:statusline')) eq('', eval('&l:statusline'))
end) end)
it('after switching windows #15390', function() it('after switching windows #15390', function()
nvim('command', 'tabnew') command('tabnew')
local tab1 = unpack(nvim('list_tabpages')) local tab1 = unpack(meths.nvim_list_tabpages())
local win1 = unpack(tabpage('list_wins', tab1)) local win1 = unpack(meths.nvim_tabpage_list_wins(tab1))
nvim('set_option_value', 'statusline', 'window-status', { win = win1.id }) meths.nvim_set_option_value('statusline', 'window-status', { win = win1.id })
nvim('command', 'split') command('split')
nvim('command', 'wincmd J') command('wincmd J')
nvim('command', 'wincmd j') command('wincmd j')
eq('window-status', nvim('get_option_value', 'statusline', { win = win1.id })) eq('window-status', meths.nvim_get_option_value('statusline', { win = win1.id }))
assert_alive() assert_alive()
end) end)
it('returns values for unset local options', function() it('returns values for unset local options', function()
eq(-1, nvim('get_option_value', 'scrolloff', { win = 0, scope = 'local' })) eq(-1, meths.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' }))
end) end)
end) end)
describe('get_position', function() describe('get_position', function()
it('works', function() it('works', function()
local height = window('get_height', nvim('list_wins')[1]) local height = meths.nvim_win_get_height(meths.nvim_list_wins()[1])
local width = window('get_width', nvim('list_wins')[1]) local width = meths.nvim_win_get_width(meths.nvim_list_wins()[1])
nvim('command', 'split') command('split')
nvim('command', 'vsplit') command('vsplit')
eq({ 0, 0 }, window('get_position', nvim('list_wins')[1])) eq({ 0, 0 }, meths.nvim_win_get_position(meths.nvim_list_wins()[1]))
local vsplit_pos = math.floor(width / 2) local vsplit_pos = math.floor(width / 2)
local split_pos = math.floor(height / 2) local split_pos = math.floor(height / 2)
local win2row, win2col = unpack(window('get_position', nvim('list_wins')[2])) local win2row, win2col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[2]))
local win3row, win3col = unpack(window('get_position', nvim('list_wins')[3])) local win3row, win3col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[3]))
eq(0, win2row) eq(0, win2row)
eq(0, win3col) eq(0, win3col)
ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1) ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1)
@ -456,46 +467,46 @@ describe('API/win', function()
describe('get_position', function() describe('get_position', function()
it('works', function() it('works', function()
nvim('command', 'tabnew') command('tabnew')
nvim('command', 'vsplit') command('vsplit')
eq(window('get_tabpage', nvim('list_wins')[1]), nvim('list_tabpages')[1]) eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[1]), meths.nvim_list_tabpages()[1])
eq(window('get_tabpage', nvim('list_wins')[2]), nvim('list_tabpages')[2]) eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[2]), meths.nvim_list_tabpages()[2])
eq(window('get_tabpage', nvim('list_wins')[3]), nvim('list_tabpages')[2]) eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[3]), meths.nvim_list_tabpages()[2])
end) end)
end) end)
describe('get_number', function() describe('get_number', function()
it('works', function() it('works', function()
local wins = nvim('list_wins') local wins = meths.nvim_list_wins()
eq(1, window('get_number', wins[1])) eq(1, meths.nvim_win_get_number(wins[1]))
nvim('command', 'split') command('split')
local win1, win2 = unpack(nvim('list_wins')) local win1, win2 = unpack(meths.nvim_list_wins())
eq(1, window('get_number', win1)) eq(1, meths.nvim_win_get_number(win1))
eq(2, window('get_number', win2)) eq(2, meths.nvim_win_get_number(win2))
nvim('command', 'wincmd J') command('wincmd J')
eq(2, window('get_number', win1)) eq(2, meths.nvim_win_get_number(win1))
eq(1, window('get_number', win2)) eq(1, meths.nvim_win_get_number(win2))
nvim('command', 'tabnew') command('tabnew')
local win3 = nvim('list_wins')[3] local win3 = meths.nvim_list_wins()[3]
-- First tab page -- First tab page
eq(2, window('get_number', win1)) eq(2, meths.nvim_win_get_number(win1))
eq(1, window('get_number', win2)) eq(1, meths.nvim_win_get_number(win2))
-- Second tab page -- Second tab page
eq(1, window('get_number', win3)) eq(1, meths.nvim_win_get_number(win3))
end) end)
end) end)
describe('is_valid', function() describe('is_valid', function()
it('works', function() it('works', function()
nvim('command', 'split') command('split')
local win = nvim('list_wins')[2] local win = meths.nvim_list_wins()[2]
nvim('set_current_win', win) meths.nvim_set_current_win(win)
ok(window('is_valid', win)) ok(meths.nvim_win_is_valid(win))
nvim('command', 'close') command('close')
ok(not window('is_valid', win)) ok(not meths.nvim_win_is_valid(win))
end) end)
end) end)
@ -671,42 +682,43 @@ describe('API/win', function()
ddd ddd
eee]]) eee]])
eq('Invalid window id: 23', pcall_err(meths.nvim_win_text_height, 23, {})) eq('Invalid window id: 23', pcall_err(meths.nvim_win_text_height, 23, {}))
eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = 5 })) eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { start_row = 5 }))
eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { start_row = -6 })) eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { start_row = -6 }))
eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = 5 })) eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { end_row = 5 }))
eq('Line index out of bounds', pcall_err(curwinmeths.text_height, { end_row = -6 })) eq('Line index out of bounds', pcall_err(meths.nvim_win_text_height, 0, { end_row = -6 }))
eq( eq(
"'start_row' is higher than 'end_row'", "'start_row' is higher than 'end_row'",
pcall_err(curwinmeths.text_height, { start_row = 3, end_row = 1 }) pcall_err(meths.nvim_win_text_height, 0, { start_row = 3, end_row = 1 })
) )
eq( eq(
"'start_vcol' specified without 'start_row'", "'start_vcol' specified without 'start_row'",
pcall_err(curwinmeths.text_height, { end_row = 2, start_vcol = 0 }) pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, start_vcol = 0 })
) )
eq( eq(
"'end_vcol' specified without 'end_row'", "'end_vcol' specified without 'end_row'",
pcall_err(curwinmeths.text_height, { start_row = 2, end_vcol = 0 }) pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, end_vcol = 0 })
) )
eq( eq(
"Invalid 'start_vcol': out of range", "Invalid 'start_vcol': out of range",
pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = -1 }) pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, start_vcol = -1 })
) )
eq( eq(
"Invalid 'start_vcol': out of range", "Invalid 'start_vcol': out of range",
pcall_err(curwinmeths.text_height, { start_row = 2, start_vcol = X + 1 }) pcall_err(meths.nvim_win_text_height, 0, { start_row = 2, start_vcol = X + 1 })
) )
eq( eq(
"Invalid 'end_vcol': out of range", "Invalid 'end_vcol': out of range",
pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = -1 }) pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, end_vcol = -1 })
) )
eq( eq(
"Invalid 'end_vcol': out of range", "Invalid 'end_vcol': out of range",
pcall_err(curwinmeths.text_height, { end_row = 2, end_vcol = X + 1 }) pcall_err(meths.nvim_win_text_height, 0, { end_row = 2, end_vcol = X + 1 })
) )
eq( eq(
"'start_vcol' is higher than 'end_vcol'", "'start_vcol' is higher than 'end_vcol'",
pcall_err( pcall_err(
curwinmeths.text_height, meths.nvim_win_text_height,
0,
{ start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 } { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 }
) )
) )

View File

@ -17,7 +17,6 @@ local expect = helpers.expect
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local curbufmeths = helpers.curbufmeths
local retry = helpers.retry local retry = helpers.retry
local source = helpers.source local source = helpers.source
@ -144,7 +143,7 @@ describe('autocmd', function()
describe('BufLeave autocommand', function() describe('BufLeave autocommand', function()
it('can wipe out the buffer created by :edit which triggered autocmd', function() it('can wipe out the buffer created by :edit which triggered autocmd', function()
meths.nvim_set_option_value('hidden', true, {}) meths.nvim_set_option_value('hidden', true, {})
curbufmeths.set_lines(0, 1, false, { meths.nvim_buf_set_lines(0, 0, 1, false, {
'start of test file xx', 'start of test file xx',
'end of test file xx', 'end of test file xx',
}) })

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ local uv = vim.uv
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, command, nvim, testprg = helpers.clear, helpers.command, helpers.nvim, helpers.testprg local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg
local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry
local matches = helpers.matches local matches = helpers.matches
local ok = helpers.ok local ok = helpers.ok
@ -16,13 +16,13 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function() describe('autocmd TermClose', function()
before_each(function() before_each(function()
clear() clear()
nvim('set_option_value', 'shell', testprg('shell-test'), {}) meths.nvim_set_option_value('shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
end) end)
local function test_termclose_delete_own_buf() local function test_termclose_delete_own_buf()
-- The terminal process needs to keep running so that TermClose isn't triggered immediately. -- The terminal process needs to keep running so that TermClose isn't triggered immediately.
nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!') command('autocmd TermClose * bdelete!')
command('terminal') command('terminal')
matches( matches(
@ -56,7 +56,7 @@ describe('autocmd TermClose', function()
it('triggers when long-running terminal job gets stopped', function() it('triggers when long-running terminal job gets stopped', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {}) meths.nvim_set_option_value('shell', is_os('win') and 'cmd.exe' or 'sh', {})
command('autocmd TermClose * let g:test_termclose = 23') command('autocmd TermClose * let g:test_termclose = 23')
command('terminal') command('terminal')
command('call jobstop(b:terminal_job_id)') command('call jobstop(b:terminal_job_id)')
@ -67,8 +67,8 @@ describe('autocmd TermClose', function()
it('kills job trapping SIGTERM', function() it('kills job trapping SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option_value', 'shell', 'sh', {}) meths.nvim_set_option_value('shell', 'sh', {})
nvim('set_option_value', 'shellcmdflag', '-c', {}) meths.nvim_set_option_value('shellcmdflag', '-c', {})
command( command(
[[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] [[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
@ -93,8 +93,8 @@ describe('autocmd TermClose', function()
it('kills PTY job trapping SIGHUP and SIGTERM', function() it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option_value', 'shell', 'sh', {}) meths.nvim_set_option_value('shell', 'sh', {})
nvim('set_option_value', 'shellcmdflag', '-c', {}) meths.nvim_set_option_value('shellcmdflag', '-c', {})
command( command(
[[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] [[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
.. [[ 'pty': 1,]] .. [[ 'pty': 1,]]

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
local feed, command, expect = helpers.feed, helpers.command, helpers.expect local feed, command, expect = helpers.feed, helpers.command, helpers.expect
local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq local meths, funcs, neq = helpers.meths, helpers.funcs, helpers.neq
describe('TextYankPost', function() describe('TextYankPost', function()
before_each(function() before_each(function()
@ -14,7 +14,7 @@ describe('TextYankPost', function()
command('autocmd TextYankPost * let g:event = copy(v:event)') command('autocmd TextYankPost * let g:event = copy(v:event)')
command('autocmd TextYankPost * let g:count += 1') command('autocmd TextYankPost * let g:count += 1')
curbufmeths.set_lines(0, -1, true, { meths.nvim_buf_set_lines(0, 0, -1, true, {
'foo\0bar', 'foo\0bar',
'baz text', 'baz text',
}) })

View File

@ -18,7 +18,7 @@ describe('v:exiting', function()
before_each(function() before_each(function()
helpers.clear() helpers.clear()
cid = helpers.nvim('get_api_info')[1] cid = helpers.meths.nvim_get_api_info()[1]
end) end)
it('defaults to v:null', function() it('defaults to v:null', function()

View File

@ -10,7 +10,6 @@ local feed = helpers.feed
local insert = helpers.insert local insert = helpers.insert
local neq = helpers.neq local neq = helpers.neq
local next_msg = helpers.next_msg local next_msg = helpers.next_msg
local nvim = helpers.nvim
local testprg = helpers.testprg local testprg = helpers.testprg
local ok = helpers.ok local ok = helpers.ok
local source = helpers.source local source = helpers.source
@ -43,8 +42,8 @@ describe('jobs', function()
before_each(function() before_each(function()
clear() clear()
channel = nvim('get_api_info')[1] channel = meths.nvim_get_api_info()[1]
nvim('set_var', 'channel', channel) meths.nvim_set_var('channel', channel)
source([[ source([[
function! Normalize(data) abort function! Normalize(data) abort
" Windows: remove ^M and term escape sequences " Windows: remove ^M and term escape sequences
@ -69,22 +68,22 @@ describe('jobs', function()
command('let g:job_opts.env = v:true') command('let g:job_opts.env = v:true')
local _, err = pcall(function() local _, err = pcall(function()
if is_os('win') then if is_os('win') then
nvim('command', "let j = jobstart('set', g:job_opts)") command("let j = jobstart('set', g:job_opts)")
else else
nvim('command', "let j = jobstart('env', g:job_opts)") command("let j = jobstart('env', g:job_opts)")
end end
end) end)
ok(string.find(err, 'E475: Invalid argument: env') ~= nil) ok(string.find(err, 'E475: Invalid argument: env') ~= nil)
end) end)
it('append environment #env', function() it('append environment #env', function()
nvim('command', "let $VAR = 'abc'") command("let $VAR = 'abc'")
nvim('command', "let $TOTO = 'goodbye world'") command("let $TOTO = 'goodbye world'")
nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") command("let g:job_opts.env = {'TOTO': 'hello world'}")
if is_os('win') then if is_os('win') then
nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]])
else else
nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) command([[call jobstart('echo $TOTO $VAR', g:job_opts)]])
end end
expect_msg_seq({ expect_msg_seq({
@ -97,14 +96,14 @@ describe('jobs', function()
end) end)
it('append environment with pty #env', function() it('append environment with pty #env', function()
nvim('command', "let $VAR = 'abc'") command("let $VAR = 'abc'")
nvim('command', "let $TOTO = 'goodbye world'") command("let $TOTO = 'goodbye world'")
nvim('command', 'let g:job_opts.pty = v:true') command('let g:job_opts.pty = v:true')
nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") command("let g:job_opts.env = {'TOTO': 'hello world'}")
if is_os('win') then if is_os('win') then
nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]])
else else
nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) command([[call jobstart('echo $TOTO $VAR', g:job_opts)]])
end end
expect_msg_seq({ expect_msg_seq({
{ 'notification', 'stdout', { 0, { 'hello world abc' } } }, { 'notification', 'stdout', { 0, { 'hello world abc' } } },
@ -116,10 +115,10 @@ describe('jobs', function()
end) end)
it('replace environment #env', function() it('replace environment #env', function()
nvim('command', "let $VAR = 'abc'") command("let $VAR = 'abc'")
nvim('command', "let $TOTO = 'goodbye world'") command("let $TOTO = 'goodbye world'")
nvim('command', "let g:job_opts.env = {'TOTO': 'hello world'}") command("let g:job_opts.env = {'TOTO': 'hello world'}")
nvim('command', 'let g:job_opts.clear_env = 1') command('let g:job_opts.clear_env = 1')
-- libuv ensures that certain "required" environment variables are -- libuv ensures that certain "required" environment variables are
-- preserved if the user doesn't provide them in a custom environment -- preserved if the user doesn't provide them in a custom environment
@ -129,13 +128,13 @@ describe('jobs', function()
-- Rather than expecting a completely empty environment, ensure that $VAR -- Rather than expecting a completely empty environment, ensure that $VAR
-- is *not* in the environment but $TOTO is. -- is *not* in the environment but $TOTO is.
if is_os('win') then if is_os('win') then
nvim('command', [[call jobstart('echo %TOTO% %VAR%', g:job_opts)]]) command([[call jobstart('echo %TOTO% %VAR%', g:job_opts)]])
expect_msg_seq({ expect_msg_seq({
{ 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } }, { 'notification', 'stdout', { 0, { 'hello world %VAR%', '' } } },
}) })
else else
nvim('command', 'set shell=/bin/sh') command('set shell=/bin/sh')
nvim('command', [[call jobstart('echo $TOTO $VAR', g:job_opts)]]) command([[call jobstart('echo $TOTO $VAR', g:job_opts)]])
expect_msg_seq({ expect_msg_seq({
{ 'notification', 'stdout', { 0, { 'hello world', '' } } }, { 'notification', 'stdout', { 0, { 'hello world', '' } } },
}) })
@ -143,17 +142,17 @@ describe('jobs', function()
end) end)
it('handles case-insensitively matching #env vars', function() it('handles case-insensitively matching #env vars', function()
nvim('command', "let $TOTO = 'abc'") command("let $TOTO = 'abc'")
-- Since $Toto is being set in the job, it should take precedence over the -- Since $Toto is being set in the job, it should take precedence over the
-- global $TOTO on Windows -- global $TOTO on Windows
nvim('command', "let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}") command("let g:job_opts = {'env': {'Toto': 'def'}, 'stdout_buffered': v:true}")
if is_os('win') then if is_os('win') then
nvim('command', [[let j = jobstart('set | find /I "toto="', g:job_opts)]]) command([[let j = jobstart('set | find /I "toto="', g:job_opts)]])
else else
nvim('command', [[let j = jobstart('env | grep -i toto=', g:job_opts)]]) command([[let j = jobstart('env | grep -i toto=', g:job_opts)]])
end end
nvim('command', 'call jobwait([j])') command('call jobwait([j])')
nvim('command', 'let g:output = Normalize(g:job_opts.stdout)') command('let g:output = Normalize(g:job_opts.stdout)')
local actual = eval('g:output') local actual = eval('g:output')
local expected local expected
if is_os('win') then if is_os('win') then
@ -169,11 +168,11 @@ describe('jobs', function()
end) end)
it('uses &shell and &shellcmdflag if passed a string', function() it('uses &shell and &shellcmdflag if passed a string', function()
nvim('command', "let $VAR = 'abc'") command("let $VAR = 'abc'")
if is_os('win') then if is_os('win') then
nvim('command', "let j = jobstart('echo %VAR%', g:job_opts)") command("let j = jobstart('echo %VAR%', g:job_opts)")
else else
nvim('command', "let j = jobstart('echo $VAR', g:job_opts)") command("let j = jobstart('echo $VAR', g:job_opts)")
end end
eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg())
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
@ -181,11 +180,11 @@ describe('jobs', function()
end) end)
it('changes to given / directory', function() it('changes to given / directory', function()
nvim('command', "let g:job_opts.cwd = '/'") command("let g:job_opts.cwd = '/'")
if is_os('win') then if is_os('win') then
nvim('command', "let j = jobstart('cd', g:job_opts)") command("let j = jobstart('cd', g:job_opts)")
else else
nvim('command', "let j = jobstart('pwd', g:job_opts)") command("let j = jobstart('pwd', g:job_opts)")
end end
eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { pathroot(), '' } } }, next_msg())
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
@ -195,11 +194,11 @@ describe('jobs', function()
it('changes to given `cwd` directory', function() it('changes to given `cwd` directory', function()
local dir = eval('resolve(tempname())'):gsub('/', get_pathsep()) local dir = eval('resolve(tempname())'):gsub('/', get_pathsep())
mkdir(dir) mkdir(dir)
nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") command("let g:job_opts.cwd = '" .. dir .. "'")
if is_os('win') then if is_os('win') then
nvim('command', "let j = jobstart('cd', g:job_opts)") command("let j = jobstart('cd', g:job_opts)")
else else
nvim('command', "let j = jobstart('pwd', g:job_opts)") command("let j = jobstart('pwd', g:job_opts)")
end end
expect_msg_seq( expect_msg_seq(
{ {
@ -221,11 +220,11 @@ describe('jobs', function()
it('fails to change to invalid `cwd`', function() it('fails to change to invalid `cwd`', function()
local dir = eval('resolve(tempname())."-bogus"') local dir = eval('resolve(tempname())."-bogus"')
local _, err = pcall(function() local _, err = pcall(function()
nvim('command', "let g:job_opts.cwd = '" .. dir .. "'") command("let g:job_opts.cwd = '" .. dir .. "'")
if is_os('win') then if is_os('win') then
nvim('command', "let j = jobstart('cd', g:job_opts)") command("let j = jobstart('cd', g:job_opts)")
else else
nvim('command', "let j = jobstart('pwd', g:job_opts)") command("let j = jobstart('pwd', g:job_opts)")
end end
end) end)
ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil)
@ -239,7 +238,7 @@ describe('jobs', function()
funcs.setfperm(dir, 'rw-------') funcs.setfperm(dir, 'rw-------')
matches( matches(
'^Vim%(call%):E903: Process failed to start: permission denied: .*', '^Vim%(call%):E903: Process failed to start: permission denied: .*',
pcall_err(nvim, 'command', "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})") pcall_err(command, "call jobstart(['pwd'], {'cwd': '" .. dir .. "'})")
) )
rmdir(dir) rmdir(dir)
end) end)
@ -269,8 +268,8 @@ describe('jobs', function()
end) end)
it('invokes callbacks when the job writes and exits', function() it('invokes callbacks when the job writes and exits', function()
nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") command("let g:job_opts.on_stderr = function('OnEvent')")
nvim('command', [[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]]) command([[call jobstart(has('win32') ? 'echo:' : 'echo', g:job_opts)]])
expect_twostreams({ expect_twostreams({
{ 'notification', 'stdout', { 0, { '', '' } } }, { 'notification', 'stdout', { 0, { '', '' } } },
{ 'notification', 'stdout', { 0, { '' } } }, { 'notification', 'stdout', { 0, { '' } } },
@ -279,11 +278,11 @@ describe('jobs', function()
end) end)
it('interactive commands', function() it('interactive commands', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
neq(0, eval('j')) neq(0, eval('j'))
nvim('command', 'call jobsend(j, "abc\\n")') command('call jobsend(j, "abc\\n")')
eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'abc', '' } } }, next_msg())
nvim('command', 'call jobsend(j, "123\\nxyz\\n")') command('call jobsend(j, "123\\nxyz\\n")')
expect_msg_seq( expect_msg_seq(
{ { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } },
-- Alternative sequence: -- Alternative sequence:
@ -292,7 +291,7 @@ describe('jobs', function()
{ 'notification', 'stdout', { 0, { 'xyz', '' } } }, { 'notification', 'stdout', { 0, { 'xyz', '' } } },
} }
) )
nvim('command', 'call jobsend(j, [123, "xyz", ""])') command('call jobsend(j, [123, "xyz", ""])')
expect_msg_seq( expect_msg_seq(
{ { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } }, { { 'notification', 'stdout', { 0, { '123', 'xyz', '' } } } },
-- Alternative sequence: -- Alternative sequence:
@ -301,7 +300,7 @@ describe('jobs', function()
{ 'notification', 'stdout', { 0, { 'xyz', '' } } }, { 'notification', 'stdout', { 0, { 'xyz', '' } } },
} }
) )
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
end) end)
@ -311,75 +310,75 @@ describe('jobs', function()
local filename = helpers.tmpname() local filename = helpers.tmpname()
write_file(filename, 'abc\0def\n') write_file(filename, 'abc\0def\n')
nvim('command', "let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)") command("let j = jobstart(['cat', '" .. filename .. "'], g:job_opts)")
eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'abc\ndef', '' } } }, next_msg())
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg())
os.remove(filename) os.remove(filename)
-- jobsend() preserves NULs. -- jobsend() preserves NULs.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', [[call jobsend(j, ["123\n456",""])]]) command([[call jobsend(j, ["123\n456",""])]])
eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '123\n456', '' } } }, next_msg())
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
end) end)
it('emits partial lines (does NOT buffer data lacking newlines)', function() it('emits partial lines (does NOT buffer data lacking newlines)', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, "abc\\nxyz")') command('call jobsend(j, "abc\\nxyz")')
eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'abc', 'xyz' } } }, next_msg())
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
end) end)
it('preserves newlines', function() it('preserves newlines', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') command('call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")')
eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'a', '', 'c', '', '', '', 'b', '', '' } } }, next_msg())
end) end)
it('preserves NULs', function() it('preserves NULs', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') command('call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])')
eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '\n123\n', 'abc\nxyz\n', '' } } }, next_msg())
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
end) end)
it('avoids sending final newline', function() it('avoids sending final newline', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') command('call jobsend(j, ["some data", "without\nfinal nl"])')
eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { 'some data', 'without\nfinal nl' } } }, next_msg())
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
end) end)
it('closes the job streams with jobclose', function() it('closes the job streams with jobclose', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobclose(j, "stdin")') command('call jobclose(j, "stdin")')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 0 } }, next_msg()) eq({ 'notification', 'exit', { 0, 0 } }, next_msg())
end) end)
it('disallows jobsend on a job that closed stdin', function() it('disallows jobsend on a job that closed stdin', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobclose(j, "stdin")') command('call jobclose(j, "stdin")')
eq( eq(
false, false,
pcall(function() pcall(function()
nvim('command', 'call jobsend(j, ["some data"])') command('call jobsend(j, ["some data"])')
end) end)
) )
command("let g:job_opts.stdin = 'null'") command("let g:job_opts.stdin = 'null'")
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
eq( eq(
false, false,
pcall(function() pcall(function()
nvim('command', 'call jobsend(j, ["some data"])') command('call jobsend(j, ["some data"])')
end) end)
) )
end) end)
@ -390,21 +389,21 @@ describe('jobs', function()
end) end)
it('jobstop twice on the stopped or exited job return 0', function() it('jobstop twice on the stopped or exited job return 0', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
neq(0, eval('j')) neq(0, eval('j'))
eq(1, eval('jobstop(j)')) eq(1, eval('jobstop(j)'))
eq(0, eval('jobstop(j)')) eq(0, eval('jobstop(j)'))
end) end)
it('will not leak memory if we leave a job running', function() it('will not leak memory if we leave a job running', function()
nvim('command', "call jobstart(['cat', '-'], g:job_opts)") command("call jobstart(['cat', '-'], g:job_opts)")
end) end)
it('can get the pid value using getpid', function() it('can get the pid value using getpid', function()
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
local pid = eval('jobpid(j)') local pid = eval('jobpid(j)')
neq(NIL, meths.nvim_get_proc(pid)) neq(NIL, meths.nvim_get_proc(pid))
nvim('command', 'call jobstop(j)') command('call jobstop(j)')
eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 0, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
eq(NIL, meths.nvim_get_proc(pid)) eq(NIL, meths.nvim_get_proc(pid))
@ -412,8 +411,7 @@ describe('jobs', function()
it('disposed on Nvim exit', function() it('disposed on Nvim exit', function()
-- use sleep, which doesn't die on stdin close -- use sleep, which doesn't die on stdin close
nvim( command(
'command',
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
) )
local pid = eval('jobpid(g:j)') local pid = eval('jobpid(g:j)')
@ -423,9 +421,8 @@ describe('jobs', function()
end) end)
it('can survive the exit of nvim with "detach"', function() it('can survive the exit of nvim with "detach"', function()
nvim('command', 'let g:job_opts.detach = 1') command('let g:job_opts.detach = 1')
nvim( command(
'command',
"let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)" "let g:j = jobstart(has('win32') ? ['ping', '-n', '1001', '127.0.0.1'] : ['sleep', '1000'], g:job_opts)"
) )
local pid = eval('jobpid(g:j)') local pid = eval('jobpid(g:j)')
@ -437,8 +434,8 @@ describe('jobs', function()
end) end)
it('can pass user data to the callback', function() it('can pass user data to the callback', function()
nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}') command('let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}')
nvim('command', [[call jobstart('echo foo', g:job_opts)]]) command([[call jobstart('echo foo', g:job_opts)]])
local data = { n = 5, s = 'str', l = { 1 } } local data = { n = 5, s = 'str', l = { 1 } }
expect_msg_seq( expect_msg_seq(
{ {
@ -456,16 +453,16 @@ describe('jobs', function()
end) end)
it('can omit data callbacks', function() it('can omit data callbacks', function()
nvim('command', 'unlet g:job_opts.on_stdout') command('unlet g:job_opts.on_stdout')
nvim('command', 'let g:job_opts.user = 5') command('let g:job_opts.user = 5')
nvim('command', [[call jobstart('echo foo', g:job_opts)]]) command([[call jobstart('echo foo', g:job_opts)]])
eq({ 'notification', 'exit', { 5, 0 } }, next_msg()) eq({ 'notification', 'exit', { 5, 0 } }, next_msg())
end) end)
it('can omit exit callback', function() it('can omit exit callback', function()
nvim('command', 'unlet g:job_opts.on_exit') command('unlet g:job_opts.on_exit')
nvim('command', 'let g:job_opts.user = 5') command('let g:job_opts.user = 5')
nvim('command', [[call jobstart('echo foo', g:job_opts)]]) command([[call jobstart('echo foo', g:job_opts)]])
expect_msg_seq( expect_msg_seq(
{ {
{ 'notification', 'stdout', { 5, { 'foo', '' } } }, { 'notification', 'stdout', { 5, { 'foo', '' } } },
@ -481,8 +478,8 @@ describe('jobs', function()
end) end)
it('will pass return code with the exit event', function() it('will pass return code with the exit event', function()
nvim('command', 'let g:job_opts.user = 5') command('let g:job_opts.user = 5')
nvim('command', "call jobstart('exit 55', g:job_opts)") command("call jobstart('exit 55', g:job_opts)")
eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg()) eq({ 'notification', 'stdout', { 5, { '' } } }, next_msg())
eq({ 'notification', 'exit', { 5, 55 } }, next_msg()) eq({ 'notification', 'exit', { 5, 55 } }, next_msg())
end) end)
@ -883,7 +880,7 @@ describe('jobs', function()
r = next_msg() r = next_msg()
eq('job ' .. i .. ' exited', r[3][1]) eq('job ' .. i .. ' exited', r[3][1])
end end
eq(10, nvim('eval', 'g:counter')) eq(10, meths.nvim_eval('g:counter'))
end) end)
describe('with timeout argument', function() describe('with timeout argument', function()
@ -953,10 +950,10 @@ describe('jobs', function()
end) end)
pending('exit event follows stdout, stderr', function() pending('exit event follows stdout, stderr', function()
nvim('command', "let g:job_opts.on_stderr = function('OnEvent')") command("let g:job_opts.on_stderr = function('OnEvent')")
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") command("let j = jobstart(['cat', '-'], g:job_opts)")
nvim('eval', 'jobsend(j, "abcdef")') meths.nvim_eval('jobsend(j, "abcdef")')
nvim('eval', 'jobstop(j)') meths.nvim_eval('jobstop(j)')
expect_msg_seq( expect_msg_seq(
{ {
{ 'notification', 'stdout', { 0, { 'abcdef' } } }, { 'notification', 'stdout', { 0, { 'abcdef' } } },
@ -1099,7 +1096,7 @@ describe('jobs', function()
end) end)
it('jobstop on same id before stopped', function() it('jobstop on same id before stopped', function()
nvim('command', 'let j = jobstart(["cat", "-"], g:job_opts)') command('let j = jobstart(["cat", "-"], g:job_opts)')
neq(0, eval('j')) neq(0, eval('j'))
eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]')) eq({ 1, 0 }, eval('[jobstop(j), jobstop(j)]'))
@ -1140,9 +1137,9 @@ describe('jobs', function()
endfunction endfunction
]]) ]])
insert(testprg('tty-test')) insert(testprg('tty-test'))
nvim('command', 'let g:job_opts.pty = 1') command('let g:job_opts.pty = 1')
nvim('command', 'let exec = [expand("<cfile>:p")]') command('let exec = [expand("<cfile>:p")]')
nvim('command', 'let j = jobstart(exec, g:job_opts)') command('let j = jobstart(exec, g:job_opts)')
j = eval 'j' j = eval 'j'
eq('tty ready', next_chunk()) eq('tty ready', next_chunk())
end) end)
@ -1153,14 +1150,14 @@ describe('jobs', function()
end) end)
it('resizing window', function() it('resizing window', function()
nvim('command', 'call jobresize(j, 40, 10)') command('call jobresize(j, 40, 10)')
eq('rows: 10, cols: 40', next_chunk()) eq('rows: 10, cols: 40', next_chunk())
nvim('command', 'call jobresize(j, 10, 40)') command('call jobresize(j, 10, 40)')
eq('rows: 40, cols: 10', next_chunk()) eq('rows: 40, cols: 10', next_chunk())
end) end)
it('jobclose() sends SIGHUP', function() it('jobclose() sends SIGHUP', function()
nvim('command', 'call jobclose(j)') command('call jobclose(j)')
local msg = next_msg() local msg = next_msg()
msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any. msg = (msg[2] == 'stdout') and next_msg() or msg -- Skip stdout, if any.
eq({ 'notification', 'exit', { 0, 42 } }, msg) eq({ 'notification', 'exit', { 0, 42 } }, msg)

View File

@ -5,7 +5,6 @@ local clear, feed = helpers.clear, helpers.feed
local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq
local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect
local funcs = helpers.funcs local funcs = helpers.funcs
local curbufmeths = helpers.curbufmeths
local command = helpers.command local command = helpers.command
local meths = helpers.meths local meths = helpers.meths
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
@ -928,7 +927,7 @@ describe('completion', function()
end) end)
it('CompleteChanged autocommand', function() it('CompleteChanged autocommand', function()
curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', '' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'foobar', '' })
source([[ source([[
set complete=. completeopt=noinsert,noselect,menuone set complete=. completeopt=noinsert,noselect,menuone
function! OnPumChange() function! OnPumChange()

View File

@ -8,7 +8,7 @@ local funcs = helpers.funcs
local feed = helpers.feed local feed = helpers.feed
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local write_file = helpers.write_file local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
describe('jumplist', function() describe('jumplist', function()
local fname1 = 'Xtest-functional-normal-jump' local fname1 = 'Xtest-functional-normal-jump'
@ -284,7 +284,7 @@ describe('jumpoptions=view', function()
screen:attach() screen:attach()
command('edit ' .. file1) command('edit ' .. file1)
feed('7GzbG') feed('7GzbG')
curbufmeths.set_lines(0, 2, true, {}) meths.nvim_buf_set_lines(0, 0, 2, true, {})
-- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover
-- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the
-- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5. -- file, delete 2 lines before line 7, meaning the jump/mark is moved 2 lines up to line 5.

View File

@ -4,7 +4,7 @@ local eq, neq, call = helpers.eq, helpers.neq, helpers.call
local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear
local command, insert, expect = helpers.command, helpers.insert, helpers.expect local command, insert, expect = helpers.command, helpers.insert, helpers.expect
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local curwin = helpers.curwin local curwin = helpers.meths.nvim_get_current_win
describe("'langmap'", function() describe("'langmap'", function()
before_each(function() before_each(function()

View File

@ -9,7 +9,6 @@ local command = helpers.command
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local insert = helpers.insert local insert = helpers.insert
local curbufmeths = helpers.curbufmeths
describe('macros', function() describe('macros', function()
before_each(function() before_each(function()
@ -41,16 +40,19 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[G3Q]] feed [[G3Q]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[ggV3jQ]] feed [[ggV3jQ]]
eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false)
)
end) end)
it('can be replayed with @', function() it('can be replayed with @', function()
@ -60,16 +62,19 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>q]] feed [[qqAFOO<esc>q]]
eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[Q]] feed [[Q]]
eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[G3@@]] feed [[G3@@]]
eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[ggV2j@@]] feed [[ggV2j@@]]
eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) eq(
{ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' },
meths.nvim_buf_get_lines(0, 0, -1, false)
)
end) end)
it('can be replayed with @q and @w', function() it('can be replayed with @q and @w', function()
@ -79,17 +84,17 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[V3j@q]] feed [[V3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[gg]] feed [[gg]]
feed [[Vj@w]] feed [[Vj@w]]
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can be replayed with @q and @w visual-block', function() it('can be replayed with @q and @w visual-block', function()
@ -99,17 +104,17 @@ hello]]
feed [[gg]] feed [[gg]]
feed [[qqAFOO<esc>qu]] feed [[qqAFOO<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[qwA123<esc>qu]] feed [[qwA123<esc>qu]]
eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) eq({ 'hello', 'hello', 'hello' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[<C-v>3j@q]] feed [[<C-v>3j@q]]
eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
feed [[gg]] feed [[gg]]
feed [[<C-v>j@w]] feed [[<C-v>j@w]]
eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
end) end)

View File

@ -1,7 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local meths = helpers.meths local meths = helpers.meths
local curbufmeths = helpers.curbufmeths
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local funcs = helpers.funcs
@ -29,13 +28,13 @@ describe('named marks', function()
it('can be set', function() it('can be set', function()
command('edit ' .. file1) command('edit ' .. file1)
command('mark a') command('mark a')
eq({ 1, 0 }, curbufmeths.get_mark('a')) eq({ 1, 0 }, meths.nvim_buf_get_mark(0, 'a'))
feed('jmb') feed('jmb')
eq({ 2, 0 }, curbufmeths.get_mark('b')) eq({ 2, 0 }, meths.nvim_buf_get_mark(0, 'b'))
feed('jmB') feed('jmB')
eq({ 3, 0 }, curbufmeths.get_mark('B')) eq({ 3, 0 }, meths.nvim_buf_get_mark(0, 'B'))
command('4kc') command('4kc')
eq({ 4, 0 }, curbufmeths.get_mark('c')) eq({ 4, 0 }, meths.nvim_buf_get_mark(0, 'c'))
end) end)
it('errors when set out of range with :mark', function() it('errors when set out of range with :mark', function()

View File

@ -184,11 +184,11 @@ describe('put command', function()
return function(exception_table, after_redo) return function(exception_table, after_redo)
expect(expect_string) expect(expect_string)
-- Have to use getcurpos() instead of curwinmeths.get_cursor() in -- Have to use getcurpos() instead of meths.nvim_win_get_cursor(0) in
-- order to account for virtualedit. -- order to account for virtualedit.
-- We always want the curswant element in getcurpos(), which is -- We always want the curswant element in getcurpos(), which is
-- sometimes different to the column element in -- sometimes different to the column element in
-- curwinmeths.get_cursor(). -- meths.nvim_win_get_cursor(0).
-- NOTE: The ".gp command leaves the cursor after the pasted text -- NOTE: The ".gp command leaves the cursor after the pasted text
-- when running, but does not when the command is redone with the -- when running, but does not when the command is redone with the
-- '.' command. -- '.' command.

View File

@ -10,7 +10,7 @@ local eval = helpers.eval
local exec = helpers.exec local exec = helpers.exec
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local curwin = helpers.curwin local curwin = helpers.meths.nvim_get_current_win
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
describe('tabpage', function() describe('tabpage', function()

View File

@ -7,7 +7,6 @@ local feed = helpers.feed
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs local funcs = helpers.funcs
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local meths = helpers.meths local meths = helpers.meths
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
@ -15,11 +14,11 @@ local cmdtest = function(cmd, prep, ret1)
describe(':' .. cmd, function() describe(':' .. cmd, function()
before_each(function() before_each(function()
clear() clear()
curbufmeths.set_lines(0, 1, true, { 'foo', 'bar', 'baz' }) meths.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' })
end) end)
local buffer_contents = function() local buffer_contents = function()
return curbufmeths.get_lines(0, -1, false) return meths.nvim_buf_get_lines(0, 0, -1, false)
end end
it(cmd .. 's' .. prep .. ' the current line by default', function() it(cmd .. 's' .. prep .. ' the current line by default', function()

View File

@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local clear, nvim, source = helpers.clear, helpers.nvim, helpers.source local clear, source = helpers.clear, helpers.source
local meths = helpers.meths
local insert = helpers.insert local insert = helpers.insert
local eq, next_msg = helpers.eq, helpers.next_msg local eq, next_msg = helpers.eq, helpers.next_msg
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
@ -13,8 +14,8 @@ describe('Vimscript dictionary notifications', function()
before_each(function() before_each(function()
clear() clear()
channel = nvim('get_api_info')[1] channel = meths.nvim_get_api_info()[1]
nvim('set_var', 'channel', channel) meths.nvim_set_var('channel', channel)
end) end)
-- the same set of tests are applied to top-level dictionaries(g:, b:, w: and -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and
@ -59,7 +60,7 @@ describe('Vimscript dictionary notifications', function()
local function verify_echo() local function verify_echo()
-- helper to verify that no notifications are sent after certain change -- helper to verify that no notifications are sent after certain change
-- to a dict -- to a dict
nvim('command', "call rpcnotify(g:channel, 'echo')") command("call rpcnotify(g:channel, 'echo')")
eq({ 'notification', 'echo', {} }, next_msg()) eq({ 'notification', 'echo', {} }, next_msg())
end end
@ -134,7 +135,7 @@ describe('Vimscript dictionary notifications', function()
it('is triggered by remove()', function() it('is triggered by remove()', function()
update('= "test"') update('= "test"')
verify_value({ new = 'test' }) verify_value({ new = 'test' })
nvim('command', 'call remove(' .. dict_expr .. ', "watched")') command('call remove(' .. dict_expr .. ', "watched")')
verify_value({ old = 'test' }) verify_value({ old = 'test' })
end) end)
@ -142,14 +143,14 @@ describe('Vimscript dictionary notifications', function()
it('is triggered by remove() when updated with nvim_*_var', function() it('is triggered by remove() when updated with nvim_*_var', function()
update_with_api('"test"') update_with_api('"test"')
verify_value({ new = 'test' }) verify_value({ new = 'test' })
nvim('command', 'call remove(' .. dict_expr .. ', "watched")') command('call remove(' .. dict_expr .. ', "watched")')
verify_value({ old = 'test' }) verify_value({ old = 'test' })
end) end)
it('is triggered by remove() when updated with vim.g', function() it('is triggered by remove() when updated with vim.g', function()
update_with_vim_g('= "test"') update_with_vim_g('= "test"')
verify_value({ new = 'test' }) verify_value({ new = 'test' })
nvim('command', 'call remove(' .. dict_expr .. ', "watched")') command('call remove(' .. dict_expr .. ', "watched")')
verify_value({ old = 'test' }) verify_value({ old = 'test' })
end) end)
end end
@ -157,7 +158,7 @@ describe('Vimscript dictionary notifications', function()
it('is triggered by extend()', function() it('is triggered by extend()', function()
update('= "xtend"') update('= "xtend"')
verify_value({ new = 'xtend' }) verify_value({ new = 'xtend' })
nvim('command', [[ command([[
call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'})
]]) ]])
verify_value({ old = 'xtend', new = 'xtend2' }) verify_value({ old = 'xtend', new = 'xtend2' })
@ -293,17 +294,17 @@ describe('Vimscript dictionary notifications', function()
end) end)
it('invokes all callbacks when the key is changed', function() it('invokes all callbacks when the key is changed', function()
nvim('command', 'let g:key = "value"') command('let g:key = "value"')
eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg())
eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg())
end) end)
it('only removes watchers that fully match dict, key and callback', function() it('only removes watchers that fully match dict, key and callback', function()
nvim('command', 'let g:key = "value"') command('let g:key = "value"')
eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg())
eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg())
nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') command('call dictwatcherdel(g:, "key", "g:Watcher1")')
nvim('command', 'let g:key = "v2"') command('let g:key = "v2"')
eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg()) eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg())
end) end)
end) end)

View File

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

View File

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

View File

@ -1,5 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, command, nvim = helpers.clear, helpers.command, helpers.nvim local clear, command = helpers.clear, helpers.command
local expect, feed = helpers.expect, helpers.feed local expect, feed = helpers.expect, helpers.feed
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local funcs = helpers.funcs local funcs = helpers.funcs
@ -42,12 +42,12 @@ describe(':emenu', function()
feed('ithis is a sentence<esc>^yiwo<esc>') feed('ithis is a sentence<esc>^yiwo<esc>')
-- Invoke "Edit.Paste" in normal-mode. -- Invoke "Edit.Paste" in normal-mode.
nvim('command', 'emenu Edit.Paste') command('emenu Edit.Paste')
-- Invoke "Edit.Paste" and "Test.Test" in command-mode. -- Invoke "Edit.Paste" and "Test.Test" in command-mode.
feed(':') feed(':')
nvim('command', 'emenu Edit.Paste') command('emenu Edit.Paste')
nvim('command', 'emenu Test.Test') command('emenu Test.Test')
expect([[ expect([[
this is a sentence this is a sentence

View File

@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command local meths, eq, feed_command = helpers.meths, helpers.eq, helpers.feed_command
local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop
local ok = helpers.ok local ok = helpers.ok
local eval = helpers.eval local eval = helpers.eval
@ -42,7 +42,7 @@ describe(':oldfiles', function()
feed_command('edit testfile2') feed_command('edit testfile2')
feed_command('wshada') feed_command('wshada')
feed_command('rshada!') feed_command('rshada!')
local oldfiles = helpers.meths.nvim_get_vvar('oldfiles') local oldfiles = meths.nvim_get_vvar('oldfiles')
feed_command('oldfiles') feed_command('oldfiles')
screen:expect([[ screen:expect([[
| |
@ -56,11 +56,11 @@ describe(':oldfiles', function()
it('can be filtered with :filter', function() it('can be filtered with :filter', function()
feed_command('edit file_one.txt') feed_command('edit file_one.txt')
local file1 = buf.get_name() local file1 = meths.nvim_buf_get_name(0)
feed_command('edit file_two.txt') feed_command('edit file_two.txt')
local file2 = buf.get_name() local file2 = meths.nvim_buf_get_name(0)
feed_command('edit another.txt') feed_command('edit another.txt')
local another = buf.get_name() local another = meths.nvim_buf_get_name(0)
feed_command('wshada') feed_command('wshada')
feed_command('rshada!') feed_command('rshada!')
@ -95,9 +95,9 @@ describe(':browse oldfiles', function()
before_each(function() before_each(function()
_clear() _clear()
feed_command('edit testfile1') feed_command('edit testfile1')
filename = buf.get_name() filename = meths.nvim_buf_get_name(0)
feed_command('edit testfile2') feed_command('edit testfile2')
filename2 = buf.get_name() filename2 = meths.nvim_buf_get_name(0)
feed_command('wshada') feed_command('wshada')
poke_eventloop() poke_eventloop()
_clear() _clear()
@ -123,16 +123,16 @@ describe(':browse oldfiles', function()
it('provides a prompt and edits the chosen file', function() it('provides a prompt and edits the chosen file', function()
feed('2<cr>') feed('2<cr>')
eq(oldfiles[2], buf.get_name()) eq(oldfiles[2], meths.nvim_buf_get_name(0))
end) end)
it('provides a prompt and does nothing on <cr>', function() it('provides a prompt and does nothing on <cr>', function()
feed('<cr>') feed('<cr>')
eq('', buf.get_name()) eq('', meths.nvim_buf_get_name(0))
end) end)
it('provides a prompt and does nothing if choice is out-of-bounds', function() it('provides a prompt and does nothing if choice is out-of-bounds', function()
feed('3<cr>') feed('3<cr>')
eq('', buf.get_name()) eq('', meths.nvim_buf_get_name(0))
end) end)
end) end)

View File

@ -8,7 +8,7 @@ local funcs = helpers.funcs
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local write_file = helpers.write_file local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
local source = helpers.source local source = helpers.source
local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' local file_base = 'Xtest-functional-ex_cmds-quickfix_commands'
@ -79,7 +79,7 @@ for _, c in ipairs({ 'l', 'c' }) do
-- Run cfile/lfile from a modified buffer -- Run cfile/lfile from a modified buffer
command('set nohidden') command('set nohidden')
command('enew!') command('enew!')
curbufmeths.set_lines(1, 1, true, { 'Quickfix' }) meths.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' })
eq( eq(
('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd),
exc_exec(('%s %s'):format(filecmd, file)) exc_exec(('%s %s'):format(filecmd, file))

View File

@ -1,5 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, eq, assert_alive = helpers.clear, helpers.nvim, helpers.eq, helpers.assert_alive local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive
local command = helpers.command
local meths = helpers.meths
describe('sign', function() describe('sign', function()
before_each(clear) before_each(clear)
@ -7,24 +9,24 @@ describe('sign', function()
describe('without specifying buffer', function() describe('without specifying buffer', function()
it('deletes the sign from all buffers', function() it('deletes the sign from all buffers', function()
-- place a sign with id 34 to first buffer -- place a sign with id 34 to first buffer
nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number')
local buf1 = nvim('eval', 'bufnr("%")') local buf1 = meths.nvim_eval('bufnr("%")')
nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf1) command('sign place 34 line=3 name=Foo buffer=' .. buf1)
-- create a second buffer and place the sign on it as well -- create a second buffer and place the sign on it as well
nvim('command', 'new') command('new')
local buf2 = nvim('eval', 'bufnr("%")') local buf2 = meths.nvim_eval('bufnr("%")')
nvim('command', 'sign place 34 line=3 name=Foo buffer=' .. buf2) command('sign place 34 line=3 name=Foo buffer=' .. buf2)
-- now unplace without specifying a buffer -- now unplace without specifying a buffer
nvim('command', 'sign unplace 34') command('sign unplace 34')
eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf1, true)) eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf1, true))
eq('--- Signs ---\n', nvim('exec', 'sign place buffer=' .. buf2, true)) eq('--- Signs ---\n', meths.nvim_exec('sign place buffer=' .. buf2, true))
end) end)
end) end)
end) end)
describe('define {id}', function() describe('define {id}', function()
it('does not leak memory when specifying multiple times the same argument', function() it('does not leak memory when specifying multiple times the same argument', function()
nvim('command', 'sign define Foo culhl=Normal culhl=Normal') command('sign define Foo culhl=Normal culhl=Normal')
assert_alive() assert_alive()
end) end)
end) end)

View File

@ -290,12 +290,6 @@ function module.nvim_prog_abs()
end end
end end
-- Executes an ex-command. Vimscript errors manifest as client (lua) errors, but
-- v:errmsg will not be updated.
function module.command(cmd)
module.request('nvim_command', cmd)
end
-- Use for commands which expect nvim to quit. -- Use for commands which expect nvim to quit.
-- The first argument can also be a timeout. -- The first argument can also be a timeout.
function module.expect_exit(fn_or_timeout, ...) function module.expect_exit(fn_or_timeout, ...)
@ -629,57 +623,17 @@ module.async_meths = module.create_callindex(module.nvim_async)
module.uimeths = module.create_callindex(ui) module.uimeths = module.create_callindex(ui)
local function create_api(request, call) local function create_api(request, call)
local m = {} local function nvim(method, ...)
function m.nvim(method, ...)
if vim.startswith(method, 'nvim_') then if vim.startswith(method, 'nvim_') then
return request(method, ...) return request(method, ...)
end end
return request('nvim_' .. method, ...) return request('nvim_' .. method, ...)
end end
function m.buffer(method, ...) return {
return request('nvim_buf_' .. method, ...) funcs = module.create_callindex(call),
end meths = module.create_callindex(nvim),
}
function m.window(method, ...)
return request('nvim_win_' .. method, ...)
end
function m.tabpage(method, ...)
return request('nvim_tabpage_' .. method, ...)
end
function m.curbuf(method, ...)
if not method then
return m.nvim('get_current_buf')
end
return m.buffer(method, 0, ...)
end
function m.curwin(method, ...)
if not method then
return m.nvim('get_current_win')
end
return m.window(method, 0, ...)
end
function m.curtab(method, ...)
if not method then
return m.nvim('get_current_tabpage')
end
return m.tabpage(method, 0, ...)
end
m.funcs = module.create_callindex(call)
m.meths = module.create_callindex(m.nvim)
m.bufmeths = module.create_callindex(m.buffer)
m.winmeths = module.create_callindex(m.window)
m.tabmeths = module.create_callindex(m.tabpage)
m.curbufmeths = module.create_callindex(m.curbuf)
m.curwinmeths = module.create_callindex(m.curwin)
m.curtabmeths = module.create_callindex(m.curtab)
return m
end end
module.rpc = { module.rpc = {
@ -705,11 +659,16 @@ end
--- add for typing. The for loop after will overwrite this --- add for typing. The for loop after will overwrite this
module.meths = vim.api module.meths = vim.api
module.funcs = vim.fn
for name, fn in pairs(module.rpc.api) do for name, fn in pairs(module.rpc.api) do
module[name] = fn module[name] = fn
end 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
function module.poke_eventloop() function module.poke_eventloop()
-- Execute 'nvim_eval' (a deferred function) to -- Execute 'nvim_eval' (a deferred function) to
-- force at least one main_loop iteration -- force at least one main_loop iteration
@ -723,7 +682,7 @@ end
---@see buf_lines() ---@see buf_lines()
function module.curbuf_contents() function module.curbuf_contents()
module.poke_eventloop() -- Before inspecting the buffer, do whatever. module.poke_eventloop() -- Before inspecting the buffer, do whatever.
return table.concat(module.curbuf('get_lines', 0, -1, true), '\n') return table.concat(module.meths.nvim_buf_get_lines(0, 0, -1, true), '\n')
end end
function module.expect(contents) function module.expect(contents)
@ -760,7 +719,7 @@ end
-- Asserts that buffer is loaded and visible in the current tabpage. -- Asserts that buffer is loaded and visible in the current tabpage.
function module.assert_visible(bufnr, visible) function module.assert_visible(bufnr, visible)
assert(type(visible) == 'boolean') assert(type(visible) == 'boolean')
eq(visible, module.bufmeths.is_loaded(bufnr)) eq(visible, module.meths.nvim_buf_is_loaded(bufnr))
if visible then if visible then
assert( assert(
-1 ~= module.funcs.bufwinnr(bufnr), -1 ~= module.funcs.bufwinnr(bufnr),

View File

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

View File

@ -18,7 +18,6 @@ local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local write_file = helpers.write_file local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths
local remove_trace = helpers.remove_trace local remove_trace = helpers.remove_trace
before_each(clear) before_each(clear)
@ -26,23 +25,23 @@ before_each(clear)
describe(':lua command', function() describe(':lua command', function()
it('works', function() it('works', function()
eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})'))
eq({ '', 'TEST' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'TEST' }, meths.nvim_buf_get_lines(0, 0, 100, false))
source([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"})
EOF]]) EOF]])
eq({ '', 'TSET' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'TSET' }, meths.nvim_buf_get_lines(0, 0, 100, false))
source([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]])
eq({ '', 'SETT' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'SETT' }, meths.nvim_buf_get_lines(0, 0, 100, false))
source([[ source([[
lua << EOF lua << EOF
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
EOF]]) EOF]])
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false))
matches( matches(
'.*Vim%(lua%):E15: Invalid expression: .*', '.*Vim%(lua%):E15: Invalid expression: .*',
pcall_err( pcall_err(
@ -68,7 +67,7 @@ describe(':lua command', function()
[[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]], [[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]],
remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))
) )
eq({ '' }, curbufmeths.get_lines(0, 100, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, 100, false))
end) end)
it('works with NULL errors', function() it('works with NULL errors', function()
eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)')) eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)'))
@ -76,13 +75,13 @@ describe(':lua command', function()
it('accepts embedded NLs without heredoc', function() it('accepts embedded NLs without heredoc', function()
-- Such code is usually used for `:execute 'lua' {generated_string}`: -- Such code is usually used for `:execute 'lua' {generated_string}`:
-- heredocs do not work in this case. -- heredocs do not work in this case.
meths.nvim_command([[ command([[
lua lua
vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})
vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"})
vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"})
]]) ]])
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false))
end) end)
it('preserves global and not preserves local variables', function() it('preserves global and not preserves local variables', function()
eq('', exec_capture('lua gvar = 42')) eq('', exec_capture('lua gvar = 42'))
@ -97,10 +96,10 @@ describe(':lua command', function()
'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'', 'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'',
pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)) pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s))
) )
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s))) eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s)))
eq({ '', s }, curbufmeths.get_lines(0, -1, false)) eq({ '', s }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('can show multiline error messages', function() it('can show multiline error messages', function()
@ -197,31 +196,31 @@ end)
describe(':luado command', function() describe(':luado command', function()
it('works', function() it('works', function()
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}'))
eq({ 'ABC', 'def', 'gHi' }, curbufmeths.get_lines(0, -1, false)) eq({ 'ABC', 'def', 'gHi' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines')) eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines'))
-- Automatic transformation of numbers -- Automatic transformation of numbers
eq('', exec_capture('luado return linenr')) eq('', exec_capture('luado return linenr'))
eq({ '1', '2', '3' }, curbufmeths.get_lines(0, -1, false)) eq({ '1', '2', '3' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture('luado return ("<%02x>"):format(line:byte())')) eq('', exec_capture('luado return ("<%02x>"):format(line:byte())'))
eq({ '<31>', '<32>', '<33>' }, curbufmeths.get_lines(0, -1, false)) eq({ '<31>', '<32>', '<33>' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('stops processing lines when suddenly out of lines', function() it('stops processing lines when suddenly out of lines', function()
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")'))
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq(1, funcs.luaeval('runs')) eq(1, funcs.luaeval('runs'))
end) end)
it('works correctly when changing lines out of range', function() it('works correctly when changing lines out of range', function()
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq( eq(
'Vim(luado):E322: Line number out of range: 1 past the end', 'Vim(luado):E322: Line number out of range: 1 past the end',
pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr') pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr')
) )
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
it('fails on errors', function() it('fails on errors', function()
eq( eq(
@ -237,7 +236,7 @@ describe(':luado command', function()
eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)')) eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)'))
end) end)
it('fails in sandbox when needed', function() it('fails in sandbox when needed', function()
curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'ABC', 'def', 'gHi' })
eq( eq(
'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', 'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1',
pcall_err(command, 'sandbox luado runs = (runs or 0) + 1') pcall_err(command, 'sandbox luado runs = (runs or 0) + 1')
@ -251,10 +250,10 @@ describe(':luado command', function()
'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'', 'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'',
pcall_err(command, ('luado return "%s'):format(s)) pcall_err(command, ('luado return "%s'):format(s))
) )
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
eq('', exec_capture(('luado return "%s"'):format(s))) eq('', exec_capture(('luado return "%s"'):format(s)))
eq({ s }, curbufmeths.get_lines(0, -1, false)) eq({ s }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
end) end)
@ -275,7 +274,7 @@ describe(':luafile', function()
]] ]]
) )
eq('', exec_capture('luafile ' .. fname)) eq('', exec_capture('luafile ' .. fname))
eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) eq({ '', 'ETTS', 'TTSE', 'STTE' }, meths.nvim_buf_get_lines(0, 0, 100, false))
end) end)
it('correctly errors out', function() it('correctly errors out', function()

View File

@ -5,8 +5,8 @@ local command = helpers.command
local clear = helpers.clear local clear = helpers.clear
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local eq = helpers.eq local eq = helpers.eq
local nvim = helpers.nvim
local matches = helpers.matches local matches = helpers.matches
local meths = helpers.meths
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
describe('vim.diagnostic', function() describe('vim.diagnostic', function()
@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function()
it('can perform updates after insert_leave', function() it('can perform updates after insert_leave', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
-- Save the diagnostics -- Save the diagnostics
exec_lua [[ exec_lua [[
@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function()
]] ]]
-- No diagnostics displayed yet. -- No diagnostics displayed yet.
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
) )
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function()
it('does not perform updates when not needed', function() it('does not perform updates when not needed', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
-- Save the diagnostics -- Save the diagnostics
exec_lua [[ exec_lua [[
@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function()
]] ]]
-- No diagnostics displayed yet. -- No diagnostics displayed yet.
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
eq(0, exec_lua [[return DisplayCount]]) eq(0, exec_lua [[return DisplayCount]])
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function()
eq(1, exec_lua [[return DisplayCount]]) eq(1, exec_lua [[return DisplayCount]])
-- Go in and out of insert mode one more time. -- Go in and out of insert mode one more time.
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
-- Should not have set the virtual text again. -- Should not have set the virtual text again.
eq(1, exec_lua [[return DisplayCount]]) eq(1, exec_lua [[return DisplayCount]])
@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function()
it('never sets virtual text, in combination with insert leave', function() it('never sets virtual text, in combination with insert leave', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
-- Save the diagnostics -- Save the diagnostics
exec_lua [[ exec_lua [[
@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function()
]] ]]
-- No diagnostics displayed yet. -- No diagnostics displayed yet.
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
eq(0, exec_lua [[return DisplayCount]]) eq(0, exec_lua [[return DisplayCount]])
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function()
eq(0, exec_lua [[return DisplayCount]]) eq(0, exec_lua [[return DisplayCount]])
-- Go in and out of insert mode one more time. -- Go in and out of insert mode one more time.
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
-- Should not have set the virtual text still. -- Should not have set the virtual text still.
eq(0, exec_lua [[return DisplayCount]]) eq(0, exec_lua [[return DisplayCount]])
@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function()
it('can perform updates while in insert mode, if desired', function() it('can perform updates while in insert mode, if desired', function()
exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
nvim('input', 'o') meths.nvim_input('o')
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
-- Save the diagnostics -- Save the diagnostics
exec_lua [[ exec_lua [[
@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function()
]] ]]
-- Diagnostics are displayed, because the user wanted them that way! -- Diagnostics are displayed, because the user wanted them that way!
eq({ mode = 'i', blocking = false }, nvim('get_mode')) eq({ mode = 'i', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,
exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]
) )
eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
nvim('input', '<esc>') meths.nvim_input('<esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
eq( eq(
1, 1,

View File

@ -341,7 +341,7 @@ describe('os.getenv', function()
end) end)
it('returns env var set by let', function() it('returns env var set by let', function()
local value = 'foo' local value = 'foo'
meths.nvim_command('let $XTEST_1 = "' .. value .. '"') command('let $XTEST_1 = "' .. value .. '"')
eq(value, funcs.luaeval('os.getenv("XTEST_1")')) eq(value, funcs.luaeval('os.getenv("XTEST_1")'))
end) end)
end) end)

View File

@ -221,9 +221,9 @@ describe('startup defaults', function()
eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {}))
-- Does not follow modifications to runtimepath. -- Does not follow modifications to runtimepath.
meths.nvim_command('set runtimepath+=foo') command('set runtimepath+=foo')
neq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) neq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {}))
meths.nvim_command('set packpath+=foo') command('set packpath+=foo')
eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {})) eq(meths.nvim_get_option_value('runtimepath', {}), meths.nvim_get_option_value('packpath', {}))
end) end)
@ -430,11 +430,11 @@ describe('XDG defaults', function()
), ),
(meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') (meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
) )
meths.nvim_command('set runtimepath&') command('set runtimepath&')
meths.nvim_command('set backupdir&') command('set backupdir&')
meths.nvim_command('set directory&') command('set directory&')
meths.nvim_command('set undodir&') command('set undodir&')
meths.nvim_command('set viewdir&') command('set viewdir&')
eq( eq(
( (
( (
@ -573,11 +573,11 @@ describe('XDG defaults', function()
), ),
(meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/') (meths.nvim_get_option_value('runtimepath', {})):gsub('\\', '/')
) )
meths.nvim_command('set runtimepath&') command('set runtimepath&')
meths.nvim_command('set backupdir&') command('set backupdir&')
meths.nvim_command('set directory&') command('set directory&')
meths.nvim_command('set undodir&') command('set undodir&')
meths.nvim_command('set viewdir&') command('set viewdir&')
eq( eq(
( (
( (
@ -617,7 +617,7 @@ describe('XDG defaults', function()
('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), ('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
meths.nvim_get_option_value('viewdir', {}):gsub('\\', '/') meths.nvim_get_option_value('viewdir', {}):gsub('\\', '/')
) )
meths.nvim_command('set all&') command('set all&')
eq( eq(
( (
'$XDG_DATA_HOME/nvim' '$XDG_DATA_HOME/nvim'
@ -745,11 +745,11 @@ describe('XDG defaults', function()
), ),
meths.nvim_get_option_value('runtimepath', {}) meths.nvim_get_option_value('runtimepath', {})
) )
meths.nvim_command('set runtimepath&') command('set runtimepath&')
meths.nvim_command('set backupdir&') command('set backupdir&')
meths.nvim_command('set directory&') command('set directory&')
meths.nvim_command('set undodir&') command('set undodir&')
meths.nvim_command('set viewdir&') command('set viewdir&')
eq( eq(
( (
'\\, \\, \\,' '\\, \\, \\,'

View File

@ -1,16 +1,14 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local eq, meths, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = local eq, meths, nvim_eval, nvim_command, exc_exec, funcs, nvim_feed =
helpers.eq, helpers.eq,
helpers.meths, helpers.meths,
helpers.eval, helpers.eval,
helpers.command, helpers.command,
helpers.nvim,
helpers.exc_exec, helpers.exc_exec,
helpers.funcs, helpers.funcs,
helpers.feed, helpers.feed
helpers.curbuf
local neq = helpers.neq local neq = helpers.neq
local read_file = helpers.read_file local read_file = helpers.read_file
@ -1581,7 +1579,7 @@ describe('autoload/shada.vim', function()
describe('function shada#strings_to_sd', function() describe('function shada#strings_to_sd', function()
local strings2sd_eq = function(expected, input) local strings2sd_eq = function(expected, input)
nvim('set_var', '__input', input) meths.nvim_set_var('__input', input)
nvim_command( nvim_command(
'let g:__actual = map(shada#strings_to_sd(g:__input), ' 'let g:__actual = map(shada#strings_to_sd(g:__input), '
.. '"filter(v:val, \\"v:key[0] isnot# \'_\' ' .. '"filter(v:val, \\"v:key[0] isnot# \'_\' '
@ -1589,7 +1587,7 @@ describe('autoload/shada.vim', function()
) )
-- print() -- print()
if type(expected) == 'table' then if type(expected) == 'table' then
nvim('set_var', '__expected', expected) meths.nvim_set_var('__expected', expected)
nvim_command('let g:__expected = ModifyVal(g:__expected)') nvim_command('let g:__expected = ModifyVal(g:__expected)')
expected = 'g:__expected' expected = 'g:__expected'
-- print(nvim_eval('msgpack#string(g:__expected)')) -- print(nvim_eval('msgpack#string(g:__expected)'))
@ -2534,7 +2532,7 @@ describe('autoload/shada.vim', function()
end end
it('works', function() it('works', function()
local version = nvim('get_vvar', 'version') local version = meths.nvim_get_vvar('version')
getbstrings_eq({ getbstrings_eq({
{ {
timestamp = 'current', timestamp = 'current',
@ -2560,7 +2558,7 @@ describe('autoload/shada.vim', function()
' % Key______ Value', ' % Key______ Value',
' + generator "test"', ' + generator "test"',
}) })
nvim('set_var', 'shada#add_own_header', 1) meths.nvim_set_var('shada#add_own_header', 1)
getbstrings_eq({ getbstrings_eq({
{ {
timestamp = 'current', timestamp = 'current',
@ -2586,14 +2584,14 @@ describe('autoload/shada.vim', function()
' % Key______ Value', ' % Key______ Value',
' + generator "test"', ' + generator "test"',
}) })
nvim('set_var', 'shada#add_own_header', 0) meths.nvim_set_var('shada#add_own_header', 0)
getbstrings_eq({}, {}) getbstrings_eq({}, {})
getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, { getbstrings_eq({ { timestamp = 0, type = 1, value = { generator = 'test' } } }, {
'Header with timestamp ' .. epoch .. ':', 'Header with timestamp ' .. epoch .. ':',
' % Key______ Value', ' % Key______ Value',
' + generator "test"', ' + generator "test"',
}) })
nvim('set_var', 'shada#keep_old_header', 0) meths.nvim_set_var('shada#keep_old_header', 0)
getbstrings_eq({}, { getbstrings_eq({}, {
'Header with timestamp ' .. epoch .. ':', 'Header with timestamp ' .. epoch .. ':',
' % Key______ Value', ' % Key______ Value',
@ -2661,8 +2659,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, nvim('get_option_value', 'modified', {})) eq(false, meths.nvim_get_option_value('modified', {}))
eq('shada', nvim('get_option_value', 'filetype', {})) eq('shada', meths.nvim_get_option_value('filetype', {}))
nvim_command('edit ' .. fname_tmp) nvim_command('edit ' .. fname_tmp)
eq({ eq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
@ -2671,8 +2669,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, nvim('get_option_value', 'modified', {})) eq(false, meths.nvim_get_option_value('modified', {}))
eq('shada', nvim('get_option_value', 'filetype', {})) eq('shada', meths.nvim_get_option_value('filetype', {}))
eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
neq({ neq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
@ -2681,7 +2679,7 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, nvim('get_option_value', 'modified', {})) neq(true, meths.nvim_get_option_value('modified', {}))
end) end)
it('event FileReadCmd', function() it('event FileReadCmd', function()
@ -2697,8 +2695,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, nvim('get_option_value', 'modified', {})) eq(true, meths.nvim_get_option_value('modified', {}))
neq('shada', nvim('get_option_value', 'filetype', {})) neq('shada', meths.nvim_get_option_value('filetype', {}))
nvim_command('1,$read ' .. fname_tmp) nvim_command('1,$read ' .. fname_tmp)
eq({ eq({
'', '',
@ -2713,9 +2711,9 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, nvim('get_option_value', 'modified', {})) eq(true, meths.nvim_get_option_value('modified', {}))
neq('shada', nvim('get_option_value', 'filetype', {})) neq('shada', meths.nvim_get_option_value('filetype', {}))
nvim('set_option_value', 'modified', false, {}) meths.nvim_set_option_value('modified', false, {})
eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
eq({ eq({
'', '',
@ -2730,13 +2728,13 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, nvim('get_option_value', 'modified', {})) neq(true, meths.nvim_get_option_value('modified', {}))
end) end)
it('event BufWriteCmd', function() it('event BufWriteCmd', function()
reset() reset()
nvim('set_var', 'shada#add_own_header', 0) meths.nvim_set_var('shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { meths.nvim_buf_set_lines(0, 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
" + n name 'A'", " + n name 'A'",
@ -2796,8 +2794,8 @@ describe('plugin/shada.vim', function()
it('event FileWriteCmd', function() it('event FileWriteCmd', function()
reset() reset()
nvim('set_var', 'shada#add_own_header', 0) meths.nvim_set_var('shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { meths.nvim_buf_set_lines(0, 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
" + n name 'A'", " + n name 'A'",
@ -2840,8 +2838,8 @@ describe('plugin/shada.vim', function()
it('event FileAppendCmd', function() it('event FileAppendCmd', function()
reset() reset()
nvim('set_var', 'shada#add_own_header', 0) meths.nvim_set_var('shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { meths.nvim_buf_set_lines(0, 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
" + n name 'A'", " + n name 'A'",
@ -3017,10 +3015,10 @@ describe('ftplugin/shada.vim', function()
it('sets options correctly', function() it('sets options correctly', function()
nvim_command('filetype plugin indent on') nvim_command('filetype plugin indent on')
nvim_command('setlocal filetype=shada') nvim_command('setlocal filetype=shada')
eq(true, nvim('get_option_value', 'expandtab', {})) eq(true, meths.nvim_get_option_value('expandtab', {}))
eq(2, nvim('get_option_value', 'tabstop', {})) eq(2, meths.nvim_get_option_value('tabstop', {}))
eq(2, nvim('get_option_value', 'softtabstop', {})) eq(2, meths.nvim_get_option_value('softtabstop', {}))
eq(2, nvim('get_option_value', 'shiftwidth', {})) eq(2, meths.nvim_get_option_value('shiftwidth', {}))
end) end)
it('sets indentkeys correctly', function() it('sets indentkeys correctly', function()
@ -3028,17 +3026,17 @@ describe('ftplugin/shada.vim', function()
nvim_command('setlocal filetype=shada') nvim_command('setlocal filetype=shada')
funcs.setline(1, ' Replacement with timestamp ' .. epoch) funcs.setline(1, ' Replacement with timestamp ' .. epoch)
nvim_feed('ggA:\027') nvim_feed('ggA:\027')
eq('Replacement with timestamp ' .. epoch .. ':', curbuf('get_lines', 0, 1, true)[1]) eq('Replacement with timestamp ' .. epoch .. ':', meths.nvim_buf_get_lines(0, 0, 1, true)[1])
nvim_feed('o-\027') nvim_feed('o-\027')
eq({ ' -' }, curbuf('get_lines', 1, 2, true)) eq({ ' -' }, meths.nvim_buf_get_lines(0, 1, 2, true))
nvim_feed('ggO+\027') nvim_feed('ggO+\027')
eq({ '+' }, curbuf('get_lines', 0, 1, true)) eq({ '+' }, meths.nvim_buf_get_lines(0, 0, 1, true))
nvim_feed('GO*\027') nvim_feed('GO*\027')
eq({ ' *' }, curbuf('get_lines', 2, 3, true)) eq({ ' *' }, meths.nvim_buf_get_lines(0, 2, 3, true))
nvim_feed('ggO /\027') nvim_feed('ggO /\027')
eq({ ' /' }, curbuf('get_lines', 0, 1, true)) eq({ ' /' }, meths.nvim_buf_get_lines(0, 0, 1, true))
nvim_feed('ggOx\027') nvim_feed('ggOx\027')
eq({ 'x' }, curbuf('get_lines', 0, 1, true)) eq({ 'x' }, meths.nvim_buf_get_lines(0, 0, 1, true))
end) end)
end) end)
@ -3063,7 +3061,7 @@ describe('syntax/shada.vim', function()
} }
screen:attach() screen:attach()
curbuf('set_lines', 0, 1, true, { meths.nvim_buf_set_lines(0, 0, 1, true, {
'Header with timestamp ' .. epoch .. ':', 'Header with timestamp ' .. epoch .. ':',
' % Key Value', ' % Key Value',
' + t "test"', ' + t "test"',

View File

@ -1,7 +1,8 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local eval, command, nvim = helpers.eval, helpers.command, helpers.nvim local eval, command = helpers.eval, helpers.command
local eq, run, stop = helpers.eq, helpers.run, helpers.stop local eq, run, stop = helpers.eq, helpers.run, helpers.stop
local clear = helpers.clear local clear = helpers.clear
local meths = helpers.meths
local function get_prefix(sync) local function get_prefix(sync)
if sync then if sync then
@ -361,7 +362,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init)
end end
local function channel() local function channel()
return nvim('get_api_info')[1] return meths.nvim_get_api_info()[1]
end end
local function host() local function host()

View File

@ -1,7 +1,6 @@
-- shada buffer list saving/reading support -- shada buffer list saving/reading support
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq, curbufmeths, meths = local nvim_command, funcs, eq, meths = helpers.command, helpers.funcs, helpers.eq, helpers.meths
helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers') local shada_helpers = require('test.functional.shada.helpers')
@ -70,9 +69,9 @@ describe('shada support code', function()
it('does not dump unnamed buffers', function() it('does not dump unnamed buffers', function()
reset('set shada+=% hidden') reset('set shada+=% hidden')
curbufmeths.set_lines(0, 1, true, { 'foo' }) meths.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
nvim_command('enew') nvim_command('enew')
curbufmeths.set_lines(0, 1, true, { 'bar' }) meths.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
eq(2, funcs.bufnr('$')) eq(2, funcs.bufnr('$'))
expect_exit(nvim_command, 'qall!') expect_exit(nvim_command, 'qall!')
reset('set shada+=% hidden') reset('set shada+=% hidden')

View File

@ -1,12 +1,6 @@
-- ShaDa marks saving/reading support -- ShaDa marks saving/reading support
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq = local meths, nvim_command, funcs, eq = helpers.meths, helpers.command, helpers.funcs, helpers.eq
helpers.meths,
helpers.curwinmeths,
helpers.curbufmeths,
helpers.command,
helpers.funcs,
helpers.eq
local feed = helpers.feed local feed = helpers.feed
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
@ -15,7 +9,7 @@ local shada_helpers = require('test.functional.shada.helpers')
local reset, clear = shada_helpers.reset, shada_helpers.clear local reset, clear = shada_helpers.reset, shada_helpers.clear
local nvim_current_line = function() local nvim_current_line = function()
return curwinmeths.get_cursor()[1] return meths.nvim_win_get_cursor(0)[1]
end end
describe('ShaDa support code', function() describe('ShaDa support code', function()
@ -49,7 +43,7 @@ describe('ShaDa support code', function()
reset() reset()
nvim_command('rshada') nvim_command('rshada')
nvim_command('normal! `A') nvim_command('normal! `A')
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line()) eq(1, nvim_current_line())
nvim_command('normal! `B') nvim_command('normal! `B')
eq(2, nvim_current_line()) eq(2, nvim_current_line())
@ -76,7 +70,7 @@ describe('ShaDa support code', function()
reset("set shada='0,f0") reset("set shada='0,f0")
nvim_command('language C') nvim_command('language C')
nvim_command('normal! `A') nvim_command('normal! `A')
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line()) eq(1, nvim_current_line())
end) end)
@ -89,7 +83,7 @@ describe('ShaDa support code', function()
reset() reset()
nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename)
nvim_command('normal! `a') nvim_command('normal! `a')
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq(testfilename, funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(1, nvim_current_line()) eq(1, nvim_current_line())
nvim_command('normal! `b') nvim_command('normal! `b')
eq(2, nvim_current_line()) eq(2, nvim_current_line())
@ -119,9 +113,9 @@ describe('ShaDa support code', function()
it('is able to populate v:oldfiles', function() it('is able to populate v:oldfiles', function()
nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename)
local tf_full = curbufmeths.get_name() local tf_full = meths.nvim_buf_get_name(0)
nvim_command('edit ' .. testfilename_2) nvim_command('edit ' .. testfilename_2)
local tf_full_2 = curbufmeths.get_name() local tf_full_2 = meths.nvim_buf_get_name(0)
expect_exit(nvim_command, 'qall') expect_exit(nvim_command, 'qall')
reset() reset()
local oldfiles = meths.nvim_get_vvar('oldfiles') local oldfiles = meths.nvim_get_vvar('oldfiles')
@ -166,7 +160,7 @@ describe('ShaDa support code', function()
nvim_command('rshada') nvim_command('rshada')
nvim_command('normal! \15') -- <C-o> nvim_command('normal! \15') -- <C-o>
eq(testfilename_2, funcs.bufname('%')) eq(testfilename_2, funcs.bufname('%'))
eq({ 2, 0 }, curwinmeths.get_cursor()) eq({ 2, 0 }, meths.nvim_win_get_cursor(0))
end) end)
it('is able to dump and restore jump list with different times (slow!)', function() it('is able to dump and restore jump list with different times (slow!)', function()

View File

@ -1,8 +1,8 @@
-- ShaDa merging data support -- ShaDa merging data support
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, curbufmeths, eq = local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq
helpers.command, helpers.funcs, helpers.curbufmeths, helpers.eq
local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture local exc_exec, exec_capture = helpers.exc_exec, helpers.exec_capture
local meths = helpers.meths
local shada_helpers = require('test.functional.shada.helpers') local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw = local reset, clear, get_shada_rw =
@ -492,14 +492,14 @@ describe('ShaDa marks support code', function()
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
nvim_command('normal! `A') nvim_command('normal! `A')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
end) end)
it('can merge with file with mark 9 as the only numeric mark', function() it('can merge with file with mark 9 as the only numeric mark', function()
wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9') wshada('\007\001\014\130\161f\196\006' .. mock_file_path .. '-\161n9')
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
nvim_command('normal! `9oabc') nvim_command('normal! `9oabc')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname)) eq(0, exc_exec('wshada ' .. shada_fname))
local found = {} local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do for _, v in ipairs(read_shada_file(shada_fname)) do
@ -632,7 +632,7 @@ describe('ShaDa marks support code', function()
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd(true))) eq(0, exc_exec(sdrcmd(true)))
nvim_command('normal! `A') nvim_command('normal! `A')
eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('?', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
end) end)
it('uses last A mark with eq timestamp from instance when reading', function() it('uses last A mark with eq timestamp from instance when reading', function()
@ -641,7 +641,7 @@ describe('ShaDa marks support code', function()
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
nvim_command('normal! `A') nvim_command('normal! `A')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
end) end)
it('uses last A mark with gt timestamp from file when reading', function() it('uses last A mark with gt timestamp from file when reading', function()
@ -650,7 +650,7 @@ describe('ShaDa marks support code', function()
wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
nvim_command('normal! `A') nvim_command('normal! `A')
eq('?', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('?', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
end) end)
it('uses last A mark with gt timestamp from instance when writing', function() it('uses last A mark with gt timestamp from instance when writing', function()
@ -658,7 +658,7 @@ describe('ShaDa marks support code', function()
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\000\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A') nvim_command('normal! `A')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname)) eq(0, exc_exec('wshada ' .. shada_fname))
local found = {} local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do for _, v in ipairs(read_shada_file(shada_fname)) do
@ -675,7 +675,7 @@ describe('ShaDa marks support code', function()
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\001\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A') nvim_command('normal! `A')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname)) eq(0, exc_exec('wshada ' .. shada_fname))
local found = {} local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do for _, v in ipairs(read_shada_file(shada_fname)) do
@ -692,7 +692,7 @@ describe('ShaDa marks support code', function()
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA') wshada('\007\002\018\131\162mX\195\161f\196\006' .. mock_file_path .. '?\161nA')
nvim_command('normal! `A') nvim_command('normal! `A')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname)) eq(0, exc_exec('wshada ' .. shada_fname))
local found = {} local found = {}
for _, v in ipairs(read_shada_file(shada_fname)) do for _, v in ipairs(read_shada_file(shada_fname)) do
@ -803,7 +803,7 @@ describe('ShaDa marks support code', function()
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na') wshada('\010\002\017\131\161l\002\161f\196\006' .. mock_file_path .. '-\161na')
nvim_command('normal! `a') nvim_command('normal! `a')
eq('-', funcs.fnamemodify(curbufmeths.get_name(), ':t')) eq('-', funcs.fnamemodify(meths.nvim_buf_get_name(0), ':t'))
eq(0, exc_exec('wshada ' .. shada_fname)) eq(0, exc_exec('wshada ' .. shada_fname))
local found = 0 local found = 0
for _, v in ipairs(read_shada_file(shada_fname)) do for _, v in ipairs(read_shada_file(shada_fname)) do
@ -940,7 +940,7 @@ describe('ShaDa jumps support code', function()
.. 'f\161l\002' .. 'f\161l\002'
) )
eq(0, exc_exec(sdrcmd())) eq(0, exc_exec(sdrcmd()))
eq('', curbufmeths.get_name()) eq('', meths.nvim_buf_get_name(0))
eq( eq(
' jump line col file/text\n' ' jump line col file/text\n'
.. ' 5 2 0 ' .. ' 5 2 0 '

View File

@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local clear, eq, meths = helpers.clear, helpers.eq, helpers.meths
local feed = helpers.feed local feed = helpers.feed
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local enter_altscreen = thelpers.enter_altscreen local enter_altscreen = thelpers.enter_altscreen
@ -42,7 +42,7 @@ describe(':terminal altscreen', function()
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(10, curbuf('line_count')) eq(10, meths.nvim_buf_line_count(0))
end) end)
it('wont clear lines already in the scrollback', function() it('wont clear lines already in the scrollback', function()
@ -107,7 +107,7 @@ describe(':terminal altscreen', function()
end) end)
it('wont modify line count', function() it('wont modify line count', function()
eq(10, curbuf('line_count')) eq(10, meths.nvim_buf_line_count(0))
end) end)
it('wont modify lines in the scrollback', function() it('wont modify lines in the scrollback', function()
@ -144,7 +144,7 @@ describe(':terminal altscreen', function()
rows: 4, cols: 50 | rows: 4, cols: 50 |
| |
]]) ]])
eq(9, curbuf('line_count')) eq(9, meths.nvim_buf_line_count(0))
end) end)
describe('and after exit', function() describe('and after exit', function()

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local feed, clear = helpers.feed, helpers.clear
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
@ -92,12 +92,12 @@ describe(':terminal buffer', function()
end) end)
it('does not create swap files', function() it('does not create swap files', function()
local swapfile = nvim('exec', 'swapname', true):gsub('\n', '') local swapfile = meths.nvim_exec('swapname', true):gsub('\n', '')
eq(nil, io.open(swapfile)) eq(nil, io.open(swapfile))
end) end)
it('does not create undofiles files', function() it('does not create undofiles files', function()
local undofile = nvim('eval', 'undofile(bufname("%"))') local undofile = meths.nvim_eval('undofile(bufname("%"))')
eq(nil, io.open(undofile)) eq(nil, io.open(undofile))
end) end)
end) end)
@ -172,7 +172,7 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function() it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies. -- Change the statusline to avoid printing the file name, which varies.
nvim('set_option_value', 'statusline', '==========', {}) meths.nvim_set_option_value('statusline', '==========', {})
-- Save the buffer number of the terminal for later testing. -- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")') local tbuf = eval('bufnr("%")')

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local feed, clear = helpers.feed, helpers.clear
local testprg, command = helpers.testprg, helpers.command local testprg, command = helpers.testprg, helpers.command
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local matches = helpers.matches local matches = helpers.matches
@ -118,8 +118,8 @@ describe('cursor with customized highlighting', function()
before_each(function() before_each(function()
clear() clear()
nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE') command('highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE')
nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE') command('highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE')
screen = Screen.new(50, 7) screen = Screen.new(50, 7)
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = { foreground = 45, background = 46 }, [1] = { foreground = 45, background = 46 },

View File

@ -1,8 +1,6 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local screen = require('test.functional.ui.screen') local screen = require('test.functional.ui.screen')
local curbufmeths = helpers.curbufmeths
local curwinmeths = helpers.curwinmeths
local testprg = helpers.testprg local testprg = helpers.testprg
local command = helpers.command local command = helpers.command
local funcs = helpers.funcs local funcs = helpers.funcs
@ -48,7 +46,7 @@ describe(':edit term://*', function()
command('edit term://foobar') command('edit term://foobar')
local bufcontents = {} local bufcontents = {}
local winheight = curwinmeths.get_height() local winheight = meths.nvim_win_get_height(0)
local buf_cont_start = rep - sb - winheight + 2 local buf_cont_start = rep - sb - winheight + 2
for i = buf_cont_start, (rep - 1) do for i = buf_cont_start, (rep - 1) do
bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i) bufcontents[#bufcontents + 1] = ('%d: foobar'):format(i)
@ -65,6 +63,6 @@ describe(':edit term://*', function()
exp_screen = exp_screen .. (' '):rep(columns) .. '|\n' exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
scr:expect(exp_screen) scr:expect(exp_screen)
eq(bufcontents, curbufmeths.get_lines(0, -1, true)) eq(bufcontents, meths.nvim_buf_get_lines(0, 0, -1, true))
end) end)
end) end)

View File

@ -1,11 +1,12 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local clear, poke_eventloop, nvim = helpers.clear, helpers.poke_eventloop, helpers.nvim local clear, poke_eventloop = helpers.clear, helpers.poke_eventloop
local testprg, source, eq = helpers.testprg, helpers.source, helpers.eq local testprg, source, eq = helpers.testprg, helpers.source, helpers.eq
local feed = helpers.feed local feed = helpers.feed
local feed_command, eval = helpers.feed_command, helpers.eval local feed_command, eval = helpers.feed_command, helpers.eval
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths
local retry = helpers.retry local retry = helpers.retry
local ok = helpers.ok local ok = helpers.ok
local command = helpers.command local command = helpers.command
@ -104,30 +105,30 @@ describe(':terminal', function()
it('nvim_get_mode() in :terminal', function() it('nvim_get_mode() in :terminal', function()
command('terminal') command('terminal')
eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode())
feed('i') feed('i')
eq({ blocking = false, mode = 't' }, nvim('get_mode')) eq({ blocking = false, mode = 't' }, meths.nvim_get_mode())
feed([[<C-\><C-N>]]) feed([[<C-\><C-N>]])
eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode())
end) end)
it(':stopinsert RPC request exits terminal-mode #7807', function() it(':stopinsert RPC request exits terminal-mode #7807', function()
command('terminal') command('terminal')
feed('i[tui] insert-mode') feed('i[tui] insert-mode')
eq({ blocking = false, mode = 't' }, nvim('get_mode')) eq({ blocking = false, mode = 't' }, meths.nvim_get_mode())
command('stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode())
end) end)
it(":stopinsert in normal mode doesn't break insert mode #9889", function() it(":stopinsert in normal mode doesn't break insert mode #9889", function()
command('terminal') command('terminal')
eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode())
command('stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking = false, mode = 'nt' }, nvim('get_mode')) eq({ blocking = false, mode = 'nt' }, meths.nvim_get_mode())
feed('a') feed('a')
eq({ blocking = false, mode = 't' }, nvim('get_mode')) eq({ blocking = false, mode = 't' }, meths.nvim_get_mode())
end) end)
it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function() it('switching to terminal buffer in Insert mode goes to Terminal mode #7164', function()
@ -138,9 +139,9 @@ describe(':terminal', function()
command('autocmd InsertLeave * let g:events += ["InsertLeave"]') command('autocmd InsertLeave * let g:events += ["InsertLeave"]')
command('autocmd TermEnter * let g:events += ["TermEnter"]') command('autocmd TermEnter * let g:events += ["TermEnter"]')
command('inoremap <F2> <Cmd>wincmd p<CR>') command('inoremap <F2> <Cmd>wincmd p<CR>')
eq({ blocking = false, mode = 'i' }, nvim('get_mode')) eq({ blocking = false, mode = 'i' }, meths.nvim_get_mode())
feed('<F2>') feed('<F2>')
eq({ blocking = false, mode = 't' }, nvim('get_mode')) eq({ blocking = false, mode = 't' }, meths.nvim_get_mode())
eq({ 'InsertLeave', 'TermEnter' }, eval('g:events')) eq({ 'InsertLeave', 'TermEnter' }, eval('g:events'))
end) end)
end) end)
@ -158,9 +159,9 @@ local function test_terminal_with_fake_shell(backslash)
clear() clear()
screen = Screen.new(50, 4) screen = Screen.new(50, 4)
screen:attach({ rgb = false }) screen:attach({ rgb = false })
nvim('set_option_value', 'shell', shell_path, {}) meths.nvim_set_option_value('shell', shell_path, {})
nvim('set_option_value', 'shellcmdflag', 'EXE', {}) meths.nvim_set_option_value('shellcmdflag', 'EXE', {})
nvim('set_option_value', 'shellxquote', '', {}) meths.nvim_set_option_value('shellxquote', '', {})
end) end)
it('with no argument, acts like termopen()', function() it('with no argument, acts like termopen()', function()
@ -177,7 +178,7 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it("with no argument, and 'shell' is set to empty string", function() it("with no argument, and 'shell' is set to empty string", function()
nvim('set_option_value', 'shell', '', {}) meths.nvim_set_option_value('shell', '', {})
feed_command('terminal') feed_command('terminal')
screen:expect([[ screen:expect([[
^ | ^ |
@ -187,7 +188,7 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it("with no argument, but 'shell' has arguments, acts like termopen()", function() it("with no argument, but 'shell' has arguments, acts like termopen()", function()
nvim('set_option_value', 'shell', shell_path .. ' INTERACT', {}) meths.nvim_set_option_value('shell', shell_path .. ' INTERACT', {})
feed_command('terminal') feed_command('terminal')
screen:expect([[ screen:expect([[
^interact $ | ^interact $ |
@ -208,7 +209,7 @@ local function test_terminal_with_fake_shell(backslash)
end) end)
it("executes a given command through the shell, when 'shell' has arguments", function() it("executes a given command through the shell, when 'shell' has arguments", function()
nvim('set_option_value', 'shell', shell_path .. ' -t jeff', {}) meths.nvim_set_option_value('shell', shell_path .. ' -t jeff', {})
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
feed_command('terminal echo hi') feed_command('terminal echo hi')
screen:expect([[ screen:expect([[

View File

@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local testprg = helpers.testprg local testprg = helpers.testprg
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local nvim = helpers.nvim local meths = helpers.meths
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local function feed_data(data) local function feed_data(data)
@ -89,8 +89,8 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts)
command = command and command or default_command command = command and command or default_command
cols = cols and cols or 50 cols = cols and cols or 50
nvim('command', 'highlight TermCursor cterm=reverse') meths.nvim_command('highlight TermCursor cterm=reverse')
nvim('command', 'highlight TermCursorNC ctermbg=11') meths.nvim_command('highlight TermCursorNC ctermbg=11')
local screen = Screen.new(cols, 7 + extra_rows) local screen = Screen.new(cols, 7 + extra_rows)
screen:set_default_attr_ids({ screen:set_default_attr_ids({
@ -113,17 +113,17 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts)
screen:attach(screen_opts or { rgb = false }) screen:attach(screen_opts or { rgb = false })
nvim('command', 'enew') meths.nvim_command('enew')
nvim('call_function', 'termopen', { command, env and { env = env } or nil }) meths.nvim_call_function('termopen', { command, env and { env = env } or nil })
nvim('input', '<CR>') meths.nvim_input('<CR>')
local vim_errmsg = nvim('eval', 'v:errmsg') local vim_errmsg = meths.nvim_eval('v:errmsg')
if vim_errmsg and '' ~= vim_errmsg then if vim_errmsg and '' ~= vim_errmsg then
error(vim_errmsg) error(vim_errmsg)
end end
nvim('command', 'setlocal scrollback=10') meths.nvim_command('setlocal scrollback=10')
nvim('command', 'startinsert') meths.nvim_command('startinsert')
nvim('input', '<Ignore>') -- Add input to separate two RPC requests meths.nvim_input('<Ignore>') -- Add input to separate two RPC requests
-- tty-test puts the terminal into raw mode and echoes input. Tests work by -- tty-test puts the terminal into raw mode and echoes input. Tests work by
-- feeding termcodes to control the display and asserting by screen:expect. -- feeding termcodes to control the display and asserting by screen:expect.
@ -147,7 +147,7 @@ local function screen_setup(extra_rows, command, cols, env, screen_opts)
screen:expect(table.concat(expected, '|\n') .. '|') screen:expect(table.concat(expected, '|\n') .. '|')
else else
-- This eval also acts as a poke_eventloop(). -- This eval also acts as a poke_eventloop().
if 0 == nvim('eval', "exists('b:terminal_job_id')") then if 0 == meths.nvim_eval("exists('b:terminal_job_id')") then
error('terminal job failed to start') error('terminal job failed to start')
end end
end end

View File

@ -1,7 +1,8 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local feed, clear = helpers.feed, helpers.clear
local meths = helpers.meths
local testprg, command = helpers.testprg, helpers.command local testprg, command = helpers.testprg, helpers.command
local nvim_prog_abs = helpers.nvim_prog_abs local nvim_prog_abs = helpers.nvim_prog_abs
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
@ -250,7 +251,7 @@ describe(':terminal highlight with custom palette', function()
[9] = { bold = true }, [9] = { bold = true },
}) })
screen:attach({ rgb = true }) screen:attach({ rgb = true })
nvim('set_var', 'terminal_color_3', '#123456') meths.nvim_set_var('terminal_color_3', '#123456')
command(("enew | call termopen(['%s'])"):format(testprg('tty-test'))) command(("enew | call termopen(['%s'])"):format(testprg('tty-test')))
feed('i') feed('i')
screen:expect([[ screen:expect([[

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval
local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command local feed, meths, command = helpers.feed, helpers.meths, helpers.command
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local is_os = helpers.is_os local is_os = helpers.is_os
local skip = helpers.skip local skip = helpers.skip
@ -11,7 +11,7 @@ describe(':terminal mouse', function()
before_each(function() before_each(function()
clear() clear()
nvim('set_option_value', 'statusline', '==========', {}) meths.nvim_set_option_value('statusline', '==========', {})
command('highlight StatusLine cterm=NONE') command('highlight StatusLine cterm=NONE')
command('highlight StatusLineNC cterm=NONE') command('highlight StatusLineNC cterm=NONE')
command('highlight VertSplit cterm=NONE') command('highlight VertSplit cterm=NONE')
@ -514,7 +514,7 @@ describe(':terminal mouse', function()
end) end)
it('handles terminal size when switching buffers', function() it('handles terminal size when switching buffers', function()
nvim('set_option_value', 'hidden', true, {}) meths.nvim_set_option_value('hidden', true, {})
feed('<c-\\><c-n><c-w><c-w>') feed('<c-\\><c-n><c-w><c-w>')
screen:expect([[ screen:expect([[
{7: 27 }line line30 | {7: 27 }line line30 |

View File

@ -1,14 +1,13 @@
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local clear, eq = helpers.clear, helpers.eq
local feed, testprg = helpers.feed, helpers.testprg local feed, testprg = helpers.feed, helpers.testprg
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local retry = helpers.retry local retry = helpers.retry
local meths = helpers.meths local meths = helpers.meths
local nvim = helpers.nvim
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
@ -86,7 +85,7 @@ describe(':terminal scrollback', function()
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(7, curbuf('line_count')) eq(7, meths.nvim_buf_line_count(0))
end) end)
describe('and then 3 more lines are printed', function() describe('and then 3 more lines are printed', function()
@ -170,7 +169,7 @@ describe(':terminal scrollback', function()
{2:^ } | {2:^ } |
| |
]]) ]])
eq(8, curbuf('line_count')) eq(8, meths.nvim_buf_line_count(0))
feed([[3k]]) feed([[3k]])
screen:expect([[ screen:expect([[
^line4 | ^line4 |
@ -204,7 +203,7 @@ describe(':terminal scrollback', function()
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(4, curbuf('line_count')) eq(4, meths.nvim_buf_line_count(0))
end end
it('will delete the last two empty lines', will_delete_last_two_lines) it('will delete the last two empty lines', will_delete_last_two_lines)
@ -222,7 +221,7 @@ describe(':terminal scrollback', function()
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(4, curbuf('line_count')) eq(4, meths.nvim_buf_line_count(0))
feed('<c-\\><c-n>gg') feed('<c-\\><c-n>gg')
screen:expect([[ screen:expect([[
^tty ready | ^tty ready |
@ -261,7 +260,7 @@ describe(':terminal scrollback', function()
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(7, curbuf('line_count')) eq(7, meths.nvim_buf_line_count(0))
end) end)
describe('and the height is increased by 1', function() describe('and the height is increased by 1', function()
@ -287,7 +286,7 @@ describe(':terminal scrollback', function()
describe('and then by 3', function() describe('and then by 3', function()
before_each(function() before_each(function()
pop_then_push() pop_then_push()
eq(8, curbuf('line_count')) eq(8, meths.nvim_buf_line_count(0))
screen:try_resize(screen._width, screen._height + 3) screen:try_resize(screen._width, screen._height + 3)
end) end)
@ -302,7 +301,7 @@ describe(':terminal scrollback', function()
{1: } | {1: } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq(9, curbuf('line_count')) eq(9, meths.nvim_buf_line_count(0))
feed('<c-\\><c-n>gg') feed('<c-\\><c-n>gg')
screen:expect([[ screen:expect([[
^tty ready | ^tty ready |
@ -342,7 +341,7 @@ describe(':terminal scrollback', function()
]]) ]])
-- since there's an empty line after the cursor, the buffer line -- since there's an empty line after the cursor, the buffer line
-- count equals the terminal screen height -- count equals the terminal screen height
eq(11, curbuf('line_count')) eq(11, meths.nvim_buf_line_count(0))
end) end)
end) end)
end) end)
@ -381,7 +380,7 @@ describe("'scrollback' option", function()
end) end)
local function set_fake_shell() local function set_fake_shell()
nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) meths.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
end end
local function expect_lines(expected, epsilon) local function expect_lines(expected, epsilon)

View File

@ -772,7 +772,7 @@ describe('treesitter highlighting (help)', function()
]], ]],
} }
helpers.curbufmeths.set_text(0, 1, 0, 5, { 'lua' }) helpers.meths.nvim_buf_set_text(0, 0, 1, 0, 5, { 'lua' })
screen:expect { screen:expect {
grid = [[ grid = [[
@ -785,7 +785,7 @@ describe('treesitter highlighting (help)', function()
]], ]],
} }
helpers.curbufmeths.set_text(0, 1, 0, 4, { 'ruby' }) helpers.meths.nvim_buf_set_text(0, 0, 1, 0, 4, { 'ruby' })
screen:expect { screen:expect {
grid = [[ grid = [[

View File

@ -4,8 +4,9 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local command, neq = helpers.command, helpers.neq local command, neq = helpers.command, helpers.neq
local meths = helpers.meths local meths = helpers.meths
local curbufmeths, eq = helpers.curbufmeths, helpers.eq local eq = helpers.eq
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local set_virtual_text = meths.nvim_buf_set_virtual_text
describe('Buffer highlighting', function() describe('Buffer highlighting', function()
local screen local screen
@ -39,8 +40,8 @@ describe('Buffer highlighting', function()
}) })
end) end)
local add_highlight = curbufmeths.add_highlight local add_highlight = meths.nvim_buf_add_highlight
local clear_namespace = curbufmeths.clear_namespace local clear_namespace = meths.nvim_buf_clear_namespace
it('works', function() it('works', function()
insert([[ insert([[
@ -55,8 +56,8 @@ describe('Buffer highlighting', function()
| |
]]) ]])
add_highlight(-1, 'String', 0, 10, 14) add_highlight(0, -1, 'String', 0, 10, 14)
add_highlight(-1, 'Statement', 1, 5, -1) add_highlight(0, -1, 'Statement', 1, 5, -1)
screen:expect([[ screen:expect([[
these are {2:some} lines | these are {2:some} lines |
@ -74,7 +75,7 @@ describe('Buffer highlighting', function()
| |
]]) ]])
clear_namespace(-1, 0, -1) clear_namespace(0, -1, 0, -1)
screen:expect([[ screen:expect([[
these are some lines | these are some lines |
^ | ^ |
@ -94,21 +95,21 @@ describe('Buffer highlighting', function()
from different sources]]) from different sources]])
command('hi ImportantWord gui=bold cterm=bold') command('hi ImportantWord gui=bold cterm=bold')
id1 = add_highlight(0, 'ImportantWord', 0, 2, 8) id1 = add_highlight(0, 0, 'ImportantWord', 0, 2, 8)
add_highlight(id1, 'ImportantWord', 1, 12, -1) add_highlight(0, id1, 'ImportantWord', 1, 12, -1)
add_highlight(id1, 'ImportantWord', 2, 0, 9) add_highlight(0, id1, 'ImportantWord', 2, 0, 9)
add_highlight(id1, 'ImportantWord', 3, 5, 14) add_highlight(0, id1, 'ImportantWord', 3, 5, 14)
-- add_highlight can be called like this to get a new source -- add_highlight can be called like this to get a new source
-- without adding any highlight -- without adding any highlight
id2 = add_highlight(0, '', 0, 0, 0) id2 = add_highlight(0, 0, '', 0, 0, 0)
neq(id1, id2) neq(id1, id2)
add_highlight(id2, 'Special', 0, 2, 8) add_highlight(0, id2, 'Special', 0, 2, 8)
add_highlight(id2, 'Identifier', 1, 3, 8) add_highlight(0, id2, 'Identifier', 1, 3, 8)
add_highlight(id2, 'Special', 1, 14, 20) add_highlight(0, id2, 'Special', 1, 14, 20)
add_highlight(id2, 'Underlined', 2, 6, 12) add_highlight(0, id2, 'Underlined', 2, 6, 12)
add_highlight(id2, 'Underlined', 3, 0, 9) add_highlight(0, id2, 'Underlined', 3, 0, 9)
screen:expect([[ screen:expect([[
a {5:longer} example | a {5:longer} example |
@ -121,7 +122,7 @@ describe('Buffer highlighting', function()
end) end)
it('and clearing the first added', function() it('and clearing the first added', function()
clear_namespace(id1, 0, -1) clear_namespace(0, id1, 0, -1)
screen:expect([[ screen:expect([[
a {4:longer} example | a {4:longer} example |
in {6:order} to de{4:monstr}ate | in {6:order} to de{4:monstr}ate |
@ -133,7 +134,7 @@ describe('Buffer highlighting', function()
end) end)
it('and clearing using deprecated name', function() it('and clearing using deprecated name', function()
curbufmeths.clear_highlight(id1, 0, -1) meths.nvim_buf_clear_highlight(0, id1, 0, -1)
screen:expect([[ screen:expect([[
a {4:longer} example | a {4:longer} example |
in {6:order} to de{4:monstr}ate | in {6:order} to de{4:monstr}ate |
@ -145,7 +146,7 @@ describe('Buffer highlighting', function()
end) end)
it('and clearing the second added', function() it('and clearing the second added', function()
clear_namespace(id2, 0, -1) clear_namespace(0, id2, 0, -1)
screen:expect([[ screen:expect([[
a {7:longer} example | a {7:longer} example |
in order to {7:demonstrate} | in order to {7:demonstrate} |
@ -157,9 +158,9 @@ describe('Buffer highlighting', function()
end) end)
it('and clearing line ranges', function() it('and clearing line ranges', function()
clear_namespace(-1, 0, 1) clear_namespace(0, -1, 0, 1)
clear_namespace(id1, 1, 2) clear_namespace(0, id1, 1, 2)
clear_namespace(id2, 2, -1) clear_namespace(0, id2, 2, -1)
screen:expect([[ screen:expect([[
a longer example | a longer example |
in {6:order} to de{4:monstr}ate | in {6:order} to de{4:monstr}ate |
@ -449,9 +450,9 @@ describe('Buffer highlighting', function()
pending('prioritizes latest added highlight', function() pending('prioritizes latest added highlight', function()
insert([[ insert([[
three overlapping colors]]) three overlapping colors]])
add_highlight(0, 'Identifier', 0, 6, 17) add_highlight(0, 0, 'Identifier', 0, 6, 17)
add_highlight(0, 'String', 0, 14, 23) add_highlight(0, 0, 'String', 0, 14, 23)
local id = add_highlight(0, 'Special', 0, 0, 9) local id = add_highlight(0, 0, 'Special', 0, 0, 9)
screen:expect([[ screen:expect([[
{4:three ove}{6:rlapp}{2:ing color}^s | {4:three ove}{6:rlapp}{2:ing color}^s |
@ -459,7 +460,7 @@ describe('Buffer highlighting', function()
| |
]]) ]])
clear_namespace(id, 0, 1) clear_namespace(0, id, 0, 1)
screen:expect([[ screen:expect([[
three {6:overlapp}{2:ing color}^s | three {6:overlapp}{2:ing color}^s |
{1:~ }|*6 {1:~ }|*6
@ -470,9 +471,9 @@ describe('Buffer highlighting', function()
it('prioritizes earlier highlight groups (TEMP)', function() it('prioritizes earlier highlight groups (TEMP)', function()
insert([[ insert([[
three overlapping colors]]) three overlapping colors]])
add_highlight(0, 'Identifier', 0, 6, 17) add_highlight(0, 0, 'Identifier', 0, 6, 17)
add_highlight(0, 'String', 0, 14, 23) add_highlight(0, 0, 'String', 0, 14, 23)
local id = add_highlight(0, 'Special', 0, 0, 9) local id = add_highlight(0, 0, 'Special', 0, 0, 9)
screen:expect { screen:expect {
grid = [[ grid = [[
@ -482,7 +483,7 @@ describe('Buffer highlighting', function()
]], ]],
} }
clear_namespace(id, 0, 1) clear_namespace(0, id, 0, 1)
screen:expect { screen:expect {
grid = [[ grid = [[
three {6:overlapp}{2:ing color}^s | three {6:overlapp}{2:ing color}^s |
@ -493,17 +494,16 @@ describe('Buffer highlighting', function()
end) end)
it('respects priority', function() it('respects priority', function()
local set_extmark = curbufmeths.set_extmark
local id = meths.nvim_create_namespace('') local id = meths.nvim_create_namespace('')
insert [[foobar]] insert [[foobar]]
set_extmark(id, 0, 0, { meths.nvim_buf_set_extmark(0, id, 0, 0, {
end_line = 0, end_line = 0,
end_col = 5, end_col = 5,
hl_group = 'Statement', hl_group = 'Statement',
priority = 100, priority = 100,
}) })
set_extmark(id, 0, 0, { meths.nvim_buf_set_extmark(0, id, 0, 0, {
end_line = 0, end_line = 0,
end_col = 6, end_col = 6,
hl_group = 'String', hl_group = 'String',
@ -516,7 +516,7 @@ describe('Buffer highlighting', function()
| |
]] ]]
clear_namespace(id, 0, -1) clear_namespace(0, id, 0, -1)
screen:expect { screen:expect {
grid = [[ grid = [[
fooba^r | fooba^r |
@ -525,13 +525,13 @@ describe('Buffer highlighting', function()
]], ]],
} }
set_extmark(id, 0, 0, { meths.nvim_buf_set_extmark(0, id, 0, 0, {
end_line = 0, end_line = 0,
end_col = 6, end_col = 6,
hl_group = 'String', hl_group = 'String',
priority = 1, priority = 1,
}) })
set_extmark(id, 0, 0, { meths.nvim_buf_set_extmark(0, id, 0, 0, {
end_line = 0, end_line = 0,
end_col = 5, end_col = 5,
hl_group = 'Statement', hl_group = 'Statement',
@ -548,8 +548,8 @@ describe('Buffer highlighting', function()
it('works with multibyte text', function() it('works with multibyte text', function()
insert([[ insert([[
Ta båten över sjön!]]) Ta båten över sjön!]])
add_highlight(-1, 'Identifier', 0, 3, 9) add_highlight(0, -1, 'Identifier', 0, 3, 9)
add_highlight(-1, 'String', 0, 16, 21) add_highlight(0, -1, 'String', 0, 16, 21)
screen:expect([[ screen:expect([[
Ta {6:båten} över {2:sjön}^! | Ta {6:båten} över {2:sjön}^! |
@ -561,7 +561,7 @@ describe('Buffer highlighting', function()
it('works with new syntax groups', function() it('works with new syntax groups', function()
insert([[ insert([[
fancy code in a new fancy language]]) fancy code in a new fancy language]])
add_highlight(-1, 'FancyLangItem', 0, 0, 5) add_highlight(0, -1, 'FancyLangItem', 0, 0, 5)
screen:expect([[ screen:expect([[
fancy code in a new fancy languag^e | fancy code in a new fancy languag^e |
{1:~ }|*6 {1:~ }|*6
@ -577,7 +577,6 @@ describe('Buffer highlighting', function()
end) end)
describe('virtual text decorations', function() describe('virtual text decorations', function()
local set_virtual_text = curbufmeths.set_virtual_text
local id1, id2 local id1, id2
before_each(function() before_each(function()
insert([[ insert([[
@ -595,9 +594,9 @@ describe('Buffer highlighting', function()
| |
]]) ]])
id1 = set_virtual_text(0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {}) id1 = set_virtual_text(0, 0, 0, { { '=', 'Statement' }, { ' 3', 'Number' } }, {})
set_virtual_text(id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {}) set_virtual_text(0, id1, 1, { { 'ERROR:', 'ErrorMsg' }, { ' invalid syntax' } }, {})
id2 = set_virtual_text(0, 2, { id2 = set_virtual_text(0, 0, 2, {
{ {
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
}, },
@ -616,7 +615,7 @@ describe('Buffer highlighting', function()
| |
]]) ]])
clear_namespace(id1, 0, -1) clear_namespace(0, id1, 0, -1)
screen:expect([[ screen:expect([[
^1 + 2 | ^1 + 2 |
3 + | 3 + |
@ -632,6 +631,7 @@ describe('Buffer highlighting', function()
eq( eq(
-1, -1,
set_virtual_text( set_virtual_text(
0,
-1, -1,
1, 1,
{ { '暗x事zz速野谷質結育副住新覚丸活解終事', 'Comment' } }, { { '暗x事zz速野谷質結育副住新覚丸活解終事', 'Comment' } },
@ -687,22 +687,22 @@ describe('Buffer highlighting', function()
-- this used to leak memory -- this used to leak memory
eq( eq(
"Invalid 'chunk': expected Array, got String", "Invalid 'chunk': expected Array, got String",
pcall_err(set_virtual_text, id1, 0, { 'texty' }, {}) pcall_err(set_virtual_text, 0, id1, 0, { 'texty' }, {})
) )
eq( eq(
"Invalid 'chunk': expected Array, got String", "Invalid 'chunk': expected Array, got String",
pcall_err(set_virtual_text, id1, 0, { { 'very' }, 'texty' }, {}) pcall_err(set_virtual_text, 0, id1, 0, { { 'very' }, 'texty' }, {})
) )
end) end)
it('can be retrieved', function() it('can be retrieved', function()
local get_extmarks = curbufmeths.get_extmarks local get_extmarks = meths.nvim_buf_get_extmarks
local line_count = curbufmeths.line_count local line_count = meths.nvim_buf_line_count
local s1 = { { 'Köttbullar', 'Comment' }, { 'Kräuterbutter' } } local s1 = { { 'Köttbullar', 'Comment' }, { 'Kräuterbutter' } }
local s2 = { { 'こんにちは', 'Comment' } } local s2 = { { 'こんにちは', 'Comment' } }
set_virtual_text(id1, 0, s1, {}) set_virtual_text(0, id1, 0, s1, {})
eq({ eq({
{ {
1, 1,
@ -719,10 +719,10 @@ describe('Buffer highlighting', function()
virt_text_hide = false, virt_text_hide = false,
}, },
}, },
}, get_extmarks(id1, { 0, 0 }, { 0, -1 }, { details = true })) }, get_extmarks(0, id1, { 0, 0 }, { 0, -1 }, { details = true }))
local lastline = line_count() local lastline = line_count(0)
set_virtual_text(id1, line_count(), s2, {}) set_virtual_text(0, id1, line_count(0), s2, {})
eq({ eq({
{ {
3, 3,
@ -739,9 +739,9 @@ describe('Buffer highlighting', function()
virt_text_hide = false, virt_text_hide = false,
}, },
}, },
}, get_extmarks(id1, { lastline, 0 }, { lastline, -1 }, { details = true })) }, get_extmarks(0, id1, { lastline, 0 }, { lastline, -1 }, { details = true }))
eq({}, get_extmarks(id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {})) eq({}, get_extmarks(0, id1, { lastline + 9000, 0 }, { lastline + 9000, -1 }, {}))
end) end)
it('is not highlighted by visual selection', function() it('is not highlighted by visual selection', function()
@ -814,7 +814,7 @@ describe('Buffer highlighting', function()
| |
]]) ]])
clear_namespace(-1, 0, -1) clear_namespace(0, -1, 0, -1)
screen:expect([[ screen:expect([[
^1 + 2{1:$} | ^1 + 2{1:$} |
3 +{1:$} | 3 +{1:$} |
@ -869,7 +869,7 @@ describe('Buffer highlighting', function()
end) end)
it('works with color column', function() it('works with color column', function()
eq(-1, set_virtual_text(-1, 3, { { '暗x事', 'Comment' } }, {})) eq(-1, set_virtual_text(0, -1, 3, { { '暗x事', 'Comment' } }, {}))
screen:expect { screen:expect {
grid = [[ grid = [[
^1 + 2 {3:=}{2: 3} | ^1 + 2 {3:=}{2: 3} |
@ -898,12 +898,11 @@ describe('Buffer highlighting', function()
end) end)
it('and virtual text use the same namespace counter', function() it('and virtual text use the same namespace counter', function()
local set_virtual_text = curbufmeths.set_virtual_text eq(1, add_highlight(0, 0, 'String', 0, 0, -1))
eq(1, add_highlight(0, 'String', 0, 0, -1)) eq(2, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {}))
eq(2, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {}))
eq(3, meths.nvim_create_namespace('my-ns')) eq(3, meths.nvim_create_namespace('my-ns'))
eq(4, add_highlight(0, 'String', 0, 0, -1)) eq(4, add_highlight(0, 0, 'String', 0, 0, -1))
eq(5, set_virtual_text(0, 0, { { '= text', 'Comment' } }, {})) eq(5, set_virtual_text(0, 0, 0, { { '= text', 'Comment' } }, {}))
eq(6, meths.nvim_create_namespace('other-ns')) eq(6, meths.nvim_create_namespace('other-ns'))
end) end)
end) end)

View File

@ -10,7 +10,6 @@ local source = helpers.source
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local dedent = helpers.dedent local dedent = helpers.dedent
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local screen local screen
@ -503,7 +502,7 @@ describe('Command-line coloring', function()
]])) ]]))
eq( eq(
{ '', ':', 'E888 detected for \\ze*', ':', 'E888 detected for \\zs*' }, { '', ':', 'E888 detected for \\ze*', ':', 'E888 detected for \\zs*' },
curbufmeths.get_lines(0, -1, false) meths.nvim_buf_get_lines(0, 0, -1, false)
) )
eq('', funcs.execute('messages')) eq('', funcs.execute('messages'))
end) end)
@ -646,7 +645,7 @@ describe('Ex commands coloring', function()
]])) ]]))
eq( eq(
{ '', 'E888 detected for \\ze*', 'E888 detected for \\zs*' }, { '', 'E888 detected for \\ze*', 'E888 detected for \\zs*' },
curbufmeths.get_lines(0, -1, false) meths.nvim_buf_get_lines(0, 0, -1, false)
) )
eq('', funcs.execute('messages')) eq('', funcs.execute('messages'))
end) end)
@ -725,10 +724,10 @@ describe('Ex commands coloring', function()
end) end)
describe('Expressions coloring support', function() describe('Expressions coloring support', function()
it('works', function() it('works', function()
meths.nvim_command('hi clear NvimNumber') command('hi clear NvimNumber')
meths.nvim_command('hi clear NvimNestingParenthesis') command('hi clear NvimNestingParenthesis')
meths.nvim_command('hi NvimNumber guifg=Blue2') command('hi NvimNumber guifg=Blue2')
meths.nvim_command('hi NvimNestingParenthesis guifg=Yellow') command('hi NvimNestingParenthesis guifg=Yellow')
feed(':echo <C-r>=(((1)))') feed(':echo <C-r>=(((1)))')
screen:expect([[ screen:expect([[
| |
@ -739,8 +738,8 @@ describe('Expressions coloring support', function()
it('does not use Nvim_color_expr', function() it('does not use Nvim_color_expr', function()
meths.nvim_set_var('Nvim_color_expr', 42) meths.nvim_set_var('Nvim_color_expr', 42)
-- Used to error out due to failing to get callback. -- Used to error out due to failing to get callback.
meths.nvim_command('hi clear NvimNumber') command('hi clear NvimNumber')
meths.nvim_command('hi NvimNumber guifg=Blue2') command('hi NvimNumber guifg=Blue2')
feed(':<C-r>=1') feed(':<C-r>=1')
screen:expect([[ screen:expect([[
| |
@ -749,12 +748,12 @@ describe('Expressions coloring support', function()
]]) ]])
end) end)
it('works correctly with non-ASCII and control characters', function() it('works correctly with non-ASCII and control characters', function()
meths.nvim_command('hi clear NvimStringBody') command('hi clear NvimStringBody')
meths.nvim_command('hi clear NvimStringQuote') command('hi clear NvimStringQuote')
meths.nvim_command('hi clear NvimInvalid') command('hi clear NvimInvalid')
meths.nvim_command('hi NvimStringQuote guifg=Blue3') command('hi NvimStringQuote guifg=Blue3')
meths.nvim_command('hi NvimStringBody guifg=Blue4') command('hi NvimStringBody guifg=Blue4')
meths.nvim_command('hi NvimInvalid guifg=Red guibg=Blue') command('hi NvimInvalid guifg=Red guibg=Blue')
feed('i<C-r>="«»"«»') feed('i<C-r>="«»"«»')
screen:expect([[ screen:expect([[
| |

View File

@ -9,7 +9,6 @@ local exec = helpers.exec
local expect_events = helpers.expect_events local expect_events = helpers.expect_events
local meths = helpers.meths local meths = helpers.meths
local funcs = helpers.funcs local funcs = helpers.funcs
local curbufmeths = helpers.curbufmeths
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@ -244,7 +243,7 @@ describe('decorations providers', function()
-- spell=false with higher priority does disable spell -- spell=false with higher priority does disable spell
local ns = meths.nvim_create_namespace "spell" local ns = meths.nvim_create_namespace "spell"
local id = curbufmeths.set_extmark(ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false }) local id = meths.nvim_buf_set_extmark(0, ns, 0, 0, { priority = 30, end_row = 2, end_col = 23, spell = false })
screen:expect{grid=[[ screen:expect{grid=[[
I am well written text. | I am well written text. |
@ -267,7 +266,7 @@ describe('decorations providers', function()
command('echo ""') command('echo ""')
-- spell=false with lower priority doesn't disable spell -- spell=false with lower priority doesn't disable spell
curbufmeths.set_extmark(ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false }) meths.nvim_buf_set_extmark(0, ns, 0, 0, { id = id, priority = 10, end_row = 2, end_col = 23, spell = false })
screen:expect{grid=[[ screen:expect{grid=[[
I am well written text. | I am well written text. |

View File

@ -12,12 +12,13 @@ local exec = helpers.exec
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local insert = helpers.insert local insert = helpers.insert
local meths = helpers.meths local meths = helpers.meths
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local run = helpers.run local run = helpers.run
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local tbl_contains = vim.tbl_contains local tbl_contains = vim.tbl_contains
local curbuf, curwin, curtab = helpers.curbuf, helpers.curwin, helpers.curtab local curbuf = helpers.meths.nvim_get_current_buf
local curwin = helpers.meths.nvim_get_current_win
local curtab = helpers.meths.nvim_get_current_tabpage
local NIL = vim.NIL local NIL = vim.NIL
describe('float window', function() describe('float window', function()
@ -6624,7 +6625,7 @@ describe('float window', function()
for i = 1,5 do for i = 1,5 do
feed(i.."<c-w>w") feed(i.."<c-w>w")
feed_command("enew") feed_command("enew")
curbufmeths.set_lines(0,-1,true,{tostring(i)}) meths.nvim_buf_set_lines(0, 0,-1,true,{tostring(i)})
end end
if multigrid then if multigrid then

View File

@ -5,7 +5,6 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local command, exec = helpers.command, helpers.exec local command, exec = helpers.command, helpers.exec
local eval = helpers.eval local eval = helpers.eval
local feed_command, eq = helpers.feed_command, helpers.eq local feed_command, eq = helpers.feed_command, helpers.eq
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
@ -2088,7 +2087,7 @@ describe("'winhighlight' highlight", function()
end) end)
it('can override NonText, Conceal and EndOfBuffer', function() it('can override NonText, Conceal and EndOfBuffer', function()
curbufmeths.set_lines(0, -1, true, { 'raa\000' }) meths.nvim_buf_set_lines(0, 0, -1, true, { 'raa\000' })
command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})') command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})')
command('set cole=2 cocu=nvic') command('set cole=2 cocu=nvic')
command('split') command('split')

View File

@ -14,7 +14,6 @@ local ok = helpers.ok
local retry = helpers.retry local retry = helpers.retry
local source = helpers.source local source = helpers.source
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local nvim = helpers.nvim
local sleep = vim.uv.sleep local sleep = vim.uv.sleep
local testprg = helpers.testprg local testprg = helpers.testprg
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
@ -1898,20 +1897,20 @@ describe("'inccommand' with 'gdefault'", function()
common_setup(nil, 'nosplit', '{') common_setup(nil, 'nosplit', '{')
command('set gdefault') command('set gdefault')
feed(':s/{\\n') feed(':s/{\\n')
eq({ mode = 'c', blocking = false }, nvim('get_mode')) eq({ mode = 'c', blocking = false }, meths.nvim_get_mode())
feed('/A<Enter>') feed('/A<Enter>')
expect('A') expect('A')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
end) end)
it('with multiline text and range, does not lock up #7244', function() it('with multiline text and range, does not lock up #7244', function()
common_setup(nil, 'nosplit', '{\n\n{') common_setup(nil, 'nosplit', '{\n\n{')
command('set gdefault') command('set gdefault')
feed(':%s/{\\n') feed(':%s/{\\n')
eq({ mode = 'c', blocking = false }, nvim('get_mode')) eq({ mode = 'c', blocking = false }, meths.nvim_get_mode())
feed('/A<Enter>') feed('/A<Enter>')
expect('A\nA') expect('A\nA')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
end) end)
it('does not crash on zero-width matches #7485', function() it('does not crash on zero-width matches #7485', function()
@ -1920,9 +1919,9 @@ describe("'inccommand' with 'gdefault'", function()
feed('gg') feed('gg')
feed('Vj') feed('Vj')
feed(':s/\\%V') feed(':s/\\%V')
eq({ mode = 'c', blocking = false }, nvim('get_mode')) eq({ mode = 'c', blocking = false }, meths.nvim_get_mode())
feed('<Esc>') feed('<Esc>')
eq({ mode = 'n', blocking = false }, nvim('get_mode')) eq({ mode = 'n', blocking = false }, meths.nvim_get_mode())
end) end)
it('removes highlights after abort for a zero-width match', function() it('removes highlights after abort for a zero-width match', function()

View File

@ -1118,9 +1118,9 @@ describe('regressions', function()
screen = Screen.new(100, 20) screen = Screen.new(100, 20)
screen:attach() screen:attach()
-- line must be greater than MATCH_CHAR_MAX_LEN -- line must be greater than MATCH_CHAR_MAX_LEN
helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1000) .. 'hello' }) helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1000) .. 'hello' })
helpers.exec 'vnew' helpers.exec 'vnew'
helpers.curbufmeths.set_lines(0, -1, false, { string.rep('a', 1010) .. 'world' }) helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { string.rep('a', 1010) .. 'world' })
helpers.exec 'windo diffthis' helpers.exec 'windo diffthis'
end) end)
@ -1133,9 +1133,9 @@ describe('regressions', function()
for i = 0, 29 do for i = 0, 29 do
lines[#lines + 1] = tostring(i) lines[#lines + 1] = tostring(i)
end end
helpers.curbufmeths.set_lines(0, -1, false, lines) helpers.meths.nvim_buf_set_lines(0, 0, -1, false, lines)
helpers.exec 'vnew' helpers.exec 'vnew'
helpers.curbufmeths.set_lines(0, -1, false, { '00', '29' }) helpers.meths.nvim_buf_set_lines(0, 0, -1, false, { '00', '29' })
helpers.exec 'windo diffthis' helpers.exec 'windo diffthis'
feed('<C-e>') feed('<C-e>')
screen:expect { screen:expect {

View File

@ -5,7 +5,7 @@ local feed, command, insert = helpers.feed, helpers.command, helpers.insert
local eq = helpers.eq local eq = helpers.eq
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local curwin = helpers.curwin local curwin = helpers.meths.nvim_get_current_win
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop

View File

@ -7,7 +7,6 @@ local exec = helpers.exec
local feed = helpers.feed local feed = helpers.feed
local insert = helpers.insert local insert = helpers.insert
local meths = helpers.meths local meths = helpers.meths
local curbufmeths = helpers.curbufmeths
local is_os = helpers.is_os local is_os = helpers.is_os
describe("'spell'", function() describe("'spell'", function()
@ -262,7 +261,7 @@ describe("'spell'", function()
exec('echo ""') exec('echo ""')
local ns = meths.nvim_create_namespace('spell') local ns = meths.nvim_create_namespace('spell')
-- extmark with spell=true enables spell -- extmark with spell=true enables spell
local id = curbufmeths.set_extmark(ns, 1, 4, { end_row = 1, end_col = 10, spell = true }) local id = meths.nvim_buf_set_extmark(0, ns, 1, 4, { end_row = 1, end_col = 10, spell = true })
screen:expect([[ screen:expect([[
{3:#include }{4:<stdbool.h>} | {3:#include }{4:<stdbool.h>} |
{5:bool} {1:func}({5:void}); | {5:bool} {1:func}({5:void}); |
@ -278,9 +277,9 @@ describe("'spell'", function()
{0:~ }|*4 {0:~ }|*4
| |
]]) ]])
curbufmeths.del_extmark(ns, id) meths.nvim_buf_del_extmark(0, ns, id)
-- extmark with spell=false disables spell -- extmark with spell=false disables spell
id = curbufmeths.set_extmark(ns, 2, 18, { end_row = 2, end_col = 26, spell = false }) id = meths.nvim_buf_set_extmark(0, ns, 2, 18, { end_row = 2, end_col = 26, spell = false })
screen:expect([[ screen:expect([[
{3:#include }{4:<stdbool.h>} | {3:#include }{4:<stdbool.h>} |
{5:bool} ^func({5:void}); | {5:bool} ^func({5:void}); |
@ -297,7 +296,7 @@ describe("'spell'", function()
{6:search hit TOP, continuing at BOTTOM} | {6:search hit TOP, continuing at BOTTOM} |
]]) ]])
exec('echo ""') exec('echo ""')
curbufmeths.del_extmark(ns, id) meths.nvim_buf_del_extmark(0, ns, id)
screen:expect([[ screen:expect([[
{3:#include }{4:<stdbool.h>} | {3:#include }{4:<stdbool.h>} |
{5:bool} func({5:void}); | {5:bool} func({5:void}); |
@ -369,7 +368,7 @@ describe("'spell'", function()
call setline(1, "This is some text without any spell errors.") call setline(1, "This is some text without any spell errors.")
]]) ]])
local ns = meths.nvim_create_namespace('spell') local ns = meths.nvim_create_namespace('spell')
curbufmeths.set_extmark(ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 }) meths.nvim_buf_set_extmark(0, ns, 0, 0, { hl_group = 'WarningMsg', end_col = 43 })
screen:expect([[ screen:expect([[
{6:^This is some text without any spell errors.}| {6:^This is some text without any spell errors.}|
{0:~ }| {0:~ }|

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curwin = helpers.curwin local curwin = helpers.meths.nvim_get_current_win
local eq = helpers.eq local eq = helpers.eq
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed = helpers.feed local feed = helpers.feed

View File

@ -8,7 +8,6 @@ local eq = helpers.eq
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local funcs = helpers.funcs
local curwin = helpers.curwin
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
describe('winbar', function() describe('winbar', function()
@ -52,7 +51,7 @@ describe('winbar', function()
]]) ]])
-- winbar is excluded from the heights returned by winheight() and getwininfo() -- winbar is excluded from the heights returned by winheight() and getwininfo()
eq(11, funcs.winheight(0)) eq(11, funcs.winheight(0))
local win_info = funcs.getwininfo(curwin().id)[1] local win_info = funcs.getwininfo(meths.nvim_get_current_win().id)[1]
eq(11, win_info.height) eq(11, win_info.height)
eq(1, win_info.winbar) eq(1, win_info.winbar)
end) end)

View File

@ -1,7 +1,7 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local neq, eq, command = helpers.neq, helpers.eq, helpers.command local neq, eq, command = helpers.neq, helpers.eq, helpers.command
local clear, curbufmeths = helpers.clear, helpers.curbufmeths local clear = helpers.clear
local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval local exc_exec, expect, eval = helpers.exc_exec, helpers.expect, helpers.eval
local insert, pcall_err = helpers.insert, helpers.pcall_err local insert, pcall_err = helpers.insert, helpers.pcall_err
local matches = helpers.matches local matches = helpers.matches
@ -97,8 +97,8 @@ describe('eval-API', function()
) )
-- But others, like nvim_buf_set_lines(), which just changes text, is OK. -- But others, like nvim_buf_set_lines(), which just changes text, is OK.
curbufmeths.set_lines(0, -1, 1, { 'wow!' }) meths.nvim_buf_set_lines(0, 0, -1, 1, { 'wow!' })
eq({ 'wow!' }, curbufmeths.get_lines(0, -1, 1)) eq({ 'wow!' }, meths.nvim_buf_get_lines(0, 0, -1, 1))
-- Turning the cmdwin buffer into a terminal buffer would be pretty weird. -- Turning the cmdwin buffer into a terminal buffer would be pretty weird.
eq( eq(
@ -143,11 +143,11 @@ describe('eval-API', function()
end) end)
it('get_lines and set_lines use NL to represent NUL', function() it('get_lines and set_lines use NL to represent NUL', function()
curbufmeths.set_lines(0, -1, true, { 'aa\0', 'b\0b' }) meths.nvim_buf_set_lines(0, 0, -1, true, { 'aa\0', 'b\0b' })
eq({ 'aa\n', 'b\nb' }, eval('nvim_buf_get_lines(0, 0, -1, 1)')) eq({ 'aa\n', 'b\nb' }, eval('nvim_buf_get_lines(0, 0, -1, 1)'))
command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])') command('call nvim_buf_set_lines(0, 1, 2, v:true, ["xx", "\\nyy"])')
eq({ 'aa\0', 'xx', '\0yy' }, curbufmeths.get_lines(0, -1, 1)) eq({ 'aa\0', 'xx', '\0yy' }, meths.nvim_buf_get_lines(0, 0, -1, 1))
end) end)
it('that are FUNC_ATTR_NOEVAL cannot be called', function() it('that are FUNC_ATTR_NOEVAL cannot be called', function()

View File

@ -6,10 +6,6 @@ local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local bufmeths = helpers.bufmeths
local curbufmeths = helpers.curbufmeths
local curwinmeths = helpers.curwinmeths
local curtabmeths = helpers.curtabmeths
local get_pathsep = helpers.get_pathsep local get_pathsep = helpers.get_pathsep
local rmdir = helpers.rmdir local rmdir = helpers.rmdir
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@ -196,7 +192,7 @@ describe('getbufline() function', function()
end) end)
it('returns empty list when range is invalid', function() it('returns empty list when range is invalid', function()
eq({}, funcs.getbufline(1, 0)) eq({}, funcs.getbufline(1, 0))
curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'baz' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' })
eq({}, funcs.getbufline(1, 2, 1)) eq({}, funcs.getbufline(1, 2, 1))
eq({}, funcs.getbufline(1, -10, -20)) eq({}, funcs.getbufline(1, -10, -20))
eq({}, funcs.getbufline(1, -2, -1)) eq({}, funcs.getbufline(1, -2, -1))
@ -205,9 +201,9 @@ describe('getbufline() function', function()
it('returns expected lines', function() it('returns expected lines', function()
meths.nvim_set_option_value('hidden', true, {}) meths.nvim_set_option_value('hidden', true, {})
command('file ' .. fname) command('file ' .. fname)
curbufmeths.set_lines(0, 1, false, { 'foo\0', '\0bar', 'baz' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'foo\0', '\0bar', 'baz' })
command('edit ' .. fname2) command('edit ' .. fname2)
curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' })
eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, 9999)) eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, 9999))
eq({ 'abc\n', '\ndef', 'ghi' }, funcs.getbufline(2, 1, 9999)) eq({ 'abc\n', '\ndef', 'ghi' }, funcs.getbufline(2, 1, 9999))
eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, '$')) eq({ 'foo\n', '\nbar', 'baz' }, funcs.getbufline(1, 1, '$'))
@ -247,7 +243,7 @@ describe('getbufvar() function', function()
-- But with window-local options it probably does not what you expect -- But with window-local options it probably does not what you expect
command('setl number') command('setl number')
-- (note that current windows buffer is 2, but getbufvar() receives 1) -- (note that current windows buffer is 2, but getbufvar() receives 1)
eq({ id = 2 }, curwinmeths.get_buf()) eq({ id = 2 }, meths.nvim_win_get_buf(0))
eq(1, funcs.getbufvar(1, '&number')) eq(1, funcs.getbufvar(1, '&number'))
eq(1, funcs.getbufvar(1, '&l:number')) eq(1, funcs.getbufvar(1, '&l:number'))
-- You can get global value though, if you find this useful. -- You can get global value though, if you find this useful.
@ -255,9 +251,9 @@ describe('getbufvar() function', function()
end) end)
it('returns expected variable value', function() it('returns expected variable value', function()
eq(2, funcs.getbufvar(1, 'changedtick')) eq(2, funcs.getbufvar(1, 'changedtick'))
curbufmeths.set_lines(0, 1, false, { 'abc\0', '\0def', 'ghi' }) meths.nvim_buf_set_lines(0, 0, 1, false, { 'abc\0', '\0def', 'ghi' })
eq(3, funcs.getbufvar(1, 'changedtick')) eq(3, funcs.getbufvar(1, 'changedtick'))
curbufmeths.set_var('test', true) meths.nvim_buf_set_var(0, 'test', true)
eq(true, funcs.getbufvar(1, 'test')) eq(true, funcs.getbufvar(1, 'test'))
eq({ test = true, changedtick = 3 }, funcs.getbufvar(1, '')) eq({ test = true, changedtick = 3 }, funcs.getbufvar(1, ''))
command('new') command('new')
@ -288,9 +284,9 @@ describe('setbufvar() function', function()
eq(false, meths.nvim_get_option_value('number', {})) eq(false, meths.nvim_get_option_value('number', {}))
command('split') command('split')
command('new') command('new')
eq(2, bufmeths.get_number(curwinmeths.get_buf())) eq(2, meths.nvim_buf_get_number(meths.nvim_win_get_buf(0)))
funcs.setbufvar(1, '&number', true) funcs.setbufvar(1, '&number', true)
local windows = curtabmeths.list_wins() local windows = meths.nvim_tabpage_list_wins(0)
eq(false, meths.nvim_get_option_value('number', { win = windows[1].id })) eq(false, meths.nvim_get_option_value('number', { win = windows[1].id }))
eq(true, meths.nvim_get_option_value('number', { win = windows[2].id })) eq(true, meths.nvim_get_option_value('number', { win = windows[2].id }))
eq(false, meths.nvim_get_option_value('number', { win = windows[3].id })) eq(false, meths.nvim_get_option_value('number', { win = windows[3].id }))
@ -309,11 +305,11 @@ describe('setbufvar() function', function()
local buf1 = meths.nvim_get_current_buf() local buf1 = meths.nvim_get_current_buf()
command('split') command('split')
command('new') command('new')
eq(2, curbufmeths.get_number()) eq(2, meths.nvim_buf_get_number(0))
funcs.setbufvar(1, 'number', true) funcs.setbufvar(1, 'number', true)
eq(true, bufmeths.get_var(buf1, 'number')) eq(true, meths.nvim_buf_get_var(buf1, 'number'))
eq('Vim(call):E461: Illegal variable name: b:', exc_exec('call setbufvar(1, "", 0)')) eq('Vim(call):E461: Illegal variable name: b:', exc_exec('call setbufvar(1, "", 0)'))
eq(true, bufmeths.get_var(buf1, 'number')) eq(true, meths.nvim_buf_get_var(buf1, 'number'))
eq( eq(
'Vim:E46: Cannot change read-only variable "b:changedtick"', 'Vim:E46: Cannot change read-only variable "b:changedtick"',
pcall_err(funcs.setbufvar, 1, 'changedtick', true) pcall_err(funcs.setbufvar, 1, 'changedtick', true)

View File

@ -10,14 +10,13 @@ local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local curbufmeths = helpers.curbufmeths
before_each(clear) before_each(clear)
local function changedtick() local function changedtick()
local ct = curbufmeths.get_changedtick() local ct = meths.nvim_buf_get_changedtick(0)
eq(ct, curbufmeths.get_var('changedtick')) eq(ct, meths.nvim_buf_get_var(0, 'changedtick'))
eq(ct, curbufmeths.get_var('changedtick')) eq(ct, meths.nvim_buf_get_var(0, 'changedtick'))
eq(ct, eval('b:changedtick')) eq(ct, eval('b:changedtick'))
eq(ct, eval('b:["changedtick"]')) eq(ct, eval('b:["changedtick"]'))
eq(ct, eval('b:.changedtick')) eq(ct, eval('b:.changedtick'))
@ -46,11 +45,11 @@ describe('b:changedtick', function()
it('increments at bdel', function() it('increments at bdel', function()
command('new') command('new')
eq(2, changedtick()) eq(2, changedtick())
local bnr = curbufmeths.get_number() local bnr = meths.nvim_buf_get_number(0)
eq(2, bnr) eq(2, bnr)
command('bdel') command('bdel')
eq(3, funcs.getbufvar(bnr, 'changedtick')) eq(3, funcs.getbufvar(bnr, 'changedtick'))
eq(1, curbufmeths.get_number()) eq(1, meths.nvim_buf_get_number(0))
end) end)
it('fails to be changed by user', function() it('fails to be changed by user', function()
local ct = changedtick() local ct = changedtick()
@ -72,7 +71,7 @@ describe('b:changedtick', function()
'Vim(let):E46: Cannot change read-only variable "d.changedtick"', 'Vim(let):E46: Cannot change read-only variable "d.changedtick"',
pcall_err(command, 'let d.changedtick = ' .. ctn) pcall_err(command, 'let d.changedtick = ' .. ctn)
) )
eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', ctn)) eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_set_var, 0, 'changedtick', ctn))
eq( eq(
'Vim(unlet):E795: Cannot delete variable b:changedtick', 'Vim(unlet):E795: Cannot delete variable b:changedtick',
@ -90,7 +89,7 @@ describe('b:changedtick', function()
'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"',
pcall_err(command, 'unlet d.changedtick') pcall_err(command, 'unlet d.changedtick')
) )
eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_del_var, 0, 'changedtick'))
eq(ct, changedtick()) eq(ct, changedtick())
eq( eq(

View File

@ -7,7 +7,7 @@ local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed = helpers.feed local feed = helpers.feed
local map = vim.tbl_map local map = vim.tbl_map
local nvim = helpers.nvim local meths = helpers.meths
local parse_context = helpers.parse_context local parse_context = helpers.parse_context
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
local source = helpers.source local source = helpers.source
@ -126,16 +126,16 @@ describe('context functions', function()
end) end)
it('saves and restores global variables properly', function() it('saves and restores global variables properly', function()
nvim('set_var', 'one', 1) meths.nvim_set_var('one', 1)
nvim('set_var', 'Two', 2) meths.nvim_set_var('Two', 2)
nvim('set_var', 'THREE', 3) meths.nvim_set_var('THREE', 3)
eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]'))
call('ctxpush') call('ctxpush')
call('ctxpush', { 'gvars' }) call('ctxpush', { 'gvars' })
nvim('del_var', 'one') meths.nvim_del_var('one')
nvim('del_var', 'Two') meths.nvim_del_var('Two')
nvim('del_var', 'THREE') meths.nvim_del_var('THREE')
eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one'))
eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two'))
eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE'))
@ -143,9 +143,9 @@ describe('context functions', function()
call('ctxpop') call('ctxpop')
eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]'))
nvim('del_var', 'one') meths.nvim_del_var('one')
nvim('del_var', 'Two') meths.nvim_del_var('Two')
nvim('del_var', 'THREE') meths.nvim_del_var('THREE')
eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one')) eq('Vim:E121: Undefined variable: g:one', pcall_err(eval, 'g:one'))
eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two')) eq('Vim:E121: Undefined variable: g:Two', pcall_err(eval, 'g:Two'))
eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE')) eq('Vim:E121: Undefined variable: g:THREE', pcall_err(eval, 'g:THREE'))
@ -300,9 +300,9 @@ describe('context functions', function()
feed('G') feed('G')
feed('gg') feed('gg')
command('edit ' .. fname2) command('edit ' .. fname2)
nvim('set_var', 'one', 1) meths.nvim_set_var('one', 1)
nvim('set_var', 'Two', 2) meths.nvim_set_var('Two', 2)
nvim('set_var', 'THREE', 3) meths.nvim_set_var('THREE', 3)
local with_regs = { local with_regs = {
['regs'] = { ['regs'] = {
@ -412,14 +412,14 @@ describe('context functions', function()
end) end)
it('sets context dictionary at index in context stack', function() it('sets context dictionary at index in context stack', function()
nvim('set_var', 'one', 1) meths.nvim_set_var('one', 1)
nvim('set_var', 'Two', 2) meths.nvim_set_var('Two', 2)
nvim('set_var', 'THREE', 3) meths.nvim_set_var('THREE', 3)
call('ctxpush') call('ctxpush')
local ctx1 = call('ctxget') local ctx1 = call('ctxget')
nvim('set_var', 'one', 'a') meths.nvim_set_var('one', 'a')
nvim('set_var', 'Two', 'b') meths.nvim_set_var('Two', 'b')
nvim('set_var', 'THREE', 'c') meths.nvim_set_var('THREE', 'c')
call('ctxpush') call('ctxpush')
call('ctxpush') call('ctxpush')
local ctx2 = call('ctxget') local ctx2 = call('ctxget')
@ -431,7 +431,7 @@ describe('context functions', function()
eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]')) eq({ 1, 2, 3 }, eval('[g:one, g:Two, g:THREE]'))
call('ctxpop') call('ctxpop')
eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]'))
nvim('set_var', 'one', 1.5) meths.nvim_set_var('one', 1.5)
eq({ 1.5, 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) eq({ 1.5, 'b', 'c' }, eval('[g:one, g:Two, g:THREE]'))
call('ctxpop') call('ctxpop')
eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]')) eq({ 'a', 'b', 'c' }, eval('[g:one, g:Two, g:THREE]'))

View File

@ -4,7 +4,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local get_cur_win_var = helpers.curwinmeths.get_var local get_win_var = helpers.meths.nvim_win_get_var
describe('setqflist()', function() describe('setqflist()', function()
local setqflist = helpers.funcs.setqflist local setqflist = helpers.funcs.setqflist
@ -26,15 +26,15 @@ describe('setqflist()', function()
it('sets w:quickfix_title', function() it('sets w:quickfix_title', function()
setqflist({ '' }, 'r', 'foo') setqflist({ '' }, 'r', 'foo')
command('copen') command('copen')
eq('foo', get_cur_win_var('quickfix_title')) eq('foo', get_win_var(0, 'quickfix_title'))
setqflist({}, 'r', { ['title'] = 'qf_title' }) setqflist({}, 'r', { ['title'] = 'qf_title' })
eq('qf_title', get_cur_win_var('quickfix_title')) eq('qf_title', get_win_var(0, 'quickfix_title'))
end) end)
it('allows string {what} for backwards compatibility', function() it('allows string {what} for backwards compatibility', function()
setqflist({}, 'r', '5') setqflist({}, 'r', '5')
command('copen') command('copen')
eq('5', get_cur_win_var('quickfix_title')) eq('5', get_win_var(0, 'quickfix_title'))
end) end)
it('requires a dict for {what}', function() it('requires a dict for {what}', function()
@ -67,9 +67,9 @@ describe('setloclist()', function()
setloclist(1, {}, 'r', 'foo') setloclist(1, {}, 'r', 'foo')
setloclist(2, {}, 'r', 'bar') setloclist(2, {}, 'r', 'bar')
command('lopen') command('lopen')
eq('bar', get_cur_win_var('quickfix_title')) eq('bar', get_win_var(0, 'quickfix_title'))
command('lclose | wincmd w | lopen') command('lclose | wincmd w | lopen')
eq('foo', get_cur_win_var('quickfix_title')) eq('foo', get_win_var(0, 'quickfix_title'))
end) end)
it("doesn't crash when when window is closed in the middle #13721", function() it("doesn't crash when when window is closed in the middle #13721", function()

View File

@ -9,7 +9,6 @@ local expect = helpers.expect
local feed = helpers.feed local feed = helpers.feed
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
local nvim = helpers.nvim
local source = helpers.source local source = helpers.source
local command = helpers.command local command = helpers.command
local exec_capture = helpers.exec_capture local exec_capture = helpers.exec_capture
@ -37,16 +36,16 @@ describe('maparg()', function()
} }
it('returns a dictionary', function() it('returns a dictionary', function()
nvim('command', 'nnoremap foo bar') command('nnoremap foo bar')
eq('bar', funcs.maparg('foo')) eq('bar', funcs.maparg('foo'))
eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true)) eq(foo_bar_map_table, funcs.maparg('foo', 'n', false, true))
end) end)
it('returns 1 for silent when <silent> is used', function() it('returns 1 for silent when <silent> is used', function()
nvim('command', 'nnoremap <silent> foo bar') command('nnoremap <silent> foo bar')
eq(1, funcs.maparg('foo', 'n', false, true)['silent']) eq(1, funcs.maparg('foo', 'n', false, true)['silent'])
nvim('command', 'nnoremap baz bat') command('nnoremap baz bat')
eq(0, funcs.maparg('baz', 'n', false, true)['silent']) eq(0, funcs.maparg('baz', 'n', false, true)['silent'])
end) end)
@ -59,8 +58,8 @@ describe('maparg()', function()
end) end)
it('returns the same value for noremap and <script>', function() it('returns the same value for noremap and <script>', function()
nvim('command', 'inoremap <script> hello world') command('inoremap <script> hello world')
nvim('command', 'inoremap this that') command('inoremap this that')
eq( eq(
funcs.maparg('hello', 'i', false, true)['noremap'], funcs.maparg('hello', 'i', false, true)['noremap'],
funcs.maparg('this', 'i', false, true)['noremap'] funcs.maparg('this', 'i', false, true)['noremap']
@ -69,14 +68,14 @@ describe('maparg()', function()
it('returns a boolean for buffer', function() it('returns a boolean for buffer', function()
-- Open enough windows to know we aren't on buffer number 1 -- Open enough windows to know we aren't on buffer number 1
nvim('command', 'new') command('new')
nvim('command', 'new') command('new')
nvim('command', 'new') command('new')
nvim('command', 'cnoremap <buffer> this that') command('cnoremap <buffer> this that')
eq(1, funcs.maparg('this', 'c', false, true)['buffer']) eq(1, funcs.maparg('this', 'c', false, true)['buffer'])
-- Global will return 0 always -- Global will return 0 always
nvim('command', 'nnoremap other another') command('nnoremap other another')
eq(0, funcs.maparg('other', 'n', false, true)['buffer']) eq(0, funcs.maparg('other', 'n', false, true)['buffer'])
end) end)
@ -89,7 +88,7 @@ describe('maparg()', function()
nnoremap fizz :call <SID>maparg_test_function()<CR> nnoremap fizz :call <SID>maparg_test_function()<CR>
]]) ]])
eq(1, funcs.maparg('fizz', 'n', false, true)['sid']) eq(1, funcs.maparg('fizz', 'n', false, true)['sid'])
eq('testing', nvim('call_function', '<SNR>1_maparg_test_function', {})) eq('testing', meths.nvim_call_function('<SNR>1_maparg_test_function', {}))
end) end)
it('works with <F12> and others', function() it('works with <F12> and others', function()

View File

@ -3,7 +3,7 @@ local clear = helpers.clear
local funcs = helpers.funcs local funcs = helpers.funcs
local eval, eq = helpers.eval, helpers.eq local eval, eq = helpers.eval, helpers.eq
local command = helpers.command local command = helpers.command
local nvim = helpers.nvim local meths = helpers.meths
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local is_os = helpers.is_os local is_os = helpers.is_os
@ -12,7 +12,7 @@ describe('msgpack*() functions', function()
local obj_test = function(msg, obj) local obj_test = function(msg, obj)
it(msg, function() it(msg, function()
nvim('set_var', 'obj', obj) meths.nvim_set_var('obj', obj)
eq(obj, eval('msgpackparse(msgpackdump(g:obj))')) eq(obj, eval('msgpackparse(msgpackdump(g:obj))'))
eq(obj, eval('msgpackparse(msgpackdump(g:obj, "B"))')) eq(obj, eval('msgpackparse(msgpackdump(g:obj, "B"))'))
end) end)

View File

@ -1,6 +1,5 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local curbufmeths = helpers.curbufmeths
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local command = helpers.command local command = helpers.command
local clear = helpers.clear local clear = helpers.clear
@ -72,10 +71,10 @@ describe('NULL', function()
null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0)
null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0)
null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function() null_expr_test('does not crash append()', 'append(0, L)', 0, 0, function()
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function()
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end) end)
null_expr_test('is identical to itself', 'L is L', 0, 1) null_expr_test('is identical to itself', 'L is L', 0, 1)
null_expr_test('can be sliced', 'L[:]', 0, {}) null_expr_test('can be sliced', 'L[:]', 0, {})
@ -184,7 +183,7 @@ describe('NULL', function()
0, 0,
'', '',
function() function()
eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq({ '' }, meths.nvim_buf_get_lines(0, 0, -1, false))
end end
) )
null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0)

View File

@ -4,14 +4,14 @@ local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local testprg = helpers.testprg local testprg = helpers.testprg
local eq, call, clear, eval, feed_command, feed, nvim = local eq, call, clear, eval, feed_command, feed, meths =
helpers.eq, helpers.eq,
helpers.call, helpers.call,
helpers.clear, helpers.clear,
helpers.eval, helpers.eval,
helpers.feed_command, helpers.feed_command,
helpers.feed, helpers.feed,
helpers.nvim helpers.meths
local command = helpers.command local command = helpers.command
local insert = helpers.insert local insert = helpers.insert
local expect = helpers.expect local expect = helpers.expect
@ -220,8 +220,8 @@ describe('system()', function()
end) end)
it('prints verbose information', function() it('prints verbose information', function()
nvim('set_option_value', 'shell', 'fake_shell', {}) meths.nvim_set_option_value('shell', 'fake_shell', {})
nvim('set_option_value', 'shellcmdflag', 'cmdflag', {}) meths.nvim_set_option_value('shellcmdflag', 'cmdflag', {})
screen:try_resize(72, 14) screen:try_resize(72, 14)
feed(':4verbose echo system("echo hi")<cr>') feed(':4verbose echo system("echo hi")<cr>')
@ -346,7 +346,7 @@ describe('system()', function()
input[#input + 1] = '01234567890ABCDEFabcdef' input[#input + 1] = '01234567890ABCDEFabcdef'
end end
input = table.concat(input, '\n') input = table.concat(input, '\n')
nvim('set_var', 'input', input) meths.nvim_set_var('input', input)
eq(input, eval('system("cat -", g:input)')) eq(input, eval('system("cat -", g:input)'))
end) end)
end) end)
@ -480,7 +480,7 @@ describe('systemlist()', function()
for _ = 1, 0xffff do for _ = 1, 0xffff do
input[#input + 1] = '01234567890ABCDEFabcdef' input[#input + 1] = '01234567890ABCDEFabcdef'
end end
nvim('set_var', 'input', input) meths.nvim_set_var('input', input)
eq(input, eval('systemlist("cat -", g:input)')) eq(input, eval('systemlist("cat -", g:input)'))
end) end)
end) end)

View File

@ -4,7 +4,7 @@ local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok
local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
local load_adjust = helpers.load_adjust local load_adjust = helpers.load_adjust
local retry = helpers.retry local retry = helpers.retry
@ -111,7 +111,7 @@ describe('timers', function()
[1] = { bold = true, foreground = Screen.colors.Blue }, [1] = { bold = true, foreground = Screen.colors.Blue },
}) })
curbufmeths.set_lines(0, -1, true, { 'ITEM 1', 'ITEM 2' }) meths.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' })
source([[ source([[
let g:cont = 0 let g:cont = 0
func! AddItem(timer) func! AddItem(timer)

View File

@ -7,14 +7,14 @@ local eq = helpers.eq
local feed = helpers.feed local feed = helpers.feed
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local next_msg = helpers.next_msg local next_msg = helpers.next_msg
local nvim = helpers.nvim local meths = helpers.meths
local source = helpers.source local source = helpers.source
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
before_each(function() before_each(function()
clear() clear()
local channel = nvim('get_api_info')[1] local channel = meths.nvim_get_api_info()[1]
nvim('set_var', 'channel', channel) meths.nvim_set_var('channel', channel)
end) end)
describe('wait()', function() describe('wait()', function()
@ -61,13 +61,13 @@ describe('wait()', function()
-- XXX: flaky (#11137) -- XXX: flaky (#11137)
helpers.retry(nil, nil, function() helpers.retry(nil, nil, function()
nvim('set_var', 'counter', 0) meths.nvim_set_var('counter', 0)
eq(-1, call('wait', 20, 'Count() >= 5', 99999)) eq(-1, call('wait', 20, 'Count() >= 5', 99999))
end) end)
nvim('set_var', 'counter', 0) meths.nvim_set_var('counter', 0)
eq(0, call('wait', 10000, 'Count() >= 5', 5)) eq(0, call('wait', 10000, 'Count() >= 5', 5))
eq(5, nvim('get_var', 'counter')) eq(5, meths.nvim_get_var('counter'))
end) end)
it('validates args', function() it('validates args', function()

View File

@ -2104,7 +2104,7 @@ func Test_trim()
call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx"))
call assert_equal("RESERVE", trim("你RESERVE好", "你好")) call assert_equal("RESERVE", trim("你RESERVE好", "你好"))
call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好"))
call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B"))
call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好"))
call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes"))
call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses"))