mirror of
https://github.com/neovim/neovim.git
synced 2026-04-30 19:24:09 +00:00
test: normalise nvim bridge functions
- remove helpers.cur*meths - remove helpers.nvim
This commit is contained in:
@@ -109,12 +109,12 @@ describe('autocmd api', function()
|
||||
buffer = 0,
|
||||
})
|
||||
|
||||
meths.nvim_command 'set filetype=txt'
|
||||
command 'set filetype=txt'
|
||||
eq(1, meths.nvim_get_var('called'))
|
||||
|
||||
-- switch to a new buffer
|
||||
meths.nvim_command 'new'
|
||||
meths.nvim_command 'set filetype=python'
|
||||
command 'new'
|
||||
command 'set filetype=python'
|
||||
|
||||
eq(1, meths.nvim_get_var('called'))
|
||||
end)
|
||||
@@ -938,7 +938,7 @@ describe('autocmd api', function()
|
||||
meths.nvim_exec_autocmds('CursorHold', { buffer = 1 })
|
||||
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'))
|
||||
end)
|
||||
|
||||
@@ -955,8 +955,8 @@ describe('autocmd api', function()
|
||||
meths.nvim_set_var('filename_executed', 'none')
|
||||
eq('none', meths.nvim_get_var('filename_executed'))
|
||||
|
||||
meths.nvim_command('edit other_file.txt')
|
||||
meths.nvim_command('edit __init__.py')
|
||||
command('edit other_file.txt')
|
||||
command('edit __init__.py')
|
||||
eq('none', meths.nvim_get_var('filename_executed'))
|
||||
|
||||
meths.nvim_create_autocmd('CursorHoldI', {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@ local helpers = require('test.functional.helpers')(after_each)
|
||||
local clear = helpers.clear
|
||||
local eq, ok = helpers.eq, helpers.ok
|
||||
local funcs = helpers.funcs
|
||||
local buffer, command, eval, nvim, next_msg =
|
||||
helpers.buffer, helpers.command, helpers.eval, helpers.nvim, helpers.next_msg
|
||||
local meths = helpers.meths
|
||||
local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg
|
||||
local nvim_prog = helpers.nvim_prog
|
||||
local pcall_err = helpers.pcall_err
|
||||
local sleep = vim.uv.sleep
|
||||
@@ -24,7 +24,7 @@ local function expectn(name, args)
|
||||
end
|
||||
|
||||
local function sendkeys(keys)
|
||||
nvim('input', keys)
|
||||
meths.nvim_input(keys)
|
||||
-- give nvim some time to process msgpack requests before possibly sending
|
||||
-- more key presses - otherwise they all pile up in the queue and get
|
||||
-- processed at once
|
||||
@@ -37,7 +37,7 @@ local function open(activate, lines)
|
||||
local filename = helpers.tmpname()
|
||||
write_file(filename, table.concat(lines, '\n') .. '\n', true)
|
||||
command('edit ' .. filename)
|
||||
local b = nvim('get_current_buf')
|
||||
local b = meths.nvim_get_current_buf()
|
||||
-- what is the value of b:changedtick?
|
||||
local tick = eval('b:changedtick')
|
||||
|
||||
@@ -45,7 +45,7 @@ local function open(activate, lines)
|
||||
-- arrive as expected
|
||||
if activate then
|
||||
local firstline = 0
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
expectn('nvim_buf_lines_event', { b, tick, firstline, -1, lines, false })
|
||||
end
|
||||
|
||||
@@ -62,12 +62,12 @@ local function editoriginal(activate, lines)
|
||||
end
|
||||
|
||||
local function reopen(buf, expectedlines)
|
||||
ok(buffer('detach', buf))
|
||||
ok(meths.nvim_buf_detach(buf))
|
||||
expectn('nvim_buf_detach_event', { buf })
|
||||
-- for some reason the :edit! increments tick by 2
|
||||
command('edit!')
|
||||
local tick = eval('b:changedtick')
|
||||
ok(buffer('attach', buf, true, {}))
|
||||
ok(meths.nvim_buf_attach(buf, true, {}))
|
||||
local firstline = 0
|
||||
expectn('nvim_buf_lines_event', { buf, tick, firstline, -1, expectedlines, false })
|
||||
command('normal! gg')
|
||||
@@ -197,21 +197,21 @@ describe('API: buffer events:', function()
|
||||
-- add a line at the start of an empty file
|
||||
command('enew')
|
||||
tick = eval('b:changedtick')
|
||||
local b2 = nvim('get_current_buf')
|
||||
ok(buffer('attach', b2, true, {}))
|
||||
local b2 = meths.nvim_get_current_buf()
|
||||
ok(meths.nvim_buf_attach(b2, true, {}))
|
||||
expectn('nvim_buf_lines_event', { b2, tick, 0, -1, { '' }, false })
|
||||
eval('append(0, ["new line 1"])')
|
||||
tick = tick + 1
|
||||
expectn('nvim_buf_lines_event', { b2, tick, 0, 0, { 'new line 1' }, false })
|
||||
|
||||
-- turn off buffer events manually
|
||||
buffer('detach', b2)
|
||||
meths.nvim_buf_detach(b2)
|
||||
expectn('nvim_buf_detach_event', { b2 })
|
||||
|
||||
-- add multiple lines to a blank file
|
||||
command('enew!')
|
||||
local b3 = nvim('get_current_buf')
|
||||
ok(buffer('attach', b3, true, {}))
|
||||
local b3 = meths.nvim_get_current_buf()
|
||||
ok(meths.nvim_buf_attach(b3, true, {}))
|
||||
tick = eval('b:changedtick')
|
||||
expectn('nvim_buf_lines_event', { b3, tick, 0, -1, { '' }, false })
|
||||
eval('append(0, ["new line 1", "new line 2", "new line 3"])')
|
||||
@@ -222,7 +222,7 @@ describe('API: buffer events:', function()
|
||||
)
|
||||
|
||||
-- use the API itself to add a line to the start of the buffer
|
||||
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
|
||||
expectn('nvim_buf_lines_event', { b3, tick, 0, 0, { 'New First Line' }, false })
|
||||
end)
|
||||
@@ -306,8 +306,8 @@ describe('API: buffer events:', function()
|
||||
command('bdelete!')
|
||||
tick = 2
|
||||
expectn('nvim_buf_detach_event', { b })
|
||||
local bnew = nvim('get_current_buf')
|
||||
ok(buffer('attach', bnew, true, {}))
|
||||
local bnew = meths.nvim_get_current_buf()
|
||||
ok(meths.nvim_buf_attach(bnew, true, {}))
|
||||
expectn('nvim_buf_lines_event', { bnew, tick, 0, -1, { '' }, false })
|
||||
sendkeys('i')
|
||||
sendkeys('h')
|
||||
@@ -472,25 +472,25 @@ describe('API: buffer events:', function()
|
||||
end)
|
||||
|
||||
it('does not get confused if enabled/disabled many times', function()
|
||||
local channel = nvim('get_api_info')[1]
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
local b, tick = editoriginal(false)
|
||||
|
||||
-- Enable buffer events many times.
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(buffer('attach', b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
expectn('nvim_buf_lines_event', { b, tick, 0, -1, origlines, false })
|
||||
eval('rpcnotify(' .. channel .. ', "Hello There")')
|
||||
expectn('Hello There', {})
|
||||
|
||||
-- Disable buffer events many times.
|
||||
ok(buffer('detach', b))
|
||||
ok(buffer('detach', b))
|
||||
ok(buffer('detach', b))
|
||||
ok(buffer('detach', b))
|
||||
ok(buffer('detach', b))
|
||||
ok(meths.nvim_buf_detach(b))
|
||||
ok(meths.nvim_buf_detach(b))
|
||||
ok(meths.nvim_buf_detach(b))
|
||||
ok(meths.nvim_buf_detach(b))
|
||||
ok(meths.nvim_buf_detach(b))
|
||||
expectn('nvim_buf_detach_event', { b })
|
||||
eval('rpcnotify(' .. channel .. ', "Hello Again")')
|
||||
expectn('Hello Again', {})
|
||||
@@ -573,7 +573,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it('works with :diffput and :diffget', function()
|
||||
local b1, tick1 = editoriginal(true, { 'AAA', 'BBB' })
|
||||
local channel = nvim('get_api_info')[1]
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
command('diffthis')
|
||||
command('rightbelow vsplit')
|
||||
local b2, tick2 = open(true, { 'BBB', 'CCC' })
|
||||
@@ -690,7 +690,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it('detaches if the buffer is closed', function()
|
||||
local b, tick = editoriginal(true, { 'AAA' })
|
||||
local channel = nvim('get_api_info')[1]
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
|
||||
-- Test that buffer events are working.
|
||||
command('normal! x')
|
||||
@@ -729,7 +729,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it(':enew! does not detach hidden buffer', function()
|
||||
local b, tick = editoriginal(true, { 'AAA', 'BBB' })
|
||||
local channel = nvim('get_api_info')[1]
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
|
||||
command('set undoreload=1 hidden')
|
||||
command('normal! x')
|
||||
@@ -743,7 +743,7 @@ describe('API: buffer events:', function()
|
||||
|
||||
it('stays attached if the buffer is hidden', function()
|
||||
local b, tick = editoriginal(true, { 'AAA' })
|
||||
local channel = nvim('get_api_info')[1]
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
|
||||
-- Test that buffer events are working.
|
||||
command('normal! x')
|
||||
@@ -790,14 +790,14 @@ describe('API: buffer events:', function()
|
||||
it('does not send the buffer content if not requested', function()
|
||||
clear()
|
||||
local b, tick = editoriginal(false)
|
||||
ok(buffer('attach', b, false, {}))
|
||||
ok(meths.nvim_buf_attach(b, false, {}))
|
||||
expectn('nvim_buf_changedtick_event', { b, tick })
|
||||
end)
|
||||
|
||||
it('returns a proper error on nonempty options dict', function()
|
||||
clear()
|
||||
local b = editoriginal(false)
|
||||
eq("Invalid key: 'builtin'", pcall_err(buffer, 'attach', b, false, { builtin = 'asfd' }))
|
||||
eq("Invalid key: 'builtin'", pcall_err(meths.nvim_buf_attach, b, false, { builtin = 'asfd' }))
|
||||
end)
|
||||
|
||||
it('nvim_buf_attach returns response after delay #8634', function()
|
||||
@@ -873,8 +873,8 @@ describe('API: buffer events:', function()
|
||||
env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
|
||||
})
|
||||
|
||||
local b = nvim('get_current_buf')
|
||||
ok(buffer('attach', b, true, {}))
|
||||
local b = meths.nvim_get_current_buf()
|
||||
ok(meths.nvim_buf_attach(b, true, {}))
|
||||
|
||||
for _ = 1, 22 do
|
||||
table.insert(expected_lines, '~')
|
||||
|
||||
@@ -3,10 +3,8 @@ local helpers = require('test.functional.helpers')(after_each)
|
||||
local NIL = vim.NIL
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local eq = helpers.eq
|
||||
local meths = helpers.meths
|
||||
local bufmeths = helpers.bufmeths
|
||||
local matches = helpers.matches
|
||||
local source = helpers.source
|
||||
local pcall_err = helpers.pcall_err
|
||||
@@ -74,16 +72,16 @@ describe('nvim_get_commands', function()
|
||||
it('gets buffer-local user-defined commands', function()
|
||||
-- Define a buffer-local command.
|
||||
command('command -buffer -nargs=1 Hello echo "Hello World"')
|
||||
eq({ Hello = cmd_dict }, curbufmeths.get_commands({ builtin = false }))
|
||||
eq({ Hello = cmd_dict }, meths.nvim_buf_get_commands(0, { builtin = false }))
|
||||
-- Define another buffer-local command.
|
||||
command('command -buffer -nargs=? Pwd pwd')
|
||||
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, curbufmeths.get_commands({ builtin = false }))
|
||||
eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, meths.nvim_buf_get_commands(0, { builtin = false }))
|
||||
-- Delete a command.
|
||||
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.
|
||||
eq({}, curbufmeths.get_commands({ builtin = true }))
|
||||
eq({}, meths.nvim_buf_get_commands(0, { builtin = true }))
|
||||
end)
|
||||
|
||||
it('gets various command attributes', function()
|
||||
@@ -203,7 +201,7 @@ describe('nvim_create_user_command', function()
|
||||
|
||||
it('works with strings', function()
|
||||
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'))
|
||||
end)
|
||||
|
||||
@@ -647,10 +645,10 @@ describe('nvim_create_user_command', function()
|
||||
|
||||
it('can define buffer-local commands', function()
|
||||
local bufnr = meths.nvim_create_buf(false, false)
|
||||
bufmeths.create_user_command(bufnr, 'Hello', '', {})
|
||||
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello'))
|
||||
meths.nvim_buf_create_user_command(bufnr, 'Hello', '', {})
|
||||
matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
|
||||
meths.nvim_set_current_buf(bufnr)
|
||||
meths.nvim_command('Hello')
|
||||
command('Hello')
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
@@ -762,15 +760,15 @@ describe('nvim_del_user_command', function()
|
||||
|
||||
it('can delete global commands', function()
|
||||
meths.nvim_create_user_command('Hello', 'echo "Hi"', {})
|
||||
meths.nvim_command('Hello')
|
||||
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)
|
||||
|
||||
it('can delete buffer-local commands', function()
|
||||
bufmeths.create_user_command(0, 'Hello', 'echo "Hi"', {})
|
||||
meths.nvim_command('Hello')
|
||||
bufmeths.del_user_command(0, 'Hello')
|
||||
matches('Not an editor command: Hello', pcall_err(meths.nvim_command, 'Hello'))
|
||||
meths.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {})
|
||||
command('Hello')
|
||||
meths.nvim_buf_del_user_command(0, 'Hello')
|
||||
matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -4,8 +4,6 @@ local Screen = require('test.functional.ui.screen')
|
||||
local request = helpers.request
|
||||
local eq = helpers.eq
|
||||
local ok = helpers.ok
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local bufmeths = helpers.bufmeths
|
||||
local pcall_err = helpers.pcall_err
|
||||
local insert = helpers.insert
|
||||
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
|
||||
opts.id = id
|
||||
end
|
||||
return curbufmeths.set_extmark(ns_id, line, col, opts)
|
||||
return meths.nvim_buf_set_extmark(0, ns_id, line, col, opts)
|
||||
end
|
||||
|
||||
local function get_extmarks(ns_id, start, end_, opts)
|
||||
if opts == nil then
|
||||
opts = {}
|
||||
end
|
||||
return curbufmeths.get_extmarks(ns_id, start, end_, opts)
|
||||
return meths.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
|
||||
end
|
||||
|
||||
local function get_extmark_by_id(ns_id, id, opts)
|
||||
if opts == nil then
|
||||
opts = {}
|
||||
end
|
||||
return curbufmeths.get_extmark_by_id(ns_id, id, opts)
|
||||
return meths.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
|
||||
end
|
||||
|
||||
local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
|
||||
@@ -198,11 +196,11 @@ describe('API/extmarks', function()
|
||||
eq({ row, col }, rv)
|
||||
|
||||
-- remove the test marks
|
||||
eq(true, curbufmeths.del_extmark(ns, marks[1]))
|
||||
eq(false, curbufmeths.del_extmark(ns, marks[1]))
|
||||
eq(true, curbufmeths.del_extmark(ns, marks[2]))
|
||||
eq(false, curbufmeths.del_extmark(ns, marks[3]))
|
||||
eq(false, curbufmeths.del_extmark(ns, 1000))
|
||||
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[1]))
|
||||
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[1]))
|
||||
eq(true, meths.nvim_buf_del_extmark(0, ns, marks[2]))
|
||||
eq(false, meths.nvim_buf_del_extmark(0, ns, marks[3]))
|
||||
eq(false, meths.nvim_buf_del_extmark(0, ns, 1000))
|
||||
end)
|
||||
|
||||
it('can clear a specific namespace range', function()
|
||||
@@ -210,7 +208,7 @@ describe('API/extmarks', function()
|
||||
set_extmark(ns2, 1, 0, 1)
|
||||
-- force a new undo buffer
|
||||
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({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
|
||||
feed('u')
|
||||
@@ -226,7 +224,7 @@ describe('API/extmarks', function()
|
||||
set_extmark(ns2, 1, 0, 1)
|
||||
-- force a new undo buffer
|
||||
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(ns2, { 0, 0 }, { -1, -1 }))
|
||||
feed('u')
|
||||
@@ -244,14 +242,14 @@ describe('API/extmarks', function()
|
||||
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
|
||||
feed('dd')
|
||||
eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
|
||||
curbufmeths.clear_namespace(ns, 0, -1)
|
||||
meths.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||
eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
|
||||
set_extmark(ns, 1, 0, 0, { right_gravity = false })
|
||||
set_extmark(ns, 2, 1, 0, { right_gravity = false })
|
||||
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
|
||||
feed('u')
|
||||
eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
|
||||
curbufmeths.clear_namespace(ns, 0, -1)
|
||||
meths.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||
end)
|
||||
|
||||
it('querying for information and ranges', function()
|
||||
@@ -933,7 +931,7 @@ describe('API/extmarks', function()
|
||||
|
||||
-- Test unset
|
||||
feed('o<esc>')
|
||||
curbufmeths.del_extmark(ns, marks[3])
|
||||
meths.nvim_buf_del_extmark(0, ns, marks[3])
|
||||
feed('u')
|
||||
rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
|
||||
-- undo does NOT restore deleted marks
|
||||
@@ -989,10 +987,10 @@ describe('API/extmarks', function()
|
||||
rv = get_extmarks(ns2, positions[2], positions[1])
|
||||
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 })
|
||||
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 })
|
||||
eq(2, #rv)
|
||||
end)
|
||||
@@ -1429,7 +1427,7 @@ describe('API/extmarks', function()
|
||||
"Invalid 'ns_id': 3",
|
||||
pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
|
||||
)
|
||||
eq("Invalid 'ns_id': 3", pcall_err(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_extmark_by_id, ns_invalid, marks[1]))
|
||||
end)
|
||||
@@ -1480,8 +1478,8 @@ describe('API/extmarks', function()
|
||||
it('can set a mark to other buffer', function()
|
||||
local buf = request('nvim_create_buf', 0, 1)
|
||||
request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
|
||||
local id = bufmeths.set_extmark(buf, ns, 1, 0, {})
|
||||
eq({ { id, 1, 0 } }, bufmeths.get_extmarks(buf, ns, 0, -1, {}))
|
||||
local id = meths.nvim_buf_set_extmark(buf, ns, 1, 0, {})
|
||||
eq({ { id, 1, 0 } }, meths.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
|
||||
end)
|
||||
|
||||
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()
|
||||
-- right gravity should move with inserted text, while
|
||||
-- left gravity should stay in place.
|
||||
curbufmeths.set_extmark(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 = false })
|
||||
meths.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
|
||||
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
|
||||
feed([[<esc>Iasdf<esc>]])
|
||||
-- eq({}, curbufmeths.get_lines(0, -1, true))
|
||||
eq({ { 1, 0, 9 }, { 2, 0, 17 } }, curbufmeths.get_extmarks(ns, 0, -1, {}))
|
||||
-- eq({}, meths.nvim_buf_get_lines(0, 0, -1, true))
|
||||
eq({ { 1, 0, 9 }, { 2, 0, 17 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
|
||||
|
||||
-- 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
|
||||
eq({ { 1, 0, 0 }, { 2, 0, 0 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
|
||||
curbufmeths.set_text(0, 0, 0, 0, { 'asdfasdf' })
|
||||
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, curbufmeths.get_extmarks(ns, 0, -1, {}))
|
||||
meths.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
|
||||
eq({ { 1, 0, 0 }, { 2, 0, 8 } }, meths.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
|
||||
|
||||
feed('u')
|
||||
-- handles pasting
|
||||
@@ -1641,7 +1639,7 @@ describe('API/extmarks', function()
|
||||
right_gravity = 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
|
||||
command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
|
||||
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
|
||||
lines[#lines + 1] = string.rep('x ', i)
|
||||
end
|
||||
curbufmeths.set_lines(0, -1, true, lines)
|
||||
meths.nvim_buf_set_lines(0, 0, -1, true, lines)
|
||||
local ns = ns1
|
||||
local q = 0
|
||||
for i = 0, 29 do
|
||||
@@ -1804,16 +1802,16 @@ describe('Extmarks buffer api with many marks', function()
|
||||
end)
|
||||
|
||||
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(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(ns2))
|
||||
end)
|
||||
|
||||
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
|
||||
if 10 <= mark[1] and mark[1] < 20 then
|
||||
ns_marks[ns1][id] = nil
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 eq, eval = helpers.eq, helpers.eval
|
||||
local command = helpers.command
|
||||
@@ -52,22 +52,22 @@ describe('API: highlight', function()
|
||||
|
||||
it('nvim_get_hl_by_id', function()
|
||||
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')")
|
||||
-- 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.
|
||||
eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false))
|
||||
|
||||
-- Test all highlight properties.
|
||||
command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
|
||||
eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true))
|
||||
eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true))
|
||||
|
||||
-- Test 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.
|
||||
eq(
|
||||
@@ -102,14 +102,14 @@ describe('API: highlight', function()
|
||||
local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red }
|
||||
|
||||
-- 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_rgb, nvim('get_hl_by_name', 'NewHighlight', true))
|
||||
eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false))
|
||||
eq(expected_rgb, meths.nvim_get_hl_by_name('NewHighlight', true))
|
||||
|
||||
-- Test `Normal` modified values.
|
||||
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.
|
||||
eq(
|
||||
@@ -137,10 +137,10 @@ describe('API: highlight', function()
|
||||
meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 })
|
||||
meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true })
|
||||
-- Note colors are "cterm" values, not rgb-as-ints
|
||||
eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false))
|
||||
eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false))
|
||||
eq(
|
||||
{ foreground = 17, background = 213, nocombine = true },
|
||||
nvim('get_hl_by_name', 'NotNormal', false)
|
||||
meths.nvim_get_hl_by_name('NotNormal', false)
|
||||
)
|
||||
end)
|
||||
|
||||
@@ -378,7 +378,7 @@ describe('API: set highlight', function()
|
||||
it("correctly sets 'Normal' internal properties", function()
|
||||
-- Normal has some special handling internally. #18024
|
||||
meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' })
|
||||
eq({ foreground = 131, background = 243 }, nvim('get_hl_by_name', 'Normal', true))
|
||||
eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true))
|
||||
end)
|
||||
|
||||
it('does not segfault on invalid group name #20009', function()
|
||||
@@ -475,7 +475,7 @@ describe('API: get highlight', function()
|
||||
end)
|
||||
|
||||
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'))
|
||||
meths.nvim_get_hl(0, { name = 'Bar', create = true })
|
||||
eq(1, funcs.hlexists('Bar'))
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
|
||||
local bufmeths = helpers.bufmeths
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local eq, neq = helpers.eq, helpers.neq
|
||||
local exec_lua = helpers.exec_lua
|
||||
local exec = helpers.exec
|
||||
@@ -112,7 +110,7 @@ describe('nvim_get_keymap', function()
|
||||
|
||||
-- The buffer mapping should not show up
|
||||
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)
|
||||
|
||||
it('considers scope for overlapping maps', function()
|
||||
@@ -124,11 +122,11 @@ describe('nvim_get_keymap', function()
|
||||
command('nnoremap <buffer> foo bar')
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
-- and set hidden so we can leave them
|
||||
command('set hidden')
|
||||
@@ -137,7 +135,7 @@ describe('nvim_get_keymap', function()
|
||||
command('new')
|
||||
command('normal! ihello 3')
|
||||
|
||||
local final_buffer = curbufmeths.get_number()
|
||||
local final_buffer = meths.nvim_buf_get_number(0)
|
||||
|
||||
command('nnoremap <buffer> foo bar')
|
||||
-- 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'))
|
||||
|
||||
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
|
||||
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'))
|
||||
end)
|
||||
|
||||
@@ -209,7 +207,7 @@ describe('nvim_get_keymap', function()
|
||||
function()
|
||||
make_new_windows(new_windows)
|
||||
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)
|
||||
end
|
||||
)
|
||||
@@ -246,7 +244,7 @@ describe('nvim_get_keymap', function()
|
||||
make_new_windows(new_windows)
|
||||
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)
|
||||
end
|
||||
)
|
||||
@@ -290,7 +288,7 @@ describe('nvim_get_keymap', function()
|
||||
|
||||
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('testing', meths.nvim_call_function('<SNR>' .. sid_result .. '_maparg_test_function', {}))
|
||||
end)
|
||||
@@ -698,33 +696,33 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
it('can set mappings whose RHS is a <Nop>', function()
|
||||
meths.nvim_set_keymap('i', 'lhs', '<Nop>', {})
|
||||
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'))
|
||||
|
||||
-- also test for case insensitivity
|
||||
meths.nvim_set_keymap('i', 'lhs', '<nOp>', {})
|
||||
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
|
||||
-- provided by the user
|
||||
eq(generate_mapargs('i', 'lhs', '<nOp>', {}), get_mapargs('i', 'lhs'))
|
||||
|
||||
meths.nvim_set_keymap('i', 'lhs', '<NOP>', {})
|
||||
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'))
|
||||
|
||||
-- a single ^V in RHS is also <Nop> (see :h map-empty-rhs)
|
||||
meths.nvim_set_keymap('i', 'lhs', '\022', {})
|
||||
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'))
|
||||
end)
|
||||
|
||||
it('treats an empty RHS in a mapping like a <Nop>', function()
|
||||
meths.nvim_set_keymap('i', 'lhs', '', {})
|
||||
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'))
|
||||
end)
|
||||
|
||||
@@ -743,7 +741,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
command([[call nvim_set_keymap('i', "\<space>", "\<tab>", {})]])
|
||||
eq(generate_mapargs('i', '<Space>', '\t', { sid = 0 }), get_mapargs('i', '<Space>'))
|
||||
feed('i ')
|
||||
eq({ '\t' }, curbufmeths.get_lines(0, -1, 0))
|
||||
eq({ '\t' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
|
||||
end
|
||||
)
|
||||
|
||||
@@ -772,12 +770,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
|
||||
meths.nvim_set_keymap('i', 'lhs', 'FlipFlop()', { expr = true })
|
||||
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 ilhs')
|
||||
eq({ '0' }, curbufmeths.get_lines(0, -1, 0))
|
||||
eq({ '0' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
|
||||
end)
|
||||
|
||||
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', {})
|
||||
|
||||
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 ilhs')
|
||||
eq({ 'rhs' }, curbufmeths.get_lines(0, -1, 0))
|
||||
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
|
||||
end)
|
||||
|
||||
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 })
|
||||
|
||||
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 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)
|
||||
|
||||
it('can set nowait mappings that fire without waiting', function()
|
||||
@@ -817,7 +815,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
|
||||
feed(c)
|
||||
sleep(5)
|
||||
end
|
||||
eq({ 'shorter456' }, curbufmeths.get_lines(0, -1, 0))
|
||||
eq({ 'shorter456' }, meths.nvim_buf_get_lines(0, 0, -1, 0))
|
||||
end)
|
||||
|
||||
-- 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()
|
||||
eq(
|
||||
'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)
|
||||
|
||||
it('can set mappings active in the current buffer but not others', function()
|
||||
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')
|
||||
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
|
||||
switch_to_buf(second)
|
||||
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
|
||||
switch_to_buf(first)
|
||||
command('normal ^lhs')
|
||||
eq({ 'rhsrhs' }, bufmeths.get_lines(0, 0, 1, 1))
|
||||
eq({ 'rhsrhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
|
||||
end)
|
||||
|
||||
it('can set local mappings in buffer other than current', function()
|
||||
local first = make_two_buffers(false)
|
||||
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
|
||||
-- shouldn't do anything
|
||||
command('normal lhs')
|
||||
eq({ '' }, bufmeths.get_lines(0, 0, 1, 1))
|
||||
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
|
||||
|
||||
-- should take effect
|
||||
switch_to_buf(first)
|
||||
command('normal lhs')
|
||||
eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1))
|
||||
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
|
||||
end)
|
||||
|
||||
it('can disable mappings made in another buffer, inside that buffer', function()
|
||||
local first = make_two_buffers(false)
|
||||
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
bufmeths.del_keymap(first, '', 'lhs')
|
||||
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
meths.nvim_buf_del_keymap(first, '', 'lhs')
|
||||
switch_to_buf(first)
|
||||
|
||||
-- shouldn't do anything
|
||||
command('normal lhs')
|
||||
eq({ '' }, bufmeths.get_lines(0, 0, 1, 1))
|
||||
eq({ '' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
|
||||
end)
|
||||
|
||||
it("can't disable mappings given wrong buffer handle", function()
|
||||
local first, second = make_two_buffers(false)
|
||||
bufmeths.set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
eq('E31: No such mapping', pcall_err(bufmeths.del_keymap, second, '', 'lhs'))
|
||||
meths.nvim_buf_set_keymap(first, '', 'lhs', 'irhs<Esc>', {})
|
||||
eq('E31: No such mapping', pcall_err(meths.nvim_buf_del_keymap, second, '', 'lhs'))
|
||||
|
||||
-- should still work
|
||||
switch_to_buf(first)
|
||||
command('normal lhs')
|
||||
eq({ 'rhs' }, bufmeths.get_lines(0, 0, 1, 1))
|
||||
eq({ 'rhs' }, meths.nvim_buf_get_lines(0, 0, 1, 1))
|
||||
end)
|
||||
|
||||
it('does not crash when setting mapping in a non-existing buffer #13541', function()
|
||||
pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
|
||||
pcall_err(meths.nvim_buf_set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
|
||||
helpers.assert_alive()
|
||||
end)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local assert_log = helpers.assert_log
|
||||
local eq, clear, eval, command, nvim, next_msg =
|
||||
helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.nvim, helpers.next_msg
|
||||
local eq, clear, eval, command, next_msg =
|
||||
helpers.eq, helpers.clear, helpers.eval, helpers.command, helpers.next_msg
|
||||
local meths = helpers.meths
|
||||
local exec_lua = helpers.exec_lua
|
||||
local retry = helpers.retry
|
||||
@@ -14,7 +14,7 @@ describe('notify', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
channel = nvim('get_api_info')[1]
|
||||
channel = meths.nvim_get_api_info()[1]
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
@@ -33,14 +33,14 @@ describe('notify', function()
|
||||
|
||||
describe('passing 0 as the channel id', 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, "event2", 4, 5, 6)')
|
||||
eval('rpcnotify(0, "event2", 7, 8, 9)')
|
||||
eq({ 'notification', 'event2', { 4, 5, 6 } }, next_msg())
|
||||
eq({ 'notification', 'event2', { 7, 8, 9 } }, next_msg())
|
||||
nvim('unsubscribe', 'event2')
|
||||
nvim('subscribe', 'event1')
|
||||
meths.nvim_unsubscribe('event2')
|
||||
meths.nvim_subscribe('event1')
|
||||
eval('rpcnotify(0, "event2", 10, 11, 12)')
|
||||
eval('rpcnotify(0, "event1", 13, 14, 15)')
|
||||
eq({ 'notification', 'event1', { 13, 14, 15 } }, next_msg())
|
||||
@@ -49,9 +49,7 @@ describe('notify', function()
|
||||
it('does not crash for deeply nested variable', function()
|
||||
meths.nvim_set_var('l', {})
|
||||
local nest_level = 1000
|
||||
meths.nvim_command(
|
||||
('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1)
|
||||
)
|
||||
command(('call map(range(%u), "extend(g:, {\'l\': [g:l]})")'):format(nest_level - 1))
|
||||
eval('rpcnotify(' .. channel .. ', "event", g:l)')
|
||||
local msg = next_msg()
|
||||
eq('notification', msg[1])
|
||||
@@ -81,10 +79,10 @@ describe('notify', function()
|
||||
clear { env = {
|
||||
NVIM_LOG_FILE = testlog,
|
||||
} }
|
||||
nvim('subscribe', 'event1')
|
||||
nvim('unsubscribe', 'doesnotexist')
|
||||
meths.nvim_subscribe('event1')
|
||||
meths.nvim_unsubscribe('doesnotexist')
|
||||
assert_log("tried to unsubscribe unknown event 'doesnotexist'", testlog, 10)
|
||||
nvim('unsubscribe', 'event1')
|
||||
meths.nvim_unsubscribe('event1')
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
-- `rpcrequest` calls we need the client event loop to be running.
|
||||
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 nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs
|
||||
local source, next_msg = helpers.source, helpers.next_msg
|
||||
@@ -18,7 +18,7 @@ describe('server -> client', function()
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
cid = nvim('get_api_info')[1]
|
||||
cid = meths.nvim_get_api_info()[1]
|
||||
end)
|
||||
|
||||
it('handles unexpected closed stream while preparing RPC response', function()
|
||||
@@ -47,7 +47,7 @@ describe('server -> client', function()
|
||||
local function on_request(method, args)
|
||||
eq('scall', method)
|
||||
eq({ 1, 2, 3 }, args)
|
||||
nvim('command', 'let g:result = [4, 5, 6]')
|
||||
command('let g:result = [4, 5, 6]')
|
||||
return eval('g:result')
|
||||
end
|
||||
run(on_request, nil, on_setup)
|
||||
@@ -77,15 +77,15 @@ describe('server -> client', function()
|
||||
describe('recursive call', function()
|
||||
it('works', function()
|
||||
local function on_setup()
|
||||
nvim('set_var', 'result1', 0)
|
||||
nvim('set_var', 'result2', 0)
|
||||
nvim('set_var', 'result3', 0)
|
||||
nvim('set_var', 'result4', 0)
|
||||
nvim('command', 'let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)')
|
||||
eq(4, nvim('get_var', 'result1'))
|
||||
eq(8, nvim('get_var', 'result2'))
|
||||
eq(16, nvim('get_var', 'result3'))
|
||||
eq(32, nvim('get_var', 'result4'))
|
||||
meths.nvim_set_var('result1', 0)
|
||||
meths.nvim_set_var('result2', 0)
|
||||
meths.nvim_set_var('result3', 0)
|
||||
meths.nvim_set_var('result4', 0)
|
||||
command('let g:result1 = rpcrequest(' .. cid .. ', "rcall", 2)')
|
||||
eq(4, meths.nvim_get_var('result1'))
|
||||
eq(8, meths.nvim_get_var('result2'))
|
||||
eq(16, meths.nvim_get_var('result3'))
|
||||
eq(32, meths.nvim_get_var('result4'))
|
||||
stop()
|
||||
end
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('server -> client', function()
|
||||
elseif n == 16 then
|
||||
cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')'
|
||||
end
|
||||
nvim('command', cmd)
|
||||
command(cmd)
|
||||
end
|
||||
return n
|
||||
end
|
||||
@@ -195,10 +195,10 @@ describe('server -> client', function()
|
||||
end)
|
||||
|
||||
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.
|
||||
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')"))
|
||||
end)
|
||||
@@ -212,7 +212,7 @@ describe('server -> client', function()
|
||||
eq(1, buf)
|
||||
|
||||
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)'))
|
||||
|
||||
@@ -231,8 +231,8 @@ describe('server -> client', function()
|
||||
describe('jobstart()', function()
|
||||
local jobid
|
||||
before_each(function()
|
||||
local channel = nvim('get_api_info')[1]
|
||||
nvim('set_var', 'channel', channel)
|
||||
local channel = meths.nvim_get_api_info()[1]
|
||||
meths.nvim_set_var('channel', channel)
|
||||
source([[
|
||||
function! s:OnEvent(id, data, event)
|
||||
call rpcnotify(g:channel, a:event, 0, a:data)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local clear, nvim, tabpage, curtab, eq, ok =
|
||||
helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq, helpers.ok
|
||||
local curtabmeths = helpers.curtabmeths
|
||||
local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok
|
||||
local meths = helpers.meths
|
||||
local funcs = helpers.funcs
|
||||
local request = helpers.request
|
||||
local NIL = vim.NIL
|
||||
@@ -13,35 +12,35 @@ describe('api/tabpage', function()
|
||||
|
||||
describe('list_wins and get_win', function()
|
||||
it('works', function()
|
||||
nvim('command', 'tabnew')
|
||||
nvim('command', 'vsplit')
|
||||
local tab1, tab2 = unpack(nvim('list_tabpages'))
|
||||
local win1, win2, win3 = unpack(nvim('list_wins'))
|
||||
eq({ win1 }, tabpage('list_wins', tab1))
|
||||
eq({ win2, win3 }, tabpage('list_wins', tab2))
|
||||
eq(win2, tabpage('get_win', tab2))
|
||||
nvim('set_current_win', win3)
|
||||
eq(win3, tabpage('get_win', tab2))
|
||||
helpers.command('tabnew')
|
||||
helpers.command('vsplit')
|
||||
local tab1, tab2 = unpack(meths.nvim_list_tabpages())
|
||||
local win1, win2, win3 = unpack(meths.nvim_list_wins())
|
||||
eq({ win1 }, meths.nvim_tabpage_list_wins(tab1))
|
||||
eq({ win2, win3 }, meths.nvim_tabpage_list_wins(tab2))
|
||||
eq(win2, meths.nvim_tabpage_get_win(tab2))
|
||||
meths.nvim_set_current_win(win3)
|
||||
eq(win3, meths.nvim_tabpage_get_win(tab2))
|
||||
end)
|
||||
|
||||
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)
|
||||
|
||||
describe('{get,set,del}_var', function()
|
||||
it('works', function()
|
||||
curtab('set_var', 'lua', { 1, 2, { ['3'] = 1 } })
|
||||
eq({ 1, 2, { ['3'] = 1 } }, curtab('get_var', 'lua'))
|
||||
eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 't:lua'))
|
||||
meths.nvim_tabpage_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
|
||||
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_tabpage_get_var(0, 'lua'))
|
||||
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('t:lua'))
|
||||
eq(1, funcs.exists('t:lua'))
|
||||
curtabmeths.del_var('lua')
|
||||
meths.nvim_tabpage_del_var(0, 'lua')
|
||||
eq(0, funcs.exists('t:lua'))
|
||||
eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua'))
|
||||
curtabmeths.set_var('lua', 1)
|
||||
eq('Key not found: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua'))
|
||||
meths.nvim_tabpage_set_var(0, 'lua', 1)
|
||||
command('lockvar t:lua')
|
||||
eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua'))
|
||||
eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1))
|
||||
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_del_var, 0, 'lua'))
|
||||
eq('Key is locked: lua', pcall_err(meths.nvim_tabpage_set_var, 0, 'lua', 1))
|
||||
end)
|
||||
|
||||
it('tabpage_set_var returns the old value', function()
|
||||
@@ -62,28 +61,28 @@ describe('api/tabpage', function()
|
||||
|
||||
describe('get_number', function()
|
||||
it('works', function()
|
||||
local tabs = nvim('list_tabpages')
|
||||
eq(1, tabpage('get_number', tabs[1]))
|
||||
local tabs = meths.nvim_list_tabpages()
|
||||
eq(1, meths.nvim_tabpage_get_number(tabs[1]))
|
||||
|
||||
nvim('command', 'tabnew')
|
||||
local tab1, tab2 = unpack(nvim('list_tabpages'))
|
||||
eq(1, tabpage('get_number', tab1))
|
||||
eq(2, tabpage('get_number', tab2))
|
||||
helpers.command('tabnew')
|
||||
local tab1, tab2 = unpack(meths.nvim_list_tabpages())
|
||||
eq(1, meths.nvim_tabpage_get_number(tab1))
|
||||
eq(2, meths.nvim_tabpage_get_number(tab2))
|
||||
|
||||
nvim('command', '-tabmove')
|
||||
eq(2, tabpage('get_number', tab1))
|
||||
eq(1, tabpage('get_number', tab2))
|
||||
helpers.command('-tabmove')
|
||||
eq(2, meths.nvim_tabpage_get_number(tab1))
|
||||
eq(1, meths.nvim_tabpage_get_number(tab2))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('is_valid', function()
|
||||
it('works', function()
|
||||
nvim('command', 'tabnew')
|
||||
local tab = nvim('list_tabpages')[2]
|
||||
nvim('set_current_tabpage', tab)
|
||||
ok(tabpage('is_valid', tab))
|
||||
nvim('command', 'tabclose')
|
||||
ok(not tabpage('is_valid', tab))
|
||||
helpers.command('tabnew')
|
||||
local tab = meths.nvim_list_tabpages()[2]
|
||||
meths.nvim_set_current_tabpage(tab)
|
||||
ok(meths.nvim_tabpage_is_valid(tab))
|
||||
helpers.command('tabclose')
|
||||
ok(not meths.nvim_tabpage_is_valid(tab))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,17 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
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.nvim,
|
||||
helpers.curbuf,
|
||||
helpers.meths.nvim_get_current_buf,
|
||||
helpers.curbuf_contents,
|
||||
helpers.window,
|
||||
helpers.curwin,
|
||||
helpers.meths.nvim_get_current_win,
|
||||
helpers.eq,
|
||||
helpers.neq,
|
||||
helpers.ok,
|
||||
helpers.feed,
|
||||
helpers.insert,
|
||||
helpers.eval,
|
||||
helpers.tabpage
|
||||
helpers.eval
|
||||
local poke_eventloop = helpers.poke_eventloop
|
||||
local curwinmeths = helpers.curwinmeths
|
||||
local exec = helpers.exec
|
||||
local funcs = helpers.funcs
|
||||
local request = helpers.request
|
||||
@@ -30,26 +26,35 @@ describe('API/win', function()
|
||||
|
||||
describe('get_buf', function()
|
||||
it('works', function()
|
||||
eq(curbuf(), window('get_buf', nvim('list_wins')[1]))
|
||||
nvim('command', 'new')
|
||||
nvim('set_current_win', nvim('list_wins')[2])
|
||||
eq(curbuf(), window('get_buf', nvim('list_wins')[2]))
|
||||
neq(window('get_buf', nvim('list_wins')[1]), window('get_buf', nvim('list_wins')[2]))
|
||||
eq(curbuf(), meths.nvim_win_get_buf(meths.nvim_list_wins()[1]))
|
||||
command('new')
|
||||
meths.nvim_set_current_win(meths.nvim_list_wins()[2])
|
||||
eq(curbuf(), meths.nvim_win_get_buf(meths.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)
|
||||
|
||||
describe('set_buf', function()
|
||||
it('works', function()
|
||||
nvim('command', 'new')
|
||||
local windows = nvim('list_wins')
|
||||
neq(window('get_buf', windows[2]), window('get_buf', windows[1]))
|
||||
window('set_buf', windows[2], window('get_buf', windows[1]))
|
||||
eq(window('get_buf', windows[2]), window('get_buf', windows[1]))
|
||||
command('new')
|
||||
local windows = meths.nvim_list_wins()
|
||||
neq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1]))
|
||||
meths.nvim_win_set_buf(windows[2], meths.nvim_win_get_buf(windows[1]))
|
||||
eq(meths.nvim_win_get_buf(windows[2]), meths.nvim_win_get_buf(windows[1]))
|
||||
end)
|
||||
|
||||
it('validates args', function()
|
||||
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
|
||||
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
|
||||
eq(
|
||||
'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)
|
||||
|
||||
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()
|
||||
it('works', function()
|
||||
eq({ 1, 0 }, curwin('get_cursor'))
|
||||
nvim('command', 'normal ityping\027o some text')
|
||||
eq({ 1, 0 }, meths.nvim_win_get_cursor(0))
|
||||
command('normal ityping\027o some text')
|
||||
eq('typing\n some text', curbuf_contents())
|
||||
eq({ 2, 10 }, curwin('get_cursor'))
|
||||
curwin('set_cursor', { 2, 6 })
|
||||
nvim('command', 'normal i dumb')
|
||||
eq({ 2, 10 }, meths.nvim_win_get_cursor(0))
|
||||
meths.nvim_win_set_cursor(0, { 2, 6 })
|
||||
command('normal i dumb')
|
||||
eq('typing\n some dumb text', curbuf_contents())
|
||||
end)
|
||||
|
||||
@@ -119,10 +124,10 @@ describe('API/win', function()
|
||||
]],
|
||||
}
|
||||
-- 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
|
||||
window('set_cursor', win, { 101, 0 })
|
||||
meths.nvim_win_set_cursor(win, { 101, 0 })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
|*7
|
||||
@@ -132,7 +137,7 @@ describe('API/win', function()
|
||||
}
|
||||
|
||||
-- move cursor to the beginning again
|
||||
window('set_cursor', win, { 1, 0 })
|
||||
meths.nvim_win_set_cursor(win, { 1, 0 })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^prologue |
|
||||
@@ -141,11 +146,11 @@ describe('API/win', function()
|
||||
}
|
||||
|
||||
-- move focus to new window
|
||||
nvim('command', 'new')
|
||||
command('new')
|
||||
neq(win, curwin())
|
||||
|
||||
-- sanity check, cursor position is kept
|
||||
eq({ 1, 0 }, window('get_cursor', win))
|
||||
eq({ 1, 0 }, meths.nvim_win_get_cursor(win))
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
@@ -159,7 +164,7 @@ describe('API/win', function()
|
||||
}
|
||||
|
||||
-- move cursor to end
|
||||
window('set_cursor', win, { 101, 0 })
|
||||
meths.nvim_win_set_cursor(win, { 101, 0 })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
@@ -173,7 +178,7 @@ describe('API/win', function()
|
||||
}
|
||||
|
||||
-- move cursor to the beginning again
|
||||
window('set_cursor', win, { 1, 0 })
|
||||
meths.nvim_win_set_cursor(win, { 1, 0 })
|
||||
screen:expect {
|
||||
grid = [[
|
||||
^ |
|
||||
@@ -200,17 +205,17 @@ describe('API/win', function()
|
||||
|
||||
-- cursor position is at beginning
|
||||
local win = curwin()
|
||||
eq({ 1, 0 }, window('get_cursor', win))
|
||||
eq({ 1, 0 }, meths.nvim_win_get_cursor(win))
|
||||
|
||||
-- move cursor to column 5
|
||||
window('set_cursor', win, { 1, 5 })
|
||||
meths.nvim_win_set_cursor(win, { 1, 5 })
|
||||
|
||||
-- move down a line
|
||||
feed('j')
|
||||
poke_eventloop() -- let nvim process the 'j' command
|
||||
|
||||
-- cursor is still in column 5
|
||||
eq({ 2, 5 }, window('get_cursor', win))
|
||||
eq({ 2, 5 }, meths.nvim_win_get_cursor(win))
|
||||
end)
|
||||
|
||||
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}|
|
||||
|
|
||||
]])
|
||||
window('set_cursor', oldwin, { 1, 0 })
|
||||
meths.nvim_win_set_cursor(oldwin, { 1, 0 })
|
||||
screen:expect([[
|
||||
aaa │{2:aaa }|
|
||||
bbb │bbb |
|
||||
@@ -278,7 +283,7 @@ describe('API/win', function()
|
||||
{3:[No Name] [+] }{4:[No Name] [+] }|
|
||||
|
|
||||
]])
|
||||
window('set_cursor', oldwin, { 2, 0 })
|
||||
meths.nvim_win_set_cursor(oldwin, { 2, 0 })
|
||||
screen:expect([[
|
||||
aa{2:a} │{2:a}aa |
|
||||
bb{2:b} │bbb |
|
||||
@@ -293,32 +298,35 @@ describe('API/win', function()
|
||||
|
||||
describe('{get,set}_height', function()
|
||||
it('works', function()
|
||||
nvim('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')
|
||||
command('vsplit')
|
||||
eq(
|
||||
window('get_height', nvim('list_wins')[2]),
|
||||
math.floor(window('get_height', nvim('list_wins')[1]) / 2)
|
||||
meths.nvim_win_get_height(meths.nvim_list_wins()[2]),
|
||||
meths.nvim_win_get_height(meths.nvim_list_wins()[1])
|
||||
)
|
||||
window('set_height', nvim('list_wins')[2], 2)
|
||||
eq(2, window('get_height', nvim('list_wins')[2]))
|
||||
meths.nvim_set_current_win(meths.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)
|
||||
|
||||
it('correctly handles height=1', function()
|
||||
nvim('command', 'split')
|
||||
nvim('set_current_win', nvim('list_wins')[1])
|
||||
window('set_height', nvim('list_wins')[2], 1)
|
||||
eq(1, window('get_height', nvim('list_wins')[2]))
|
||||
command('split')
|
||||
meths.nvim_set_current_win(meths.nvim_list_wins()[1])
|
||||
meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1)
|
||||
eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2]))
|
||||
end)
|
||||
|
||||
it('correctly handles height=1 with a winbar', function()
|
||||
nvim('command', 'set winbar=foobar')
|
||||
nvim('command', 'set winminheight=0')
|
||||
nvim('command', 'split')
|
||||
nvim('set_current_win', nvim('list_wins')[1])
|
||||
window('set_height', nvim('list_wins')[2], 1)
|
||||
eq(1, window('get_height', nvim('list_wins')[2]))
|
||||
command('set winbar=foobar')
|
||||
command('set winminheight=0')
|
||||
command('split')
|
||||
meths.nvim_set_current_win(meths.nvim_list_wins()[1])
|
||||
meths.nvim_win_set_height(meths.nvim_list_wins()[2], 1)
|
||||
eq(1, meths.nvim_win_get_height(meths.nvim_list_wins()[2]))
|
||||
end)
|
||||
|
||||
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()
|
||||
it('works', function()
|
||||
nvim('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')
|
||||
command('split')
|
||||
eq(
|
||||
window('get_width', nvim('list_wins')[2]),
|
||||
math.floor(window('get_width', nvim('list_wins')[1]) / 2)
|
||||
meths.nvim_win_get_width(meths.nvim_list_wins()[2]),
|
||||
meths.nvim_win_get_width(meths.nvim_list_wins()[1])
|
||||
)
|
||||
window('set_width', nvim('list_wins')[2], 2)
|
||||
eq(2, window('get_width', nvim('list_wins')[2]))
|
||||
meths.nvim_set_current_win(meths.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)
|
||||
|
||||
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()
|
||||
it('works', function()
|
||||
curwin('set_var', 'lua', { 1, 2, { ['3'] = 1 } })
|
||||
eq({ 1, 2, { ['3'] = 1 } }, curwin('get_var', 'lua'))
|
||||
eq({ 1, 2, { ['3'] = 1 } }, nvim('eval', 'w:lua'))
|
||||
meths.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
|
||||
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_win_get_var(0, 'lua'))
|
||||
eq({ 1, 2, { ['3'] = 1 } }, meths.nvim_eval('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('Key not found: lua', pcall_err(curwinmeths.del_var, 'lua'))
|
||||
curwinmeths.set_var('lua', 1)
|
||||
eq('Key not found: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua'))
|
||||
meths.nvim_win_set_var(0, 'lua', 1)
|
||||
command('lockvar w:lua')
|
||||
eq('Key is locked: lua', pcall_err(curwinmeths.del_var, 'lua'))
|
||||
eq('Key is locked: lua', pcall_err(curwinmeths.set_var, 'lua', 1))
|
||||
eq('Key is locked: lua', pcall_err(meths.nvim_win_del_var, 0, 'lua'))
|
||||
eq('Key is locked: lua', pcall_err(meths.nvim_win_set_var, 0, 'lua', 1))
|
||||
end)
|
||||
|
||||
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()
|
||||
it('works', function()
|
||||
nvim('set_option_value', 'colorcolumn', '4,3', {})
|
||||
eq('4,3', nvim('get_option_value', 'colorcolumn', {}))
|
||||
meths.nvim_set_option_value('colorcolumn', '4,3', {})
|
||||
eq('4,3', meths.nvim_get_option_value('colorcolumn', {}))
|
||||
command('set modified hidden')
|
||||
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
|
||||
nvim('set_option_value', 'statusline', 'window-status', { win = 0 })
|
||||
eq('window-status', nvim('get_option_value', 'statusline', { win = 0 }))
|
||||
eq('', nvim('get_option_value', 'statusline', { scope = 'global' }))
|
||||
meths.nvim_set_option_value('statusline', 'window-status', { win = 0 })
|
||||
eq('window-status', meths.nvim_get_option_value('statusline', { win = 0 }))
|
||||
eq('', meths.nvim_get_option_value('statusline', { scope = 'global' }))
|
||||
command('set modified')
|
||||
command('enew') -- global-local: not preserved in new buffer
|
||||
-- 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'))
|
||||
end)
|
||||
|
||||
it('after switching windows #15390', function()
|
||||
nvim('command', 'tabnew')
|
||||
local tab1 = unpack(nvim('list_tabpages'))
|
||||
local win1 = unpack(tabpage('list_wins', tab1))
|
||||
nvim('set_option_value', 'statusline', 'window-status', { win = win1.id })
|
||||
nvim('command', 'split')
|
||||
nvim('command', 'wincmd J')
|
||||
nvim('command', 'wincmd j')
|
||||
eq('window-status', nvim('get_option_value', 'statusline', { win = win1.id }))
|
||||
command('tabnew')
|
||||
local tab1 = unpack(meths.nvim_list_tabpages())
|
||||
local win1 = unpack(meths.nvim_tabpage_list_wins(tab1))
|
||||
meths.nvim_set_option_value('statusline', 'window-status', { win = win1.id })
|
||||
command('split')
|
||||
command('wincmd J')
|
||||
command('wincmd j')
|
||||
eq('window-status', meths.nvim_get_option_value('statusline', { win = win1.id }))
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
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)
|
||||
|
||||
describe('get_position', function()
|
||||
it('works', function()
|
||||
local height = window('get_height', nvim('list_wins')[1])
|
||||
local width = window('get_width', nvim('list_wins')[1])
|
||||
nvim('command', 'split')
|
||||
nvim('command', 'vsplit')
|
||||
eq({ 0, 0 }, window('get_position', nvim('list_wins')[1]))
|
||||
local height = meths.nvim_win_get_height(meths.nvim_list_wins()[1])
|
||||
local width = meths.nvim_win_get_width(meths.nvim_list_wins()[1])
|
||||
command('split')
|
||||
command('vsplit')
|
||||
eq({ 0, 0 }, meths.nvim_win_get_position(meths.nvim_list_wins()[1]))
|
||||
local vsplit_pos = math.floor(width / 2)
|
||||
local split_pos = math.floor(height / 2)
|
||||
local win2row, win2col = unpack(window('get_position', nvim('list_wins')[2]))
|
||||
local win3row, win3col = unpack(window('get_position', nvim('list_wins')[3]))
|
||||
local win2row, win2col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[2]))
|
||||
local win3row, win3col = unpack(meths.nvim_win_get_position(meths.nvim_list_wins()[3]))
|
||||
eq(0, win2row)
|
||||
eq(0, win3col)
|
||||
ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1)
|
||||
@@ -456,46 +467,46 @@ describe('API/win', function()
|
||||
|
||||
describe('get_position', function()
|
||||
it('works', function()
|
||||
nvim('command', 'tabnew')
|
||||
nvim('command', 'vsplit')
|
||||
eq(window('get_tabpage', nvim('list_wins')[1]), nvim('list_tabpages')[1])
|
||||
eq(window('get_tabpage', nvim('list_wins')[2]), nvim('list_tabpages')[2])
|
||||
eq(window('get_tabpage', nvim('list_wins')[3]), nvim('list_tabpages')[2])
|
||||
command('tabnew')
|
||||
command('vsplit')
|
||||
eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[1]), meths.nvim_list_tabpages()[1])
|
||||
eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[2]), meths.nvim_list_tabpages()[2])
|
||||
eq(meths.nvim_win_get_tabpage(meths.nvim_list_wins()[3]), meths.nvim_list_tabpages()[2])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_number', function()
|
||||
it('works', function()
|
||||
local wins = nvim('list_wins')
|
||||
eq(1, window('get_number', wins[1]))
|
||||
local wins = meths.nvim_list_wins()
|
||||
eq(1, meths.nvim_win_get_number(wins[1]))
|
||||
|
||||
nvim('command', 'split')
|
||||
local win1, win2 = unpack(nvim('list_wins'))
|
||||
eq(1, window('get_number', win1))
|
||||
eq(2, window('get_number', win2))
|
||||
command('split')
|
||||
local win1, win2 = unpack(meths.nvim_list_wins())
|
||||
eq(1, meths.nvim_win_get_number(win1))
|
||||
eq(2, meths.nvim_win_get_number(win2))
|
||||
|
||||
nvim('command', 'wincmd J')
|
||||
eq(2, window('get_number', win1))
|
||||
eq(1, window('get_number', win2))
|
||||
command('wincmd J')
|
||||
eq(2, meths.nvim_win_get_number(win1))
|
||||
eq(1, meths.nvim_win_get_number(win2))
|
||||
|
||||
nvim('command', 'tabnew')
|
||||
local win3 = nvim('list_wins')[3]
|
||||
command('tabnew')
|
||||
local win3 = meths.nvim_list_wins()[3]
|
||||
-- First tab page
|
||||
eq(2, window('get_number', win1))
|
||||
eq(1, window('get_number', win2))
|
||||
eq(2, meths.nvim_win_get_number(win1))
|
||||
eq(1, meths.nvim_win_get_number(win2))
|
||||
-- Second tab page
|
||||
eq(1, window('get_number', win3))
|
||||
eq(1, meths.nvim_win_get_number(win3))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('is_valid', function()
|
||||
it('works', function()
|
||||
nvim('command', 'split')
|
||||
local win = nvim('list_wins')[2]
|
||||
nvim('set_current_win', win)
|
||||
ok(window('is_valid', win))
|
||||
nvim('command', 'close')
|
||||
ok(not window('is_valid', win))
|
||||
command('split')
|
||||
local win = meths.nvim_list_wins()[2]
|
||||
meths.nvim_set_current_win(win)
|
||||
ok(meths.nvim_win_is_valid(win))
|
||||
command('close')
|
||||
ok(not meths.nvim_win_is_valid(win))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -671,42 +682,43 @@ describe('API/win', function()
|
||||
ddd
|
||||
eee]])
|
||||
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(curwinmeths.text_height, { 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(curwinmeths.text_height, { end_row = -6 }))
|
||||
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(meths.nvim_win_text_height, 0, { start_row = -6 }))
|
||||
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(meths.nvim_win_text_height, 0, { end_row = -6 }))
|
||||
eq(
|
||||
"'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(
|
||||
"'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(
|
||||
"'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(
|
||||
"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(
|
||||
"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(
|
||||
"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(
|
||||
"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(
|
||||
"'start_vcol' is higher than 'end_vcol'",
|
||||
pcall_err(
|
||||
curwinmeths.text_height,
|
||||
meths.nvim_win_text_height,
|
||||
0,
|
||||
{ start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 }
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user