diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-08-11 09:27:48 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-09-21 16:04:09 +0100 |
commit | e5c174421df3872df0dd3a676609d1e74dfef6a9 (patch) | |
tree | 39354b9db7b9f3ccb9145f52d11574baa4508951 /test/functional/lua | |
parent | a19e89022d8b72ee92bb974100b497f1c79b7765 (diff) | |
download | rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.gz rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.bz2 rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.zip |
test: support upvalues in exec_lua
Diffstat (limited to 'test/functional/lua')
-rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 127 | ||||
-rw-r--r-- | test/functional/lua/ffi_spec.lua | 56 | ||||
-rw-r--r-- | test/functional/lua/filetype_spec.lua | 17 | ||||
-rw-r--r-- | test/functional/lua/fs_spec.lua | 34 | ||||
-rw-r--r-- | test/functional/lua/glob_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/lua/highlight_spec.lua | 68 | ||||
-rw-r--r-- | test/functional/lua/inspector_spec.lua | 31 | ||||
-rw-r--r-- | test/functional/lua/loader_spec.lua | 42 | ||||
-rw-r--r-- | test/functional/lua/loop_spec.lua | 74 | ||||
-rw-r--r-- | test/functional/lua/mpack_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/lua/overrides_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/lua/system_spec.lua | 32 |
13 files changed, 271 insertions, 261 deletions
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 8ca97c8e5e..f277868b1c 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -282,19 +282,19 @@ describe('lua buffer event callbacks: on_lines', function() end) it('does not SEGFAULT when accessing window buffer info in on_detach #14998', function() - local code = [[ + local code = function() local buf = vim.api.nvim_create_buf(false, false) - vim.cmd"split" + vim.cmd 'split' vim.api.nvim_win_set_buf(0, buf) vim.api.nvim_buf_attach(buf, false, { - on_detach = function(_, buf) + on_detach = function(_, buf0) vim.fn.tabpagebuflist() - vim.fn.win_findbuf(buf) - end + vim.fn.win_findbuf(buf0) + end, }) - ]] + end exec_lua(code) command('q!') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 718b9469a3..4ae1146703 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1,7 +1,6 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() -local NIL = vim.NIL local command = n.command local clear = n.clear local exec_lua = n.exec_lua @@ -175,11 +174,11 @@ describe('vim.diagnostic', function() eq(3, #result) eq( 2, - exec_lua(function(result0) + exec_lua(function() return #vim.tbl_filter(function(d) return d.bufnr == _G.diagnostic_bufnr - end, result0) - end, result) + end, result) + end) ) eq('Diagnostic #1', result[1].message) end) @@ -792,7 +791,7 @@ describe('vim.diagnostic', function() --- @return table local function test_enable(legacy) - local result = exec_lua(function(legacy0) + return exec_lua(function() local other_bufnr = vim.api.nvim_create_buf(true, false) vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr) @@ -823,7 +822,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.disable(_G.diagnostic_bufnr, _G.diagnostic_ns) else vim.diagnostic.enable(false, { bufnr = _G.diagnostic_bufnr, ns_id = _G.diagnostic_ns }) @@ -836,7 +835,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.disable(_G.diagnostic_bufnr, _G.other_ns) else vim.diagnostic.enable(false, { bufnr = _G.diagnostic_bufnr, ns_id = _G.other_ns }) @@ -849,7 +848,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.enable(_G.diagnostic_bufnr, _G.diagnostic_ns) else vim.diagnostic.enable(true, { bufnr = _G.diagnostic_bufnr, ns_id = _G.diagnostic_ns }) @@ -862,7 +861,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then -- Should have no effect vim.diagnostic.disable(other_bufnr, _G.other_ns) else @@ -878,9 +877,7 @@ describe('vim.diagnostic', function() ) return result - end, legacy) - - return result + end) end it('with both buffer and namespace arguments', function() @@ -1052,7 +1049,7 @@ describe('vim.diagnostic', function() it('will not cycle when wrap is off', function() eq( - vim.NIL, + nil, exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Diagnostic #1', 1, 1, 1, 1), @@ -1261,7 +1258,7 @@ describe('vim.diagnostic', function() it('respects wrap parameter', function() eq( - vim.NIL, + nil, exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Diagnostic #2', 4, 4, 4, 4), @@ -1514,12 +1511,14 @@ describe('vim.diagnostic', function() describe('count', function() it('returns actually present severity counts', function() eq( - exec_lua [[return { - [vim.diagnostic.severity.ERROR] = 4, - [vim.diagnostic.severity.WARN] = 3, - [vim.diagnostic.severity.INFO] = 2, - [vim.diagnostic.severity.HINT] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.ERROR] = 4, + [vim.diagnostic.severity.WARN] = 3, + [vim.diagnostic.severity.INFO] = 2, + [vim.diagnostic.severity.HINT] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 2), @@ -1537,10 +1536,12 @@ describe('vim.diagnostic', function() end) ) eq( - exec_lua [[return { - [vim.diagnostic.severity.ERROR] = 2, - [vim.diagnostic.severity.INFO] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.ERROR] = 2, + [vim.diagnostic.severity.INFO] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 2), @@ -1554,11 +1555,17 @@ describe('vim.diagnostic', function() it('returns only requested diagnostics count when severity range is supplied', function() eq( - exec_lua [[return { - { [vim.diagnostic.severity.ERROR] = 1, [vim.diagnostic.severity.WARN] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1, [vim.diagnostic.severity.HINT] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, - }]], + exec_lua(function() + return { + { [vim.diagnostic.severity.ERROR] = 1, [vim.diagnostic.severity.WARN] = 1 }, + { + [vim.diagnostic.severity.WARN] = 1, + [vim.diagnostic.severity.INFO] = 1, + [vim.diagnostic.severity.HINT] = 1, + }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1589,11 +1596,13 @@ describe('vim.diagnostic', function() it('returns only requested diagnostics when severities are supplied', function() eq( - exec_lua [[return { - { [vim.diagnostic.severity.WARN] = 1 }, - { [vim.diagnostic.severity.ERROR] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, - }]], + exec_lua(function() + return { + { [vim.diagnostic.severity.WARN] = 1 }, + { [vim.diagnostic.severity.ERROR] = 1 }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1624,10 +1633,12 @@ describe('vim.diagnostic', function() it('allows filtering by line', function() eq( - exec_lua [[return { - [vim.diagnostic.severity.WARN] = 1, - [vim.diagnostic.severity.INFO] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.WARN] = 1, + [vim.diagnostic.severity.INFO] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1764,11 +1775,11 @@ describe('vim.diagnostic', function() it('allows filtering by severity', function() local get_extmark_count_with_severity = function(min_severity) - return exec_lua(function(min_severity0) + return exec_lua(function() vim.diagnostic.config({ underline = false, virtual_text = { - severity = { min = min_severity0 }, + severity = { min = min_severity }, }, }) @@ -1777,7 +1788,7 @@ describe('vim.diagnostic', function() }) return _G.count_extmarks(_G.diagnostic_bufnr, _G.diagnostic_ns) - end, min_severity) + end) end -- No messages with Error or higher @@ -2512,7 +2523,7 @@ describe('vim.diagnostic', function() -- End position is exclusive eq( - vim.NIL, + nil, exec_lua(function() local diagnostics = { _G.make_error('Syntax error', 1, 1, 2, 0), @@ -2606,7 +2617,7 @@ describe('vim.diagnostic', function() -- End position is exclusive eq( - vim.NIL, + nil, exec_lua(function() local diagnostics = { _G.make_error('Syntax error', 1, 1, 1, 3), @@ -2851,10 +2862,10 @@ describe('vim.diagnostic', function() it('can filter by severity', function() local count_diagnostics_with_severity = function(min_severity, max_severity) - return exec_lua(function(min_severity0, max_severity0) + return exec_lua(function() vim.diagnostic.config({ float = { - severity = { min = min_severity0, max = max_severity0 }, + severity = { min = min_severity, max = max_severity }, }, }) @@ -2874,7 +2885,7 @@ describe('vim.diagnostic', function() local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - end, min_severity, max_severity) + end) end eq(2, count_diagnostics_with_severity('ERROR')) @@ -3060,7 +3071,7 @@ describe('vim.diagnostic', function() -- open float failed non diagnostic lnum eq( - vim.NIL, + nil, exec_lua(function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) local _, winnr = vim.diagnostic.open_float(0, { header = false }) @@ -3068,7 +3079,7 @@ describe('vim.diagnostic', function() end) ) eq( - vim.NIL, + nil, exec_lua(function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) local _, winnr = vim.diagnostic.open_float(0, { header = false, scope = 'cursor' }) @@ -3180,19 +3191,19 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^(%w+): [^:]+:(%d+):(%d+):(.+)$', { 'severity', 'lnum', 'col', 'message' } ) - end, msg) + end) ) end) it('returns nil if the pattern fails to match', function() eq( - NIL, + nil, exec_lua(function() local msg = 'The answer to life, the universe, and everything is' return vim.diagnostic.match(msg, 'This definitely will not match', {}) @@ -3212,15 +3223,15 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^[^:]+:(%d+):(.+)$', { 'lnum', 'message' }, nil, { severity = vim.diagnostic.severity.INFO } ) - end, msg) + end) ) end) @@ -3236,14 +3247,14 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^(%d+):(%w+):(.+)$', { 'lnum', 'severity', 'message' }, { FATAL = vim.diagnostic.severity.ERROR } ) - end, msg) + end) ) end) end) diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua index 85ca264107..96f5812493 100644 --- a/test/functional/lua/ffi_spec.lua +++ b/test/functional/lua/ffi_spec.lua @@ -15,27 +15,27 @@ describe('ffi.cdef', function() eq( 12, - exec_lua [=[ - local ffi = require('ffi') + exec_lua(function() + local ffi = require('ffi') - ffi.cdef [[ + ffi.cdef [[ typedef struct window_S win_T; int win_col_off(win_T *wp); extern win_T *curwin; ]] - vim.cmd('set number numberwidth=4 signcolumn=yes:4') + vim.cmd('set number numberwidth=4 signcolumn=yes:4') - return ffi.C.win_col_off(ffi.C.curwin) - ]=] + return ffi.C.win_col_off(ffi.C.curwin) + end) ) eq( 20, - exec_lua [=[ - local ffi = require('ffi') + exec_lua(function() + local ffi = require('ffi') - ffi.cdef[[ + ffi.cdef [[ typedef struct {} stl_hlrec_t; typedef struct {} StlClickRecord; typedef struct {} statuscol_T; @@ -58,32 +58,32 @@ describe('ffi.cdef', function() ); ]] - return ffi.C.build_stl_str_hl( - ffi.C.find_window_by_handle(0, ffi.new('Error')), - ffi.new('char[1024]'), - 1024, - ffi.cast('char*', 'StatusLineOfLength20'), - -1, - 0, - 0, - 0, - nil, - nil, - nil - ) - ]=] + return ffi.C.build_stl_str_hl( + ffi.C.find_window_by_handle(0, ffi.new('Error')), + ffi.new('char[1024]'), + 1024, + ffi.cast('char*', 'StatusLineOfLength20'), + -1, + 0, + 0, + 0, + nil, + nil, + nil + ) + end) ) -- Check that extern symbols are exported and accessible eq( true, - exec_lua [[ - local ffi = require('ffi') + exec_lua(function() + local ffi = require('ffi') - ffi.cdef('uint64_t display_tick;') + ffi.cdef('uint64_t display_tick;') - return ffi.C.display_tick >= 0 - ]] + return ffi.C.display_tick >= 0 + end) ) end) end) diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua index b5eb9fab23..574c837f92 100644 --- a/test/functional/lua/filetype_spec.lua +++ b/test/functional/lua/filetype_spec.lua @@ -70,15 +70,15 @@ describe('vim.filetype', function() eq( 'dosini', - exec_lua(function(root0) + exec_lua(function() vim.filetype.add({ filename = { ['config'] = 'toml', - [root0 .. '/.config/fun/config'] = 'dosini', + [root .. '/.config/fun/config'] = 'dosini', }, }) - return vim.filetype.match({ filename = root0 .. '/.config/fun/config' }) - end, root) + return vim.filetype.match({ filename = root .. '/.config/fun/config' }) + end) ) end) @@ -123,7 +123,7 @@ describe('vim.filetype', function() exec_lua(function() -- Needs to be set so detect#sh doesn't fail vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$' - return vim.filetype.match({ contents = { '#!/usr/bin/env bash' } }) + return (vim.filetype.match({ contents = { '#!/usr/bin/env bash' } })) end) ) end) @@ -152,7 +152,12 @@ describe('vim.filetype', function() xml = { formatexpr = 'xmlformat#Format()' }, } do for option, value in pairs(opts) do - eq(value, exec_lua([[ return vim.filetype.get_option(...) ]], ft, option)) + eq( + value, + exec_lua(function() + return vim.filetype.get_option(ft, option) + end) + ) end end end) diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 4848787ed2..f0d49205e7 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -141,14 +141,14 @@ describe('vim.fs', function() it('works', function() eq( true, - exec_lua(function(dir, nvim) - for name, type in vim.fs.dir(dir) do - if name == nvim and type == 'file' then + exec_lua(function() + for name, type in vim.fs.dir(nvim_dir) do + if name == nvim_prog_basename and type == 'file' then return true end end return false - end, nvim_dir, nvim_prog_basename) + end) ) end) @@ -167,22 +167,21 @@ describe('vim.fs', function() io.open('testd/a/b/c/c4', 'w'):close() local function run(dir, depth, skip) - local r = exec_lua(function(dir0, depth0, skip0) + return exec_lua(function() local r = {} local skip_f - if skip0 then + if skip then skip_f = function(n0) - if vim.tbl_contains(skip0 or {}, n0) then + if vim.tbl_contains(skip or {}, n0) then return false end end end - for name, type_ in vim.fs.dir(dir0, { depth = depth0, skip = skip_f }) do + for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do r[name] = type_ end return r - end, dir, depth, skip) - return r + end) end local exp = {} @@ -252,9 +251,12 @@ describe('vim.fs', function() opts = { path = test_source_path .. '/contrib', limit = math.huge } eq( - exec_lua(function(dir) - return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir .. '/contrib/*', false, true)) - end, test_source_path), + exec_lua(function() + return vim.tbl_map( + vim.fs.basename, + vim.fn.glob(test_source_path .. '/contrib/*', false, true) + ) + end), vim.tbl_map( vim.fs.basename, vim.fs.find(function(_, d) @@ -337,10 +339,10 @@ describe('vim.fs', function() local xdg_config_home = test_build_dir .. '/.config' eq( xdg_config_home .. '/nvim', - exec_lua(function(...) - vim.env.XDG_CONFIG_HOME = ... + exec_lua(function() + vim.env.XDG_CONFIG_HOME = xdg_config_home return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') - end, xdg_config_home) + end) ) end) diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua index 6f1e5be501..8302c7334d 100644 --- a/test/functional/lua/glob_spec.lua +++ b/test/functional/lua/glob_spec.lua @@ -2,16 +2,15 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() local eq = t.eq -local exec_lua = n.exec_lua describe('glob', function() before_each(n.clear) after_each(n.clear) - local match = function(...) - return exec_lua(function(pattern, str) + local match = function(pattern, str) + return n.exec_lua(function() return require('vim.glob').to_lpeg(pattern):match(str) ~= nil - end, ...) + end) end describe('glob matching', function() diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua index ad709a06f1..c048949df8 100644 --- a/test/functional/lua/highlight_spec.lua +++ b/test/functional/lua/highlight_spec.lua @@ -31,10 +31,10 @@ describe('vim.highlight.range', function() end) it('works with charwise selection', function() - exec_lua([[ + exec_lua(function() local ns = vim.api.nvim_create_namespace('') vim.highlight.range(0, ns, 'Search', { 1, 5 }, { 3, 10 }) - ]]) + end) screen:expect([[ ^asdfghjkl{1:$} | «口{10:=口»}{100:$} | @@ -46,10 +46,10 @@ describe('vim.highlight.range', function() end) it('works with linewise selection', function() - exec_lua([[ + exec_lua(function() local ns = vim.api.nvim_create_namespace('') vim.highlight.range(0, ns, 'Search', { 0, 0 }, { 4, 0 }, { regtype = 'V' }) - ]]) + end) screen:expect([[ {10:^asdfghjkl}{100:$} | {10:«口=口»}{100:$} | @@ -61,10 +61,10 @@ describe('vim.highlight.range', function() end) it('works with blockwise selection', function() - exec_lua([[ + exec_lua(function() local ns = vim.api.nvim_create_namespace('') vim.highlight.range(0, ns, 'Search', { 0, 0 }, { 4, 4 }, { regtype = '\022' }) - ]]) + end) screen:expect([[ {10:^asdf}ghjkl{1:$} | {10:«口=}口»{1:$} | @@ -76,10 +76,10 @@ describe('vim.highlight.range', function() end) it('works with blockwise selection with width', function() - exec_lua([[ + exec_lua(function() local ns = vim.api.nvim_create_namespace('') vim.highlight.range(0, ns, 'Search', { 0, 4 }, { 4, 7 }, { regtype = '\0226' }) - ]]) + end) screen:expect([[ ^asdf{10:ghjkl}{1:$} | «口={10:口»}{1:$} | @@ -91,11 +91,11 @@ describe('vim.highlight.range', function() end) it('can use -1 or v:maxcol to indicate end of line', function() - exec_lua([[ + exec_lua(function() local ns = vim.api.nvim_create_namespace('') vim.highlight.range(0, ns, 'Search', { 0, 4 }, { 1, -1 }, {}) vim.highlight.range(0, ns, 'Search', { 2, 6 }, { 3, vim.v.maxcol }, {}) - ]]) + end) screen:expect([[ ^asdf{10:ghjkl}{100:$} | {10:«口=口»}{100:$} | @@ -114,33 +114,37 @@ describe('vim.highlight.on_yank', function() it('does not show errors even if buffer is wiped before timeout', function() command('new') - exec_lua([[ - vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y", regtype = "v"}}) + exec_lua(function() + vim.highlight.on_yank({ + timeout = 10, + on_macro = true, + event = { operator = 'y', regtype = 'v' }, + }) vim.cmd('bwipeout!') - ]]) + end) vim.uv.sleep(10) n.feed('<cr>') -- avoid hang if error message exists eq('', eval('v:errmsg')) end) it('does not close timer twice', function() - exec_lua([[ - vim.highlight.on_yank({timeout = 10, on_macro = true, event = {operator = "y"}}) + exec_lua(function() + vim.highlight.on_yank({ timeout = 10, on_macro = true, event = { operator = 'y' } }) vim.uv.sleep(10) vim.schedule(function() - vim.highlight.on_yank({timeout = 0, on_macro = true, event = {operator = "y"}}) + vim.highlight.on_yank({ timeout = 0, on_macro = true, event = { operator = 'y' } }) end) - ]]) + end) eq('', eval('v:errmsg')) end) it('does not show in another window', function() command('vsplit') - exec_lua([[ - vim.api.nvim_buf_set_mark(0,"[",1,1,{}) - vim.api.nvim_buf_set_mark(0,"]",1,1,{}) - vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}}) - ]]) + exec_lua(function() + vim.api.nvim_buf_set_mark(0, '[', 1, 1, {}) + vim.api.nvim_buf_set_mark(0, ']', 1, 1, {}) + vim.highlight.on_yank({ timeout = math.huge, on_macro = true, event = { operator = 'y' } }) + end) local ns = api.nvim_create_namespace('hlyank') local win = api.nvim_get_current_win() eq({ win }, api.nvim__ns_get(ns).wins) @@ -150,19 +154,19 @@ describe('vim.highlight.on_yank', function() it('removes old highlight if new one is created before old one times out', function() command('vnew') - exec_lua([[ - vim.api.nvim_buf_set_mark(0,"[",1,1,{}) - vim.api.nvim_buf_set_mark(0,"]",1,1,{}) - vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}}) - ]]) + exec_lua(function() + vim.api.nvim_buf_set_mark(0, '[', 1, 1, {}) + vim.api.nvim_buf_set_mark(0, ']', 1, 1, {}) + vim.highlight.on_yank({ timeout = math.huge, on_macro = true, event = { operator = 'y' } }) + end) local ns = api.nvim_create_namespace('hlyank') eq(api.nvim_get_current_win(), api.nvim__ns_get(ns).wins[1]) command('wincmd w') - exec_lua([[ - vim.api.nvim_buf_set_mark(0,"[",1,1,{}) - vim.api.nvim_buf_set_mark(0,"]",1,1,{}) - vim.highlight.on_yank({timeout = math.huge, on_macro = true, event = {operator = "y"}}) - ]]) + exec_lua(function() + vim.api.nvim_buf_set_mark(0, '[', 1, 1, {}) + vim.api.nvim_buf_set_mark(0, ']', 1, 1, {}) + vim.highlight.on_yank({ timeout = math.huge, on_macro = true, event = { operator = 'y' } }) + end) local win = api.nvim_get_current_win() eq({ win }, api.nvim__ns_get(ns).wins) command('wincmd w') diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua index 8fadba6ee8..3a1263f6a3 100644 --- a/test/functional/lua/inspector_spec.lua +++ b/test/functional/lua/inspector_spec.lua @@ -12,22 +12,21 @@ describe('vim.inspect_pos', function() end) it('it returns items', function() - local ret = exec_lua([[ + local buf, items, other_buf_syntax = exec_lua(function() local buf = vim.api.nvim_create_buf(true, false) local buf1 = vim.api.nvim_create_buf(true, false) - local ns1 = vim.api.nvim_create_namespace("ns1") - local ns2 = vim.api.nvim_create_namespace("") + local ns1 = vim.api.nvim_create_namespace('ns1') + local ns2 = vim.api.nvim_create_namespace('') vim.api.nvim_set_current_buf(buf) - vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) - vim.api.nvim_buf_set_lines(buf1, 0, -1, false, {"--commentline"}) + vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' }) + vim.api.nvim_buf_set_lines(buf1, 0, -1, false, { '--commentline' }) vim.bo[buf].filetype = 'lua' vim.bo[buf1].filetype = 'lua' - vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" }) - vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" }) - vim.cmd("syntax on") - return {buf, vim.inspect_pos(0, 0, 10), vim.inspect_pos(buf1, 0, 10).syntax } - ]]) - local buf, items, other_buf_syntax = unpack(ret) + vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = 'Normal' }) + vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = 'Normal' }) + vim.cmd('syntax on') + return buf, vim.inspect_pos(0, 0, 10), vim.inspect_pos(buf1, 0, 10).syntax + end) eq('', eval('v:errmsg')) eq({ @@ -95,14 +94,14 @@ describe('vim.show_pos', function() end) it('it does not error', function() - exec_lua([[ + exec_lua(function() local buf = vim.api.nvim_create_buf(true, false) vim.api.nvim_set_current_buf(buf) - vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) + vim.api.nvim_buf_set_lines(0, 0, -1, false, { 'local a = 123' }) vim.bo[buf].filetype = 'lua' - vim.cmd("syntax on") - return {buf, vim.show_pos(0, 0, 10)} - ]]) + vim.cmd('syntax on') + return { buf, vim.show_pos(0, 0, 10) } + end) eq('', eval('v:errmsg')) end) end) diff --git a/test/functional/lua/loader_spec.lua b/test/functional/lua/loader_spec.lua index 06403e856c..8508f2aa14 100644 --- a/test/functional/lua/loader_spec.lua +++ b/test/functional/lua/loader_spec.lua @@ -12,14 +12,14 @@ describe('vim.loader', function() it('can work in compatibility with --luamod-dev #27413', function() clear({ args = { '--luamod-dev' } }) - exec_lua [[ + exec_lua(function() vim.loader.enable() - require("vim.fs") + require('vim.fs') -- try to load other vim submodules as well (Nvim Lua stdlib) for key, _ in pairs(vim._submodules) do - local modname = 'vim.' .. key -- e.g. "vim.fs" + local modname = 'vim.' .. key -- e.g. "vim.fs" local lhs = vim[key] local rhs = require(modname) @@ -28,28 +28,25 @@ describe('vim.loader', function() ('%s != require("%s"), %s != %s'):format(modname, modname, tostring(lhs), tostring(rhs)) ) end - ]] + end) end) it('handles changing files (#23027)', function() - exec_lua [[ + exec_lua(function() vim.loader.enable() - ]] + end) local tmp = t.tmpname() command('edit ' .. tmp) eq( 1, - exec_lua( - [[ - vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=1'}) - vim.cmd.write() - loadfile(...)() - return _G.TEST - ]], - tmp - ) + exec_lua(function() + vim.api.nvim_buf_set_lines(0, 0, -1, true, { '_G.TEST=1' }) + vim.cmd.write() + loadfile(tmp)() + return _G.TEST + end) ) -- fs latency @@ -57,15 +54,12 @@ describe('vim.loader', function() eq( 2, - exec_lua( - [[ - vim.api.nvim_buf_set_lines(0, 0, -1, true, {'_G.TEST=2'}) - vim.cmd.write() - loadfile(...)() - return _G.TEST - ]], - tmp - ) + exec_lua(function() + vim.api.nvim_buf_set_lines(0, 0, -1, true, { '_G.TEST=2' }) + vim.cmd.write() + loadfile(tmp)() + return _G.TEST + end) ) end) diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 566a171a84..de8200a5f1 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -25,30 +25,34 @@ describe('vim.uv', function() it('timer', function() exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {}) - local code = [[ + local code = function() local touch = 0 local function wait(ms) local this = coroutine.running() assert(this) - local timer = vim.uv.new_timer() - timer:start(ms, 0, vim.schedule_wrap(function () - timer:close() - touch = touch + 1 - coroutine.resume(this) - touch = touch + 1 - assert(touch==3) - vim.api.nvim_set_var("coroutine_cnt_1", touch) - end)) + local timer = assert(vim.uv.new_timer()) + timer:start( + ms, + 0, + vim.schedule_wrap(function() + timer:close() + touch = touch + 1 + coroutine.resume(this) + touch = touch + 1 + assert(touch == 3) + vim.api.nvim_set_var('coroutine_cnt_1', touch) + end) + ) coroutine.yield() touch = touch + 1 return touch end coroutine.wrap(function() local touched = wait(10) - assert(touched==touch) - vim.api.nvim_set_var("coroutine_cnt", touched) + assert(touched == touch) + vim.api.nvim_set_var('coroutine_cnt', touched) end)() - ]] + end eq(0, api.nvim_get_var('coroutine_cnt')) exec_lua(code) @@ -99,15 +103,19 @@ describe('vim.uv', function() -- callbacks can be scheduled to be executed in the main event loop -- where the entire API is available - exec_lua([[ - local timer = vim.uv.new_timer() - timer:start(20, 0, vim.schedule_wrap(function () - _G.is_fast = vim.in_fast_event() - timer:close() - vim.api.nvim_set_var("valid", true) - vim.api.nvim_command("echomsg 'howdy'") - end)) - ]]) + exec_lua(function() + local timer = assert(vim.uv.new_timer()) + timer:start( + 20, + 0, + vim.schedule_wrap(function() + _G.is_fast = vim.in_fast_event() + timer:close() + vim.api.nvim_set_var('valid', true) + vim.api.nvim_command("echomsg 'howdy'") + end) + ) + end) screen:expect([[ ^ | @@ -118,15 +126,15 @@ describe('vim.uv', function() eq(false, exec_lua('return _G.is_fast')) -- fast (not deferred) API functions are allowed to be called directly - exec_lua([[ - local timer = vim.uv.new_timer() - timer:start(20, 0, function () + exec_lua(function() + local timer = assert(vim.uv.new_timer()) + timer:start(20, 0, function() timer:close() -- input is queued for processing after the callback returns - vim.api.nvim_input("isneaky") + vim.api.nvim_input('isneaky') _G.mode = vim.api.nvim_get_mode() end) - ]]) + end) screen:expect([[ sneaky^ | {1:~ }|*8 @@ -134,15 +142,15 @@ describe('vim.uv', function() ]]) eq({ blocking = false, mode = 'n' }, exec_lua('return _G.mode')) - exec_lua([[ - local timer = vim.uv.new_timer() - timer:start(20, 0, function () + exec_lua(function() + local timer = assert(vim.uv.new_timer()) + timer:start(20, 0, function() _G.is_fast = vim.in_fast_event() timer:close() - _G.value = vim.fn.has("nvim-0.5") - _G.unvalue = vim.fn.has("python3") + _G.value = vim.fn.has('nvim-0.5') + _G.unvalue = vim.fn.has('python3') end) - ]]) + end) screen:expect({ any = [[{3:Vim:E5560: Vimscript function must not be called i}]] }) feed('<cr>') diff --git a/test/functional/lua/mpack_spec.lua b/test/functional/lua/mpack_spec.lua index efd69d4607..ebede26936 100644 --- a/test/functional/lua/mpack_spec.lua +++ b/test/functional/lua/mpack_spec.lua @@ -11,20 +11,20 @@ describe('lua vim.mpack', function() it('encodes vim.NIL', function() eq( { true, true, true, true }, - exec_lua [[ - local var = vim.mpack.decode(vim.mpack.encode({33, vim.NIL, 77})) - return {var[1]==33, var[2]==vim.NIL, var[3]==77, var[4]==nil} - ]] + exec_lua(function() + local var = vim.mpack.decode(vim.mpack.encode({ 33, vim.NIL, 77 })) + return { var[1] == 33, var[2] == vim.NIL, var[3] == 77, var[4] == nil } + end) ) end) it('encodes vim.empty_dict()', function() eq( { { {}, 'foo', {} }, true, false }, - exec_lua [[ - local var = vim.mpack.decode(vim.mpack.encode({{}, "foo", vim.empty_dict()})) - return {var, vim.islist(var[1]), vim.islist(var[3])} - ]] + exec_lua(function() + local var = vim.mpack.decode(vim.mpack.encode({ {}, 'foo', vim.empty_dict() })) + return { var, vim.islist(var[1]), vim.islist(var[3]) } + end) ) end) end) diff --git a/test/functional/lua/overrides_spec.lua b/test/functional/lua/overrides_spec.lua index 849978f080..33a2813200 100644 --- a/test/functional/lua/overrides_spec.lua +++ b/test/functional/lua/overrides_spec.lua @@ -134,14 +134,12 @@ describe('print', function() eq('abc def', exec_capture('lua print("abc", "", "def")')) end) it('defers printing in luv event handlers', function() - exec_lua( - [[ - local cmd = ... + exec_lua(function(cmd) function test() local timer = vim.uv.new_timer() local done = false timer:start(10, 0, function() - print("very fast") + print('very fast') timer:close() done = true end) @@ -149,14 +147,12 @@ describe('print', function() -- loop until we know for sure the callback has been executed while not done do os.execute(cmd) - vim.uv.run("nowait") -- fake os_breakcheck() + vim.uv.run('nowait') -- fake os_breakcheck() end - print("very slow") - vim.api.nvim_command("sleep 1m") -- force deferred event processing + print('very slow') + vim.api.nvim_command('sleep 1m') -- force deferred event processing end - ]], - (is_os('win') and 'timeout 1') or 'sleep 0.1' - ) + end, (is_os('win') and 'timeout 1') or 'sleep 0.1') eq('very slow\nvery fast', exec_capture('lua test()')) end) diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua index e72a009d2e..482bfcf1a9 100644 --- a/test/functional/lua/system_spec.lua +++ b/test/functional/lua/system_spec.lua @@ -6,10 +6,8 @@ local exec_lua = n.exec_lua local eq = t.eq local function system_sync(cmd, opts) - return exec_lua( - [[ - local cmd, opts = ... - local obj = vim.system(...) + return exec_lua(function() + local obj = vim.system(cmd, opts) if opts.timeout then -- Minor delay before calling wait() so the timeout uv timer can have a headstart over the @@ -24,16 +22,11 @@ local function system_sync(cmd, opts) assert(not proc, 'process still exists') return res - ]], - cmd, - opts - ) + end) end local function system_async(cmd, opts) - return exec_lua( - [[ - local cmd, opts = ... + return exec_lua(function() _G.done = false local obj = vim.system(cmd, opts, function(obj) _G.done = true @@ -51,10 +44,7 @@ local function system_async(cmd, opts) assert(not proc, 'process still exists') return _G.ret - ]], - cmd, - opts - ) + end) end describe('vim.system', function() @@ -84,7 +74,7 @@ describe('vim.system', function() end it('kill processes', function() - exec_lua([[ + exec_lua(function() local signal local cmd = vim.system({ 'cat', '-' }, { stdin = true }, function(r) signal = r.signal @@ -104,19 +94,21 @@ describe('vim.system', function() assert(not proc, 'process still exists') assert(signal == 2) - ]]) + end) end) it('SystemObj:wait() does not process non-fast events #27292', function() eq( false, - exec_lua([[ + exec_lua(function() _G.processed = false local cmd = vim.system({ 'sleep', '1' }) - vim.schedule(function() _G.processed = true end) + vim.schedule(function() + _G.processed = true + end) cmd:wait() return _G.processed - ]]) + end) ) eq(true, exec_lua([[return _G.processed]])) end) |