aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/api
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/autocmd_spec.lua78
-rw-r--r--test/functional/api/buffer_spec.lua193
-rw-r--r--test/functional/api/buffer_updates_spec.lua32
-rw-r--r--test/functional/api/command_spec.lua25
-rw-r--r--test/functional/api/extmark_spec.lua82
-rw-r--r--test/functional/api/highlight_spec.lua22
-rw-r--r--test/functional/api/keymap_spec.lua203
-rw-r--r--test/functional/api/menu_spec.lua8
-rw-r--r--test/functional/api/proc_spec.lua19
-rw-r--r--test/functional/api/server_notifications_spec.lua40
-rw-r--r--test/functional/api/server_requests_spec.lua65
-rw-r--r--test/functional/api/tabpage_spec.lua42
-rw-r--r--test/functional/api/ui_spec.lua22
-rw-r--r--test/functional/api/version_spec.lua8
-rw-r--r--test/functional/api/vim_spec.lua441
-rw-r--r--test/functional/api/window_spec.lua1162
16 files changed, 1952 insertions, 490 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua
index e89abf6c64..3f9883f43f 100644
--- a/test/functional/api/autocmd_spec.lua
+++ b/test/functional/api/autocmd_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local neq = helpers.neq
-local exec_lua = helpers.exec_lua
-local matches = helpers.matches
-local api = helpers.api
-local source = helpers.source
-local pcall_err = helpers.pcall_err
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local neq = t.neq
+local exec_lua = n.exec_lua
+local matches = t.matches
+local api = n.api
+local source = n.source
+local pcall_err = t.pcall_err
before_each(clear)
@@ -355,6 +356,44 @@ describe('autocmd api', function()
test({ 'list' })
test({ foo = 'bar' })
end)
+
+ it('function in arbitrary data is passed to all autocmds #28353', function()
+ eq(
+ 1303,
+ exec_lua([[
+ local res = 1
+
+ local fun = function(m, x)
+ res = res * m + x
+ end
+
+ local group = vim.api.nvim_create_augroup('MyTest', { clear = false })
+
+ vim.api.nvim_create_autocmd('User', {
+ group = group,
+ callback = function(payload)
+ payload.data.fun(10, payload.data.x)
+ end,
+ pattern = 'MyEvent',
+ })
+ vim.api.nvim_create_autocmd('User', {
+ group = group,
+ callback = function(payload)
+ payload.data.fun(100, payload.data.x)
+ end,
+ pattern = 'MyEvent',
+ })
+
+ vim.api.nvim_exec_autocmds('User', {
+ group = group,
+ pattern = 'MyEvent',
+ data = { x = 3, fun = fun },
+ })
+
+ return res
+ ]])
+ )
+ end)
end)
describe('nvim_get_autocmds', function()
@@ -610,15 +649,17 @@ describe('autocmd api', function()
it('can retrieve a callback from an autocmd', function()
local content = 'I Am A Callback'
api.nvim_set_var('content', content)
-
- local result = exec_lua([[
+ exec_lua([[
local cb = function() return vim.g.content end
vim.api.nvim_create_autocmd("User", {
pattern = "TestTrigger",
desc = "A test autocommand with a callback",
callback = cb,
})
- local aus = vim.api.nvim_get_autocmds({ event = 'User', pattern = 'TestTrigger'})
+ ]])
+
+ local result = exec_lua([[
+ local aus = vim.api.nvim_get_autocmds({ event = 'User', pattern = 'TestTrigger' })
local first = aus[1]
return {
cb = {
@@ -627,9 +668,14 @@ describe('autocmd api', function()
}
}
]])
+ eq({ cb = { type = 'function', can_retrieve = true } }, result)
- eq('function', result.cb.type)
- eq(true, result.cb.can_retrieve)
+ -- Also test with Vimscript
+ source([[
+ let s:aus = nvim_get_autocmds({'event': 'User', 'pattern': 'TestTrigger'})
+ let g:result = s:aus[0].callback()
+ ]])
+ eq(content, api.nvim_get_var('result'))
end)
it(
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 78d220ff57..cf69958fd8 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -1,21 +1,23 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local eq = helpers.eq
-local ok = helpers.ok
-local describe_lua_and_rpc = helpers.describe_lua_and_rpc(describe)
-local api = helpers.api
-local fn = helpers.fn
-local request = helpers.request
-local exc_exec = helpers.exc_exec
-local exec_lua = helpers.exec_lua
-local feed_command = helpers.feed_command
-local insert = helpers.insert
+
+local clear = n.clear
+local eq = t.eq
+local ok = t.ok
+local describe_lua_and_rpc = n.describe_lua_and_rpc(describe)
+local api = n.api
+local fn = n.fn
+local request = n.request
+local exc_exec = n.exc_exec
+local exec_lua = n.exec_lua
+local feed_command = n.feed_command
+local insert = n.insert
local NIL = vim.NIL
-local command = helpers.command
-local feed = helpers.feed
-local pcall_err = helpers.pcall_err
-local assert_alive = helpers.assert_alive
+local command = n.command
+local feed = n.feed
+local pcall_err = t.pcall_err
+local assert_alive = n.assert_alive
describe('api/buf', function()
before_each(clear)
@@ -121,6 +123,65 @@ describe('api/buf', function()
eq({ 5, 2 }, api.nvim_win_get_cursor(win2))
end)
+ it('cursor position is maintained consistently with viewport', function()
+ local screen = Screen.new(20, 12)
+ screen:set_default_attr_ids {
+ [1] = { bold = true, foreground = Screen.colors.Blue1 },
+ [2] = { reverse = true, bold = true },
+ [3] = { reverse = true },
+ }
+ screen:attach()
+
+ local lines = { 'line1', 'line2', 'line3', 'line4', 'line5', 'line6' }
+ local buf = api.nvim_get_current_buf()
+
+ api.nvim_buf_set_lines(buf, 0, -1, true, lines)
+
+ command('6')
+ command('new')
+ screen:expect {
+ grid = [[
+ ^ |
+ {1:~ }|*4
+ {2:[No Name] }|
+ line5 |
+ line6 |
+ {1:~ }|*2
+ {3:[No Name] [+] }|
+ |
+ ]],
+ }
+
+ lines[5] = 'boogalo 5'
+ api.nvim_buf_set_lines(buf, 0, -1, true, lines)
+ screen:expect {
+ grid = [[
+ ^ |
+ {1:~ }|*4
+ {2:[No Name] }|
+ boogalo 5 |
+ line6 |
+ {1:~ }|*2
+ {3:[No Name] [+] }|
+ |
+ ]],
+ }
+
+ command('wincmd w')
+ screen:expect {
+ grid = [[
+ |
+ {1:~ }|*4
+ {3:[No Name] }|
+ boogalo 5 |
+ ^line6 |
+ {1:~ }|*2
+ {2:[No Name] [+] }|
+ |
+ ]],
+ }
+ end)
+
it('line_count has defined behaviour for unloaded buffers', function()
-- we'll need to know our bufnr for when it gets unloaded
local bufnr = api.nvim_buf_get_number(0)
@@ -323,20 +384,20 @@ describe('api/buf', function()
]],
}
- -- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
- mmm |
wwweeee |
xxx |
yyy |
+ zzz |
{3:[No Name] [+] }|
|
]],
+ unchanged = true,
}
end)
@@ -402,7 +463,6 @@ describe('api/buf', function()
]],
}
- -- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
@@ -412,10 +472,10 @@ describe('api/buf', function()
mmm |
wwweeee |
{2:[No Name] [+] }|
- mmm |
wwweeee |
xxx |
yyy |
+ zzz |
{3:[No Name] [+] }|
|
]],
@@ -1316,12 +1376,7 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 12 }, cursor)
-- coladd should be 0
- eq(
- 0,
- exec_lua([[
- return vim.fn.winsaveview().coladd
- ]])
- )
+ eq(0, fn.winsaveview().coladd)
end)
it('does not change cursor screen column when cursor >EOL and row got shorter', function()
@@ -1335,9 +1390,7 @@ describe('api/buf', function()
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol
- exec_lua([[
- vim.fn.winrestview({ coladd = 5 })
- ]])
+ fn.winrestview({ coladd = 5 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1356,12 +1409,7 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 26 }, cursor)
-- coladd should be increased so that cursor stays in the same screen column
- eq(
- 13,
- exec_lua([[
- return vim.fn.winsaveview().coladd
- ]])
- )
+ eq(13, fn.winsaveview().coladd)
end)
it(
@@ -1377,9 +1425,7 @@ describe('api/buf', function()
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol
- exec_lua([[
- vim.fn.winrestview({ coladd = 21 })
- ]])
+ fn.winrestview({ coladd = 21 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1398,12 +1444,7 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 38 }, cursor)
-- coladd should be increased so that cursor stays in the same screen column
- eq(
- 2,
- exec_lua([[
- return vim.fn.winsaveview().coladd
- ]])
- )
+ eq(2, fn.winsaveview().coladd)
end
)
@@ -1420,9 +1461,7 @@ describe('api/buf', function()
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol just a bit
- exec_lua([[
- vim.fn.winrestview({ coladd = 3 })
- ]])
+ fn.winrestview({ coladd = 3 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 2, 11, {
@@ -1441,12 +1480,7 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 1, 22 }, cursor)
-- coladd should become 0
- eq(
- 0,
- exec_lua([[
- return vim.fn.winsaveview().coladd
- ]])
- )
+ eq(0, fn.winsaveview().coladd)
end
)
@@ -1464,9 +1498,7 @@ describe('api/buf', function()
-- turn on virtualedit
command('set virtualedit=all')
-- move cursor after eol
- exec_lua([[
- vim.fn.winrestview({ coladd = 28 })
- ]])
+ fn.winrestview({ coladd = 28 })
local cursor = exec_lua([[
vim.api.nvim_buf_set_text(0, 0, 15, 3, 11, {
@@ -1485,12 +1517,7 @@ describe('api/buf', function()
-- immediate call to nvim_win_get_cursor should have returned the same position
eq({ 2, 26 }, cursor)
-- coladd should be increased so that cursor stays in the same screen column
- eq(
- 13,
- exec_lua([[
- return vim.fn.winsaveview().coladd
- ]])
- )
+ eq(13, fn.winsaveview().coladd)
end
)
end)
@@ -1686,12 +1713,11 @@ describe('api/buf', function()
api.nvim_buf_set_text(0, 0, 0, 1, 3, { 'XXX', 'YYY' })
screen:expect([[
- XXX |
- YYY |
- ^ |
- ~ |
- |
-
+ XXX |
+ YYY |
+ ^ |
+ {1:~ }|
+ |
]])
end)
@@ -2024,6 +2050,37 @@ describe('api/buf', function()
eq(1, fn.filereadable(new_name))
os.remove(new_name)
end)
+
+ describe("with 'autochdir'", function()
+ local topdir
+ local oldbuf
+ local newbuf
+
+ before_each(function()
+ command('set shellslash')
+ topdir = fn.getcwd()
+ t.mkdir(topdir .. '/Xacd')
+
+ oldbuf = api.nvim_get_current_buf()
+ command('vnew')
+ newbuf = api.nvim_get_current_buf()
+ command('set autochdir')
+ end)
+
+ after_each(function()
+ n.rmdir(topdir .. '/Xacd')
+ end)
+
+ it('does not change cwd with non-current buffer', function()
+ api.nvim_buf_set_name(oldbuf, topdir .. '/Xacd/foo.txt')
+ eq(topdir, fn.getcwd())
+ end)
+
+ it('changes cwd with current buffer', function()
+ api.nvim_buf_set_name(newbuf, topdir .. '/Xacd/foo.txt')
+ eq(topdir .. '/Xacd', fn.getcwd())
+ end)
+ end)
end)
describe('nvim_buf_is_loaded', function()
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index 262ca40e28..e030b45396 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -1,13 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local eq, ok = helpers.eq, helpers.ok
-local fn = helpers.fn
-local api = helpers.api
-local command, eval, next_msg = helpers.command, helpers.eval, helpers.next_msg
-local nvim_prog = helpers.nvim_prog
-local pcall_err = helpers.pcall_err
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local eq, ok = t.eq, t.ok
+local fn = n.fn
+local api = n.api
+local command, eval, next_msg = n.command, n.eval, n.next_msg
+local nvim_prog = n.nvim_prog
+local pcall_err = t.pcall_err
local sleep = vim.uv.sleep
-local write_file = helpers.write_file
+local write_file = t.write_file
local origlines = {
'original line 1',
@@ -34,7 +36,7 @@ local function sendkeys(keys)
end
local function open(activate, lines)
- local filename = helpers.tmpname()
+ local filename = t.tmpname()
write_file(filename, table.concat(lines, '\n') .. '\n', true)
command('edit ' .. filename)
local b = api.nvim_get_current_buf()
@@ -511,11 +513,11 @@ describe('API: buffer events:', function()
-- create several new sessions, in addition to our main API
local sessions = {}
- local pipe = helpers.new_pipename()
+ local pipe = n.new_pipename()
eval("serverstart('" .. pipe .. "')")
- sessions[1] = helpers.connect(pipe)
- sessions[2] = helpers.connect(pipe)
- sessions[3] = helpers.connect(pipe)
+ sessions[1] = n.connect(pipe)
+ sessions[2] = n.connect(pipe)
+ sessions[3] = n.connect(pipe)
local function request(sessionnr, method, ...)
local status, rv = sessions[sessionnr]:request(method, ...)
@@ -814,7 +816,7 @@ describe('API: buffer events:', function()
clear()
sleep(250)
-- response
- eq(true, helpers.request('nvim_buf_attach', 0, false, {}))
+ eq(true, n.request('nvim_buf_attach', 0, false, {}))
-- notification
eq({
[1] = 'notification',
diff --git a/test/functional/api/command_spec.lua b/test/functional/api/command_spec.lua
index f73b9c8b13..a16c6a88e3 100644
--- a/test/functional/api/command_spec.lua
+++ b/test/functional/api/command_spec.lua
@@ -1,17 +1,18 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local NIL = vim.NIL
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local api = helpers.api
-local matches = helpers.matches
-local source = helpers.source
-local pcall_err = helpers.pcall_err
-local exec_lua = helpers.exec_lua
-local assert_alive = helpers.assert_alive
-local feed = helpers.feed
-local fn = helpers.fn
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local api = n.api
+local matches = t.matches
+local source = n.source
+local pcall_err = t.pcall_err
+local exec_lua = n.exec_lua
+local assert_alive = n.assert_alive
+local feed = n.feed
+local fn = n.fn
describe('nvim_get_commands', function()
local cmd_dict = {
diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua
index 2acfbfc949..7b2fe209ba 100644
--- a/test/functional/api/extmark_spec.lua
+++ b/test/functional/api/extmark_spec.lua
@@ -1,20 +1,21 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local request = helpers.request
-local eq = helpers.eq
-local ok = helpers.ok
-local pcall_err = helpers.pcall_err
-local insert = helpers.insert
-local feed = helpers.feed
-local clear = helpers.clear
-local command = helpers.command
-local exec = helpers.exec
-local api = helpers.api
-local assert_alive = helpers.assert_alive
+local request = n.request
+local eq = t.eq
+local ok = t.ok
+local pcall_err = t.pcall_err
+local insert = n.insert
+local feed = n.feed
+local clear = n.clear
+local command = n.command
+local exec = n.exec
+local api = n.api
+local assert_alive = n.assert_alive
local function expect(contents)
- return eq(contents, helpers.curbuf_contents())
+ return eq(contents, n.curbuf_contents())
end
local function set_extmark(ns_id, id, line, col, opts)
@@ -460,7 +461,7 @@ describe('API/extmarks', function()
-- This shouldn't seg fault
screen:expect([[
12345^ 1 |
- ~ |*8
+ {1:~ }|*8
|
]])
end)
@@ -513,7 +514,7 @@ describe('API/extmarks', function()
insert('abc')
screen:expect([[
ab^c12345 |
- ~ |*8
+ {1:~ }|*8
|
]])
local rv = get_extmark_by_id(ns, marks[1])
@@ -1568,7 +1569,7 @@ describe('API/extmarks', function()
sign_text = '>>',
spell = true,
virt_lines = {
- { { 'lines', 'Macro' }, { '???' } },
+ { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
{ { 'stack', { 'Type', 'Search' } }, { '!!!' } },
},
virt_lines_above = true,
@@ -1603,7 +1604,7 @@ describe('API/extmarks', function()
sign_text = '>>',
spell = true,
virt_lines = {
- { { 'lines', 'Macro' }, { '???' } },
+ { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
{ { 'stack', { 'Type', 'Search' } }, { '!!!' } },
},
virt_lines_above = true,
@@ -1734,16 +1735,17 @@ describe('API/extmarks', function()
command('d2')
screen:expect([[
S2^aaa bbb ccc |
- aaa bbb ccc |*3
- |*2
+ {7: }aaa bbb ccc |*3
+ {7: } |
+ |
]])
-- mark is restored with undo_restore == true
command('silent undo')
screen:expect([[
- S1 ^aaa bbb ccc |
- S1S2aaa bbb ccc |
- S2 aaa bbb ccc |
- aaa bbb ccc |*2
+ S1{7: }^aaa bbb ccc |
+ S2S1aaa bbb ccc |
+ S2{7: }aaa bbb ccc |
+ {7: }aaa bbb ccc |*2
|
]])
-- decor is not removed twice
@@ -1894,6 +1896,24 @@ describe('Extmarks buffer api with many marks', function()
end
eq(ns_marks[ns1], get_marks(ns1))
eq(ns_marks[ns2], get_marks(ns2))
+
+ api.nvim_buf_clear_namespace(0, ns1, 0, 10)
+ for id, mark in pairs(ns_marks[ns1]) do
+ if mark[1] < 10 then
+ ns_marks[ns1][id] = nil
+ end
+ end
+ eq(ns_marks[ns1], get_marks(ns1))
+ eq(ns_marks[ns2], get_marks(ns2))
+
+ api.nvim_buf_clear_namespace(0, ns1, 20, -1)
+ for id, mark in pairs(ns_marks[ns1]) do
+ if mark[1] >= 20 then
+ ns_marks[ns1][id] = nil
+ end
+ end
+ eq(ns_marks[ns1], get_marks(ns1))
+ eq(ns_marks[ns2], get_marks(ns2))
end)
it('can delete line', function()
@@ -1964,7 +1984,7 @@ describe('API/win_extmark', function()
grid = [[
non ui-watched line |
ui-watched lin^e |
- ~ |
+ {1:~ }|
|
]],
extmarks = {
@@ -2052,7 +2072,7 @@ describe('API/win_extmark', function()
grid = [[
ui-watched linupdat^e|
e |
- ~ |
+ {1:~ }|
|
]],
extmarks = {
@@ -2079,9 +2099,9 @@ describe('API/win_extmark', function()
grid = [[
## grid 1
[4:--------------------]|*3
- [No Name] [+] |
+ {3:[No Name] [+] }|
[2:--------------------]|*2
- [No Name] [+] |
+ {2:[No Name] [+] }|
[3:--------------------]|
## grid 2
non ui-watched line |
@@ -2091,7 +2111,7 @@ describe('API/win_extmark', function()
## grid 4
non ui-watched line |
ui-watched lin^e |
- ~ |
+ {1:~ }|
]],
extmarks = {
[2] = {
@@ -2112,13 +2132,13 @@ describe('API/win_extmark', function()
grid = [[
## grid 1
[4:--------------------]|*3
- [No Name] [+] |
+ {3:[No Name] [+] }|
[2:--------------------]|*2
- [No Name] [+] |
+ {2:[No Name] [+] }|
[3:--------------------]|
## grid 2
non ui-watched line |
- ui-watched linupd@@@|
+ ui-watched linupd{1:@@@}|
## grid 3
|
## grid 4
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 1973d3e1c7..dd0611f184 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -1,14 +1,16 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local eq, eval = helpers.eq, helpers.eval
-local command = helpers.command
-local exec_capture = helpers.exec_capture
-local api = helpers.api
-local fn = helpers.fn
-local pcall_err = helpers.pcall_err
-local ok = helpers.ok
-local assert_alive = helpers.assert_alive
+
+local clear = n.clear
+local eq, eval = t.eq, n.eval
+local command = n.command
+local exec_capture = n.exec_capture
+local api = n.api
+local fn = n.fn
+local pcall_err = t.pcall_err
+local ok = t.ok
+local assert_alive = n.assert_alive
describe('API: highlight', function()
clear()
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index 0decd710e9..995711507f 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -1,17 +1,19 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local command = helpers.command
-local eq, neq = helpers.eq, helpers.neq
-local exec_lua = helpers.exec_lua
-local exec = helpers.exec
-local feed = helpers.feed
-local fn = helpers.fn
-local api = helpers.api
-local source = helpers.source
-local pcall_err = helpers.pcall_err
-
-local shallowcopy = helpers.shallowcopy
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local eq, neq = t.eq, t.neq
+local exec_lua = n.exec_lua
+local exec = n.exec
+local feed = n.feed
+local fn = n.fn
+local api = n.api
+local matches = t.matches
+local source = n.source
+local pcall_err = t.pcall_err
+
+local shallowcopy = t.shallowcopy
local sleep = vim.uv.sleep
local sid_api_client = -9
@@ -398,7 +400,9 @@ describe('nvim_get_keymap', function()
0,
exec_lua([[
GlobalCount = 0
- vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {
+ callback = function() GlobalCount = GlobalCount + 1 end,
+ })
return GlobalCount
]])
)
@@ -738,7 +742,7 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
end
end
- it('can set mappings containing literal keycodes', function()
+ it('can set mappings containing C0 control codes', function()
api.nvim_set_keymap('n', '\n\r\n', 'rhs', {})
local expected = generate_mapargs('n', '<NL><CR><NL>', 'rhs')
eq(expected, get_mapargs('n', '<NL><CR><NL>'))
@@ -951,7 +955,9 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
0,
exec_lua [[
GlobalCount = 0
- vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {
+ callback = function() GlobalCount = GlobalCount + 1 end,
+ })
return GlobalCount
]]
)
@@ -963,34 +969,38 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it(':map command shows lua mapping correctly', function()
exec_lua [[
- vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {
+ callback = function() print('jkl;') end,
+ })
]]
- assert.truthy(
- string.match(
- exec_lua [[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]],
- '^\nn asdf <Lua %d+>'
- )
+ matches(
+ '^\nn asdf <Lua %d+>',
+ exec_lua [[return vim.api.nvim_exec2(':nmap asdf', { output = true }).output]]
)
end)
it('mapcheck() returns lua mapping correctly', function()
exec_lua [[
- vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() print('jkl;') end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {
+ callback = function() print('jkl;') end,
+ })
]]
- assert.truthy(string.match(fn.mapcheck('asdf', 'n'), '^<Lua %d+>'))
+ matches('^<Lua %d+>', fn.mapcheck('asdf', 'n'))
end)
- it('maparg() returns lua mapping correctly', function()
+ it('maparg() and maplist() return lua mapping correctly', function()
eq(
0,
exec_lua([[
GlobalCount = 0
- vim.api.nvim_set_keymap('n', 'asdf', '', {callback = function() GlobalCount = GlobalCount + 1 end })
+ vim.api.nvim_set_keymap('n', 'asdf', '', {
+ callback = function() GlobalCount = GlobalCount + 1 end,
+ })
return GlobalCount
]])
)
- assert.truthy(string.match(fn.maparg('asdf', 'n'), '^<Lua %d+>'))
+ matches('^<Lua %d+>', fn.maparg('asdf', 'n'))
local mapargs = fn.maparg('asdf', 'n', false, true)
mapargs.callback = nil
@@ -1010,11 +1020,20 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
call maparg('asdf', 'n', v:false, v:true).callback()
]])
eq(2, exec_lua([[return GlobalCount]]))
+
+ api.nvim_eval([[
+ maplist()->filter({_, m -> m.lhs == 'asdf'})->foreach({_, m -> m.callback()})
+ ]])
+ eq(3, exec_lua([[return GlobalCount]]))
end)
it('can make lua expr mappings replacing keycodes', function()
exec_lua [[
- vim.api.nvim_set_keymap('n', 'aa', '', {callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, expr = true, replace_keycodes = true })
+ vim.api.nvim_set_keymap('n', 'aa', '', {
+ callback = function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end,
+ expr = true,
+ replace_keycodes = true,
+ })
]]
feed('aa')
@@ -1024,7 +1043,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('can make lua expr mappings without replacing keycodes', function()
exec_lua [[
- vim.api.nvim_set_keymap('i', 'aa', '', {callback = function() return '<space>' end, expr = true })
+ vim.api.nvim_set_keymap('i', 'aa', '', {
+ callback = function() return '<space>' end,
+ expr = true,
+ })
]]
feed('iaa<esc>')
@@ -1034,7 +1056,10 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
it('lua expr mapping returning nil is equiv