diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-19 22:57:13 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-19 22:57:13 +0000 |
commit | 9be89f131f87608f224f0ee06d199fcd09d32176 (patch) | |
tree | 11022dcfa9e08cb4ac5581b16734196128688d48 /test/functional/lua/vim_spec.lua | |
parent | ff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff) | |
parent | 88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff) | |
download | rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2 rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/lua/vim_spec.lua')
-rw-r--r-- | test/functional/lua/vim_spec.lua | 402 |
1 files changed, 236 insertions, 166 deletions
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index c8f94c6ffa..3c65ec664e 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -135,19 +135,19 @@ describe('lua stdlib', function() -- See MAINTAIN.md for the soft/hard deprecation policy describe(('vim.deprecate prerel=%s,'):format(prerel or 'nil'), function() - local curver = exec_lua('return vim.version()') --[[@as {major:number, minor:number}]] - -- "0.10" or "0.10-dev+xxx" - local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') - -- "0.10" or "0.11" - local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1)) - local was_removed = prerel and 'was removed' or 'will be removed' + local curver --- @type {major:number, minor:number} + + before_each(function() + curver = exec_lua('return vim.version()') + end) it('plugin=nil, same message skipped', function() + -- "0.10" or "0.10-dev+xxx" + local curstr = ('%s.%s%s'):format(curver.major, curver.minor, prerel or '') eq( - dedent( - [[ - foo.bar() is deprecated. Run ":checkhealth vim.deprecated" for more information]] - ):format(curstr), + ([[foo.bar() is deprecated. Run ":checkhealth vim.deprecated" for more information]]):format( + curstr + ), exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', curstr) ) -- Same message as above; skipped this time. @@ -162,6 +162,10 @@ describe('lua stdlib', function() end) it('plugin=nil, show error if hard-deprecated', function() + -- "0.10" or "0.11" + local nextver = ('%s.%s'):format(curver.major, curver.minor + (prerel and 0 or 1)) + + local was_removed = prerel and 'was removed' or 'will be removed' eq( dedent( [[ @@ -173,8 +177,7 @@ describe('lua stdlib', function() it('plugin=nil, to be deleted in the next major version (1.0)', function() eq( - dedent [[ - foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]], + [[foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]], exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]] ) end) @@ -535,12 +538,6 @@ describe('lua stdlib', function() matches('big failure\nvery async', remove_trace(eval('v:errmsg'))) 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 }, - }) screen:attach() screen:expect { grid = [[ @@ -559,11 +556,11 @@ describe('lua stdlib', function() ]]) 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}^ | + {9:stack traceback:} | + {9: [C]: in function 'nvim_command'} | + {9: [string "<nvim>"]:2: in function <[string "<nvim>"]:}| + {9:1>} | + {6:Press ENTER or type command to continue}^ | ]], } end) @@ -1062,7 +1059,7 @@ describe('lua stdlib', function() local a = { a = {[2] = 3} } local b = { a = {[3] = 3} } local c = vim.tbl_deep_extend("force", a, b) - return vim.deep_equal(c, {a = {[3] = 3}}) + return vim.deep_equal(c, {a = {[2] = 3, [3] = 3}}) ]])) eq( @@ -1074,34 +1071,28 @@ describe('lua stdlib', function() ]]) ) - matches( - 'invalid "behavior": nil', - pcall_err( - exec_lua, - [[ - return vim.tbl_deep_extend() - ]] - ) - ) + ok(exec_lua([[ + local a = { sub = { 'a', 'b' } } + local b = { sub = { 'b', 'c' } } + local c = vim.tbl_deep_extend('force', a, b) + return vim.deep_equal(c, { sub = { 'b', 'c' } }) + ]])) + + 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, - [[ - return vim.tbl_deep_extend("keep") - ]] - ) + 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, - [[ - return vim.tbl_deep_extend("keep", {}) - ]] - ) + pcall_err(exec_lua, [[return vim.tbl_deep_extend("keep", {})]]) + ) + + matches( + 'after the second argument%: expected table, got number', + pcall_err(exec_lua, [[return vim.tbl_deep_extend("keep", {}, 42)]]) ) end) @@ -1200,8 +1191,7 @@ describe('lua stdlib', function() ]]) eq(true, exec_lua([[return next(vim.fn.FooFunc(3)) == nil ]])) 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(true, exec_lua([[return vim.tbl_isempty(vim.api.nvim_call_function("FooFunc", {5}))]])) eq(5, eval('g:test')) eq({ 2, 'foo', true }, exec_lua([[return vim.fn.VarArg(2, "foo", true)]])) @@ -1239,7 +1229,7 @@ describe('lua stdlib', function() ) end) - it('vim.fn should error when calling API function', function() + it('vim.fn errors 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()') @@ -1314,12 +1304,6 @@ describe('lua stdlib', function() end) 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 }, - }) screen:attach() exec_lua([[ timer = vim.uv.new_timer() @@ -1332,13 +1316,13 @@ describe('lua stdlib', function() ]]) screen:expect { grid = [[ - {3:[string "<nvim>"]:6: E5560: rpcrequest must not be}| - {3: called in a lua loop callback} | - {3:stack traceback:} | - {3: [C]: in function 'rpcrequest'} | - {3: [string "<nvim>"]:6: in function <[string }| - {3:"<nvim>"]:2>} | - {4:Press ENTER or type command to continue}^ | + {9:[string "<nvim>"]:6: E5560: rpcrequest must not be}| + {9: called in a lua loop callback} | + {9:stack traceback:} | + {9: [C]: in function 'rpcrequest'} | + {9: [string "<nvim>"]:6: in function <[string }| + {9:"<nvim>"]:2>} | + {6:Press ENTER or type command to continue}^ | ]], } feed('<cr>') @@ -1408,7 +1392,25 @@ describe('lua stdlib', function() exec_lua("vim.validate{arg1={{}, 't' }, arg2={ 'foo', 's' }}") 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'} }}") - + vim.validate('arg1', 5, 'number') + vim.validate('arg1', '5', 'string') + vim.validate('arg1', { 5 }, 'table') + vim.validate('arg1', function() + return 5 + end, 'function') + vim.validate('arg1', nil, 'number', true) + vim.validate('arg1', nil, 'string', true) + vim.validate('arg1', nil, 'table', true) + vim.validate('arg1', nil, 'function', true) + + matches('arg1: expected number, got nil', pcall_err(vim.validate, 'arg1', nil, 'number')) + matches('arg1: expected string, got nil', pcall_err(vim.validate, 'arg1', nil, 'string')) + matches('arg1: expected table, got nil', pcall_err(vim.validate, 'arg1', nil, 'table')) + matches('arg1: expected function, got nil', pcall_err(vim.validate, 'arg1', nil, 'function')) + matches('arg1: expected string, got number', pcall_err(vim.validate, 'arg1', 5, 'string')) + matches('arg1: expected table, got number', pcall_err(vim.validate, 'arg1', 5, 'table')) + matches('arg1: expected function, got number', pcall_err(vim.validate, 'arg1', 5, 'function')) + matches('arg1: expected number, got string', pcall_err(vim.validate, 'arg1', '5', 'number')) 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 }}')) @@ -1472,6 +1474,60 @@ describe('lua stdlib', function() ]]) ) + eq( + { false, false }, + exec_lua([[ + local meta = { __call = {} } + assert(meta.__call) + local function new() + return setmetatable({}, meta) + end + local not_callable = new() + return { pcall(function() not_callable() end), vim.is_callable(not_callable) } + ]]) + ) + eq( + { false, false }, + exec_lua([[ + local function new() + return { __call = function()end } + end + local not_callable = new() + assert(not_callable.__call) + return { pcall(function() not_callable() end), vim.is_callable(not_callable) } + ]]) + ) + eq( + { false, false }, + exec_lua([[ + local meta = setmetatable( + { __index = { __call = function() end } }, + { __index = { __call = function() end } } + ) + assert(meta.__call) + local not_callable = setmetatable({}, meta) + assert(not_callable.__call) + return { pcall(function() not_callable() end), vim.is_callable(not_callable) } + ]]) + ) + eq( + { false, false }, + exec_lua([[ + local meta = setmetatable({ + __index = function() + return function() end + end, + }, { + __index = function() + return function() end + end, + }) + assert(meta.__call) + local not_callable = setmetatable({}, meta) + assert(not_callable.__call) + return { pcall(function() not_callable() end), vim.is_callable(not_callable) } + ]]) + ) 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({})')) @@ -1891,7 +1947,7 @@ describe('lua stdlib', function() eq(NIL, fn.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('Dict is locked', pcall_err(exec_lua, [[vim.v.nosuchvar = 42]])) eq('Key is fixed: errmsg', pcall_err(exec_lua, [[vim.v.errmsg = nil]])) exec_lua([[vim.v.errmsg = 'set by Lua']]) eq('set by Lua', eval('v:errmsg')) @@ -1919,16 +1975,12 @@ describe('lua stdlib', function() eq({ 1, 5 }, api.nvim_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 }, - }) screen:attach() eq(1, eval('v:hlsearch')) screen:expect { grid = [[ - {1:foo} {1:^foo} {1:foo} | - {0:~ }| + {10:foo} {10:^foo} {10:foo} | + {1:~ }| | ]], } @@ -1937,7 +1989,7 @@ describe('lua stdlib', function() screen:expect { grid = [[ foo ^foo foo | - {0:~ }| + {1:~ }| | ]], } @@ -1945,8 +1997,8 @@ describe('lua stdlib', function() eq(1, eval('v:hlsearch')) screen:expect { grid = [[ - {1:foo} {1:^foo} {1:foo} | - {0:~ }| + {10:foo} {10:^foo} {10:foo} | + {1:~ }| | ]], } @@ -2005,13 +2057,17 @@ describe('lua stdlib', function() vim.cmd "enew" ]] eq(100, fn.luaeval 'vim.wo.scrolloff') + + matches('only bufnr=0 is supported', pcall_err(exec_lua, 'vim.wo[0][10].signcolumn = "no"')) + + matches('only bufnr=0 is supported', pcall_err(exec_lua, 'local a = vim.wo[0][10].signcolumn')) end) describe('vim.opt', function() -- TODO: We still need to write some tests for optlocal, opt and then getting the options -- Probably could also do some stuff with getting things from viml side as well to confirm behavior is the same. - it('should allow setting number values', function() + it('allows setting number values', function() local scrolloff = exec_lua [[ vim.opt.scrolloff = 10 return vim.o.scrolloff @@ -2019,7 +2075,7 @@ describe('lua stdlib', function() eq(10, scrolloff) end) - pending('should handle STUPID window things', function() + pending('handles STUPID window things', function() local result = exec_lua [[ local result = {} @@ -2032,7 +2088,7 @@ describe('lua stdlib', function() eq({}, result) end) - it('should allow setting tables', function() + it('allows setting tables', function() local wildignore = exec_lua [[ vim.opt.wildignore = { 'hello', 'world' } return vim.o.wildignore @@ -2040,7 +2096,7 @@ describe('lua stdlib', function() eq('hello,world', wildignore) end) - it('should allow setting tables with shortnames', function() + it('allows setting tables with shortnames', function() local wildignore = exec_lua [[ vim.opt.wig = { 'hello', 'world' } return vim.o.wildignore @@ -2048,7 +2104,7 @@ describe('lua stdlib', function() eq('hello,world', wildignore) end) - it('should error when you attempt to set string values to numeric options', function() + it('errors when you attempt to set string values to numeric options', function() local result = exec_lua [[ return { pcall(function() vim.opt.textwidth = 'hello world' end) @@ -2058,7 +2114,7 @@ describe('lua stdlib', function() eq(false, result[1]) end) - it('should error when you attempt to setlocal a global value', function() + it('errors when you attempt to setlocal a global value', function() local result = exec_lua [[ return pcall(function() vim.opt_local.clipboard = "hello" end) ]] @@ -2066,7 +2122,7 @@ describe('lua stdlib', function() eq(false, result) end) - it('should allow you to set boolean values', function() + it('allows you to set boolean values', function() eq( { true, false, true }, exec_lua [[ @@ -2086,7 +2142,7 @@ describe('lua stdlib', function() ) end) - it('should change current buffer values and defaults for global local values', function() + it('changes current buffer values and defaults for global local values', function() local result = exec_lua [[ local result = {} @@ -2125,7 +2181,7 @@ describe('lua stdlib', function() eq('', result[8]) end) - it('should allow you to retrieve window opts even if they have not been set', function() + it('allows you to retrieve window opts even if they have not been set', function() local result = exec_lua [[ local result = {} table.insert(result, vim.opt.number:get()) @@ -2140,7 +2196,7 @@ describe('lua stdlib', function() eq({ false, false, true, true }, result) end) - it('should allow all sorts of string manipulation', function() + it('allows all sorts of string manipulation', function() eq( { 'hello', 'hello world', 'start hello world' }, exec_lua [[ @@ -2161,7 +2217,7 @@ describe('lua stdlib', function() end) describe('option:get()', function() - it('should work for boolean values', function() + it('works for boolean values', function() eq( false, exec_lua [[ @@ -2171,7 +2227,7 @@ describe('lua stdlib', function() ) end) - it('should work for number values', function() + it('works for number values', function() local tabstop = exec_lua [[ vim.opt.tabstop = 10 return vim.opt.tabstop:get() @@ -2180,7 +2236,7 @@ describe('lua stdlib', function() eq(10, tabstop) end) - it('should work for string values', function() + it('works for string values', function() eq( 'hello world', exec_lua [[ @@ -2190,7 +2246,7 @@ describe('lua stdlib', function() ) end) - it('should work for set type flaglists', function() + it('works for set type flaglists', function() local formatoptions = exec_lua [[ vim.opt.formatoptions = 'tcro' return vim.opt.formatoptions:get() @@ -2200,7 +2256,7 @@ describe('lua stdlib', function() eq(true, not formatoptions.q) end) - it('should work for set type flaglists', function() + it('works for set type flaglists', function() local formatoptions = exec_lua [[ vim.opt.formatoptions = { t = true, c = true, r = true, o = true } return vim.opt.formatoptions:get() @@ -2210,7 +2266,7 @@ describe('lua stdlib', function() eq(true, not formatoptions.q) end) - it('should work for array list type options', function() + it('works for array list type options', function() local wildignore = exec_lua [[ vim.opt.wildignore = "*.c,*.o,__pycache__" return vim.opt.wildignore:get() @@ -2220,7 +2276,7 @@ describe('lua stdlib', function() eq('*.c', wildignore[1]) end) - it('should work for options that are both commalist and flaglist', function() + it('works for options that are both commalist and flaglist', function() local result = exec_lua [[ vim.opt.whichwrap = "b,s" return vim.opt.whichwrap:get() @@ -2236,7 +2292,7 @@ describe('lua stdlib', function() eq({ b = true, h = true }, result) end) - it('should work for key-value pair options', function() + it('works for key-value pair options', function() local listchars = exec_lua [[ vim.opt.listchars = "tab:> ,space:_" return vim.opt.listchars:get() @@ -2248,7 +2304,7 @@ describe('lua stdlib', function() }, listchars) end) - it('should allow you to add numeric options', function() + it('allows you to add numeric options', function() eq( 16, exec_lua [[ @@ -2259,7 +2315,7 @@ describe('lua stdlib', function() ) end) - it('should allow you to subtract numeric options', function() + it('allows you to subtract numeric options', function() eq( 2, exec_lua [[ @@ -2272,7 +2328,7 @@ describe('lua stdlib', function() end) describe('key:value style options', function() - it('should handle dictionary style', function() + it('handles dict style', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2284,7 +2340,7 @@ describe('lua stdlib', function() eq('eol:~,space:.', listchars) end) - it('should allow adding dictionary style', function() + it('allows adding dict style', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2299,7 +2355,7 @@ describe('lua stdlib', function() eq('eol:~,space:-', listchars) end) - it('should allow adding dictionary style', function() + it('allows adding dict style', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2313,7 +2369,7 @@ describe('lua stdlib', function() eq('eol:~,space:_', listchars) end) - it('should allow completely new keys', function() + it('allows completely new keys', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2327,7 +2383,7 @@ describe('lua stdlib', function() eq('eol:~,space:.,tab:>>>', listchars) end) - it('should allow subtracting dictionary style', function() + it('allows subtracting dict style', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2341,7 +2397,7 @@ describe('lua stdlib', function() eq('eol:~', listchars) end) - it('should allow subtracting dictionary style', function() + it('allows subtracting dict style', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2355,7 +2411,7 @@ describe('lua stdlib', function() eq('', listchars) end) - it('should allow subtracting dictionary style multiple times', function() + it('allows subtracting dict style multiple times', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2369,7 +2425,7 @@ describe('lua stdlib', function() eq('eol:~', listchars) end) - it('should allow adding a key:value string to a listchars', function() + it('allows adding a key:value string to a listchars', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2383,7 +2439,7 @@ describe('lua stdlib', function() eq('eol:~,space:.,tab:>~', listchars) end) - it('should allow prepending a key:value string to a listchars', function() + it('allows prepending a key:value string to a listchars', function() local listchars = exec_lua [[ vim.opt.listchars = { eol = "~", @@ -2398,7 +2454,7 @@ describe('lua stdlib', function() end) end) - it('should automatically set when calling remove', function() + it('automatically sets when calling remove', function() eq( 'foo,baz', exec_lua [[ @@ -2410,7 +2466,7 @@ describe('lua stdlib', function() ) end) - it('should automatically set when calling remove with a table', function() + it('automatically sets when calling remove with a table', function() eq( 'foo', exec_lua [[ @@ -2422,7 +2478,7 @@ describe('lua stdlib', function() ) end) - it('should automatically set when calling append', function() + it('automatically sets when calling append', function() eq( 'foo,bar,baz,bing', exec_lua [[ @@ -2434,7 +2490,7 @@ describe('lua stdlib', function() ) end) - it('should automatically set when calling append with a table', function() + it('automatically sets when calling append with a table', function() eq( 'foo,bar,baz,bing,zap', exec_lua [[ @@ -2446,7 +2502,7 @@ describe('lua stdlib', function() ) end) - it('should allow adding tables', function() + it('allows adding tables', function() local wildignore = exec_lua [[ vim.opt.wildignore = 'foo' return vim.o.wildignore @@ -2460,7 +2516,7 @@ describe('lua stdlib', function() eq('foo,bar,baz', wildignore) end) - it('should handle adding duplicates', function() + it('handles adding duplicates', function() local wildignore = exec_lua [[ vim.opt.wildignore = 'foo' return vim.o.wildignore @@ -2480,7 +2536,7 @@ describe('lua stdlib', function() eq('foo,bar,baz', wildignore) end) - it('should allow adding multiple times', function() + it('allows adding multiple times', function() local wildignore = exec_lua [[ vim.opt.wildignore = 'foo' vim.opt.wildignore = vim.opt.wildignore + 'bar' + 'baz' @@ -2489,7 +2545,7 @@ describe('lua stdlib', function() eq('foo,bar,baz', wildignore) end) - it('should remove values when you use minus', function() + it('removes values when you use minus', function() local wildignore = exec_lua [[ vim.opt.wildignore = 'foo' return vim.o.wildignore @@ -2509,7 +2565,7 @@ describe('lua stdlib', function() eq('foo,baz', wildignore) end) - it('should prepend values when using ^', function() + it('prepends values when using ^', function() local wildignore = exec_lua [[ vim.opt.wildignore = 'foo' vim.opt.wildignore = vim.opt.wildignore ^ 'first' @@ -2524,7 +2580,7 @@ describe('lua stdlib', function() eq('super_first,first,foo', wildignore) end) - it('should not remove duplicates from wildmode: #14708', function() + it('does not remove duplicates from wildmode: #14708', function() local wildmode = exec_lua [[ vim.opt.wildmode = {"full", "list", "full"} return vim.o.wildmode @@ -2534,7 +2590,7 @@ describe('lua stdlib', function() end) describe('option types', function() - it('should allow to set option with numeric value', function() + it('allows to set option with numeric value', function() eq( 4, exec_lua [[ @@ -2583,7 +2639,7 @@ describe('lua stdlib', function() ) end) - it('should allow to set option with boolean value', function() + it('allows to set option with boolean value', function() eq( true, exec_lua [[ @@ -2632,7 +2688,7 @@ describe('lua stdlib', function() ) end) - it('should allow to set option with array or string value', function() + it('allows to set option with array or string value', function() eq( 'indent,eol,start', exec_lua [[ @@ -2679,7 +2735,7 @@ describe('lua stdlib', function() ) end) - it('should allow set option with map or string value', function() + it('allows set option with map or string value', function() eq( 'eol:~,space:.', exec_lua [[ @@ -2729,7 +2785,7 @@ describe('lua stdlib', function() ) end) - it('should allow set option with set or string value', function() + it('allows set option with set or string value', function() local ww = exec_lua [[ vim.opt.whichwrap = { b = true, @@ -3179,11 +3235,11 @@ describe('lua stdlib', function() ]] end) - it('should run from lua', function() + it('runs from lua', function() exec_lua [[vim.wait(100, function() return true end)]] end) - it('should wait the expected time if false', function() + it('waits the expected time if false', function() eq( { time = true, wait_result = { false, -1 } }, exec_lua [[ @@ -3199,7 +3255,7 @@ describe('lua stdlib', function() ) end) - it('should not block other events', function() + it('does not block other events', function() eq( { time = true, wait_result = true }, exec_lua [[ @@ -3224,7 +3280,7 @@ describe('lua stdlib', function() ) end) - it('should not process non-fast events when commanded', function() + it('does not process non-fast events when commanded', function() eq( { wait_result = false }, exec_lua [[ @@ -3247,7 +3303,7 @@ describe('lua stdlib', function() ) end) - it('should work with vim.defer_fn', function() + it('works with vim.defer_fn', function() eq( { time = true, wait_result = true }, exec_lua [[ @@ -3264,7 +3320,7 @@ describe('lua stdlib', function() ) end) - it('should not crash when callback errors', function() + it('does not crash when callback errors', function() local result = exec_lua [[ return {pcall(function() vim.wait(1000, function() error("As Expected") end) end)} ]] @@ -3280,7 +3336,7 @@ describe('lua stdlib', function() ) end) - it('should allow waiting with no callback, explicit', function() + it('allows waiting with no callback, explicit', function() eq( true, exec_lua [[ @@ -3291,7 +3347,7 @@ describe('lua stdlib', function() ) end) - it('should allow waiting with no callback, implicit', function() + it('allows waiting with no callback, implicit', function() eq( true, exec_lua [[ @@ -3302,7 +3358,7 @@ describe('lua stdlib', function() ) end) - it('should call callbacks exactly once if they return true immediately', function() + it('calls callbacks exactly once if they return true immediately', function() eq( true, exec_lua [[ @@ -3316,7 +3372,7 @@ describe('lua stdlib', function() ) end) - it('should call callbacks few times with large `interval`', function() + it('calls callbacks few times with large `interval`', function() eq( true, exec_lua [[ @@ -3327,7 +3383,7 @@ describe('lua stdlib', function() ) end) - it('should play nice with `not` when fails', function() + it('plays nice with `not` when fails', function() eq( true, exec_lua [[ @@ -3340,7 +3396,7 @@ describe('lua stdlib', function() ) end) - it('should play nice with `if` when success', function() + it('plays nice with `if` when success', function() eq( true, exec_lua [[ @@ -3353,7 +3409,7 @@ describe('lua stdlib', function() ) end) - it('should return immediately with false if timeout is 0', function() + it('returns immediately with false if timeout is 0', function() eq( { false, -1 }, exec_lua [[ @@ -3364,7 +3420,7 @@ describe('lua stdlib', function() ) end) - it('should work with tables with __call', function() + it('works with tables with __call', function() eq( true, exec_lua [[ @@ -3374,7 +3430,7 @@ describe('lua stdlib', function() ) end) - it('should work with tables with __call that change', function() + it('works with tables with __call that change', function() eq( true, exec_lua [[ @@ -3391,7 +3447,7 @@ describe('lua stdlib', function() ) end) - it('should not work with negative intervals', function() + it('fails with negative intervals', function() local pcall_result = exec_lua [[ return pcall(function() vim.wait(1000, function() return false end, -1) end) ]] @@ -3399,7 +3455,7 @@ describe('lua stdlib', function() eq(false, pcall_result) end) - it('should not work with weird intervals', function() + it('fails with weird intervals', function() local pcall_result = exec_lua [[ return pcall(function() vim.wait(1000, function() return false end, 'a string value') end) ]] @@ -3442,7 +3498,7 @@ describe('lua stdlib', function() end) end) - it('should not run in fast callbacks #26122', function() + it('fails in fast callbacks #26122', function() local screen = Screen.new(80, 10) screen:attach() exec_lua([[ @@ -3462,15 +3518,11 @@ describe('lua stdlib', function() it('vim.notify_once', function() local screen = Screen.new(60, 5) - screen:set_default_attr_ids({ - [0] = { bold = true, foreground = Screen.colors.Blue }, - [1] = { foreground = Screen.colors.Red }, - }) screen:attach() screen:expect { grid = [[ ^ | - {0:~ }|*3 + {1:~ }|*3 | ]], } @@ -3478,15 +3530,15 @@ describe('lua stdlib', function() screen:expect { grid = [[ ^ | - {0:~ }|*3 - {1:I'll only tell you this once...} | + {1:~ }|*3 + {19:I'll only tell you this once...} | ]], } feed('<C-l>') screen:expect { grid = [[ ^ | - {0:~ }|*3 + {1:~ }|*3 | ]], } @@ -3663,10 +3715,6 @@ describe('lua stdlib', function() it('updates ruler if cursor moved', 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 }, - } screen:attach() exec_lua [[ _G.api = vim.api @@ -3681,9 +3729,9 @@ describe('lua stdlib', function() ]] screen:expect [[ 19 | - {1:[No Name] [+] 20,1 3%}| - ^19 | {2:[No Name] [+] 20,1 3%}| + ^19 | + {3:[No Name] [+] 20,1 3%}| | ]] exec_lua [[ @@ -3692,9 +3740,9 @@ describe('lua stdlib', function() ]] screen:expect [[ 99 | - {1:[No Name] [+] 100,1 19%}| + {2:[No Name] [+] 100,1 19%}| ^19 | - {2:[No Name] [+] 20,1 3%}| + {3:[No Name] [+] 20,1 3%}| | ]] end) @@ -3810,13 +3858,6 @@ describe('lua stdlib', function() it('vim.lua_omnifunc', function() 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 }, - } screen:attach() command [[ set omnifunc=v:lua.vim.lua_omnifunc ]] @@ -3826,10 +3867,10 @@ describe('lua stdlib', function() screen:expect { grid = [[ vim.inspect^ | - {1:~ }{2: inspect }{1: }| - {1:~ }{3: inspect_pos }{1: }| + {1:~ }{12: inspect }{1: }| + {1:~ }{4: inspect_pos }{1: }| {1:~ }| - {4:-- Omni completion (^O^N^P) }{5:match 1 of 2} | + {5:-- Omni completion (^O^N^P) }{6:match 1 of 2} | ]], } end) @@ -4002,7 +4043,36 @@ end) describe('vim.keymap', function() before_each(clear) - it('can make a mapping', function() + it('validates', function() + matches( + 'mode: expected string|table, got number', + pcall_err(exec_lua, [[vim.keymap.set(42, 'x', print)]]) + ) + + matches( + 'rhs: expected string|function, got nil', + pcall_err(exec_lua, [[vim.keymap.set('n', 'x')]]) + ) + + matches( + 'lhs: expected string, got table', + pcall_err(exec_lua, [[vim.keymap.set('n', {}, print)]]) + ) + + matches( + 'opts: expected table, got function', + pcall_err(exec_lua, [[vim.keymap.set({}, 'x', 42, function() end)]]) + ) + + matches( + 'rhs: expected string|function, got number', + pcall_err(exec_lua, [[vim.keymap.set('z', 'x', 42)]]) + ) + + matches('Invalid mode shortname: "z"', pcall_err(exec_lua, [[vim.keymap.set('z', 'x', 'y')]])) + end) + + it('mapping', function() eq( 0, exec_lua [[ @@ -4017,7 +4087,7 @@ describe('vim.keymap', function() eq(1, exec_lua [[return GlobalCount]]) end) - it('can make an expr mapping', function() + it('expr mapping', function() exec_lua [[ vim.keymap.set('n', 'aa', function() return '<Insert>π<C-V><M-π>foo<lt><Esc>' end, {expr = true}) ]] @@ -4027,7 +4097,7 @@ describe('vim.keymap', function() eq({ 'π<M-π>foo<' }, api.nvim_buf_get_lines(0, 0, -1, false)) end) - it('can overwrite a mapping', function() + it('overwrite a mapping', function() eq( 0, exec_lua [[ @@ -4050,7 +4120,7 @@ describe('vim.keymap', function() eq(0, exec_lua [[return GlobalCount]]) end) - it('can unmap a mapping', function() + it('unmap', function() eq( 0, exec_lua [[ @@ -4074,7 +4144,7 @@ describe('vim.keymap', function() eq('\nNo mapping found', n.exec_capture('nmap asdf')) end) - it('works with buffer-local mappings', function() + it('buffer-local mappings', function() eq( 0, exec_lua [[ @@ -4116,7 +4186,7 @@ describe('vim.keymap', function() ) end) - it('can do <Plug> mappings', function() + it('<Plug> mappings', function() eq( 0, exec_lua [[ |