diff options
Diffstat (limited to 'test/functional')
51 files changed, 603 insertions, 322 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index da7515f012..8ed642b43e 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -534,6 +534,26 @@ describe('api/buf', function() end) end) + describe('nvim_buf_delete', function() + it('allows for just deleting', function() + nvim('command', 'new') + local b = nvim('get_current_buf') + ok(buffer('is_valid', b)) + nvim('buf_delete', b, {}) + ok(not buffer('is_loaded', b)) + ok(not buffer('is_valid', b)) + end) + + it('allows for just unloading', function() + nvim('command', 'new') + local b = nvim('get_current_buf') + ok(buffer('is_valid', b)) + nvim('buf_delete', b, { unload = true }) + ok(not buffer('is_loaded', b)) + ok(buffer('is_valid', b)) + end) + end) + describe('nvim_buf_get_mark', function() it('works', function() curbuf('set_lines', -1, -1, true, {'a', 'bit of', 'text'}) diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 72e810e3e4..0b52d06df9 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -449,19 +449,19 @@ describe('API', function() end) it('reports errors', function() - eq([[Error loading lua: [string "<nvim>"]:1: '=' expected near '+']], + eq([[Error loading lua: [string "<nvim>"]:0: '=' expected near '+']], pcall_err(meths.exec_lua, 'a+*b', {})) - eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol near '1']], + eq([[Error loading lua: [string "<nvim>"]:0: unexpected symbol near '1']], pcall_err(meths.exec_lua, '1+2', {})) - eq([[Error loading lua: [string "<nvim>"]:1: unexpected symbol]], + eq([[Error loading lua: [string "<nvim>"]:0: unexpected symbol]], pcall_err(meths.exec_lua, 'aa=bb\0', {})) - eq([[Error executing lua: [string "<nvim>"]:1: attempt to call global 'bork' (a nil value)]], + eq([[Error executing lua: [string "<nvim>"]:0: attempt to call global 'bork' (a nil value)]], pcall_err(meths.exec_lua, 'bork()', {})) - eq('Error executing lua: [string "<nvim>"]:1: did\nthe\nfail', + eq('Error executing lua: [string "<nvim>"]:0: did\nthe\nfail', pcall_err(meths.exec_lua, 'error("did\\nthe\\nfail")', {})) end) @@ -605,7 +605,7 @@ describe('API', function() end) it('vim.paste() failure', function() nvim('exec_lua', 'vim.paste = (function(lines, phase) error("fake fail") end)', {}) - eq([[Error executing lua: [string "<nvim>"]:1: fake fail]], + eq([[Error executing lua: [string "<nvim>"]:0: fake fail]], pcall_err(request, 'nvim_paste', 'line 1\nline 2\nline 3', false, 1)) end) end) @@ -1252,7 +1252,7 @@ describe('API', function() {0:~ }| {1:very fail} | ]]) - helpers.wait() + helpers.poke_eventloop() -- shows up to &cmdheight lines nvim_async('err_write', 'more fail\ntoo fail\n') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 8c7c3208c0..7471f50dbd 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -3,7 +3,7 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, ok, feed, insert, eval = helpers.clear, helpers.nvim, helpers.curbuf, helpers.curbuf_contents, helpers.window, helpers.curwin, helpers.eq, helpers.neq, helpers.ok, helpers.feed, helpers.insert, helpers.eval -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths local funcs = helpers.funcs local request = helpers.request @@ -82,7 +82,7 @@ describe('API/win', function() insert("epilogue") local win = curwin() feed('gg') - wait() -- let nvim process the 'gg' command + poke_eventloop() -- let nvim process the 'gg' command -- cursor position is at beginning eq({1, 0}, window('get_cursor', win)) @@ -128,7 +128,7 @@ describe('API/win', function() insert("second line") feed('gg') - wait() -- let nvim process the 'gg' command + poke_eventloop() -- let nvim process the 'gg' command -- cursor position is at beginning local win = curwin() @@ -139,7 +139,7 @@ describe('API/win', function() -- move down a line feed('j') - wait() -- let nvim process the 'j' command + poke_eventloop() -- let nvim process the 'j' command -- cursor is still in column 5 eq({2, 5}, window('get_cursor', win)) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index 80c65e4544..230b7f8e01 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -8,7 +8,7 @@ local run = helpers.run local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local redir_exec = helpers.redir_exec -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('v:exiting', function() local cid @@ -52,7 +52,7 @@ describe(':cquit', function() local function test_cq(cmdline, exit_code, redir_msg) if redir_msg then eq('\n' .. redir_msg, redir_exec(cmdline)) - wait() + poke_eventloop() eq(2, eval("1+1")) -- Still alive? else funcs.system({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline}) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 1155f12ffc..6d1182478a 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -11,7 +11,7 @@ local os_kill = helpers.os_kill local retry = helpers.retry local meths = helpers.meths local NIL = helpers.NIL -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local iswin = helpers.iswin local get_pathsep = helpers.get_pathsep local pathroot = helpers.pathroot @@ -428,7 +428,7 @@ describe('jobs', function() \ } let job = jobstart(['cat', '-'], g:callbacks) ]]) - wait() + poke_eventloop() source([[ function! g:JobHandler(job_id, data, event) endfunction diff --git a/test/functional/eval/interrupt_spec.lua b/test/functional/eval/interrupt_spec.lua index 7f4ca95317..05b1f4ff57 100644 --- a/test/functional/eval/interrupt_spec.lua +++ b/test/functional/eval/interrupt_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local meths = helpers.meths local clear = helpers.clear local sleep = helpers.sleep -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed local eq = helpers.eq @@ -39,7 +39,7 @@ describe('List support code', function() feed(':let t_rt = reltime()<CR>:let t_bl = copy(bl)<CR>') sleep(min_dur / 16 * 1000) feed('<C-c>') - wait() + poke_eventloop() command('let t_dur = reltimestr(reltime(t_rt))') local t_dur = tonumber(meths.get_var('t_dur')) if t_dur >= dur / 8 then @@ -50,7 +50,7 @@ describe('List support code', function() feed(':let t_rt = reltime()<CR>:let t_j = join(bl)<CR>') sleep(min_dur / 16 * 1000) feed('<C-c>') - wait() + poke_eventloop() command('let t_dur = reltimestr(reltime(t_rt))') local t_dur = tonumber(meths.get_var('t_dur')) print(('t_dur: %g'):format(t_dur)) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 802c3f68c6..003ab64dd4 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command -local feed, wait = helpers.feed, helpers.wait +local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok local eval = helpers.eval @@ -90,7 +90,7 @@ describe(':browse oldfiles', function() feed_command('edit testfile2') filename2 = buf.get_name() feed_command('wshada') - wait() + poke_eventloop() _clear() -- Ensure nvim is out of "Press ENTER..." prompt. diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index dca7f35923..a30eb748d0 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -125,6 +125,26 @@ function tests.basic_check_capabilities() } end +function tests.capabilities_for_client_supports_method() + skeleton { + on_init = function(params) + local expected_capabilities = protocol.make_client_capabilities() + assert_eq(params.capabilities, expected_capabilities) + return { + capabilities = { + textDocumentSync = protocol.TextDocumentSyncKind.Full; + completionProvider = true; + hoverProvider = true; + definitionProvider = false; + referencesProvider = false; + } + } + end; + body = function() + end; + } +end + function tests.basic_finish() skeleton { on_init = function(params) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 99cbf30c7c..0bd378d832 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -554,9 +554,9 @@ function module.curbuf(method, ...) return module.buffer(method, 0, ...) end -function module.wait() - -- Execute 'nvim_eval' (a deferred function) to block - -- until all pending input is processed. +function module.poke_eventloop() + -- Execute 'nvim_eval' (a deferred function) to + -- force at least one main_loop iteration session:request('nvim_eval', '1') end @@ -566,7 +566,7 @@ end --@see buf_lines() function module.curbuf_contents() - module.wait() -- Before inspecting the buffer, process all input. + module.poke_eventloop() -- Before inspecting the buffer, do whatever. return table.concat(module.curbuf('get_lines', 0, -1, true), '\n') end diff --git a/test/functional/legacy/005_bufleave_delete_buffer_spec.lua b/test/functional/legacy/005_bufleave_delete_buffer_spec.lua index 8b92c877a6..8e977aa73e 100644 --- a/test/functional/legacy/005_bufleave_delete_buffer_spec.lua +++ b/test/functional/legacy/005_bufleave_delete_buffer_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, expect = helpers.command, helpers.expect -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('test5', function() setup(clear) @@ -34,7 +34,7 @@ describe('test5', function() command('bwipe') feed('G?this is a<cr>') feed('othis is some more text<esc>') - wait() + poke_eventloop() -- Append some text to this file. @@ -45,7 +45,7 @@ describe('test5', function() command('bwipe!') -- Append an extra line to the output register. feed('ithis is another test line<esc>:yank A<cr>') - wait() + poke_eventloop() -- Output results command('%d') diff --git a/test/functional/legacy/006_argument_list_spec.lua b/test/functional/legacy/006_argument_list_spec.lua index 9f75a91fa8..d269bf8ec9 100644 --- a/test/functional/legacy/006_argument_list_spec.lua +++ b/test/functional/legacy/006_argument_list_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, dedent, eq = helpers.command, helpers.dedent, helpers.eq local curbuf_contents = helpers.curbuf_contents -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('argument list', function() setup(clear) @@ -17,7 +17,7 @@ describe('argument list', function() this is a test this is a test end of test file Xxx]]) - wait() + poke_eventloop() command('au BufReadPost Xxx2 next Xxx2 Xxx1') command('/^start of') @@ -30,7 +30,7 @@ describe('argument list', function() -- Write test file Xxx3 feed('$r3:.,/end of/w! Xxx3<cr>') - wait() + poke_eventloop() -- Redefine arglist; go to Xxx1 command('next! Xxx1 Xxx2 Xxx3') @@ -43,7 +43,7 @@ describe('argument list', function() -- Append contents of last window (Xxx1) feed('') - wait() + poke_eventloop() command('%yank A') -- should now be in Xxx2 diff --git a/test/functional/legacy/012_directory_spec.lua b/test/functional/legacy/012_directory_spec.lua index cec4f93737..48dd24db9e 100644 --- a/test/functional/legacy/012_directory_spec.lua +++ b/test/functional/legacy/012_directory_spec.lua @@ -8,7 +8,7 @@ local lfs = require('lfs') local eq = helpers.eq local neq = helpers.neq -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local funcs = helpers.funcs local meths = helpers.meths local clear = helpers.clear @@ -64,7 +64,7 @@ describe("'directory' option", function() eq(nil, lfs.attributes('.Xtest1.swp')) command('edit! Xtest1') - wait() + poke_eventloop() eq('Xtest1', funcs.buffer_name('%')) -- Verify that the swapfile exists. In the legacy test this was done by -- reading the output from :!ls. @@ -72,7 +72,7 @@ describe("'directory' option", function() meths.set_option('directory', './Xtest2,.') command('edit Xtest1') - wait() + poke_eventloop() -- swapfile should no longer exist in CWD. eq(nil, lfs.attributes('.Xtest1.swp')) @@ -82,7 +82,7 @@ describe("'directory' option", function() meths.set_option('directory', 'Xtest.je') command('edit Xtest2/Xtest3') eq(true, curbufmeths.get_option('swapfile')) - wait() + poke_eventloop() eq({ "Xtest3" }, ls_dir_sorted("Xtest2")) eq({ "Xtest3.swp" }, ls_dir_sorted("Xtest.je")) diff --git a/test/functional/legacy/023_edit_arguments_spec.lua b/test/functional/legacy/023_edit_arguments_spec.lua index e705397a2b..f59d192c1e 100644 --- a/test/functional/legacy/023_edit_arguments_spec.lua +++ b/test/functional/legacy/023_edit_arguments_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, insert = helpers.clear, helpers.insert local command, expect = helpers.command, helpers.expect -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe(':edit', function() setup(clear) @@ -13,7 +13,7 @@ describe(':edit', function() The result should be in Xfile1: "fooPIPEbar", in Xfile2: "fooSLASHbar" foo|bar foo/bar]]) - wait() + poke_eventloop() -- Prepare some test files command('$-1w! Xfile1') diff --git a/test/functional/legacy/030_fileformats_spec.lua b/test/functional/legacy/030_fileformats_spec.lua index 2fd51602d8..15dbd05cf5 100644 --- a/test/functional/legacy/030_fileformats_spec.lua +++ b/test/functional/legacy/030_fileformats_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, clear, command = helpers.feed, helpers.clear, helpers.command local eq, write_file = helpers.eq, helpers.write_file -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('fileformats option', function() setup(function() @@ -107,7 +107,7 @@ describe('fileformats option', function() command('bwipe XXDosMac') command('e! XXEol') feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') - wait() + poke_eventloop() command('w! XXtt54') command('bwipeout! XXEol') command('set fileformats=dos,mac') @@ -116,7 +116,7 @@ describe('fileformats option', function() command('bwipe XXUxDs') command('e! XXUxMac') feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') - wait() + poke_eventloop() command('w! XXtt62') command('bwipeout! XXUxMac') command('e! XXUxDsMc') @@ -124,7 +124,7 @@ describe('fileformats option', function() command('bwipe XXUxDsMc') command('e! XXMacEol') feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') - wait() + poke_eventloop() command('w! XXtt64') command('bwipeout! XXMacEol') @@ -135,7 +135,7 @@ describe('fileformats option', function() command('bwipe XXUxDsMc') command('e! XXEol') feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') - wait() + poke_eventloop() command('w! XXtt72') command('bwipeout! XXEol') command('set fileformats=mac,dos,unix') @@ -144,7 +144,7 @@ describe('fileformats option', function() command('bwipe XXUxDsMc') command('e! XXEol') feed('ggO<C-R>=&ffs<CR>:<C-R>=&ff<CR><ESC>') - wait() + poke_eventloop() command('w! XXtt82') command('bwipeout! XXEol') -- Try with 'binary' set. @@ -165,7 +165,7 @@ describe('fileformats option', function() -- char was. command('set fileformat=unix nobin') feed('ggdGaEND<esc>') - wait() + poke_eventloop() command('w >>XXtt01') command('w >>XXtt02') command('w >>XXtt11') @@ -204,52 +204,52 @@ describe('fileformats option', function() command('$r XXtt01') command('$r XXtt02') feed('Go1<esc>') - wait() + poke_eventloop() command('$r XXtt11') command('$r XXtt12') command('$r XXtt13') feed('Go2<esc>') - wait() + poke_eventloop() command('$r XXtt21') command('$r XXtt22') command('$r XXtt23') feed('Go3<esc>') - wait() + poke_eventloop() command('$r XXtt31') command('$r XXtt32') command('$r XXtt33') feed('Go4<esc>') - wait() + poke_eventloop() command('$r XXtt41') command('$r XXtt42') command('$r XXtt43') feed('Go5<esc>') - wait() + poke_eventloop() command('$r XXtt51') command('$r XXtt52') command('$r XXtt53') command('$r XXtt54') feed('Go6<esc>') - wait() + poke_eventloop() command('$r XXtt61') command('$r XXtt62') command('$r XXtt63') command('$r XXtt64') feed('Go7<esc>') - wait() + poke_eventloop() command('$r XXtt71') command('$r XXtt72') feed('Go8<esc>') - wait() + poke_eventloop() command('$r XXtt81') command('$r XXtt82') feed('Go9<esc>') - wait() + poke_eventloop() command('$r XXtt91') command('$r XXtt92') command('$r XXtt93') feed('Go10<esc>') - wait() + poke_eventloop() command('$r XXUnix') command('set nobinary ff&') diff --git a/test/functional/legacy/033_lisp_indent_spec.lua b/test/functional/legacy/033_lisp_indent_spec.lua index 5132333a5c..b27de6c16d 100644 --- a/test/functional/legacy/033_lisp_indent_spec.lua +++ b/test/functional/legacy/033_lisp_indent_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, expect = helpers.command, helpers.expect -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('lisp indent', function() setup(clear) @@ -39,7 +39,7 @@ describe('lisp indent', function() command('set lisp') command('/^(defun') feed('=G:/^(defun/,$yank A<cr>') - wait() + poke_eventloop() -- Put @a and clean empty line command('%d') diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua index 38e8145d1c..6f66efcb67 100644 --- a/test/functional/legacy/036_regexp_character_classes_spec.lua +++ b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -15,7 +15,7 @@ end local function diff(text, nodedent) local fname = helpers.tmpname() command('w! '..fname) - helpers.wait() + helpers.poke_eventloop() local data = io.open(fname):read('*all') if nodedent then helpers.eq(text, data) diff --git a/test/functional/legacy/045_folding_spec.lua b/test/functional/legacy/045_folding_spec.lua index 1e5239ceac..7d7856fd37 100644 --- a/test/functional/legacy/045_folding_spec.lua +++ b/test/functional/legacy/045_folding_spec.lua @@ -59,7 +59,7 @@ describe('folding', function() feed('kYpj') feed_command('call append("$", foldlevel("."))') - helpers.wait() + helpers.poke_eventloop() screen:expect([[ dd {{{ | ee {{{ }}} | @@ -88,7 +88,7 @@ describe('folding', function() feed_command('call append("$", foldlevel(2))') feed('zR') - helpers.wait() + helpers.poke_eventloop() screen:expect([[ aa | bb | diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua index 0c9c9621ee..d3f2897493 100644 --- a/test/functional/legacy/051_highlight_spec.lua +++ b/test/functional/legacy/051_highlight_spec.lua @@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed local expect = helpers.expect local eq = helpers.eq -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local exc_exec = helpers.exc_exec local feed_command = helpers.feed_command @@ -34,7 +34,7 @@ describe(':highlight', function() -- More --^ | ]]) feed('q') - wait() -- wait until we're back to normal + poke_eventloop() -- wait until we're back to normal feed_command('hi Search') feed_command('hi Normal') diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua index bdc2c9779c..328d6f6fa0 100644 --- a/test/functional/legacy/057_sort_spec.lua +++ b/test/functional/legacy/057_sort_spec.lua @@ -2,8 +2,8 @@ local helpers = require('test.functional.helpers')(after_each) -local insert, command, clear, expect, eq, wait = helpers.insert, - helpers.command, helpers.clear, helpers.expect, helpers.eq, helpers.wait +local insert, command, clear, expect, eq, poke_eventloop = helpers.insert, + helpers.command, helpers.clear, helpers.expect, helpers.eq, helpers.poke_eventloop local exc_exec = helpers.exc_exec describe(':sort', function() @@ -27,7 +27,7 @@ describe(':sort', function() it('alphabetical', function() insert(text) - wait() + poke_eventloop() command('sort') expect([[ @@ -67,7 +67,7 @@ describe(':sort', function() b321 b321b ]]) - wait() + poke_eventloop() command('sort n') expect([[ abc @@ -92,7 +92,7 @@ describe(':sort', function() it('hexadecimal', function() insert(text) - wait() + poke_eventloop() command('sort x') expect([[ @@ -114,7 +114,7 @@ describe(':sort', function() it('alphabetical, unique', function() insert(text) - wait() + poke_eventloop() command('sort u') expect([[ @@ -135,7 +135,7 @@ describe(':sort', function() it('alphabetical, reverse', function() insert(text) - wait() + poke_eventloop() command('sort!') expect([[ c321d @@ -157,7 +157,7 @@ describe(':sort', function() it('numerical, reverse', function() insert(text) - wait() + poke_eventloop() command('sort! n') expect([[ b322b @@ -179,7 +179,7 @@ describe(':sort', function() it('unique, reverse', function() insert(text) - wait() + poke_eventloop() command('sort! u') expect([[ c321d @@ -200,7 +200,7 @@ describe(':sort', function() it('octal', function() insert(text) - wait() + poke_eventloop() command('sort o') expect([[ abc @@ -222,7 +222,7 @@ describe(':sort', function() it('reverse, hexadecimal', function() insert(text) - wait() + poke_eventloop() command('sort! x') expect([[ c321d @@ -244,7 +244,7 @@ describe(':sort', function() it('alphabetical, skip first character', function() insert(text) - wait() + poke_eventloop() command('sort/./') expect([[ a @@ -266,7 +266,7 @@ describe(':sort', function() it('alphabetical, skip first 2 characters', function() insert(text) - wait() + poke_eventloop() command('sort/../') expect([[ ab @@ -288,7 +288,7 @@ describe(':sort', function() it('alphabetical, unique, skip first 2 characters', function() insert(text) - wait() + poke_eventloop() command('sort/../u') expect([[ ab @@ -309,7 +309,7 @@ describe(':sort', function() it('numerical, skip first character', function() insert(text) - wait() + poke_eventloop() command('sort/./n') expect([[ abc @@ -331,7 +331,7 @@ describe(':sort', function() it('alphabetical, sort on first character', function() insert(text) - wait() + poke_eventloop() command('sort/./r') expect([[ @@ -353,7 +353,7 @@ describe(':sort', function() it('alphabetical, sort on first 2 characters', function() insert(text) - wait() + poke_eventloop() command('sort/../r') expect([[ a @@ -375,7 +375,7 @@ describe(':sort', function() it('numerical, sort on first character', function() insert(text) - wait() + poke_eventloop() command('sort/./rn') expect([[ abc @@ -397,7 +397,7 @@ describe(':sort', function() it('alphabetical, skip past first digit', function() insert(text) - wait() + poke_eventloop() command([[sort/\d/]]) expect([[ abc @@ -419,7 +419,7 @@ describe(':sort', function() it('alphabetical, sort on first digit', function() insert(text) - wait() + poke_eventloop() command([[sort/\d/r]]) expect([[ abc @@ -441,7 +441,7 @@ describe(':sort', function() it('numerical, skip past first digit', function() insert(text) - wait() + poke_eventloop() command([[sort/\d/n]]) expect([[ abc @@ -463,7 +463,7 @@ describe(':sort', function() it('numerical, sort on first digit', function() insert(text) - wait() + poke_eventloop() command([[sort/\d/rn]]) expect([[ abc @@ -485,7 +485,7 @@ describe(':sort', function() it('alphabetical, skip past first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/]]) expect([[ abc @@ -507,7 +507,7 @@ describe(':sort', function() it('numerical, skip past first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/n]]) expect([[ abc @@ -529,7 +529,7 @@ describe(':sort', function() it('hexadecimal, skip past first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/x]]) expect([[ abc @@ -551,7 +551,7 @@ describe(':sort', function() it('alpha, on first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/r]]) expect([[ abc @@ -573,7 +573,7 @@ describe(':sort', function() it('numeric, on first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/rn]]) expect([[ abc @@ -595,7 +595,7 @@ describe(':sort', function() it('hexadecimal, on first 2 digits', function() insert(text) - wait() + poke_eventloop() command([[sort/\d\d/rx]]) expect([[ abc @@ -638,7 +638,7 @@ describe(':sort', function() 0b100010 0b100100 0b100010]]) - wait() + poke_eventloop() command([[sort b]]) expect([[ 0b000000 @@ -673,7 +673,7 @@ describe(':sort', function() 0b101010 0b000000 b0b111000]]) - wait() + poke_eventloop() command([[sort b]]) expect([[ 0b000000 @@ -700,7 +700,7 @@ describe(':sort', function() 1.15e-6 -1.1e3 -1.01e3]]) - wait() + poke_eventloop() command([[sort f]]) expect([[ -1.1e3 diff --git a/test/functional/legacy/074_global_var_in_viminfo_spec.lua b/test/functional/legacy/074_global_var_in_viminfo_spec.lua index f7f074c61a..445d742c1f 100644 --- a/test/functional/legacy/074_global_var_in_viminfo_spec.lua +++ b/test/functional/legacy/074_global_var_in_viminfo_spec.lua @@ -2,9 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') -local clear, command, eq, neq, eval, wait = +local clear, command, eq, neq, eval, poke_eventloop = helpers.clear, helpers.command, helpers.eq, helpers.neq, helpers.eval, - helpers.wait + helpers.poke_eventloop describe('storing global variables in ShaDa files', function() local tempname = 'Xtest-functional-legacy-074' @@ -36,7 +36,7 @@ describe('storing global variables in ShaDa files', function() eq(test_list, eval('MY_GLOBAL_LIST')) command('wsh! ' .. tempname) - wait() + poke_eventloop() -- Assert that the shada file exists. neq(nil, lfs.attributes(tempname)) diff --git a/test/functional/legacy/075_maparg_spec.lua b/test/functional/legacy/075_maparg_spec.lua index ee2b041b51..ad6c190104 100644 --- a/test/functional/legacy/075_maparg_spec.lua +++ b/test/functional/legacy/075_maparg_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed local command, expect = helpers.command, helpers.expect -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('maparg()', function() setup(clear) @@ -25,7 +25,7 @@ describe('maparg()', function() command('map abc y<S-char-114>y') command([[call append('$', maparg('abc'))]]) feed('Go<esc>:<cr>') - wait() + poke_eventloop() -- Outside of the range, minimum command('inoremap <Char-0x1040> a') diff --git a/test/functional/legacy/107_adjust_window_and_contents_spec.lua b/test/functional/legacy/107_adjust_window_and_contents_spec.lua index 239f60341a..841eeef0af 100644 --- a/test/functional/legacy/107_adjust_window_and_contents_spec.lua +++ b/test/functional/legacy/107_adjust_window_and_contents_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local clear = helpers.clear local insert = helpers.insert local command = helpers.command @@ -16,7 +16,7 @@ describe('107', function() screen:attach() insert('start:') - wait() + poke_eventloop() command('new') command('call setline(1, range(1,256))') command('let r=[]') diff --git a/test/functional/legacy/autoformat_join_spec.lua b/test/functional/legacy/autoformat_join_spec.lua index 84d661c190..22b1c258fe 100644 --- a/test/functional/legacy/autoformat_join_spec.lua +++ b/test/functional/legacy/autoformat_join_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, expect = helpers.command, helpers.expect -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('autoformat join', function() setup(clear) @@ -21,7 +21,7 @@ Results:]]) feed('gg') feed('0gqj<cr>') - wait() + poke_eventloop() command([[let a=string(getpos("'[")).'/'.string(getpos("']"))]]) command("g/^This line/;'}-join") diff --git a/test/functional/legacy/close_count_spec.lua b/test/functional/legacy/close_count_spec.lua index 9b932e2ef0..60ae155fbf 100644 --- a/test/functional/legacy/close_count_spec.lua +++ b/test/functional/legacy/close_count_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear @@ -110,23 +110,23 @@ describe('close_count', function() command('for i in range(5)|new|endfor') command('4wincmd w') feed('<C-W>c<cr>') - wait() + poke_eventloop() command('let buffers = []') command('windo call add(buffers, bufnr("%"))') eq({25, 24, 23, 21, 1}, eval('buffers')) feed('1<C-W>c<cr>') - wait() + poke_eventloop() command('let buffers = []') command('windo call add(buffers, bufnr("%"))') eq({24, 23, 21, 1}, eval('buffers')) feed('9<C-W>c<cr>') - wait() + poke_eventloop() command('let buffers = []') command('windo call add(buffers, bufnr("%"))') eq({24, 23, 21}, eval('buffers')) command('1wincmd w') feed('2<C-W>c<cr>') - wait() + poke_eventloop() command('let buffers = []') command('windo call add(buffers, bufnr("%"))') eq({24, 21}, eval('buffers')) diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua index aafcda67dc..3fbbe96947 100644 --- a/test/functional/legacy/display_spec.lua +++ b/test/functional/legacy/display_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local feed = helpers.feed local feed_command = helpers.feed_command @@ -18,7 +18,7 @@ describe('display', function() }) feed_command([[call setline(1, repeat('a', 21))]]) - wait() + poke_eventloop() feed('O') screen:expect([[ ^ | diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index 4198ea8bfe..ee9bd29fc4 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, command, expect = helpers.clear, helpers.command, helpers.expect local eq, eval, write_file = helpers.eq, helpers.eval, helpers.write_file -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local exc_exec = helpers.exc_exec local dedent = helpers.dedent @@ -71,7 +71,7 @@ describe('eval', function() command([[call SetReg('I', 'abcI')]]) feed('Go{{{1 Appending single lines with setreg()<esc>') - wait() + poke_eventloop() command([[call SetReg('A', 'abcAc', 'c')]]) command([[call SetReg('A', 'abcAl', 'l')]]) command([[call SetReg('A', 'abcAc2','c')]]) @@ -700,13 +700,13 @@ describe('eval', function() start:]]) command('/^012345678') feed('6l') - wait() + poke_eventloop() command('let sp = getcurpos()') feed('0') - wait() + poke_eventloop() command("call setpos('.', sp)") feed('jyl') - wait() + poke_eventloop() command('$put') expect([[ 012345678 diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 56a5652184..92a757ca85 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local feed_command, expect, wait = helpers.feed_command, helpers.expect, helpers.wait +local feed_command, expect, poke_eventloop = helpers.feed_command, helpers.expect, helpers.poke_eventloop describe('mapping', function() before_each(clear) @@ -29,9 +29,9 @@ describe('mapping', function() feed_command('cunmap <c-c>') feed('GA<cr>') feed('TEST2: CTRL-C |') - wait() + poke_eventloop() feed('<c-c>A|<cr><esc>') - wait() + poke_eventloop() feed_command('unmap <c-c>') feed_command('unmap! <c-c>') @@ -46,7 +46,7 @@ describe('mapping', function() feed('GV') -- XXX: For some reason the mapping is only triggered -- when <C-c> is in a separate feed command. - wait() + poke_eventloop() feed('<c-c>') feed_command('vunmap <c-c>') diff --git a/test/functional/legacy/memory_usage_spec.lua b/test/functional/legacy/memory_usage_spec.lua index 251e6a5ea4..fb0bacc2d2 100644 --- a/test/functional/legacy/memory_usage_spec.lua +++ b/test/functional/legacy/memory_usage_spec.lua @@ -7,7 +7,7 @@ local iswin = helpers.iswin local retry = helpers.retry local ok = helpers.ok local source = helpers.source -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local uname = helpers.uname local load_adjust = helpers.load_adjust @@ -102,7 +102,7 @@ describe('memory usage', function() call s:f(0) endfor ]]) - wait() + poke_eventloop() local after = monitor_memory_usage(pid) -- Estimate the limit of max usage as 2x initial usage. -- The lower limit can fluctuate a bit, use 97%. @@ -147,11 +147,11 @@ describe('memory usage', function() call s:f() endfor ]]) - wait() + poke_eventloop() local after = monitor_memory_usage(pid) for _ = 1, 3 do feed_command('so '..fname) - wait() + poke_eventloop() end local last = monitor_memory_usage(pid) -- The usage may be a bit less than the last value, use 80%. diff --git a/test/functional/legacy/search_mbyte_spec.lua b/test/functional/legacy/search_mbyte_spec.lua index a365f79cdf..ef7e41aa30 100644 --- a/test/functional/legacy/search_mbyte_spec.lua +++ b/test/functional/legacy/search_mbyte_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local clear = helpers.clear local insert = helpers.insert local expect = helpers.expect @@ -15,7 +15,7 @@ describe('search_mbyte', function() Test bce: A]=]) - wait() + poke_eventloop() command('/^Test bce:/+1') command([[$put =search('A', 'bce', line('.'))]]) diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua index bb039a585c..4ed08881de 100644 --- a/test/functional/legacy/search_spec.lua +++ b/test/functional/legacy/search_spec.lua @@ -6,7 +6,7 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local funcs = helpers.funcs -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('search cmdline', function() local screen @@ -483,9 +483,9 @@ describe('search cmdline', function() -- "interactive". This mimics Vim's test_override("char_avail"). -- (See legacy test: test_search.vim) feed('?the') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 the first | @@ -496,11 +496,11 @@ describe('search cmdline', function() command('$') feed('?the') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 ^the first | @@ -511,13 +511,13 @@ describe('search cmdline', function() command('$') feed('?the') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<c-g>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 the first | @@ -528,9 +528,9 @@ describe('search cmdline', function() command('$') feed('?the') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 ^the first | @@ -541,11 +541,11 @@ describe('search cmdline', function() command('$') feed('?the') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 the first | @@ -556,13 +556,13 @@ describe('search cmdline', function() command('$') feed('?the') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<c-t>') - wait() + poke_eventloop() feed('<cr>') screen:expect([[ 1 the first | diff --git a/test/functional/legacy/utf8_spec.lua b/test/functional/legacy/utf8_spec.lua index 5b93f25b24..8b5fc02d11 100644 --- a/test/functional/legacy/utf8_spec.lua +++ b/test/functional/legacy/utf8_spec.lua @@ -5,7 +5,7 @@ local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert local command, expect = helpers.command, helpers.expect local eq, eval = helpers.eq, helpers.eval local source = helpers.source -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('utf8', function() before_each(clear) @@ -18,7 +18,7 @@ describe('utf8', function() -- Visual block Insert adjusts for multi-byte char feed('gg0l<C-V>jjIx<Esc>') - wait() + poke_eventloop() command('let r = getline(1, "$")') command('bwipeout!') diff --git a/test/functional/legacy/wordcount_spec.lua b/test/functional/legacy/wordcount_spec.lua index 0c8bd2cdcc..826743b0ca 100644 --- a/test/functional/legacy/wordcount_spec.lua +++ b/test/functional/legacy/wordcount_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, command = helpers.clear, helpers.command local eq, eval = helpers.eq, helpers.eval -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('wordcount', function() before_each(clear) @@ -14,7 +14,7 @@ describe('wordcount', function() insert([=[ RESULT test:]=]) - wait() + poke_eventloop() command('new') source([=[ @@ -127,7 +127,7 @@ describe('wordcount', function() -- -- Start visual mode quickly and select complete buffer. command('0') feed('V2jy<cr>') - wait() + poke_eventloop() command('set stl= ls=1') command('let log=DoRecordWin([3,99,0])') command('let log[1]=g:visual_stat') @@ -144,7 +144,7 @@ describe('wordcount', function() -- Start visual mode quickly and select complete buffer. command('0') feed('v$y<cr>') - wait() + poke_eventloop() command('set stl= ls=1') command('let log=DoRecordWin([3,99,0])') command('let log[1]=g:visual_stat') @@ -161,7 +161,7 @@ describe('wordcount', function() -- Start visual mode quickly and select complete buffer. command('2') feed('0v$y<cr>') - wait() + poke_eventloop() command('set stl= ls=1') command('let log=DoRecordWin([3,99,0])') command('let log[1]=g:visual_stat') diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua index cbc3aee557..f2a1b7dede 100644 --- a/test/functional/lua/commands_spec.lua +++ b/test/functional/lua/commands_spec.lua @@ -43,7 +43,7 @@ describe(':lua command', function() eq({'', 'ETTS', 'TTSE', 'STTE'}, curbufmeths.get_lines(0, 100, false)) end) it('throws catchable errors', function() - eq([[Vim(lua):E5107: Error loading lua [string ":lua"]:1: unexpected symbol near ')']], + 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]], exc_exec('lua error("TEST")')) diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 75966393b1..2ec48777fd 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -477,14 +477,14 @@ describe('v:lua', function() eq(NIL, eval('v:lua.mymod.noisy("eval")')) eq("hey eval", meths.get_current_line()) - eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:10: attempt to call global 'nonexistent' (a nil value)", + eq("Vim:E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)", pcall_err(eval, 'v:lua.mymod.crashy()')) end) it('works in :call', function() command(":call v:lua.mymod.noisy('command')") eq("hey command", meths.get_current_line()) - eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:10: attempt to call global 'nonexistent' (a nil value)", + eq("Vim(call):E5108: Error executing lua [string \"<nvim>\"]:0: attempt to call global 'nonexistent' (a nil value)", pcall_err(command, 'call v:lua.mymod.crashy()')) end) diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index 74ae6cde2b..3526b64395 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -15,17 +15,16 @@ before_each(clear) describe('treesitter API', function() -- error tests not requiring a parser library it('handles missing language', function() - eq("Error executing lua: .../language.lua: no parser for 'borklang' language, see :help treesitter-parsers", + eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "parser = vim.treesitter.get_parser(0, 'borklang')")) -- actual message depends on platform matches("Error executing lua: Failed to load parser: uv_dlopen: .+", pcall_err(exec_lua, "parser = vim.treesitter.require_language('borklang', 'borkbork.so')")) - eq("Error executing lua: .../language.lua: no parser for 'borklang' language, see :help treesitter-parsers", + eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", pcall_err(exec_lua, "parser = vim.treesitter.inspect_language('borklang')")) end) - end) describe('treesitter API with C parser', function() @@ -186,6 +185,16 @@ void ui_refresh(void) (field_expression argument: (identifier) @fieldarg) ]] + it("supports runtime queries", function() + if not check_parser() then return end + + local ret = exec_lua [[ + return require"vim.treesitter.query".get_query("c", "highlights").captures[1] + ]] + + eq('variable', ret) + end) + it('support query and iter by capture', function() if not check_parser() then return end @@ -420,9 +429,10 @@ static int nlua_schedule(lua_State *const lstate) ]]} exec_lua([[ + local parser = vim.treesitter.get_parser(0, "c") local highlighter = vim.treesitter.highlighter local query = ... - test_hl = highlighter.new(query, 0, "c") + test_hl = highlighter.new(parser, query) ]], hl_query) screen:expect{grid=[[ {2:/// Schedule Lua callback on main loop's event queue} | @@ -559,6 +569,72 @@ static int nlua_schedule(lua_State *const lstate) ]]} end) + it("supports highlighting with custom parser", function() + if not check_parser() then return end + + local screen = Screen.new(65, 18) + screen:attach() + screen:set_default_attr_ids({ {bold = true, foreground = Screen.colors.SeaGreen4} }) + + insert(test_text) + + screen:expect{ grid= [[ + int width = INT_MAX, height = INT_MAX; | + bool ext_widgets[kUIExtCount]; | + for (UIExtension i = 0; (int)i < kUIExtCount; i++) { | + ext_widgets[i] = true; | + } | + | + bool inclusive = ui_override(); | + for (size_t i = 0; i < ui_count; i++) { | + UI *ui = uis[i]; | + width = MIN(ui->width, width); | + height = MIN(ui->height, height); | + foo = BAR(ui->bazaar, bazaar); | + for (UIExtension j = 0; (int)j < kUIExtCount; j++) { | + ext_widgets[j] &= (ui->ui_ext[j] || inclusive); | + } | + } | + ^} | + | + ]] } + + exec_lua([[ + parser = vim.treesitter.get_parser(0, "c") + query = vim.treesitter.parse_query("c", "(declaration) @decl") + + local nodes = {} + for _, node in query:iter_captures(parser:parse():root(), 0, 0, 19) do + table.insert(nodes, node) + end + + parser:set_included_ranges(nodes) + + local hl = vim.treesitter.highlighter.new(parser, "(identifier) @type") + ]]) + + screen:expect{ grid = [[ + int {1:width} = {1:INT_MAX}, {1:height} = {1:INT_MAX}; | + bool {1:ext_widgets}[{1:kUIExtCount}]; | + for (UIExtension {1:i} = 0; (int)i < kUIExtCount; i++) { | + ext_widgets[i] = true; | + } | + | + bool {1:inclusive} = {1:ui_override}(); | + for (size_t {1:i} = 0; i < ui_count; i++) { | + UI *{1:ui} = {1:uis}[{1:i}]; | + width = MIN(ui->width, width); | + height = MIN(ui->height, height); | + foo = BAR(ui->bazaar, bazaar); | + for (UIExtension {1:j} = 0; (int)j < kUIExtCount; j++) { | + ext_widgets[j] &= (ui->ui_ext[j] || inclusive); | + } | + } | + ^} | + | + ]] } + end) + it('inspects language', function() if not check_parser() then return end @@ -604,23 +680,29 @@ static int nlua_schedule(lua_State *const lstate) insert(test_text) - local res = exec_lua([[ + local res = exec_lua [[ parser = vim.treesitter.get_parser(0, "c") return { parser:parse():root():range() } - ]]) + ]] eq({0, 0, 19, 0}, res) -- The following sets the included ranges for the current parser -- As stated here, this only includes the function (thus the whole buffer, without the last line) - local res2 = exec_lua([[ + local res2 = exec_lua [[ local root = parser:parse():root() parser:set_included_ranges({root:child(0)}) parser.valid = false return { parser:parse():root():range() } - ]]) + ]] eq({0, 0, 18, 1}, res2) + + local range = exec_lua [[ + return parser:included_ranges() + ]] + + eq(range, { { 0, 0, 18, 1 } }) end) it("allows to set complex ranges", function() if not check_parser() then return end @@ -628,7 +710,7 @@ static int nlua_schedule(lua_State *const lstate) insert(test_text) - local res = exec_lua([[ + local res = exec_lua [[ parser = vim.treesitter.get_parser(0, "c") query = vim.treesitter.parse_query("c", "(declaration) @decl") @@ -646,7 +728,7 @@ static int nlua_schedule(lua_State *const lstate) table.insert(res, { root:named_child(i):range() }) end return res - ]]) + ]] eq({ { 2, 2, 2, 40 }, diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 63e48a18ca..1cbf6b21e3 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -4,13 +4,14 @@ local Screen = require('test.functional.ui.screen') local funcs = helpers.funcs local meths = helpers.meths +local dedent = helpers.dedent local command = helpers.command local clear = helpers.clear local eq = helpers.eq local ok = helpers.ok local eval = helpers.eval local feed = helpers.feed -local pcall_err = helpers.pcall_err +local pcall_err_withfile = helpers.pcall_err_withfile local exec_lua = helpers.exec_lua local matches = helpers.matches local source = helpers.source @@ -128,8 +129,8 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.startswith("123", "2")')) eq(false, funcs.luaeval('vim.startswith("123", "1234")')) - eq("string", type(pcall_err(funcs.luaeval, 'vim.startswith("123", nil)'))) - eq("string", type(pcall_err(funcs.luaeval, 'vim.startswith(nil, "123")'))) + eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.startswith("123", nil)'))) + eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.startswith(nil, "123")'))) end) it('vim.endswith', function() @@ -142,8 +143,8 @@ describe('lua stdlib', function() eq(false, funcs.luaeval('vim.endswith("123", "2")')) eq(false, funcs.luaeval('vim.endswith("123", "1234")')) - eq("string", type(pcall_err(funcs.luaeval, 'vim.endswith("123", nil)'))) - eq("string", type(pcall_err(funcs.luaeval, 'vim.endswith(nil, "123")'))) + eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.endswith("123", nil)'))) + eq("string", type(pcall_err_withfile(funcs.luaeval, 'vim.endswith(nil, "123")'))) end) it("vim.str_utfindex/str_byteindex", function() @@ -182,10 +183,10 @@ describe('lua stdlib', function() eq({"yy","xx"}, exec_lua("return test_table")) -- Validates args. - eq('Error executing lua: vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule('stringly')")) - eq('Error executing lua: vim.schedule: expected function', - pcall_err(exec_lua, "vim.schedule()")) + eq('.../helpers.lua:0: Error executing lua: vim.schedule: expected function', + pcall_err_withfile(exec_lua, "vim.schedule('stringly')")) + eq('.../helpers.lua:0: Error executing lua: vim.schedule: expected function', + pcall_err_withfile(exec_lua, "vim.schedule()")) exec_lua([[ vim.schedule(function() @@ -257,17 +258,29 @@ describe('lua stdlib', function() } for _, t in ipairs(loops) do - matches(".*Infinite loop detected", pcall_err(split, t[1], t[2])) + matches(".*Infinite loop detected", pcall_err_withfile(split, t[1], t[2])) end -- Validates args. eq(true, pcall(split, 'string', 'string')) - eq('Error executing lua: .../shared.lua: s: expected string, got number', - pcall_err(split, 1, 'string')) - eq('Error executing lua: .../shared.lua: sep: expected string, got number', - pcall_err(split, 'string', 1)) - eq('Error executing lua: .../shared.lua: plain: expected boolean, got number', - pcall_err(split, 'string', 'string', 1)) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number + stack traceback: + shared.lua:0: in function 'gsplit' + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(split, 1, 'string')) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: sep: expected string, got number + stack traceback: + shared.lua:0: in function 'gsplit' + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(split, 'string', 1)) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: plain: expected boolean, got number + stack traceback: + shared.lua:0: in function 'gsplit' + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(split, 'string', 'string', 1)) end) it('vim.trim', function() @@ -287,8 +300,11 @@ describe('lua stdlib', function() end -- Validates args. - eq('Error executing lua: .../shared.lua: s: expected string, got number', - pcall_err(trim, 2)) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number + stack traceback: + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(trim, 2)) end) it('vim.inspect', function() @@ -353,8 +369,8 @@ describe('lua stdlib', function() return t1.f() ~= t2.f() ]])) - eq('Error executing lua: .../shared.lua: Cannot deepcopy object of type thread', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: Cannot deepcopy object of type thread', + pcall_err_withfile(exec_lua, [[ local thread = coroutine.create(function () return 0 end) local t = {thr = thread} vim.deepcopy(t) @@ -366,8 +382,11 @@ describe('lua stdlib', function() eq('foo%%%-bar', exec_lua([[return vim.pesc(vim.pesc('foo-bar'))]])) -- Validates args. - eq('Error executing lua: .../shared.lua: s: expected string, got number', - pcall_err(exec_lua, [[return vim.pesc(2)]])) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: s: expected string, got number + stack traceback: + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(exec_lua, [[return vim.pesc(2)]])) end) it('vim.tbl_keys', function() @@ -491,20 +510,20 @@ describe('lua stdlib', function() return c.x.a == 1 and c.x.b == 2 and c.x.c == nil and count == 1 ]])) - eq('Error executing lua: .../shared.lua: invalid "behavior": nil', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: invalid "behavior": nil', + pcall_err_withfile(exec_lua, [[ return vim.tbl_extend() ]]) ) - eq('Error executing lua: .../shared.lua: wrong number of arguments (given 1, expected at least 3)', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 1, expected at least 3)', + pcall_err_withfile(exec_lua, [[ return vim.tbl_extend("keep") ]]) ) - eq('Error executing lua: .../shared.lua: wrong number of arguments (given 2, expected at least 3)', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 2, expected at least 3)', + pcall_err_withfile(exec_lua, [[ return vim.tbl_extend("keep", {}) ]]) ) @@ -579,20 +598,20 @@ describe('lua stdlib', function() return vim.tbl_islist(c) and count == 0 ]])) - eq('Error executing lua: .../shared.lua: invalid "behavior": nil', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: invalid "behavior": nil', + pcall_err_withfile(exec_lua, [[ return vim.tbl_deep_extend() ]]) ) - eq('Error executing lua: .../shared.lua: wrong number of arguments (given 1, expected at least 3)', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 1, expected at least 3)', + pcall_err_withfile(exec_lua, [[ return vim.tbl_deep_extend("keep") ]]) ) - eq('Error executing lua: .../shared.lua: wrong number of arguments (given 2, expected at least 3)', - pcall_err(exec_lua, [[ + eq('.../helpers.lua:0: Error executing lua: shared.lua:0: wrong number of arguments (given 2, expected at least 3)', + pcall_err_withfile(exec_lua, [[ return vim.tbl_deep_extend("keep", {}) ]]) ) @@ -624,8 +643,11 @@ describe('lua stdlib', function() it('vim.list_extend', function() eq({1,2,3}, exec_lua [[ return vim.list_extend({1}, {2,3}) ]]) - eq('Error executing lua: .../shared.lua: src: expected table, got nil', - pcall_err(exec_lua, [[ return vim.list_extend({1}, nil) ]])) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: shared.lua:0: src: expected table, got nil + stack traceback: + shared.lua:0: in function <shared.lua:0>]]), + pcall_err_withfile(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) ]]) @@ -648,8 +670,8 @@ describe('lua stdlib', function() assert(vim.deep_equal(a, { A = 1; [1] = 'A'; })) vim.tbl_add_reverse_lookup(a) ]] - matches('Error executing lua: .../shared.lua: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"', - pcall_err(exec_lua, code)) + matches('.../helpers.lua:0: Error executing lua: shared.lua:0: The reverse lookup found an existing value for "[1A]" while processing key "[1A]"', + pcall_err_withfile(exec_lua, code)) end) it('vim.call, vim.fn', function() @@ -820,34 +842,77 @@ 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' }}") - eq("Error executing lua: .../shared.lua: 1: expected table, got number", - pcall_err(exec_lua, "vim.validate{ 1, 'x' }")) - eq("Error executing lua: .../shared.lua: invalid type name: x", - pcall_err(exec_lua, "vim.validate{ arg1={ 1, 'x' }}")) - eq("Error executing lua: .../shared.lua: invalid type name: 1", - pcall_err(exec_lua, "vim.validate{ arg1={ 1, 1 }}")) - eq("Error executing lua: .../shared.lua: invalid type name: nil", - pcall_err(exec_lua, "vim.validate{ arg1={ 1 }}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: opt[1]: expected table, got number + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ 1, 'x' }")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: x + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1, 'x' }}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: 1 + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1, 1 }}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: invalid type name: nil + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ arg1={ 1 }}")) -- Validated parameters are required by default. - eq("Error executing lua: .../shared.lua: arg1: expected string, got nil", - pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's' }}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ arg1={ nil, 's' }}")) -- Explicitly required. - eq("Error executing lua: .../shared.lua: arg1: expected string, got nil", - pcall_err(exec_lua, "vim.validate{ arg1={ nil, 's', false }}")) - - eq("Error executing lua: .../shared.lua: arg1: expected table, got number", - pcall_err(exec_lua, "vim.validate{arg1={1, 't'}}")) - eq("Error executing lua: .../shared.lua: arg2: expected string, got number", - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}")) - eq("Error executing lua: .../shared.lua: arg2: expected string, got nil", - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - eq("Error executing lua: .../shared.lua: arg2: expected string, got nil", - pcall_err(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) - eq("Error executing lua: .../shared.lua: arg1: expected even number, got 3", - pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}")) - eq("Error executing lua: .../shared.lua: arg1: expected ?, got 3", - pcall_err(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected string, got nil + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{ arg1={ nil, 's', false }}")) + + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected table, got number + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={1, 't'}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got number + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={1, 's'}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg2: expected string, got nil + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={{}, 't'}, arg2={nil, 's'}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected even number, got 3 + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end, 'even number'}}")) + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3 + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1 end}}")) + + -- Pass an additional message back. + eq(dedent([[ + .../helpers.lua:0: Error executing lua: [string "<nvim>"]:0: arg1: expected ?, got 3. Info: TEST_MSG + stack traceback: + [string "<nvim>"]:0: in main chunk]]), + pcall_err_withfile(exec_lua, "vim.validate{arg1={3, function(a) return a == 1, 'TEST_MSG' end}}")) end) it('vim.is_callable', function() @@ -992,10 +1057,10 @@ describe('lua stdlib', function() ]] eq('', funcs.luaeval "vim.bo.filetype") eq(true, funcs.luaeval "vim.bo[BUF].modifiable") - matches("^Error executing lua: .*: Invalid option name: 'nosuchopt'$", - pcall_err(exec_lua, 'return vim.bo.nosuchopt')) - matches("^Error executing lua: .*: Expected lua string$", - pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) + matches("^.../helpers.lua:0: Error executing lua: .*: Invalid option name: 'nosuchopt'$", + pcall_err_withfile(exec_lua, 'return vim.bo.nosuchopt')) + matches("^.../helpers.lua:0: Error executing lua: .*: Expected lua string$", + pcall_err_withfile(exec_lua, 'return vim.bo[0][0].autoread')) end) it('vim.wo', function() @@ -1011,10 +1076,10 @@ describe('lua stdlib', function() eq(0, funcs.luaeval "vim.wo.cole") eq(0, funcs.luaeval "vim.wo[0].cole") eq(0, funcs.luaeval "vim.wo[1001].cole") - matches("^Error executing lua: .*: Invalid option name: 'notanopt'$", - pcall_err(exec_lua, 'return vim.wo.notanopt')) - matches("^Error executing lua: .*: Expected lua string$", - pcall_err(exec_lua, 'return vim.wo[0][0].list')) + matches("^.../helpers.lua:0: Error executing lua: .*: Invalid option name: 'notanopt'$", + pcall_err_withfile(exec_lua, 'return vim.wo.notanopt')) + matches("^.../helpers.lua:0: Error executing lua: .*: Expected lua string$", + pcall_err_withfile(exec_lua, 'return vim.wo[0][0].list')) eq(2, funcs.luaeval "vim.wo[1000].cole") exec_lua [[ vim.wo[1000].cole = 0 diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index f514f4ea6f..067a13ce68 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -270,6 +270,70 @@ describe('LSP', function() test_name = "basic_check_capabilities"; on_init = function(client) client.stop() + local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") + eq(full_kind, client.resolved_capabilities().text_document_did_change) + end; + on_exit = function(code, signal) + eq(0, code, "exit code", fake_lsp_logfile) + eq(0, signal, "exit signal", fake_lsp_logfile) + end; + on_callback = function(...) + eq(table.remove(expected_callbacks), {...}, "expected callback") + end; + } + end) + + it('client.supports_methods() should validate capabilities', function() + local expected_callbacks = { + {NIL, "shutdown", {}, 1}; + } + test_rpc_server { + test_name = "capabilities_for_client_supports_method"; + on_init = function(client) + client.stop() + local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") + eq(full_kind, client.resolved_capabilities().text_document_did_change) + eq(true, client.resolved_capabilities().completion) + eq(true, client.resolved_capabilities().hover) + eq(false, client.resolved_capabilities().goto_definition) + eq(false, client.resolved_capabilities().rename) + + -- known methods for resolved capabilities + eq(true, client.supports_method("textDocument/hover")) + eq(false, client.supports_method("textDocument/definition")) + + -- unknown methods are assumed to be supported. + eq(true, client.supports_method("unknown-method")) + end; + on_exit = function(code, signal) + eq(0, code, "exit code", fake_lsp_logfile) + eq(0, signal, "exit signal", fake_lsp_logfile) + end; + on_callback = function(...) + eq(table.remove(expected_callbacks), {...}, "expected callback") + end; + } + end) + + it('should call unsupported_method when trying to call an unsupported method', function() + local expected_callbacks = { + {NIL, "shutdown", {}, 1}; + } + test_rpc_server { + test_name = "capabilities_for_client_supports_method"; + on_setup = function() + exec_lua([=[ + vim.lsp._unsupported_method = function(method) + vim.lsp._last_unsupported_method = method + return 'fake-error' + end + vim.lsp.buf.hover() + ]=]) + end; + on_init = function(client) + client.stop() + local method = exec_lua("return vim.lsp._last_unsupported_method") + eq("textDocument/hover", method) end; on_exit = function(code, signal) eq(0, code, "exit code", fake_lsp_logfile) @@ -747,8 +811,16 @@ describe('LSP', function() end) it('should invalid cmd argument', function() - eq('Error executing lua: .../shared.lua: cmd: expected list, got nvim', pcall_err(_cmd_parts, "nvim")) - eq('Error executing lua: .../shared.lua: cmd argument: expected string, got number', pcall_err(_cmd_parts, {"nvim", 1})) + eq(dedent([[ + Error executing lua: .../lsp.lua:0: cmd: expected list, got nvim + stack traceback: + .../lsp.lua:0: in function .../lsp.lua:0>]]), + pcall_err(_cmd_parts, 'nvim')) + eq(dedent([[ + Error executing lua: .../lsp.lua:0: cmd argument: expected string, got number + stack traceback: + .../lsp.lua:0: in function .../lsp.lua:0>]]), + pcall_err(_cmd_parts, {'nvim', 1})) end) end) end) diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua index bb7d23ede6..2729d8dfa2 100644 --- a/test/functional/provider/ruby_spec.lua +++ b/test/functional/provider/ruby_spec.lua @@ -5,6 +5,7 @@ local command = helpers.command local curbufmeths = helpers.curbufmeths local eq = helpers.eq local eval = helpers.eval +local exc_exec = helpers.exc_exec local expect = helpers.expect local feed = helpers.feed local feed_command = helpers.feed_command @@ -109,3 +110,24 @@ describe('ruby provider', function() eq(2, eval('1+1')) -- Still alive? end) end) + +describe('rubyeval()', function() + it('evaluates ruby objects', function() + eq({1, 2, {['key'] = 'val'}}, funcs.rubyeval('[1, 2, {key: "val"}]')) + end) + + it('returns nil for empty strings', function() + eq(helpers.NIL, funcs.rubyeval('')) + end) + + it('errors out when given non-string', function() + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(10)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_dict)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:_null_list)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(0.0)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(function("tr"))')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:true)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:false)')) + eq('Vim(call):E474: Invalid argument', exc_exec('call rubyeval(v:null)')) + end) +end) diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 6372cd935e..8e171d31aa 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source local eq, neq = helpers.eq, helpers.neq local write_file = helpers.write_file @@ -13,7 +13,7 @@ describe(':terminal buffer', function() before_each(function() clear() feed_command('set modifiable swapfile undolevels=20') - wait() + poke_eventloop() screen = thelpers.screen_setup() end) diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index ef12438ecc..8d70ebf679 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -70,7 +70,7 @@ describe(':terminal cursor', function() :set number | ]]) feed('i') - helpers.wait() + helpers.poke_eventloop() screen:expect([[ {7: 1 }tty ready | {7: 2 }rows: 6, cols: 46 | diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 138befd978..4b512605e1 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, wait, nvim = helpers.clear, helpers.wait, helpers.nvim +local clear, poke_eventloop, nvim = helpers.clear, helpers.poke_eventloop, helpers.nvim local nvim_dir, source, eq = helpers.nvim_dir, helpers.source, helpers.eq local feed = helpers.feed local feed_command, eval = helpers.feed_command, helpers.eval @@ -29,7 +29,7 @@ describe(':terminal', function() -- Invoke a command that emits frequent terminal activity. feed([[:terminal "]]..nvim_dir..[[/shell-test" REP 9999 !terminal_output!<cr>]]) feed([[<C-\><C-N>]]) - wait() + poke_eventloop() -- Wait for some terminal activity. retry(nil, 4000, function() ok(funcs.line('$') > 6) @@ -60,7 +60,7 @@ describe(':terminal', function() feed_command([[terminal while true; do echo foo; sleep .1; done]]) end feed([[<C-\><C-N>M]]) -- move cursor away from last line - wait() + poke_eventloop() eq(3, eval("line('$')")) -- window height eq(2, eval("line('.')")) -- cursor is in the middle feed_command('vsplit') @@ -76,11 +76,11 @@ describe(':terminal', function() -- Create a new line (in the shell). For a normal buffer this -- increments the jumplist; for a terminal-buffer it should not. #3723 feed('i') - wait() + poke_eventloop() feed('<CR><CR><CR><CR>') - wait() + poke_eventloop() feed([[<C-\><C-N>]]) - wait() + poke_eventloop() -- Wait for >=1 lines to be created. retry(nil, 4000, function() ok(funcs.line('$') > lines_before) @@ -210,7 +210,7 @@ describe(':terminal (with fake shell)', function() it('ignores writes if the backing stream closes', function() terminal_with_fake_shell() feed('iiXXXXXXX') - wait() + poke_eventloop() -- Race: Though the shell exited (and streams were closed by SIGCHLD -- handler), :terminal cleanup is pending on the main-loop. -- This write should be ignored (not crash, #5445). diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 1df8df6f6e..77fdba7fc4 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -6,7 +6,7 @@ local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.fee local iswin = helpers.iswin local eval = helpers.eval local command = helpers.command -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local retry = helpers.retry local curbufmeths = helpers.curbufmeths local nvim = helpers.nvim @@ -347,7 +347,7 @@ describe(':terminal prints more lines than the screen height and exits', functio local screen = Screen.new(30, 7) screen:attach({rgb=false}) feed_command('call termopen(["'..nvim_dir..'/tty-test", "10"]) | startinsert') - wait() + poke_eventloop() screen:expect([[ line6 | line7 | @@ -423,7 +423,7 @@ describe("'scrollback' option", function() retry(nil, nil, function() expect_lines(33, 2) end) curbufmeths.set_option('scrollback', 10) - wait() + poke_eventloop() retry(nil, nil, function() expect_lines(16) end) curbufmeths.set_option('scrollback', 10000) retry(nil, nil, function() expect_lines(16) end) diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index f1c828d17e..9f278fd157 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local feed_data = thelpers.feed_data local feed, clear = helpers.feed, helpers.clear -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local iswin = helpers.iswin local command = helpers.command local retry = helpers.retry @@ -127,7 +127,7 @@ describe(':terminal window', function() it('wont show any folds', function() feed([[<C-\><C-N>ggvGzf]]) - wait() + poke_eventloop() screen:expect([[ ^tty ready | line1 | diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 11fe861de8..eec8eb93d4 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -59,7 +59,7 @@ describe('floatwin', function() end) it('closed immediately by autocmd #11383', function() - eq('Error executing lua: [string "<nvim>"]:4: Window was closed immediately', + eq('Error executing lua: [string "<nvim>"]:0: Window was closed immediately', pcall_err(exec_lua, [[ local a = vim.api local function crashes(contents) diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 16c5477ee4..712c1f377a 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -14,7 +14,7 @@ local neq = helpers.neq local ok = helpers.ok local retry = helpers.retry local source = helpers.source -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop local nvim = helpers.nvim local sleep = helpers.sleep local nvim_dir = helpers.nvim_dir @@ -114,7 +114,7 @@ describe(":substitute, inccommand=split interactivity", function() it("no preview if invoked by a script", function() source('%s/tw/MO/g') - wait() + poke_eventloop() eq(1, eval("bufnr('$')")) -- sanity check: assert the buffer state expect(default_text:gsub("tw", "MO")) @@ -123,10 +123,10 @@ describe(":substitute, inccommand=split interactivity", function() it("no preview if invoked by feedkeys()", function() -- in a script... source([[:call feedkeys(":%s/tw/MO/g\<CR>")]]) - wait() + poke_eventloop() -- or interactively... feed([[:call feedkeys(":%s/tw/MO/g\<CR>")<CR>]]) - wait() + poke_eventloop() eq(1, eval("bufnr('$')")) -- sanity check: assert the buffer state expect(default_text:gsub("tw", "MO")) @@ -194,7 +194,7 @@ describe(":substitute, 'inccommand' preserves", function() -- Start typing an incomplete :substitute command. feed([[:%s/e/YYYY/g]]) - wait() + poke_eventloop() -- Cancel the :substitute. feed([[<C-\><C-N>]]) @@ -230,7 +230,7 @@ describe(":substitute, 'inccommand' preserves", function() -- Start typing an incomplete :substitute command. feed([[:%s/e/YYYY/g]]) - wait() + poke_eventloop() -- Cancel the :substitute. feed([[<C-\><C-N>]]) @@ -251,7 +251,7 @@ describe(":substitute, 'inccommand' preserves", function() some text 1 some text 2]]) feed(":%s/e/XXX/") - wait() + poke_eventloop() eq(expected_tick, eval("b:changedtick")) end) @@ -1128,15 +1128,15 @@ describe(":substitute, inccommand=split", function() feed(":%s/tw/Xo/g") -- Delete and re-type the g a few times. feed("<BS>") - wait() + poke_eventloop() feed("g") - wait() + poke_eventloop() feed("<BS>") - wait() + poke_eventloop() feed("g") - wait() + poke_eventloop() feed("<CR>") - wait() + poke_eventloop() feed(":vs tmp<enter>") eq(3, helpers.call('bufnr', '$')) end) @@ -1171,7 +1171,7 @@ describe(":substitute, inccommand=split", function() feed_command("silent edit! test/functional/fixtures/bigfile_oneline.txt") -- Start :substitute with a slow pattern. feed([[:%s/B.*N/x]]) - wait() + poke_eventloop() -- Assert that 'inccommand' is DISABLED in cmdline mode. eq("", eval("&inccommand")) @@ -1360,7 +1360,7 @@ describe("inccommand=nosplit", function() feed("<Esc>") command("set icm=nosplit") feed(":%s/tw/OKOK") - wait() + poke_eventloop() screen:expect([[ Inc substitution on | {12:OKOK}o lines | @@ -2592,7 +2592,7 @@ describe(":substitute", function() feed("<C-c>") feed('gg') - wait() + poke_eventloop() feed([[:%s/\(some\)\@<lt>!thing/one/]]) screen:expect([[ something | @@ -2613,7 +2613,7 @@ describe(":substitute", function() ]]) feed([[<C-c>]]) - wait() + poke_eventloop() feed([[:%s/some\(thing\)\@=/every/]]) screen:expect([[ {12:every}thing | @@ -2634,7 +2634,7 @@ describe(":substitute", function() ]]) feed([[<C-c>]]) - wait() + poke_eventloop() feed([[:%s/some\(thing\)\@!/every/]]) screen:expect([[ something | @@ -2718,7 +2718,7 @@ it(':substitute with inccommand during :terminal activity', function() feed('gg') feed(':%s/foo/ZZZ') sleep(20) -- Allow some terminal activity. - helpers.wait() + helpers.poke_eventloop() screen:expect_unchanged() end) end) diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index d857b57a31..a741136111 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -546,7 +546,7 @@ describe('ui/mouse/input', function() :tabprevious | ]]) feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab - helpers.wait() + helpers.poke_eventloop() feed('<LeftMouse><0,1>') screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua index e4d1187dea..6601c2d68e 100644 --- a/test/functional/ui/multigrid_spec.lua +++ b/test/functional/ui/multigrid_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local feed, command, insert = helpers.feed, helpers.command, helpers.insert local eq = helpers.eq local meths = helpers.meths -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('ext_multigrid', function() @@ -1846,8 +1846,8 @@ describe('ext_multigrid', function() meths.input_mouse('left', 'press', '', 1,6, 20) -- TODO(bfredl): "batching" input_mouse is formally not supported yet. -- Normally it should work fine in async context when nvim is not blocked, - -- but add a wait be sure. - wait() + -- but add a poke_eventloop be sure. + poke_eventloop() meths.input_mouse('left', 'drag', '', 1, 4, 20) screen:expect{grid=[[ ## grid 1 @@ -1921,7 +1921,7 @@ describe('ext_multigrid', function() ]]} meths.input_mouse('left', 'press', '', 1,8, 26) - wait() + poke_eventloop() meths.input_mouse('left', 'drag', '', 1, 6, 30) screen:expect{grid=[[ ## grid 1 diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index c1c5d1ce2e..3f984ff943 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -1213,10 +1213,10 @@ describe('builtin popupmenu', function() funcs.complete(29, {'word', 'choice', 'text', 'thing'}) screen:expect([[ some long prefix before the ^ | - {n:word }{1: }| - {n:choice }{1: }| - {n:text }{1: }| - {n:thing }{1: }| + {1:~ }{n: word }| + {1:~ }{n: choice}| + {1:~ }{n: text }| + {1:~ }{n: thing }| {1:~ }| {1:~ }| {1:~ }| @@ -1261,10 +1261,10 @@ describe('builtin popupmenu', function() feed('<c-p>') screen:expect([[ some long prefix before the text| - {n:^word }{1: }| - {n:choice }{1: }| - {s:text }{1: }| - {n:thing }{1: }| + {1:^~ }{n: word }| + {1:~ }{n: choice}| + {1:~ }{s: text }| + {1:~ }{n: thing }| {1:~ }| {1:~ }| {1:~ }| @@ -1341,10 +1341,10 @@ describe('builtin popupmenu', function() screen:expect([[ some long prefix | before the text^ | - {1:~ }{n: word }| - {1:~ }{n: choice }| - {1:~ }{s: text }| - {1:~ }{n: thing }| + {1:~ }{n: word }{1: }| + {1:~ }{n: choice }{1: }| + {1:~ }{s: text }{1: }| + {1:~ }{n: thing }{1: }| {1:~ }| {2:-- INSERT --} | ]]) @@ -1358,10 +1358,10 @@ describe('builtin popupmenu', function() funcs.complete(29, {'word', 'choice', 'text', 'thing'}) screen:expect([[ some long prefix before the ^ | - {n:word }{1: }| - {n:choice }{1: }| - {n:text }{1: }| - {n:thing }{1: }| + {1:~ }{n: word }| + {1:~ }{n: choice}| + {1:~ }{n: text }| + {1:~ }{n: thing }| {1:~ }| {1:~ }| {1:~ }| @@ -2168,8 +2168,8 @@ describe('builtin popupmenu', function() funcs.complete(29, {'word', 'choice', 'text', 'thing'}) screen:expect([[ some long prefix before the ^ | - {n:word }{c: }{1: }| - {n:choice }{s: }{1: }| + {1:~ }{n: word }{c: }| + {1:~ }{n: choice}{s: }| {1:~ }| {1:~ }| {1:~ }| @@ -2187,10 +2187,10 @@ describe('builtin popupmenu', function() funcs.complete(29, {'word', 'choice', 'text', 'thing'}) screen:expect([[ some long prefix before the ^ | - {n:word }{1: }| - {n:choice }{1: }| - {n:text }{1: }| - {n:thing }{1: }| + {1:~ }{n: word }| + {1:~ }{n: choice}| + {1:~ }{n: text }| + {1:~ }{n: thing }| {1:~ }| {1:~ }| {2:-- INSERT --} | diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index 635ce7392b..222275eb4d 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -158,7 +158,7 @@ describe('search highlighting', function() bar foo baz ]]) feed('/foo') - helpers.wait() + helpers.poke_eventloop() screen:expect_unchanged() end) diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 9d4cb325d9..01fc50289d 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -6,7 +6,7 @@ local feed_command, source, expect = helpers.feed_command, helpers.source, helpe local curbufmeths = helpers.curbufmeths local command = helpers.command local meths = helpers.meths -local wait = helpers.wait +local poke_eventloop = helpers.poke_eventloop describe('completion', function() local screen @@ -737,8 +737,8 @@ describe('completion', function() -- Does not indent when "ind" is typed. feed("in<C-X><C-N>") -- Completion list is generated incorrectly if we send everything at once - -- via nvim_input(). So wait() before sending <BS>. #8480 - wait() + -- via nvim_input(). So poke_eventloop() before sending <BS>. #8480 + poke_eventloop() feed("<BS>d") screen:expect([[ @@ -778,7 +778,7 @@ describe('completion', function() ]]) -- Works for unindenting too. feed("ounin<C-X><C-N>") - helpers.wait() + helpers.poke_eventloop() feed("<BS>d") screen:expect([[ inc uninc indent unindent | @@ -1000,65 +1000,65 @@ describe('completion', function() command('let g:foo = []') feed('o') - wait() + poke_eventloop() feed('<esc>') eq({'I'}, eval('g:foo')) command('let g:foo = []') feed('S') - wait() + poke_eventloop() feed('f') - wait() + poke_eventloop() eq({'I', 'I'}, eval('g:foo')) feed('<esc>') command('let g:foo = []') feed('S') - wait() + poke_eventloop() feed('f') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() eq({'I', 'I', 'P'}, eval('g:foo')) feed('<esc>') command('let g:foo = []') feed('S') - wait() + poke_eventloop() feed('f') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() eq({'I', 'I', 'P', 'P'}, eval('g:foo')) feed('<esc>') command('let g:foo = []') feed('S') - wait() + poke_eventloop() feed('f') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() eq({'I', 'I', 'P', 'P', 'P'}, eval('g:foo')) feed('<esc>') command('let g:foo = []') feed('S') - wait() + poke_eventloop() feed('f') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') - wait() + poke_eventloop() feed('<C-N>') eq({'I', 'I', 'P', 'P', 'P', 'P'}, eval('g:foo')) feed('<esc>') diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/viml/errorlist_spec.lua index c5390cbd12..9acc61e398 100644 --- a/test/functional/viml/errorlist_spec.lua +++ b/test/functional/viml/errorlist_spec.lua @@ -27,7 +27,7 @@ describe('setqflist()', function() setqflist({''}, 'r', 'foo') command('copen') eq('foo', get_cur_win_var('quickfix_title')) - setqflist({''}, 'r', {['title'] = 'qf_title'}) + setqflist({}, 'r', {['title'] = 'qf_title'}) eq('qf_title', get_cur_win_var('quickfix_title')) end) |