diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 03:05:22 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-03 03:05:22 -0800 |
| commit | a064ed622927b4c5e30165abbe54db841359c71f (patch) | |
| tree | 76973648e9ad684068457ff021b4d13281bfad84 /test/functional/lua | |
| parent | ee2127363463b89ba9d5071babcb9bd16c4db691 (diff) | |
| parent | 04f2f864e270e772c6326cefdf24947f0130e492 (diff) | |
| download | rneovim-a064ed622927b4c5e30165abbe54db841359c71f.tar.gz rneovim-a064ed622927b4c5e30165abbe54db841359c71f.tar.bz2 rneovim-a064ed622927b4c5e30165abbe54db841359c71f.zip | |
Merge #26398 lintlua for test/ dir
Diffstat (limited to 'test/functional/lua')
32 files changed, 3904 insertions, 2223 deletions
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua index 8c03eb60ec..55f9ba7e13 100644 --- a/test/functional/lua/api_spec.lua +++ b/test/functional/lua/api_spec.lua @@ -17,50 +17,63 @@ describe('luaeval(vim.api.…)', function() describe('with channel_id and buffer handle', function() describe('nvim_buf_get_lines', function() it('works', function() - funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) - eq({'a\000b'}, - funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)')) + funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) + eq({ 'a\000b' }, funcs.luaeval('vim.api.nvim_buf_get_lines(1, 2, 3, false)')) end) end) describe('nvim_buf_set_lines', function() it('works', function() - funcs.setline(1, {"abc", "def", "a\nb", "ttt"}) + funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) eq(NIL, funcs.luaeval('vim.api.nvim_buf_set_lines(1, 1, 2, false, {"b\\0a"})')) - eq({'abc', 'b\000a', 'a\000b', 'ttt'}, - funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)')) + eq( + { 'abc', 'b\000a', 'a\000b', 'ttt' }, + funcs.luaeval('vim.api.nvim_buf_get_lines(1, 0, 4, false)') + ) end) end) end) 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, "'replacement string' item contains newlines"}, - funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}')) + funcs.setline(1, { 'abc', 'def', 'a\nb', 'ttt' }) + eq( + { false, "'replacement string' item contains newlines" }, + funcs.luaeval('{pcall(vim.api.nvim_buf_set_lines, 1, 1, 2, false, {"b\\na"})}') + ) end) it('transforms API error from nvim_win_set_cursor into lua error', function() - eq({false, 'Argument "pos" must be a [row, col] array'}, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}')) + eq( + { false, 'Argument "pos" must be a [row, col] array' }, + funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {1, 2, 3})}') + ) -- Used to produce a memory leak due to a bug in nvim_win_set_cursor - eq({false, 'Invalid window id: -1'}, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}')) + eq( + { false, 'Invalid window id: -1' }, + funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, -1, {1, 2, 3})}') + ) end) - it('transforms API error from nvim_win_set_cursor + same array as in first test into lua error', - function() - eq({false, 'Argument "pos" must be a [row, col] array'}, - funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}')) - end) + it( + 'transforms API error from nvim_win_set_cursor + same array as in first test into lua error', + function() + eq( + { false, 'Argument "pos" must be a [row, col] array' }, + funcs.luaeval('{pcall(vim.api.nvim_win_set_cursor, 0, {"b\\na"})}') + ) + end + ) end) it('correctly evaluates API code which calls luaeval', function() - local str = (([===[vim.api.nvim_eval([==[ + local str = ( + ([===[vim.api.nvim_eval([==[ luaeval('vim.api.nvim_eval([=[ luaeval("vim.api.nvim_eval([[ luaeval(1) ]])") ]=])') - ]==])]===]):gsub('\n', ' ')) + ]==])]===]):gsub('\n', ' ') + ) eq(1, funcs.luaeval(str)) end) @@ -86,28 +99,32 @@ describe('luaeval(vim.api.…)', function() eq(6, eval([[type(luaeval('vim.api.nvim_eval("v:false")'))]])) eq(7, eval([[type(luaeval('vim.api.nvim_eval("v:null")'))]])) - eq({foo=42}, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]])) - eq({42}, funcs.luaeval([[vim.api.nvim_eval('[42]')]])) + eq({ foo = 42 }, funcs.luaeval([[vim.api.nvim_eval('{"foo": 42}')]])) + eq({ 42 }, funcs.luaeval([[vim.api.nvim_eval('[42]')]])) - eq({foo={bar=42}, baz=50}, funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]])) - eq({{42}, {}}, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=])) + eq( + { foo = { bar = 42 }, baz = 50 }, + funcs.luaeval([[vim.api.nvim_eval('{"foo": {"bar": 42}, "baz": 50}')]]) + ) + eq({ { 42 }, {} }, funcs.luaeval([=[vim.api.nvim_eval('[[42], []]')]=])) end) it('correctly converts to API objects', function() eq(1, funcs.luaeval('vim.api.nvim__id(1)')) eq('1', funcs.luaeval('vim.api.nvim__id("1")')) - eq({1}, funcs.luaeval('vim.api.nvim__id({1})')) - eq({foo=1}, funcs.luaeval('vim.api.nvim__id({foo=1})')) + eq({ 1 }, funcs.luaeval('vim.api.nvim__id({1})')) + eq({ foo = 1 }, funcs.luaeval('vim.api.nvim__id({foo=1})')) eq(1.5, funcs.luaeval('vim.api.nvim__id(1.5)')) eq(true, funcs.luaeval('vim.api.nvim__id(true)')) eq(false, funcs.luaeval('vim.api.nvim__id(false)')) 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: ""', - exc_exec('call nvim_eval(v:_null_blob)')) - eq('Vim(call):E5555: API call: Vim:E15: Invalid expression: ""', - exc_exec('call nvim_eval(0z)')) + 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: ""', exc_exec('call nvim_eval(0z)')) eq(1, eval('nvim_eval(0z31)')) eq(0, eval([[type(luaeval('vim.api.nvim__id(1)'))]])) @@ -119,27 +136,56 @@ describe('luaeval(vim.api.…)', function() eq(6, eval([[type(luaeval('vim.api.nvim__id(false)'))]])) eq(7, eval([[type(luaeval('vim.api.nvim__id(nil)'))]])) - eq({foo=1, bar={42, {{baz=true}, 5}}}, funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})')) + eq( + { foo = 1, bar = { 42, { { baz = true }, 5 } } }, + funcs.luaeval('vim.api.nvim__id({foo=1, bar={42, {{baz=true}, 5}}})') + ) eq(true, funcs.luaeval('vim.api.nvim__id(vim.api.nvim__id)(true)')) - eq(42, exec_lua [[ + eq( + 42, + exec_lua [[ local f = vim.api.nvim__id({42, vim.api.nvim__id}) return f[2](f[1]) - ]]) + ]] + ) end) it('correctly converts container objects with type_idx to API objects', function() - eq(5, eval('type(luaeval("vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))')) + eq( + 5, + eval('type(luaeval("vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=0})"))') + ) eq(4, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary})'))]])) eq(3, eval([[type(luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})'))]])) eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array})')) -- Presence of type_idx makes Vim ignore some keys - eq({42}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({foo=2}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq(10, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({}, funcs.luaeval('vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + eq( + { 42 }, + funcs.luaeval( + 'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' + ) + ) + eq( + { foo = 2 }, + funcs.luaeval( + 'vim.api.nvim__id({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' + ) + ) + eq( + 10, + funcs.luaeval( + 'vim.api.nvim__id({[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' + ) + ) + eq( + {}, + funcs.luaeval( + 'vim.api.nvim__id({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})' + ) + ) end) it('correctly converts arrays with type_idx to API objects', function() @@ -147,24 +193,67 @@ describe('luaeval(vim.api.…)', function() eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array})')) - eq({42}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({{foo=2}}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({10}, funcs.luaeval('vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({}, funcs.luaeval('vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})')) + eq( + { 42 }, + funcs.luaeval( + 'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' + ) + ) + eq( + { { foo = 2 } }, + funcs.luaeval( + 'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' + ) + ) + eq( + { 10 }, + funcs.luaeval( + 'vim.api.nvim__id_array({{[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' + ) + ) + eq( + {}, + funcs.luaeval( + 'vim.api.nvim__id_array({[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2})' + ) + ) eq({}, funcs.luaeval('vim.api.nvim__id_array({})')) eq(3, eval([[type(luaeval('vim.api.nvim__id_array({})'))]])) end) it('correctly converts dictionaries with type_idx to API objects', function() - eq(4, eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]])) + eq( + 4, + eval([[type(luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})'))]]) + ) eq({}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary})')) - eq({v={42}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({foo=2}, funcs.luaeval('vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})')) - eq({v=10}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})')) - eq({v={}}, funcs.luaeval('vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})')) + eq( + { v = { 42 } }, + funcs.luaeval( + 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' + ) + ) + eq( + { foo = 2 }, + funcs.luaeval( + 'vim.api.nvim__id_dictionary({[vim.type_idx]=vim.types.dictionary, [vim.val_idx]=10, [5]=1, foo=2, [1]=42})' + ) + ) + eq( + { v = 10 }, + funcs.luaeval( + 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.float, [vim.val_idx]=10, [5]=1, foo=2, [1]=42}})' + ) + ) + eq( + { v = {} }, + funcs.luaeval( + 'vim.api.nvim__id_dictionary({v={[vim.type_idx]=vim.types.array, [vim.val_idx]=10, [5]=1, foo=2}})' + ) + ) -- If API requests dictionary, then empty table will be the one. This is not -- the case normally because empty table is an empty array. @@ -173,14 +262,26 @@ describe('luaeval(vim.api.…)', function() 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) ]])) + 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, {}) ]])) + 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() @@ -190,50 +291,92 @@ describe('luaeval(vim.api.…)', function() -- 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={}}) ]])) + 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]], - remove_trace(exc_exec([[call luaeval("vim.api.nvim__id({1, foo=42})")]]))) + 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', - remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]]))) - eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument', - remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]]))) - 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)")]]))) + eq( + 'Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument', + remove_trace(exc_exec([[call luaeval("vim.api.nvim__id()")]])) + ) + eq( + 'Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected 1 argument', + remove_trace(exc_exec([[call luaeval("vim.api.nvim__id(1, 2)")]])) + ) + 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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]], - remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]]))) + 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: 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: 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: 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: 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: 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: 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: 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: 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: 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]], + remove_trace(exc_exec([[call luaeval("vim.api.nvim_set_keymap('', '', '', '')")]])) + ) -- TODO: check for errors with Tabpage argument -- TODO: check for errors with Window argument @@ -243,7 +386,12 @@ describe('luaeval(vim.api.…)', function() it('accepts any value as API Boolean', function() eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", vim, false, nil)')) eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", 0, 1.5, "test")')) - eq('', funcs.luaeval('vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})')) + eq( + '', + funcs.luaeval( + 'vim.api.nvim_replace_termcodes("", true, {}, {[vim.type_idx]=vim.types.array})' + ) + ) end) it('serializes sparse arrays in Lua', function() diff --git a/test/functional/lua/base64_spec.lua b/test/functional/lua/base64_spec.lua index f0d112c23e..21fd536a98 100644 --- a/test/functional/lua/base64_spec.lua +++ b/test/functional/lua/base64_spec.lua @@ -49,12 +49,15 @@ describe('vim.base64', function() end -- Explicitly check encoded output - eq('VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=', encode('The quick brown fox jumps over the lazy dog\n')) + eq( + 'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZwo=', + encode('The quick brown fox jumps over the lazy dog\n') + ) -- Test vectors from rfc4648 local rfc4648 = { { '', '' }, - { 'f', 'Zg==', }, + { 'f', 'Zg==' }, { 'fo', 'Zm8=' }, { 'foo', 'Zm9v' }, { 'foob', 'Zm9vYg==' }, diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index a3f637e4de..073ac40ef1 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -14,15 +14,17 @@ local expect_events = helpers.expect_events local write_file = helpers.write_file local dedent = helpers.dedent -local origlines = {"original line 1", - "original line 2", - "original line 3", - "original line 4", - "original line 5", - "original line 6", - " indented line"} - -before_each(function () +local origlines = { + 'original line 1', + 'original line 2', + 'original line 3', + 'original line 4', + 'original line 5', + 'original line 6', + ' indented line', +} + +before_each(function() clear() exec_lua [[ local evname = ... @@ -57,11 +59,11 @@ describe('lua buffer event callbacks: on_lines', function() if verify then lastsize = meths.buf_get_offset(0, meths.buf_line_count(0)) end - exec_lua("return test_register(...)", 0, "on_lines", "test1",false,utf_sizes) - local verify_name = "test1" + exec_lua('return test_register(...)', 0, 'on_lines', 'test1', false, utf_sizes) + local verify_name = 'test1' local function check_events(expected) - local events = exec_lua("return get_events(...)" ) + local events = exec_lua('return get_events(...)') if utf_sizes then -- this test case uses ASCII only, so sizes should be the same. -- Unicode is tested below. @@ -70,10 +72,10 @@ describe('lua buffer event callbacks: on_lines', function() event[10] = event[10] or event[9] end end - expect_events(expected, events, "line updates") + expect_events(expected, events, 'line updates') if verify then for _, event in ipairs(events) do - if event[1] == verify_name and event[2] == "lines" then + if event[1] == verify_name and event[2] == 'lines' then local startline, endline = event[5], event[7] local newrange = meths.buf_get_offset(0, endline) - meths.buf_get_offset(0, startline) local newsize = meths.buf_get_offset(0, meths.buf_line_count(0)) @@ -84,101 +86,102 @@ describe('lua buffer event callbacks: on_lines', function() end end end - return check_events, function(new) verify_name = new end + return check_events, function(new) + verify_name = new + end end - -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot -- assert the wrong thing), but masks errors with unflushed lines (as -- nvim_buf_get_offset forces a flush of the memline). To be safe run the -- test both ways. - local function check(verify,utf_sizes) + local function check(verify, utf_sizes) local check_events, verify_name = setup_eventcheck(verify, utf_sizes, origlines) local tick = meths.buf_get_changedtick(0) command('set autoindent') command('normal! GyyggP') tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 0, 0, 1, 0}} + check_events { { 'test1', 'lines', 1, tick, 0, 0, 1, 0 } } - meths.buf_set_lines(0, 3, 5, true, {"changed line"}) + meths.buf_set_lines(0, 3, 5, true, { 'changed line' }) tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 3, 5, 4, 32 }} + check_events { { 'test1', 'lines', 1, tick, 3, 5, 4, 32 } } - exec_lua("return test_register(...)", 0, "on_lines", "test2", true, utf_sizes) + exec_lua('return test_register(...)', 0, 'on_lines', 'test2', true, utf_sizes) tick = tick + 1 command('undo') -- plugins can opt in to receive changedtick events, or choose -- to only receive actual changes. check_events { - { "test1", "lines", 1, tick, 3, 4, 5, 13 }; - { "test2", "lines", 1, tick, 3, 4, 5, 13 }; - { "test2", "changedtick", 1, tick+1 }; + { 'test1', 'lines', 1, tick, 3, 4, 5, 13 }, + { 'test2', 'lines', 1, tick, 3, 4, 5, 13 }, + { 'test2', 'changedtick', 1, tick + 1 }, } tick = tick + 1 tick = tick + 1 command('redo') check_events { - { "test1", "lines", 1, tick, 3, 5, 4, 32 }; - { "test2", "lines", 1, tick, 3, 5, 4, 32 }; - { "test2", "changedtick", 1, tick+1 }; + { 'test1', 'lines', 1, tick, 3, 5, 4, 32 }, + { 'test2', 'lines', 1, tick, 3, 5, 4, 32 }, + { 'test2', 'changedtick', 1, tick + 1 }, } tick = tick + 1 tick = tick + 1 command('undo!') check_events { - { "test1", "lines", 1, tick, 3, 4, 5, 13 }; - { "test2", "lines", 1, tick, 3, 4, 5, 13 }; - { "test2", "changedtick", 1, tick+1 }; + { 'test1', 'lines', 1, tick, 3, 4, 5, 13 }, + { 'test2', 'lines', 1, tick, 3, 4, 5, 13 }, + { 'test2', 'changedtick', 1, tick + 1 }, } tick = tick + 1 -- simulate next callback returning true exec_lua("test_unreg = 'test1'") - meths.buf_set_lines(0, 6, 7, true, {"x1","x2","x3"}) + meths.buf_set_lines(0, 6, 7, true, { 'x1', 'x2', 'x3' }) tick = tick + 1 -- plugins can opt in to receive changedtick events, or choose -- to only receive actual changes. check_events { - { "test1", "lines", 1, tick, 6, 7, 9, 16 }; - { "test2", "lines", 1, tick, 6, 7, 9, 16 }; + { 'test1', 'lines', 1, tick, 6, 7, 9, 16 }, + { 'test2', 'lines', 1, tick, 6, 7, 9, 16 }, } - verify_name "test2" + verify_name 'test2' - meths.buf_set_lines(0, 1, 1, true, {"added"}) + meths.buf_set_lines(0, 1, 1, true, { 'added' }) tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 1, 1, 2, 0 }} + check_events { { 'test2', 'lines', 1, tick, 1, 1, 2, 0 } } feed('wix') tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 16 }} + check_events { { 'test2', 'lines', 1, tick, 4, 5, 5, 16 } } -- check hot path for multiple insert feed('yz') tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 17 }} + check_events { { 'test2', 'lines', 1, tick, 4, 5, 5, 17 } } feed('<bs>') tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 4, 5, 5, 19 }} + check_events { { 'test2', 'lines', 1, tick, 4, 5, 5, 19 } } feed('<esc>Go') tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 11, 11, 12, 0 }} + check_events { { 'test2', 'lines', 1, tick, 11, 11, 12, 0 } } feed('x') tick = tick + 1 - check_events {{ "test2", "lines", 1, tick, 11, 12, 12, 5 }} + check_events { { 'test2', 'lines', 1, tick, 11, 12, 12, 5 } } |