diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
| commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
| tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/lua | |
| parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
| download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip | |
refactor: format test/*
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 } } command('bwipe!') - check_events {{ "test2", "detach", 1 }} - end + check_events { { 'test2', 'detach', 1 } } + end it('works', function() check(false) @@ -189,54 +192,56 @@ describe('lua buffer event callbacks: on_lines', function() end) it('works with utf_sizes and ASCII text', function() - check(false,true) + check(false, true) end) local function check_unicode(verify) - local unicode_text = {"ascii text", - "latin text åäö", - "BMP text ɧ αλφά", - "BMP text 汉语 ↥↧", - "SMP 🤦 🦄🦃", - "combining å بِيَّة"} + local unicode_text = { + 'ascii text', + 'latin text åäö', + 'BMP text ɧ αλφά', + 'BMP text 汉语 ↥↧', + 'SMP 🤦 🦄🦃', + 'combining å بِيَّة', + } local check_events, verify_name = setup_eventcheck(verify, true, unicode_text) local tick = meths.buf_get_changedtick(0) feed('ggdd') tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 0, 1, 0, 11, 11, 11 }} + check_events { { 'test1', 'lines', 1, tick, 0, 1, 0, 11, 11, 11 } } feed('A<bs>') tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 0, 1, 1, 18, 15, 15 }} + check_events { { 'test1', 'lines', 1, tick, 0, 1, 1, 18, 15, 15 } } feed('<esc>jylp') tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 1, 2, 2, 21, 16, 16 }} + check_events { { 'test1', 'lines', 1, tick, 1, 2, 2, 21, 16, 16 } } feed('+eea<cr>') tick = tick + 1 - check_events {{ "test1", "lines", 1, tick, 2, 3, 4, 23, 15, 15 }} + check_events { { 'test1', 'lines', 1, tick, 2, 3, 4, 23, 15, 15 } } feed('<esc>jdw') tick = tick + 1 -- non-BMP chars count as 2 UTF-2 codeunits - check_events {{ "test1", "lines", 1, tick, 4, 5, 5, 18, 9, 12 }} + check_events { { 'test1', 'lines', 1, tick, 4, 5, 5, 18, 9, 12 } } feed('+rx') tick = tick + 1 -- count the individual codepoints of a composed character. - check_events {{ "test1", "lines", 1, tick, 5, 6, 6, 27, 20, 20 }} + check_events { { 'test1', 'lines', 1, tick, 5, 6, 6, 27, 20, 20 } } feed('kJ') tick = tick + 1 -- verification fails with multiple line updates, sorry about that - verify_name "" + verify_name '' -- NB: this is inefficient (but not really wrong). check_events { - { "test1", "lines", 1, tick, 4, 5, 5, 14, 5, 8 }; - { "test1", "lines", 1, tick+1, 5, 6, 5, 27, 20, 20 }; + { 'test1', 'lines', 1, tick, 4, 5, 5, 14, 5, 8 }, + { 'test1', 'lines', 1, tick + 1, 5, 6, 5, 27, 20, 20 }, } end @@ -248,9 +253,8 @@ describe('lua buffer event callbacks: on_lines', function() check_unicode(true) end) - it('has valid cursor position while shifting', function() - meths.buf_set_lines(0, 0, -1, true, {'line1'}) + meths.buf_set_lines(0, 0, -1, true, { 'line1' }) exec_lua([[ vim.api.nvim_buf_attach(0, false, { on_lines = function() @@ -263,10 +267,10 @@ describe('lua buffer event callbacks: on_lines', function() end) it('has valid cursor position while deleting lines', function() - meths.buf_set_lines(0, 0, -1, true, { "line_1", "line_2", "line_3", "line_4"}) - meths.win_set_cursor(0, {2, 0}) + meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3', 'line_4' }) + meths.win_set_cursor(0, { 2, 0 }) eq(2, meths.win_get_cursor(0)[1]) - meths.buf_set_lines(0, 0, -1, true, { "line_1", "line_2", "line_3"}) + meths.buf_set_lines(0, 0, -1, true, { 'line_1', 'line_2', 'line_3' }) eq(2, meths.win_get_cursor(0)[1]) end) @@ -286,16 +290,16 @@ describe('lua buffer event callbacks: on_lines', function() ]] exec_lua(code) - command("q!") + command('q!') helpers.assert_alive() exec_lua(code) - command("bd!") + command('bd!') helpers.assert_alive() end) it('#12718 lnume', function() - meths.buf_set_lines(0, 0, -1, true, {'1', '2', '3'}) + meths.buf_set_lines(0, 0, -1, true, { '1', '2', '3' }) exec_lua([[ vim.api.nvim_buf_attach(0, false, { on_lines = function(...) @@ -308,28 +312,31 @@ describe('lua buffer event callbacks: on_lines', function() feed('G0') feed('p') -- Is the last arg old_byte_size correct? Doesn't matter for this PR - eq(meths.get_var('linesev'), { "lines", 1, 4, 2, 3, 5, 4 }) + eq(meths.get_var('linesev'), { 'lines', 1, 4, 2, 3, 5, 4 }) feed('2G0') feed('p') - eq(meths.get_var('linesev'), { "lines", 1, 5, 1, 4, 4, 8 }) + eq(meths.get_var('linesev'), { 'lines', 1, 5, 1, 4, 4, 8 }) feed('1G0') feed('P') - eq(meths.get_var('linesev'), { "lines", 1, 6, 0, 3, 3, 9 }) + eq(meths.get_var('linesev'), { 'lines', 1, 6, 0, 3, 3, 9 }) end) - it('calling nvim_buf_call() from callback does not cause Normal mode CTRL-A to misbehave #16729', function() - exec_lua([[ + it( + 'calling nvim_buf_call() from callback does not cause Normal mode CTRL-A to misbehave #16729', + function() + exec_lua([[ vim.api.nvim_buf_attach(0, false, { on_lines = function(...) vim.api.nvim_buf_call(0, function() end) end, }) ]]) - feed('itest123<Esc><C-A>') - eq('test124', meths.get_current_line()) - end) + feed('itest123<Esc><C-A>') + eq('test124', meths.get_current_line()) + end + ) end) describe('lua: nvim_buf_attach on_bytes', function() @@ -350,13 +357,13 @@ describe('lua: nvim_buf_attach on_bytes', function() local len = meths.buf_get_offset(0, meths.buf_line_count(0)) eq(len == -1 and 1 or len, string.len(shadowbytes)) end - exec_lua("return test_register(...)", 0, "on_bytes", "test1", false, false, true) + exec_lua('return test_register(...)', 0, 'on_bytes', 'test1', false, false, true) meths.buf_get_changedtick(0) - local verify_name = "test1" + local verify_name = 'test1' local function check_events(expected) - local events = exec_lua("return get_events(...)" ) - expect_events(expected, events, "byte updates") + local events = exec_lua('return get_events(...)') + expect_events(expected, events, 'byte updates') if not verify then return @@ -364,12 +371,12 @@ describe('lua: nvim_buf_attach on_bytes', function() for _, event in ipairs(events) do for _, elem in ipairs(event) do - if type(elem) == "number" and elem < 0 then - fail(string.format("Received event has negative values")) + if type(elem) == 'number' and elem < 0 then + fail(string.format('Received event has negative values')) end end - if event[1] == verify_name and event[2] == "bytes" then + if event[1] == verify_name and event[2] == 'bytes' then local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) local before = string.sub(shadowbytes, 1, start_byte) -- no text in the tests will contain 0xff bytes (invalid UTF-8) @@ -377,7 +384,7 @@ describe('lua: nvim_buf_attach on_bytes', function() local unknown = string.rep('\255', new_byte) local after = string.sub(shadowbytes, start_byte + old_byte + 1) shadowbytes = before .. unknown .. after - elseif event[1] == verify_name and event[2] == "reload" then + elseif event[1] == verify_name and event[2] == 'reload' then shadowbytes = table.concat(meths.buf_get_lines(0, 0, -1, true), '\n') .. '\n' end end @@ -385,7 +392,11 @@ describe('lua: nvim_buf_attach on_bytes', function() local text = meths.buf_get_lines(0, 0, -1, true) local bytes = table.concat(text, '\n') .. '\n' - eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') + eq( + string.len(bytes), + string.len(shadowbytes), + '\non_bytes: total bytecount of buffer is wrong' + ) for i = 1, string.len(shadowbytes) do local shadowbyte = string.sub(shadowbytes, i, i) if shadowbyte ~= '\255' then @@ -400,89 +411,89 @@ describe('lua: nvim_buf_attach on_bytes', function() -- Yes, we can do both local function do_both(verify) it('single and multiple join', function() - local check_events = setup_eventcheck(verify, origlines) - feed 'ggJ' - check_events { - {'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1}; - } + local check_events = setup_eventcheck(verify, origlines) + feed 'ggJ' + check_events { + { 'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1 }, + } - feed '3J' - check_events { - {'test1', 'bytes', 1, 5, 0, 31, 31, 1, 0, 1, 0, 1, 1}; - {'test1', 'bytes', 1, 5, 0, 47, 47, 1, 0, 1, 0, 1, 1}; - } + feed '3J' + check_events { + { 'test1', 'bytes', 1, 5, 0, 31, 31, 1, 0, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 0, 47, 47, 1, 0, 1, 0, 1, 1 }, + } end) it('opening lines', function() - local check_events = setup_eventcheck(verify, origlines) - -- meths.set_option_value('autoindent', true, {}) - feed 'Go' - check_events { - { "test1", "bytes", 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 1 }; - } - feed '<cr>' - check_events { - { "test1", "bytes", 1, 5, 7, 0, 114, 0, 0, 0, 1, 0, 1 }; - } + local check_events = setup_eventcheck(verify, origlines) + -- meths.set_option_value('autoindent', true, {}) + feed 'Go' + check_events { + { 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 1 }, + } + feed '<cr>' + check_events { + { 'test1', 'bytes', 1, 5, 7, 0, 114, 0, 0, 0, 1, 0, 1 }, + } end) it('opening lines with autoindent', function() - local check_events = setup_eventcheck(verify, origlines) - meths.set_option_value('autoindent', true, {}) - feed 'Go' - check_events { - { "test1", "bytes", 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 5 }; - } - feed '<cr>' - check_events { - { "test1", "bytes", 1, 4, 7, 0, 114, 0, 4, 4, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 7, 0, 114, 0, 0, 0, 1, 4, 5 }; - } + local check_events = setup_eventcheck(verify, origlines) + meths.set_option_value('autoindent', true, {}) + feed 'Go' + check_events { + { 'test1', 'bytes', 1, 3, 7, 0, 114, 0, 0, 0, 1, 0, 5 }, + } + feed '<cr>' + check_events { + { 'test1', 'bytes', 1, 4, 7, 0, 114, 0, 4, 4, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 7, 0, 114, 0, 0, 0, 1, 4, 5 }, + } end) it('setline(num, line)', function() local check_events = setup_eventcheck(verify, origlines) - funcs.setline(2, "babla") + funcs.setline(2, 'babla') check_events { - { "test1", "bytes", 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 }; + { 'test1', 'bytes', 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 }, } - funcs.setline(2, {"foo", "bar"}) + funcs.setline(2, { 'foo', 'bar' }) check_events { - { "test1", "bytes", 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 }; - { "test1", "bytes", 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 }; + { 'test1', 'bytes', 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 }, + { 'test1', 'bytes', 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 }, } local buf_len = meths.buf_line_count(0) - funcs.setline(buf_len + 1, "baz") + funcs.setline(buf_len + 1, 'baz') check_events { - { "test1", "bytes", 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 }; + { 'test1', 'bytes', 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 }, } end) it('continuing comments with fo=or', function() - local check_events = setup_eventcheck(verify, {'// Comment'}) + local check_events = setup_eventcheck(verify, { '// Comment' }) meths.set_option_value('formatoptions', 'ro', {}) meths.set_option_value('filetype', 'c', {}) feed 'A<CR>' check_events { - { "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 }; + { 'test1', 'bytes', 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 }, } feed '<ESC>' check_events { - { "test1", "bytes", 1, 4, 1, 2, 13, 0, 1, 1, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 1, 2, 13, 0, 1, 1, 0, 0, 0 }, } feed 'ggo' -- goto first line to continue testing check_events { - { "test1", "bytes", 1, 5, 1, 0, 11, 0, 0, 0, 1, 0, 4 }; + { 'test1', 'bytes', 1, 5, 1, 0, 11, 0, 0, 0, 1, 0, 4 }, } feed '<CR>' check_events { - { "test1", "bytes", 1, 6, 1, 2, 13, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 7, 1, 2, 13, 0, 0, 0, 1, 3, 4 }; + { 'test1', 'bytes', 1, 6, 1, 2, 13, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 7, 1, 2, 13, 0, 0, 0, 1, 3, 4 }, } end) @@ -491,59 +502,59 @@ describe('lua: nvim_buf_attach on_bytes', function() feed 'ia' check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, } end) - it("deleting lines", function() + it('deleting lines', function() local check_events = setup_eventcheck(verify, origlines) - feed("dd") + feed('dd') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 }, } - feed("d2j") + feed('d2j') check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 3, 0, 48, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 0, 0, 0, 3, 0, 48, 0, 0, 0 }, } - feed("ld<c-v>2j") + feed('ld<c-v>2j') check_events { - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 1, 1, 16, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 2, 1, 31, 0, 1, 1, 0, 0, 0 }; + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 1, 1, 16, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 2, 1, 31, 0, 1, 1, 0, 0, 0 }, } - feed("vjwd") + feed('vjwd') check_events { - { "test1", "bytes", 1, 10, 0, 1, 1, 1, 9, 23, 0, 0, 0 }; + { 'test1', 'bytes', 1, 10, 0, 1, 1, 1, 9, 23, 0, 0, 0 }, } end) - it("changing lines", function() + it('changing lines', function() local check_events = setup_eventcheck(verify, origlines) - feed "cc" + feed 'cc' check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 15, 15, 0, 0, 0 }, } - feed "<ESC>" + feed '<ESC>' check_events {} - feed "c3j" + feed 'c3j' check_events { - { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }, } end) - it("visual charwise paste", function() - local check_events = setup_eventcheck(verify, {'1234567890'}) + it('visual charwise paste', function() + local check_events = setup_eventcheck(verify, { '1234567890' }) funcs.setreg('a', '___') feed '1G1|vll' @@ -551,184 +562,188 @@ describe('lua: nvim_buf_attach on_bytes', function() feed '"ap' check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 0, 0, 0, 0, 0, 0, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 3, 3, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 0, 0, 0, 0, 0, 0, 0, 3, 3 }, } end) it('blockwise paste', function() - local check_events = setup_eventcheck(verify, {'1', '2', '3'}) + local check_events = setup_eventcheck(verify, { '1', '2', '3' }) feed('1G0') feed('y<C-v>2j') feed('G0') feed('p') check_events { - { "test1", "bytes", 1, 3, 2, 1, 5, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 3, 3, 0, 7, 0, 0, 0, 0, 3, 3 }; - { "test1", "bytes", 1, 3, 4, 0, 10, 0, 0, 0, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 2, 1, 5, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 3, 3, 0, 7, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 3, 4, 0, 10, 0, 0, 0, 0, 3, 3 }, } feed('2G0') feed('p') check_events { - { "test1", "bytes", 1, 4, 1, 1, 3, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 4, 2, 1, 6, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 4, 3, 1, 10, 0, 0, 0, 0, 1, 1 }; + { 'test1', 'bytes', 1, 4, 1, 1, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 4, 2, 1, 6, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 4, 3, 1, 10, 0, 0, 0, 0, 1, 1 }, } feed('1G0') feed('P') check_events { - { "test1", "bytes", 1, 5, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 5, 1, 0, 3, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 5, 2, 0, 7, 0, 0, 0, 0, 1, 1 }; + { 'test1', 'bytes', 1, 5, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 1, 0, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 2, 0, 7, 0, 0, 0, 0, 1, 1 }, } - end) - it("linewise paste", function() + it('linewise paste', function() local check_events = setup_eventcheck(verify, origlines) - feed'yyp' + feed 'yyp' check_events { - { "test1", "bytes", 1, 3, 1, 0, 16, 0, 0, 0, 1, 0, 16 }; + { 'test1', 'bytes', 1, 3, 1, 0, 16, 0, 0, 0, 1, 0, 16 }, } - feed'Gyyp' + feed 'Gyyp' check_events { - { "test1", "bytes", 1, 4, 8, 0, 130, 0, 0, 0, 1, 0, 18 }; + { 'test1', 'bytes', 1, 4, 8, 0, 130, 0, 0, 0, 1, 0, 18 }, } end) it('inccomand=nosplit and substitute', function() - local check_events = setup_eventcheck(verify, - {"abcde", "12345"}) + local check_events = setup_eventcheck(verify, { 'abcde', '12345' }) meths.set_option_value('inccommand', 'nosplit', {}) -- linewise substitute feed(':%s/bcd/') check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 0, 0, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 3, 3, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 0, 0, 0, 3, 3 }, } feed('a') check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 1, 1, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 3, 3, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 1, 1, 0, 3, 3 }, } - feed("<esc>") + feed('<esc>') -- splitting lines feed([[:%s/abc/\r]]) check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 1, 0, 1 }; - { "test1", "bytes", 1, 6, 0, 0, 0, 1, 0, 1, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 3, 3, 1, 0, 1 }, + { 'test1', 'bytes', 1, 6, 0, 0, 0, 1, 0, 1, 0, 3, 3 }, } - feed("<esc>") + feed('<esc>') -- multi-line regex feed([[:%s/de\n123/a]]) check_events { - { "test1", "bytes", 1, 3, 0, 3, 3, 1, 3, 6, 0, 1, 1 }; - { "test1", "bytes", 1, 6, 0, 3, 3, 0, 1, 1, 1, 3, 6 }; + { 'test1', 'bytes', 1, 3, 0, 3, 3, 1, 3, 6, 0, 1, 1 }, + { 'test1', 'bytes', 1, 6, 0, 3, 3, 0, 1, 1, 1, 3, 6 }, } - feed("<esc>") + feed('<esc>') -- replacing with unicode - feed(":%s/b/→") + feed(':%s/b/→') check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 3, 3 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 3, 3, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 3, 3 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 3, 3, 0, 1, 1 }, } - feed("<esc>") + feed('<esc>') -- replacing with expression register feed([[:%s/b/\=5+5]]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }, } - feed("<esc>") + feed('<esc>') -- replacing with backslash feed([[:%s/b/\\]]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 1, 1, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, } - feed("<esc>") + feed('<esc>') -- replacing with backslash from expression register feed([[:%s/b/\='\']]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 1, 1, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, } - feed("<esc>") + feed('<esc>') -- replacing with backslash followed by another character feed([[:%s/b/\\!]]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }, } - feed("<esc>") + feed('<esc>') -- replacing with backslash followed by another character from expression register feed([[:%s/b/\='\!']]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 1, 1, 0, 2, 2 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 2, 2, 0, 1, 1 }, } end) it('nvim_buf_set_text insert', function() - local check_events = setup_eventcheck(verify, {"bastext"}) - meths.buf_set_text(0, 0, 3, 0, 3, {"fiol","kontra"}) + local check_events = setup_eventcheck(verify, { 'bastext' }) + meths.buf_set_text(0, 0, 3, 0, 3, { 'fiol', 'kontra' }) check_events { - { "test1", "bytes", 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 }; + { 'test1', 'bytes', 1, 3, 0, 3, 3, 0, 0, 0, 1, 6, 11 }, } - meths.buf_set_text(0, 1, 6, 1, 6, {"punkt","syntgitarr","övnings"}) + meths.buf_set_text(0, 1, 6, 1, 6, { 'punkt', 'syntgitarr', 'övnings' }) check_events { - { "test1", "bytes", 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 }; + { 'test1', 'bytes', 1, 4, 1, 6, 14, 0, 0, 0, 2, 8, 25 }, } - eq({ "basfiol", "kontrapunkt", "syntgitarr", "övningstext" }, - meths.buf_get_lines(0, 0, -1, true)) + eq( + { 'basfiol', 'kontrapunkt', 'syntgitarr', 'övningstext' }, + meths.buf_get_lines(0, 0, -1, true) + ) end) it('nvim_buf_set_text replace', function() local check_events = setup_eventcheck(verify, origlines) - meths.buf_set_text(0, 2, 3, 2, 8, {"very text"}) + meths.buf_set_text(0, 2, 3, 2, 8, { 'very text' }) check_events { - { "test1", "bytes", 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 }; + { 'test1', 'bytes', 1, 3, 2, 3, 35, 0, 5, 5, 0, 9, 9 }, } - meths.buf_set_text(0, 3, 5, 3, 7, {" splitty","line "}) + meths.buf_set_text(0, 3, 5, 3, 7, { ' splitty', 'line ' }) check_events { - { "test1", "bytes", 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 }; + { 'test1', 'bytes', 1, 4, 3, 5, 57, 0, 2, 2, 1, 5, 14 }, } - meths.buf_set_text(0, 0, 8, 1, 2, {"JOINY"}) + meths.buf_set_text(0, 0, 8, 1, 2, { 'JOINY' }) check_events { - { "test1", "bytes", 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 }; + { 'test1', 'bytes', 1, 5, 0, 8, 8, 1, 2, 10, 0, 5, 5 }, } - meths.buf_set_text(0, 4, 0, 6, 0, {"was 5,6",""}) + meths.buf_set_text(0, 4, 0, 6, 0, { 'was 5,6', '' }) check_events { - { "test1", "bytes", 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 }; + { 'test1', 'bytes', 1, 6, 4, 0, 75, 2, 0, 32, 1, 0, 8 }, } - eq({ "originalJOINYiginal line 2", "orivery text line 3", "origi splitty", - "line l line 4", "was 5,6", " indented line" }, - meths.buf_get_lines(0, 0, -1, true)) - + eq({ + 'originalJOINYiginal line 2', + 'orivery text line 3', + 'origi splitty', + 'line l line 4', + 'was 5,6', + ' indented line', + }, meths.buf_get_lines(0, 0, -1, true)) end) it('nvim_buf_set_text delete', function() @@ -737,511 +752,516 @@ describe('lua: nvim_buf_attach on_bytes', function() -- really {""} but accepts {} as a shorthand meths.buf_set_text(0, 0, 0, 1, 0, {}) check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 16, 0, 0, 0 }, } -- TODO(bfredl): this works but is not as convenient as set_lines - meths.buf_set_text(0, 4, 15, 5, 17, {""}) + meths.buf_set_text(0, 4, 15, 5, 17, { '' }) check_events { - { "test1", "bytes", 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 4, 15, 79, 1, 17, 18, 0, 0, 0 }, } - eq({ "original line 2", "original line 3", "original line 4", - "original line 5", "original line 6" }, - meths.buf_get_lines(0, 0, -1, true)) + eq({ + 'original line 2', + 'original line 3', + 'original line 4', + 'original line 5', + 'original line 6', + }, meths.buf_get_lines(0, 0, -1, true)) end) it('checktime autoread', function() - write_file("Xtest-reload", dedent [[ + write_file( + 'Xtest-reload', + dedent [[ old line 1 - old line 2]]) + old line 2]] + ) local atime = os.time() - 10 - luv.fs_utime("Xtest-reload", atime, atime) - command "e Xtest-reload" - command "set autoread" + luv.fs_utime('Xtest-reload', atime, atime) + command 'e Xtest-reload' + command 'set autoread' local check_events = setup_eventcheck(verify, nil) - write_file("Xtest-reload", dedent [[ + write_file( + 'Xtest-reload', + dedent [[ new line 1 new line 2 - new line 3]]) + new line 3]] + ) - command "checktime" + command 'checktime' check_events { - { "test1", "reload", 1 }; + { 'test1', 'reload', 1 }, } feed 'ggJ' check_events { - { "test1", "bytes", 1, 5, 0, 10, 10, 1, 0, 1, 0, 1, 1 }; + { 'test1', 'bytes', 1, 5, 0, 10, 10, 1, 0, 1, 0, 1, 1 }, } - eq({'new line 1 new line 2', 'new line 3'}, meths.buf_get_lines(0, 0, -1, true)) + eq({ 'new line 1 new line 2', 'new line 3' }, meths.buf_get_lines(0, 0, -1, true)) -- check we can undo and redo a reload event. feed 'u' check_events { - { "test1", "bytes", 1, 8, 0, 10, 10, 0, 1, 1, 1, 0, 1 }; + { 'test1', 'bytes', 1, 8, 0, 10, 10, 0, 1, 1, 1, 0, 1 }, } feed 'u' check_events { - { "test1", "reload", 1 }; + { 'test1', 'reload', 1 }, } feed '<c-r>' check_events { - { "test1", "reload", 1 }; + { 'test1', 'reload', 1 }, } feed '<c-r>' check_events { - { "test1", "bytes", 1, 14, 0, 10, 10, 1, 0, 1, 0, 1, 1 }; + { 'test1', 'bytes', 1, 14, 0, 10, 10, 1, 0, 1, 0, 1, 1 }, } end) - it("tab with noexpandtab and softtabstop", function() - command("set noet") - command("set ts=4") - command("set sw=2") - command("set sts=4") + it('tab with noexpandtab and softtabstop', function() + command('set noet') + command('set ts=4') + command('set sw=2') + command('set sts=4') - local check_events = setup_eventcheck(verify, {'asdfasdf'}) + local check_events = setup_eventcheck(verify, { 'asdfasdf' }) - feed("gg0i<tab>") + feed('gg0i<tab>') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, - { "test1", "bytes", 1, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, } - feed("<tab>") + feed('<tab>') -- when spaces are merged into a tabstop check_events { - { "test1", "bytes", 1, 5, 0, 2, 2, 0, 0, 0, 0, 1, 1 }, - { "test1", "bytes", 1, 6, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, - { "test1", "bytes", 1, 7, 0, 0, 0, 0, 4, 4, 0, 1, 1 }, + { 'test1', 'bytes', 1, 5, 0, 2, 2, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 6, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 7, 0, 0, 0, 0, 4, 4, 0, 1, 1 }, } - - feed("<esc>u") + feed('<esc>u') check_events { - { "test1", "bytes", 1, 9, 0, 0, 0, 0, 1, 1, 0, 4, 4 }, - { "test1", "bytes", 1, 9, 0, 0, 0, 0, 4, 4, 0, 0, 0 } + { 'test1', 'bytes', 1, 9, 0, 0, 0, 0, 1, 1, 0, 4, 4 }, + { 'test1', 'bytes', 1, 9, 0, 0, 0, 0, 4, 4, 0, 0, 0 }, } -- in REPLACE mode - feed("R<tab><tab>") + feed('R<tab><tab>') check_events { - { "test1", "bytes", 1, 10, 0, 0, 0, 0, 1, 1, 0, 1, 1 }, - { "test1", "bytes", 1, 11, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, - { "test1", "bytes", 1, 12, 0, 2, 2, 0, 1, 1, 0, 1, 1 }, - { "test1", "bytes", 1, 13, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, - { "test1", "bytes", 1, 14, 0, 0, 0, 0, 4, 4, 0, 1, 1 }, + { 'test1', 'bytes', 1, 10, 0, 0, 0, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 11, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 12, 0, 2, 2, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 13, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 14, 0, 0, 0, 0, 4, 4, 0, 1, 1 }, } - feed("<esc>u") + feed('<esc>u') check_events { - { "test1", "bytes", 1, 16, 0, 0, 0, 0, 1, 1, 0, 4, 4 }, - { "test1", "bytes", 1, 16, 0, 2, 2, 0, 2, 2, 0, 1, 1 }, - { "test1", "bytes", 1, 16, 0, 0, 0, 0, 2, 2, 0, 1, 1 } + { 'test1', 'bytes', 1, 16, 0, 0, 0, 0, 1, 1, 0, 4, 4 }, + { 'test1', 'bytes', 1, 16, 0, 2, 2, 0, 2, 2, 0, 1, 1 }, + { 'test1', 'bytes', 1, 16, 0, 0, 0, 0, 2, 2, 0, 1, 1 }, } -- in VISUALREPLACE mode - feed("gR<tab><tab>") - check_events { - { "test1", "bytes", 1, 17, 0, 0, 0, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 18, 0, 1, 1, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 19, 0, 2, 2, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 20, 0, 3, 3, 0, 1, 1, 0, 1, 1 }; - { "test1", "bytes", 1, 21, 0, 3, 3, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 22, 0, 3, 3, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 24, 0, 2, 2, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 25, 0, 2, 2, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 27, 0, 1, 1, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 28, 0, 1, 1, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 30, 0, 0, 0, 0, 1, 1, 0, 0, 0 }; - { "test1", "bytes", 1, 31, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 33, 0, 0, 0, 0, 4, 4, 0, 1, 1 }; + feed('gR<tab><tab>') + check_events { + { 'test1', 'bytes', 1, 17, 0, 0, 0, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 18, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 19, 0, 2, 2, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 20, 0, 3, 3, 0, 1, 1, 0, 1, 1 }, + { 'test1', 'bytes', 1, 21, 0, 3, 3, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 22, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 24, 0, 2, 2, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 25, 0, 2, 2, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 27, 0, 1, 1, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 28, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 30, 0, 0, 0, 0, 1, 1, 0, 0, 0 }, + { 'test1', 'bytes', 1, 31, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 33, 0, 0, 0, 0, 4, 4, 0, 1, 1 }, } -- inserting tab after other tabs - command("set sw=4") - feed("<esc>0a<tab>") + command('set sw=4') + feed('<esc>0a<tab>') check_events { - { "test1", "bytes", 1, 34, 0, 1, 1, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 35, 0, 2, 2, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 36, 0, 3, 3, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 37, 0, 4, 4, 0, 0, 0, 0, 1, 1 }; - { "test1", "bytes", 1, 38, 0, 1, 1, 0, 4, 4, 0, 1, 1 }; + { 'test1', 'bytes', 1, 34, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 35, 0, 2, 2, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 36, 0, 3, 3, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 37, 0, 4, 4, 0, 0, 0, 0, 1, 1 }, + { 'test1', 'bytes', 1, 38, 0, 1, 1, 0, 4, 4, 0, 1, 1 }, } end) - it("retab", function() - command("set noet") - command("set ts=4") + it('retab', function() + command('set noet') + command('set ts=4') - local check_events = setup_eventcheck(verify, {" asdf"}) - command("retab 8") + local check_events = setup_eventcheck(verify, { ' asdf' }) + command('retab 8') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 7, 7, 0, 9, 9 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 7, 7, 0, 9, 9 }, } end) - it("sends events when undoing with undofile", function() - write_file("Xtest-undofile", dedent([[ + it('sends events when undoing with undofile', function() + write_file( + 'Xtest-undofile', + dedent([[ 12345 hello world - ]])) + ]]) + ) - command("e! Xtest-undofile") - command("set undodir=. | set undofile") + command('e! Xtest-undofile') + command('set undodir=. | set undofile') - local ns = helpers.request('nvim_create_namespace', "ns1") + local ns = helpers.request('nvim_create_namespace', 'ns1') meths.buf_set_extmark(0, ns, 0, 0, {}) - eq({"12345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) -- splice - feed("gg0d2l") + feed('gg0d2l') - eq({"345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + eq({ '345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) -- move - command(".m+1") + command('.m+1') - eq({"hello world", "345"}, meths.buf_get_lines(0, 0, -1, true)) + eq({ 'hello world', '345' }, meths.buf_get_lines(0, 0, -1, true)) -- reload undofile and undo changes - command("w") - command("set noundofile") - command("bw!") - command("e! Xtest-undofile") + command('w') + command('set noundofile') + command('bw!') + command('e! Xtest-undofile') - command("set undofile") + command('set undofile') local check_events = setup_eventcheck(verify, nil) - feed("u") - eq({"345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + feed('u') + eq({ '345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) check_events { - { "test1", "bytes", 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 }, - { "test1", "bytes", 2, 6, 0, 0, 0, 0, 0, 0, 1, 0, 4 } + { 'test1', 'bytes', 2, 6, 1, 0, 12, 1, 0, 4, 0, 0, 0 }, + { 'test1', 'bytes', 2, 6, 0, 0, 0, 0, 0, 0, 1, 0, 4 }, } - feed("u") - eq({"12345", "hello world"}, meths.buf_get_lines(0, 0, -1, true)) + feed('u') + eq({ '12345', 'hello world' }, meths.buf_get_lines(0, 0, -1, true)) check_events { - { "test1", "bytes", 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 } + { 'test1', 'bytes', 2, 8, 0, 0, 0, 0, 0, 0, 0, 2, 2 }, } - command("bw!") + command('bw!') end) - it("blockwise paste with uneven line lengths", function() - local check_events = setup_eventcheck(verify, {'aaaa', 'aaa', 'aaa'}) + it('blockwise paste with uneven line lengths', function() + local check_events = setup_eventcheck(verify, { 'aaaa', 'aaa', 'aaa' }) -- eq({}, meths.buf_get_lines(0, 0, -1, true)) - feed("gg0<c-v>jj$d") + feed('gg0<c-v>jj$d') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0 }, - { "test1", "bytes", 1, 3, 1, 0, 1, 0, 3, 3, 0, 0, 0 }, - { "test1", "bytes", 1, 3, 2, 0, 2, 0, 3, 3, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 1, 0, 1, 0, 3, 3, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 2, 0, 2, 0, 3, 3, 0, 0, 0 }, } - feed("p") + feed('p') check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 0, 0, 0, 0, 4, 4 }, - { "test1", "bytes", 1, 4, 1, 0, 5, 0, 0, 0, 0, 3, 3 }, - { "test1", "bytes", 1, 4, 2, 0, 9, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 0, 0, 0, 4, 4 }, + { 'test1', 'bytes', 1, 4, 1, 0, 5, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 4, 2, 0, 9, 0, 0, 0, 0, 3, 3 }, } - end) - it(":luado", function() - local check_events = setup_eventcheck(verify, {"abc", "12345"}) + it(':luado', function() + local check_events = setup_eventcheck(verify, { 'abc', '12345' }) command(".luado return 'a'") check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 3, 3, 0, 1, 1 }, } - command("luado return 10") + command('luado return 10') check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 0, 1, 1, 0, 2, 2 }; - { "test1", "bytes", 1, 5, 1, 0, 3, 0, 5, 5, 0, 2, 2 }; + { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 1, 1, 0, 2, 2 }, + { 'test1', 'bytes', 1, 5, 1, 0, 3, 0, 5, 5, 0, 2, 2 }, } - end) - it("flushes deleted bytes on move", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC", "DDD"}) + it('flushes deleted bytes on move', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC', 'DDD' }) - feed(":.move+1<cr>") + feed(':.move+1<cr>') check_events { - { "test1", "bytes", 1, 5, 0, 0, 0, 1, 0, 4, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 1, 0, 4, 0, 0, 0, 1, 0, 4 }; + { 'test1', 'bytes', 1, 5, 0, 0, 0, 1, 0, 4, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 1, 0, 4, 0, 0, 0, 1, 0, 4 }, } - feed("jd2j") + feed('jd2j') check_events { - { "test1", "bytes", 1, 6, 2, 0, 8, 2, 0, 8, 0, 0, 0 }; + { 'test1', 'bytes', 1, 6, 2, 0, 8, 2, 0, 8, 0, 0, 0 }, } end) - it("virtual edit", function () - local check_events = setup_eventcheck(verify, { "", " " }) + it('virtual edit', function() + local check_events = setup_eventcheck(verify, { '', ' ' }) - meths.set_option_value('virtualedit', "all", {}) + meths.set_option_value('virtualedit', 'all', {}) feed [[<Right><Right>iab<ESC>]] check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 2, 2 }; - { "test1", "bytes", 1, 4, 0, 2, 2, 0, 0, 0, 0, 2, 2 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 0, 0, 0, 2, 2 }, + { 'test1', 'bytes', 1, 4, 0, 2, 2, 0, 0, 0, 0, 2, 2 }, } feed [[j<Right><Right>iab<ESC>]] check_events { - { "test1", "bytes", 1, 5, 1, 0, 5, 0, 1, 1, 0, 8, 8 }; - { "test1", "bytes", 1, 6, 1, 5, 10, 0, 0, 0, 0, 2, 2 }; + { 'test1', 'bytes', 1, 5, 1, 0, 5, 0, 1, 1, 0, 8, 8 }, + { 'test1', 'bytes', 1, 6, 1, 5, 10, 0, 0, 0, 0, 2, 2 }, } end) - it("block visual paste", function() - local check_events = setup_eventcheck(verify, {"AAA", - "BBB", - "CCC", - "DDD", - "EEE", - "FFF"}) - funcs.setreg("a", "___") + it('block visual paste', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF' }) + funcs.setreg('a', '___') feed([[gg0l<c-v>3jl"ap]]) check_events { - { "test1", "bytes", 1, 3, 0, 1, 1, 0, 2, 2, 0, 0, 0 }; - { "test1", "bytes", 1, 3, 1, 1, 3, 0, 2, 2, 0, 0, 0 }; - { "test1", "bytes", 1, 3, 2, 1, 5, 0, 2, 2, 0, 0, 0 }; - { "test1", "bytes", 1, 3, 3, 1, 7, 0, 2, 2, 0, 0, 0 }; - { "test1", "bytes", 1, 5, 0, 1, 1, 0, 0, 0, 0, 3, 3 }; - { "test1", "bytes", 1, 6, 1, 1, 6, 0, 0, 0, 0, 3, 3 }; - { "test1", "bytes", 1, 7, 2, 1, 11, 0, 0, 0, 0, 3, 3 }; - { "test1", "bytes", 1, 8, 3, 1, 16, 0, 0, 0, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 1, 1, 0, 2, 2, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 1, 1, 3, 0, 2, 2, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 2, 1, 5, 0, 2, 2, 0, 0, 0 }, + { 'test1', 'bytes', 1, 3, 3, 1, 7, 0, 2, 2, 0, 0, 0 }, + { 'test1', 'bytes', 1, 5, 0, 1, 1, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 6, 1, 1, 6, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 7, 2, 1, 11, 0, 0, 0, 0, 3, 3 }, + { 'test1', 'bytes', 1, 8, 3, 1, 16, 0, 0, 0, 0, 3, 3 }, } end) - it("visual paste", function() - local check_events= setup_eventcheck(verify, { "aaa {", "b", "}" }) + it('visual paste', function() + local check_events = setup_eventcheck(verify, { 'aaa {', 'b', '}' }) -- Setting up - feed[[jdd]] + feed [[jdd]] check_events { - { "test1", "bytes", 1, 3, 1, 0, 6, 1, 0, 2, 0, 0, 0 }; + { 'test1', 'bytes', 1, 3, 1, 0, 6, 1, 0, 2, 0, 0, 0 }, } -- Actually testing - feed[[v%p]] + feed [[v%p]] check_events { - { "test1", "bytes", 1, 8, 0, 4, 4, 1, 1, 3, 0, 0, 0 }; - { "test1", "bytes", 1, 8, 0, 4, 4, 0, 0, 0, 2, 0, 3 }; + { 'test1', 'bytes', 1, 8, 0, 4, 4, 1, 1, 3, 0, 0, 0 }, + { 'test1', 'bytes', 1, 8, 0, 4, 4, 0, 0, 0, 2, 0, 3 }, } end) - it("nvim_buf_set_lines", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB"}) + it('nvim_buf_set_lines', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB' }) -- delete meths.buf_set_lines(0, 0, 1, true, {}) check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 4, 0, 0, 0 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 4, 0, 0, 0 }, } -- add - meths.buf_set_lines(0, 0, 0, true, {'asdf'}) + meths.buf_set_lines(0, 0, 0, true, { 'asdf' }) check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 5 }; + { 'test1', 'bytes', 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 5 }, } -- replace - meths.buf_set_lines(0, 0, 1, true, {'asdf', 'fdsa'}) + meths.buf_set_lines(0, 0, 1, true, { 'asdf', 'fdsa' }) check_events { - { "test1", "bytes", 1, 5, 0, 0, 0, 1, 0, 5, 2, 0, 10 }; + { 'test1', 'bytes', 1, 5, 0, 0, 0, 1, 0, 5, 2, 0, 10 }, } end) - it("flushes delbytes on substitute", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) + it('flushes delbytes on substitute', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC' }) - feed("gg0") - command("s/AAA/GGG/") + feed('gg0') + command('s/AAA/GGG/') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 3, 3 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 3, 3, 0, 3, 3 }, } -- check that byte updates for :delete (which uses curbuf->deleted_bytes2) -- are correct - command("delete") + command('delete') check_events { - { "test1", "bytes", 1, 4, 0, 0, 0, 1, 0, 4, 0, 0, 0 }; + { 'test1', 'bytes', 1, 4, 0, 0, 0, 1, 0, 4, 0, 0, 0 }, } end) - it("flushes delbytes on join", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) + it('flushes delbytes on join', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC' }) - feed("gg0J") + feed('gg0J') check_events { - { "test1", "bytes", 1, 3, 0, 3, 3, 1, 0, 1, 0, 1, 1 }; + { 'test1', 'bytes', 1, 3, 0, 3, 3, 1, 0, 1, 0, 1, 1 }, } - command("delete") + command('delete') check_events { - { "test1", "bytes", 1, 5, 0, 0, 0, 1, 0, 8, 0, 0, 0 }; + { 'test1', 'bytes', 1, 5, 0, 0, 0, 1, 0, 8, 0, 0, 0 }, } end) - it("sends updates on U", function() - feed("ggiAAA<cr>BBB") - feed("<esc>gg$a CCC") + it('sends updates on U', function() + feed('ggiAAA<cr>BBB') + feed('<esc>gg$a CCC') local check_events = setup_eventcheck(verify, nil) - feed("ggU") + feed('ggU') check_events { - { "test1", "bytes", 1, 6, 0, 7, 7, 0, 0, 0, 0, 3, 3 }; + { 'test1', 'bytes', 1, 6, 0, 7, 7, 0, 0, 0, 0, 3, 3 }, } end) - it("delete in completely empty buffer", function() + it('delete in completely empty buffer', function() local check_events = setup_eventcheck(verify, nil) - command "delete" - check_events { } + command 'delete' + check_events {} end) - it("delete the only line of a buffer", function() - local check_events = setup_eventcheck(verify, {"AAA"}) + it('delete the only line of a buffer', function() + local check_events = setup_eventcheck(verify, { 'AAA' }) - command "delete" + command 'delete' check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 1, 0, 4, 1, 0, 1 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 1, 0, 4, 1, 0, 1 }, } end) - it("delete the last line of a buffer with two lines", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB"}) + it('delete the last line of a buffer with two lines', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB' }) - command "2delete" + command '2delete' check_events { - { "test1", "bytes", 1, 3, 1, 0, 4, 1, 0, 4, 0, 0, 0 }; + { 'test1', 'bytes', 1, 3, 1, 0, 4, 1, 0, 4, 0, 0, 0 }, } end) - it(":sort lines", function() - local check_events = setup_eventcheck(verify, {"CCC", "BBB", "AAA"}) + it(':sort lines', function() + local check_events = setup_eventcheck(verify, { 'CCC', 'BBB', 'AAA' }) - command "%sort" + command '%sort' check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 3, 0, 12 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 3, 0, 12, 3, 0, 12 }, } end) - it("handles already sorted lines", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) + it('handles already sorted lines', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC' }) - command "%sort" - check_events { } + command '%sort' + check_events {} end) - it("works with accepting spell suggestions", function() - local check_events = setup_eventcheck(verify, {"hallo world", "hallo world"}) + it('works with accepting spell suggestions', function() + local check_events = setup_eventcheck(verify, { 'hallo world', 'hallo world' }) - feed("gg0z=4<cr><cr>") -- accepts 'Hello' + feed('gg0z=4<cr><cr>') -- accepts 'Hello' check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 0, 2, 2, 0, 2, 2 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 0, 2, 2, 0, 2, 2 }, } - command("spellrepall") -- replaces whole words + command('spellrepall') -- replaces whole words check_events { - { "test1", "bytes", 1, 4, 1, 0, 12, 0, 5, 5, 0, 5, 5 }; + { 'test1', 'bytes', 1, 4, 1, 0, 12, 0, 5, 5, 0, 5, 5 }, } end) it('works with :diffput and :diffget', function() - local check_events = setup_eventcheck(verify, {"AAA"}) + local check_events = setup_eventcheck(verify, { 'AAA' }) command('diffthis') command('new') command('diffthis') - meths.buf_set_lines(0, 0, -1, true, {"AAA", "BBB"}) + meths.buf_set_lines(0, 0, -1, true, { 'AAA', 'BBB' }) feed('G') command('diffput') check_events { - { "test1", "bytes", 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 4 }; + { 'test1', 'bytes', 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 4 }, } - meths.buf_set_lines(0, 0, -1, true, {"AAA", "CCC"}) + meths.buf_set_lines(0, 0, -1, true, { 'AAA', 'CCC' }) feed('<C-w>pG') command('diffget') check_events { - { "test1", "bytes", 1, 4, 1, 0, 4, 1, 0, 4, 1, 0, 4 }; + { 'test1', 'bytes', 1, 4, 1, 0, 4, 1, 0, 4, 1, 0, 4 }, } end) local function test_lockmarks(mode) - local description = (mode ~= "") and mode or "(baseline)" - it("test_lockmarks " .. description .. " %delete _", function() - local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) + local description = (mode ~= '') and mode or '(baseline)' + it('test_lockmarks ' .. description .. ' %delete _', function() + local check_events = setup_eventcheck(verify, { 'AAA', 'BBB', 'CCC' }) - command(mode .. " %delete _") + command(mode .. ' %delete _') check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 1, 0, 1 }; + { 'test1', 'bytes', 1, 3, 0, 0, 0, 3, 0, 12, 1, 0, 1 }, } end) - it("test_lockmarks " .. description .. " append()", function() + it('test_lockmarks ' .. description .. ' append()', function() local check_events = setup_eventcheck(verify) command(mode .. " call append(0, 'CCC')") check_events { - { "test1", "bytes", 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 4 }; + { 'test1', 'bytes', 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 4 }, } command(mode .. " call append(1, 'BBBB')") check_events { - { "test1", "bytes", 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 5 }; + { 'test1', 'bytes', 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 5 }, } command(mode .. " call append(2, '')") check_events { - { "test1", "bytes", 1, 4, 2, 0, 9, 0, 0, 0, 1, 0, 1 }; + { 'test1', 'bytes', 1, 4, 2, 0, 9, 0, 0, 0, 1, 0, 1 }, } - command(mode .. " $delete _") + command(mode .. ' $delete _') check_events { - { "test1", "bytes", 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 }; + { 'test1', 'bytes', 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 }, } - eq("CCC|BBBB|", table.concat(meths.buf_get_lines(0, 0, -1, true), "|")) + eq('CCC|BBBB|', table.concat(meths.buf_get_lines(0, 0, -1, true), '|')) end) end -- check that behavior is identical with and without "lockmarks" - test_lockmarks "" - test_lockmarks "lockmarks" + test_lockmarks '' + test_lockmarks 'lockmarks' teardown(function() - os.remove "Xtest-reload" - os.remove "Xtest-undofile" - os.remove ".Xtest-undofile.un~" + os.remove 'Xtest-reload' + os.remove 'Xtest-undofile' + os.remove '.Xtest-undofile.un~' end) end @@ -1253,4 +1273,3 @@ describe('lua: nvim_buf_attach on_bytes', function() do_both(false) end) end) - diff --git a/test/functional/lua/command_line_completion_spec.lua b/test/functional/lua/command_line_completion_spec.lua index 177e077f4a..b88a38082f 100644 --- a/test/functional/lua/command_line_completion_spec.lua +++ b/test/functional/lua/command_line_completion_spec.lua @@ -5,34 +5,33 @@ local eq = helpers.eq local exec_lua = helpers.exec_lua local get_completions = function(input, env) - return exec_lua("return {vim._expand_pat(...)}", input, env) + return exec_lua('return {vim._expand_pat(...)}', input, env) end local get_compl_parts = function(parts) - return exec_lua("return {vim._expand_pat_get_parts(...)}", parts) + return exec_lua('return {vim._expand_pat_get_parts(...)}', parts) end before_each(clear) describe('nlua_expand_pat', function() it('should complete exact matches', function() - eq({{'exact'}, 0}, get_completions('exact', { exact = true })) + eq({ { 'exact' }, 0 }, get_completions('exact', { exact = true })) end) it('should return empty table when nothing matches', function() - eq({{}, 0}, get_completions('foo', { bar = true })) + eq({ {}, 0 }, get_completions('foo', { bar = true })) end) it('should return nice completions with function call prefix', function() - eq({{'FOO'}, 6}, get_completions('print(F', { FOO = true, bawr = true })) + eq({ { 'FOO' }, 6 }, get_completions('print(F', { FOO = true, bawr = true })) end) it('should return keys for nested dictionaries', function() eq( - {{ + { { 'nvim_buf_set_lines', - }, 8 - }, + }, 8 }, get_completions('vim.api.nvim_buf_', { vim = { api = { @@ -40,34 +39,32 @@ describe('nlua_expand_pat', function() nvim_win_doesnt_match = true, }, other_key = true, - } + }, }) ) end) it('it should work with colons', function() eq( - {{ + { { 'bawr', 'baz', - }, 8 - }, + }, 8 }, get_completions('MyClass:b', { MyClass = { baz = true, bawr = true, foo = false, - } + }, }) ) end) it('should return keys for string reffed dictionaries', function() eq( - {{ + { { 'nvim_buf_set_lines', - }, 11 - }, + }, 11 }, get_completions('vim["api"].nvim_buf_', { vim = { api = { @@ -75,17 +72,16 @@ describe('nlua_expand_pat', function() nvim_win_doesnt_match = true, }, other_key = true, - } + }, }) ) end) it('should return keys for string reffed dictionaries', function() eq( - {{ + { { 'nvim_buf_set_lines', - }, 21 - }, + }, 21 }, get_completions('vim["nested"]["api"].nvim_buf_', { vim = { nested = { @@ -95,80 +91,76 @@ describe('nlua_expand_pat', function() }, }, other_key = true, - } + }, }) ) end) it('should work with lazy submodules of "vim" global', function() - eq({{ 'inspect', 'inspect_pos' }, 4 }, - get_completions('vim.inspec')) + eq({ { 'inspect', 'inspect_pos' }, 4 }, get_completions('vim.inspec')) - eq({{ 'treesitter' }, 4 }, - get_completions('vim.treesi')) + eq({ { 'treesitter' }, 4 }, get_completions('vim.treesi')) - eq({{ 'set' }, 11 }, - get_completions('vim.keymap.se')) + eq({ { 'set' }, 11 }, get_completions('vim.keymap.se')) end) it('should be able to interpolate globals', function() eq( - {{ + { { 'nvim_buf_set_lines', - }, 12 - }, + }, 12 }, get_completions('vim[MY_VAR].nvim_buf_', { - MY_VAR = "api", + MY_VAR = 'api', vim = { api = { nvim_buf_set_lines = true, nvim_win_doesnt_match = true, }, other_key = true, - } + }, }) ) end) it('should return everything if the input is of length 0', function() - eq({{"other", "vim"}, 0}, get_completions('', { vim = true, other = true })) + eq({ { 'other', 'vim' }, 0 }, get_completions('', { vim = true, other = true })) end) describe('get_parts', function() it('should return an empty list for no separators', function() - eq({{}, 1}, get_compl_parts("vim")) + eq({ {}, 1 }, get_compl_parts('vim')) end) it('just the first item before a period', function() - eq({{"vim"}, 5}, get_compl_parts("vim.ap")) + eq({ { 'vim' }, 5 }, get_compl_parts('vim.ap')) end) it('should return multiple parts just for period', function() - eq({{"vim", "api"}, 9}, get_compl_parts("vim.api.nvim_buf")) + eq({ { 'vim', 'api' }, 9 }, get_compl_parts('vim.api.nvim_buf')) end) it('should be OK with colons', function() - eq({{"vim", "api"}, 9}, get_compl_parts("vim:api.nvim_buf")) + eq({ { 'vim', 'api' }, 9 }, get_compl_parts('vim:api.nvim_buf')) end) it('should work for just one string ref', function() - eq({{"vim", "api"}, 12}, get_compl_parts("vim['api'].nvim_buf")) + eq({ { 'vim', 'api' }, 12 }, get_compl_parts("vim['api'].nvim_buf")) end) it('should work for just one string ref, with double quote', function() - eq({{"vim", "api"}, 12}, get_compl_parts('vim["api"].nvim_buf')) + eq({ { 'vim', 'api' }, 12 }, get_compl_parts('vim["api"].nvim_buf')) end) it('should allows back-to-back string ref', function() - eq({{"vim", "nested", "api"}, 22}, get_compl_parts('vim["nested"]["api"].nvim_buf')) + eq({ { 'vim', 'nested', 'api' }, 22 }, get_compl_parts('vim["nested"]["api"].nvim_buf')) end) it('should allows back-to-back string ref with spaces before and after', function() - eq({{"vim", "nested", "api"}, 25}, get_compl_parts('vim[ "nested" ]["api"].nvim_buf')) + eq({ { 'vim', 'nested', 'api' }, 25 }, get_compl_parts('vim[ "nested" ]["api"].nvim_buf')) end) it('should allow VAR style loolup', function() - eq({{"vim", {"NESTED"}, "api"}, 20}, get_compl_parts('vim[NESTED]["api"].nvim_buf')) + eq({ { 'vim', { 'NESTED' }, 'api' }, 20 }, get_compl_parts('vim[NESTED]["api"].nvim_buf')) end) end) end) diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index d8a68219c1..b7bf2b2eae 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -25,43 +25,53 @@ before_each(clear) describe(':lua command', function() it('works', function() - eq('', exec_capture( - 'lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) - eq({'', 'TEST'}, curbufmeths.get_lines(0, 100, false)) + eq('', exec_capture('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TEST"})')) + eq({ '', 'TEST' }, curbufmeths.get_lines(0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"TSET"}) EOF]]) - eq({'', 'TSET'}, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'TSET' }, curbufmeths.get_lines(0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"SETT"})]]) - eq({'', 'SETT'}, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'SETT' }, curbufmeths.get_lines(0, 100, false)) source([[ lua << EOF vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) EOF]]) - eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) - matches('.*Vim%(lua%):E15: Invalid expression: .*', pcall_err(source, [[ + eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) + matches( + '.*Vim%(lua%):E15: Invalid expression: .*', + pcall_err( + source, + [[ lua << eval EOF {} EOF - ]])) + ]] + ) + ) end) it('throws catchable errors', function() - eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']], - pcall_err(command, 'lua ()')) - eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]], - remove_trace(exc_exec('lua error("TEST")'))) - eq([[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]], - remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})'))) - eq({''}, curbufmeths.get_lines(0, 100, false)) + eq( + [[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']], + pcall_err(command, 'lua ()') + ) + eq( + [[Vim(lua):E5108: Error executing lua [string ":lua"]:1: TEST]], + remove_trace(exc_exec('lua error("TEST")')) + ) + eq( + [[Vim(lua):E5108: Error executing lua [string ":lua"]:1: Invalid buffer id: -10]], + remove_trace(exc_exec('lua vim.api.nvim_buf_set_lines(-10, 1, 1, false, {"TEST"})')) + ) + eq({ '' }, curbufmeths.get_lines(0, 100, false)) end) it('works with NULL errors', function() - eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], - exc_exec('lua error(nil)')) + eq([=[Vim(lua):E5108: Error executing lua [NULL]]=], exc_exec('lua error(nil)')) end) it('accepts embedded NLs without heredoc', function() -- Such code is usually used for `:execute 'lua' {generated_string}`: @@ -72,7 +82,7 @@ describe(':lua command', function() vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) ]]) - eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) end) it('preserves global and not preserves local variables', function() eq('', exec_capture('lua gvar = 42')) @@ -83,26 +93,29 @@ describe(':lua command', function() it('works with long strings', function() local s = ('x'):rep(100500) - eq('Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'', - pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s))) - eq({''}, curbufmeths.get_lines(0, -1, false)) + eq( + 'Vim(lua):E5107: Error loading lua [string ":lua"]:0: unfinished string near \'<eof>\'', + pcall_err(command, ('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)) + ) + eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq('', exec_capture(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s))) - eq({'', s}, curbufmeths.get_lines(0, -1, false)) + eq({ '', s }, curbufmeths.get_lines(0, -1, false)) end) it('can show multiline error messages', function() - local screen = Screen.new(40,10) + local screen = Screen.new(40, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) feed(':lua error("fail\\nmuch error\\nsuch details")<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {2: }| {3:E5108: Error executing lua [string ":lua}| {3:"]:1: fail} | @@ -113,22 +126,30 @@ describe(':lua command', function() {3: [string ":lua"]:1: in main chunk}| | {4:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*8 | - ]]} - eq('E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details', remove_trace(eval('v:errmsg'))) + ]], + } + eq( + 'E5108: Error executing lua [string ":lua"]:1: fail\nmuch error\nsuch details', + remove_trace(eval('v:errmsg')) + ) - local status, err = pcall(command,'lua error("some error\\nin a\\nAPI command")') - local expected = 'Vim(lua):E5108: Error executing lua [string ":lua"]:1: some error\nin a\nAPI command' + local status, err = pcall(command, 'lua error("some error\\nin a\\nAPI command")') + local expected = + 'Vim(lua):E5108: Error executing lua [string ":lua"]:1: some error\nin a\nAPI command' eq(false, status) eq(expected, string.sub(remove_trace(err), -string.len(expected))) feed(':messages<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {2: }| {3:E5108: Error executing lua [string ":lua}| {3:"]:1: fail} | @@ -139,17 +160,18 @@ describe(':lua command', function() {3: [string ":lua"]:1: in main chunk}| | {4:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) it('prints result of =expr', function() - exec_lua("x = 5") - eq("5", exec_capture(':lua =x')) - eq("5", exec_capture('=x')) + exec_lua('x = 5') + eq('5', exec_capture(':lua =x')) + eq('5', exec_capture('=x')) exec_lua("function x() return 'hello' end") eq('hello', exec_capture(':lua = x()')) - exec_lua("x = {a = 1, b = 2}") - eq("{\n a = 1,\n b = 2\n}", exec_capture(':lua =x')) + exec_lua('x = {a = 1, b = 2}') + eq('{\n a = 1,\n b = 2\n}', exec_capture(':lua =x')) exec_lua([[function x(success) if success then return true, "Return value" @@ -157,69 +179,82 @@ describe(':lua command', function() return false, nil, "Error message" end end]]) - eq(dedent[[ + eq( + dedent [[ true Return value]], - exec_capture(':lua =x(true)')) - eq(dedent[[ + exec_capture(':lua =x(true)') + ) + eq( + dedent [[ false nil Error message]], - exec_capture('=x(false)')) + exec_capture('=x(false)') + ) end) end) describe(':luado command', function() it('works', function() - curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('luado lines = (lines or {}) lines[#lines + 1] = {linenr, line}')) - eq({'ABC', 'def', 'gHi'}, curbufmeths.get_lines(0, -1, false)) - eq({{1, 'ABC'}, {2, 'def'}, {3, 'gHi'}}, funcs.luaeval('lines')) + eq({ 'ABC', 'def', 'gHi' }, curbufmeths.get_lines(0, -1, false)) + eq({ { 1, 'ABC' }, { 2, 'def' }, { 3, 'gHi' } }, funcs.luaeval('lines')) -- Automatic transformation of numbers eq('', exec_capture('luado return linenr')) - eq({'1', '2', '3'}, curbufmeths.get_lines(0, -1, false)) + eq({ '1', '2', '3' }, curbufmeths.get_lines(0, -1, false)) eq('', exec_capture('luado return ("<%02x>"):format(line:byte())')) - eq({'<31>', '<32>', '<33>'}, curbufmeths.get_lines(0, -1, false)) + eq({ '<31>', '<32>', '<33>' }, curbufmeths.get_lines(0, -1, false)) end) it('stops processing lines when suddenly out of lines', function() - curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) + curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) eq('', exec_capture('2,$luado runs = ((runs or 0) + 1) vim.api.nvim_command("%d")')) - eq({''}, curbufmeths.get_lines(0, -1, false)) + eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq(1, funcs.luaeval('runs')) end) it('works correctly when changing lines out of range', function() - curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) - eq('Vim(luado):E322: Line number out of range: 1 past the end', - pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr')) - eq({''}, curbufmeths.get_lines(0, -1, false)) + curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + eq( + 'Vim(luado):E322: Line number out of range: 1 past the end', + pcall_err(command, '2,$luado vim.api.nvim_command("%d") return linenr') + ) + eq({ '' }, curbufmeths.get_lines(0, -1, false)) end) it('fails on errors', function() - eq([[Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unexpected symbol near ')']], - pcall_err(command, 'luado ()')) - eq([[Vim(luado):E5111: Error calling lua: [string ":luado"]:0: attempt to perform arithmetic on global 'liness' (a nil value)]], - pcall_err(command, 'luado return liness + 1')) + eq( + [[Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unexpected symbol near ')']], + pcall_err(command, 'luado ()') + ) + eq( + [[Vim(luado):E5111: Error calling lua: [string ":luado"]:0: attempt to perform arithmetic on global 'liness' (a nil value)]], + pcall_err(command, 'luado return liness + 1') + ) end) it('works with NULL errors', function() - eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], - exc_exec('luado error(nil)')) + eq([=[Vim(luado):E5111: Error calling lua: [NULL]]=], exc_exec('luado error(nil)')) end) it('fails in sandbox when needed', function() - curbufmeths.set_lines(0, 1, false, {"ABC", "def", "gHi"}) - eq('Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', - pcall_err(command, 'sandbox luado runs = (runs or 0) + 1')) + curbufmeths.set_lines(0, 1, false, { 'ABC', 'def', 'gHi' }) + eq( + 'Vim(luado):E48: Not allowed in sandbox: sandbox luado runs = (runs or 0) + 1', + pcall_err(command, 'sandbox luado runs = (runs or 0) + 1') + ) eq(NIL, funcs.luaeval('runs')) end) it('works with long strings', function() local s = ('x'):rep(100500) - eq('Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'', - pcall_err(command, ('luado return "%s'):format(s))) - eq({''}, curbufmeths.get_lines(0, -1, false)) + eq( + 'Vim(luado):E5109: Error loading lua: [string ":luado"]:0: unfinished string near \'<eof>\'', + pcall_err(command, ('luado return "%s'):format(s)) + ) + eq({ '' }, curbufmeths.get_lines(0, -1, false)) eq('', exec_capture(('luado return "%s"'):format(s))) - eq({s}, curbufmeths.get_lines(0, -1, false)) + eq({ s }, curbufmeths.get_lines(0, -1, false)) end) end) @@ -231,26 +266,39 @@ describe(':luafile', function() end) it('works', function() - write_file(fname, [[ + write_file( + fname, + [[ vim.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"}) vim.api.nvim_buf_set_lines(1, 2, 3, false, {"TTSE"}) vim.api.nvim_buf_set_lines(1, 3, 4, false, {"STTE"}) - ]]) + ]] + ) eq('', exec_capture('luafile ' .. fname)) - eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) + eq({ '', 'ETTS', 'TTSE', 'STTE' }, curbufmeths.get_lines(0, 100, false)) end) it('correctly errors out', function() write_file(fname, '()') - eq(("Vim(luafile):E5112: Error while creating lua chunk: %s:1: unexpected symbol near ')'"):format(fname), - exc_exec('luafile ' .. fname)) + eq( + ("Vim(luafile):E5112: Error while creating lua chunk: %s:1: unexpected symbol near ')'"):format( + fname + ), + exc_exec('luafile ' .. fname) + ) write_file(fname, 'vimm.api.nvim_buf_set_lines(1, 1, 2, false, {"ETTS"})') - eq(("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format(fname), - remove_trace(exc_exec('luafile ' .. fname))) + eq( + ("Vim(luafile):E5113: Error while calling lua chunk: %s:1: attempt to index global 'vimm' (a nil value)"):format( + fname + ), + remove_trace(exc_exec('luafile ' .. fname)) + ) end) it('works with NULL errors', function() write_file(fname, 'error(nil)') - eq([=[Vim(luafile):E5113: Error while calling lua chunk: [NULL]]=], - exc_exec('luafile ' .. fname)) + eq( + [=[Vim(luafile):E5113: Error while calling lua chunk: [NULL]]=], + exc_exec('luafile ' .. fname) + ) end) end) diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index d59ee02f01..22ef66bc60 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -128,12 +128,20 @@ describe('vim.diagnostic', function() return vim.diagnostic.get() ]] eq(3, #result) - eq(2, exec_lua([[return #vim.tbl_filter(function(d) return d.bufnr == diagnostic_bufnr end, ...)]], result)) + eq( + 2, + exec_lua( + [[return #vim.tbl_filter(function(d) return d.bufnr == diagnostic_bufnr end, ...)]], + result + ) + ) eq('Diagnostic #1', result[1].message) end) it('removes diagnostics from the cache when a buffer is removed', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.api.nvim_win_set_buf(0, diagnostic_bufnr) local other_bufnr = vim.fn.bufadd('test | test') local lines = vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, -1, true) @@ -151,16 +159,23 @@ describe('vim.diagnostic', function() vim.opt_local.buflisted = true vim.cmd('bwipeout!') return #vim.diagnostic.get() - ]]) - eq(2, exec_lua [[ + ]] + ) + eq( + 2, + exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) vim.opt_local.buflisted = false return #vim.diagnostic.get() - ]]) - eq(0, exec_lua [[ + ]] + ) + eq( + 0, + exec_lua [[ vim.cmd('bwipeout!') return #vim.diagnostic.get() - ]]) + ]] + ) end) it('removes diagnostic from stale cache on reset', function() @@ -194,37 +209,48 @@ describe('vim.diagnostic', function() end) it('resolves buffer number 0 to the current buffer', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 2, 1, 2, 1), }) return #vim.diagnostic.get(0) - ]]) + ]] + ) end) it('saves and count a single error', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns) - ]]) + ]] + ) end) it('saves and count multiple errors', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 2, 1, 2, 1), }) return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns) - ]]) + ]] + ) end) it('saves and count from multiple namespaces', function() - eq({1, 1, 2}, exec_lua [[ + eq( + { 1, 1, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1', 1, 1, 1, 1), }) @@ -239,11 +265,14 @@ describe('vim.diagnostic', function() -- All namespaces count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR), } - ]]) + ]] + ) end) it('saves and count from multiple namespaces with respect to severity', function() - eq({3, 0, 3}, exec_lua [[ + eq( + { 3, 0, 3 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), make_error('Diagnostic From Server 1:2', 2, 2, 2, 2), @@ -260,7 +289,8 @@ describe('vim.diagnostic', function() -- All namespaces count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR), } - ]]) + ]] + ) end) it('handles one namespace clearing highlights while the other still has highlights', function() @@ -269,8 +299,10 @@ describe('vim.diagnostic', function() -- 1 Warning (2) + 1 Warning (1) -- 2 highlights and 2 underlines (since error) -- 1 highlight + 1 underline - local all_highlights = {1, 1, 2, 4, 2} - eq(all_highlights, exec_lua [[ + local all_highlights = { 1, 1, 2, 4, 2 } + eq( + all_highlights, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -289,10 +321,13 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Clear diagnostics from namespace 1, and make sure we have the right amount of stuff for namespace 2 - eq({1, 1, 2, 0, 2}, exec_lua [[ + eq( + { 1, 1, 2, 0, 2 }, + exec_lua [[ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns) return { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -301,10 +336,13 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Show diagnostics from namespace 1 again - eq(all_highlights, exec_lua([[ + eq( + all_highlights, + exec_lua([[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) return { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -313,11 +351,14 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]])) + ]]) + ) end) it('does not display diagnostics when disabled', function() - eq({0, 2}, exec_lua [[ + eq( + { 0, 2 }, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -335,9 +376,12 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) vim.diagnostic.disable(diagnostic_bufnr, other_ns) @@ -345,7 +389,8 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) end) describe('show() and hide()', function() @@ -660,8 +705,10 @@ describe('vim.diagnostic', function() -- 1 Warning (2) + 1 Warning (1) -- 2 highlights and 2 underlines (since error) -- 1 highlight + 1 underline - local all_highlights = {1, 1, 2, 4, 2} - eq(all_highlights, exec_lua [[ + local all_highlights = { 1, 1, 2, 4, 2 } + eq( + all_highlights, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -680,13 +727,16 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Reset diagnostics from namespace 1 exec_lua([[ vim.diagnostic.reset(diagnostic_ns) ]]) -- Make sure we have the right diagnostic count - eq({0, 1, 1, 0, 2} , exec_lua [[ + eq( + { 0, 1, 1, 0, 2 }, + exec_lua [[ local diagnostic_count = {} vim.wait(100, function () diagnostic_count = { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -696,13 +746,16 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, other_ns), } end ) return diagnostic_count - ]]) + ]] + ) -- Reset diagnostics from namespace 2 exec_lua([[ vim.diagnostic.reset(other_ns) ]]) -- Make sure we have the right diagnostic count - eq({0, 0, 0, 0, 0}, exec_lua [[ + eq( + { 0, 0, 0, 0, 0 }, + exec_lua [[ local diagnostic_count = {} vim.wait(100, function () diagnostic_count = { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -712,8 +765,8 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, other_ns), } end ) return diagnostic_count - ]]) - + ]] + ) end) it("doesn't error after bwipeout called on buffer", function() @@ -728,17 +781,22 @@ describe('vim.diagnostic', function() describe('get_next_pos()', function() it('can find the next pos with only one namespace', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) return vim.diagnostic.get_next_pos() - ]]) + ]] + ) end) it('can find next pos with two errors', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 4, 4, 4, 4), @@ -746,44 +804,56 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('can cycle when position is past error', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('will not cycle when wrap is off', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns, wrap = false } - ]]) + ]] + ) end) it('can cycle even from the last line', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {vim.api.nvim_buf_line_count(0), 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('works with diagnostics past the end of the line #16349', function() - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 3, 9001, 3, 9001), make_error('Diagnostic #2', 4, 0, 4, 0), @@ -792,11 +862,14 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_cursor(0, {1, 1}) vim.diagnostic.goto_next { float = false } return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('works with diagnostics before the start of the line', function() - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 3, 9001, 3, 9001), make_error('Diagnostic #2', 4, -1, 4, -1), @@ -805,24 +878,30 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_cursor(0, {1, 1}) vim.diagnostic.goto_next { float = false } return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) -end) + ]] + ) + end) end) describe('get_prev_pos()', function() it('can find the prev pos with only one namespace', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos() - ]]) + ]] + ) end) it('can find prev pos with two errors', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 4, 4, 4, 4), @@ -830,29 +909,36 @@ end) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('can cycle when position is past error', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('respects wrap parameter', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns, wrap = false} - ]]) + ]] + ) end) end) @@ -862,18 +948,23 @@ end) end) it('returns all diagnostics when no severity is supplied', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), }) return #vim.diagnostic.get(diagnostic_bufnr) - ]]) + ]] + ) end) it('returns only requested diagnostics when severity range is supplied', function() - eq({2, 3, 2}, exec_lua [[ + eq( + { 2, 3, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -891,11 +982,14 @@ end) } }), } - ]]) + ]] + ) end) it('returns only requested diagnostics when severities are supplied', function() - eq({1, 1, 2}, exec_lua [[ + eq( + { 1, 1, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -913,11 +1007,14 @@ end) } }), } - ]]) + ]] + ) end) it('allows filtering by line', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -926,7 +1023,8 @@ end) }) return #vim.diagnostic.get(diagnostic_bufnr, {lnum = 2}) - ]]) + ]] + ) end) end) @@ -1048,7 +1146,9 @@ end) describe('config()', function() it('works with global, namespace, and ephemeral options', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1063,9 +1163,12 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1080,9 +1183,12 @@ end) }, {virtual_text = true}) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1097,9 +1203,12 @@ end) }, {virtual_text = true}) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1116,7 +1225,8 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('can use functions for config values', function() @@ -1129,7 +1239,10 @@ end) }) ]] - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) -- Now, don't enable virtual text. @@ -1140,13 +1253,17 @@ end) }, diagnostic_ns) ]] - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('allows filtering by severity', function() local get_extmark_count_with_severity = function(min_severity) - return exec_lua([[ + return exec_lua( + [[ vim.diagnostic.config({ underline = false, virtual_text = { @@ -1159,15 +1276,17 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]], min_severity) + ]], + min_severity + ) end -- No messages with Error or higher - eq(0, get_extmark_count_with_severity("ERROR")) + eq(0, get_extmark_count_with_severity('ERROR')) -- But now we don't filter it - eq(1, get_extmark_count_with_severity("WARN")) - eq(1, get_extmark_count_with_severity("HINT")) + eq(1, get_extmark_count_with_severity('WARN')) + eq(1, get_extmark_count_with_severity('HINT')) end) it('allows sorting by severity', function() @@ -1219,16 +1338,16 @@ end) -- Virt texts are defined lowest priority to highest, signs from -- highest to lowest - eq({'Warn', 'Error', 'Info'}, result[1]) - eq({'Info', 'Error', 'Warn'}, result[2]) + eq({ 'Warn', 'Error', 'Info' }, result[1]) + eq({ 'Info', 'Error', 'Warn' }, result[2]) result = exec_lua [[return get_virt_text_and_signs(true)]] - eq({'Info', 'Warn', 'Error'}, result[1]) - eq({'Error', 'Warn', 'Info'}, result[2]) + eq({ 'Info', 'Warn', 'Error' }, result[1]) + eq({ 'Error', 'Warn', 'Info' }, result[2]) result = exec_lua [[return get_virt_text_and_signs({ reverse = true })]] - eq({'Error', 'Warn', 'Info'}, result[1]) - eq({'Info', 'Warn', 'Error'}, result[2]) + eq({ 'Error', 'Warn', 'Info' }, result[1]) + eq({ 'Info', 'Warn', 'Error' }, result[2]) end) it('can show diagnostic sources in virtual text', function() @@ -1311,8 +1430,8 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) return {extmarks[1][4].virt_text, extmarks[2][4].virt_text} ]] - eq(" 👀 Warning", result[1][3][1]) - eq(" 🔥 Error", result[2][3][1]) + eq(' 👀 Warning', result[1][3][1]) + eq(' 🔥 Error', result[2][3][1]) end) it('includes source for formatted diagnostics', function() @@ -1339,12 +1458,14 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) return {extmarks[1][4].virt_text, extmarks[2][4].virt_text} ]] - eq(" some_linter: 👀 Warning", result[1][3][1]) - eq(" another_linter: 🔥 Error", result[2][3][1]) + eq(' some_linter: 👀 Warning', result[1][3][1]) + eq(' another_linter: 🔥 Error', result[2][3][1]) end) it('can add a prefix to virtual text', function() - eq('E Some error', exec_lua [[ + eq( + 'E Some error', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0), } @@ -1361,9 +1482,12 @@ end) local prefix = extmarks[1][4].virt_text[2][1] local message = extmarks[1][4].virt_text[3][1] return prefix .. message - ]]) + ]] + ) - eq('[(1/1) err-code] Some error', exec_lua [[ + eq( + '[(1/1) err-code] Some error', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), } @@ -1380,11 +1504,14 @@ end) local prefix = extmarks[1][4].virt_text[2][1] local message = extmarks[1][4].virt_text[3][1] return prefix .. message - ]]) + ]] + ) end) it('can add a suffix to virtual text', function() - eq(' Some error ✘', exec_lua [[ + eq( + ' Some error ✘', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0), } @@ -1400,9 +1527,12 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) local virt_text = extmarks[1][4].virt_text[3][1] return virt_text - ]]) + ]] + ) - eq(' Some error [err-code]', exec_lua [[ + eq( + ' Some error [err-code]', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), } @@ -1418,20 +1548,23 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) local virt_text = extmarks[1][4].virt_text[3][1] return virt_text - ]]) + ]] + ) end) end) describe('set()', function() it('validates its arguments', function() - matches("expected a list of diagnostics", - pcall_err(exec_lua, [[vim.diagnostic.set(1, 0, {lnum = 1, col = 2})]])) + matches( + 'expected a list of diagnostics', + pcall_err(exec_lua, [[vim.diagnostic.set(1, 0, {lnum = 1, col = 2})]]) + ) end) it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1444,21 +1577,27 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1480,24 +1619,30 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1505,8 +1650,8 @@ end) it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1529,24 +1674,30 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1554,8 +1705,8 @@ end) it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1569,46 +1720,64 @@ end) ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim("input", "<esc>") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '<esc>') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('can set diagnostics without displaying them', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('can set display options', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }, { virtual_text = false, underline = false }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }, { virtual_text = true, underline = false }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('sets and clears signs #26193 #26555', function() @@ -1636,8 +1805,8 @@ end) return result ]] - eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) - eq({4, 'DiagnosticSignWarn'}, {result[2].lnum, result[2].name}) + eq({ 2, 'DiagnosticSignError' }, { result[1].lnum, result[1].name }) + eq({ 4, 'DiagnosticSignWarn' }, { result[2].lnum, result[2].name }) end do @@ -1658,10 +1827,18 @@ end) -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 eq(0, helpers.funcs.has('nvim-0.12')) - helpers.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg') - helpers.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg') - helpers.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined') - helpers.command('sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined') + helpers.command( + 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg' + ) + helpers.command( + 'sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg' + ) + helpers.command( + 'sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined' + ) + helpers.command( + 'sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined' + ) local result = exec_lua [[ vim.diagnostic.config({ @@ -1712,7 +1889,9 @@ end) describe('open_float()', function() it('can display a header', function() - eq({'Diagnostics:', '1. Syntax error'}, exec_lua [[ + eq( + { 'Diagnostics:', '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1722,9 +1901,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"We're no strangers to love...", '1. Syntax error'}, exec_lua [[ + eq( + { "We're no strangers to love...", '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1734,9 +1916,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'You know the rules', '1. Syntax error'}, exec_lua [[ + eq( + { 'You know the rules', '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1746,11 +1931,14 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from the whole buffer', function() - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1761,12 +1949,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from a single line', function() -- Using cursor position - eq({'1. Some warning'}, exec_lua [[ + eq( + { '1. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1778,10 +1969,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With specified position - eq({'1. Some warning'}, exec_lua [[ + eq( + { '1. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1793,12 +1987,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from a specific position', function() -- Using cursor position - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 1, 1, 1, 2), make_warning("Some warning", 1, 3, 1, 4), @@ -1810,10 +2007,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With specified position - eq({'Some warning'}, exec_lua [[ + eq( + { 'Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 1, 1, 1, 2), make_warning("Some warning", 1, 3, 1, 4), @@ -1825,10 +2025,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With column position past the end of the line. #16062 - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local first_line_len = #vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, 1, true)[1] local diagnostics = { make_error("Syntax error", 0, first_line_len + 1, 1, 0), @@ -1840,14 +2043,19 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) - it('creates floating window and returns float bufnr and winnr if current line contains diagnostics', function() - -- Two lines: - -- Diagnostic: - -- 1. <msg> - eq(2, exec_lua [[ + it( + 'creates floating window and returns float bufnr and winnr if current line contains diagnostics', + function() + -- Two lines: + -- Diagnostic: + -- 1. <msg> + eq( + 2, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1857,11 +2065,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) - end) + ]] + ) + end + ) it('only reports diagnostics from the current buffer when bufnr is omitted #15710', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ local other_bufnr = vim.api.nvim_create_buf(true, false) local buf_1_diagnostics = { make_error("Syntax error", 0, 1, 0, 3), @@ -1876,11 +2088,14 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) it('allows filtering by namespace', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ local ns_1_diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1894,13 +2109,18 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) - it('creates floating window and returns float bufnr and winnr without header, if requested', function() - -- One line (since no header): - -- 1. <msg> - eq(1, exec_lua [[ + it( + 'creates floating window and returns float bufnr and winnr without header, if requested', + function() + -- One line (since no header): + -- 1. <msg> + eq( + 1, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1910,11 +2130,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) - end) + ]] + ) + end + ) it('clamps diagnostic line numbers within the valid range', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ local diagnostics = { make_error("Syntax error", 6, 0, 6, 0), } @@ -1924,13 +2148,16 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) it('can show diagnostic source', function() exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]] - eq({"1. Syntax error"}, exec_lua [[ + eq( + { '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, "source x"), } @@ -1942,9 +2169,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. source x: Syntax error"}, exec_lua [[ + eq( + { '1. source x: Syntax error' }, + exec_lua [[ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false, source = "always", @@ -1952,9 +2182,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. source x: Syntax error", "2. source y: Another error"}, exec_lua [[ + eq( + { '1. source x: Syntax error', '2. source y: Another error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, "source x"), make_error("Another error", 0, 1, 0, 3, "source y"), @@ -1967,13 +2200,16 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('respects severity_sort', function() exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]] - eq({"1. Syntax error", "2. Info", "3. Error", "4. Warning"}, exec_lua [[ + eq( + { '1. Syntax error', '2. Info', '3. Error', '4. Warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_info('Info', 0, 3, 0, 4), @@ -1989,28 +2225,36 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[ + eq( + { '1. Syntax error', '2. Error', '3. Warning', '4. Info' }, + exec_lua [[ vim.diagnostic.config({severity_sort = true}) local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false }) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[ + eq( + { '1. Info', '2. Warning', '3. Error', '4. Syntax error' }, + exec_lua [[ vim.diagnostic.config({severity_sort = { reverse = true } }) local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false }) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can filter by severity', function() local count_diagnostics_with_severity = function(min_severity, max_severity) - return exec_lua([[ + return exec_lua( + [[ local min_severity, max_severity = ... vim.diagnostic.config({ float = { @@ -2033,19 +2277,24 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]], min_severity, max_severity) + ]], + min_severity, + max_severity + ) end - eq(2, count_diagnostics_with_severity("ERROR")) - eq(3, count_diagnostics_with_severity("WARN")) - eq(1, count_diagnostics_with_severity("WARN", "WARN")) - eq(4, count_diagnostics_with_severity("HINT")) - eq(0, count_diagnostics_with_severity("HINT", "HINT")) + eq(2, count_diagnostics_with_severity('ERROR')) + eq(3, count_diagnostics_with_severity('WARN')) + eq(1, count_diagnostics_with_severity('WARN', 'WARN')) + eq(4, count_diagnostics_with_severity('HINT')) + eq(0, count_diagnostics_with_severity('HINT', 'HINT')) end) it('can add a prefix to diagnostics', function() -- Default is to add a number - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -2056,9 +2305,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'Syntax error', 'Some warning'}, exec_lua [[ + eq( + { 'Syntax error', 'Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -2069,9 +2321,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 0, 1, 0, 3), @@ -2091,9 +2346,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -2112,15 +2370,20 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq(".../diagnostic.lua:0: prefix: expected string|table|function, got number", - pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]])) + eq( + '.../diagnostic.lua:0: prefix: expected string|table|function, got number', + pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]]) + ) end) it('can add a suffix to diagnostics', function() -- Default is to render the diagnostic error code - eq({'1. Syntax error [code-x]', '2. Some warning [code-y]'}, exec_lua [[ + eq( + { '1. Syntax error [code-x]', '2. Some warning [code-y]' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), @@ -2131,9 +2394,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), @@ -2144,10 +2410,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- Suffix is rendered on the last line of a multiline diagnostic - eq({'1. Syntax error', ' More context [code-x]'}, exec_lua [[ + eq( + { '1. Syntax error', ' More context [code-x]' }, + exec_lua [[ local diagnostics = { make_error("Syntax error\nMore context", 0, 1, 0, 3, nil, "code-x"), } @@ -2157,14 +2426,19 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq(".../diagnostic.lua:0: suffix: expected string|table|function, got number", - pcall_err(exec_lua, [[ vim.diagnostic.open_float({ suffix = 42 }) ]])) + eq( + '.../diagnostic.lua:0: suffix: expected string|table|function, got number', + pcall_err(exec_lua, [[ vim.diagnostic.open_float({ suffix = 42 }) ]]) + ) end) it('works with the old signature', function() - eq({'1. Syntax error'}, exec_lua [[ + eq( + { '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -2174,7 +2448,8 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) end) @@ -2219,55 +2494,76 @@ end) describe('match()', function() it('matches a string', function() - local msg = "ERROR: george.txt:19:84:Two plus two equals five" + local msg = 'ERROR: george.txt:19:84:Two plus two equals five' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.ERROR]], lnum = 18, col = 83, end_lnum = 18, end_col = 83, - message = "Two plus two equals five", + message = 'Two plus two equals five', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^(%w+): [^:]+:(%d+):(%d+):(.+)$", {"severity", "lnum", "col", "message"}) - ]], msg)) + ]], + msg + ) + ) end) it('returns nil if the pattern fails to match', function() - eq(NIL, exec_lua [[ + eq( + NIL, + exec_lua [[ local msg = "The answer to life, the universe, and everything is" return vim.diagnostic.match(msg, "This definitely will not match", {}) - ]]) + ]] + ) end) it('respects default values', function() - local msg = "anna.txt:1:Happy families are all alike" + local msg = 'anna.txt:1:Happy families are all alike' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.INFO]], lnum = 0, col = 0, end_lnum = 0, end_col = 0, - message = "Happy families are all alike", + message = 'Happy families are all alike', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^[^:]+:(%d+):(.+)$", {"lnum", "message"}, nil, {severity = vim.diagnostic.severity.INFO}) - ]], msg)) + ]], + msg + ) + ) end) it('accepts a severity map', function() - local msg = "46:FATAL:Et tu, Brute?" + local msg = '46:FATAL:Et tu, Brute?' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.ERROR]], lnum = 45, col = 0, end_lnum = 45, end_col = 0, - message = "Et tu, Brute?", + message = 'Et tu, Brute?', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^(%d+):(%w+):(.+)$", {"lnum", "severity", "message"}, {FATAL = vim.diagnostic.severity.ERROR}) - ]], msg)) + ]], + msg + ) + ) end) end) @@ -2299,12 +2595,20 @@ end) describe('handlers', function() it('checks that a new handler is a table', function() - matches([[.*handler: expected table, got string.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = "bar" ]])) - matches([[.*handler: expected table, got function.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = function() end ]])) + matches( + [[.*handler: expected table, got string.*]], + pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = "bar" ]]) + ) + matches( + [[.*handler: expected table, got function.*]], + pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = function() end ]]) + ) end) it('can add new handlers', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local handler_called = false vim.diagnostic.handlers.test = { show = function(namespace, bufnr, diagnostics, opts) @@ -2321,11 +2625,14 @@ end) make_warning("Warning", 0, 0, 0, 0), }) return handler_called - ]]) + ]] + ) end) it('can disable handlers by setting the corresponding option to false', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ local handler_called = false vim.diagnostic.handlers.test = { show = function(namespace, bufnr, diagnostics, opts) @@ -2338,11 +2645,14 @@ end) make_warning("Warning", 0, 0, 0, 0), }) return handler_called - ]]) + ]] + ) end) - it('always calls a handler\'s hide function if defined', function() - eq({false, true}, exec_lua [[ + it("always calls a handler's hide function if defined", function() + eq( + { false, true }, + exec_lua [[ local hide_called = false local show_called = false vim.diagnostic.handlers.test = { @@ -2362,11 +2672,14 @@ end) }) vim.diagnostic.hide(diagnostic_ns, diagnostic_bufnr) return {show_called, hide_called} - ]]) + ]] + ) end) it('triggers the autocommand when diagnostics are set', function() - eq({true, true}, exec_lua [[ + eq( + { true, true }, + exec_lua [[ -- Set a different buffer as current to test that <abuf> is being set properly in -- DiagnosticChanged callbacks local tmp = vim.api.nvim_create_buf(false, true) @@ -2386,11 +2699,14 @@ end) triggered[1] == diagnostic_bufnr, triggered[2] == 1, } - ]]) - end) + ]] + ) + end) it('triggers the autocommand when diagnostics are cleared', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local tmp = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(tmp) vim.g.diagnostic_autocmd_triggered = 0 @@ -2398,11 +2714,14 @@ end) vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test") vim.diagnostic.reset(diagnostic_ns, diagnostic_bufnr) return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr - ]]) - end) + ]] + ) + end) - it("checks if diagnostics are disabled in a buffer", function() - eq({true, true, true , true}, exec_lua [[ + it('checks if diagnostics are disabled in a buffer', function() + eq( + { true, true, true, true }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) @@ -2414,9 +2733,12 @@ end) vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), vim.diagnostic.is_disabled(_, diagnostic_ns), } - ]]) + ]] + ) - eq({false, false, false , false}, exec_lua [[ + eq( + { false, false, false, false }, + exec_lua [[ vim.diagnostic.enable() return { vim.diagnostic.is_disabled(), @@ -2424,7 +2746,8 @@ end) vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), vim.diagnostic.is_disabled(_, diagnostic_ns), } - ]]) + ]] + ) end) end) end) diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua index dc00eff9b5..c9e8e9d4ca 100644 --- a/test/functional/lua/ffi_spec.lua +++ b/test/functional/lua/ffi_spec.lua @@ -11,7 +11,9 @@ describe('ffi.cdef', function() pending('missing LuaJIT FFI') end - eq(12, exec_lua[[ + eq( + 12, + exec_lua [[ local ffi = require('ffi') ffi.cdef('int curwin_col_off(void);') @@ -19,9 +21,12 @@ describe('ffi.cdef', function() vim.cmd('set number numberwidth=4 signcolumn=yes:4') return ffi.C.curwin_col_off() - ]]) + ]] + ) - eq(20, exec_lua[=[ + eq( + 20, + exec_lua [=[ local ffi = require('ffi') ffi.cdef[[ @@ -61,15 +66,19 @@ describe('ffi.cdef', function() nil, nil ) - ]=]) + ]=] + ) -- Check that extern symbols are exported and accessible - eq(true, exec_lua[[ + eq( + true, + exec_lua [[ local ffi = require('ffi') ffi.cdef('uint64_t display_tick;') return ffi.C.display_tick >= 0 - ]]) + ]] + ) end) end) diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index b3d95e1c7f..50db613dde 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -19,18 +19,23 @@ describe('vim.filetype', function() end) it('works with extensions', function() - eq('radicalscript', exec_lua [[ + eq( + 'radicalscript', + exec_lua [[ vim.filetype.add({ extension = { rs = 'radicalscript', }, }) return vim.filetype.match({ filename = 'main.rs' }) - ]]) + ]] + ) end) it('prioritizes filenames over extensions', function() - eq('somethingelse', exec_lua [[ + eq( + 'somethingelse', + exec_lua [[ vim.filetype.add({ extension = { rs = 'radicalscript', @@ -40,20 +45,27 @@ describe('vim.filetype', function() }, }) return vim.filetype.match({ filename = 'main.rs' }) - ]]) + ]] + ) end) it('works with filenames', function() - eq('nim', exec_lua [[ + eq( + 'nim', + exec_lua [[ vim.filetype.add({ filename = { ['s_O_m_e_F_i_l_e'] = 'nim', }, }) return vim.filetype.match({ filename = 's_O_m_e_F_i_l_e' }) - ]]) + ]] + ) - eq('dosini', exec_lua([[ + eq( + 'dosini', + exec_lua( + [[ local root = ... vim.filetype.add({ filename = { @@ -62,11 +74,17 @@ describe('vim.filetype', function() }, }) return vim.filetype.match({ filename = root .. '/.config/fun/config' }) - ]], root)) + ]], + root + ) + ) end) it('works with patterns', function() - eq('markdown', exec_lua([[ + eq( + 'markdown', + exec_lua( + [[ local root = ... vim.env.HOME = '/a-funky+home%dir' vim.filetype.add({ @@ -75,13 +93,18 @@ describe('vim.filetype', function() } }) return vim.filetype.match({ filename = '~/blog/why_neovim_is_awesome.txt' }) - ]], root)) + ]], + root + ) + ) end) it('works with functions', function() command('new') command('file relevant_to_me') - eq('foss', exec_lua [[ + eq( + 'foss', + exec_lua [[ vim.filetype.add({ pattern = { ["relevant_to_(%a+)"] = function(path, bufnr, capture) @@ -92,26 +115,33 @@ describe('vim.filetype', function() } }) return vim.filetype.match({ buf = 0 }) - ]]) + ]] + ) end) it('works with contents #22180', function() - eq('sh', exec_lua [[ + eq( + 'sh', + exec_lua [[ -- Needs to be set so detect#sh doesn't fail vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$' return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } }) - ]]) + ]] + ) end) it('considers extension mappings when matching from hashbang', function() - eq('fooscript', exec_lua [[ + eq( + 'fooscript', + exec_lua [[ vim.filetype.add({ extension = { foo = 'fooscript', } }) return vim.filetype.match({ contents = { '#!/usr/bin/env foo' } }) - ]]) + ]] + ) end) it('can get default option values for filetypes via vim.filetype.get_option()', function() @@ -120,20 +150,21 @@ describe('vim.filetype', function() for ft, opts in pairs { lua = { commentstring = '-- %s' }, vim = { commentstring = '"%s' }, - man = { tagfunc = 'v:lua.require\'man\'.goto_tag' }, - xml = { formatexpr = 'xmlformat#Format()' } + man = { tagfunc = "v:lua.require'man'.goto_tag" }, + xml = { formatexpr = 'xmlformat#Format()' }, } do for option, value in pairs(opts) do eq(value, exec_lua([[ return vim.filetype.get_option(...) ]], ft, option)) end end - end) end) describe('filetype.lua', function() it('does not override user autocommands that set filetype #20333', function() - clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}}) + clear({ + args = { '--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md' }, + }) eq('notmarkdown', meths.get_option_value('filetype', {})) end) end) diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 76f543cc97..c212f4ad9a 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -56,13 +56,13 @@ describe('vim.fs', function() local test_dir = nvim_dir .. '/test' mkdir_p(test_dir) local dirs = {} - for dir in vim.fs.parents(test_dir .. "/foo.txt") do + for dir in vim.fs.parents(test_dir .. '/foo.txt') do dirs[#dirs + 1] = dir if dir == test_build_dir then break end end - eq({test_dir, nvim_dir, test_build_dir}, dirs) + eq({ test_dir, nvim_dir, test_build_dir }, dirs) rmdir(test_dir) end) end) @@ -74,11 +74,15 @@ describe('vim.fs', function() local function test_paths(paths) for _, path in ipairs(paths) do eq( - exec_lua([[ + exec_lua( + [[ local path = ... return vim.fn.fnamemodify(path,':h'):gsub('\\', '/') - ]], path), - vim.fs.dirname(path), path + ]], + path + ), + vim.fs.dirname(path), + path ) end end @@ -97,10 +101,15 @@ describe('vim.fs', function() local function test_paths(paths) for _, path in ipairs(paths) do eq( - exec_lua([[ + exec_lua( + [[ local path = ... return vim.fn.fnamemodify(path,':t'):gsub('\\', '/') - ]], path), vim.fs.basename(path), path + ]], + path + ), + vim.fs.basename(path), + path ) end end @@ -125,7 +134,10 @@ describe('vim.fs', function() end) it('works', function() - eq(true, exec_lua([[ + eq( + true, + exec_lua( + [[ local dir, nvim = ... for name, type in vim.fs.dir(dir) do if name == nvim and type == 'file' then @@ -133,7 +145,11 @@ describe('vim.fs', function() end end return false - ]], nvim_dir, nvim_prog_basename)) + ]], + nvim_dir, + nvim_prog_basename + ) + ) end) it('works with opts.depth and opts.skip', function() @@ -151,7 +167,8 @@ describe('vim.fs', function() io.open('testd/a/b/c/c4', 'w'):close() local function run(dir, depth, skip) - local r = exec_lua([[ + local r = exec_lua( + [[ local dir, depth, skip = ... local r = {} local skip_f @@ -166,7 +183,11 @@ describe('vim.fs', function() r[name] = type_ end return r - ]], dir, depth, skip) + ]], + dir, + depth, + skip + ) return r end @@ -192,7 +213,7 @@ describe('vim.fs', function() exp['a/b/c'] = 'directory' eq(exp, run('testd', 3)) - eq(exp, run('testd', 999, {'a/b/c'})) + eq(exp, run('testd', 999, { 'a/b/c' })) exp['a/b/c/a4'] = 'file' exp['a/b/c/b4'] = 'file' @@ -204,27 +225,53 @@ describe('vim.fs', function() describe('find()', function() it('works', function() - eq({test_build_dir .. "/build"}, vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' })) - eq({nvim_prog}, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' })) + eq( + { test_build_dir .. '/build' }, + vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' }) + ) + eq({ nvim_prog }, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' })) local parent, name = nvim_dir:match('^(.*/)([^/]+)$') - eq({nvim_dir}, vim.fs.find(name, { path = parent, upward = true, type = 'directory' })) + eq({ nvim_dir }, vim.fs.find(name, { path = parent, upward = true, type = 'directory' })) end) it('accepts predicate as names', function() local opts = { path = nvim_dir, upward = true, type = 'directory' } - eq({test_build_dir .. "/build"}, vim.fs.find(function(x) return x == 'build' end, opts)) - eq({nvim_prog}, vim.fs.find(function(x) return x == nvim_prog_basename end, { path = test_build_dir, type = 'file' })) - eq({}, vim.fs.find(function(x) return x == 'no-match' end, opts)) + eq( + { test_build_dir .. '/build' }, + vim.fs.find(function(x) + return x == 'build' + end, opts) + ) + eq( + { nvim_prog }, + vim.fs.find(function(x) + return x == nvim_prog_basename + end, { path = test_build_dir, type = 'file' }) + ) + eq( + {}, + vim.fs.find(function(x) + return x == 'no-match' + end, opts) + ) - opts = { path = test_source_path .. "/contrib", limit = math.huge } + opts = { path = test_source_path .. '/contrib', limit = math.huge } eq( - exec_lua([[ + exec_lua( + [[ local dir = ... return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true)) - ]], test_source_path), - vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts)) + ]], + test_source_path + ), + vim.tbl_map( + vim.fs.basename, + vim.fs.find(function(_, d) + return d:match('[\\/]contrib$') + end, opts) ) + ) end) end) @@ -250,10 +297,16 @@ describe('vim.fs', function() end) it('works with environment variables', function() local xdg_config_home = test_build_dir .. '/.config' - eq(xdg_config_home .. '/nvim', exec_lua([[ + eq( + xdg_config_home .. '/nvim', + exec_lua( + [[ vim.env.XDG_CONFIG_HOME = ... return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') - ]], xdg_config_home)) + ]], + xdg_config_home + ) + ) end) if is_os('win') then it('Last slash is not truncated from root drive', function() diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua index ce38d25e46..c7ef498008 100644 --- a/test/functional/lua/glob_spec.lua +++ b/test/functional/lua/glob_spec.lua @@ -7,11 +7,14 @@ describe('glob', function() after_each(helpers.clear) local match = function(...) - return exec_lua([[ + return exec_lua( + [[ local pattern = select(1, ...) local str = select(2, ...) return require("vim.glob").to_lpeg(pattern):match(str) ~= nil - ]], ...) + ]], + ... + ) end describe('glob matching', function() diff --git a/test/functional/lua/help_spec.lua b/test/functional/lua/help_spec.lua index ef1b8ebf3f..12fd942474 100644 --- a/test/functional/lua/help_spec.lua +++ b/test/functional/lua/help_spec.lua @@ -8,7 +8,9 @@ local exec_lua = helpers.exec_lua local eq = helpers.eq local ok = helpers.ok -if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then return end +if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then + return +end describe(':help docs', function() before_each(clear) @@ -23,10 +25,14 @@ describe(':help docs', function() ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles) eq({}, rv.parse_errors, 'no parse errors') - eq(0, rv.err_count, 'no parse errors') + eq(0, rv.err_count, 'no parse errors') eq({}, rv.invalid_links, 'invalid tags in :help docs') eq({}, rv.invalid_urls, 'invalid URLs in :help docs') - eq({}, rv.invalid_spelling, 'invalid spelling in :help docs (see spell_dict in scripts/gen_help_html.lua)') + eq( + {}, + rv.invalid_spelling, + 'invalid spelling in :help docs (see spell_dict in scripts/gen_help_html.lua)' + ) end) it('gen_help_html.lua generates HTML', function() @@ -36,7 +42,8 @@ describe(':help docs', function() local tmpdir = exec_lua('return vim.fs.dirname(vim.fn.tempname())') -- Because gen() is slow (~30s), this test is limited to a few files. - local rv = exec_lua([[ + local rv = exec_lua( + [[ local to_dir = ... return require('scripts.gen_help_html').gen( './build/runtime/doc', diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua index c369956e56..ad8b5a45a8 100644 --- a/test/functional/lua/inspector_spec.lua +++ b/test/functional/lua/inspector_spec.lua @@ -46,9 +46,9 @@ describe('vim.inspect_pos', function() hl_group_link = 'Normal', ns_id = 1, priority = 4096, - right_gravity = true + right_gravity = true, }, - row = 0 + row = 0, }, { col = 10, @@ -63,10 +63,10 @@ describe('vim.inspect_pos', function() hl_group_link = 'Normal', ns_id = 2, priority = 4096, - right_gravity = true + right_gravity = true, }, - row = 0 - } + row = 0, + }, }, treesitter = {}, semantic_tokens = {}, diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua index a589474262..fdf573669a 100644 --- a/test/functional/lua/iter_spec.lua +++ b/test/functional/lua/iter_spec.lua @@ -6,11 +6,11 @@ local pcall_err = helpers.pcall_err describe('vim.iter', function() it('new() on iterable class instance', function() local rb = vim.ringbuf(3) - rb:push("a") - rb:push("b") + rb:push('a') + rb:push('b') local it = vim.iter(rb) - eq({"a", "b"}, it:totable()) + eq({ 'a', 'b' }, it:totable()) end) it('filter()', function() @@ -20,18 +20,43 @@ describe('vim.iter', function() local t = { 1, 2, 3, 4, 5 } eq({ 1, 3, 5 }, vim.iter(t):filter(odd):totable()) - eq({ 2, 4 }, vim.iter(t):filter(function(v) return not odd(v) end):totable()) - eq({}, vim.iter(t):filter(function(v) return v > 5 end):totable()) + eq( + { 2, 4 }, + vim + .iter(t) + :filter(function(v) + return not odd(v) + end) + :totable() + ) + eq( + {}, + vim + .iter(t) + :filter(function(v) + return v > 5 + end) + :totable() + ) do local it = vim.iter(ipairs(t)) - it:filter(function(i, v) return i > 1 and v < 5 end) - it:map(function(_, v) return v * 2 end) + it:filter(function(i, v) + return i > 1 and v < 5 + end) + it:map(function(_, v) + return v * 2 + end) eq({ 4, 6, 8 }, it:totable()) end local it = vim.iter(string.gmatch('the quick brown fox', '%w+')) - eq({'the', 'fox'}, it:filter(function(s) return #s <= 3 end):totable()) + eq( + { 'the', 'fox' }, + it:filter(function(s) + return #s <= 3 + end):totable() + ) end) it('map()', function() @@ -39,11 +64,11 @@ describe('vim.iter', function() eq( { 2, 4, 6, 8, 10 }, vim - .iter(t) - :map(function(v) - return 2 * v - end) - :totable() + .iter(t) + :map(function(v) + return 2 * v + end) + :totable() ) local it = vim.gsplit( @@ -59,21 +84,25 @@ describe('vim.iter', function() eq( { 'Lion 2', 'Lion 4' }, vim - .iter(it) - :map(function(s) - local lnum = s:match('(%d+)') - if lnum and tonumber(lnum) % 2 == 0 then - return vim.trim(s:gsub('Line', 'Lion')) - end - end) - :totable() + .iter(it) + :map(function(s) + local lnum = s:match('(%d+)') + if lnum and tonumber(lnum) % 2 == 0 then + return vim.trim(s:gsub('Line', 'Lion')) + end + end) + :totable() ) end) it('for loops', function() - local t = {1, 2, 3, 4, 5} + local t = { 1, 2, 3, 4, 5 } local acc = 0 - for v in vim.iter(t):map(function(v) return v * 3 end) do + for v in + vim.iter(t):map(function(v) + return v * 3 + end) + do acc = acc + v end eq(45, acc) @@ -81,23 +110,27 @@ describe('vim.iter', function() it('totable()', function() do - local it = vim.iter({1, 2, 3}):map(function(v) return v, v*v end) - eq({{1, 1}, {2, 4}, {3, 9}}, it:totable()) + local it = vim.iter({ 1, 2, 3 }):map(function(v) + return v, v * v + end) + eq({ { 1, 1 }, { 2, 4 }, { 3, 9 } }, it:totable()) end do local it = vim.iter(string.gmatch('1,4,lol,17,blah,2,9,3', '%d+')):map(tonumber) - eq({1, 4, 17, 2, 9, 3}, it:totable()) + eq({ 1, 4, 17, 2, 9, 3 }, it:totable()) end end) it('join()', function() - eq('1, 2, 3', vim.iter({1, 2, 3}):join(', ')) + eq('1, 2, 3', vim.iter({ 1, 2, 3 }):join(', ')) eq('a|b|c|d', vim.iter(vim.gsplit('a|b|c|d', '|')):join('|')) end) it('next()', function() - local it = vim.iter({1, 2, 3}):map(function(v) return 2 * v end) + local it = vim.iter({ 1, 2, 3 }):map(function(v) + return 2 * v + end) eq(2, it:next()) eq(4, it:next()) eq(6, it:next()) @@ -105,19 +138,19 @@ describe('vim.iter', function() end) it('rev()', function() - eq({3, 2, 1}, vim.iter({1, 2, 3}):rev():totable()) + eq({ 3, 2, 1 }, vim.iter({ 1, 2, 3 }):rev():totable()) - local it = vim.iter(string.gmatch("abc", "%w")) + local it = vim.iter(string.gmatch('abc', '%w')) matches('rev%(%) requires a list%-like table', pcall_err(it.rev, it)) end) it('skip()', function() do - local t = {4, 3, 2, 1} + local t = { 4, 3, 2, 1 } eq(t, vim.iter(t):skip(0):totable()) - eq({3, 2, 1}, vim.iter(t):skip(1):totable()) - eq({2, 1}, vim.iter(t):skip(2):totable()) - eq({1}, vim.iter(t):skip(#t - 1):totable()) + eq({ 3, 2, 1 }, vim.iter(t):skip(1):totable()) + eq({ 2, 1 }, vim.iter(t):skip(2):totable()) + eq({ 1 }, vim.iter(t):skip(#t - 1):totable()) eq({}, vim.iter(t):skip(#t):totable()) eq({}, vim.iter(t):skip(#t + 1):totable()) end @@ -126,10 +159,10 @@ describe('vim.iter', function() local function skip(n) return vim.iter(vim.gsplit('a|b|c|d', '|')):skip(n):totable() end - eq({'a', 'b', 'c', 'd'}, skip(0)) - eq({'b', 'c', 'd'}, skip(1)) - eq({'c', 'd'}, skip(2)) - eq({'d'}, skip(3)) + eq({ 'a', 'b', 'c', 'd' }, skip(0)) + eq({ 'b', 'c', 'd' }, skip(1)) + eq({ 'c', 'd' }, skip(2)) + eq({ 'd' }, skip(3)) eq({}, skip(4)) eq({}, skip(5)) end @@ -137,11 +170,11 @@ describe('vim.iter', function() it('skipback()', function() do - local t = {4, 3, 2, 1} + local t = { 4, 3, 2, 1 } eq(t, vim.iter(t):skipback(0):totable()) - eq({4, 3, 2}, vim.iter(t):skipback(1):totable()) - eq({4, 3}, vim.iter(t):skipback(2):totable()) - eq({4}, vim.iter(t):skipback(#t - 1):totable()) + eq({ 4, 3, 2 }, vim.iter(t):skipback(1):totable()) + eq({ 4, 3 }, vim.iter(t):skipback(2):totable()) + eq({ 4 }, vim.iter(t):skipback(#t - 1):totable()) eq({}, vim.iter(t):skipback(#t):totable()) eq({}, vim.iter(t):skipback(#t + 1):totable()) end @@ -151,14 +184,14 @@ describe('vim.iter', function() end) it('slice()', function() - local t = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - eq({3, 4, 5, 6, 7}, vim.iter(t):slice(3, 7):totable()) + local t = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } + eq({ 3, 4, 5, 6, 7 }, vim.iter(t):slice(3, 7):totable()) eq({}, vim.iter(t):slice(6, 5):totable()) eq({}, vim.iter(t):slice(0, 0):totable()) - eq({1}, vim.iter(t):slice(1, 1):totable()) - eq({1, 2}, vim.iter(t):slice(1, 2):totable()) - eq({10}, vim.iter(t):slice(10, 10):totable()) - eq({8, 9, 10}, vim.iter(t):slice(8, 11):totable()) + eq({ 1 }, vim.iter(t):slice(1, 1):totable()) + eq({ 1, 2 }, vim.iter(t):slice(1, 2):totable()) + eq({ 10 }, vim.iter(t):slice(10, 10):totable()) + eq({ 8, 9, 10 }, vim.iter(t):slice(8, 11):totable()) local it = vim.iter(vim.gsplit('a|b|c|d', '|')) matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3)) @@ -166,7 +199,7 @@ describe('vim.iter', function() it('nth()', function() do - local t = {4, 3, 2, 1} + local t = { 4, 3, 2, 1 } eq(nil, vim.iter(t):nth(0)) eq(4, vim.iter(t):nth(1)) eq(3, vim.iter(t):nth(2)) @@ -190,7 +223,7 @@ describe('vim.iter', function() it('nthback()', function() do - local t = {4, 3, 2, 1} + local t = { 4, 3, 2, 1 } eq(nil, vim.iter(t):nthback(0)) eq(1, vim.iter(t):nthback(1)) eq(2, vim.iter(t):nthback(2)) @@ -246,8 +279,18 @@ describe('vim.iter', function() end do - eq(true, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'd' end)) - eq(false, vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) return s == 'e' end)) + eq( + true, + vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) + return s == 'd' + end) + ) + eq( + false, + vim.iter(vim.gsplit('a|b|c|d', '|')):any(function(s) + return s == 'e' + end) + ) end end) @@ -267,8 +310,18 @@ describe('vim.iter', function() end do - eq(true, vim.iter(vim.gsplit('a|a|a|a', '|')):all(function(s) return s == 'a' end)) - eq(false, vim.iter(vim.gsplit('a|a|a|b', '|')):all(function(s) return s == 'a' end)) + eq( + true, + vim.iter(vim.gsplit('a|a|a|a', '|')):all(function(s) + return s == 'a' + end) + ) + eq( + false, + vim.iter(vim.gsplit('a|a|a|b', '|')):all(function(s) + return s == 'a' + end) + ) end end) @@ -280,10 +333,10 @@ describe('vim.iter', function() it('enumerate()', function() local it = vim.iter(vim.gsplit('abc', '')):enumerate() - eq({1, 'a'}, {it:next()}) - eq({2, 'b'}, {it:next()}) - eq({3, 'c'}, {it:next()}) - eq({}, {it:next()}) + eq({ 1, 'a' }, { it:next() }) + eq({ 2, 'b' }, { it:next() }) + eq({ 3, 'c' }, { it:next() }) + eq({}, { it:next() }) end) it('peek()', function() @@ -301,14 +354,21 @@ describe('vim.iter', function() end) it('find()', function() - local t = {3, 6, 9, 12} + local t = { 3, 6, 9, 12 } eq(12, vim.iter(t):find(12)) eq(nil, vim.iter(t):find(15)) - eq(12, vim.iter(t):find(function(v) return v % 4 == 0 end)) + eq( + 12, + vim.iter(t):find(function(v) + return v % 4 == 0 + end) + ) do local it = vim.iter(t) - local pred = function(v) return v % 3 == 0 end + local pred = function(v) + return v % 3 == 0 + end eq(3, it:find(pred)) eq(6, it:find(pred)) eq(9, it:find(pred)) @@ -318,7 +378,9 @@ describe('vim.iter', function() do local it = vim.iter(vim.gsplit('AbCdE', '')) - local pred = function(s) return s:match('[A-Z]') end + local pred = function(s) + return s:match('[A-Z]') + end eq('A', it:find(pred)) eq('C', it:find(pred)) eq('E', it:find(pred)) @@ -327,7 +389,7 @@ describe('vim.iter', function() end) it('rfind()', function() - local t = {1, 2, 3, 2, 1} + local t = { 1, 2, 3, 2, 1 } do local it = vim.iter(t) eq(1, it:rfind(1)) @@ -337,10 +399,12 @@ describe('vim.iter', function() do local it = vim.iter(t):enumerate() - local pred = function(i) return i % 2 ~= 0 end - eq({5, 1}, {it:rfind(pred)}) - eq({3, 3}, {it:rfind(pred)}) - eq({1, 1}, {it:rfind(pred)}) + local pred = function(i) + return i % 2 ~= 0 + end + eq({ 5, 1 }, { it:rfind(pred) }) + eq({ 3, 3 }, { it:rfind(pred) }) + eq({ 1, 1 }, { it:rfind(pred) }) eq(nil, it:rfind(pred)) end @@ -382,12 +446,20 @@ describe('vim.iter', function() end) it('fold()', function() - local t = {1, 2, 3, 4, 5} - eq(115, vim.iter(t):fold(100, function(acc, v) return acc + v end)) - eq({5, 4, 3, 2, 1}, vim.iter(t):fold({}, function(acc, v) - table.insert(acc, 1, v) - return acc - end)) + local t = { 1, 2, 3, 4, 5 } + eq( + 115, + vim.iter(t):fold(100, function(acc, v) + return acc + v + end) + ) + eq( + { 5, 4, 3, 2, 1 }, + vim.iter(t):fold({}, function(acc, v) + table.insert(acc, 1, v) + return acc + end) + ) end) it('handles map-like tables', function() @@ -417,9 +489,12 @@ describe('vim.iter', function() }, } - local output = vim.iter(map):map(function(key, value) - return { [key] = value.file } - end):totable() + local output = vim + .iter(map) + :map(function(key, value) + return { [key] = value.file } + end) + :totable() table.sort(output, function(a, b) return next(a) < next(b) diff --git a/test/functional/lua/json_spec.lua b/test/functional/lua/json_spec.lua index 705bfcf2f9..d348e2de3c 100644 --- a/test/functional/lua/json_spec.lua +++ b/test/functional/lua/json_spec.lua @@ -16,40 +16,44 @@ describe('vim.json.decode()', function() end) it('validation', function() - eq('Expected object key string but found invalid token at character 2', - pcall_err(exec_lua, [[return vim.json.decode('{a:"b"}')]])) + eq( + 'Expected object key string but found invalid token at character 2', + pcall_err(exec_lua, [[return vim.json.decode('{a:"b"}')]]) + ) end) it('options', function() local jsonstr = '{"arr":[1,2,null],"bar":[3,7],"foo":{"a":"b"},"baz":null}' eq({ - arr = { 1, 2, vim.NIL }, - bar = { 3, 7 }, - baz = vim.NIL, - foo = { a = 'b' }, - }, - exec_lua([[return vim.json.decode(..., {})]], jsonstr)) - eq({ - arr = { 1, 2, vim.NIL }, - bar = { 3, 7 }, - -- baz = nil, - foo = { a = 'b' }, - }, - exec_lua([[return vim.json.decode(..., { luanil = { object = true } })]], jsonstr)) + arr = { 1, 2, vim.NIL }, + bar = { 3, 7 }, + baz = vim.NIL, + foo = { a = 'b' }, + }, exec_lua([[return vim.json.decode(..., {})]], jsonstr)) eq({ - arr = { 1, 2 }, - bar = { 3, 7 }, - baz = vim.NIL, - foo = { a = 'b' }, - }, - exec_lua([[return vim.json.decode(..., { luanil = { array = true } })]], jsonstr)) + arr = { 1, 2, vim.NIL }, + bar = { 3, 7 }, + -- baz = nil, + foo = { a = 'b' }, + }, exec_lua([[return vim.json.decode(..., { luanil = { object = true } })]], jsonstr)) eq({ + arr = { 1, 2 }, + bar = { 3, 7 }, + baz = vim.NIL, + foo = { a = 'b' }, + }, exec_lua([[return vim.json.decode(..., { luanil = { array = true } })]], jsonstr)) + eq( + { arr = { 1, 2 }, bar = { 3, 7 }, -- baz = nil, foo = { a = 'b' }, }, - exec_lua([[return vim.json.decode(..., { luanil = { array = true, object = true } })]], jsonstr)) + exec_lua( + [[return vim.json.decode(..., { luanil = { array = true, object = true } })]], + jsonstr + ) + ) end) it('parses integer numbers', function() @@ -96,13 +100,15 @@ describe('vim.json.decode()', function() end) it('parses containers', function() - eq({1}, exec_lua([[return vim.json.decode('[1]')]])) - eq({vim.NIL, 1}, exec_lua([[return vim.json.decode('[null, 1]')]])) - eq({['1']=2}, exec_lua([[return vim.json.decode('{"1": 2}')]])) - eq({['1']=2, ['3']={{['4']={['5']={{}, 1}}}}}, - exec_lua([[return vim.json.decode('{"1": 2, "3": [{"4": {"5": [ [], 1]}}]}')]])) + eq({ 1 }, exec_lua([[return vim.json.decode('[1]')]])) + eq({ vim.NIL, 1 }, exec_lua([[return vim.json.decode('[null, 1]')]])) + eq({ ['1'] = 2 }, exec_lua([[return vim.json.decode('{"1": 2}')]])) + eq( + { ['1'] = 2, ['3'] = { { ['4'] = { ['5'] = { {}, 1 } } } } }, + exec_lua([[return vim.json.decode('{"1": 2, "3": [{"4": {"5": [ [], 1]}}]}')]]) + ) -- Empty string is a valid key. #20757 - eq({['']=42}, exec_lua([[return vim.json.decode('{"": 42}')]])) + eq({ [''] = 42 }, exec_lua([[return vim.json.decode('{"": 42}')]])) end) it('parses strings properly', function() @@ -111,8 +117,8 @@ describe('vim.json.decode()', function() eq('\\/"\t\b\n\r\f', exec_lua([=[return vim.json.decode([["\\\/\"\t\b\n\r\f"]])]=])) eq('/a', exec_lua([=[return vim.json.decode([["\/a"]])]=])) -- Unicode characters: 2-byte, 3-byte - eq('«',exec_lua([=[return vim.json.decode([["«"]])]=])) - eq('ફ',exec_lua([=[return vim.json.decode([["ફ"]])]=])) + eq('«', exec_lua([=[return vim.json.decode([["«"]])]=])) + eq('ફ', exec_lua([=[return vim.json.decode([["ફ"]])]=])) end) it('parses surrogate pairs properly', function() @@ -120,11 +126,11 @@ describe('vim.json.decode()', function() end) it('accepts all spaces in every position where space may be put', function() - local s = ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t' + local s = + ' \t\n\r \t\r\n \n\t\r \n\r\t \r\t\n \r\n\t\t \n\r\t \r\n\t\n \r\t\n\r \t\r \n\t\r\n \n \t\r\n \r\t\n\t \r\n\t\r \n\r \t\n\r\t \r \t\n\r \n\t\r\t \n\r\t\n \r\n \t\r\n\t' local str = ('%s{%s"key"%s:%s[%s"val"%s,%s"val2"%s]%s,%s"key2"%s:%s1%s}%s'):gsub('%%s', s) - eq({key={'val', 'val2'}, key2=1}, exec_lua([[return vim.json.decode(...)]], str)) + eq({ key = { 'val', 'val2' }, key2 = 1 }, exec_lua([[return vim.json.decode(...)]], str)) end) - end) describe('vim.json.encode()', function() @@ -170,5 +176,4 @@ describe('vim.json.encode()', function() it('dumps vim.NIL', function() eq('null', exec_lua([[return vim.json.encode(vim.NIL)]])) end) - end) diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua index 34c36b04ef..92dd2296cb 100644 --- a/test/functional/lua/loader_spec.lua +++ b/test/functional/lua/loader_spec.lua @@ -9,37 +9,49 @@ describe('vim.loader', function() before_each(helpers.clear) it('handles changing files (#23027)', function() - exec_lua[[ + exec_lua [[ vim.loader.enable() ]] local tmp = helpers.tmpname() command('edit ' .. tmp) - eq(1, exec_lua([[ + eq( + 1, + exec_lua( + [[ vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=1'}) vim.cmd.write() loadfile(...)() return _G.TEST - ]], tmp)) + ]], + tmp + ) + ) -- fs latency helpers.sleep(10) - eq(2, exec_lua([[ + eq( + 2, + exec_lua( + [[ vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=2'}) vim.cmd.write() loadfile(...)() return _G.TEST - ]], tmp)) + ]], + tmp + ) + ) end) it('handles % signs in modpath (#24491)', function() - exec_lua[[ + exec_lua [[ vim.loader.enable() ]] - local tmp1, tmp2 = (function (t) + local tmp1, tmp2 = (function(t) assert(os.remove(t)) assert(helpers.mkdir(t)) assert(helpers.mkdir(t .. '/%')) diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 4f98fe0977..e46dbe7455 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -15,16 +15,15 @@ local retry = helpers.retry before_each(clear) describe('vim.uv', function() - it('version', function() - assert(funcs.luaeval('vim.uv.version()')>=72961, "libuv version too old") - matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.uv.version_string()')) + assert(funcs.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') + matches('(%d+)%.(%d+)%.(%d+)', funcs.luaeval('vim.uv.version_string()')) end) it('timer', function() exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {}) - local code=[[ + local code = [[ local uv = vim.uv local touch = 0 @@ -61,14 +60,14 @@ describe('vim.uv', function() end) it('is API safe', function() - local screen = Screen.new(50,10) + local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [5] = {bold = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [5] = { bold = true }, }) -- deferred API functions are disabled, as their safety can't be guaranteed @@ -96,7 +95,7 @@ describe('vim.uv', function() ]]) feed('<cr>') eq(false, eval("get(g:, 'valid', v:false)")) - eq(true, exec_lua("return _G.is_fast")) + eq(true, exec_lua('return _G.is_fast')) -- callbacks can be scheduled to be executed in the main event loop -- where the entire API is available @@ -116,7 +115,7 @@ describe('vim.uv', function() howdy | ]]) eq(true, eval("get(g:, 'valid', v:false)")) - eq(false, exec_lua("return _G.is_fast")) + eq(false, exec_lua('return _G.is_fast')) -- fast (not deferred) API functions are allowed to be called directly exec_lua([[ @@ -133,7 +132,7 @@ describe('vim.uv', function() {1:~ }|*8 {5:-- INSERT --} | ]]) - eq({blocking=false, mode='n'}, exec_lua("return _G.mode")) + eq({ blocking = false, mode = 'n' }, exec_lua('return _G.mode')) end) it("is equal to require('luv')", function() diff --git a/test/functional/lua/mpack_spec.lua b/test/functional/lua/mpack_spec.lua index cc788ed8bb..0b6a6d60bd 100644 --- a/test/functional/lua/mpack_spec.lua +++ b/test/functional/lua/mpack_spec.lua @@ -8,16 +8,22 @@ local exec_lua = helpers.exec_lua describe('lua vim.mpack', function() before_each(clear) it('encodes vim.NIL', function() - eq({true, true, true, true}, exec_lua [[ + eq( + { true, true, true, true }, + exec_lua [[ local var = vim.mpack.decode(vim.mpack.encode({33, vim.NIL, 77})) return {var[1]==33, var[2]==vim.NIL, var[3]==77, var[4]==nil} - ]]) + ]] + ) end) it('encodes vim.empty_dict()', function() - eq({{{}, "foo", {}}, true, false}, exec_lua [[ + eq( + { { {}, 'foo', {} }, true, false }, + exec_lua [[ local var = vim.mpack.decode(vim.mpack.encode({{}, "foo", vim.empty_dict()})) return {var, vim.tbl_islist(var[1]), vim.tbl_islist(var[3])} - ]]) + ]] + ) end) end) diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index f3ea29b8a7..0f1c7d8a51 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -42,25 +42,36 @@ describe('print', function() eq('abc', exec_capture('luafile ' .. fname)) end) it('handles errors in __tostring', function() - write_file(fname, [[ + write_file( + fname, + [[ local meta_nilerr = { __tostring = function() error(nil) end } local meta_abcerr = { __tostring = function() error("abc") end } local meta_tblout = { __tostring = function() return {"TEST"} end } v_nilerr = setmetatable({}, meta_nilerr) v_abcerr = setmetatable({}, meta_abcerr) v_tblout = setmetatable({}, meta_tblout) - ]]) + ]] + ) eq('', exec_capture('luafile ' .. fname)) -- TODO(bfredl): these look weird, print() should not use "E5114:" style errors.. - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]', - pcall_err(command, 'lua print("foo", v_nilerr, "bar")')) - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', - pcall_err(command, 'lua print("foo", v_abcerr, "bar")')) - eq('Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>', - pcall_err(command, 'lua print("foo", v_tblout, "bar")')) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: [NULL]', + pcall_err(command, 'lua print("foo", v_nilerr, "bar")') + ) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc', + pcall_err(command, 'lua print("foo", v_abcerr, "bar")') + ) + eq( + 'Vim(lua):E5108: Error executing lua E5114: Error while converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>', + pcall_err(command, 'lua print("foo", v_tblout, "bar")') + ) end) it('coerces error values into strings', function() - write_file(fname, [[ + write_file( + fname, + [[ function string_error() error("my mistake") end function number_error() error(1234) end function nil_error() error(nil) end @@ -82,27 +93,35 @@ describe('print', function() }) error(err) end - ]]) + ]] + ) eq('', exec_capture('luafile ' .. fname)) - eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake', - pcall_err(command, 'lua string_error()')) - eq('Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234', - pcall_err(command, 'lua number_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua nil_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua table_error()')) - eq('Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake', - pcall_err(command, 'lua custom_error()')) - eq('Vim(lua):E5108: Error executing lua [NULL]', - pcall_err(command, 'lua bad_custom_error()')) + eq( + 'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:1: my mistake', + pcall_err(command, 'lua string_error()') + ) + eq( + 'Vim(lua):E5108: Error executing lua Xtest-functional-lua-overrides-luafile:2: 1234', + pcall_err(command, 'lua number_error()') + ) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua nil_error()')) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua table_error()')) + eq( + 'Vim(lua):E5108: Error executing lua Internal Error [11234] my mistake', + pcall_err(command, 'lua custom_error()') + ) + eq('Vim(lua):E5108: Error executing lua [NULL]', pcall_err(command, 'lua bad_custom_error()')) end) it('prints strings with NULs and NLs correctly', function() meths.set_option_value('more', true, {}) - eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', - exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]])) - eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', - exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]])) + eq( + 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', + exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]) + ) + eq( + 'abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', + exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\0")]]) + ) eq('T^@', exec_capture([[lua print("T\0")]])) eq('T\n', exec_capture([[lua print("T\n")]])) end) @@ -114,7 +133,8 @@ describe('print', function() eq('abc def', exec_capture('lua print("abc", "", "def")')) end) it('defers printing in luv event handlers', function() - exec_lua([[ + exec_lua( + [[ local cmd = ... function test() local timer = vim.uv.new_timer() @@ -133,7 +153,9 @@ describe('print', function() print("very slow") vim.api.nvim_command("sleep 1m") -- force deferred event processing end - ]], (is_os('win') and "timeout 1") or "sleep 0.1") + ]], + (is_os('win') and 'timeout 1') or 'sleep 0.1' + ) eq('very slow\nvery fast', exec_capture('lua test()')) end) @@ -141,22 +163,25 @@ describe('print', function() local screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ - [0] = {bold = true, foreground=Screen.colors.Blue}, - [1] = {bold = true, foreground = Screen.colors.SeaGreen}, - [2] = {bold = true, reverse = true}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, foreground = Screen.colors.SeaGreen }, + [2] = { bold = true, reverse = true }, }) feed([[:lua print('\na')<CR>]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*3 {2: }| | a | {1:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('<CR>') feed([[:lua print('b\n\nc')<CR>]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 {2: }| @@ -164,7 +189,8 @@ describe('print', function() | c | {1:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) end) @@ -175,10 +201,10 @@ describe('debug.debug', function() screen = Screen.new() screen:attach() screen:set_default_attr_ids { - [0] = {bold=true, foreground=255}; - [1] = {bold = true, reverse = true}; - E = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}; - cr = {bold = true, foreground = Screen.colors.SeaGreen4}; + [0] = { bold = true, foreground = 255 }, + [1] = { bold = true, reverse = true }, + E = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + cr = { bold = true, foreground = Screen.colors.SeaGreen4 }, } end) @@ -191,13 +217,15 @@ describe('debug.debug', function() end ]]) feed(':lua Test()\n') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*10 {1: }| nil | lua_debug> ^ | - ]]} + ]], + } feed('print("TEST")\n') screen:expect([[ | @@ -209,7 +237,8 @@ describe('debug.debug', function() lua_debug> ^ | ]]) feed('<C-c>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*2 {1: }| @@ -223,7 +252,8 @@ describe('debug.debug', function() {E: [string ":lua"]:5: in function 'Test'} | {E: [string ":lua"]:1: in main chunk} | Interrupt: {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('<C-l>:lua Test()\n') screen:expect([[ | @@ -233,7 +263,8 @@ describe('debug.debug', function() lua_debug> ^ | ]]) feed('\n') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*4 {1: }| @@ -245,20 +276,24 @@ describe('debug.debug', function() {E: [string ":lua"]:5: in function 'Test'} | {E: [string ":lua"]:1: in main chunk} | {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) it("can be safely exited with 'cont'", function() feed('<cr>') feed(':lua debug.debug() print("x")<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*12 lua_debug> ^ | - ]]} + ]], + } - feed("conttt<cr>") -- misspelled cont; invalid syntax - screen:expect{grid=[[ + feed('conttt<cr>') -- misspelled cont; invalid syntax + screen:expect { + grid = [[ | {0:~ }|*8 {1: }| @@ -266,10 +301,12 @@ describe('debug.debug', function() {E:E5115: Error while loading debug string: (debug comma}| {E:nd):1: '=' expected near '<eof>'} | lua_debug> ^ | - ]]} + ]], + } - feed("cont<cr>") -- exactly "cont", exit now - screen:expect{grid=[[ + feed('cont<cr>') -- exactly "cont", exit now + screen:expect { + grid = [[ | {0:~ }|*6 {1: }| @@ -279,14 +316,17 @@ describe('debug.debug', function() lua_debug> cont | x | {cr:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('<cr>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*12 | - ]]} + ]], + } end) end) @@ -296,12 +336,12 @@ describe('os.getenv', function() end) it('returns env var set by the parent process', function() local value = 'foo' - clear({env = {['XTEST_1']=value}}) + clear({ env = { ['XTEST_1'] = value } }) eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) it('returns env var set by let', function() local value = 'foo' - meths.command('let $XTEST_1 = "'..value..'"') + meths.command('let $XTEST_1 = "' .. value .. '"') eq(value, funcs.luaeval('os.getenv("XTEST_1")')) end) end) @@ -310,6 +350,6 @@ end) -- luajit or PUC lua 5.1. describe('bit module', function() it('works', function() - eq (9, exec_lua [[ return require'bit'.band(11,13) ]]) + eq(9, exec_lua [[ return require'bit'.band(11,13) ]]) end) end) diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua index 0b8b2234db..84948490ae 100644 --- a/test/functional/lua/runtime_spec.lua +++ b/test/functional/lua/runtime_spec.lua @@ -15,8 +15,8 @@ describe('runtime:', function() local init = 'dummy_init.lua' setup(function() - io.open(init, 'w'):close() -- touch init file - clear{args = {'-u', init}} + io.open(init, 'w'):close() -- touch init file + clear { args = { '-u', init } } exec('set rtp+=' .. plug_dir) exec([[ set shell=doesnotexist @@ -45,11 +45,11 @@ describe('runtime:', function() end) it('lua colorschemes work and are included in cmdline completion', function() - local colorscheme_file = table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep) + local colorscheme_file = table.concat({ colorscheme_folder, 'new_colorscheme.lua' }, sep) write_file(colorscheme_file, [[vim.g.lua_colorscheme = 1]]) - eq({'new_colorscheme'}, funcs.getcompletion('new_c', 'color')) - eq({'colors/new_colorscheme.lua'}, funcs.getcompletion('colors/new_c', 'runtime')) + eq({ 'new_colorscheme' }, funcs.getcompletion('new_c', 'color')) + eq({ 'colors/new_colorscheme.lua' }, funcs.getcompletion('colors/new_c', 'runtime')) exec('colorscheme new_colorscheme') @@ -64,48 +64,60 @@ describe('runtime:', function() end) exec('set pp+=' .. pack_dir) - local pack_opt_dir = table.concat({pack_dir, 'pack', 'some_name', 'opt'}, sep) - local colors_opt_dir = table.concat({pack_opt_dir, 'some_pack', 'colors'}, sep) + local pack_opt_dir = table.concat({ pack_dir, 'pack', 'some_name', 'opt' }, sep) + local colors_opt_dir = table.concat({ pack_opt_dir, 'some_pack', 'colors' }, sep) mkdir_p(colors_opt_dir) - local after_colorscheme_folder = table.concat({plug_dir, 'after', 'colors'}, sep) + local after_colorscheme_folder = table.concat({ plug_dir, 'after', 'colors' }, sep) mkdir_p(after_colorscheme_folder) exec('set rtp+=' .. plug_dir .. '/after') - write_file(table.concat({colors_opt_dir, 'new_colorscheme.lua'}, sep), - [[vim.g.colorscheme = 'lua_pp']]) + write_file( + table.concat({ colors_opt_dir, 'new_colorscheme.lua' }, sep), + [[vim.g.colorscheme = 'lua_pp']] + ) exec('colorscheme new_colorscheme') eq('lua_pp', eval('g:colorscheme')) - write_file(table.concat({colors_opt_dir, 'new_colorscheme.vim'}, sep), - [[let g:colorscheme = 'vim_pp']]) + write_file( + table.concat({ colors_opt_dir, 'new_colorscheme.vim' }, sep), + [[let g:colorscheme = 'vim_pp']] + ) exec('colorscheme new_colorscheme') eq('vim_pp', eval('g:colorscheme')) - write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.lua'}, sep), - [[vim.g.colorscheme = 'lua_rtp_after']]) + write_file( + table.concat({ after_colorscheme_folder, 'new_colorscheme.lua' }, sep), + [[vim.g.colorscheme = 'lua_rtp_after']] + ) exec('colorscheme new_colorscheme') eq('lua_rtp_after', eval('g:colorscheme')) - write_file(table.concat({after_colorscheme_folder, 'new_colorscheme.vim'}, sep), - [[let g:colorscheme = 'vim_rtp_after']]) + write_file( + table.concat({ after_colorscheme_folder, 'new_colorscheme.vim' }, sep), + [[let g:colorscheme = 'vim_rtp_after']] + ) exec('colorscheme new_colorscheme') eq('vim_rtp_after', eval('g:colorscheme')) - write_file(table.concat({colorscheme_folder, 'new_colorscheme.lua'}, sep), - [[vim.g.colorscheme = 'lua_rtp']]) + write_file( + table.concat({ colorscheme_folder, 'new_colorscheme.lua' }, sep), + [[vim.g.colorscheme = 'lua_rtp']] + ) exec('colorscheme new_colorscheme') eq('lua_rtp', eval('g:colorscheme')) - write_file(table.concat({colorscheme_folder, 'new_colorscheme.vim'}, sep), - [[let g:colorscheme = 'vim_rtp']]) + write_file( + table.concat({ colorscheme_folder, 'new_colorscheme.vim' }, sep), + [[let g:colorscheme = 'vim_rtp']] + ) exec('colorscheme new_colorscheme') eq('vim_rtp', eval('g:colorscheme')) end) end) describe('compiler', function() - local compiler_folder = table.concat({plug_dir, 'compiler'}, sep) + local compiler_folder = table.concat({ plug_dir, 'compiler' }, sep) before_each(function() mkdir_p(compiler_folder) end) @@ -114,8 +126,8 @@ describe('runtime:', function() local compiler_file = compiler_folder .. sep .. 'new_compiler.lua' write_file(compiler_file, [[vim.b.lua_compiler = 1]]) - eq({'new_compiler'}, funcs.getcompletion('new_c', 'compiler')) - eq({'compiler/new_compiler.lua'}, funcs.getcompletion('compiler/new_c', 'runtime')) + eq({ 'new_compiler' }, funcs.getcompletion('new_c', 'compiler')) + eq({ 'compiler/new_compiler.lua' }, funcs.getcompletion('compiler/new_c', 'runtime')) exec('compiler new_compiler') @@ -123,126 +135,189 @@ describe('runtime:', function() end) it("'rtp' order is respected", function() - local after_compiler_folder = table.concat({plug_dir, 'after', 'compiler'}, sep) - mkdir_p(table.concat({compiler_folder, 'new_compiler'}, sep)) - mkdir_p(table.concat({after_compiler_folder, 'new_compiler'}, sep)) + local after_compiler_folder = table.concat({ plug_dir, 'after', 'compiler' }, sep) + mkdir_p(table.concat({ compiler_folder, 'new_compiler' }, sep)) + mkdir_p(table.concat({ after_compiler_folder, 'new_compiler' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/compiler/ are loaded after all files in compiler/. - write_file(table.concat({compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({after_compiler_folder, 'new_compiler.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_compiler_folder, 'new_compiler.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) + write_file(table.concat({ compiler_folder, 'new_compiler.vim' }, sep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ compiler_folder, 'new_compiler.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'B']] + ) + write_file( + table.concat({ after_compiler_folder, 'new_compiler.vim' }, sep), + [[let g:seq ..= 'a']] + ) + write_file( + table.concat({ after_compiler_folder, 'new_compiler.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) exec('compiler new_compiler') eq('ABab', eval('g:seq')) end) end) describe('ftplugin', function() - local ftplugin_folder = table.concat({plug_dir, 'ftplugin'}, sep) + local ftplugin_folder = table.concat({ plug_dir, 'ftplugin' }, sep) it('lua ftplugins work and are included in cmdline completion', function() mkdir_p(ftplugin_folder) - local ftplugin_file = table.concat({ftplugin_folder , 'new-ft.lua'}, sep) - write_file(ftplugin_file , [[vim.b.lua_ftplugin = 1]]) + local ftplugin_file = table.concat({ ftplugin_folder, 'new-ft.lua' }, sep) + write_file(ftplugin_file, [[vim.b.lua_ftplugin = 1]]) - eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype')) - eq({'ftplugin/new-ft.lua'}, funcs.getcompletion('ftplugin/new-f', 'runtime')) + eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype')) + eq({ 'ftplugin/new-ft.lua' }, funcs.getcompletion('ftplugin/new-f', 'runtime')) exec [[set filetype=new-ft]] eq(1, eval('b:lua_ftplugin')) end) it("'rtp' order is respected", function() - local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep) - mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep)) - mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep)) + local after_ftplugin_folder = table.concat({ plug_dir, 'after', 'ftplugin' }, sep) + mkdir_p(table.concat({ ftplugin_folder, 'new-ft' }, sep)) + mkdir_p(table.concat({ after_ftplugin_folder, 'new-ft' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/ftplugin/ are loaded after all files in ftplugin/. - write_file(table.concat({ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']]) - write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']]) - write_file(table.concat({ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'E']]) - write_file(table.concat({ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'F']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'c']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']]) + write_file(table.concat({ ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'B']] + ) + write_file(table.concat({ ftplugin_folder, 'new-ft_a.vim' }, sep), [[let g:seq ..= 'C']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft_a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'D']] + ) + write_file(table.concat({ ftplugin_folder, 'new-ft', 'a.vim' }, sep), [[let g:seq ..= 'E']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft', 'a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'F']] + ) + write_file(table.concat({ after_ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']]) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft_a.vim' }, sep), + [[let g:seq ..= 'c']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft_a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'd']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft', 'a.vim' }, sep), + [[let g:seq ..= 'e']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft', 'a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'f']] + ) exec('setfiletype new-ft') eq('ABCDEFabcdef', eval('g:seq')) end) it("'rtp' order is respected with 'fileignorecase'", function() exec('set fileignorecase') - local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep) - mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep)) - mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep)) + local after_ftplugin_folder = table.concat({ plug_dir, 'after', 'ftplugin' }, sep) + mkdir_p(table.concat({ ftplugin_folder, 'new-ft' }, sep)) + mkdir_p(table.concat({ after_ftplugin_folder, 'new-ft' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/ftplugin/ are loaded after all files in ftplugin/. - write_file(table.concat({ftplugin_folder, 'new-ft.VIM'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({ftplugin_folder, 'new-ft.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']]) - write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']]) - write_file(table.concat({ftplugin_folder, 'new-ft', 'a.VIM'}, sep), [[let g:seq ..= 'E']]) - write_file(table.concat({ftplugin_folder, 'new-ft', 'a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'F']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft_a.VIM'}, sep), [[let g:seq ..= 'c']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft_a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'd']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']]) - write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']]) + write_file(table.concat({ ftplugin_folder, 'new-ft.VIM' }, sep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft.LUA' }, sep), + [[vim.g.seq = vim.g.seq .. 'B']] + ) + write_file(table.concat({ ftplugin_folder, 'new-ft_a.vim' }, sep), [[let g:seq ..= 'C']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft_a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'D']] + ) + write_file(table.concat({ ftplugin_folder, 'new-ft', 'a.VIM' }, sep), [[let g:seq ..= 'E']]) + write_file( + table.concat({ ftplugin_folder, 'new-ft', 'a.LUA' }, sep), + [[vim.g.seq = vim.g.seq .. 'F']] + ) + write_file(table.concat({ after_ftplugin_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']]) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft_a.VIM' }, sep), + [[let g:seq ..= 'c']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft_a.LUA' }, sep), + [[vim.g.seq = vim.g.seq .. 'd']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft', 'a.vim' }, sep), + [[let g:seq ..= 'e']] + ) + write_file( + table.concat({ after_ftplugin_folder, 'new-ft', 'a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'f']] + ) exec('setfiletype new-ft') eq('ABCDEFabcdef', eval('g:seq')) end) end) describe('indent', function() - local indent_folder = table.concat({plug_dir, 'indent'}, sep) + local indent_folder = table.concat({ plug_dir, 'indent' }, sep) it('lua indents work and are included in cmdline completion', function() mkdir_p(indent_folder) - local indent_file = table.concat({indent_folder , 'new-ft.lua'}, sep) - write_file(indent_file , [[vim.b.lua_indent = 1]]) + local indent_file = table.concat({ indent_folder, 'new-ft.lua' }, sep) + write_file(indent_file, [[vim.b.lua_indent = 1]]) - eq({'new-ft'}, funcs.getcompletion('new-f', 'filetype')) - eq({'indent/new-ft.lua'}, funcs.getcompletion('indent/new-f', 'runtime')) + eq({ 'new-ft' }, funcs.getcompletion('new-f', 'filetype')) + eq({ 'indent/new-ft.lua' }, funcs.getcompletion('indent/new-f', 'runtime')) exec [[set filetype=new-ft]] eq(1, eval('b:lua_indent')) end) it("'rtp' order is respected", function() - local after_indent_folder = table.concat({plug_dir, 'after', 'indent'}, sep) - mkdir_p(table.concat({indent_folder, 'new-ft'}, sep)) - mkdir_p(table.concat({after_indent_folder, 'new-ft'}, sep)) + local after_indent_folder = table.concat({ plug_dir, 'after', 'indent' }, sep) + mkdir_p(table.concat({ indent_folder, 'new-ft' }, sep)) + mkdir_p(table.concat({ after_indent_folder, 'new-ft' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/indent/ are loaded after all files in indent/. - write_file(table.concat({indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({after_indent_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_indent_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) + write_file(table.concat({ indent_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ indent_folder, 'new-ft.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'B']] + ) + write_file(table.concat({ after_indent_folder, 'new-ft.vim' }, sep), [[let g:seq ..= 'a']]) + write_file( + table.concat({ after_indent_folder, 'new-ft.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) exec('setfiletype new-ft') eq('ABab', eval('g:seq')) end) end) describe('syntax', function() - local syntax_folder = table.concat({plug_dir, 'syntax'}, sep) + local syntax_folder = table.concat({ plug_dir, 'syntax' }, sep) before_each(function() mkdir_p(syntax_folder) - local syntax_file = table.concat({syntax_folder , 'my-lang.lua'}, sep) - write_file(syntax_file , [[vim.b.current_syntax = 'my-lang']]) + local syntax_file = table.concat({ syntax_folder, 'my-lang.lua' }, sep) + write_file(syntax_file, [[vim.b.current_syntax = 'my-lang']]) exec([[let b:current_syntax = '']]) end) @@ -263,27 +338,42 @@ describe('runtime:', function() end) it('lua syntaxes are included in cmdline completion', function() - eq({'my-lang'}, funcs.getcompletion('my-l', 'filetype')) - eq({'my-lang'}, funcs.getcompletion('my-l', 'syntax')) - eq({'syntax/my-lang.lua'}, funcs.getcompletion('syntax/my-l', 'runtime')) + eq({ 'my-lang' }, funcs.getcompletion('my-l', 'filetype')) + eq({ 'my-lang' }, funcs.getcompletion('my-l', 'syntax')) + eq({ 'syntax/my-lang.lua' }, funcs.getcompletion('syntax/my-l', 'runtime')) end) it("'rtp' order is respected", function() - local after_syntax_folder = table.concat({plug_dir, 'after', 'syntax'}, sep) - mkdir_p(table.concat({syntax_folder, 'my-lang'}, sep)) - mkdir_p(table.concat({after_syntax_folder, 'my-lang'}, sep)) + local after_syntax_folder = table.concat({ plug_dir, 'after', 'syntax' }, sep) + mkdir_p(table.concat({ syntax_folder, 'my-lang' }, sep)) + mkdir_p(table.concat({ after_syntax_folder, 'my-lang' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/syntax/ are loaded after all files in syntax/. - write_file(table.concat({syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'C']]) - write_file(table.concat({syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']]) - write_file(table.concat({after_syntax_folder, 'my-lang.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_syntax_folder, 'my-lang.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) - write_file(table.concat({after_syntax_folder, 'my-lang', 'a.vim'}, sep), [[let g:seq ..= 'c']]) - write_file(table.concat({after_syntax_folder, 'my-lang', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'd']]) + write_file(table.concat({ syntax_folder, 'my-lang.vim' }, sep), [[let g:seq ..= 'A']]) + write_file( + table.concat({ syntax_folder, 'my-lang.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'B']] + ) + write_file(table.concat({ syntax_folder, 'my-lang', 'a.vim' }, sep), [[let g:seq ..= 'C']]) + write_file( + table.concat({ syntax_folder, 'my-lang', 'a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'D']] + ) + write_file(table.concat({ after_syntax_folder, 'my-lang.vim' }, sep), [[let g:seq ..= 'a']]) + write_file( + table.concat({ after_syntax_folder, 'my-lang.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) + write_file( + table.concat({ after_syntax_folder, 'my-lang', 'a.vim' }, sep), + [[let g:seq ..= 'c']] + ) + write_file( + table.concat({ after_syntax_folder, 'my-lang', 'a.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'd']] + ) exec('setfiletype my-lang') eq('ABCDabcd', eval('g:seq')) end) @@ -291,21 +381,23 @@ describe('runtime:', function() describe('spell', function() it("loads spell/LANG.{vim,lua} respecting 'rtp' order", function() - local spell_folder = table.concat({plug_dir, 'spell'}, sep) - local after_spell_folder = table.concat({plug_dir, 'after', 'spell'}, sep) - mkdir_p(table.concat({spell_folder, 'Xtest'}, sep)) - mkdir_p(table.concat({after_spell_folder, 'Xtest'}, sep)) + local spell_folder = table.concat({ plug_dir, 'spell' }, sep) + local after_spell_folder = table.concat({ plug_dir, 'after', 'spell' }, sep) + mkdir_p(table.concat({ spell_folder, 'Xtest' }, sep)) + mkdir_p(table.concat({ after_spell_folder, 'Xtest' }, sep)) exec('set rtp+=' .. plug_dir .. '/after') exec('let g:seq = ""') -- A .lua file is loaded after a .vim file if they only differ in extension. -- All files in after/spell/ are loaded after all files in spell/. - write_file(table.concat({spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'A']]) - write_file(table.concat({spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'B']]) - write_file(table.concat({after_spell_folder, 'Xtest.vim'}, sep), [[let g:seq ..= 'a']]) - write_file(table.concat({after_spell_folder, 'Xtest.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']]) + write_file(table.concat({ spell_folder, 'Xtest.vim' }, sep), [[let g:seq ..= 'A']]) + write_file(table.concat({ spell_folder, 'Xtest.lua' }, sep), [[vim.g.seq = vim.g.seq .. 'B']]) + write_file(table.concat({ after_spell_folder, 'Xtest.vim' }, sep), [[let g:seq ..= 'a']]) + write_file( + table.concat({ after_spell_folder, 'Xtest.lua' }, sep), + [[vim.g.seq = vim.g.seq .. 'b']] + ) exec('set spelllang=Xtest') eq('ABab', eval('g:seq')) end) end) - end) diff --git a/test/functional/lua/secure_spec.lua b/test/functional/lua/secure_spec.lua index c59d3f3cda..52770867a8 100644 --- a/test/functional/lua/secure_spec.lua +++ b/test/functional/lua/secure_spec.lua @@ -19,11 +19,14 @@ describe('vim.secure', function() local xstate = 'Xstate' setup(function() - clear{env={XDG_STATE_HOME=xstate}} + clear { env = { XDG_STATE_HOME = xstate } } helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) - helpers.write_file('Xfile', [[ + helpers.write_file( + 'Xfile', + [[ let g:foobar = 42 - ]]) + ]] + ) end) teardown(function() @@ -35,10 +38,10 @@ describe('vim.secure', function() local screen = Screen.new(80, 8) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen}, - [4] = {reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen }, + [4] = { reverse = true }, }) --- XXX: screen:expect() may fail if this path is too long. @@ -46,20 +49,27 @@ describe('vim.secure', function() -- Need to use feed_command instead of exec_lua because of the confirmation prompt feed_command([[lua vim.secure.read('Xfile')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*3 {2: }| :lua vim.secure.read('Xfile') | - {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}| + {3:]] + .. cwd + .. pathsep + .. [[Xfile is not trusted.}{MATCH:%s+}| {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | - ]]} + ]], + } feed('d') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*6 | - ]]} + ]], + } local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'Xfile'), vim.trim(trust)) @@ -68,20 +78,27 @@ describe('vim.secure', function() os.remove(funcs.stdpath('state') .. pathsep .. 'trust') feed_command([[lua vim.secure.read('Xfile')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*3 {2: }| :lua vim.secure.read('Xfile') | - {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}| + {3:]] + .. cwd + .. pathsep + .. [[Xfile is not trusted.}{MATCH:%s+}| {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | - ]]} + ]], + } feed('a') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*6 | - ]]} + ]], + } local hash = funcs.sha256(helpers.read_file('Xfile')) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') @@ -91,44 +108,61 @@ describe('vim.secure', function() os.remove(funcs.stdpath('state') .. pathsep .. 'trust') feed_command([[lua vim.secure.read('Xfile')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*3 {2: }| :lua vim.secure.read('Xfile') | - {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}| + {3:]] + .. cwd + .. pathsep + .. [[Xfile is not trusted.}{MATCH:%s+}| {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | - ]]} + ]], + } feed('i') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*6 | - ]]} + ]], + } -- Trust database is not updated trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(nil, trust) feed_command([[lua vim.secure.read('Xfile')]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ | {1:~ }|*3 {2: }| :lua vim.secure.read('Xfile') | - {3:]] .. cwd .. pathsep .. [[Xfile is not trusted.}{MATCH:%s+}| + {3:]] + .. cwd + .. pathsep + .. [[Xfile is not trusted.}{MATCH:%s+}| {3:[i]gnore, (v)iew, (d)eny, (a)llow: }^ | - ]]} + ]], + } feed('v') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^let g:foobar = 42 | {1:~ }|*2 - {2:]] .. funcs.fnamemodify(cwd, ':~') .. pathsep .. [[Xfile [RO]{MATCH:%s+}}| + {2:]] + .. funcs.fnamemodify(cwd, ':~') + .. pathsep + .. [[Xfile [RO]{MATCH:%s+}}| | {1:~ }| {4:[No Name] }| | - ]]} + ]], + } -- Trust database is not updated trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') @@ -144,7 +178,7 @@ describe('vim.secure', function() local xstate = 'Xstate' setup(function() - clear{env={XDG_STATE_HOME=xstate}} + clear { env = { XDG_STATE_HOME = xstate } } helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim')) end) @@ -161,13 +195,17 @@ describe('vim.secure', function() end) it('returns error when passing both path and bufnr', function() - matches('"path" and "bufnr" are mutually exclusive', - pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]])) + matches( + '"path" and "bufnr" are mutually exclusive', + pcall_err(exec_lua, [[vim.secure.trust({action='deny', bufnr=0, path='test_file'})]]) + ) end) it('returns error when passing neither path or bufnr', function() - matches('one of "path" or "bufnr" is required', - pcall_err(exec_lua, [[vim.secure.trust({action='deny'})]])) + matches( + 'one of "path" or "bufnr" is required', + pcall_err(exec_lua, [[vim.secure.trust({action='deny'})]]) + ) end) it('trust then deny then remove a file using bufnr', function() @@ -176,15 +214,15 @@ describe('vim.secure', function() local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) @@ -195,15 +233,15 @@ describe('vim.secure', function() local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='deny', bufnr=0})}]])) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='remove', bufnr=0})}]])) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) @@ -214,15 +252,21 @@ describe('vim.secure', function() local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])) + eq( + { true, full_path }, + exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) + ) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])) + eq( + { true, full_path }, + exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) + ) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) @@ -233,23 +277,31 @@ describe('vim.secure', function() local full_path = cwd .. pathsep .. 'test_file' command('edit test_file') - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]])) + eq( + { true, full_path }, + exec_lua([[return {vim.secure.trust({action='deny', path='test_file'})}]]) + ) local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + eq({ true, full_path }, exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, full_path), vim.trim(trust)) - eq({true, full_path}, exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]])) + eq( + { true, full_path }, + exec_lua([[return {vim.secure.trust({action='remove', path='test_file'})}]]) + ) trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') eq('', vim.trim(trust)) end) it('trust returns error when buffer not associated to file', function() command('new') - eq({false, 'buffer is not associated with a file'}, - exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]])) + eq( + { false, 'buffer is not associated with a file' }, + exec_lua([[return {vim.secure.trust({action='allow', bufnr=0})}]]) + ) end) end) end) diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index f0b3b44139..defd13429e 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -154,7 +154,10 @@ describe('vim.snippet', function() end) it('errors with multiple placeholders for the same index', function() - test_expand_fail('class ${1:Foo} { void ${1:foo}() {} }', 'multiple placeholders for tabstop $1') + test_expand_fail( + 'class ${1:Foo} { void ${1:foo}() {} }', + 'multiple placeholders for tabstop $1' + ) end) it('errors with multiple $0 tabstops', function() @@ -162,26 +165,32 @@ describe('vim.snippet', function() end) it('cancels session when deleting the snippet', function() - test_expand_success({ 'local function $1()', ' $0', 'end' }, { 'local function ()', ' ', 'end' }) + test_expand_success( + { 'local function $1()', ' $0', 'end' }, + { 'local function ()', ' ', 'end' } + ) feed('<esc>Vjjd') eq(false, exec_lua('return vim.snippet.active()')) end) it('cancels session when inserting outside snippet region', function() feed('i<cr>') - test_expand_success({ 'local function $1()', ' $0', 'end' }, { '', 'local function ()', ' ', 'end' }) + test_expand_success( + { 'local function $1()', ' $0', 'end' }, + { '', 'local function ()', ' ', 'end' } + ) feed('<esc>O-- A comment') eq(false, exec_lua('return vim.snippet.active()')) end) - it('inserts choice', function () + it('inserts choice', function() test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' }) sleep(100) feed('<Down><C-y>') eq({ 'console.log()' }, buf_lines(0)) end) - it('closes the choice completion menu when jumping', function () + it('closes the choice completion menu when jumping', function() test_expand_success({ 'console.${1|assert,log,error|}($2)' }, { 'console.()' }) sleep(100) exec_lua('vim.snippet.jump(1)') diff --git a/test/functional/lua/spell_spec.lua b/test/functional/lua/spell_spec.lua index b3de6a0912..e82dd7b4a0 100644 --- a/test/functional/lua/spell_spec.lua +++ b/test/functional/lua/spell_spec.lua @@ -11,43 +11,32 @@ describe('vim.spell', function() describe('.check', function() local check = function(x, exp) - return eq(exp, exec_lua("return vim.spell.check(...)", x)) + return eq(exp, exec_lua('return vim.spell.check(...)', x)) end it('can handle nil', function() - eq([[bad argument #1 to 'check' (expected string)]], - pcall_err(exec_lua, [[vim.spell.check(nil)]])) + eq( + [[bad argument #1 to 'check' (expected string)]], + pcall_err(exec_lua, [[vim.spell.check(nil)]]) + ) end) it('can check spellings', function() check('hello', {}) - check( - 'helloi', - {{"helloi", "bad", 1}} - ) + check('helloi', { { 'helloi', 'bad', 1 } }) - check( - 'hello therei', - {{"therei", "bad", 7}} - ) + check('hello therei', { { 'therei', 'bad', 7 } }) - check( - 'hello. there', - {{"there", "caps", 8}} - ) + check('hello. there', { { 'there', 'caps', 8 } }) - check( - 'neovim cna chkc spellins. okay?', - { - {"neovim" , "bad" , 1}, - {"cna" , "bad" , 8}, - {"chkc" , "bad" , 12}, - {"spellins", "bad" , 17}, - {"okay" , "caps", 27} - } - ) + check('neovim cna chkc spellins. okay?', { + { 'neovim', 'bad', 1 }, + { 'cna', 'bad', 8 }, + { 'chkc', 'bad', 12 }, + { 'spellins', 'bad', 17 }, + { 'okay', 'caps', 27 }, + }) end) - end) end) diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua index a988d3f0d7..bae8322b43 100644 --- a/test/functional/lua/system_spec.lua +++ b/test/functional/lua/system_spec.lua @@ -4,7 +4,8 @@ local exec_lua = helpers.exec_lua local eq = helpers.eq local function system_sync(cmd, opts) - return exec_lua([[ + return exec_lua( + [[ local cmd, opts = ... local obj = vim.system(...) @@ -21,11 +22,15 @@ local function system_sync(cmd, opts) assert(not proc, 'process still exists') return res - ]], cmd, opts) + ]], + cmd, + opts + ) end local function system_async(cmd, opts) - return exec_lua([[ + return exec_lua( + [[ local cmd, opts = ... _G.done = false local obj = vim.system(cmd, opts, function(obj) @@ -44,7 +49,10 @@ local function system_async(cmd, opts) assert(not proc, 'process still exists') return _G.ret - ]], cmd, opts) + ]], + cmd, + opts + ) end describe('vim.system', function() @@ -52,10 +60,10 @@ describe('vim.system', function() clear() end) - for name, system in pairs{ sync = system_sync, async = system_async, } do - describe('('..name..')', function() + for name, system in pairs { sync = system_sync, async = system_async } do + describe('(' .. name .. ')', function() it('can run simple commands', function() - eq('hello\n', system({'echo', 'hello' }, { text = true }).stdout) + eq('hello\n', system({ 'echo', 'hello' }, { text = true }).stdout) end) it('handle input', function() @@ -67,7 +75,7 @@ describe('vim.system', function() code = 124, signal = 15, stdout = '', - stderr = '' + stderr = '', }, system({ 'sleep', '10' }, { timeout = 1000 })) end) end) @@ -96,5 +104,4 @@ describe('vim.system', function() assert(signal == 2) ]]) end) - end) diff --git a/test/functional/lua/text_spec.lua b/test/functional/lua/text_spec.lua index 68206557c3..e31aa63768 100644 --- a/test/functional/lua/text_spec.lua +++ b/test/functional/lua/text_spec.lua @@ -20,4 +20,3 @@ describe('vim.text', function() end) end) end) - diff --git a/test/functional/lua/thread_spec.lua b/test/functional/lua/thread_spec.lua index 23c0c42f07..0a7a7f0448 100644 --- a/test/functional/lua/thread_spec.lua +++ b/test/functional/lua/thread_spec.lua @@ -17,11 +17,11 @@ describe('thread', function() screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [5] = {bold = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [5] = { bold = true }, }) end) @@ -150,7 +150,7 @@ describe('thread', function() thread_test:do_test() ]] - eq({'notification', 'result', {true}}, next_msg()) + eq({ 'notification', 'result', { true } }, next_msg()) end) it('uv', function() @@ -182,7 +182,7 @@ describe('thread', function() thread_test:do_test() ]] - eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg()) + eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg()) end) it('json', function() @@ -197,7 +197,7 @@ describe('thread', function() thread_test:do_test() ]] - eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg()) + eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg()) end) it('diff', function() @@ -212,14 +212,18 @@ describe('thread', function() thread_test:do_test() ]] - eq({'notification', 'result', - {table.concat({ + eq({ + 'notification', + 'result', + { + table.concat({ '@@ -1 +1 @@', '-Hello', '+Helli', - '' - }, '\n')}}, - next_msg()) + '', + }, '\n'), + }, + }, next_msg()) end) end) end) @@ -241,28 +245,30 @@ describe('threadpool', function() work:queue() ]] - eq({'notification', 'result', {true}}, next_msg()) + eq({ 'notification', 'result', { true } }, next_msg()) end) it('with invalid argument', function() - local status = pcall_err(exec_lua, [[ + local status = pcall_err( + exec_lua, + [[ local work = vim.uv.new_thread(function() end, function() end) work:queue({}) - ]]) + ]] + ) - eq([[Error: thread arg not support type 'function' at 1]], - status) + eq([[Error: thread arg not support type 'function' at 1]], status) end) it('with invalid return value', function() local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [5] = {bold = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [5] = { bold = true }, }) exec_lua [[ @@ -338,7 +344,7 @@ describe('threadpool', function() threadpool_test:do_test() ]] - eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg()) + eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg()) end) it('json', function() @@ -354,7 +360,7 @@ describe('threadpool', function() threadpool_test:do_test() ]] - eq({'notification', 'result', {{33, NIL, 'text'}}}, next_msg()) + eq({ 'notification', 'result', { { 33, NIL, 'text' } } }, next_msg()) end) it('work', function() @@ -369,14 +375,18 @@ describe('threadpool', function() threadpool_test:do_test() ]] - eq({'notification', 'result', - {table.concat({ + eq({ + 'notification', + 'result', + { + table.concat({ '@@ -1 +1 @@', '-Hello', '+Helli', - '' - }, '\n')}}, - next_msg()) + '', + }, '\n'), + }, + }, next_msg()) end) end) end) diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 04ffeddc87..c0a0b3e762 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -5,7 +5,7 @@ local exec_lua = helpers.exec_lua local clear = helpers.clear local feed = helpers.feed local funcs = helpers.funcs -local inspect = require'vim.inspect' +local inspect = require 'vim.inspect' describe('vim.ui_attach', function() local screen @@ -26,54 +26,67 @@ describe('vim.ui_attach', function() end ]] - screen = Screen.new(40,5) + screen = Screen.new(40, 5) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}; - [2] = {bold = true}; - [3] = {background = Screen.colors.Grey}; - [4] = {background = Screen.colors.LightMagenta}; + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true }, + [3] = { background = Screen.colors.Grey }, + [4] = { background = Screen.colors.LightMagenta }, }) screen:attach() end) local function expect_events(expected) - local evs = exec_lua "return get_events(...)" + local evs = exec_lua 'return get_events(...)' eq(expected, evs, inspect(evs)) end it('can receive popupmenu events', function() exec_lua [[ vim.ui_attach(ns, {ext_popupmenu=true}, on_event) ]] feed('ifo') - screen:expect{grid=[[ + screen:expect { + grid = [[ fo^ | {1:~ }|*3 {2:-- INSERT --} | - ]]} + ]], + } - funcs.complete(1, {'food', 'foobar', 'foo'}) - screen:expect{grid=[[ + funcs.complete(1, { 'food', 'foobar', 'foo' }) + screen:expect { + grid = [[ food^ | {1:~ }|*3 {2:-- INSERT --} | - ]]} + ]], + } expect_events { - { "popupmenu_show", { { "food", "", "", "" }, { "foobar", "", "", "" }, { "foo", "", "", "" } }, 0, 0, 0, 1 }; + { + 'popupmenu_show', + { { 'food', '', '', '' }, { 'foobar', '', '', '' }, { 'foo', '', '', '' } }, + 0, + 0, + 0, + 1, + }, } feed '<c-n>' - screen:expect{grid=[[ + screen:expect { + grid = [[ foobar^ | {1:~ }|*3 {2:-- INSERT --} | - ]]} + ]], + } expect_events { - { "popupmenu_select", 1 }; + { 'popupmenu_select', 1 }, } feed '<c-y>' screen:expect_unchanged() expect_events { - { "popupmenu_hide" }; + { 'popupmenu_hide' }, } -- vim.ui_detach() stops events, and reenables builtin pum immediately @@ -82,26 +95,31 @@ describe('vim.ui_attach', function() vim.fn.complete(1, {'food', 'foobar', 'foo'}) ]] - screen:expect{grid=[[ + screen:expect { + grid = [[ food^ | {3:food }{1: }| {4:foobar }{1: }| {4:foo }{1: }| {2:-- INSERT --} | - ]]} - expect_events { + ]], } - + expect_events {} end) it('does not crash on exit', function() funcs.system({ helpers.nvim_prog, - '-u', 'NONE', - '-i', 'NONE', - '--cmd', [[ lua ns = vim.api.nvim_create_namespace 'testspace' ]], - '--cmd', [[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]], - '--cmd', 'quitall!', + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + [[ lua ns = vim.api.nvim_create_namespace 'testspace' ]], + '--cmd', + [[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]], + '--cmd', + 'quitall!', }) eq(0, helpers.eval('v:shell_error')) end) diff --git a/test/functional/lua/ui_spec.lua b/test/functional/lua/ui_spec.lua index d4c150c5f2..b3057068fe 100644 --- a/test/functional/lua/ui_spec.lua +++ b/test/functional/lua/ui_spec.lua @@ -16,7 +16,7 @@ describe('vim.ui', function() describe('select()', function() it('can select an item', function() - local result = exec_lua[[ + local result = exec_lua [[ local items = { { name = 'Item 1' }, { name = 'Item 2' }, @@ -51,7 +51,7 @@ describe('vim.ui', function() describe('input()', function() it('can input text', function() - local result = exec_lua[[ + local result = exec_lua [[ local opts = { prompt = 'Input: ', } @@ -117,38 +117,44 @@ describe('vim.ui', function() it('can return nil when interrupted with Ctrl-C #18144', function() feed(':lua result = "on_confirm not called"<cr>') feed(':lua vim.ui.input({}, function(input) result = input end)<cr>') - poke_eventloop() -- This is needed because Ctrl-C flushes input + poke_eventloop() -- This is needed because Ctrl-C flushes input feed('Inputted Text<c-c>') eq(true, exec_lua('return (nil == result)')) end) - it('can return the identical object when an arbitrary opts.cancelreturn object is given', function() - feed(':lua fn = function() return 42 end<CR>') - eq(42, exec_lua('return fn()')) - feed(':lua vim.ui.input({ cancelreturn = fn }, function(input) result = input end)<cr>') - feed('cancel<esc>') - eq(true, exec_lua('return (result == fn)')) - eq(42, exec_lua('return result()')) - end) - + it( + 'can return the identical object when an arbitrary opts.cancelreturn object is given', + function() + feed(':lua fn = function() return 42 end<CR>') + eq(42, exec_lua('return fn()')) + feed(':lua vim.ui.input({ cancelreturn = fn }, function(input) result = input end)<cr>') + feed('cancel<esc>') + eq(true, exec_lua('return (result == fn)')) + eq(42, exec_lua('return result()')) + end + ) end) describe('open()', function() it('validation', function() if is_os('win') or not is_ci('github') then - exec_lua[[vim.system = function() return { wait=function() return { code=3} end } end]] + exec_lua [[vim.system = function() return { wait=function() return { code=3} end } end]] end if not is_os('bsd') then - matches('vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }', - exec_lua[[local _, err = vim.ui.open('non-existent-file') ; return err]]) + matches( + 'vim.ui.open: command failed %(%d%): { "[^"]+", .*"non%-existent%-file" }', + exec_lua [[local _, err = vim.ui.open('non-existent-file') ; return err]] + ) end - exec_lua[[ + exec_lua [[ vim.fn.has = function() return 0 end vim.fn.executable = function() return 0 end ]] - eq('vim.ui.open: no handler found (tried: wslview, xdg-open)', - exec_lua[[local _, err = vim.ui.open('foo') ; return err]]) + eq( + 'vim.ui.open: no handler found (tried: wslview, xdg-open)', + exec_lua [[local _, err = vim.ui.open('foo') ; return err]] + ) end) end) end) diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 416e9e1f02..e238bc8a82 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -16,20 +16,23 @@ describe('URI methods', function() it('file path includes only ascii characters', function() exec_lua("filepath = '/Foo/Bar/Baz.txt'") - eq('file:///Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq('file:///Foo/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)')) end) it('file path including white space', function() exec_lua("filepath = '/Foo /Bar/Baz.txt'") - eq('file:///Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq('file:///Foo%20/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)')) end) it('file path including Unicode characters', function() exec_lua("filepath = '/xy/åäö/ɧ/汉语/↥/🤦/🦄/å/بِيَّ.txt'") -- The URI encoding should be case-insensitive - eq('file:///xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq( + 'file:///xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', + exec_lua('return vim.uri_from_fname(filepath)') + ) end) end) @@ -37,19 +40,22 @@ describe('URI methods', function() it('file path includes only ascii characters', function() exec_lua([[filepath = 'C:\\Foo\\Bar\\Baz.txt']]) - eq('file:///C:/Foo/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq('file:///C:/Foo/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)')) end) it('file path including white space', function() exec_lua([[filepath = 'C:\\Foo \\Bar\\Baz.txt']]) - eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq('file:///C:/Foo%20/Bar/Baz.txt', exec_lua('return vim.uri_from_fname(filepath)')) end) it('file path including Unicode characters', function() exec_lua([[filepath = 'C:\\xy\\åäö\\ɧ\\汉语\\↥\\🤦\\🦄\\å\\بِيَّ.txt']]) - eq('file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', exec_lua("return vim.uri_from_fname(filepath)")) + eq( + 'file:///C:/xy/%c3%a5%c3%a4%c3%b6/%c9%a7/%e6%b1%89%e8%af%ad/%e2%86%a5/%f0%9f%a4%a6/%f0%9f%a6%84/a%cc%8a/%d8%a8%d9%90%d9%8a%d9%8e%d9%91.txt', + exec_lua('return vim.uri_from_fname(filepath)') + ) end) end) end) @@ -59,19 +65,19 @@ describe('URI methods', function() it('file path includes only ascii characters', function() exec_lua("uri = 'file:///Foo/Bar/Baz.txt'") - eq('/Foo/Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)")) + eq('/Foo/Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)')) end) it('local file path without hostname', function() exec_lua("uri = 'file:/Foo/Bar/Baz.txt'") - eq('/Foo/Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)")) + eq('/Foo/Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)')) end) it('file path including white space', function() exec_lua("uri = 'file:///Foo%20/Bar/Baz.txt'") - eq('/Foo /Bar/Baz.txt', exec_lua("return vim.uri_to_fname(uri)")) + eq('/Foo /Bar/Baz.txt', exec_lua('return vim.uri_to_fname(uri)')) end) it('file path including Unicode characters', function() @@ -133,73 +139,100 @@ describe('URI methods', function() describe('decode non-file URI', function() it('uri_to_fname returns non-file URI unchanged', function() - eq('jdt1.23+x-z://content/%5C/', exec_lua [[ + eq( + 'jdt1.23+x-z://content/%5C/', + exec_lua [[ return vim.uri_to_fname('jdt1.23+x-z://content/%5C/') - ]]) + ]] + ) end) it('uri_to_fname returns non-file upper-case scheme URI unchanged', function() - eq('JDT://content/%5C/', exec_lua [[ + eq( + 'JDT://content/%5C/', + exec_lua [[ return vim.uri_to_fname('JDT://content/%5C/') - ]]) + ]] + ) end) it('uri_to_fname returns non-file scheme URI without authority unchanged', function() - eq('zipfile:///path/to/archive.zip%3A%3Afilename.txt', exec_lua [[ + eq( + 'zipfile:///path/to/archive.zip%3A%3Afilename.txt', + exec_lua [[ return vim.uri_to_fname('zipfile:///path/to/archive.zip%3A%3Afilename.txt') - ]]) + ]] + ) end) end) describe('decode URI without scheme', function() it('fails because URI must have a scheme', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ return pcall(vim.uri_to_fname, 'not_an_uri.txt') - ]]) + ]] + ) end) it('uri_to_fname should not treat comma as a scheme character', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ return pcall(vim.uri_to_fname, 'foo,://bar') - ]]) + ]] + ) end) end) - end) describe('uri from bufnr', function() it('Windows paths should not be treated as uris', function() - skip(not is_os('win'), "Not applicable on non-Windows") + skip(not is_os('win'), 'Not applicable on non-Windows') local file = helpers.tmpname() write_file(file, 'Test content') - local test_case = string.format([[ + local test_case = string.format( + [[ local file = '%s' return vim.uri_from_bufnr(vim.fn.bufadd(file)) - ]], file) - local expected_uri = 'file:///' .. file:gsub("\\", "/") - eq(expected_uri, exec_lua(test_case)) - os.remove(file) + ]], + file + ) + local expected_uri = 'file:///' .. file:gsub('\\', '/') + eq(expected_uri, exec_lua(test_case)) + os.remove(file) end) end) describe('uri to bufnr', function() it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris', function() - local uri = 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class' - local test_case = string.format([[ + local uri = + 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class' + local test_case = string.format( + [[ local uri = '%s' return vim.uri_from_bufnr(vim.uri_to_bufnr(uri)) - ]], uri) + ]], + uri + ) eq(uri, exec_lua(test_case)) end) - it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', function() - local uri = 'zipfile:///path/to/archive.zip%3A%3Afilename.txt' - local test_case = string.format([[ + it( + 'uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', + function() + local uri = 'zipfile:///path/to/archive.zip%3A%3Afilename.txt' + local test_case = string.format( + [[ local uri = '%s' return vim.uri_from_bufnr(vim.uri_to_bufnr(uri)) - ]], uri) - eq(uri, exec_lua(test_case)) - end) + ]], + uri + ) + eq(uri, exec_lua(test_case)) + end + ) end) end) diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua index d1c981c388..c321421ad0 100644 --- a/test/functional/lua/version_spec.lua +++ b/test/functional/lua/version_spec.lua @@ -11,7 +11,6 @@ local function v(ver) end describe('version', function() - it('package', function() clear() eq({ major = 42, minor = 3, patch = 99 }, exec_lua("return vim.version.parse('v42.3.99')")) @@ -35,7 +34,13 @@ describe('version', function() ['v1.2'] = { major = 1, minor = 2, patch = 0 }, ['v1.2.3-prerelease'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease' }, ['v1.2-prerelease'] = { major = 1, minor = 2, patch = 0, prerelease = 'prerelease' }, - ['v1.2.3-prerelease+build'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease', build = 'build' }, + ['v1.2.3-prerelease+build'] = { + major = 1, + minor = 2, + patch = 3, + prerelease = 'prerelease', + build = 'build', + }, ['1.2.3+build'] = { major = 1, minor = 2, patch = 3, build = 'build' }, } for input, output in pairs(tests) do @@ -108,86 +113,114 @@ describe('version', function() describe('cmp()', function() local testcases = { - { v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1, }, - { v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1, }, - { v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1, }, - { v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0, }, - { v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1, }, - { v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1, }, - { v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1, }, - { v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0, }, + { v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1 }, + { v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1 }, + { v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1 }, + { v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0 }, + { v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1 }, + { v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1 }, + { v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1 }, + { v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0 }, -- prerelease 💩 https://semver.org/#spec-item-11 - { v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1, }, - { v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1, }, - { v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1, }, - { v1 = '1.0.0-2', v2 = '1.0.0-9', want = -1, }, - { v1 = '1.0.0-2', v2 = '1.0.0-2.0', want = -1, }, - { v1 = '1.0.0-2.0', v2 = '1.0.0-2', want = 1, }, - { v1 = '1.0.0-2.0', v2 = '1.0.0-2.0', want = 0, }, - { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha', want = 0, }, - { v1 = '1.0.0-alpha', v2 = '1.0.0-beta', want = -1, }, - { v1 = '1.0.0-beta', v2 = '1.0.0-alpha', want = 1, }, - { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.1', want = -1, }, - { v1 = '1.0.0-alpha.1', v2 = '1.0.0-alpha', want = 1, }, - { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1, }, - { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1, }, - { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1, }, - { v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1, }, - { v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1, }, - { v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1, }, - { v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0, }, - { v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1, }, + { v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1 }, + { v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1 }, + { v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1 }, + { v1 = '1.0.0-2', v2 = '1.0.0-9', want = -1 }, + { v1 = '1.0.0-2', v2 = '1.0.0-2.0', want = -1 }, + { v1 = '1.0.0-2.0', v2 = '1.0.0-2', want = 1 }, + { v1 = '1.0.0-2.0', v2 = '1.0.0-2.0', want = 0 }, + { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha', want = 0 }, + { v1 = '1.0.0-alpha', v2 = '1.0.0-beta', want = -1 }, + { v1 = '1.0.0-beta', v2 = '1.0.0-alpha', want = 1 }, + { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.1', want = -1 }, + { v1 = '1.0.0-alpha.1', v2 = '1.0.0-alpha', want = 1 }, + { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1 }, + { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1 }, + { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1 }, + { v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1 }, + { v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1 }, + { v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1 }, + { v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0 }, + { v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1 }, } for _, tc in ipairs(testcases) do - local msg = function(s) return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<')) end - it(string.format('(v1 = %s, v2 = %s)', tc.v1, tc.v2), - function() - local rv = vim.version.cmp(tc.v1, tc.v2, { strict = true }) - ok(tc.want == rv, msg(tc.want), msg(rv)) - end - ) + local msg = function(s) + return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<')) + end + it(string.format('(v1 = %s, v2 = %s)', tc.v1, tc.v2), function() + local rv = vim.version.cmp(tc.v1, tc.v2, { strict = true }) + ok(tc.want == rv, msg(tc.want), msg(rv)) + end) end end) describe('parse()', function() describe('strict=true', function() local testcases = { - { desc = 'Nvim version', version = 'v0.9.0-dev-1233+g210120dde81e', want = { major = 0, minor = 9, patch = 0, prerelease = 'dev-1233', build = 'g210120dde81e', }, }, - { desc = 'no v', version = '10.20.123', want = { major = 10, minor = 20, patch = 123, prerelease = nil, build = nil, }, }, - { desc = 'with v', version = 'v1.2.3', want = { major = 1, minor = 2, patch = 3 }, }, - { desc = 'prerelease', version = '1.2.3-alpha', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' }, }, - { desc = 'prerelease.x', version = '1.2.3-alpha.1', want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' }, }, - { desc = 'build.x', version = '1.2.3+build.15', want = { major = 1, minor = 2, patch = 3, build = 'build.15' }, }, - { desc = 'prerelease and build', version = '1.2.3-rc1+build.15', want = { major = 1, minor = 2, patch = 3, prerelease = 'rc1', build = 'build.15', }, }, + { + desc = 'Nvim version', + version = 'v0.9.0-dev-1233+g210120dde81e', + want = { + major = 0, + minor = 9, + patch = 0, + prerelease = 'dev-1233', + build = 'g210120dde81e', + }, + }, + { + desc = 'no v', + version = '10.20.123', + want = { major = 10, minor = 20, patch = 123, prerelease = nil, build = nil }, + }, + { + desc = 'with v', + version = 'v1.2.3', + want = { major = 1, minor = 2, patch = 3 }, + }, + { + desc = 'prerelease', + version = '1.2.3-alpha', + want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' }, + }, + { + desc = 'prerelease.x', + version = '1.2.3-alpha.1', + want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' }, + }, + { + desc = 'build.x', + version = '1.2.3+build.15', + want = { major = 1, minor = 2, patch = 3, build = 'build.15' }, + }, + { + desc = 'prerelease and build', + version = '1.2.3-rc1+build.15', + want = { major = 1, minor = 2, patch = 3, prerelease = 'rc1', build = 'build.15' }, + }, } for _, tc in ipairs(testcases) do - it( - string.format('%q: version = %q', tc.desc, tc.version), - function() - eq(tc.want, vim.version.parse(tc.version)) - end - ) + it(string.format('%q: version = %q', tc.desc, tc.version), function() + eq(tc.want, vim.version.parse(tc.version)) + end) end end) describe('strict=false', function() local testcases = { - { version = '1.2', want = { major = 1, minor = 2, patch = 0 }, }, - { version = '1', want = { major = 1, minor = 0, patch = 0 }, }, - { version = '1.1-0', want = { major = 1, minor = 1, patch = 0, prerelease = '0' }, }, - { version = '1-1.0', want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' }, }, - { version = 'v1.2.3 ', want = { major = 1, minor = 2, patch = 3 }, }, - { version = ' v1.2.3', want = { major = 1, minor = 2, patch = 3 }, }, - { version = 'tmux 3.2a', want = { major = 3, minor = 2, patch = 0, }, }, + { version = '1.2', want = { major = 1, minor = 2, patch = 0 } }, + { version = '1', want = { major = 1, minor = 0, patch = 0 } }, + { version = '1.1-0', want = { major = 1, minor = 1, patch = 0, prerelease = '0' } }, + { version = '1-1.0', want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' } }, + { version = 'v1.2.3 ', want = { major = 1, minor = 2, patch = 3 } }, + { version = ' v1.2.3', want = { major = 1, minor = 2, patch = 3 } }, + { version = 'tmux 3.2a', want = { major = 3, minor = 2, patch = 0 } }, } for _, tc in ipairs(testcases) do - it( - string.format('version = %q', tc.version), - function() - eq(tc.want, vim.version.parse(tc.version, { strict = false })) - end - ) + it(string.format('version = %q', tc.version), function() + eq(tc.want, vim.version.parse(tc.version, { strict = false })) + end) end end) @@ -205,8 +238,8 @@ describe('version', function() { version = '1.2.3-%?' }, { version = '1.2.3+%?' }, { version = '1.2.3+build.0-rc1' }, - { version = '3.2a', }, - { version = 'tmux 3.2a', }, + { version = '3.2a' }, + { version = 'tmux 3.2a' }, } local function quote_empty(s) @@ -230,8 +263,10 @@ describe('version', function() } for _, tc in ipairs(testcases) do it(string.format('(%s): %s', tc.desc, tostring(tc.version)), function() - local expected = string.format(type(tc.version) == 'string' - and 'invalid version: "%s"' or 'invalid version: %s', tostring(tc.version)) + local expected = string.format( + type(tc.version) == 'string' and 'invalid version: "%s"' or 'invalid version: %s', + tostring(tc.version) + ) matches(expected, pcall_err(vim.version.parse, tc.version, { strict = true })) end) end @@ -255,19 +290,19 @@ describe('version', function() it('lt()', function() eq(true, vim.version.lt('1', '2')) - eq(false, vim.version.lt({3}, {0, 7, 4})) - eq(false, vim.version.lt({major=3, minor=3, patch=0}, {3, 2, 0})) + eq(false, vim.version.lt({ 3 }, { 0, 7, 4 })) + eq(false, vim.version.lt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 })) end) it('gt()', function() eq(true, vim.version.gt('2', '1')) - eq(true, vim.version.gt({3}, {0, 7, 4})) - eq(true, vim.version.gt({major=3, minor=3, patch=0}, {3, 2, 0})) + eq(true, vim.version.gt({ 3 }, { 0, 7, 4 })) + eq(true, vim.version.gt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 })) end) it('eq()', function() eq(true, vim.version.eq('2', '2')) - eq(true, vim.version.eq({3, 1, 0}, '3.1.0')) - eq(true, vim.version.eq({major=3, minor=3, patch=0}, {3, 3, 0})) + eq(true, vim.version.eq({ 3, 1, 0 }, '3.1.0')) + eq(true, vim.version.eq({ major = 3, minor = 3, patch = 0 }, { 3, 3, 0 })) end) end) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e017ea7670..4ebba827ef 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -130,20 +130,30 @@ describe('lua stdlib', function() it('vim.deprecate', function() -- vim.deprecate(name, alternative, version, plugin, backtrace) - eq(dedent[[ + eq( + dedent [[ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated This feature will be removed in Nvim version 0.10]], - exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')) + exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10') + ) -- Same message, skipped. - eq(vim.NIL, - exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')) + eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')) -- Don't show error if not hard deprecated eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'nil', '5000.0.0')) -- When `plugin` is specified, don't show ":help deprecated". #22235 - eq(dedent[[ + eq( + dedent [[ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. This feature will be removed in my-plugin.nvim version 0.3.0]], - exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.3.0', 'my-plugin.nvim', false)) + exec_lua( + 'return vim.deprecate(...)', + 'foo.bar()', + 'zub.wooo{ok=yay}', + '0.3.0', + 'my-plugin.nvim', + false + ) + ) end) it('vim.startswith', function() @@ -156,10 +166,11 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.startswith("123", "2")')) eq(false, funcs.luaeval('vim.startswith("123", "1234")')) - matches("prefix: expected string, got nil", - pcall_err(exec_lua, 'return vim.startswith("123", nil)')) - matches("s: expected string, got nil", - pcall_err(exec_lua, 'return vim.startswith(nil, "123")')) + matches( + 'prefix: expected string, got nil', + pcall_err(exec_lua, 'return vim.startswith("123", nil)') + ) + matches('s: expected string, got nil', pcall_err(exec_lua, 'return vim.startswith(nil, "123")')) end) it('vim.endswith', function() @@ -172,73 +183,275 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.endswith("123", "2")')) eq(false, funcs.luaeval('vim.endswith("123", "1234")')) - matches("suffix: expected string, got nil", - pcall_err(exec_lua, 'return vim.endswith("123", nil)')) - matches("s: expected string, got nil", - pcall_err(exec_lua, 'return vim.endswith(nil, "123")')) + matches( + 'suffix: expected string, got nil', + pcall_err(exec_lua, 'return vim.endswith("123", nil)') + ) + matches('s: expected string, got nil', pcall_err(exec_lua, 'return vim.endswith(nil, "123")')) end) - it("vim.str_utfindex/str_byteindex", function() + it('vim.str_utfindex/str_byteindex', function() exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ\000ъ"]]) - local indices32 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,29,33,34,35,37,38,40,42,44,46,48,49,51} - local indices16 = {[0]=0,1,2,3,5,7,9,10,12,13,16,19,20,23,24,28,28,29,33,33,34,35,37,38,40,42,44,46,48,49,51} - for i,k in pairs(indices32) do - eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ...)", i), i) + local indices32 = { + [0] = 0, + 1, + 2, + 3, + 5, + 7, + 9, + 10, + 12, + 13, + 16, + 19, + 20, + 23, + 24, + 28, + 29, + 33, + 34, + 35, + 37, + 38, + 40, + 42, + 44, + 46, + 48, + 49, + 51, + } + local indices16 = { + [0] = 0, + 1, + 2, + 3, + 5, + 7, + 9, + 10, + 12, + 13, + 16, + 19, + 20, + 23, + 24, + 28, + 28, + 29, + 33, + 33, + 34, + 35, + 37, + 38, + 40, + 42, + 44, + 46, + 48, + 49, + 51, + } + for i, k in pairs(indices32) do + eq(k, exec_lua('return vim.str_byteindex(_G.test_text, ...)', i), i) end - for i,k in pairs(indices16) do - eq(k, exec_lua("return vim.str_byteindex(_G.test_text, ..., true)", i), i) + for i, k in pairs(indices16) do + eq(k, exec_lua('return vim.str_byteindex(_G.test_text, ..., true)', i), i) end - eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ...)", #indices32 + 1)) - eq("index out of range", pcall_err(exec_lua, "return vim.str_byteindex(_G.test_text, ..., true)", #indices16 + 1)) + eq( + 'index out of range', + pcall_err(exec_lua, 'return vim.str_byteindex(_G.test_text, ...)', #indices32 + 1) + ) + eq( + 'index out of range', + pcall_err(exec_lua, 'return vim.str_byteindex(_G.test_text, ..., true)', #indices16 + 1) + ) local i32, i16 = 0, 0 local len = 51 - for k = 0,len do + for k = 0, len do if indices32[i32] < k then i32 = i32 + 1 end if indices16[i16] < k then i16 = i16 + 1 - if indices16[i16+1] == indices16[i16] then + if indices16[i16 + 1] == indices16[i16] then i16 = i16 + 1 end end - eq({i32, i16}, exec_lua("return {vim.str_utfindex(_G.test_text, ...)}", k), k) + eq({ i32, i16 }, exec_lua('return {vim.str_utfindex(_G.test_text, ...)}', k), k) end - eq("index out of range", pcall_err(exec_lua, "return vim.str_utfindex(_G.test_text, ...)", len + 1)) + eq( + 'index out of range', + pcall_err(exec_lua, 'return vim.str_utfindex(_G.test_text, ...)', len + 1) + ) end) - it("vim.str_utf_start", function() + it('vim.str_utf_start', function() exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]]) - local expected_positions = {0,0,0,0,-1,0,-1,0,-1,0,0,-1,0,0,-1,-2,0,-1,-2,0,0,-1,-2,0,0,-1,-2,-3,0,0,-1,-2,-3,0,0,0,-1,0,0,-1,0,-1,0,-1,0,-1,0,-1} - eq(expected_positions, exec_lua([[ + local expected_positions = { + 0, + 0, + 0, + 0, + -1, + 0, + -1, + 0, + -1, + 0, + 0, + -1, + 0, + 0, + -1, + -2, + 0, + -1, + -2, + 0, + 0, + -1, + -2, + 0, + 0, + -1, + -2, + -3, + 0, + 0, + -1, + -2, + -3, + 0, + 0, + 0, + -1, + 0, + 0, + -1, + 0, + -1, + 0, + -1, + 0, + -1, + 0, + -1, + } + eq( + expected_positions, + exec_lua([[ local start_codepoint_positions = {} for idx = 1, #_G.test_text do table.insert(start_codepoint_positions, vim.str_utf_start(_G.test_text, idx)) end return start_codepoint_positions - ]])) + ]]) + ) end) - it("vim.str_utf_end", function() + it('vim.str_utf_end', function() exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]]) - local expected_positions = {0,0,0,1,0,1,0,1,0,0,1,0,0,2,1,0,2,1,0,0,2,1,0,0,3,2,1,0,0,3,2,1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0 } - eq(expected_positions, exec_lua([[ + local expected_positions = { + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 2, + 1, + 0, + 2, + 1, + 0, + 0, + 2, + 1, + 0, + 0, + 3, + 2, + 1, + 0, + 0, + 3, + 2, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + } + eq( + expected_positions, + exec_lua([[ local end_codepoint_positions = {} for idx = 1, #_G.test_text do table.insert(end_codepoint_positions, vim.str_utf_end(_G.test_text, idx)) end return end_codepoint_positions - ]])) + ]]) + ) end) - - it("vim.str_utf_pos", function() + it('vim.str_utf_pos', function() exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]]) - local expected_positions = { 1,2,3,4,6,8,10,11,13,14,17,20,21,24,25,29,30,34,35,36,38,39,41,43,45,47 } - eq(expected_positions, exec_lua("return vim.str_utf_pos(_G.test_text)")) + local expected_positions = { + 1, + 2, + 3, + 4, + 6, + 8, + 10, + 11, + 13, + 14, + 17, + 20, + 21, + 24, + 25, + 29, + 30, + 34, + 35, + 36, + 38, + 39, + 41, + 43, + 45, + 47, + } + eq(expected_positions, exec_lua('return vim.str_utf_pos(_G.test_text)')) end) - it("vim.schedule", function() + it('vim.schedule', function() exec_lua([[ test_table = {} vim.schedule(function() @@ -246,13 +459,11 @@ describe('lua stdlib', function() end) table.insert(test_table, "yy") ]]) - eq({"yy","xx"}, exec_lua("return test_table")) + eq({ 'yy', 'xx' }, exec_lua('return test_table')) -- Validates args. - matches('vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule('stringly')")) - matches('vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule()")) + matches('vim.schedule: expected function', pcall_err(exec_lua, "vim.schedule('stringly')")) + matches('vim.schedule: expected function', pcall_err(exec_lua, 'vim.schedule()')) exec_lua([[ vim.schedule(function() @@ -260,22 +471,24 @@ describe('lua stdlib', function() end) ]]) - feed("<cr>") - matches('big failure\nvery async', remove_trace(eval("v:errmsg"))) + feed('<cr>') + matches('big failure\nvery async', remove_trace(eval('v:errmsg'))) - local screen = Screen.new(60,5) + local screen = Screen.new(60, 5) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) screen:attach() - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {1:~ }|*3 | - ]]} + ]], + } -- nvim_command causes a Vimscript exception, check that it is properly caught -- and propagated as an error message in async contexts.. #10809 @@ -284,62 +497,61 @@ describe('lua stdlib', function() vim.api.nvim_command(":echo 'err") end) ]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ {3:stack traceback:} | {3: [C]: in function 'nvim_command'} | {3: [string "<nvim>"]:2: in function <[string "<nvim>"]:}| {3:1>} | {4:Press ENTER or type command to continue}^ | - ]]} + ]], + } end) it('vim.gsplit, vim.split', function() local tests = { -- plain trimempty - { 'a,b', ',', false, false, { 'a', 'b' } }, - { ':aa::::bb:', ':', false, false, { '', 'aa', '', '', '', 'bb', '' } }, - { ':aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } }, - { 'aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } }, - { ':aa::bb:', ':', false, true, { 'aa', '', 'bb' } }, - { '/a/b:/b/\n', '[:\n]', false, true, { '/a/b', '/b/' } }, - { '::ee::ff:', ':', false, false, { '', '', 'ee', '', 'ff', '' } }, - { '::ee::ff::', ':', false, true, { 'ee', '', 'ff' } }, - { 'ab', '.', false, false, { '', '', '' } }, - { 'a1b2c', '[0-9]', false, false, { 'a', 'b', 'c' } }, - { 'xy', '', false, false, { 'x', 'y' } }, - { 'here be dragons', ' ', false, false, { 'here', 'be', 'dragons'} }, - { 'axaby', 'ab?', false, false, { '', 'x', 'y' } }, - { 'f v2v v3v w2w ', '([vw])2%1', false, false, { 'f ', ' v3v ', ' ' } }, - { '', '', false, false, {} }, - { '', '', false, true, {} }, - { '\n', '[:\n]', false, true, {} }, - { '', 'a', false, false, { '' } }, - { 'x*yz*oo*l', '*', true, false, { 'x', 'yz', 'oo', 'l' } }, + { 'a,b', ',', false, false, { 'a', 'b' } }, + { ':aa::::bb:', ':', false, false, { '', 'aa', '', '', '', 'bb', '' } }, + { ':aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } }, + { 'aa::::bb:', ':', false, true, { 'aa', '', '', '', 'bb' } }, + { ':aa::bb:', ':', false, true, { 'aa', '', 'bb' } }, + { '/a/b:/b/\n', '[:\n]', false, true, { '/a/b', '/b/' } }, + { '::ee::ff:', ':', false, false, { '', '', 'ee', '', 'ff', '' } }, + { '::ee::ff::', ':', false, true, { 'ee', '', 'ff' } }, + { 'ab', '.', false, false, { '', '', '' } }, + { 'a1b2c', '[0-9]', false, false, { 'a', 'b', 'c' } }, + { 'xy', '', false, false, { 'x', 'y' } }, + { 'here be dragons', ' ', false, false, { 'here', 'be', 'dragons' } }, + { 'axaby', 'ab?', false, false, { '', 'x', 'y' } }, + { 'f v2v v3v w2w ', '([vw])2%1', false, false, { 'f ', ' v3v ', ' ' } }, + { '', '', false, false, {} }, + { '', '', false, true, {} }, + { '\n', '[:\n]', false, true, {} }, + { '', 'a', false, false, { '' } }, + { 'x*yz*oo*l', '*', true, false, { 'x', 'yz', 'oo', 'l' } }, } for _, t in ipairs(tests) do - eq(t[5], vim.split(t[1], t[2], {plain=t[3], trimempty=t[4]}), t[1]) + eq(t[5], vim.split(t[1], t[2], { plain = t[3], trimempty = t[4] }), t[1]) end -- Test old signature - eq({'x', 'yz', 'oo', 'l'}, vim.split("x*yz*oo*l", "*", true)) + eq({ 'x', 'yz', 'oo', 'l' }, vim.split('x*yz*oo*l', '*', true)) local loops = { - { "abc", ".-" }, + { 'abc', '.-' }, } for _, t in ipairs(loops) do - matches("Infinite loop detected", pcall_err(vim.split, t[1], t[2])) + matches('Infinite loop detected', pcall_err(vim.split, t[1], t[2])) end -- Validates args. eq(true, pcall(vim.split, 'string', 'string')) - matches('s: expected string, got number', - pcall_err(vim.split, 1, 'string')) - matches('sep: expected string, got number', - pcall_err(vim.split, 'string', 1)) - matches('opts: expected table, got number', - pcall_err(vim.split, 'string', 'string', 1)) + matches('s: expected string, got number', pcall_err(vim.split, 1, 'string')) + matches('sep: expected string, got number', pcall_err(vim.split, 'string', 1)) + matches('opts: expected table, got number', pcall_err(vim.split, 'string', 'string', 1)) end) it('vim.trim', function() @@ -348,10 +560,10 @@ describe('lua stdlib', function() end local trims = { - { " a", "a" }, - { " b ", "b" }, - { "\tc" , "c" }, - { "r\n", "r" }, + { ' a', 'a' }, + { ' b ', 'b' }, + { '\tc', 'c' }, + { 'r\n', 'r' }, } for _, t in ipairs(trims) do @@ -359,8 +571,7 @@ describe('lua stdlib', function() end -- Validates args. - matches('s: expected string, got number', - pcall_err(trim, 2)) + matches('s: expected string, got number', pcall_err(trim, 2)) end) it('vim.inspect', function() @@ -370,21 +581,23 @@ describe('lua stdlib', function() end eq('2', inspect(2)) - eq('{+a = {+b = 1+}+}', - inspect({ a = { b = 1 } }, { newline = '+', indent = '' })) + eq('{+a = {+b = 1+}+}', inspect({ a = { b = 1 } }, { newline = '+', indent = '' })) -- special value vim.inspect.KEY works - eq('{ KEY_a = "x", KEY_b = "y"}', exec_lua([[ + eq( + '{ KEY_a = "x", KEY_b = "y"}', + exec_lua([[ return vim.inspect({a="x", b="y"}, {newline = '', process = function(item, path) if path[#path] == vim.inspect.KEY then return 'KEY_'..item end return item end}) - ]])) + ]]) + ) end) - it("vim.deepcopy", function() + it('vim.deepcopy', function() ok(exec_lua([[ local a = { x = { 1, 2 }, y = 5} local b = vim.deepcopy(a) @@ -445,23 +658,27 @@ describe('lua stdlib', function() return t2.a == vim.NIL ]])) - matches('Cannot deepcopy object of type thread', - pcall_err(exec_lua, [[ + matches( + 'Cannot deepcopy object of type thread', + pcall_err( + exec_lua, + [[ local thread = coroutine.create(function () return 0 end) local t = {thr = thread} vim.deepcopy(t) - ]])) + ]] + ) + ) end) it('vim.pesc', function() eq('foo%-bar', exec_lua([[return vim.pesc('foo-bar')]])) eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) -- pesc() returns one result. #20751 - eq({'x'}, exec_lua([[return {vim.pesc('x')}]])) + eq({ 'x' }, exec_lua([[return {vim.pesc('x')}]])) -- Validates args. - matches('s: expected string, got number', - pcall_err(exec_lua, [[return vim.pesc(2)]])) + matches('s: expected string, got number', pcall_err(exec_lua, [[return vim.pesc(2)]])) end) it('vim.list_contains', function() @@ -473,97 +690,131 @@ describe('lua stdlib', function() eq(true, exec_lua("return vim.tbl_contains({'a','b','c'}, 'c')")) eq(false, exec_lua("return vim.tbl_contains({'a','b','c'}, 'd')")) eq(true, exec_lua("return vim.tbl_contains({[2]='a',foo='b',[5] = 'c'}, 'c')")) - eq(true, exec_lua([[ + eq( + true, + exec_lua([[ return vim.tbl_contains({ 'a', { 'b', 'c' } }, function(v) return vim.deep_equal(v, { 'b', 'c' }) end, { predicate = true }) - ]])) + ]]) + ) end) it('vim.tbl_keys', function() - eq({}, exec_lua("return vim.tbl_keys({})")) + eq({}, exec_lua('return vim.tbl_keys({})')) for _, v in pairs(exec_lua("return vim.tbl_keys({'a', 'b', 'c'})")) do - eq(true, exec_lua("return vim.tbl_contains({ 1, 2, 3 }, ...)", v)) + eq(true, exec_lua('return vim.tbl_contains({ 1, 2, 3 }, ...)', v)) end - for _, v in pairs(exec_lua("return vim.tbl_keys({a=1, b=2, c=3})")) do + for _, v in pairs(exec_lua('return vim.tbl_keys({a=1, b=2, c=3})')) do eq(true, exec_lua("return vim.tbl_contains({ 'a', 'b', 'c' }, ...)", v)) end end) it('vim.tbl_values', function() - eq({}, exec_lua("return vim.tbl_values({})")) + eq({}, exec_lua('return vim.tbl_values({})')) for _, v in pairs(exec_lua("return vim.tbl_values({'a', 'b', 'c'})")) do eq(true, exec_lua("return vim.tbl_contains({ 'a', 'b', 'c' }, ...)", v)) end - for _, v in pairs(exec_lua("return vim.tbl_values({a=1, b=2, c=3})")) do - eq(true, exec_lua("return vim.tbl_contains({ 1, 2, 3 }, ...)", v)) + for _, v in pairs(exec_lua('return vim.tbl_values({a=1, b=2, c=3})')) do + eq(true, exec_lua('return vim.tbl_contains({ 1, 2, 3 }, ...)', v)) end end) it('vim.tbl_map', function() - eq({}, exec_lua([[ + eq( + {}, + exec_lua([[ return vim.tbl_map(function(v) return v * 2 end, {}) - ]])) - eq({2, 4, 6}, exec_lua([[ + ]]) + ) + eq( + { 2, 4, 6 }, + exec_lua([[ return vim.tbl_map(function(v) return v * 2 end, {1, 2, 3}) - ]])) - eq({{i=2}, {i=4}, {i=6}}, exec_lua([[ + ]]) + ) + eq( + { { i = 2 }, { i = 4 }, { i = 6 } }, + exec_lua([[ return vim.tbl_map(function(v) return { i = v.i * 2 } end, {{i=1}, {i=2}, {i=3}}) - ]])) + ]]) + ) end) it('vim.tbl_filter', function() - eq({}, exec_lua([[ + eq( + {}, + exec_lua([[ return vim.tbl_filter(function(v) return (v % 2) == 0 end, {}) - ]])) - eq({2}, exec_lua([[ + ]]) + ) + eq( + { 2 }, + exec_lua([[ return vim.tbl_filter(function(v) return (v % 2) == 0 end, {1, 2, 3}) - ]])) - eq({{i=2}}, exec_lua([[ + ]]) + ) + eq( + { { i = 2 } }, + exec_lua([[ return vim.tbl_filter(function(v) return (v.i % 2) == 0 end, {{i=1}, {i=2}, {i=3}}) - ]])) + ]]) + ) end) it('vim.tbl_isarray', function() - eq(true, exec_lua("return vim.tbl_isarray({})")) - eq(false, exec_lua("return vim.tbl_isarray(vim.empty_dict())")) + eq(true, exec_lua('return vim.tbl_isarray({})')) + eq(false, exec_lua('return vim.tbl_isarray(vim.empty_dict())')) eq(true, exec_lua("return vim.tbl_isarray({'a', 'b', 'c'})")) eq(false, exec_lua("return vim.tbl_isarray({'a', '32', a='hello', b='baz'})")) eq(false, exec_lua("return vim.tbl_isarray({1, a='hello', b='baz'})")) eq(false, exec_lua("return vim.tbl_isarray({a='hello', b='baz', 1})")) eq(false, exec_lua("return vim.tbl_isarray({1, 2, nil, a='hello'})")) - eq(true, exec_lua("return vim.tbl_isarray({1, 2, nil, 4})")) - eq(true, exec_lua("return vim.tbl_isarray({nil, 2, 3, 4})")) - eq(false, exec_lua("return vim.tbl_isarray({1, [1.5]=2, [3]=3})")) + eq(true, exec_lua('return vim.tbl_isarray({1, 2, nil, 4})')) + eq(true, exec_lua('return vim.tbl_isarray({nil, 2, 3, 4})')) + eq(false, exec_lua('return vim.tbl_isarray({1, [1.5]=2, [3]=3})')) end) it('vim.tbl_islist', function() - eq(true, exec_lua("return vim.tbl_islist({})")) - eq(false, exec_lua("return vim.tbl_islist(vim.empty_dict())")) + eq(true, exec_lua('return vim.tbl_islist({})')) + eq(false, exec_lua('return vim.tbl_islist(vim.empty_dict())')) eq(true, exec_lua("return vim.tbl_islist({'a', 'b', 'c'})")) eq(false, exec_lua("return vim.tbl_islist({'a', '32', a='hello', b='baz'})")) eq(false, exec_lua("return vim.tbl_islist({1, a='hello', b='baz'})")) eq(false, exec_lua("return vim.tbl_islist({a='hello', b='baz', 1})")) eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, a='hello'})")) - eq(false, exec_lua("return vim.tbl_islist({1, 2, nil, 4})")) - eq(false, exec_lua("return vim.tbl_islist({nil, 2, 3, 4})")) - eq(false, exec_lua("return vim.tbl_islist({1, [1.5]=2, [3]=3})")) + eq(false, exec_lua('return vim.tbl_islist({1, 2, nil, 4})')) + eq(false, exec_lua('return vim.tbl_islist({nil, 2, 3, 4})')) + eq(false, exec_lua('return vim.tbl_islist({1, [1.5]=2, [3]=3})')) end) it('vim.tbl_isempty', function() - eq(true, exec_lua("return vim.tbl_isempty({})")) - eq(false, exec_lua("return vim.tbl_isempty({ 1, 2, 3 })")) - eq(false, exec_lua("return vim.tbl_isempty({a=1, b=2, c=3})")) + eq(true, exec_lua('return vim.tbl_isempty({})')) + eq(false, exec_lua('return vim.tbl_isempty({ 1, 2, 3 })')) + eq(false, exec_lua('return vim.tbl_isempty({a=1, b=2, c=3})')) end) it('vim.tbl_get', function() - eq(true, exec_lua("return vim.tbl_get({ test = { nested_test = true }}, 'test', 'nested_test')")) + eq( + true, + exec_lua("return vim.tbl_get({ test = { nested_test = true }}, 'test', 'nested_test')") + ) eq(NIL, exec_lua("return vim.tbl_get({ unindexable = true }, 'unindexable', 'missing_key')")) eq(NIL, exec_lua("return vim.tbl_get({ unindexable = 1 }, 'unindexable', 'missing_key')")) - eq(NIL, exec_lua("return vim.tbl_get({ unindexable = coroutine.create(function () end) }, 'unindexable', 'missing_key')")) - eq(NIL, exec_lua("return vim.tbl_get({ unindexable = function () end }, 'unindexable', 'missing_key')")) + eq( + NIL, + exec_lua( + "return vim.tbl_get({ unindexable = coroutine.create(function () end) }, 'unindexable', 'missing_key')" + ) + ) + eq( + NIL, + exec_lua( + "return vim.tbl_get({ unindexable = function () end }, 'unindexable', 'missing_key')" + ) + ) eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')")) - eq(NIL, exec_lua("return vim.tbl_get({})")) + eq(NIL, exec_lua('return vim.tbl_get({})')) eq(1, exec_lua("return select('#', vim.tbl_get({}))")) eq(1, exec_lua("return select('#', vim.tbl_get({ nested = {} }, 'nested', 'missing_key'))")) end) @@ -629,22 +880,34 @@ describe('lua stdlib', function() return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1 ]])) - matches('invalid "behavior": nil', - pcall_err(exec_lua, [[ + matches( + 'invalid "behavior": nil', + pcall_err( + exec_lua, + [[ return vim.tbl_extend() - ]]) + ]] + ) ) - matches('wrong number of arguments %(given 1, expected at least 3%)', - pcall_err(exec_lua, [[ + matches( + 'wrong number of arguments %(given 1, expected at least 3%)', + pcall_err( + exec_lua, + [[ return vim.tbl_extend("keep") - ]]) + ]] + ) ) - matches('wrong number of arguments %(given 2, expected at least 3%)', - pcall_err(exec_lua, [[ + matches( + 'wrong number of arguments %(given 2, expected at least 3%)', + pcall_err( + exec_lua, + [[ return vim.tbl_extend("keep", {}) - ]]) + ]] + ) ) end) @@ -717,17 +980,23 @@ describe('lua stdlib', function() return vim.tbl_islist(c) and count == 0 ]])) - eq({a = {b = 1}}, exec_lua([[ + eq( + { a = { b = 1 } }, + exec_lua([[ local a = { a = { b = 1 } } local b = { a = {} } return vim.tbl_deep_extend("force", a, b) - ]])) + ]]) + ) - eq({a = {b = 1}}, exec_lua([[ + eq( + { a = { b = 1 } }, + exec_lua([[ local a = { a = 123 } local b = { a = { b = 1} } return vim.tbl_deep_extend("force", a, b) - ]])) + ]]) + ) ok(exec_lua([[ local a = { a = {[2] = 3} } @@ -736,28 +1005,43 @@ describe('lua stdlib', function() return vim.deep_equal(c, {a = {[3] = 3}}) ]])) - eq({a = 123}, exec_lua([[ + eq( + { a = 123 }, + exec_lua([[ local a = { a = { b = 1} } local b = { a = 123 } return vim.tbl_deep_extend("force", a, b) - ]])) + ]]) + ) - matches('invalid "behavior": nil', - pcall_err(exec_lua, [[ + matches( + 'invalid "behavior": nil', + pcall_err( + exec_lua, + [[ return vim.tbl_deep_extend() - ]]) + ]] + ) ) - matches('wrong number of arguments %(given 1, expected at least 3%)', - pcall_err(exec_lua, [[ + matches( + 'wrong number of arguments %(given 1, expected at least 3%)', + pcall_err( + exec_lua, + [[ return vim.tbl_deep_extend("keep") - ]]) + ]] + ) ) - matches('wrong number of arguments %(given 2, expected at least 3%)', - pcall_err(exec_lua, [[ + matches( + 'wrong number of arguments %(given 2, expected at least 3%)', + pcall_err( + exec_lua, + [[ return vim.tbl_deep_extend("keep", {}) - ]]) + ]] + ) ) end) @@ -786,23 +1070,28 @@ describe('lua stdlib', function() end) it('vim.list_extend', function() - eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]]) - matches('src: expected table, got nil', - pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]])) - eq({1,2}, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]]) + eq({ 1, 2, 3 }, exec_lua [[ return vim.list_extend({1}, {2,3}) ]]) + matches( + 'src: expected table, got nil', + pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]]) + ) + eq({ 1, 2 }, exec_lua [[ return vim.list_extend({1}, {2;a=1}) ]]) eq(true, exec_lua [[ local a = {1} return vim.list_extend(a, {2;a=1}) == a ]]) - eq({2}, exec_lua [[ return vim.list_extend({}, {2;a=1}, 1) ]]) + eq({ 2 }, exec_lua [[ return vim.list_extend({}, {2;a=1}, 1) ]]) eq({}, exec_lua [[ return vim.list_extend({}, {2;a=1}, 2) ]]) eq({}, exec_lua [[ return vim.list_extend({}, {2;a=1}, 1, -1) ]]) - eq({2}, exec_lua [[ return vim.list_extend({}, {2;a=1}, -1, 2) ]]) + eq({ 2 }, exec_lua [[ return vim.list_extend({}, {2;a=1}, -1, 2) ]]) end) it('vim.tbl_add_reverse_lookup', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local a = { A = 1 } vim.tbl_add_reverse_lookup(a) return vim.deep_equal(a, { A = 1; [1] = 'A'; }) - ]]) + ]] + ) -- Throw an error for trying to do it twice (run into an existing key) local code = [[ local res = {} @@ -811,17 +1100,19 @@ describe('lua stdlib', function() assert(vim.deep_equal(a, { A = 1; [1] = 'A'; })) vim.tbl_add_reverse_lookup(a) ]] - matches('The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$', - pcall_err(exec_lua, code)) + matches( + 'The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$', + pcall_err(exec_lua, code) + ) end) it('vim.spairs', function() local res = '' local table = { - ccc=1, - bbb=2, - ddd=3, - aaa=4 + ccc = 1, + bbb = 2, + ddd = 3, + aaa = 4, } for key, _ in vim.spairs(table) do res = res .. key @@ -848,37 +1139,51 @@ describe('lua stdlib', function() endfunc ]]) eq(true, exec_lua([[return next(vim.fn.FooFunc(3)) == nil ]])) - eq(3, eval("g:test")) + eq(3, eval('g:test')) -- compat: nvim_call_function uses "special" value for empty dict eq(true, exec_lua([[return next(vim.api.nvim_call_function("FooFunc", {5})) == true ]])) - eq(5, eval("g:test")) + eq(5, eval('g:test')) - eq({2, "foo", true}, exec_lua([[return vim.fn.VarArg(2, "foo", true)]])) + eq({ 2, 'foo', true }, exec_lua([[return vim.fn.VarArg(2, "foo", true)]])) - eq(true, exec_lua([[ + eq( + true, + exec_lua([[ local x = vim.fn.Nilly() return #x == 2 and x[1] == vim.NIL and x[2] == vim.NIL - ]])) - eq({NIL, NIL}, exec_lua([[return vim.fn.Nilly()]])) + ]]) + ) + eq({ NIL, NIL }, exec_lua([[return vim.fn.Nilly()]])) -- error handling - eq({false, 'Vim:E897: List or Blob required'}, exec_lua([[return {pcall(vim.fn.add, "aa", "bb")}]])) + eq( + { false, 'Vim:E897: List or Blob required' }, + exec_lua([[return {pcall(vim.fn.add, "aa", "bb")}]]) + ) -- conversion between LuaRef and Vim Funcref - eq(true, exec_lua([[ + eq( + true, + exec_lua([[ local x = vim.fn.VarArg(function() return 'foo' end, function() return 'bar' end) return #x == 2 and x[1]() == 'foo' and x[2]() == 'bar' - ]])) + ]]) + ) -- Test for #20211 - eq('a (b) c', exec_lua([[ + eq( + 'a (b) c', + exec_lua([[ return vim.fn.substitute('a b c', 'b', function(m) return '(' .. m[1] .. ')' end, 'g') - ]])) + ]]) + ) end) it('vim.fn should error when calling API function', function() - matches('Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead', - pcall_err(exec_lua, "vim.fn.nvim_get_current_line()")) + matches( + 'Tried to call API function with vim.fn: use vim.api.nvim_get_current_line instead', + pcall_err(exec_lua, 'vim.fn.nvim_get_current_line()') + ) end) it('vim.fn is allowed in "fast" context by some functions #18306', function() @@ -892,7 +1197,7 @@ describe('lua stdlib', function() ]]) helpers.poke_eventloop() - eq('hello', exec_lua[[return vim.g.fnres]]) + eq('hello', exec_lua [[return vim.g.fnres]]) end) it('vim.rpcrequest and vim.rpcnotify', function() @@ -902,50 +1207,58 @@ describe('lua stdlib', function() ]]) eq('meow', meths.get_current_line()) command("let x = [3, 'aa', v:true, v:null]") - eq(true, exec_lua([[ + eq( + true, + exec_lua([[ ret = vim.rpcrequest(chan, 'nvim_get_var', 'x') return #ret == 4 and ret[1] == 3 and ret[2] == 'aa' and ret[3] == true and ret[4] == vim.NIL - ]])) - eq({3, 'aa', true, NIL}, exec_lua([[return ret]])) + ]]) + ) + eq({ 3, 'aa', true, NIL }, exec_lua([[return ret]])) - eq({{}, {}, false, true}, exec_lua([[ + eq( + { {}, {}, false, true }, + exec_lua([[ vim.rpcrequest(chan, 'nvim_exec', 'let xx = {}\nlet yy = []', false) local dict = vim.rpcrequest(chan, 'nvim_eval', 'xx') local list = vim.rpcrequest(chan, 'nvim_eval', 'yy') return {dict, list, vim.tbl_islist(dict), vim.tbl_islist(list)} - ]])) + ]]) + ) - exec_lua([[ + exec_lua([[ vim.rpcrequest(chan, 'nvim_set_var', 'aa', {}) vim.rpcrequest(chan, 'nvim_set_var', 'bb', vim.empty_dict()) ]]) - eq({1, 1}, eval('[type(g:aa) == type([]), type(g:bb) == type({})]')) + eq({ 1, 1 }, eval('[type(g:aa) == type([]), type(g:bb) == type({})]')) -- error handling - eq({false, 'Invalid channel: 23'}, - exec_lua([[return {pcall(vim.rpcrequest, 23, 'foo')}]])) - eq({false, 'Invalid channel: 23'}, - exec_lua([[return {pcall(vim.rpcnotify, 23, 'foo')}]])) - - eq({false, 'Vim:E121: Undefined variable: foobar'}, - exec_lua([[return {pcall(vim.rpcrequest, chan, 'nvim_eval', "foobar")}]])) + eq({ false, 'Invalid channel: 23' }, exec_lua([[return {pcall(vim.rpcrequest, 23, 'foo')}]])) + eq({ false, 'Invalid channel: 23' }, exec_lua([[return {pcall(vim.rpcnotify, 23, 'foo')}]])) + eq( + { false, 'Vim:E121: Undefined variable: foobar' }, + exec_lua([[return {pcall(vim.rpcrequest, chan, 'nvim_eval', "foobar")}]]) + ) -- rpcnotify doesn't wait on request - eq('meow', exec_lua([[ + eq( + 'meow', + exec_lua([[ vim.rpcnotify(chan, 'nvim_set_current_line', 'foo') return vim.api.nvim_get_current_line() - ]])) + ]]) + ) retry(10, nil, function() eq('foo', meths.get_current_line()) end) - local screen = Screen.new(50,7) + local screen = Screen.new(50, 7) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) screen:attach() exec_lua([[ @@ -957,7 +1270,8 @@ describe('lua stdlib', function() vim.rpcrequest(chan, 'nvim_set_current_line', 'bork') end) ]]) - screen:expect{grid=[[ + screen:expect { + grid = [[ {3:[string "<nvim>"]:6: E5560: rpcrequest must not be}| {3: called in a lua loop callback} | {3:stack traceback:} | @@ -965,35 +1279,42 @@ describe('lua stdlib', function() {3: [string "<nvim>"]:6: in function <[string }| {3:"<nvim>"]:2>} | {4:Press ENTER or type command to continue}^ | - ]]} + ]], + } feed('<cr>') - eq({3, NIL}, meths.get_var('yy')) + eq({ 3, NIL }, meths.get_var('yy')) exec_lua([[timer:close()]]) end) it('vim.empty_dict()', function() - eq({true, false, true, true}, exec_lua([[ + eq( + { true, false, true, true }, + exec_lua([[ vim.api.nvim_set_var('listy', {}) vim.api.nvim_set_var('dicty', vim.empty_dict()) local listy = vim.fn.eval("listy") local dicty = vim.fn.eval("dicty") return {vim.tbl_islist(listy), vim.tbl_islist(dicty), next(listy) == nil, next(dicty) == nil} - ]])) + ]]) + ) -- vim.empty_dict() gives new value each time -- equality is not overridden (still by ref) -- non-empty table uses the usual heuristics (ignores the tag) - eq({false, {"foo"}, {namey="bar"}}, exec_lua([[ + eq( + { false, { 'foo' }, { namey = 'bar' } }, + exec_lua([[ local aa = vim.empty_dict() local bb = vim.empty_dict() local equally = (aa == bb) aa[1] = "foo" bb["namey"] = "bar" return {equally, aa, bb} - ]])) + ]]) + ) - eq("{ {}, vim.empty_dict() }", exec_lua("return vim.inspect({{}, vim.empty_dict()})")) + eq('{ {}, vim.empty_dict() }', exec_lua('return vim.inspect({{}, vim.empty_dict()})')) eq('{}', exec_lua([[ return vim.fn.json_encode(vim.empty_dict()) ]])) eq('{"a": {}, "b": []}', exec_lua([[ return vim.fn.json_encode({a=vim.empty_dict(), b={}}) ]])) end) @@ -1028,56 +1349,72 @@ describe('lua stdlib', function() exec_lua("vim.validate{arg1={2, function(a) return (a % 2) == 0 end, 'even number' }}") exec_lua("vim.validate{arg1={5, {'n', 's'} }, arg2={ 'foo', {'n', 's'} }}") - matches('expected table, got number', - pcall_err(exec_lua, "vim.validate{ 1, 'x' }")) - matches('invalid type name: x', - pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}")) - matches('invalid type name: 1', - pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}")) - matches('invalid type name: nil', - pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}")) + matches('expected table, got number', pcall_err(exec_lua, "vim.validate{ 1, 'x' }")) + matches('invalid type name: x', pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}")) + matches('invalid type name: 1', pcall_err(exec_lua, 'vim.validate{ arg1={ 1, 1 }}')) + matches('invalid type name: nil', pcall_err(exec_lua, 'vim.validate{ arg1={ 1 }}')) -- Validated parameters are required by default. - matches('arg1: expected string, got nil', - pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}")) + matches( + 'arg1: expected string, got nil', + pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}") + ) -- Explicitly required. - matches('arg1: expected string, got nil', - pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}")) - - matches('arg1: expected table, got number', - pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}")) - matches('arg2: expected string, got number', - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}")) - matches('arg2: expected string, got nil', - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - matches('arg2: expected string, got nil', - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - matches('arg1: expected even number, got 3', - pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}")) - matches('arg1: expected %?, got 3', - pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}")) - matches('arg1: expected number|string, got nil', - pcall_err(exec_lua, "vim.validate{ arg1={ nil, {'n', 's'} }}")) + matches( + 'arg1: expected string, got nil', + pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}") + ) + + matches('arg1: expected table, got number', pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}")) + matches( + 'arg2: expected string, got number', + pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}") + ) + matches( + 'arg2: expected string, got nil', + pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}") + ) + matches( + 'arg2: expected string, got nil', + pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}") + ) + matches( + 'arg1: expected even number, got 3', + pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}") + ) + matches( + 'arg1: expected %?, got 3', + pcall_err(exec_lua, 'vim.validate{arg1={3, function(a) return a == 1 end}}') + ) + matches( + 'arg1: expected number|string, got nil', + pcall_err(exec_lua, "vim.validate{ arg1={ nil, {'n', 's'} }}") + ) -- Pass an additional message back. - matches('arg1: expected %?, got 3. Info: TEST_MSG', - pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}")) + matches( + 'arg1: expected %?, got 3. Info: TEST_MSG', + pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}") + ) end) it('vim.is_callable', function() - eq(true, exec_lua("return vim.is_callable(function()end)")) - eq(true, exec_lua([[ + eq(true, exec_lua('return vim.is_callable(function()end)')) + eq( + true, + exec_lua([[ local meta = { __call = function()end } local function new_callable() return setmetatable({}, meta) end local callable = new_callable() return vim.is_callable(callable) - ]])) + ]]) + ) - eq(false, exec_lua("return vim.is_callable(1)")) + eq(false, exec_lua('return vim.is_callable(1)')) eq(false, exec_lua("return vim.is_callable('foo')")) - eq(false, exec_lua("return vim.is_callable({})")) + eq(false, exec_lua('return vim.is_callable({})')) end) it('vim.g', function() @@ -1089,24 +1426,26 @@ describe('lua stdlib', function() vim.api.nvim_set_var("to_delete", {hello="world"}) ]] - eq('hi', funcs.luaeval "vim.g.testing") - eq(123, funcs.luaeval "vim.g.other") - eq(5120.1, funcs.luaeval "vim.g.floaty") - eq(NIL, funcs.luaeval "vim.g.nonexistent") - eq(NIL, funcs.luaeval "vim.g.nullvar") + eq('hi', funcs.luaeval 'vim.g.testing') + eq(123, funcs.luaeval 'vim.g.other') + eq(5120.1, funcs.luaeval 'vim.g.floaty') + eq(NIL, funcs.luaeval 'vim.g.nonexistent') + eq(NIL, funcs.luaeval 'vim.g.nullvar') -- lost over RPC, so test locally: - eq({false, true}, exec_lua [[ + eq( + { false, true }, + exec_lua [[ return {vim.g.nonexistent == vim.NIL, vim.g.nullvar == vim.NIL} - ]]) + ]] + ) - eq({hello="world"}, funcs.luaeval "vim.g.to_delete") + eq({ hello = 'world' }, funcs.luaeval 'vim.g.to_delete') exec_lua [[ vim.g.to_delete = nil ]] - eq(NIL, funcs.luaeval "vim.g.to_delete") + eq(NIL, funcs.luaeval 'vim.g.to_delete') - matches([[attempt to index .* nil value]], - pcall_err(exec_lua, 'return vim.g[0].testing')) + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.g[0].testing')) exec_lua [[ local counter = 0 @@ -1173,12 +1512,12 @@ describe('lua stdlib', function() local pathsep = helpers.get_pathsep() local xconfig = 'Xhome' .. pathsep .. 'Xconfig' local xdata = 'Xhome' .. pathsep .. 'Xdata' - local autoload_folder = table.concat({xconfig, 'nvim', 'autoload'}, pathsep) - local autoload_file = table.concat({autoload_folder , 'testload.vim'}, pathsep) + local autoload_folder = table.concat({ xconfig, 'nvim', 'autoload' }, pathsep) + local autoload_file = table.concat({ autoload_folder, 'testload.vim' }, pathsep) mkdir_p(autoload_folder) - write_file(autoload_file , [[let testload#value = 2]]) + write_file(autoload_file, [[let testload#value = 2]]) - clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } } + clear { args_rm = { '-u' }, env = { XDG_CONFIG_HOME = xconfig, XDG_DATA_HOME = xdata } } eq(2, exec_lua("return vim.g['testload#value']")) rmdir('Xhome') @@ -1195,26 +1534,28 @@ describe('lua stdlib', function() vim.api.nvim_buf_set_var(BUF, "testing", "bye") ]] - eq('hi', funcs.luaeval "vim.b.testing") - eq('bye', funcs.luaeval "vim.b[BUF].testing") - eq(123, funcs.luaeval "vim.b.other") - eq(5120.1, funcs.luaeval "vim.b.floaty") - eq(NIL, funcs.luaeval "vim.b.nonexistent") - eq(NIL, funcs.luaeval "vim.b[BUF].nonexistent") - eq(NIL, funcs.luaeval "vim.b.nullvar") + eq('hi', funcs.luaeval 'vim.b.testing') + eq('bye', funcs.luaeval 'vim.b[BUF].testing') + eq(123, funcs.luaeval 'vim.b.other') + eq(5120.1, funcs.luaeval 'vim.b.floaty') + eq(NIL, funcs.luaeval 'vim.b.nonexistent') + eq(NIL, funcs.luaeval 'vim.b[BUF].nonexistent') + eq(NIL, funcs.luaeval 'vim.b.nullvar') -- lost over RPC, so test locally: - eq({false, true}, exec_lua [[ + eq( + { false, true }, + exec_lua [[ return {vim.b.nonexistent == vim.NIL, vim.b.nullvar == vim.NIL} - ]]) + ]] + ) - matches([[attempt to index .* nil value]], - pcall_err(exec_lua, 'return vim.b[BUF][0].testing')) + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.b[BUF][0].testing')) - eq({hello="world"}, funcs.luaeval "vim.b.to_delete") + eq({ hello = 'world' }, funcs.luaeval 'vim.b.to_delete') exec_lua [[ vim.b.to_delete = nil ]] - eq(NIL, funcs.luaeval "vim.b.to_delete") + eq(NIL, funcs.luaeval 'vim.b.to_delete') exec_lua [[ local counter = 0 @@ -1281,9 +1622,9 @@ describe('lua stdlib', function() vim.cmd "vnew" ]] - eq(NIL, funcs.luaeval "vim.b.testing") - eq(NIL, funcs.luaeval "vim.b.other") - eq(NIL, funcs.luaeval "vim.b.nonexistent") + eq(NIL, funcs.luaeval 'vim.b.testing') + eq(NIL, funcs.luaeval 'vim.b.other') + eq(NIL, funcs.luaeval 'vim.b.nonexistent') end) it('vim.w', function() @@ -1299,20 +1640,19 @@ describe('lua stdlib', function() vim.api.nvim_win_set_var(WIN, "testing", "bye") ]] - eq('hi', funcs.luaeval "vim.w.testing") - eq('bye', funcs.luaeval "vim.w[WIN].testing") - eq(123, funcs.luaeval "vim.w.other") - eq(NIL, funcs.luaeval "vim.w.nonexistent") - eq(NIL, funcs.luaeval "vim.w[WIN].nonexistent") + eq('hi', funcs.luaeval 'vim.w.testing') + eq('bye', funcs.luaeval 'vim.w[WIN].testing') + eq(123, funcs.luaeval 'vim.w.other') + eq(NIL, funcs.luaeval 'vim.w.nonexistent') + eq(NIL, funcs.luaeval 'vim.w[WIN].nonexistent') - matches([[attempt to index .* nil value]], - pcall_err(exec_lua, 'return vim.w[WIN][0].testing')) + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.w[WIN][0].testing')) - eq({hello="world"}, funcs.luaeval "vim.w.to_delete") + eq({ hello = 'world' }, funcs.luaeval 'vim.w.to_delete') exec_lua [[ vim.w.to_delete = nil ]] - eq(NIL, funcs.luaeval "vim.w.to_delete") + eq(NIL, funcs.luaeval 'vim.w.to_delete') exec_lua [[ local counter = 0 @@ -1379,9 +1719,9 @@ describe('lua stdlib', function() vim.cmd "vnew" ]] - eq(NIL, funcs.luaeval "vim.w.testing") - eq(NIL, funcs.luaeval "vim.w.other") - eq(NIL, funcs.luaeval "vim.w.nonexistent") + eq(NIL, funcs.luaeval 'vim.w.testing') + eq(NIL, funcs.luaeval 'vim.w.other') + eq(NIL, funcs.luaeval 'vim.w.nonexistent') end) it('vim.t', function() @@ -1391,21 +1731,20 @@ describe('lua stdlib', function() vim.api.nvim_tabpage_set_var(0, "to_delete", {hello="world"}) ]] - eq('hi', funcs.luaeval "vim.t.testing") - eq(123, funcs.luaeval "vim.t.other") - eq(NIL, funcs.luaeval "vim.t.nonexistent") - eq('hi', funcs.luaeval "vim.t[0].testing") - eq(123, funcs.luaeval "vim.t[0].other") - eq(NIL, funcs.luaeval "vim.t[0].nonexistent") + eq('hi', funcs.luaeval 'vim.t.testing') + eq(123, funcs.luaeval 'vim.t.other') + eq(NIL, funcs.luaeval 'vim.t.nonexistent') + eq('hi', funcs.luaeval 'vim.t[0].testing') + eq(123, funcs.luaeval 'vim.t[0].other') + eq(NIL, funcs.luaeval 'vim.t[0].nonexistent') - matches([[attempt to index .* nil value]], - pcall_err(exec_lua, 'return vim.t[0][0].testing')) + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.t[0][0].testing')) - eq({hello="world"}, funcs.luaeval "vim.t.to_delete") + eq({ hello = 'world' }, funcs.luaeval 'vim.t.to_delete') exec_lua [[ vim.t.to_delete = nil ]] - eq(NIL, funcs.luaeval "vim.t.to_delete") + eq(NIL, funcs.luaeval 'vim.t.to_delete') exec_lua [[ local counter = 0 @@ -1461,9 +1800,9 @@ describe('lua stdlib', function() vim.cmd "tabnew" ]] - eq(NIL, funcs.luaeval "vim.t.testing") - eq(NIL, funcs.luaeval "vim.t.other") - eq(NIL, funcs.luaeval "vim.t.nonexistent") + eq(NIL, funcs.luaeval 'vim.t.testing') + eq(NIL, funcs.luaeval 'vim.t.other') + eq(NIL, funcs.luaeval 'vim.t.nonexistent') end) it('vim.env', function() @@ -1487,11 +1826,10 @@ describe('lua stdlib', function() end) it('vim.v', function() - eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval "vim.v.progpath") + eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval 'vim.v.progpath') eq(false, funcs.luaeval "vim.v['false']") - eq(NIL, funcs.luaeval "vim.v.null") - matches([[attempt to index .* nil value]], - pcall_err(exec_lua, 'return vim.v[0].progpath')) + eq(NIL, funcs.luaeval 'vim.v.null') + matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath')) eq('Key is read-only: count', pcall_err(exec_lua, [[vim.v.count = 42]])) eq('Dictionary is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]])) eq('Key is fixed: errmsg', pcall_err(exec_lua, [[vim.v.errmsg = nil]])) @@ -1507,69 +1845,72 @@ describe('lua stdlib', function() eq({}, eval('v:oldfiles')) feed('i foo foo foo<Esc>0/foo<CR>') - eq({1, 1}, meths.win_get_cursor(0)) + eq({ 1, 1 }, meths.win_get_cursor(0)) eq(1, eval('v:searchforward')) feed('n') - eq({1, 5}, meths.win_get_cursor(0)) + eq({ 1, 5 }, meths.win_get_cursor(0)) exec_lua([[vim.v.searchforward = 0]]) eq(0, eval('v:searchforward')) feed('n') - eq({1, 1}, meths.win_get_cursor(0)) + eq({ 1, 1 }, meths.win_get_cursor(0)) exec_lua([[vim.v.searchforward = 1]]) eq(1, eval('v:searchforward')) feed('n') - eq({1, 5}, meths.win_get_cursor(0)) + eq({ 1, 5 }, meths.win_get_cursor(0)) local screen = Screen.new(60, 3) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {background = Screen.colors.Yellow}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.Yellow }, }) screen:attach() eq(1, eval('v:hlsearch')) - screen:expect{grid=[[ + screen:expect { + grid = [[ {1:foo} {1:^foo} {1:foo} | {0:~ }| | - ]]} + ]], + } exec_lua([[vim.v.hlsearch = 0]]) eq(0, eval('v:hlsearch')) - screen:expect{grid=[[ + screen:expect { + grid = [[ foo ^foo foo | {0:~ }| | - ]]} + ]], + } exec_lua([[vim.v.hlsearch = 1]]) eq(1, eval('v:hlsearch')) - screen:expect{grid=[[ + screen:expect { + grid = [[ {1:foo} {1:^foo} {1:foo} | {0:~ }| | - ]]} + ]], + } end) it('vim.bo', function() - eq('', funcs.luaeval "vim.bo.filetype") + eq('', funcs.luaeval 'vim.bo.filetype') exec_lua [[ vim.api.nvim_set_option_value("filetype", "markdown", {}) BUF = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_option_value("modifiable", false, {buf = BUF}) ]] - eq(false, funcs.luaeval "vim.bo.modified") - eq('markdown', funcs.luaeval "vim.bo.filetype") - eq(false, funcs.luaeval "vim.bo[BUF].modifiable") + eq(false, funcs.luaeval 'vim.bo.modified') + eq('markdown', funcs.luaeval 'vim.bo.filetype') + eq(false, funcs.luaeval 'vim.bo[BUF].modifiable') exec_lua [[ vim.bo.filetype = '' vim.bo[BUF].modifiable = true ]] - eq('', funcs.luaeval "vim.bo.filetype") - eq(true, funcs.luaeval "vim.bo[BUF].modifiable") - matches("Unknown option 'nosuchopt'$", - pcall_err(exec_lua, 'return vim.bo.nosuchopt')) - matches("Expected Lua string$", - pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) - matches("Invalid buffer id: %-1$", - pcall_err(exec_lua, 'return vim.bo[-1].filetype')) + eq('', funcs.luaeval 'vim.bo.filetype') + eq(true, funcs.luaeval 'vim.bo[BUF].modifiable') + matches("Unknown option 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt')) + matches('Expected Lua string$', pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) + matches('Invalid buffer id: %-1$', pcall_err(exec_lua, 'return vim.bo[-1].filetype')) end) it('vim.wo', function() @@ -1578,34 +1919,32 @@ describe('lua stdlib', function() vim.cmd "split" vim.api.nvim_set_option_value("cole", 2, {}) ]] - eq(2, funcs.luaeval "vim.wo.cole") + eq(2, funcs.luaeval 'vim.wo.cole') exec_lua [[ vim.wo.conceallevel = 0 ]] - eq(0, funcs.luaeval "vim.wo.cole") - eq(0, funcs.luaeval "vim.wo[0].cole") - eq(0, funcs.luaeval "vim.wo[1001].cole") - matches("Unknown option 'notanopt'$", - pcall_err(exec_lua, 'return vim.wo.notanopt')) - matches("Invalid window id: %-1$", - pcall_err(exec_lua, 'return vim.wo[-1].list')) - eq(2, funcs.luaeval "vim.wo[1000].cole") + eq(0, funcs.luaeval 'vim.wo.cole') + eq(0, funcs.luaeval 'vim.wo[0].cole') + eq(0, funcs.luaeval 'vim.wo[1001].cole') + matches("Unknown option 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt')) + matches('Invalid window id: %-1$', pcall_err(exec_lua, 'return vim.wo[-1].list')) + eq(2, funcs.luaeval 'vim.wo[1000].cole') exec_lua [[ vim.wo[1000].cole = 0 ]] - eq(0, funcs.luaeval "vim.wo[1000].cole") + eq(0, funcs.luaeval 'vim.wo[1000].cole') -- Can handle global-local values exec_lua [[vim.o.scrolloff = 100]] exec_lua [[vim.wo.scrolloff = 200]] - eq(200, funcs.luaeval "vim.wo.scrolloff") + eq(200, funcs.luaeval 'vim.wo.scrolloff') exec_lua [[vim.wo.scrolloff = -1]] - eq(100, funcs.luaeval "vim.wo.scrolloff") + eq(100, funcs.luaeval 'vim.wo.scrolloff') exec_lua [[ vim.wo[0][0].scrolloff = 200 vim.cmd "enew" ]] - eq(100, funcs.luaeval "vim.wo.scrolloff") + eq(100, funcs.luaeval 'vim.wo.scrolloff') end) describe('vim.opt', function() @@ -1638,7 +1977,7 @@ describe('lua stdlib', function() vim.opt.wildignore = { 'hello', 'world' } return vim.o.wildignore ]] - eq(wildignore, "hello,world") + eq(wildignore, 'hello,world') end) it('should allow setting tables with shortnames', function() @@ -1646,7 +1985,7 @@ describe('lua stdlib', function() vim.opt.wig = { 'hello', 'world' } return vim.o.wildignore ]] - eq(wildignore, "hello,world") + eq(wildignore, 'hello,world') end) it('should error when you attempt to set string values to numeric options', function() @@ -1668,7 +2007,9 @@ describe('lua stdlib', function() end) it('should allow you to set boolean values', function() - eq({true, false, true}, exec_lua [[ + eq( + { true, false, true }, + exec_lua [[ local results = {} vim.opt.autoindent = true @@ -1681,7 +2022,8 @@ describe('lua stdlib', function() table.insert(results, vim.bo.autoindent) return results - ]]) + ]] + ) end) it('should change current buffer values and defaults for global local values', function() @@ -1707,20 +2049,20 @@ describe('lua stdlib', function() ]] -- Set -> global & local - eq("global-local", result[1]) - eq("", result[2]) + eq('global-local', result[1]) + eq('', result[2]) -- Setlocal -> only local - eq("global-local", result[3]) - eq("only-local", result[4]) + eq('global-local', result[3]) + eq('only-local', result[4]) -- Setglobal -> only global - eq("only-global", result[5]) - eq("only-local", result[6]) + eq('only-global', result[5]) + eq('only-local', result[6]) -- Set -> sets global value and resets local value - eq("global-local", result[7]) - eq("", result[8]) + eq('global-local', result[7]) + eq('', result[8]) end) it('should allow you to retrieve window opts even if they have not been set', function() @@ -1735,11 +2077,13 @@ describe('lua stdlib', function() return result ]] - eq({false, false, true, true}, result) + eq({ false, false, true, true }, result) end) it('should allow all sorts of string manipulation', function() - eq({'hello', 'hello world', 'start hello world'}, exec_lua [[ + eq( + { 'hello', 'hello world', 'start hello world' }, + exec_lua [[ local results = {} vim.opt.makeprg = "hello" @@ -1752,19 +2096,23 @@ describe('lua stdlib', function() table.insert(results, vim.o.makeprg) return results - ]]) + ]] + ) end) describe('option:get()', function() it('should work for boolean values', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.opt.number = false return vim.opt.number:get() - ]]) + ]] + ) end) it('should work for number values', function() - local tabstop = exec_lua[[ + local tabstop = exec_lua [[ vim.opt.tabstop = 10 return vim.opt.tabstop:get() ]] @@ -1773,10 +2121,13 @@ describe('lua stdlib', function() end) it('should work for string values', function() - eq("hello world", exec_lua [[ + eq( + 'hello world', + exec_lua [[ vim.opt.makeprg = "hello world" return vim.opt.makeprg:get() - ]]) + ]] + ) end) it('should work for set type flaglists', function() @@ -1806,7 +2157,7 @@ describe('lua stdlib', function() ]] eq(3, #wildignore) - eq("*.c", wildignore[1]) + eq('*.c', wildignore[1]) end) it('should work for options that are both commalist and flaglist', function() @@ -1815,14 +2166,14 @@ describe('lua stdlib', function() return vim.opt.whichwrap:get() ]] - eq({b = true, s = true}, result) + eq({ b = true, s = true }, result) result = exec_lua [[ vim.opt.whichwrap = { b = true, s = false, h = true } return vim.opt.whichwrap:get() ]] - eq({b = true, h = true}, result) + eq({ b = true, h = true }, result) end) it('should work for key-value pair options', function() @@ -1832,25 +2183,31 @@ describe('lua stdlib', function() ]] eq({ - tab = "> ", - space = "_", + tab = '> ', + space = '_', }, listchars) end) it('should allow you to add numeric options', function() - eq(16, exec_lua [[ + eq( + 16, + exec_lua [[ vim.opt.tabstop = 12 vim.opt.tabstop = vim.opt.tabstop + 4 return vim.bo.tabstop - ]]) + ]] + ) end) it('should allow you to subtract numeric options', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.opt.tabstop = 4 vim.opt.tabstop = vim.opt.tabstop - 2 return vim.bo.tabstop - ]]) + ]] + ) end) end) @@ -1864,7 +2221,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:.", listchars) + eq('eol:~,space:.', listchars) end) it('should allow adding dictionary style', function() @@ -1879,7 +2236,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:-", listchars) + eq('eol:~,space:-', listchars) end) it('should allow adding dictionary style', function() @@ -1893,7 +2250,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:_", listchars) + eq('eol:~,space:_', listchars) end) it('should allow completely new keys', function() @@ -1907,7 +2264,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:.,tab:>>>", listchars) + eq('eol:~,space:.,tab:>>>', listchars) end) it('should allow subtracting dictionary style', function() @@ -1921,7 +2278,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~", listchars) + eq('eol:~', listchars) end) it('should allow subtracting dictionary style', function() @@ -1935,7 +2292,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("", listchars) + eq('', listchars) end) it('should allow subtracting dictionary style multiple times', function() @@ -1949,7 +2306,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~", listchars) + eq('eol:~', listchars) end) it('should allow adding a key:value string to a listchars', function() @@ -1963,7 +2320,7 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:.,tab:>~", listchars) + eq('eol:~,space:.,tab:>~', listchars) end) it('should allow prepending a key:value string to a listchars', function() @@ -1977,44 +2334,56 @@ describe('lua stdlib', function() return vim.o.listchars ]] - eq("eol:~,space:.,tab:>~", listchars) + eq('eol:~,space:.,tab:>~', listchars) end) end) it('should automatically set when calling remove', function() - eq("foo,baz", exec_lua [[ + eq( + 'foo,baz', + exec_lua [[ vim.opt.wildignore = "foo,bar,baz" vim.opt.wildignore:remove("bar") return vim.o.wildignore - ]]) + ]] + ) end) it('should automatically set when calling remove with a table', function() - eq("foo", exec_lua [[ + eq( + 'foo', + exec_lua [[ vim.opt.wildignore = "foo,bar,baz" vim.opt.wildignore:remove { "bar", "baz" } return vim.o.wildignore - ]]) + ]] + ) end) it('should automatically set when calling append', function() - eq("foo,bar,baz,bing", exec_lua [[ + eq( + 'foo,bar,baz,bing', + exec_lua [[ vim.opt.wildignore = "foo,bar,baz" vim.opt.wildignore:append("bing") return vim.o.wildignore - ]]) + ]] + ) end) it('should automatically set when calling append with a table', function() - eq("foo,bar,baz,bing,zap", exec_lua [[ + eq( + 'foo,bar,baz,bing,zap', + exec_lua [[ vim.opt.wildignore = "foo,bar,baz" vim.opt.wildignore:append { "bing", "zap" } return vim.o.wildignore - ]]) + ]] + ) end) it('should allow adding tables', function() @@ -2106,96 +2475,198 @@ describe('lua stdlib', function() describe('option types', function() it('should allow to set option with numeric value', function() - eq(4, exec_lua [[ + eq( + 4, + exec_lua [[ vim.opt.tabstop = 4 return vim.bo.tabstop - ]]) + ]] + ) - matches("Invalid option type 'string' for 'tabstop'", pcall_err(exec_lua, [[ + matches( + "Invalid option type 'string' for 'tabstop'", + pcall_err( + exec_lua, + [[ vim.opt.tabstop = '4' - ]])) - matches("Invalid option type 'boolean' for 'tabstop'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'boolean' for 'tabstop'", + pcall_err( + exec_lua, + [[ vim.opt.tabstop = true - ]])) - matches("Invalid option type 'table' for 'tabstop'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'table' for 'tabstop'", + pcall_err( + exec_lua, + [[ vim.opt.tabstop = {4, 2} - ]])) - matches("Invalid option type 'function' for 'tabstop'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'function' for 'tabstop'", + pcall_err( + exec_lua, + [[ vim.opt.tabstop = function() return 4 end - ]])) + ]] + ) + ) end) it('should allow to set option with boolean value', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ vim.opt.undofile = true return vim.bo.undofile - ]]) + ]] + ) - matches("Invalid option type 'number' for 'undofile'", pcall_err(exec_lua, [[ + matches( + "Invalid option type 'number' for 'undofile'", + pcall_err( + exec_lua, + [[ vim.opt.undofile = 0 - ]])) - matches("Invalid option type 'table' for 'undofile'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'table' for 'undofile'", + pcall_err( + exec_lua, + [[ vim.opt.undofile = {true} - ]])) - matches("Invalid option type 'string' for 'undofile'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'string' for 'undofile'", + pcall_err( + exec_lua, + [[ vim.opt.undofile = 'true' - ]])) - matches("Invalid option type 'function' for 'undofile'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'function' for 'undofile'", + pcall_err( + exec_lua, + [[ vim.opt.undofile = function() return true end - ]])) + ]] + ) + ) end) it('should allow to set option with array or string value', function() - eq('indent,eol,start', exec_lua [[ + eq( + 'indent,eol,start', + exec_lua [[ vim.opt.backspace = {'indent','eol','start'} return vim.go.backspace - ]]) - eq('indent,eol,start', exec_lua [[ + ]] + ) + eq( + 'indent,eol,start', + exec_lua [[ vim.opt.backspace = 'indent,eol,start' return vim.go.backspace - ]]) + ]] + ) - matches("Invalid option type 'boolean' for 'backspace'", pcall_err(exec_lua, [[ + matches( + "Invalid option type 'boolean' for 'backspace'", + pcall_err( + exec_lua, + [[ vim.opt.backspace = true - ]])) - matches("Invalid option type 'number' for 'backspace'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'number' for 'backspace'", + pcall_err( + exec_lua, + [[ vim.opt.backspace = 2 - ]])) - matches("Invalid option type 'function' for 'backspace'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'function' for 'backspace'", + pcall_err( + exec_lua, + [[ vim.opt.backspace = function() return 'indent,eol,start' end - ]])) + ]] + ) + ) end) it('should allow set option with map or string value', function() - eq("eol:~,space:.", exec_lua [[ + eq( + 'eol:~,space:.', + exec_lua [[ vim.opt.listchars = { eol = "~", space = ".", } return vim.o.listchars - ]]) - eq("eol:~,space:.,tab:>~", exec_lua [[ + ]] + ) + eq( + 'eol:~,space:.,tab:>~', + exec_lua [[ vim.opt.listchars = "eol:~,space:.,tab:>~" return vim.o.listchars - ]]) + ]] + ) - matches("Invalid option type 'boolean' for 'listchars'", pcall_err(exec_lua, [[ + matches( + "Invalid option type 'boolean' for 'listchars'", + pcall_err( + exec_lua, + [[ vim.opt.listchars = true - ]])) - matches("Invalid option type 'number' for 'listchars'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'number' for 'listchars'", + pcall_err( + exec_lua, + [[ vim.opt.listchars = 2 - ]])) - matches("Invalid option type 'function' for 'listchars'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'function' for 'listchars'", + pcall_err( + exec_lua, + [[ vim.opt.listchars = function() return "eol:~,space:.,tab:>~" end - ]])) + ]] + ) + ) end) it('should allow set option with set or string value', function() @@ -2207,23 +2678,44 @@ describe('lua stdlib', function() return vim.go.whichwrap ]] - eq(ww, "b,s") - eq("b,s,<,>,[,]", exec_lua [[ + eq(ww, 'b,s') + eq( + 'b,s,<,>,[,]', + exec_lua [[ vim.opt.whichwrap = "b,s,<,>,[,]" return vim.go.whichwrap - ]]) + ]] + ) - matches("Invalid option type 'boolean' for 'whichwrap'", pcall_err(exec_lua, [[ + matches( + "Invalid option type 'boolean' for 'whichwrap'", + pcall_err( + exec_lua, + [[ vim.opt.whichwrap = true - ]])) - matches("Invalid option type 'number' for 'whichwrap'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'number' for 'whichwrap'", + pcall_err( + exec_lua, + [[ vim.opt.whichwrap = 2 - ]])) - matches("Invalid option type 'function' for 'whichwrap'", pcall_err(exec_lua, [[ + ]] + ) + ) + matches( + "Invalid option type 'function' for 'whichwrap'", + pcall_err( + exec_lua, + [[ vim.opt.whichwrap = function() return "b,s,<,>,[,]" end - ]])) + ]] + ) + ) end) end) @@ -2234,7 +2726,7 @@ describe('lua stdlib', function() return { vim.opt.isfname:get(), vim.go.isfname } ]] - eq({{",", "a", "b", "c"}, "a,b,,,c"}, result) + eq({ { ',', 'a', 'b', 'c' }, 'a,b,,,c' }, result) end) -- isfname=a,b,c,^,,def @@ -2244,77 +2736,101 @@ describe('lua stdlib', function() return { vim.opt.isfname:get(), vim.go.isfname } ]] - eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result) + eq({ { '^,', 'a', 'b', 'c' }, 'a,b,^,,c' }, result) end) - - describe('https://github.com/neovim/neovim/issues/14828', function() it('gives empty list when item is empty:array', function() - eq({}, exec_lua [[ + eq( + {}, + exec_lua [[ vim.cmd("set wildignore=") return vim.opt.wildignore:get() - ]]) + ]] + ) - eq({}, exec_lua [[ + eq( + {}, + exec_lua [[ vim.opt.wildignore = {} return vim.opt.wildignore:get() - ]]) + ]] + ) end) it('gives empty list when item is empty:set', function() - eq({}, exec_lua [[ + eq( + {}, + exec_lua [[ vim.cmd("set formatoptions=") return vim.opt.formatoptions:get() - ]]) + ]] + ) - eq({}, exec_lua [[ + eq( + {}, + exec_lua [[ vim.opt.formatoptions = {} return vim.opt.formatoptions:get() - ]]) + ]] + ) end) it('does not append to empty item', function() - eq({"*.foo", "*.bar"}, exec_lua [[ + eq( + { '*.foo', '*.bar' }, + exec_lua [[ vim.opt.wildignore = {} vim.opt.wildignore:append { "*.foo", "*.bar" } return vim.opt.wildignore:get() - ]]) + ]] + ) end) it('does not prepend to empty item', function() - eq({"*.foo", "*.bar"}, exec_lua [[ + eq( + { '*.foo', '*.bar' }, + exec_lua [[ vim.opt.wildignore = {} vim.opt.wildignore:prepend { "*.foo", "*.bar" } return vim.opt.wildignore:get() - ]]) + ]] + ) end) it('append to empty set', function() - eq({ t = true }, exec_lua [[ + eq( + { t = true }, + exec_lua [[ vim.opt.formatoptions = {} vim.opt.formatoptions:append("t") return vim.opt.formatoptions:get() - ]]) + ]] + ) end) it('prepend to empty set', function() - eq({ t = true }, exec_lua [[ + eq( + { t = true }, + exec_lua [[ vim.opt.formatoptions = {} vim.opt.formatoptions:prepend("t") return vim.opt.formatoptions:get() - ]]) + ]] + ) end) end) end) -- vim.opt describe('vim.opt_local', function() it('appends into global value when changing local option value', function() - eq({ "foo,bar,baz,qux" }, exec_lua [[ + eq( + { 'foo,bar,baz,qux' }, + exec_lua [[ local result = {} vim.opt.tags = "foo,bar" @@ -2324,20 +2840,24 @@ describe('lua stdlib', function() table.insert(result, vim.bo.tags) return result - ]]) + ]] + ) end) end) describe('vim.opt_global', function() it('gets current global option value', function() - eq({ "yes" }, exec_lua [[ + eq( + { 'yes' }, + exec_lua [[ local result = {} vim.cmd "setglobal signcolumn=yes" table.insert(result, vim.opt_global.signcolumn:get()) return result - ]]) + ]] + ) end) end) @@ -2346,15 +2866,15 @@ describe('lua stdlib', function() vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('<abuf>')" vim.cmd "new" ]] - eq('2', funcs.luaeval "BUF") - eq(2, funcs.luaeval "#vim.api.nvim_list_bufs()") + eq('2', funcs.luaeval 'BUF') + eq(2, funcs.luaeval '#vim.api.nvim_list_bufs()') -- vim.cmd can be indexed with a command name exec_lua [[ vim.cmd.let 'g:var = 2' ]] - eq(2, funcs.luaeval "vim.g.var") + eq(2, funcs.luaeval 'vim.g.var') end) it('vim.regex', function() @@ -2363,16 +2883,16 @@ describe('lua stdlib', function() vim.cmd "set nomagic ignorecase" re2 = vim.regex"xYz" ]] - eq({}, exec_lua[[return {re1:match_str("x ac")}]]) - eq({3,7}, exec_lua[[return {re1:match_str("ac abbc")}]]) + eq({}, exec_lua [[return {re1:match_str("x ac")}]]) + eq({ 3, 7 }, exec_lua [[return {re1:match_str("ac abbc")}]]) - meths.buf_set_lines(0, 0, -1, true, {"yy", "abc abbc"}) - eq({}, exec_lua[[return {re1:match_line(0, 0)}]]) - eq({0,3}, exec_lua[[return {re1:match_line(0, 1)}]]) - eq({3,7}, exec_lua[[return {re1:match_line(0, 1, 1)}]]) - eq({3,7}, exec_lua[[return {re1:match_line(0, 1, 1, 8)}]]) - eq({}, exec_lua[[return {re1:match_line(0, 1, 1, 7)}]]) - eq({0,3}, exec_lua[[return {re1:match_line(0, 1, 0, 7)}]]) + meths.buf_set_lines(0, 0, -1, true, { 'yy', 'abc abbc' }) + eq({}, exec_lua [[return {re1:match_line(0, 0)}]]) + eq({ 0, 3 }, exec_lua [[return {re1:match_line(0, 1)}]]) + eq({ 3, 7 }, exec_lua [[return {re1:match_line(0, 1, 1)}]]) + eq({ 3, 7 }, exec_lua [[return {re1:match_line(0, 1, 1, 8)}]]) + eq({}, exec_lua [[return {re1:match_line(0, 1, 1, 7)}]]) + eq({ 0, 3 }, exec_lua [[return {re1:match_line(0, 1, 0, 7)}]]) -- vim.regex() error inside :silent! should not crash. #20546 command([[silent! lua vim.regex('\\z')]]) @@ -2380,46 +2900,49 @@ describe('lua stdlib', function() end) it('vim.defer_fn', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.g.test = false vim.defer_fn(function() vim.g.test = true end, 150) return vim.g.test - ]]) + ]] + ) exec_lua [[vim.wait(1000, function() return vim.g.test end)]] - eq(true, exec_lua[[return vim.g.test]]) + eq(true, exec_lua [[return vim.g.test]]) end) describe('vim.region', function() it('charwise', function() - insert(dedent( [[ + insert(dedent([[ text tααt tααt text text tαxt txtα tex text tαxt tαxt ]])) - eq({5,13}, exec_lua[[ return vim.region(0,{0,5},{0,13},'v',false)[0] ]]) - eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,13},'v',true)[0] ]]) - eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,14},'v',true)[0] ]]) - eq({5,15}, exec_lua[[ return vim.region(0,{0,5},{0,15},'v',false)[0] ]]) - eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,15},'v',true)[0] ]]) - eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,16},'v',true)[0] ]]) - eq({5,17}, exec_lua[[ return vim.region(0,{0,5},{0,17},'v',false)[0] ]]) - eq({5,18}, exec_lua[[ return vim.region(0,{0,5},{0,17},'v',true)[0] ]]) + eq({ 5, 13 }, exec_lua [[ return vim.region(0,{0,5},{0,13},'v',false)[0] ]]) + eq({ 5, 15 }, exec_lua [[ return vim.region(0,{0,5},{0,13},'v',true)[0] ]]) + eq({ 5, 15 }, exec_lua [[ return vim.region(0,{0,5},{0,14},'v',true)[0] ]]) + eq({ 5, 15 }, exec_lua [[ return vim.region(0,{0,5},{0,15},'v',false)[0] ]]) + eq({ 5, 17 }, exec_lua [[ return vim.region(0,{0,5},{0,15},'v',true)[0] ]]) + eq({ 5, 17 }, exec_lua [[ return vim.region(0,{0,5},{0,16},'v',true)[0] ]]) + eq({ 5, 17 }, exec_lua [[ return vim.region(0,{0,5},{0,17},'v',false)[0] ]]) + eq({ 5, 18 }, exec_lua [[ return vim.region(0,{0,5},{0,17},'v',true)[0] ]]) end) it('blockwise', function() insert([[αα]]) - eq({0,5}, exec_lua[[ return vim.region(0,{0,0},{0,4},'3',true)[0] ]]) + eq({ 0, 5 }, exec_lua [[ return vim.region(0,{0,0},{0,4},'3',true)[0] ]]) end) it('linewise', function() - insert(dedent( [[ + insert(dedent([[ text tααt tααt text text tαxt txtα tex text tαxt tαxt ]])) - eq({0,-1}, exec_lua[[ return vim.region(0,{1,5},{1,14},'V',true)[1] ]]) + eq({ 0, -1 }, exec_lua [[ return vim.region(0,{1,5},{1,14},'V',true)[1] ]]) end) it('getpos() input', function() insert('getpos') - eq({0,6}, exec_lua[[ return vim.region(0,{0,0},'.','v',true)[0] ]]) + eq({ 0, 6 }, exec_lua [[ return vim.region(0,{0,0},'.','v',true)[0] ]]) end) end) @@ -2518,9 +3041,9 @@ describe('lua stdlib', function() table.insert(keys, buf) end) ]] - insert("hello") + insert('hello') - eq('iworld<ESC>', exec_lua[[return table.concat(keys, '')]]) + eq('iworld<ESC>', exec_lua [[return table.concat(keys, '')]]) end) it('can call vim.fn functions on Ctrl-C #17273', function() @@ -2534,7 +3057,7 @@ describe('lua stdlib', function() end) ]]) feed('/') - poke_eventloop() -- This is needed because Ctrl-C flushes input + poke_eventloop() -- This is needed because Ctrl-C flushes input feed('<C-C>') eq('/', exec_lua([[return _G.ctrl_c_cmdtype]])) end) @@ -2542,7 +3065,7 @@ describe('lua stdlib', function() describe('vim.wait', function() before_each(function() - exec_lua[[ + exec_lua [[ -- high precision timer get_time = function() return vim.fn.reltimefloat(vim.fn.reltime()) @@ -2551,11 +3074,13 @@ describe('lua stdlib', function() end) it('should run from lua', function() - exec_lua[[vim.wait(100, function() return true end)]] + exec_lua [[vim.wait(100, function() return true end)]] end) it('should wait the expected time if false', function() - eq({time = true, wait_result = {false, -1}}, exec_lua[[ + eq( + { time = true, wait_result = { false, -1 } }, + exec_lua [[ start_time = get_time() wait_succeed, wait_fail_val = vim.wait(200, function() return false end) @@ -2564,11 +3089,14 @@ describe('lua stdlib', function() time = (start_time + 0.15) < get_time(), wait_result = {wait_succeed, wait_fail_val} } - ]]) + ]] + ) end) it('should not block other events', function() - eq({time = true, wait_result = true}, exec_lua[[ + eq( + { time = true, wait_result = true }, + exec_lua [[ start_time = get_time() vim.g.timer_result = false @@ -2586,11 +3114,14 @@ describe('lua stdlib', function() time = (start_time + 5) > get_time(), wait_result = wait_result, } - ]]) + ]] + ) end) it('should not process non-fast events when commanded', function() - eq({wait_result = false}, exec_lua[[ + eq( + { wait_result = false }, + exec_lua [[ start_time = get_time() vim.g.timer_result = false @@ -2606,11 +3137,14 @@ describe('lua stdlib', function() return { wait_result = wait_result, } - ]]) + ]] + ) end) it('should work with vim.defer_fn', function() - eq({time = true, wait_result = true}, exec_lua[[ + eq( + { time = true, wait_result = true }, + exec_lua [[ start_time = get_time() vim.defer_fn(function() vim.g.timer_result = true end, 100) @@ -2620,94 +3154,124 @@ describe('lua stdlib', function() time = (start_time + 5) > get_time(), wait_result = wait_result, } - ]]) + ]] + ) end) it('should not crash when callback errors', function() local result = exec_lua [[ return {pcall(function() vim.wait(1000, function() error("As Expected") end) end)} ]] - eq({false, '[string "<nvim>"]:1: As Expected'}, {result[1], remove_trace(result[2])}) + eq({ false, '[string "<nvim>"]:1: As Expected' }, { result[1], remove_trace(result[2]) }) end) it('if callback is passed, it must be a function', function() - eq({false, 'vim.wait: if passed, condition must be a function'}, exec_lua [[ + eq( + { false, 'vim.wait: if passed, condition must be a function' }, + exec_lua [[ return {pcall(function() vim.wait(1000, 13) end)} - ]]) + ]] + ) end) it('should allow waiting with no callback, explicit', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local start_time = vim.uv.hrtime() vim.wait(50, nil) return vim.uv.hrtime() - start_time > 25000 - ]]) + ]] + ) end) it('should allow waiting with no callback, implicit', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local start_time = vim.uv.hrtime() vim.wait(50) return vim.uv.hrtime() - start_time > 25000 - ]]) + ]] + ) end) it('should call callbacks exactly once if they return true immediately', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ vim.g.wait_count = 0 vim.wait(1000, function() vim.g.wait_count = vim.g.wait_count + 1 return true end, 20) return vim.g.wait_count == 1 - ]]) + ]] + ) end) it('should call callbacks few times with large `interval`', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ vim.g.wait_count = 0 vim.wait(50, function() vim.g.wait_count = vim.g.wait_count + 1 end, 200) return vim.g.wait_count < 5 - ]]) + ]] + ) end) it('should play nice with `not` when fails', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ if not vim.wait(50, function() end) then return true end return false - ]]) + ]] + ) end) it('should play nice with `if` when success', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ if vim.wait(50, function() return true end) then return true end return false - ]]) + ]] + ) end) it('should return immediately with false if timeout is 0', function() - eq({false, -1}, exec_lua [[ + eq( + { false, -1 }, + exec_lua [[ return { vim.wait(0, function() return false end) } - ]]) + ]] + ) end) it('should work with tables with __call', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local t = setmetatable({}, {__call = function(...) return true end}) return vim.wait(100, t, 10) - ]]) + ]] + ) end) it('should work with tables with __call that change', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local t = {count = 0} setmetatable(t, { __call = function() @@ -2717,7 +3281,8 @@ describe('lua stdlib', function() }) return vim.wait(1000, t, 10) - ]]) + ]] + ) end) it('should not work with negative intervals', function() @@ -2751,9 +3316,9 @@ describe('lua stdlib', function() end ]]) feed(':lua _G.Wait()<CR>') - eq({'notification', 'ready', {}}, next_msg(500)) + eq({ 'notification', 'ready', {} }, next_msg(500)) feed('<C-C>') - eq({'notification', 'wait', {-2}}, next_msg(500)) + eq({ 'notification', 'wait', { -2 } }, next_msg(500)) end) it('with callback', function() @@ -2765,9 +3330,9 @@ describe('lua stdlib', function() end ]]) feed(':lua _G.Wait()<CR>') - eq({'notification', 'ready', {}}, next_msg(500)) + eq({ 'notification', 'ready', {} }, next_msg(500)) feed('<C-C>') - eq({'notification', 'wait', {-2}}, next_msg(500)) + eq({ 'notification', 'wait', { -2 } }, next_msg(500)) end) end) @@ -2790,29 +3355,35 @@ describe('lua stdlib', function() end) it('vim.notify_once', function() - local screen = Screen.new(60,5) + local screen = Screen.new(60, 5) screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {foreground=Screen.colors.Red}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { foreground = Screen.colors.Red }, }) screen:attach() - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*3 | - ]]} + ]], + } exec_lua [[vim.notify_once("I'll only tell you this once...", vim.log.levels.WARN)]] - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*3 {1:I'll only tell you this once...} | - ]]} + ]], + } feed('<C-l>') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | {0:~ }|*3 | - ]]} + ]], + } exec_lua [[vim.notify_once("I'll only tell you this once...")]] screen:expect_unchanged() end) @@ -2825,13 +3396,13 @@ describe('lua stdlib', function() end) fun("BOB", nil, "MIKE") ]] - eq({'notification', 'mayday_mayday', {{a='BOB', c='MIKE'}}}, next_msg()) + eq({ 'notification', 'mayday_mayday', { { a = 'BOB', c = 'MIKE' } } }, next_msg()) -- let's gooooo exec_lua [[ vim.schedule_wrap(function(...) vim.rpcnotify(1, 'boogalo', select('#', ...)) end)(nil,nil,nil,nil) ]] - eq({'notification', 'boogalo', {4}}, next_msg()) + eq({ 'notification', 'boogalo', { 4 } }, next_msg()) end) end) @@ -2843,8 +3414,8 @@ describe('lua stdlib', function() return buf2 ]] - eq(false, meths.get_option_value('autoindent', {buf=buf1})) - eq(false, meths.get_option_value('autoindent', {buf=buf2})) + eq(false, meths.get_option_value('autoindent', { buf = buf1 })) + eq(false, meths.get_option_value('autoindent', { buf = buf2 })) local val = exec_lua [[ return vim.api.nvim_buf_call(buf2, function() @@ -2853,8 +3424,8 @@ describe('lua stdlib', function() end) ]] - eq(false, meths.get_option_value('autoindent', {buf=buf1})) - eq(true, meths.get_option_value('autoindent', {buf=buf2})) + eq(false, meths.get_option_value('autoindent', { buf = buf1 })) + eq(true, meths.get_option_value('autoindent', { buf = buf2 })) eq(buf1, meths.get_current_buf().id) eq(buf2, val) end) @@ -2871,7 +3442,9 @@ describe('lua stdlib', function() end) it('can be nested crazily with hidden buffers', function() - eq(true, exec_lua([[ + eq( + true, + exec_lua([[ local function scratch_buf_call(fn) local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_option_value('cindent', true, {buf = buf}) @@ -2907,7 +3480,8 @@ describe('lua stdlib', function() end) end) end) - ]])) + ]]) + ) end) end) @@ -2922,8 +3496,8 @@ describe('lua stdlib', function() ]] command('wincmd p') - eq('', meths.get_option_value('winhighlight', {win=win1})) - eq('', meths.get_option_value('winhighlight', {win=win2})) + eq('', meths.get_option_value('winhighlight', { win = win1 })) + eq('', meths.get_option_value('winhighlight', { win = win2 })) local val = exec_lua [[ return vim.api.nvim_win_call(win2, function() @@ -2932,8 +3506,8 @@ describe('lua stdlib', function() end) ]] - eq('', meths.get_option_value('winhighlight', {win=win1})) - eq('Normal:Normal', meths.get_option_value('winhighlight', {win=win2})) + eq('', meths.get_option_value('winhighlight', { win = win1 })) + eq('Normal:Normal', meths.get_option_value('winhighlight', { win = win2 })) eq(win1, meths.get_current_win().id) eq(win2, val) end) @@ -2972,8 +3546,8 @@ describe('lua stdlib', function() -- Fixed for win_execute in vim-patch:8.1.2124, but should've applied to nvim_win_call too! local screen = Screen.new(30, 5) screen:set_default_attr_ids { - [1] = {reverse = true}, - [2] = {bold = true, reverse = true}, + [1] = { reverse = true }, + [2] = { bold = true, reverse = true }, } screen:attach() exec_lua [[ @@ -3010,71 +3584,94 @@ describe('lua stdlib', function() describe('vim.iconv', function() it('can convert strings', function() - eq('hello', exec_lua[[ + eq( + 'hello', + exec_lua [[ return vim.iconv('hello', 'latin1', 'utf-8') - ]]) + ]] + ) end) it('can validate arguments', function() - eq({false, 'Expected at least 3 arguments'}, exec_lua[[ + eq( + { false, 'Expected at least 3 arguments' }, + exec_lua [[ return {pcall(vim.iconv, 'hello')} - ]]) + ]] + ) - eq({false, 'bad argument #3 to \'?\' (expected string)'}, exec_lua[[ + eq( + { false, "bad argument #3 to '?' (expected string)" }, + exec_lua [[ return {pcall(vim.iconv, 'hello', 'utf-8', true)} - ]]) + ]] + ) end) it('can handle bad encodings', function() - eq(NIL, exec_lua[[ + eq( + NIL, + exec_lua [[ return vim.iconv('hello', 'foo', 'bar') - ]]) + ]] + ) end) it('can handle strings with NUL bytes', function() - eq(7, exec_lua[[ + eq( + 7, + exec_lua [[ local a = string.char(97, 98, 99, 0, 100, 101, 102) -- abc\0def return string.len(vim.iconv(a, 'latin1', 'utf-8')) - ]]) + ]] + ) end) - end) - describe("vim.defaulttable", function() - it("creates nested table by default", function() - eq({ b = {c = 1 } }, exec_lua[[ + describe('vim.defaulttable', function() + it('creates nested table by default', function() + eq( + { b = { c = 1 } }, + exec_lua [[ local a = vim.defaulttable() a.b.c = 1 return a - ]]) + ]] + ) end) - it("allows to create default objects", function() - eq({ b = 1 }, exec_lua[[ + it('allows to create default objects', function() + eq( + { b = 1 }, + exec_lua [[ local a = vim.defaulttable(function() return 0 end) a.b = a.b + 1 return a - ]]) + ]] + ) end) it('accepts the key name', function() - eq({ b = 'b', c = 'c' }, exec_lua [[ + eq( + { b = 'b', c = 'c' }, + exec_lua [[ local a = vim.defaulttable(function(k) return k end) local _ = a.b local _ = a.c return a - ]]) + ]] + ) end) end) it('vim.lua_omnifunc', function() - local screen = Screen.new(60,5) + local screen = Screen.new(60, 5) screen:set_default_attr_ids { - [1] = {foreground = Screen.colors.Blue1, bold = true}; - [2] = {background = Screen.colors.WebGray}; - [3] = {background = Screen.colors.LightMagenta}; - [4] = {bold = true}; - [5] = {foreground = Screen.colors.SeaGreen, bold = true}; + [1] = { foreground = Screen.colors.Blue1, bold = true }, + [2] = { background = Screen.colors.WebGray }, + [3] = { background = Screen.colors.LightMagenta }, + [4] = { bold = true }, + [5] = { foreground = Screen.colors.SeaGreen, bold = true }, } screen:attach() command [[ set omnifunc=v:lua.vim.lua_omnifunc ]] @@ -3082,22 +3679,27 @@ describe('lua stdlib', function() -- Note: the implementation is shared with lua command line completion. -- More tests for completion in lua/command_line_completion_spec.lua feed [[ivim.insp<c-x><c-o>]] - screen:expect{grid=[[ + screen:expect { + grid = [[ vim.inspect^ | {1:~ }{2: inspect }{1: }| {1:~ }{3: inspect_pos }{1: }| {1:~ }| {4:-- Omni completion (^O^N^P) }{5:match 1 of 2} | - ]]} + ]], + } end) it('vim.print', function() -- vim.print() returns its args. - eq({42, 'abc', { a = { b = 77 }}}, - exec_lua[[return {vim.print(42, 'abc', { a = { b = 77 }})}]]) + eq( + { 42, 'abc', { a = { b = 77 } } }, + exec_lua [[return {vim.print(42, 'abc', { a = { b = 77 }})}]] + ) -- vim.print() pretty-prints the args. - eq(dedent[[ + eq( + dedent [[ 42 abc @@ -3106,12 +3708,14 @@ describe('lua stdlib', function() b = 77 } }]], - eval[[execute('lua vim.print(42, "abc", { a = { b = 77 }})')]]) + eval [[execute('lua vim.print(42, "abc", { a = { b = 77 }})')]] + ) end) it('vim.F.if_nil', function() local function if_nil(...) - return exec_lua([[ + return exec_lua( + [[ local args = {...} local nargs = select('#', ...) for i = 1, nargs do @@ -3120,7 +3724,9 @@ describe('lua stdlib', function() end end return vim.F.if_nil(unpack(args, 1, nargs)) - ]], ...) + ]], + ... + ) end local a = NIL @@ -3136,15 +3742,18 @@ describe('lua stdlib', function() end) it('lpeg', function() - eq(5, exec_lua [[ + eq( + 5, + exec_lua [[ local m = vim.lpeg return m.match(m.R'09'^1, '4504ab') - ]]) + ]] + ) eq(4, exec_lua [[ return vim.re.match("abcde", '[a-c]+') ]]) end) - it("vim.ringbuf", function() + it('vim.ringbuf', function() local results = exec_lua([[ local ringbuf = vim.ringbuf(3) ringbuf:push("a") -- idx: 0 @@ -3172,14 +3781,14 @@ describe('lua stdlib', function() } ]]) local expected = { - peeka1 = "a", - peeka2 = "a", - pop1 = "a", + peeka1 = 'a', + peeka2 = 'a', + pop1 = 'a', pop2 = nil, - pop3 = "b", - pop4 = "c", - pop5 = "d", - pop_after_add_b = "a", + pop3 = 'b', + pop4 = 'c', + pop5 = 'd', + pop_after_add_b = 'a', } eq(expected, results) end) @@ -3187,8 +3796,8 @@ end) describe('lua: builtin modules', function() local function do_tests() - eq(2, exec_lua[[return vim.tbl_count {x=1,y=2}]]) - eq('{ 10, "spam" }', exec_lua[[return vim.inspect {10, 'spam'}]]) + eq(2, exec_lua [[return vim.tbl_count {x=1,y=2}]]) + eq('{ 10, "spam" }', exec_lua [[return vim.inspect {10, 'spam'}]]) end it('works', function() @@ -3202,17 +3811,23 @@ describe('lua: builtin modules', function() end) it('works without runtime', function() - clear{env={VIMRUNTIME='fixtures/a'}} + clear { env = { VIMRUNTIME = 'fixtures/a' } } do_tests() end) - it('fails when disabled without runtime', function() clear() command("let $VIMRUNTIME='fixtures/a'") -- Use system([nvim,…]) instead of clear() to avoid stderr noise. #21844 - local out = funcs.system({nvim_prog, '--clean', '--luamod-dev', - [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]], '+qa!'}):gsub('\r\n', '\n') + local out = funcs + .system({ + nvim_prog, + '--clean', + '--luamod-dev', + [[+call nvim_exec_lua('return vim.tbl_count {x=1,y=2}')]], + '+qa!', + }) + :gsub('\r\n', '\n') eq(1, eval('v:shell_error')) matches("'vim%.shared' not found", out) end) @@ -3229,7 +3844,7 @@ describe('lua: require("mod") from packages', function() return err ]] - matches("unexpected symbol", syntax_error_msg) + matches('unexpected symbol', syntax_error_msg) end) it('uses the right order of mod.lua vs mod/init.lua', function() @@ -3246,15 +3861,18 @@ describe('vim.keymap', function() before_each(clear) it('can make a mapping', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) end) it('can make an expr mapping', function() @@ -3264,19 +3882,22 @@ describe('vim.keymap', function() feed('aa') - eq({'π<M-π>foo<'}, meths.buf_get_lines(0, 0, -1, false)) + eq({ 'π<M-π>foo<' }, meths.buf_get_lines(0, 0, -1, false)) end) it('can overwrite a mapping', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount - 1 end) @@ -3284,19 +3905,22 @@ describe('vim.keymap', function() feed('asdf\n') - eq(0, exec_lua[[return GlobalCount]]) + eq(0, exec_lua [[return GlobalCount]]) end) it('can unmap a mapping', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.keymap.del('n', 'asdf') @@ -3304,20 +3928,23 @@ describe('vim.keymap', function() feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) it('works with buffer-local mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end, {buffer=true}) return GlobalCount - ]]) + ]] + ) feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) exec_lua [[ vim.keymap.del('n', 'asdf', {buffer=true}) @@ -3325,42 +3952,54 @@ describe('vim.keymap', function() feed('asdf\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) it('does not mutate the opts parameter', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ opts = {buffer=true} vim.keymap.set('n', 'asdf', function() end, opts) return opts.buffer - ]]) - eq(true, exec_lua [[ + ]] + ) + eq( + true, + exec_lua [[ vim.keymap.del('n', 'asdf', opts) return opts.buffer - ]]) + ]] + ) end) it('can do <Plug> mappings', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ GlobalCount = 0 vim.keymap.set('n', '<plug>(asdf)', function() GlobalCount = GlobalCount + 1 end) vim.keymap.set('n', 'ww', '<plug>(asdf)') return GlobalCount - ]]) + ]] + ) feed('ww\n') - eq(1, exec_lua[[return GlobalCount]]) + eq(1, exec_lua [[return GlobalCount]]) end) end) describe('Vimscript function exists()', function() it('can check a lua function', function() - eq(1, exec_lua[[ + eq( + 1, + exec_lua [[ _G.test = function() print("hello") end return vim.fn.exists('v:lua.test') - ]]) + ]] + ) eq(1, funcs.exists('v:lua.require("mpack").decode')) eq(1, funcs.exists("v:lua.require('mpack').decode")) diff --git a/test/functional/lua/watch_spec.lua b/test/functional/lua/watch_spec.lua index cdcef08a1a..106d40fe0e 100644 --- a/test/functional/lua/watch_spec.lua +++ b/test/functional/lua/watch_spec.lua @@ -12,7 +12,7 @@ describe('vim._watch', function() describe('watch', function() it('detects file changes', function() - skip(is_os('bsd'), "Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38") + skip(is_os('bsd'), 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38') local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( @@ -99,7 +99,7 @@ describe('vim._watch', function() describe('poll', function() it('detects file changes', function() - skip(is_os('bsd'), "bsd only reports rename on folders if file inside change") + skip(is_os('bsd'), 'bsd only reports rename on folders if file inside change') local root_dir = vim.uv.fs_mkdtemp(vim.fs.dirname(helpers.tmpname()) .. '/nvim_XXXXXXXXXX') local result = exec_lua( @@ -165,12 +165,12 @@ describe('vim._watch', function() local expected = { { change_type = created, - path = root_dir .. "/file", + path = root_dir .. '/file', }, { change_type = deleted, - path = root_dir .. "/file", - } + path = root_dir .. '/file', + }, } eq(expected, result) end) diff --git a/test/functional/lua/xdiff_spec.lua b/test/functional/lua/xdiff_spec.lua index 3121ac051f..0563161adb 100644 --- a/test/functional/lua/xdiff_spec.lua +++ b/test/functional/lua/xdiff_spec.lua @@ -11,7 +11,7 @@ describe('xdiff bindings', function() describe('can diff text', function() before_each(function() - exec_lua[[ + exec_lua [[ a1 = 'Hello\n' b1 = 'Helli\n' @@ -21,15 +21,14 @@ describe('xdiff bindings', function() end) it('with no callback', function() - eq( table.concat({ '@@ -1 +1 @@', '-Hello', '+Helli', - '' + '', }, '\n'), - exec_lua("return vim.diff(a1, b1)") + exec_lua('return vim.diff(a1, b1)') ) eq( @@ -41,11 +40,10 @@ describe('xdiff bindings', function() '-foo', '+bar', '+baz', - '' + '', }, '\n'), - exec_lua("return vim.diff(a2, b2)") + exec_lua('return vim.diff(a2, b2)') ) - end) it('with callback', function() @@ -53,43 +51,55 @@ describe('xdiff bindings', function() exp[#exp+1] = {sa, ca, sb, cb} end]]) - eq({{1, 1, 1, 1}}, exec_lua[[ + eq( + { { 1, 1, 1, 1 } }, + exec_lua [[ exp = {} assert(vim.diff(a1, b1, {on_hunk = on_hunk}) == nil) return exp - ]]) + ]] + ) - eq({{1, 1, 1, 1}, {3, 1, 3, 2}}, exec_lua[[ + eq( + { { 1, 1, 1, 1 }, { 3, 1, 3, 2 } }, + exec_lua [[ exp = {} assert(vim.diff(a2, b2, {on_hunk = on_hunk}) == nil) return exp - ]]) + ]] + ) -- gives higher precedence to on_hunk over result_type - eq({{1, 1, 1, 1}, {3, 1, 3, 2}}, exec_lua[[ + eq( + { { 1, 1, 1, 1 }, { 3, 1, 3, 2 } }, + exec_lua [[ exp = {} assert(vim.diff(a2, b2, {on_hunk = on_hunk, result_type='indices'}) == nil) return exp - ]]) + ]] + ) end) it('with error callback', function() - exec_lua[[ + exec_lua [[ on_hunk = function(sa, ca, sb, cb) error('ERROR1') end ]] - eq([[error running function on_hunk: [string "<nvim>"]:0: ERROR1]], - pcall_err(exec_lua, [[vim.diff(a1, b1, {on_hunk = on_hunk})]])) + eq( + [[error running function on_hunk: [string "<nvim>"]:0: ERROR1]], + pcall_err(exec_lua, [[vim.diff(a1, b1, {on_hunk = on_hunk})]]) + ) end) it('with hunk_lines', function() - eq({{1, 1, 1, 1}}, - exec_lua([[return vim.diff(a1, b1, {result_type = 'indices'})]])) + eq({ { 1, 1, 1, 1 } }, exec_lua([[return vim.diff(a1, b1, {result_type = 'indices'})]])) - eq({{1, 1, 1, 1}, {3, 1, 3, 2}}, - exec_lua([[return vim.diff(a2, b2, {result_type = 'indices'})]])) + eq( + { { 1, 1, 1, 1 }, { 3, 1, 3, 2 } }, + exec_lua([[return vim.diff(a2, b2, {result_type = 'indices'})]]) + ) end) it('can run different algorithms', function() @@ -101,7 +111,8 @@ describe('xdiff bindings', function() '.bar {', ' margin: 0;', '}', - ''}, '\n') + '', + }, '\n') local b = table.concat({ '.bar {', @@ -112,10 +123,12 @@ describe('xdiff bindings', function() ' margin: 0;', ' color: green;', '}', - ''}, '\n') + '', + }, '\n') eq( - table.concat({'@@ -1,4 +0,0 @@', + table.concat({ + '@@ -1,4 +0,0 @@', '-.foo1 {', '- margin: 0;', '-}', @@ -126,31 +139,37 @@ describe('xdiff bindings', function() '+ margin: 0;', '+ color: green;', '+}', - ''}, '\n'), - exec_lua([[ + '', + }, '\n'), + exec_lua( + [[ local args = {...} return vim.diff(args[1], args[2], { algorithm = 'patience' }) - ]], a, b)) + ]], + a, + b + ) + ) end) end) it('can handle bad args', function() - eq([[Expected at least 2 arguments]], - pcall_err(exec_lua, [[vim.diff('a')]])) - - eq([[bad argument #1 to 'diff' (expected string)]], - pcall_err(exec_lua, [[vim.diff(1, 2)]])) + eq([[Expected at least 2 arguments]], pcall_err(exec_lua, [[vim.diff('a')]])) - eq([[bad argument #3 to 'diff' (expected table)]], - pcall_err(exec_lua, [[vim.diff('a', 'b', true)]])) + eq([[bad argument #1 to 'diff' (expected string)]], pcall_err(exec_lua, [[vim.diff(1, 2)]])) - eq([[unexpected key: bad_key]], - pcall_err(exec_lua, [[vim.diff('a', 'b', { bad_key = true })]])) + eq( + [[bad argument #3 to 'diff' (expected table)]], + pcall_err(exec_lua, [[vim.diff('a', 'b', true)]]) + ) - eq([[on_hunk is not a function]], - pcall_err(exec_lua, [[vim.diff('a', 'b', { on_hunk = true })]])) + eq([[unexpected key: bad_key]], pcall_err(exec_lua, [[vim.diff('a', 'b', { bad_key = true })]])) + eq( + [[on_hunk is not a function]], + pcall_err(exec_lua, [[vim.diff('a', 'b', { on_hunk = true })]]) + ) end) end) |