aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/autocmd_spec.lua80
-rw-r--r--test/functional/api/buffer_updates_spec.lua4
-rw-r--r--test/functional/api/vim_spec.lua21
3 files changed, 91 insertions, 14 deletions
diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua
index 41de308a2c..491dac9f35 100644
--- a/test/functional/api/autocmd_spec.lua
+++ b/test/functional/api/autocmd_spec.lua
@@ -119,13 +119,45 @@ describe('autocmd api', function()
describe('desc', function()
it('can add description to one autocmd', function()
+ local cmd = "echo 'Should Not Have Errored'"
+ local desc = "Can show description"
meths.create_autocmd("BufReadPost", {
pattern = "*.py",
- command = "echo 'Should Not Have Errored'",
- desc = "Can show description",
+ command = cmd,
+ desc = desc,
})
- eq("Can show description", meths.get_autocmds { event = "BufReadPost" }[1].desc)
+ eq(desc, meths.get_autocmds { event = "BufReadPost" }[1].desc)
+ eq(cmd, meths.get_autocmds { event = "BufReadPost" }[1].command)
+ end)
+
+ it('can add description to one autocmd that uses a callback', function()
+ local desc = 'Can show description'
+ meths.set_var('desc', desc)
+
+ exec_lua([[
+ local callback = function() print 'Should Not Have Errored' end
+ vim.api.nvim_create_autocmd("BufReadPost", {
+ pattern = "*.py",
+ callback = callback,
+ desc = vim.g.desc,
+ })
+ ]])
+
+ eq(desc, meths.get_autocmds({ event = 'BufReadPost' })[1].desc)
+ matches('<lua: %d+>', meths.get_autocmds({ event = 'BufReadPost' })[1].command)
+ end)
+
+ it('will not add a description unless it was provided', function()
+ exec_lua([[
+ local callback = function() print 'Should Not Have Errored' end
+ vim.api.nvim_create_autocmd("BufReadPost", {
+ pattern = "*.py",
+ callback = callback,
+ })
+ ]])
+
+ eq(nil, meths.get_autocmds({ event = 'BufReadPost' })[1].desc)
end)
it('can add description to multiple autocmd', function()
@@ -169,15 +201,11 @@ describe('autocmd api', function()
]]
meths.exec_autocmds("User", {pattern = "Test"})
- eq({{
- buflocal = false,
- command = 'A test autocommand',
- desc = 'A test autocommand',
- event = 'User',
- id = 1,
- once = false,
- pattern = 'Test',
- }}, meths.get_autocmds({event = "User", pattern = "Test"}))
+
+ local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' })
+ local first = aus[1]
+ eq(first.id, 1)
+
meths.set_var("some_condition", true)
meths.exec_autocmds("User", {pattern = "Test"})
eq({}, meths.get_autocmds({event = "User", pattern = "Test"}))
@@ -230,6 +258,34 @@ describe('autocmd api', function()
}, meths.get_var("autocmd_args"))
end)
+
+ it('can receive arbitrary data', function()
+ local function test(data)
+ eq(data, exec_lua([[
+ local input = ...
+ local output
+ vim.api.nvim_create_autocmd("User", {
+ pattern = "Test",
+ callback = function(args)
+ output = args.data
+ end,
+ })
+
+ vim.api.nvim_exec_autocmds("User", {
+ pattern = "Test",
+ data = input,
+ })
+
+ return output
+ ]], data))
+ end
+
+ test("Hello")
+ test(42)
+ test(true)
+ test({ "list" })
+ test({ foo = "bar" })
+ end)
end)
describe('nvim_get_autocmds', function()
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index fc09e4cde0..2728dcf74c 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -785,7 +785,8 @@ describe('API: buffer events:', function()
local function lines_subset(first, second)
for i = 1,#first do
- if first[i] ~= second[i] then
+ -- need to ignore trailing spaces
+ if first[i]:gsub(' +$', '') ~= second[i]:gsub(' +$', '') then
return false
end
end
@@ -827,7 +828,6 @@ describe('API: buffer events:', function()
end
it('when :terminal lines change', function()
- if helpers.pending_win32(pending) then return end
local buffer_lines = {}
local expected_lines = {}
command('terminal "'..nvim_prog..'" -u NONE -i NONE -n -c "set shortmess+=A"')
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index 8c4048132c..55535a92e5 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -3120,6 +3120,19 @@ describe('API', function()
'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
{ use_tabline = true, highlights = true }))
end)
+ it('works with winbar', function()
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'WinBar' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { use_winbar = true, highlights = true }))
+ end)
end)
end)
describe('nvim_parse_cmd', function()
@@ -3641,5 +3654,13 @@ describe('API', function()
meths.cmd({ cmd = "update" }, {})
meths.cmd({ cmd = "buffer", count = 0 }, {})
end)
+ it('doesn\'t suppress errors when used in keymapping', function()
+ meths.exec_lua([[
+ vim.keymap.set("n", "[l",
+ function() vim.api.nvim_cmd({ cmd = "echo", args = {"foo"} }, {}) end)
+ ]], {})
+ feed("[l")
+ neq(nil, string.find(eval("v:errmsg"), "E5108:"))
+ end)
end)
end)