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/lua/api_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/api_spec.lua') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 03832978a4..dc6452dd62 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -33,7 +33,7 @@ describe('luaeval(vim.api.…)', function() describe('with errors', function() it('transforms API error from nvim_buf_set_lines into lua error', function() funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) - eq({false, 'String cannot contain newlines'}, + eq({false, "'replacement string' item contains newlines"}, funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}')) end) -- cgit From fd68cd1c0aa7b3074ed8b316a354bf17111cf0b3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 18:27:33 +0800 Subject: vim-patch:8.2.2857: Vim9: exception in ISN_INSTR caught at wrong level (#23131) Problem: Vim9: exception in ISN_INSTR caught at wrong level. Solution: Set the starting trylevel in exec_instructions(). (closes vim/vim#8214) https://github.com/vim/vim/commit/ff65288aa89dcd50760ad942d58baff70c6e93e6 Co-authored-by: Bram Moolenaar --- test/functional/lua/api_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/api_spec.lua') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index dc6452dd62..ffa2f40e91 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -103,9 +103,9 @@ describe('luaeval(vim.api.…)', function() eq(NIL, funcs.luaeval('vim.api.nvim__id(nil)')) -- API strings from Blobs can work as NUL-terminated C strings - eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ', + eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', exc_exec('call nvim_eval(v:_null_blob)')) - eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ', + eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', exc_exec('call nvim_eval(0z)')) eq(1, eval('nvim_eval(0z31)')) -- 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/lua/api_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/lua/api_spec.lua') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index ffa2f40e91..5dfc2eb83b 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -173,7 +173,7 @@ describe('luaeval(vim.api.…)', function() it('errors out correctly when working with API', function() -- Conversion errors - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Cannot convert given lua table', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))) -- Errors in number of arguments eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument', @@ -183,32 +183,32 @@ describe('luaeval(vim.api.…)', function() eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 2 arguments', remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2, 3)")]]))) -- Error in argument types - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua string', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'name': Expected Lua string]], remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_var(1, 2)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua number', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Expected Lua number]], remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'start': Number is not integral]], remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua number', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'window': Expected Lua number]], remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Lua number]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'flt': Expected Float-like Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float({[vim.type_idx]=vim.types.dictionary})")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array(1)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'arr': Expected Array-like Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_array({[vim.type_idx]=vim.types.dictionary})")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary(1)")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Unexpected type', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'dct': Expected Dict-like Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.array})")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table', + eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua table]], remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))) -- TODO: check for errors with Tabpage argument -- cgit From dbcba26bf1e4ec717dc488b73351f8a9bb93ff26 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 9 Aug 2023 20:25:16 +0200 Subject: fix(api): revert unintended change of optional bool params Currently (as of nvim 0.9), the behavior of boolean params in vim.api lua wrappers is inconsistent for optional parameters (part of an `opts` dict) compared to positional parameters. This was inadvertently changed in #24524 . While cleaning up this inconsistency is something we might want eventually, it needs to be discussed separately and the impact of existing code considered. --- test/functional/lua/api_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/functional/lua/api_spec.lua') diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 5dfc2eb83b..d808693a9e 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -9,6 +9,7 @@ local eval = helpers.eval local NIL = helpers.NIL local eq = helpers.eq local exec_lua = helpers.exec_lua +local pcall_err = helpers.pcall_err before_each(clear) @@ -171,6 +172,29 @@ describe('luaeval(vim.api.…)', function() eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({})'))]])) end) + it('converts booleans in positional args', function() + eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, false) ]]) + eq({''}, exec_lua [[ return vim.api.nvim_buf_get_lines(0, 0, 10, nil) ]]) + eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, true) ]])) + eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 1) ]])) + + -- this follows lua conventions for bools (not api convention for Boolean) + eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, 0) ]])) + eq('Index out of bounds', pcall_err(exec_lua, [[ return vim.api.nvim_buf_get_lines(0, 0, 10, {}) ]])) + end) + + it('converts booleans in optional args', function() + eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=false}) ]]) + eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {}) ]]) -- same as {output=nil} + + -- API conventions (not lua conventions): zero is falsy + eq({}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=0}) ]]) + + eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=true}) ]]) + eq({output='foobar'}, exec_lua [[ return vim.api.nvim_exec2("echo 'foobar'", {output=1}) ]]) + eq([[Invalid 'output': not a boolean]], pcall_err(exec_lua, [[ return vim.api.nvim_exec2("echo 'foobar'", {output={}}) ]])) + end) + it('errors out correctly when working with API', function() -- Conversion errors eq([[Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Invalid 'obj': Cannot convert given Lua table]], -- cgit