From c5b34fa55483d84d1de32937ffff0b7cf1aeba78 Mon Sep 17 00:00:00 2001 From: glacambre Date: Sat, 11 Feb 2023 09:45:11 +0100 Subject: refactor: move init_default_autocmds to lua The original motivation for this change came from developping https://github.com/neovim/neovim/pull/22159, which will require adding more autocommand creation to Neovim's startup sequence. This change requires lightly editing a test that expected no autocommand to have been created from lua. --- test/functional/api/autocmd_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 22a1311ee9..af13736aa9 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -209,7 +209,7 @@ describe('autocmd api', function() local aus = meths.get_autocmds({ event = 'User', pattern = 'Test' }) local first = aus[1] - eq(first.id, 1) + eq(true, first.id > 0) meths.set_var("some_condition", true) meths.exec_autocmds("User", {pattern = "Test"}) -- cgit From 46a87a5d2bac598fed0870f0d3c926087f95d30f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 05:19:04 -0500 Subject: refactor(api): VALIDATE macros #22187 Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting. --- test/functional/api/autocmd_spec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 22a1311ee9..56b0a4d9b2 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -21,7 +21,7 @@ describe('autocmd api', function() callback = "NotAllowed", }) - eq("specify either 'callback' or 'command', not both", rv) + eq("Cannot use both 'callback' and 'command'", rv) end) it('doesnt leak when you use ++once', function() @@ -66,7 +66,7 @@ describe('autocmd api', function() pattern = "*.py", }) - eq("cannot pass both: 'pattern' and 'buffer' for the same autocmd", rv) + eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", rv) end) it('does not allow passing invalid buffers', function() @@ -407,8 +407,8 @@ describe('autocmd api', function() pattern = "", }}, aus) - eq("Invalid value for 'buffer': must be an integer or array of integers", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) - eq("Invalid value for 'buffer': must be an integer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) + eq("Invalid buffer: expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) + eq("Invalid buffer: expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } })) local bufs = {} @@ -416,7 +416,7 @@ describe('autocmd api', function() table.insert(bufs, meths.create_buf(true, false)) end - eq("Too many buffers. Please limit yourself to 256 or fewer", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) + eq("Too many buffers (maximum of 256)", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) end) it('should return autocmds when group is specified by id', function() @@ -578,7 +578,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('invalid augroup: NotDefined', code) + matches("Invalid group: 'NotDefined'", code) end) it('raises error for undefined augroup id', function() @@ -596,7 +596,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('invalid augroup: 1', code) + matches('Invalid group: 1', code) end) it('raises error for invalid group type', function() @@ -611,7 +611,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("'group' must be a string or an integer", code) + matches("Invalid group: expected String or Integer, got Boolean", code) end) it('raises error for invalid pattern array', function() @@ -625,7 +625,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("All entries in 'pattern' must be strings", code) + matches("Invalid 'pattern' item type: expected String, got Array", code) end) end) -- cgit From ff3d04b75b4a9314815c37d53ebc4d035a043335 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 08:07:38 -0500 Subject: refactor(api): VALIDATE macros #22256 - VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args --- test/functional/api/autocmd_spec.lua | 104 +++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 35 deletions(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 56b0a4d9b2..f10f18174e 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -14,14 +14,31 @@ before_each(clear) describe('autocmd api', function() describe('nvim_create_autocmd', function() - it('"command" and "callback" are mutually exclusive', function() - local rv = pcall_err(meths.create_autocmd, "BufReadPost", { - pattern = "*.py,*.pyi", + it('validation', function() + eq("Cannot use both 'callback' and 'command'", pcall_err(meths.create_autocmd, 'BufReadPost', { + pattern = '*.py,*.pyi', command = "echo 'Should Have Errored", - callback = "NotAllowed", - }) - - eq("Cannot use both 'callback' and 'command'", rv) + callback = 'NotAllowed', + })) + eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", pcall_err(meths.create_autocmd, 'FileType', { + command = 'let g:called = g:called + 1', + buffer = 0, + pattern = '*.py', + })) + eq("Required: 'event'", pcall_err(meths.create_autocmd, {}, { + command = 'ls', + })) + eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', { + })) + eq('Invalid desc: expected String, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + command = 'ls', + desc = 42, + })) + eq('Invalid callback: expected Lua function or Vim function name, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + callback = 0, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, + {'FileType', {}}, {})) end) it('doesnt leak when you use ++once', function() @@ -59,18 +76,8 @@ describe('autocmd api', function() eq(1, meths.get_var('called')) end) - it('does not allow passing buffer and patterns', function() - local rv = pcall_err(meths.create_autocmd, "Filetype", { - command = "let g:called = g:called + 1", - buffer = 0, - pattern = "*.py", - }) - - eq("Cannot use both 'pattern' and 'buffer' for the same autocmd", rv) - end) - it('does not allow passing invalid buffers', function() - local ok, msg = pcall(meths.create_autocmd, "Filetype", { + local ok, msg = pcall(meths.create_autocmd, 'FileType', { command = "let g:called = g:called + 1", buffer = -1, }) @@ -295,7 +302,7 @@ describe('autocmd api', function() describe('nvim_get_autocmds', function() describe('events', function() - it('should return one autocmd when there is only one for an event', function() + it('returns one autocmd when there is only one for an event', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] @@ -303,7 +310,7 @@ describe('autocmd api', function() eq(1, #aus) end) - it('should return two autocmds when there are two for an event', function() + it('returns two autocmds when there are two for an event', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] @@ -312,7 +319,7 @@ describe('autocmd api', function() eq(2, #aus) end) - it('should return the same thing if you use string or list', function() + it('returns the same thing if you use string or list', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] command [[au InsertEnter * :echo "2"]] @@ -322,7 +329,7 @@ describe('autocmd api', function() eq(string_aus, array_aus) end) - it('should return two autocmds when there are two for an event', function() + it('returns two autocmds when there are two for an event', function() command [[au! InsertEnter]] command [[au! InsertLeave]] command [[au InsertEnter * :echo "1"]] @@ -332,7 +339,7 @@ describe('autocmd api', function() eq(2, #aus) end) - it('should return different IDs for different autocmds', function() + it('returns different IDs for different autocmds', function() command [[au! InsertEnter]] command [[au! InsertLeave]] command [[au InsertEnter * :echo "1"]] @@ -356,7 +363,7 @@ describe('autocmd api', function() eq(first, new_aus[1]) end) - it('should return event name', function() + it('returns event name', function() command [[au! InsertEnter]] command [[au InsertEnter * :echo "1"]] @@ -364,7 +371,7 @@ describe('autocmd api', function() eq({ { buflocal = false, command = ':echo "1"', event = "InsertEnter", once = false, pattern = "*" } }, aus) end) - it('should work with buffer numbers', function() + it('works with buffer numbers', function() command [[new]] command [[au! InsertEnter]] command [[au InsertEnter :echo "1"]] @@ -419,7 +426,7 @@ describe('autocmd api', function() eq("Too many buffers (maximum of 256)", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = bufs })) end) - it('should return autocmds when group is specified by id', function() + it('returns autocmds when group is specified by id', function() local auid = meths.create_augroup("nvim_test_augroup", { clear = true }) meths.create_autocmd("FileType", { group = auid, command = 'echo "1"' }) meths.create_autocmd("FileType", { group = auid, command = 'echo "2"' }) @@ -431,7 +438,7 @@ describe('autocmd api', function() eq(0, #aus2) end) - it('should return autocmds when group is specified by name', function() + it('returns autocmds when group is specified by name', function() local auname = "nvim_test_augroup" meths.create_augroup(auname, { clear = true }) meths.create_autocmd("FileType", { group = auname, command = 'echo "1"' }) @@ -531,7 +538,7 @@ describe('autocmd api', function() command [[augroup END]] end) - it('should return all groups if no group is specified', function() + it('returns all groups if no group is specified', function() local aus = meths.get_autocmds { event = "InsertEnter" } if #aus ~= 4 then eq({}, aus) @@ -540,7 +547,7 @@ describe('autocmd api', function() eq(4, #aus) end) - it('should return only the group specified', function() + it('returns only the group specified', function() local aus = meths.get_autocmds { event = "InsertEnter", group = "GroupOne", @@ -551,7 +558,7 @@ describe('autocmd api', function() eq("GroupOne", aus[1].group_name) end) - it('should return only the group specified, multiple values', function() + it('returns only the group specified, multiple values', function() local aus = meths.get_autocmds { event = "InsertEnter", group = "GroupTwo", @@ -625,7 +632,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid 'pattern' item type: expected String, got Array", code) + matches("Invalid 'pattern' item: expected String, got Array", code) end) end) @@ -640,7 +647,7 @@ describe('autocmd api', function() command [[au InsertEnter :echo "Buffer"]] end) - it('should should return for literal match', function() + it('returns for literal match', function() local aus = meths.get_autocmds { event = "InsertEnter", pattern = "*" @@ -650,7 +657,7 @@ describe('autocmd api', function() eq([[:echo "No Group"]], aus[1].command) end) - it('should return for multiple matches', function() + it('returns for multiple matches', function() -- vim.api.nvim_get_autocmds local aus = meths.get_autocmds { event = "InsertEnter", @@ -687,6 +694,23 @@ describe('autocmd api', function() end) describe('nvim_exec_autocmds', function() + it('validation', function() + eq('Invalid group: 9997999', pcall_err(meths.exec_autocmds, 'FileType', { + group = 9997999, + })) + eq("Invalid group: 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { + group = 'bogus', + })) + eq('Invalid group: expected String or Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + group = {}, + })) + eq('Invalid buffer: expected Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + buffer = {}, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, + {'FileType', {}}, {})) + end) + it("can trigger builtin autocmds", function() meths.set_var("autocmd_executed", false) @@ -1036,7 +1060,7 @@ describe('autocmd api', function() local augroup = "WillBeDeleted" meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd({"Filetype"}, { + meths.create_autocmd({"FileType"}, { pattern = "*", command = "echo 'does not matter'", }) @@ -1055,7 +1079,7 @@ describe('autocmd api', function() meths.set_var("value_set", false) meths.create_augroup(augroup, { clear = true }) - meths.create_autocmd("Filetype", { + meths.create_autocmd("FileType", { pattern = "", command = "let g:value_set = v:true", }) @@ -1171,6 +1195,16 @@ describe('autocmd api', function() end) describe('nvim_clear_autocmds', function() + it('validation', function() + eq("Cannot use both 'pattern' and 'buffer'", pcall_err(meths.clear_autocmds, { + pattern = '*', + buffer = 42, + })) + eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, { + event = {'FileType', {}} + })) + end) + it('should clear based on event + pattern', function() command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') -- cgit From 556f8646c01d1751cf39fe4df9c622899dceab9d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 14:19:28 -0500 Subject: refactor(api): consistent VALIDATE messages #22262 Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace. --- test/functional/api/autocmd_spec.lua | 43 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index f10f18174e..d1a93b5a86 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -30,11 +30,11 @@ describe('autocmd api', function() })) eq("Required: 'command' or 'callback'", pcall_err(meths.create_autocmd, 'FileType', { })) - eq('Invalid desc: expected String, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + eq("Invalid 'desc': expected String, got Integer", pcall_err(meths.create_autocmd, 'FileType', { command = 'ls', desc = 42, })) - eq('Invalid callback: expected Lua function or Vim function name, got Integer', pcall_err(meths.create_autocmd, 'FileType', { + eq("Invalid 'callback': expected Lua function or Vim function name, got Integer", pcall_err(meths.create_autocmd, 'FileType', { callback = 0, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, @@ -301,6 +301,27 @@ describe('autocmd api', function() end) describe('nvim_get_autocmds', function() + it('validation', function() + eq("Invalid 'group': 9997999", pcall_err(meths.get_autocmds, { + group = 9997999, + })) + eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, { + group = 'bogus', + })) + eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, { + group = {}, + })) + eq("Invalid 'buffer': expected Integer or Array, got Boolean", pcall_err(meths.get_autocmds, { + buffer = true, + })) + eq("Invalid 'event': expected String or Array", pcall_err(meths.get_autocmds, { + event = true, + })) + eq("Invalid 'pattern': expected String or Array, got Boolean", pcall_err(meths.get_autocmds, { + pattern = true, + })) + end) + describe('events', function() it('returns one autocmd when there is only one for an event', function() command [[au! InsertEnter]] @@ -414,8 +435,8 @@ describe('autocmd api', function() pattern = "", }}, aus) - eq("Invalid buffer: expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) - eq("Invalid buffer: expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) + eq("Invalid 'buffer': expected Integer or Array, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = "foo" })) + eq("Invalid 'buffer': expected Integer, got String", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { "foo", 42 } })) eq("Invalid buffer id: 42", pcall_err(meths.get_autocmds, { event = "InsertEnter", buffer = { 42 } })) local bufs = {} @@ -585,7 +606,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid group: 'NotDefined'", code) + matches("Invalid 'group': 'NotDefined'", code) end) it('raises error for undefined augroup id', function() @@ -603,7 +624,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches('Invalid group: 1', code) + matches("Invalid 'group': 1", code) end) it('raises error for invalid group type', function() @@ -618,7 +639,7 @@ describe('autocmd api', function() ]], {})) eq(false, success) - matches("Invalid group: expected String or Integer, got Boolean", code) + matches("Invalid 'group': expected String or Integer, got Boolean", code) end) it('raises error for invalid pattern array', function() @@ -695,16 +716,16 @@ describe('autocmd api', function() describe('nvim_exec_autocmds', function() it('validation', function() - eq('Invalid group: 9997999', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': 9997999", pcall_err(meths.exec_autocmds, 'FileType', { group = 9997999, })) - eq("Invalid group: 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': 'bogus'", pcall_err(meths.exec_autocmds, 'FileType', { group = 'bogus', })) - eq('Invalid group: expected String or Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { group = {}, })) - eq('Invalid buffer: expected Integer, got Array', pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, -- cgit From 3ac952d4e27f4e2454332a730310316fe13fd4a3 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 23 Apr 2023 06:53:25 +0530 Subject: fix(api): avoid assertion when autocmd group id is 0 (#23210) --- test/functional/api/autocmd_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index b1e38e77a1..57390519de 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -39,6 +39,10 @@ describe('autocmd api', function() })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.create_autocmd, {'FileType', {}}, {})) + eq("Invalid 'group': 0", pcall_err(meths.create_autocmd, 'FileType', { + group = 0, + command = 'ls', + })) end) it('doesnt leak when you use ++once', function() @@ -308,6 +312,9 @@ describe('autocmd api', function() eq("Invalid 'group': 'bogus'", pcall_err(meths.get_autocmds, { group = 'bogus', })) + eq("Invalid 'group': 0", pcall_err(meths.get_autocmds, { + group = 0, + })) eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.get_autocmds, { group = {}, })) @@ -725,6 +732,9 @@ describe('autocmd api', function() eq("Invalid 'group': expected String or Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { group = {}, })) + eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', { + group = 0, + })) eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) @@ -1049,6 +1059,12 @@ describe('autocmd api', function() eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]]) eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 0)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 0)) + + eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, 12342)]]) + eq('Vim:E367: No such group: "[NULL]"', pcall_err(meths.del_augroup_by_id, 12312)) end) it('groups work with once', function() @@ -1224,6 +1240,7 @@ describe('autocmd api', function() eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.clear_autocmds, { event = {'FileType', {}} })) + eq("Invalid 'group': 0", pcall_err(meths.clear_autocmds, {group = 0})) end) it('should clear based on event + pattern', function() -- cgit From dd24ea819507e3a5da04df55df7dda5240e5b57f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Jun 2023 09:29:12 +0800 Subject: fix(events): don't expand non-file as file name --- test/functional/api/autocmd_spec.lua | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 57390519de..4cfe8672b1 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -228,23 +228,28 @@ describe('autocmd api', function() end) it('receives an args table', function() - local res = exec_lua [[ - local group_id = vim.api.nvim_create_augroup("TestGroup", {}) - local autocmd_id = vim.api.nvim_create_autocmd("User", { + local group_id = meths.create_augroup("TestGroup", {}) + -- Having an existing autocmd calling expand("") shouldn't change args #18964 + meths.create_autocmd('User', { + group = 'TestGroup', + pattern = 'Te*', + command = 'call expand("")', + }) + + local autocmd_id = exec_lua [[ + return vim.api.nvim_create_autocmd("User", { group = "TestGroup", pattern = "Te*", callback = function(args) vim.g.autocmd_args = args end, }) - - return {group_id, autocmd_id} ]] meths.exec_autocmds("User", {pattern = "Test pattern"}) eq({ - id = res[2], - group = res[1], + id = autocmd_id, + group = group_id, event = "User", match = "Test pattern", file = "Test pattern", @@ -252,27 +257,24 @@ describe('autocmd api', function() }, meths.get_var("autocmd_args")) -- Test without a group - res = exec_lua [[ - local autocmd_id = vim.api.nvim_create_autocmd("User", { + autocmd_id = exec_lua [[ + return vim.api.nvim_create_autocmd("User", { pattern = "*", callback = function(args) vim.g.autocmd_args = args end, }) - - return {autocmd_id} ]] meths.exec_autocmds("User", {pattern = "some_pat"}) eq({ - id = res[1], + id = autocmd_id, group = nil, event = "User", match = "some_pat", file = "some_pat", buf = 1, }, meths.get_var("autocmd_args")) - end) it('can receive arbitrary data', function() -- cgit From 0b351c3740d621689b17267171e162abd421e759 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 2 Aug 2023 13:00:13 +0200 Subject: test(api): update tests to new error messages --- test/functional/api/autocmd_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 4cfe8672b1..ba267e7539 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -737,7 +737,7 @@ describe('autocmd api', function() eq("Invalid 'group': 0", pcall_err(meths.exec_autocmds, 'FileType', { group = 0, })) - eq("Invalid 'buffer': expected Integer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { + eq("Invalid 'buffer': expected Buffer, got Array", pcall_err(meths.exec_autocmds, 'FileType', { buffer = {}, })) eq("Invalid 'event' item: expected String, got Array", pcall_err(meths.exec_autocmds, -- cgit From 139e6f68f937b9efcadf2709ee1c83213d3266fa Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:50:44 +0200 Subject: fix(autocmd): API functions accept garbage after event name #25523 "VimEnter foo" was accepted as a valid event name for "VimEnter". Events delimited with commas, eg. "VimEnter,BufRead", were also accepted, even though only the first event was actually parsed. Co-authored-by: ii14 --- test/functional/api/autocmd_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index ba267e7539..bcae35d724 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -43,6 +43,11 @@ describe('autocmd api', function() group = 0, command = 'ls', })) + + eq("Invalid 'event': 'foo'", pcall_err(meths.create_autocmd, 'foo', { command = '' })) + eq("Invalid 'event': 'VimEnter '", pcall_err(meths.create_autocmd, 'VimEnter ', { command = '' })) + eq("Invalid 'event': 'VimEnter foo'", pcall_err(meths.create_autocmd, 'VimEnter foo', { command = '' })) + eq("Invalid 'event': 'BufAdd,BufDelete'", pcall_err(meths.create_autocmd, 'BufAdd,BufDelete', { command = '' })) end) it('doesnt leak when you use ++once', function() -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- test/functional/api/autocmd_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/autocmd_spec.lua') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index bcae35d724..fd46a1dcfa 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -1333,7 +1333,7 @@ describe('autocmd api', function() local without_group = meths.get_autocmds(search) eq(2, #without_group) - -- Doest clear with passing group. + -- Doesn't clear with passing group. meths.clear_autocmds { buffer = 0, group = search.group } local with_group = meths.get_autocmds(search) eq(1, #with_group) -- cgit