diff options
Diffstat (limited to 'test/functional/ex_cmds')
39 files changed, 1457 insertions, 1400 deletions
diff --git a/test/functional/ex_cmds/append_spec.lua b/test/functional/ex_cmds/append_spec.lua index 4134eed87e..5eb8d49c74 100644 --- a/test/functional/ex_cmds/append_spec.lua +++ b/test/functional/ex_cmds/append_spec.lua @@ -5,21 +5,20 @@ local dedent = helpers.dedent local exec = helpers.exec local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command -local curbufmeths = helpers.curbufmeths -local meths = helpers.meths +local api = helpers.api local Screen = require('test.functional.ui.screen') local cmdtest = function(cmd, prep, ret1) describe(':' .. cmd, function() before_each(function() clear() - curbufmeths.set_lines(0, 1, true, { 'foo', 'bar', 'baz' }) + api.nvim_buf_set_lines(0, 0, 1, true, { 'foo', 'bar', 'baz' }) end) local buffer_contents = function() - return curbufmeths.get_lines(0, -1, false) + return api.nvim_buf_get_lines(0, 0, -1, false) end it(cmd .. 's' .. prep .. ' the current line by default', function() @@ -29,8 +28,7 @@ local cmdtest = function(cmd, prep, ret1) -- Used to crash because this invokes history processing which uses -- hist_char2type which after fdb68e35e4c729c7ed097d8ade1da29e5b3f4b31 -- crashed. - it(cmd .. 's' .. prep .. ' the current line by default when feeding', - function() + it(cmd .. 's' .. prep .. ' the current line by default when feeding', function() feed(':' .. cmd .. '\nabc\ndef\n.\n') eq(ret1, buffer_contents()) end) @@ -40,15 +38,15 @@ local cmdtest = function(cmd, prep, ret1) feed(':' .. hisline .. '<CR>') feed(':' .. cmd .. '<CR>abc<CR>def<C-f>') eq({ 'def' }, buffer_contents()) - eq(hisline, funcs.histget(':', -2)) - eq(cmd, funcs.histget(':')) + eq(hisline, fn.histget(':', -2)) + eq(cmd, fn.histget(':')) -- Test that command-line window was launched - eq('nofile', meths.get_option_value('buftype', {})) - eq('n', funcs.mode(1)) + eq('nofile', api.nvim_get_option_value('buftype', {})) + eq('n', fn.mode(1)) feed('<CR>') - eq('c', funcs.mode(1)) + eq('c', fn.mode(1)) feed('.<CR>') - eq('n', funcs.mode(1)) + eq('n', fn.mode(1)) eq(ret1, buffer_contents()) end) end) @@ -63,8 +61,8 @@ describe('the first line is redrawn correctly after inserting text in an empty b clear() screen = Screen.new(20, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue}, - [2] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue }, + [2] = { bold = true, reverse = true }, }) screen:attach() end) @@ -78,11 +76,7 @@ describe('the first line is redrawn correctly after inserting text in an empty b screen:expect([[ aaaaa | ^bbbbb | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) end) @@ -96,11 +90,7 @@ describe('the first line is redrawn correctly after inserting text in an empty b screen:expect([[ aaaaa | ^bbbbb | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) end) diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua index 4dea50b53e..810b001ec0 100644 --- a/test/functional/ex_cmds/arg_spec.lua +++ b/test/functional/ex_cmds/arg_spec.lua @@ -1,30 +1,30 @@ -local helpers = require("test.functional.helpers")(after_each) -local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs +local helpers = require('test.functional.helpers')(after_each) +local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok local clear = helpers.clear -describe(":argument", function() +describe(':argument', function() before_each(function() clear() end) - it("does not restart :terminal buffer", function() - command("terminal") - helpers.feed([[<C-\><C-N>]]) - command("argadd") - helpers.feed([[<C-\><C-N>]]) - local bufname_before = funcs.bufname("%") - local bufnr_before = funcs.bufnr("%") - helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + it('does not restart :terminal buffer', function() + command('terminal') + helpers.feed([[<C-\><C-N>]]) + command('argadd') + helpers.feed([[<C-\><C-N>]]) + local bufname_before = fn.bufname('%') + local bufnr_before = fn.bufnr('%') + helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity - command("argument 1") - helpers.feed([[<C-\><C-N>]]) + command('argument 1') + helpers.feed([[<C-\><C-N>]]) - local bufname_after = funcs.bufname("%") - local bufnr_after = funcs.bufnr("%") - eq("["..bufname_before.."]", helpers.eval('trim(execute("args"))')) - ok(funcs.line('$') > 1) - eq(bufname_before, bufname_after) - eq(bufnr_before, bufnr_after) + local bufname_after = fn.bufname('%') + local bufnr_after = fn.bufnr('%') + eq('[' .. bufname_before .. ']', helpers.eval('trim(execute("args"))')) + ok(fn.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) end) end) diff --git a/test/functional/ex_cmds/cd_spec.lua b/test/functional/ex_cmds/cd_spec.lua index b6a3713158..1815c672dc 100644 --- a/test/functional/ex_cmds/cd_spec.lua +++ b/test/functional/ex_cmds/cd_spec.lua @@ -1,6 +1,5 @@ -- Specs for :cd, :tcd, :lcd and getcwd() -local luv = require('luv') local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq @@ -21,18 +20,30 @@ local directories = { } -- Shorthand writing to get the current working directory -local cwd = function(...) return call('getcwd', ...) end -- effective working dir -local wcwd = function() return cwd(0) end -- window dir -local tcwd = function() return cwd(-1, 0) end -- tab dir +local cwd = function(...) + return call('getcwd', ...) +end -- effective working dir +local wcwd = function() + return cwd(0) +end -- window dir +local tcwd = function() + return cwd(-1, 0) +end -- tab dir -- Same, except these tell us if there is a working directory at all -local lwd = function(...) return call('haslocaldir', ...) end -- effective working dir -local wlwd = function() return lwd(0) end -- window dir -local tlwd = function() return lwd(-1, 0) end -- tab dir +local lwd = function(...) + return call('haslocaldir', ...) +end -- effective working dir +local wlwd = function() + return lwd(0) +end -- window dir +local tlwd = function() + return lwd(-1, 0) +end -- tab dir --local glwd = function() return eval('haslocaldir(-1, -1)') end -- global dir -- Test both the `cd` and `chdir` variants -for _, cmd in ipairs {'cd', 'chdir'} do +for _, cmd in ipairs { 'cd', 'chdir' } do describe(':' .. cmd, function() before_each(function() clear() @@ -44,7 +55,7 @@ for _, cmd in ipairs {'cd', 'chdir'} do after_each(function() for _, d in pairs(directories) do - luv.fs_rmdir(d) + vim.uv.fs_rmdir(d) end end) @@ -168,23 +179,23 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Create a new tab first and verify that is has the same working dir command('tabnew') eq(globalDir, cwd()) - eq(globalDir, tcwd()) -- has no tab-local directory + eq(globalDir, tcwd()) -- has no tab-local directory eq(0, tlwd()) - eq(globalDir, wcwd()) -- has no window-local directory + eq(globalDir, wcwd()) -- has no window-local directory eq(0, wlwd()) -- Change tab-local working directory and verify it is different command('silent t' .. cmd .. ' ' .. directories.tab) eq(globalDir .. pathsep .. directories.tab, cwd()) - eq(cwd(), tcwd()) -- working directory matches tab directory + eq(cwd(), tcwd()) -- working directory matches tab directory eq(1, tlwd()) - eq(cwd(), wcwd()) -- still no window-directory + eq(cwd(), wcwd()) -- still no window-directory eq(0, wlwd()) -- Create a new window in this tab to test `:lcd` command('new') - eq(1, tlwd()) -- Still tab-local working directory - eq(0, wlwd()) -- Still no window-local working directory + eq(1, tlwd()) -- Still tab-local working directory + eq(0, wlwd()) -- Still no window-local working directory eq(globalDir .. pathsep .. directories.tab, cwd()) command('silent l' .. cmd .. ' ../' .. directories.window) eq(globalDir .. pathsep .. directories.window, cwd()) @@ -193,13 +204,13 @@ for _, cmd in ipairs {'cd', 'chdir'} do -- Verify the first window still has the tab local directory command('wincmd w') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- No window-local directory + eq(0, wlwd()) -- No window-local directory -- Change back to initial tab and verify working directory has stayed command('tabnext') - eq(globalDir, cwd() ) + eq(globalDir, cwd()) eq(0, tlwd()) eq(0, wlwd()) @@ -207,31 +218,31 @@ for _, cmd in ipairs {'cd', 'chdir'} do command('silent ' .. cmd .. ' ' .. directories.global) eq(globalDir .. pathsep .. directories.global, cwd()) command('tabnext') - eq(globalDir .. pathsep .. directories.tab, cwd()) + eq(globalDir .. pathsep .. directories.tab, cwd()) eq(globalDir .. pathsep .. directories.tab, tcwd()) - eq(0, wlwd()) -- Still no window-local directory in this window + eq(0, wlwd()) -- Still no window-local directory in this window -- Unless the global change happened in a tab with local directory command('silent ' .. cmd .. ' ..') - eq(globalDir, cwd() ) - eq(0 , tlwd()) - eq(0 , wlwd()) + eq(globalDir, cwd()) + eq(0, tlwd()) + eq(0, wlwd()) -- Which also affects the first tab command('tabnext') eq(globalDir, cwd()) -- But not in a window with its own local directory command('tabnext | wincmd w') - eq(globalDir .. pathsep .. directories.window, cwd() ) - eq(0 , tlwd()) + eq(globalDir .. pathsep .. directories.window, cwd()) + eq(0, tlwd()) eq(globalDir .. pathsep .. directories.window, wcwd()) end) end) end -- Test legal parameters for 'getcwd' and 'haslocaldir' -for _, cmd in ipairs {'getcwd', 'haslocaldir'} do - describe(cmd..'()', function() +for _, cmd in ipairs { 'getcwd', 'haslocaldir' } do + describe(cmd .. '()', function() before_each(function() clear() end) @@ -271,7 +282,7 @@ for _, cmd in ipairs {'getcwd', 'haslocaldir'} do end) end -describe("getcwd()", function () +describe('getcwd()', function() before_each(function() clear() mkdir(directories.global) @@ -281,11 +292,11 @@ describe("getcwd()", function () helpers.rmdir(directories.global) end) - it("returns empty string if working directory does not exist", function() + it('returns empty string if working directory does not exist', function() skip(is_os('win')) - command("cd "..directories.global) - command("call delete('../"..directories.global.."', 'd')") - eq("", helpers.eval("getcwd()")) + command('cd ' .. directories.global) + command("call delete('../" .. directories.global .. "', 'd')") + eq('', helpers.eval('getcwd()')) end) it("works with 'autochdir' after local directory was set (#9892)", function() diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 2a2628350d..cb7d7340e2 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -4,7 +4,7 @@ local feed = helpers.feed local eq = helpers.eq local expect = helpers.expect local eval = helpers.eval -local funcs = helpers.funcs +local fn = helpers.fn local insert = helpers.insert local write_file = helpers.write_file local exc_exec = helpers.exc_exec @@ -16,24 +16,24 @@ describe('mappings with <Cmd>', function() local tmpfile = 'X_ex_cmds_cmd_map' local function cmdmap(lhs, rhs) - command('noremap '..lhs..' <Cmd>'..rhs..'<cr>') - command('noremap! '..lhs..' <Cmd>'..rhs..'<cr>') + command('noremap ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>') + command('noremap! ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>') end before_each(function() clear() screen = Screen.new(65, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [4] = {bold = true}, - [5] = {background = Screen.colors.LightGrey}, - [6] = {foreground = Screen.colors.Blue1}, - [7] = {bold = true, reverse = true}, - [8] = {background = Screen.colors.WebGray}, - [9] = {background = Screen.colors.LightMagenta}, - [10] = {foreground = Screen.colors.Red}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true }, + [5] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey }, + [6] = { foreground = Screen.colors.Blue1 }, + [7] = { bold = true, reverse = true }, + [8] = { background = Screen.colors.WebGray }, + [9] = { background = Screen.colors.LightMagenta }, + [10] = { foreground = Screen.colors.Red }, }) screen:attach() @@ -57,7 +57,7 @@ describe('mappings with <Cmd>', function() feed('gg') cmdmap('<F8>', 'startinsert') cmdmap('<F9>', 'stopinsert') - command("abbr foo <Cmd>let g:y = 17<cr>bar") + command('abbr foo <Cmd>let g:y = 17<cr>bar') end) after_each(function() @@ -69,11 +69,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ ^some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {6:<F3>} {6:*} {6:<Cmd>}let m = mode(1){6:<CR>} | ]]) end) @@ -85,11 +81,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ ^some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} | ]]) @@ -98,11 +90,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ ^some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {2:E1255: <Cmd> mapping must end with <CR>} | ]]) eq(0, eval('x')) @@ -114,11 +102,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | ^of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) @@ -127,11 +111,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of ^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) end) @@ -141,7 +121,7 @@ describe('mappings with <Cmd>', function() feed('<F3>') eq('foo…bar', eval('g:str')) local str = eval([["foo\<D-…>bar"]]) - command([[noremap <F3> <Cmd>let g:str = ']]..str..[['<CR>]]) + command([[noremap <F3> <Cmd>let g:str = ']] .. str .. [['<CR>]]) feed('<F3>') eq(str, eval('g:str')) command([[noremap <F3> <Cmd>let g:str = 'foo<D-…>bar'<CR>]]) @@ -180,7 +160,7 @@ describe('mappings with <Cmd>', function() eq('n', eval('mode(1)')) -- operator-pending mode - feed("d<F3>") + feed('d<F3>') eq('no', eval('m')) -- did leave operator-pending mode eq('n', eval('mode(1)')) @@ -191,21 +171,21 @@ describe('mappings with <Cmd>', function() eq('i', eval('mode(1)')) -- replace mode - feed("<Ins><F3>") + feed('<Ins><F3>') eq('R', eval('m')) eq('R', eval('mode(1)')) feed('<esc>') eq('n', eval('mode(1)')) -- virtual replace mode - feed("gR<F3>") + feed('gR<F3>') eq('Rv', eval('m')) eq('Rv', eval('mode(1)')) feed('<esc>') eq('n', eval('mode(1)')) -- langmap works, but is not distinguished in mode(1) - feed(":set iminsert=1<cr>i<F3>") + feed(':set iminsert=1<cr>i<F3>') eq('i', eval('m')) eq('i', eval('mode(1)')) feed('<esc>') @@ -232,26 +212,22 @@ describe('mappings with <Cmd>', function() -- check v:count and v:register works feed('<F2>') - eq({'n', 0, '"'}, eval('s')) + eq({ 'n', 0, '"' }, eval('s')) feed('7<F2>') - eq({'n', 7, '"'}, eval('s')) + eq({ 'n', 7, '"' }, eval('s')) feed('"e<F2>') - eq({'n', 0, 'e'}, eval('s')) + eq({ 'n', 0, 'e' }, eval('s')) feed('5"k<F2>') - eq({'n', 5, 'k'}, eval('s')) + eq({ 'n', 5, 'k' }, eval('s')) feed('"+2<F2>') - eq({'n', 2, '+'}, eval('s')) + eq({ 'n', 2, '+' }, eval('s')) -- text object enters visual mode feed('<F7>') screen:expect([[ so{5:me short lines} | {5:of }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- VISUAL --} | ]]) feed('<esc>') @@ -269,15 +245,11 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of alpha^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) -- feedkeys were not executed immediately - eq({'n', 'of test text'}, eval('[m,a]')) + eq({ 'n', 'of test text' }, eval('[m,a]')) eq('i', eval('mode(1)')) feed('<esc>') @@ -285,15 +257,11 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of alphabet^atest text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) -- feedkeys(..., 'x') was executed immediately, but insert mode gets aborted - eq({'n', 'of alphabetatest text'}, eval('[m,b]')) + eq({ 'n', 'of alphabetatest text' }, eval('[m,b]')) eq('n', eval('mode(1)')) end) @@ -302,45 +270,39 @@ describe('mappings with <Cmd>', function() command('noremap ,f <Cmd>nosuchcommand<cr>') command('noremap ,e <Cmd>throw "very error"\\| call append(1, "yy")<cr>') command('noremap ,m <Cmd>echoerr "The message."\\| call append(1, "zz")<cr>') - command('noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>') + command( + 'noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>' + ) - feed(":normal ,x<cr>") + feed(':normal ,x<cr>') screen:expect([[ ^some short lines | aa | xx | of test text | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 :normal ,x | ]]) - eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec("normal ,f")) - eq('very error', exc_exec("normal ,e")) - eq('Vim(echoerr):The message.', exc_exec("normal ,m")) + eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec('normal ,f')) + eq('very error', exc_exec('normal ,e')) + eq('Vim(echoerr):The message.', exc_exec('normal ,m')) feed('w') screen:expect([[ some ^short lines | aa | xx | of test text | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 :normal ,x | ]]) command(':%d') - eq('Vim(echoerr):Err', exc_exec("normal ,w")) + eq('Vim(echoerr):Err', exc_exec('normal ,w')) screen:expect([[ ^ | 0 | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 --No lines in buffer-- | ]]) @@ -364,27 +326,22 @@ describe('mappings with <Cmd>', function() screen:expect([[ {5:some short }^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- can invoke operator, ending visual mode feed('<F5>') - eq('n', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('a',1,1)) + eq('n', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('a', 1, 1)) -- error doesn't interrupt visual mode feed('ggvw<F6>') screen:expect([[ {5:some }short lines | of test text | - {1:~ }| - {1:~ }| + {1:~ }|*2 {7: }| {2:Error detected while processing :} | {2:E605: Exception not caught: very error} | @@ -396,37 +353,25 @@ describe('mappings with <Cmd>', function() screen:expect([[ {5:some }^short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) feed('<F7>') screen:expect([[ so{5:me short lines} | {5:of }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- VISUAL --} | ]]) - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- startinsert gives "-- (insert) VISUAL --" mode feed('<F8>') screen:expect([[ so{5:me short lines} | {5:of }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- (insert) VISUAL --} | ]]) eq('v', eval('mode(1)')) @@ -442,32 +387,27 @@ describe('mappings with <Cmd>', function() screen:expect([[ {5:some short }^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- SELECT --} | ]]) - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) -- visual mapping in select mode restart select mode after operator feed('<F5>') - eq('s', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('a',1,1)) + eq('s', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('a', 1, 1)) -- select mode mapping works, and does not restart select mode feed('<F2>') - eq('n', funcs.mode(1)) - eq({'some short l'}, funcs.getreg('b',1,1)) + eq('n', fn.mode(1)) + eq({ 'some short l' }, fn.getreg('b', 1, 1)) -- error doesn't interrupt temporary visual mode feed('<esc>ggvw<c-g><F6>') screen:expect([[ {5:some }short lines | of test text | - {1:~ }| - {1:~ }| + {1:~ }|*2 {7: }| {2:Error detected while processing :} | {2:E605: Exception not caught: very error} | @@ -479,23 +419,18 @@ describe('mappings with <Cmd>', function() screen:expect([[ {5:some }^short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- VISUAL --} | ]]) -- quirk: restoration of select mode is not performed - eq('v', funcs.mode(1)) + eq('v', fn.mode(1)) -- error doesn't interrupt select mode feed('<esc>ggvw<c-g><F1>') screen:expect([[ {5:some }short lines | of test text | - {1:~ }| - {1:~ }| + {1:~ }|*2 {7: }| {2:Error detected while processing :} | {2:E605: Exception not caught: very error} | @@ -507,39 +442,27 @@ describe('mappings with <Cmd>', function() screen:expect([[ {5:some }^short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- SELECT --} | ]]) -- quirk: restoration of select mode is not performed - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) feed('<F7>') screen:expect([[ so{5:me short lines} | {5:of }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- SELECT --} | ]]) - eq('s', funcs.mode(1)) + eq('s', fn.mode(1)) -- startinsert gives "-- SELECT (insert) --" mode feed('<F8>') screen:expect([[ so{5:me short lines} | {5:of }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- (insert) SELECT --} | ]]) eq('s', eval('mode(1)')) @@ -547,17 +470,16 @@ describe('mappings with <Cmd>', function() eq('i', eval('mode(1)')) end) - it('works in operator-pending mode', function() feed('d<F4>') expect([[ lines of test text]]) - eq({'some short '}, funcs.getreg('"',1,1)) + eq({ 'some short ' }, fn.getreg('"', 1, 1)) feed('.') expect([[ test text]]) - eq({'lines', 'of '}, funcs.getreg('"',1,1)) + eq({ 'lines', 'of ' }, fn.getreg('"', 1, 1)) feed('uu') expect([[ some short lines @@ -568,8 +490,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of test text | - {1:~ }| - {1:~ }| + {1:~ }|*2 {7: }| {2:Error detected while processing :} | {2:E605: Exception not caught: very error} | @@ -584,7 +505,7 @@ describe('mappings with <Cmd>', function() feed('"bd<F7>') expect([[ soest text]]) - eq(funcs.getreg('b',1,1), {'me short lines', 'of t'}) + eq(fn.getreg('b', 1, 1), { 'me short lines', 'of t' }) -- startinsert aborts operator feed('d<F8>') @@ -594,17 +515,12 @@ describe('mappings with <Cmd>', function() end) it('works in insert mode', function() - -- works the same as <c-o>w<c-o>w feed('iindeed <F4>little ') screen:expect([[ indeed some short little ^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) @@ -612,26 +528,20 @@ describe('mappings with <Cmd>', function() screen:expect([[ indeed some short little lines | of test text | - {1:~ }| - {1:~ }| + {1:~ }|*2 {7: }| {2:Error detected while processing :} | {2:E605: Exception not caught: very error} | {3:Press ENTER or type command to continue}^ | ]]) - feed('<cr>') eq('E605: Exception not caught: very error', eval('v:errmsg')) -- still in insert screen:expect([[ indeed some short little ^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) eq('i', eval('mode(1)')) @@ -643,11 +553,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ in{5:deed some short little lines} | {5:of stuff }^test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT VISUAL --} | ]]) expect([[ @@ -655,17 +561,13 @@ describe('mappings with <Cmd>', function() of stuff test text]]) feed('<F5>') - eq(funcs.getreg('a',1,1), {'deed some short little lines', 'of stuff t'}) + eq(fn.getreg('a', 1, 1), { 'deed some short little lines', 'of stuff t' }) -- still in insert screen:expect([[ in^deed some short little lines | of stuff test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) eq('i', eval('mode(1)')) @@ -675,11 +577,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ in bar ^deed some short little lines | of stuff test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) eq(17, eval('g:y')) @@ -700,9 +598,7 @@ describe('mappings with <Cmd>', function() some^ | {8:some } | {9:short }{1: }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 {4:-- Keyword Local completion (^N^P) }{3:match 1 of 2} | ]]) @@ -717,9 +613,7 @@ describe('mappings with <Cmd>', function() some^ | {9:some } | {9:short }{1: }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 {4:-- Keyword Local completion (^N^P) }{10:Back at original} | ]]) end) @@ -734,11 +628,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ ^some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {2:E492: Not an editor command: text} | ]]) @@ -773,11 +663,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ ^some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 | ]]) eq('n', eval('mode(1)')) @@ -786,11 +672,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 :let g:x = 3^ | ]]) feed('+2<cr>') @@ -798,11 +680,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short ^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 :let g:x = 3+2 | ]]) eq(5, eval('g:x')) @@ -811,11 +689,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 :let g:y = 7^ | ]]) eq('c', eval('mode(1)')) @@ -824,16 +698,11 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short ^lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {4:-- INSERT --} | ]]) eq('i', eval('mode(1)')) eq(9, eval('g:y')) - end) it("doesn't crash when invoking cmdline mode recursively #8859", function() @@ -842,11 +711,7 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 :bar^ | ]]) @@ -854,27 +719,25 @@ describe('mappings with <Cmd>', function() screen:expect([[ some short lines | of test text | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 :barx^ | ]]) end) - it("works with <SID> mappings", function() + it('works with <SID> mappings', function() command('new!') - write_file(tmpfile, [[ + write_file( + tmpfile, + [[ map <f2> <Cmd>call <SID>do_it()<Cr> function! s:do_it() let g:x = 10 endfunction - ]]) - command('source '..tmpfile) + ]] + ) + command('source ' .. tmpfile) feed('<f2>') eq('', eval('v:errmsg')) eq(10, eval('g:x')) end) end) - diff --git a/test/functional/ex_cmds/debug_spec.lua b/test/functional/ex_cmds/debug_spec.lua index a4d381d3f1..85327c87e6 100644 --- a/test/functional/ex_cmds/debug_spec.lua +++ b/test/functional/ex_cmds/debug_spec.lua @@ -9,10 +9,10 @@ describe(':debug', function() clear() screen = Screen.new(30, 14) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) screen:attach() end) @@ -20,14 +20,7 @@ describe(':debug', function() feed(':echoerr bork<cr>') screen:expect([[ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 {2: }| {3:E121: Undefined variable: bork}| | @@ -38,11 +31,7 @@ describe(':debug', function() feed(':debug echo "aa"| echo "bb"<cr>') screen:expect([[ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*5 {2: }| {3:E121: Undefined variable: bork}| | @@ -56,8 +45,7 @@ describe(':debug', function() feed('step<cr>') screen:expect([[ | - {1:~ }| - {1:~ }| + {1:~ }|*2 {2: }| {3:E121: Undefined variable: bork}| | @@ -92,18 +80,7 @@ describe(':debug', function() feed('<cr>') screen:expect([[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*12 | ]]) end) diff --git a/test/functional/ex_cmds/dict_notifications_spec.lua b/test/functional/ex_cmds/dict_notifications_spec.lua index 6a0b40bd88..fc7714d16b 100644 --- a/test/functional/ex_cmds/dict_notifications_spec.lua +++ b/test/functional/ex_cmds/dict_notifications_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local assert_alive = helpers.assert_alive -local clear, nvim, source = helpers.clear, helpers.nvim, helpers.source +local clear, source = helpers.clear, helpers.source +local api = helpers.api local insert = helpers.insert local eq, next_msg = helpers.eq, helpers.next_msg local exc_exec = helpers.exc_exec @@ -8,14 +9,13 @@ local exec_lua = helpers.exec_lua local command = helpers.command local eval = helpers.eval - describe('Vimscript dictionary notifications', function() local channel before_each(function() clear() - channel = nvim('get_api_info')[1] - nvim('set_var', 'channel', channel) + channel = api.nvim_get_chan_info(0).id + api.nvim_set_var('channel', channel) end) -- the same set of tests are applied to top-level dictionaries(g:, b:, w: and @@ -29,9 +29,9 @@ describe('Vimscript dictionary notifications', function() key = 'watched' end if opval == '' then - command(('unlet %s[\'%s\']'):format(dict_expr, key)) + command(("unlet %s['%s']"):format(dict_expr, key)) else - command(('let %s[\'%s\'] %s'):format(dict_expr, key, opval)) + command(("let %s['%s'] %s"):format(dict_expr, key, opval)) end end @@ -40,9 +40,9 @@ describe('Vimscript dictionary notifications', function() key = 'watched' end if opval == '' then - exec_lua(('vim.api.nvim_del_var(\'%s\')'):format(key)) + exec_lua(("vim.api.nvim_del_var('%s')"):format(key)) else - exec_lua(('vim.api.nvim_set_var(\'%s\', %s)'):format(key, opval)) + exec_lua(("vim.api.nvim_set_var('%s', %s)"):format(key, opval)) end end @@ -60,15 +60,15 @@ describe('Vimscript dictionary notifications', function() local function verify_echo() -- helper to verify that no notifications are sent after certain change -- to a dict - nvim('command', "call rpcnotify(g:channel, 'echo')") - eq({'notification', 'echo', {}}, next_msg()) + command("call rpcnotify(g:channel, 'echo')") + eq({ 'notification', 'echo', {} }, next_msg()) end local function verify_value(vals, key) if not key then key = 'watched' end - eq({'notification', 'values', {key, vals}}, next_msg()) + eq({ 'notification', 'values', { key, vals } }, next_msg()) end describe(dict_expr .. ' watcher', function() @@ -81,20 +81,20 @@ describe('Vimscript dictionary notifications', function() before_each(function() source([[ function! g:Changed(dict, key, value) - if a:dict isnot ]]..dict_expr..[[ | + if a:dict isnot ]] .. dict_expr .. [[ | throw 'invalid dict' endif call rpcnotify(g:channel, 'values', a:key, a:value) endfunction - call dictwatcheradd(]]..dict_expr..[[, "watched", "g:Changed") - call dictwatcheradd(]]..dict_expr..[[, "watched2", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "watched", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "watched2", "g:Changed") ]]) end) after_each(function() source([[ - call dictwatcherdel(]]..dict_expr..[[, "watched", "g:Changed") - call dictwatcherdel(]]..dict_expr..[[, "watched2", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "watched", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "watched2", "g:Changed") ]]) update('= "test"') update('= "test2"', 'watched2') @@ -134,99 +134,99 @@ describe('Vimscript dictionary notifications', function() it('is triggered by remove()', function() update('= "test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + command('call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) if is_g then it('is triggered by remove() when updated with nvim_*_var', function() update_with_api('"test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + command('call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) it('is triggered by remove() when updated with vim.g', function() update_with_vim_g('= "test"') - verify_value({new = 'test'}) - nvim('command', 'call remove('..dict_expr..', "watched")') - verify_value({old = 'test'}) + verify_value({ new = 'test' }) + command('call remove(' .. dict_expr .. ', "watched")') + verify_value({ old = 'test' }) end) end it('is triggered by extend()', function() update('= "xtend"') - verify_value({new = 'xtend'}) - nvim('command', [[ - call extend(]]..dict_expr..[[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) + verify_value({ new = 'xtend' }) + command([[ + call extend(]] .. dict_expr .. [[, {'watched': 'xtend2', 'watched2': 5, 'watched3': 'a'}) ]]) - verify_value({old = 'xtend', new = 'xtend2'}) - verify_value({new = 5}, 'watched2') + verify_value({ old = 'xtend', new = 'xtend2' }) + verify_value({ new = 5 }, 'watched2') update('') - verify_value({old = 'xtend2'}) + verify_value({ old = 'xtend2' }) update('', 'watched2') - verify_value({old = 5}, 'watched2') + verify_value({ old = 5 }, 'watched2') update('', 'watched3') verify_echo() end) it('is triggered with key patterns', function() source([[ - call dictwatcheradd(]]..dict_expr..[[, "wat*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "wat*", "g:Changed") ]]) update('= 1') - verify_value({new = 1}) - verify_value({new = 1}) + verify_value({ new = 1 }) + verify_value({ new = 1 }) update('= 3', 'watched2') - verify_value({new = 3}, 'watched2') - verify_value({new = 3}, 'watched2') + verify_value({ new = 3 }, 'watched2') + verify_value({ new = 3 }, 'watched2') verify_echo() source([[ - call dictwatcherdel(]]..dict_expr..[[, "wat*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "wat*", "g:Changed") ]]) -- watch every key pattern source([[ - call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "*", "g:Changed") ]]) update('= 3', 'another_key') update('= 4', 'another_key') update('', 'another_key') update('= 2') - verify_value({new = 3}, 'another_key') - verify_value({old = 3, new = 4}, 'another_key') - verify_value({old = 4}, 'another_key') - verify_value({old = 1, new = 2}) - verify_value({old = 1, new = 2}) + verify_value({ new = 3 }, 'another_key') + verify_value({ old = 3, new = 4 }, 'another_key') + verify_value({ old = 4 }, 'another_key') + verify_value({ old = 1, new = 2 }) + verify_value({ old = 1, new = 2 }) verify_echo() source([[ - call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "*", "g:Changed") ]]) end) it('is triggered for empty keys', function() command([[ - call dictwatcheradd(]]..dict_expr..[[, "", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "", "g:Changed") ]]) update('= 1', '') - verify_value({new = 1}, '') + verify_value({ new = 1 }, '') update('= 2', '') - verify_value({old = 1, new = 2}, '') + verify_value({ old = 1, new = 2 }, '') command([[ - call dictwatcherdel(]]..dict_expr..[[, "", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "", "g:Changed") ]]) end) it('is triggered for empty keys when using catch-all *', function() command([[ - call dictwatcheradd(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcheradd(]] .. dict_expr .. [[, "*", "g:Changed") ]]) update('= 1', '') - verify_value({new = 1}, '') + verify_value({ new = 1 }, '') update('= 2', '') - verify_value({old = 1, new = 2}, '') + verify_value({ old = 1, new = 2 }, '') command([[ - call dictwatcherdel(]]..dict_expr..[[, "*", "g:Changed") + call dictwatcherdel(]] .. dict_expr .. [[, "*", "g:Changed") ]]) end) @@ -244,31 +244,31 @@ describe('Vimscript dictionary notifications', function() end test_updates({ - {'= 3', {new = 3}}, - {'= 6', {old = 3, new = 6}}, - {'+= 3', {old = 6, new = 9}}, - {'', {old = 9}} + { '= 3', { new = 3 } }, + { '= 6', { old = 3, new = 6 } }, + { '+= 3', { old = 6, new = 9 } }, + { '', { old = 9 } }, }) test_updates({ - {'= "str"', {new = 'str'}}, - {'= "str2"', {old = 'str', new = 'str2'}}, - {'.= "2str"', {old = 'str2', new = 'str22str'}}, - {'', {old = 'str22str'}} + { '= "str"', { new = 'str' } }, + { '= "str2"', { old = 'str', new = 'str2' } }, + { '.= "2str"', { old = 'str2', new = 'str22str' } }, + { '', { old = 'str22str' } }, }) test_updates({ - {'= [1, 2]', {new = {1, 2}}}, - {'= [1, 2, 3]', {old = {1, 2}, new = {1, 2, 3}}}, + { '= [1, 2]', { new = { 1, 2 } } }, + { '= [1, 2, 3]', { old = { 1, 2 }, new = { 1, 2, 3 } } }, -- the += will update the list in place, so old and new are the same - {'+= [4, 5]', {old = {1, 2, 3, 4, 5}, new = {1, 2, 3, 4, 5}}}, - {'', {old = {1, 2, 3, 4 ,5}}} + { '+= [4, 5]', { old = { 1, 2, 3, 4, 5 }, new = { 1, 2, 3, 4, 5 } } }, + { '', { old = { 1, 2, 3, 4, 5 } } }, }) test_updates({ - {'= {"k": "v"}', {new = {k = 'v'}}}, - {'= {"k1": 2}', {old = {k = 'v'}, new = {k1 = 2}}}, - {'', {old = {k1 = 2}}}, + { '= {"k": "v"}', { new = { k = 'v' } } }, + { '= {"k1": 2}', { old = { k = 'v' }, new = { k1 = 2 } } }, + { '', { old = { k1 = 2 } } }, }) end) end @@ -294,18 +294,18 @@ describe('Vimscript dictionary notifications', function() end) it('invokes all callbacks when the key is changed', function() - nvim('command', 'let g:key = "value"') - eq({'notification', '1', {'key', {new = 'value'}}}, next_msg()) - eq({'notification', '2', {'key', {new = 'value'}}}, next_msg()) + command('let g:key = "value"') + eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) + eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) end) it('only removes watchers that fully match dict, key and callback', function() - nvim('command', 'let g:key = "value"') - eq({'notification', '1', {'key', {new = 'value'}}}, next_msg()) - eq({'notification', '2', {'key', {new = 'value'}}}, next_msg()) - nvim('command', 'call dictwatcherdel(g:, "key", "g:Watcher1")') - nvim('command', 'let g:key = "v2"') - eq({'notification', '2', {'key', {old = 'value', new = 'v2'}}}, next_msg()) + command('let g:key = "value"') + eq({ 'notification', '1', { 'key', { new = 'value' } } }, next_msg()) + eq({ 'notification', '2', { 'key', { new = 'value' } } }, next_msg()) + command('call dictwatcherdel(g:, "key", "g:Watcher1")') + command('let g:key = "v2"') + eq({ 'notification', '2', { 'key', { old = 'value', new = 'v2' } } }, next_msg()) end) end) @@ -315,8 +315,10 @@ describe('Vimscript dictionary notifications', function() call rpcnotify(g:channel, '1', a:key, a:value) endfunction ]]) - eq('Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"', - exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")')) + eq( + 'Vim(call):E46: Cannot change read-only variable "dictwatcheradd() argument"', + exc_exec('call dictwatcheradd(v:_null_dict, "x", "g:Watcher1")') + ) end) describe('errors', function() @@ -333,13 +335,17 @@ describe('Vimscript dictionary notifications', function() -- WARNING: This suite depends on the above tests it('fails to remove if no watcher with matching callback is found', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(g:, "key", "g:Watcher1")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(g:, "key", "g:Watcher1")') + ) end) it('fails to remove if no watcher with matching key is found', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(g:, "invalid_key", "g:Watcher2")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(g:, "invalid_key", "g:Watcher2")') + ) end) it("does not fail to add/remove if the callback doesn't exist", function() @@ -348,8 +354,10 @@ describe('Vimscript dictionary notifications', function() end) it('fails to remove watcher from v:_null_dict', function() - eq("Vim(call):Couldn't find a watcher matching key and callback", - exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")')) + eq( + "Vim(call):Couldn't find a watcher matching key and callback", + exc_exec('call dictwatcherdel(v:_null_dict, "x", "g:Watcher2")') + ) end) --[[ @@ -373,7 +381,7 @@ describe('Vimscript dictionary notifications', function() ]]) command('call g:ReplaceWatcher2()') command('let g:key = "value"') - eq({'notification', '2b', {'key', {old = 'v2', new = 'value'}}}, next_msg()) + eq({ 'notification', '2b', { 'key', { old = 'v2', new = 'value' } } }, next_msg()) end) it('does not crash when freeing a watched dictionary', function() @@ -400,7 +408,7 @@ describe('Vimscript dictionary notifications', function() call dictwatcheradd(d, 'foo', {dict, key, value -> rpcnotify(g:channel, '2', key, value)}) let d.foo = 'bar' ]]) - eq({'notification', '2', {'foo', {old = 'baz', new = 'bar'}}}, next_msg()) + eq({ 'notification', '2', { 'foo', { old = 'baz', new = 'bar' } } }, next_msg()) end) end) @@ -412,12 +420,11 @@ describe('Vimscript dictionary notifications', function() call dictwatcheradd(b:, 'changedtick', 'OnTickChanged') ]]) - insert('t'); - eq({'notification', 'SendChangeTick', {'changedtick', {old = 2, new = 3}}}, - next_msg()) + insert('t') + eq({ 'notification', 'SendChangeTick', { 'changedtick', { old = 2, new = 3 } } }, next_msg()) command([[call dictwatcherdel(b:, 'changedtick', 'OnTickChanged')]]) - insert('t'); + insert('t') assert_alive() end) @@ -479,7 +486,7 @@ describe('Vimscript dictionary notifications', function() let g:d.foo = 23 ]]) eq(23, eval('g:d.foo')) - eq({"W1"}, eval('g:calls')) + eq({ 'W1' }, eval('g:calls')) end) it('calls watcher deleted in callback', function() @@ -507,7 +514,6 @@ describe('Vimscript dictionary notifications', function() let g:d.foo = 123 ]]) eq(123, eval('g:d.foo')) - eq({"W1", "W2", "W2", "W1"}, eval('g:calls')) + eq({ 'W1', 'W2', 'W2', 'W1' }, eval('g:calls')) end) - end) diff --git a/test/functional/ex_cmds/digraphs_spec.lua b/test/functional/ex_cmds/digraphs_spec.lua index 5de2adc191..24b6f7c53b 100644 --- a/test/functional/ex_cmds/digraphs_spec.lua +++ b/test/functional/ex_cmds/digraphs_spec.lua @@ -10,13 +10,13 @@ describe(':digraphs', function() clear() screen = Screen.new(65, 8) screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [4] = {bold = true}, - [5] = {background = Screen.colors.LightGrey}, - [6] = {foreground = Screen.colors.Blue1}, - [7] = {bold = true, reverse = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [4] = { bold = true }, + [5] = { background = Screen.colors.LightGrey }, + [6] = { foreground = Screen.colors.Blue1 }, + [7] = { bold = true, reverse = true }, }) screen:attach() end) diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua index 2537ab9cdc..cbda5aac98 100644 --- a/test/functional/ex_cmds/drop_spec.lua +++ b/test/functional/ex_cmds/drop_spec.lua @@ -3,7 +3,7 @@ local command = helpers.command local Screen = require('test.functional.ui.screen') local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command -describe(":drop", function() +describe(':drop', function() local screen before_each(function() @@ -11,68 +11,52 @@ describe(":drop", function() screen = Screen.new(35, 10) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {bold = true, reverse = true}, - [2] = {reverse = true}, - [3] = {bold = true}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, reverse = true }, + [2] = { reverse = true }, + [3] = { bold = true }, }) - command("set laststatus=2 shortmess-=F") + command('set laststatus=2 shortmess-=F') end) - it("works like :e when called with only one window open", function() - feed_command("drop tmp1.vim") + it('works like :e when called with only one window open', function() + feed_command('drop tmp1.vim') screen:expect([[ ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*7 {1:tmp1.vim }| "tmp1.vim" [New] | ]]) end) - it("switches to an open window showing the buffer", function() - feed_command("edit tmp1") - feed_command("vsplit") - feed_command("edit tmp2") - feed_command("drop tmp1") + it('switches to an open window showing the buffer', function() + feed_command('edit tmp1') + feed_command('vsplit') + feed_command('edit tmp2') + feed_command('drop tmp1') screen:expect([[ │^ | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*7 {2:tmp2 }{1:tmp1 }| - :drop tmp1 | + "tmp1" [New] | ]]) end) it("splits off a new window when a buffer can't be abandoned", function() - command("set nohidden") - feed_command("edit tmp1") - feed_command("vsplit") - feed_command("edit tmp2") - feed("iABC<esc>") - feed_command("drop tmp3") + command('set nohidden') + feed_command('edit tmp1') + feed_command('vsplit') + feed_command('edit tmp2') + feed('iABC<esc>') + feed_command('drop tmp3') screen:expect([[ ^ │ | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*3 {1:tmp3 }│{0:~ }| ABC │{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*2 {2:tmp2 [+] tmp1 }| "tmp3" [New] | ]]) end) - end) diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua index a6be04138b..e9176a6204 100644 --- a/test/functional/ex_cmds/echo_spec.lua +++ b/test/functional/ex_cmds/echo_spec.lua @@ -1,11 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) local eq = helpers.eq -local NIL = helpers.NIL +local NIL = vim.NIL local eval = helpers.eval local clear = helpers.clear -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local source = helpers.source local dedent = helpers.dedent local command = helpers.command @@ -14,15 +14,15 @@ local exec_capture = helpers.exec_capture local matches = helpers.matches describe(':echo :echon :echomsg :echoerr', function() - local fn_tbl = {'String', 'StringN', 'StringMsg', 'StringErr'} + local fn_tbl = { 'String', 'StringN', 'StringMsg', 'StringErr' } local function assert_same_echo_dump(expected, input, use_eval) - for _,v in pairs(fn_tbl) do - eq(expected, use_eval and eval(v..'('..input..')') or funcs[v](input)) + for _, v in pairs(fn_tbl) do + eq(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input)) end end local function assert_matches_echo_dump(expected, input, use_eval) - for _,v in pairs(fn_tbl) do - matches(expected, use_eval and eval(v..'('..input..')') or funcs[v](input)) + for _, v in pairs(fn_tbl) do + matches(expected, use_eval and eval(v .. '(' .. input .. ')') or fn[v](input)) end end @@ -68,31 +68,29 @@ describe(':echo :echon :echomsg :echoerr', function() eq('v:true', eval('String(v:true)')) eq('v:false', eval('String(v:false)')) eq('v:null', eval('String(v:null)')) - eq('v:true', funcs.String(true)) - eq('v:false', funcs.String(false)) - eq('v:null', funcs.String(NIL)) + eq('v:true', fn.String(true)) + eq('v:false', fn.String(false)) + eq('v:null', fn.String(NIL)) eq('v:true', eval('StringMsg(v:true)')) eq('v:false', eval('StringMsg(v:false)')) eq('v:null', eval('StringMsg(v:null)')) - eq('v:true', funcs.StringMsg(true)) - eq('v:false', funcs.StringMsg(false)) - eq('v:null', funcs.StringMsg(NIL)) + eq('v:true', fn.StringMsg(true)) + eq('v:false', fn.StringMsg(false)) + eq('v:null', fn.StringMsg(NIL)) eq('v:true', eval('StringErr(v:true)')) eq('v:false', eval('StringErr(v:false)')) eq('v:null', eval('StringErr(v:null)')) - eq('v:true', funcs.StringErr(true)) - eq('v:false', funcs.StringErr(false)) - eq('v:null', funcs.StringErr(NIL)) + eq('v:true', fn.StringErr(true)) + eq('v:false', fn.StringErr(false)) + eq('v:null', fn.StringErr(NIL)) end) - it('dumps values with at most six digits after the decimal point', - function() + it('dumps values with at most six digits after the decimal point', function() assert_same_echo_dump('1.234568e-20', 1.23456789123456789123456789e-020) assert_same_echo_dump('1.234568', 1.23456789123456789123456789) end) - it('dumps values with at most seven digits before the decimal point', - function() + it('dumps values with at most seven digits before the decimal point', function() assert_same_echo_dump('1234567.891235', 1234567.89123456789123456789) assert_same_echo_dump('1.234568e7', 12345678.9123456789123456789) end) @@ -115,8 +113,8 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('dumps large values', function() - assert_same_echo_dump('2147483647', 2^31-1) - assert_same_echo_dump('-2147483648', -2^31) + assert_same_echo_dump('2147483647', 2 ^ 31 - 1) + assert_same_echo_dump('-2147483648', -2 ^ 31) end) end) @@ -198,75 +196,95 @@ describe(':echo :echon :echomsg :echoerr', function() let TestDictRef = function('TestDict', d) let d.tdr = TestDictRef ]]) - eq(dedent([[ + eq( + dedent([[ function('TestDict', {'tdr': function('TestDict', {...@1})})]]), - exec_capture('echo String(d.tdr)')) + exec_capture('echo String(d.tdr)') + ) end) it('dumps automatically created partials', function() assert_same_echo_dump( "function('<SNR>1_Test2', {'f': function('<SNR>1_Test2')})", '{"f": Test2_f}.f', - true) + true + ) assert_same_echo_dump( "function('<SNR>1_Test2', [1], {'f': function('<SNR>1_Test2', [1])})", '{"f": function(Test2_f, [1])}.f', - true) + true + ) end) it('dumps manually created partials', function() - assert_same_echo_dump("function('Test3', [1, 2], {})", - "function('Test3', [1, 2], {})", true) - assert_same_echo_dump("function('Test3', [1, 2])", - "function('Test3', [1, 2])", true) - assert_same_echo_dump("function('Test3', {})", - "function('Test3', {})", true) + assert_same_echo_dump("function('Test3', [1, 2], {})", "function('Test3', [1, 2], {})", true) + assert_same_echo_dump("function('Test3', [1, 2])", "function('Test3', [1, 2])", true) + assert_same_echo_dump("function('Test3', {})", "function('Test3', {})", true) end) - it('does not crash or halt when dumping partials with reference cycles in self', - function() - meths.set_var('d', {v=true}) - eq(dedent([[ - {'p': function('<SNR>1_Test2', {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]]), - exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))')) + it('does not crash or halt when dumping partials with reference cycles in self', function() + api.nvim_set_var('d', { v = true }) + eq( + dedent( + [[ + {'p': function('<SNR>1_Test2', {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]] + ), + exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": g:d.f}))') + ) end) - it('does not show errors when dumping partials referencing the same dictionary', - function() + it('does not show errors when dumping partials referencing the same dictionary', function() command('let d = {}') -- Regression for “eval/typval_encode: Dump empty dictionary before -- checking for refcycle”, results in error. - eq('[function(\'tr\', {}), function(\'tr\', {})]', eval('String([function("tr", d), function("tr", d)])')) + eq( + "[function('tr', {}), function('tr', {})]", + eval('String([function("tr", d), function("tr", d)])') + ) -- Regression for “eval: Work with reference cycles in partials (self) -- properly”, results in crash. eval('extend(d, {"a": 1})') - eq('[function(\'tr\', {\'a\': 1}), function(\'tr\', {\'a\': 1})]', eval('String([function("tr", d), function("tr", d)])')) + eq( + "[function('tr', {'a': 1}), function('tr', {'a': 1})]", + eval('String([function("tr", d), function("tr", d)])') + ) end) - it('does not crash or halt when dumping partials with reference cycles in arguments', - function() - meths.set_var('l', {}) + it('does not crash or halt when dumping partials with reference cycles in arguments', function() + api.nvim_set_var('l', {}) eval('add(l, l)') -- Regression: the below line used to crash (add returns original list and -- there was error in dumping partials). Tested explicitly in -- test/unit/api/private_helpers_spec.lua. eval('add(l, function("Test1", l))') - eq(dedent([=[ - function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=]), - exec_capture('echo String(function("Test1", l))')) - end) - - it('does not crash or halt when dumping partials with reference cycles in self and arguments', - function() - meths.set_var('d', {v=true}) - meths.set_var('l', {}) - eval('add(l, l)') - eval('add(l, function("Test1", l))') - eval('add(l, function("Test1", d))') - eq(dedent([=[ - {'p': function('<SNR>1_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]=]), - exec_capture('echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))')) - end) + eq( + dedent( + [=[ + function('Test1', [[[...@2], function('Test1', [[...@2]])], function('Test1', [[[...@4], function('Test1', [[...@4]])]])])]=] + ), + exec_capture('echo String(function("Test1", l))') + ) + end) + + it( + 'does not crash or halt when dumping partials with reference cycles in self and arguments', + function() + api.nvim_set_var('d', { v = true }) + api.nvim_set_var('l', {}) + eval('add(l, l)') + eval('add(l, function("Test1", l))') + eval('add(l, function("Test1", d))') + eq( + dedent( + [=[ + {'p': function('<SNR>1_Test2', [[[...@3], function('Test1', [[...@3]]), function('Test1', {...@0})], function('Test1', [[[...@5], function('Test1', [[...@5]]), function('Test1', {...@0})]]), function('Test1', {...@0})], {...@0}), 'f': function('<SNR>1_Test2'), 'v': v:true}]=] + ), + exec_capture( + 'echo String(extend(extend(g:d, {"f": g:Test2_f}), {"p": function(g:d.f, l)}))' + ) + ) + end + ) end) describe('used to represent lists', function() @@ -275,25 +293,25 @@ describe(':echo :echon :echomsg :echoerr', function() end) it('dumps non-empty list', function() - assert_same_echo_dump('[1, 2]', {1,2}) + assert_same_echo_dump('[1, 2]', { 1, 2 }) end) it('dumps nested lists', function() - assert_same_echo_dump('[[[[[]]]]]', {{{{{}}}}}) + assert_same_echo_dump('[[[[[]]]]]', { { { { {} } } } }) end) it('dumps nested non-empty lists', function() - assert_same_echo_dump('[1, [[3, [[5], 4]], 2]]', {1, {{3, {{5}, 4}}, 2}}) + assert_same_echo_dump('[1, [[3, [[5], 4]], 2]]', { 1, { { 3, { { 5 }, 4 } }, 2 } }) end) it('does not error when dumping recursive lists', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq(0, exc_exec('echo String(l)')) end) it('dumps recursive lists without error', function() - meths.set_var('l', {}) + api.nvim_set_var('l', {}) eval('add(l, l)') eq('[[...@0]]', exec_capture('echo String(l)')) eq('[[[...@1]]]', exec_capture('echo String([l])')) @@ -308,27 +326,25 @@ describe(':echo :echon :echomsg :echoerr', function() it('dumps list with two same empty dictionaries, also in partials', function() command('let d = {}') assert_same_echo_dump('[{}, {}]', '[d, d]', true) - eq('[function(\'tr\', {}), {}]', eval('String([function("tr", d), d])')) - eq('[{}, function(\'tr\', {})]', eval('String([d, function("tr", d)])')) + eq("[function('tr', {}), {}]", eval('String([function("tr", d), d])')) + eq("[{}, function('tr', {})]", eval('String([d, function("tr", d)])')) end) it('dumps non-empty dictionary', function() - assert_same_echo_dump("{'t''est': 1}", {["t'est"]=1}) + assert_same_echo_dump("{'t''est': 1}", { ["t'est"] = 1 }) end) it('does not error when dumping recursive dictionaries', function() - meths.set_var('d', {d=1}) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') eq(0, exc_exec('echo String(d)')) end) it('dumps recursive dictionaries without the error', function() - meths.set_var('d', {d=1}) + api.nvim_set_var('d', { d = 1 }) eval('extend(d, {"d": d})') - eq('{\'d\': {...@0}}', - exec_capture('echo String(d)')) - eq('{\'out\': {\'d\': {...@1}}}', - exec_capture('echo String({"out": d})')) + eq("{'d': {...@0}}", exec_capture('echo String(d)')) + eq("{'out': {'d': {...@1}}}", exec_capture('echo String({"out": d})')) end) end) @@ -342,43 +358,43 @@ describe(':echo :echon :echomsg :echoerr', function() it('displays hex as hex', function() -- Regression: due to missing (uint8_t) cast \x80 was represented as -- ~@<80>. - eq('<80>', funcs.String(chr(0x80))) - eq('<81>', funcs.String(chr(0x81))) - eq('<8e>', funcs.String(chr(0x8e))) - eq('<c2>', funcs.String(('«'):sub(1, 1))) - eq('«', funcs.String(('«'):sub(1, 2))) - - eq('<80>', funcs.StringMsg(chr(0x80))) - eq('<81>', funcs.StringMsg(chr(0x81))) - eq('<8e>', funcs.StringMsg(chr(0x8e))) - eq('<c2>', funcs.StringMsg(('«'):sub(1, 1))) - eq('«', funcs.StringMsg(('«'):sub(1, 2))) + eq('<80>', fn.String(chr(0x80))) + eq('<81>', fn.String(chr(0x81))) + eq('<8e>', fn.String(chr(0x8e))) + eq('<c2>', fn.String(('«'):sub(1, 1))) + eq('«', fn.String(('«'):sub(1, 2))) + + eq('<80>', fn.StringMsg(chr(0x80))) + eq('<81>', fn.StringMsg(chr(0x81))) + eq('<8e>', fn.StringMsg(chr(0x8e))) + eq('<c2>', fn.StringMsg(('«'):sub(1, 1))) + eq('«', fn.StringMsg(('«'):sub(1, 2))) end) it('displays ASCII control characters using ^X notation', function() - eq('^C', funcs.String(ctrl('c'))) - eq('^A', funcs.String(ctrl('a'))) - eq('^F', funcs.String(ctrl('f'))) - eq('^C', funcs.StringMsg(ctrl('c'))) - eq('^A', funcs.StringMsg(ctrl('a'))) - eq('^F', funcs.StringMsg(ctrl('f'))) + eq('^C', fn.String(ctrl('c'))) + eq('^A', fn.String(ctrl('a'))) + eq('^F', fn.String(ctrl('f'))) + eq('^C', fn.StringMsg(ctrl('c'))) + eq('^A', fn.StringMsg(ctrl('a'))) + eq('^F', fn.StringMsg(ctrl('f'))) end) it('prints CR, NL and tab as-is', function() - eq('\n', funcs.String('\n')) - eq('\r', funcs.String('\r')) - eq('\t', funcs.String('\t')) + eq('\n', fn.String('\n')) + eq('\r', fn.String('\r')) + eq('\t', fn.String('\t')) end) it('prints non-printable UTF-8 in <> notation', function() -- SINGLE SHIFT TWO, unicode control - eq('<8e>', funcs.String(funcs.nr2char(0x8E))) - eq('<8e>', funcs.StringMsg(funcs.nr2char(0x8E))) + eq('<8e>', fn.String(fn.nr2char(0x8E))) + eq('<8e>', fn.StringMsg(fn.nr2char(0x8E))) -- Surrogate pair: U+1F0A0 PLAYING CARD BACK is represented in UTF-16 as -- 0xD83C 0xDCA0. This is not valid in UTF-8. - eq('<d83c>', funcs.String(funcs.nr2char(0xD83C))) - eq('<dca0>', funcs.String(funcs.nr2char(0xDCA0))) - eq('<d83c><dca0>', funcs.String(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) - eq('<d83c>', funcs.StringMsg(funcs.nr2char(0xD83C))) - eq('<dca0>', funcs.StringMsg(funcs.nr2char(0xDCA0))) - eq('<d83c><dca0>', funcs.StringMsg(funcs.nr2char(0xD83C) .. funcs.nr2char(0xDCA0))) + eq('<d83c>', fn.String(fn.nr2char(0xD83C))) + eq('<dca0>', fn.String(fn.nr2char(0xDCA0))) + eq('<d83c><dca0>', fn.String(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0))) + eq('<d83c>', fn.StringMsg(fn.nr2char(0xD83C))) + eq('<dca0>', fn.StringMsg(fn.nr2char(0xDCA0))) + eq('<d83c><dca0>', fn.StringMsg(fn.nr2char(0xD83C) .. fn.nr2char(0xDCA0))) end) end) end) diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua index 6ed500a293..b927fa418a 100644 --- a/test/functional/ex_cmds/edit_spec.lua +++ b/test/functional/ex_cmds/edit_spec.lua @@ -1,27 +1,27 @@ -local helpers = require("test.functional.helpers")(after_each) -local eq, command, funcs = helpers.eq, helpers.command, helpers.funcs +local helpers = require('test.functional.helpers')(after_each) +local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok local clear = helpers.clear local feed = helpers.feed -describe(":edit", function() +describe(':edit', function() before_each(function() clear() end) - it("without arguments does not restart :terminal buffer", function() - command("terminal") - feed([[<C-\><C-N>]]) - local bufname_before = funcs.bufname("%") - local bufnr_before = funcs.bufnr("%") - helpers.ok(nil ~= string.find(bufname_before, "^term://")) -- sanity + it('without arguments does not restart :terminal buffer', function() + command('terminal') + feed([[<C-\><C-N>]]) + local bufname_before = fn.bufname('%') + local bufnr_before = fn.bufnr('%') + helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity - command("edit") + command('edit') - local bufname_after = funcs.bufname("%") - local bufnr_after = funcs.bufnr("%") - ok(funcs.line('$') > 1) - eq(bufname_before, bufname_after) - eq(bufnr_before, bufnr_after) + local bufname_after = fn.bufname('%') + local bufnr_after = fn.bufnr('%') + ok(fn.line('$') > 1) + eq(bufname_before, bufname_after) + eq(bufnr_before, bufnr_after) end) end) diff --git a/test/functional/ex_cmds/encoding_spec.lua b/test/functional/ex_cmds/encoding_spec.lua index 7f2bd78a47..8953fb8eaf 100644 --- a/test/functional/ex_cmds/encoding_spec.lua +++ b/test/functional/ex_cmds/encoding_spec.lua @@ -3,7 +3,6 @@ local clear, feed_command, feed = helpers.clear, helpers.feed_command, helpers.f local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval describe('&encoding', function() - before_each(function() clear() -- sanity check: tests should run with encoding=utf-8 @@ -32,9 +31,9 @@ describe('&encoding', function() it('can be set to utf-8 without error', function() feed_command('set encoding=utf-8') - eq("", eval('v:errmsg')) + eq('', eval('v:errmsg')) clear('--cmd', 'set enc=utf-8') - eq("", eval('v:errmsg')) + eq('', eval('v:errmsg')) end) end) diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua index a92329ede5..d16a52ee62 100644 --- a/test/functional/ex_cmds/excmd_spec.lua +++ b/test/functional/ex_cmds/excmd_spec.lua @@ -1,8 +1,8 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -20,15 +20,25 @@ describe('Ex cmds', function() command(':later 9999999999999999999999999999999999999999') command(':echo expand("#<9999999999999999999999999999999999999999")') command(':lockvar 9999999999999999999999999999999999999999') - command(':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999') - check_excmd_err(':tabnext 9999999999999999999999999999999999999999', - 'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999') - check_excmd_err(':N 9999999999999999999999999999999999999999', - 'Vim(Next):E939: Positive count required') - check_excmd_err(':bdelete 9999999999999999999999999999999999999999', - 'Vim(bdelete):E939: Positive count required') - eq('Vim(menu):E329: No menu "9999999999999999999999999999999999999999"', - pcall_err(command, ':menu 9999999999999999999999999999999999999999')) + command( + ':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999' + ) + check_excmd_err( + ':tabnext 9999999999999999999999999999999999999999', + 'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999' + ) + check_excmd_err( + ':N 9999999999999999999999999999999999999999', + 'Vim(Next):E939: Positive count required' + ) + check_excmd_err( + ':bdelete 9999999999999999999999999999999999999999', + 'Vim(bdelete):E939: Positive count required' + ) + eq( + 'Vim(menu):E329: No menu "9999999999999999999999999999999999999999"', + pcall_err(command, ':menu 9999999999999999999999999999999999999999') + ) assert_alive() end) @@ -39,15 +49,15 @@ describe('Ex cmds', function() it(':def is an unknown command #23149', function() eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) - eq(1, funcs.exists(':d')) - eq('delete', funcs.fullcommand('d')) - eq(1, funcs.exists(':de')) - eq('delete', funcs.fullcommand('de')) - eq(0, funcs.exists(':def')) - eq('', funcs.fullcommand('def')) - eq(1, funcs.exists(':defe')) - eq('defer', funcs.fullcommand('defe')) - eq(2, funcs.exists(':defer')) - eq('defer', funcs.fullcommand('defer')) + eq(1, fn.exists(':d')) + eq('delete', fn.fullcommand('d')) + eq(1, fn.exists(':de')) + eq('delete', fn.fullcommand('de')) + eq(0, fn.exists(':def')) + eq('', fn.fullcommand('def')) + eq(1, fn.exists(':defe')) + eq('defer', fn.fullcommand('defe')) + eq(2, fn.exists(':defer')) + eq('defer', fn.fullcommand('defer')) end) end) diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua index 131661828e..a48c408600 100644 --- a/test/functional/ex_cmds/file_spec.lua +++ b/test/functional/ex_cmds/file_spec.lua @@ -1,14 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local rmdir = helpers.rmdir local mkdir = helpers.mkdir describe(':file', function() - local swapdir = luv.cwd()..'/Xtest-file_spec' + local swapdir = vim.uv.cwd() .. '/Xtest-file_spec' before_each(function() clear() rmdir(swapdir) @@ -19,18 +18,17 @@ describe(':file', function() rmdir(swapdir) end) - it("rename does not lose swapfile #6487", function() + it('rename does not lose swapfile #6487', function() local testfile = 'test-file_spec' - local testfile_renamed = testfile..'-renamed' + local testfile_renamed = testfile .. '-renamed' -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. - command('set directory^='..swapdir..'//') + command('set directory^=' .. swapdir .. '//') command('set swapfile fileformat=unix undolevels=-1') - command('edit! '..testfile) + command('edit! ' .. testfile) -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. - command('file '..testfile_renamed) - eq(testfile_renamed..'.swp', - string.match(funcs.execute('swapname'), '[^%%]+$')) + command('file ' .. testfile_renamed) + eq(testfile_renamed .. '.swp', string.match(fn.execute('swapname'), '[^%%]+$')) end) end) diff --git a/test/functional/ex_cmds/grep_spec.lua b/test/functional/ex_cmds/grep_spec.lua index 43ef1bd424..bf81ba2137 100644 --- a/test/functional/ex_cmds/grep_spec.lua +++ b/test/functional/ex_cmds/grep_spec.lua @@ -15,7 +15,7 @@ describe(':grep', function() -- Change to test directory so that the test does not run too long. feed_command('cd test') feed_command('grep a **/*') - feed('<cr>') -- Press ENTER - ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 + feed('<cr>') -- Press ENTER + ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1 end) end) diff --git a/test/functional/ex_cmds/help_spec.lua b/test/functional/ex_cmds/help_spec.lua index aca0cbbaa6..cee33de1a6 100644 --- a/test/functional/ex_cmds/help_spec.lua +++ b/test/functional/ex_cmds/help_spec.lua @@ -3,8 +3,8 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local eq = helpers.eq -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local mkdir = helpers.mkdir local rmdir = helpers.rmdir local write_file = helpers.write_file @@ -15,19 +15,19 @@ describe(':help', function() it('window closed makes cursor return to a valid win/buf #9773', function() helpers.add_builddir_to_rtp() command('help help') - eq(1001, funcs.win_getid()) + eq(1001, fn.win_getid()) command('quit') - eq(1000, funcs.win_getid()) + eq(1000, fn.win_getid()) command('autocmd WinNew * wincmd p') command('help help') -- Window 1002 is opened, but the autocmd switches back to 1000 and -- creates the help buffer there instead. - eq(1000, funcs.win_getid()) + eq(1000, fn.win_getid()) command('quit') -- Before #9773, Nvim would crash on quitting the help window. - eq(1002, funcs.win_getid()) + eq(1002, fn.win_getid()) end) it('multibyte help tags work #23975', function() @@ -40,6 +40,6 @@ describe(':help', function() command('helptags Xhelptags/doc') command('set rtp+=Xhelptags') command('help …') - eq('*…*', meths.get_current_line()) + eq('*…*', api.nvim_get_current_line()) end) end) diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua index 958dd99226..897a2997bc 100644 --- a/test/functional/ex_cmds/highlight_spec.lua +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -1,11 +1,11 @@ local Screen = require('test.functional.ui.screen') -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local eq, command = helpers.eq, helpers.command local clear = helpers.clear local eval, exc_exec = helpers.eval, helpers.exc_exec local exec = helpers.exec -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api describe(':highlight', function() local screen @@ -17,15 +17,18 @@ describe(':highlight', function() end) it('invalid color name', function() - eq('Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', - exc_exec("highlight normal ctermfg=#181818")) - eq('Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818', - exc_exec("highlight normal ctermbg=#181818")) + eq( + 'Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', + exc_exec('highlight normal ctermfg=#181818') + ) + eq( + 'Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818', + exc_exec('highlight normal ctermbg=#181818') + ) end) it('invalid group name', function() - eq('Vim(highlight):E411: Highlight group not found: foo', - exc_exec("highlight foo")) + eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec('highlight foo')) end) it('"Normal" foreground with red', function() @@ -50,18 +53,18 @@ describe(':highlight', function() end) it('clear', function() - meths.set_var('colors_name', 'foo') - eq(1, funcs.exists('g:colors_name')) + api.nvim_set_var('colors_name', 'foo') + eq(1, fn.exists('g:colors_name')) command('hi clear') - eq(0, funcs.exists('g:colors_name')) - meths.set_var('colors_name', 'foo') - eq(1, funcs.exists('g:colors_name')) + eq(0, fn.exists('g:colors_name')) + api.nvim_set_var('colors_name', 'foo') + eq(1, fn.exists('g:colors_name')) exec([[ func HiClear() hi clear endfunc ]]) - funcs.HiClear() - eq(0, funcs.exists('g:colors_name')) + fn.HiClear() + eq(0, fn.exists('g:colors_name')) end) end) diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua index d02af21731..5f59402d10 100644 --- a/test/functional/ex_cmds/ls_spec.lua +++ b/test/functional/ex_cmds/ls_spec.lua @@ -4,7 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed -local nvim = helpers.nvim +local api = helpers.api local testprg = helpers.testprg local retry = helpers.retry @@ -14,7 +14,7 @@ describe(':ls', function() end) it('R, F for :terminal buffers', function() - nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) + api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {}) command('edit foo') command('set hidden') @@ -44,6 +44,4 @@ describe(':ls', function() eq('\n 3 %aF ', string.match(ls_output, '^\n *3 ... ')) end) end) - end) - diff --git a/test/functional/ex_cmds/make_spec.lua b/test/functional/ex_cmds/make_spec.lua index d82f59ddf9..dd47bdec58 100644 --- a/test/functional/ex_cmds/make_spec.lua +++ b/test/functional/ex_cmds/make_spec.lua @@ -3,40 +3,41 @@ local clear = helpers.clear local eval = helpers.eval local has_powershell = helpers.has_powershell local matches = helpers.matches -local nvim = helpers.nvim +local api = helpers.api local testprg = helpers.testprg describe(':make', function() clear() - before_each(function () + before_each(function() clear() end) describe('with powershell', function() if not has_powershell() then - pending("not tested; powershell was not found", function() end) + pending('not tested; powershell was not found', function() end) return end - before_each(function () + before_each(function() helpers.set_shell_powershell() end) - it('captures stderr & non zero exit code #14349', function () - nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {}) + it('captures stderr & non zero exit code #14349', function() + api.nvim_set_option_value('makeprg', testprg('shell-test') .. ' foo', {}) local out = eval('execute("make")') -- Error message is captured in the file and printed in the footer - matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out) + matches( + '[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', + out + ) end) - it('captures stderr & zero exit code #14349', function () - nvim('set_option_value', 'makeprg', testprg('shell-test'), {}) + it('captures stderr & zero exit code #14349', function() + api.nvim_set_option_value('makeprg', testprg('shell-test'), {}) local out = eval('execute("make")') -- Ensure there are no "shell returned X" messages between -- command and last line (indicating zero exit) matches('LastExitCode%s+ready [$]%s+[(]', out) matches('\n.*%: ready [$]', out) end) - end) - end) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index a580e88b93..d3b027e6f4 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -1,11 +1,11 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local eq = helpers.eq local exec = helpers.exec local exec_capture = helpers.exec_capture local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local command = helpers.command local expect = helpers.expect @@ -16,13 +16,13 @@ describe(':*map', function() before_each(clear) it('are not affected by &isident', function() - meths.set_var('counter', 0) + api.nvim_set_var('counter', 0) command('nnoremap <C-x> :let counter+=1<CR>') - meths.set_option_value('isident', ('%u'):format(('>'):byte()), {}) + api.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {}) command('nnoremap <C-y> :let counter+=1<CR>') -- &isident used to disable keycode parsing here as well feed('\24\25<C-x><C-y>') - eq(4, meths.get_var('counter')) + eq(4, api.nvim_get_var('counter')) end) it(':imap <M-">', function() @@ -33,56 +33,60 @@ describe(':*map', function() it('shows <Nop> as mapping rhs', function() command('nmap asdf <Nop>') - eq([[ + eq( + [[ n asdf <Nop>]], - exec_capture('nmap asdf')) + exec_capture('nmap asdf') + ) end) it('mappings with description can be filtered', function() - meths.set_keymap('n', 'asdf1', 'qwert', {desc='do the one thing'}) - meths.set_keymap('n', 'asdf2', 'qwert', {desc='doesnot really do anything'}) - meths.set_keymap('n', 'asdf3', 'qwert', {desc='do the other thing'}) - eq([[ + api.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' }) + api.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' }) + api.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' }) + eq( + [[ n asdf3 qwert do the other thing n asdf1 qwert do the one thing]], - exec_capture('filter the nmap')) + exec_capture('filter the nmap') + ) end) it('<Plug> mappings ignore nore', function() command('let x = 0') - eq(0, meths.eval('x')) + eq(0, api.nvim_eval('x')) command [[ nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> nmap increase_x_remap <Plug>(Increase_x) nnoremap increase_x_noremap <Plug>(Increase_x) ]] feed('increase_x_remap') - eq(1, meths.eval('x')) + eq(1, api.nvim_eval('x')) feed('increase_x_noremap') - eq(2, meths.eval('x')) + eq(2, api.nvim_eval('x')) end) it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function() command('let x = 0') - eq(0, meths.eval('x')) + eq(0, api.nvim_eval('x')) command [[ nnoremap x <nop> nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr> nmap increase_x_remap x<Plug>(Increase_x)x nnoremap increase_x_noremap x<Plug>(Increase_x)x ]] - insert("Some text") + insert('Some text') eq('Some text', eval("getline('.')")) feed('increase_x_remap') - eq(1, meths.eval('x')) + eq(1, api.nvim_eval('x')) eq('Some text', eval("getline('.')")) feed('increase_x_noremap') - eq(2, meths.eval('x')) + eq(2, api.nvim_eval('x')) eq('Some te', eval("getline('.')")) end) @@ -105,25 +109,19 @@ describe('Screen', function() command('map <expr> x input("> ")') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]]) feed('x') screen:expect([[ | - ~ | - ~ | - ~ | + ~ |*3 > ^ | ]]) feed('\n') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 > | ]]) end) @@ -133,25 +131,19 @@ describe('Screen', function() feed('i') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 -- INSERT -- | ]]) feed('x') screen:expect([[ | - ~ | - ~ | - ~ | + ~ |*3 > ^ | ]]) feed('\n') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 -- INSERT -- | ]]) end) @@ -161,9 +153,7 @@ describe('Screen', function() feed(':<F2>') screen:expect([[ | - ~ | - ~ | - ~ | + ~ |*3 :^ | ]]) end) @@ -201,8 +191,7 @@ describe('Screen', function() command('nmap <expr> <F2> execute("throw 42")') feed('<F2>') screen:expect([[ - | - | + |*2 Error detected while processing : | E605: Exception not caught: 42 | Press ENTER or type command to continue^ | @@ -210,9 +199,7 @@ describe('Screen', function() feed('<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]]) end) @@ -223,9 +210,7 @@ describe('Screen', function() feed(':echo "foo') screen:expect([[ | - ~ | - ~ | - ~ | + ~ |*3 :echo "foo^ | ]]) feed('<F2>') @@ -261,9 +246,7 @@ describe('Screen', function() feed(': nmap a<CR>') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 n a b | ]]) end) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index b9ed32c328..bb6ef72787 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -1,12 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, command, nvim = helpers.clear, helpers.command, helpers.nvim +local clear, command = helpers.clear, helpers.command local expect, feed = helpers.expect, helpers.feed local eq, eval = helpers.eq, helpers.eval -local funcs = helpers.funcs - +local fn = helpers.fn describe(':emenu', function() - before_each(function() clear() command('nnoremenu Test.Test inormal<ESC>') @@ -41,26 +39,25 @@ describe(':emenu', function() end) it('executes correct bindings in command mode', function() - feed('ithis is a sentence<esc>^yiwo<esc>') + feed('ithis is a sentence<esc>^yiwo<esc>') - -- Invoke "Edit.Paste" in normal-mode. - nvim('command', 'emenu Edit.Paste') + -- Invoke "Edit.Paste" in normal-mode. + command('emenu Edit.Paste') - -- Invoke "Edit.Paste" and "Test.Test" in command-mode. - feed(':') - nvim('command', 'emenu Edit.Paste') - nvim('command', 'emenu Test.Test') + -- Invoke "Edit.Paste" and "Test.Test" in command-mode. + feed(':') + command('emenu Edit.Paste') + command('emenu Test.Test') - expect([[ + expect([[ this is a sentence this]]) - -- Assert that Edit.Paste pasted @" into the commandline. - eq('thiscmdmode', eval('getcmdline()')) + -- Assert that Edit.Paste pasted @" into the commandline. + eq('thiscmdmode', eval('getcmdline()')) end) end) describe('menu_get', function() - before_each(function() clear() command([=[ @@ -83,12 +80,12 @@ describe('menu_get', function() end) it("path='', modes='a'", function() - local m = funcs.menu_get("","a"); + local m = fn.menu_get('', 'a') -- HINT: To print the expected table and regenerate the tests: -- print(require('vim.inspect')(m)) local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -97,45 +94,45 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 + rhs = 'insert', + silent = 0, }, s = { sid = 1, noremap = 1, enabled = 1, - rhs = "x", - silent = 0 + rhs = 'x', + silent = 0, }, n = { sid = 1, noremap = 1, enabled = 1, - rhs = "inormal<Esc>", - silent = 0 + rhs = 'inormal<Esc>', + silent = 0, }, v = { sid = 1, noremap = 1, enabled = 1, - rhs = "x", - silent = 0 + rhs = 'x', + silent = 0, }, c = { sid = 1, noremap = 1, enabled = 1, - rhs = "cmdmode", - silent = 0 - } + rhs = 'cmdmode', + silent = 0, + }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, { priority = 500, - name = "Nested", + name = 'Nested', submenus = { { mappings = { @@ -143,34 +140,34 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 + rhs = 'level1', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "level1", - silent = 0 - } + rhs = 'level1', + silent = 0, + }, }, priority = 500, - name = "test", - hidden = 0 + name = 'test', + hidden = 0, }, { mappings = { @@ -178,67 +175,67 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 + rhs = 'level2', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "level2", - silent = 0 - } + rhs = 'level2', + silent = 0, + }, }, priority = 500, - name = "Nested2", - hidden = 0 - } + name = 'Nested2', + hidden = 0, + }, }, - hidden = 0 - } + hidden = 0, + }, }, priority = 500, - name = "Test" + name = 'Test', }, { priority = 500, - name = "Export", + name = 'Export', submenus = { { - tooltip = "This is the tooltip", + tooltip = 'This is the tooltip', hidden = 0, - name = "Script", + name = 'Script', priority = 500, mappings = { n = { sid = 1, noremap = 1, enabled = 1, - rhs = "p", - silent = 0 - } - } - } + rhs = 'p', + silent = 0, + }, + }, + }, }, - hidden = 0 + hidden = 0, }, { priority = 500, - name = "Edit", + name = 'Edit', submenus = { { mappings = { @@ -246,27 +243,27 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "<C-R>\"", - silent = 0 + rhs = '<C-R>"', + silent = 0, }, n = { sid = 1, noremap = 1, enabled = 1, - rhs = "p", - silent = 0 - } + rhs = 'p', + silent = 0, + }, }, priority = 500, - name = "Paste", - hidden = 0 - } + name = 'Paste', + hidden = 0, + }, }, - hidden = 0 + hidden = 0, }, { priority = 500, - name = "]Export", + name = ']Export', submenus = { { mappings = { @@ -274,72 +271,76 @@ describe('menu_get', function() sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, v = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, s = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 + rhs = 'thisoneshouldbehidden', + silent = 0, }, n = { sid = 0, noremap = 0, enabled = 1, - rhs = "thisoneshouldbehidden", - silent = 0 - } + rhs = 'thisoneshouldbehidden', + silent = 0, + }, }, priority = 500, - name = "hidden", - hidden = 0 - } + name = 'hidden', + hidden = 0, + }, }, - hidden = 1 - } + hidden = 1, + }, } eq(expected, m) end) it('matching path, all modes', function() - local m = funcs.menu_get("Export", "a") - local expected = { { - hidden = 0, - name = "Export", - priority = 500, - submenus = { { - tooltip = "This is the tooltip", + local m = fn.menu_get('Export', 'a') + local expected = { + { hidden = 0, - name = "Script", + name = 'Export', priority = 500, - mappings = { - n = { - sid = 1, - noremap = 1, - enabled = 1, - rhs = "p", - silent = 0 - } - } - } } - } } + submenus = { + { + tooltip = 'This is the tooltip', + hidden = 0, + name = 'Script', + priority = 500, + mappings = { + n = { + sid = 1, + noremap = 1, + enabled = 1, + rhs = 'p', + silent = 0, + }, + }, + }, + }, + }, + } eq(expected, m) end) it('no path, matching modes', function() - local m = funcs.menu_get("","i") + local m = fn.menu_get('', 'i') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -348,27 +349,27 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 - } + rhs = 'insert', + silent = 0, + }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, }, priority = 500, - name = "Test" - } + name = 'Test', + }, } eq(expected, m) end) it('matching path and modes', function() - local m = funcs.menu_get("Test","i") + local m = fn.menu_get('Test', 'i') local expected = { { - shortcut = "T", + shortcut = 'T', submenus = { { mappings = { @@ -376,26 +377,25 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "insert", - silent = 0 + rhs = 'insert', + silent = 0, }, }, priority = 500, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, }, priority = 500, - name = "Test", - hidden = 0 - } + name = 'Test', + hidden = 0, + }, } eq(expected, m) end) end) describe('menu_get', function() - before_each(function() clear() command('aunmenu *') @@ -412,10 +412,10 @@ describe('menu_get', function() command('nnoremenu &Test.Test8 <NoP>') command('nnoremenu &Test.Test9 ""') - local m = funcs.menu_get(""); + local m = fn.menu_get('') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -425,12 +425,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "inormal<Esc>", - silent = 0 - } + rhs = 'inormal<Esc>', + silent = 0, + }, }, - name = "Test", - hidden = 0 + name = 'Test', + hidden = 0, }, { priority = 500, @@ -439,12 +439,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "<Tab><Esc>", - silent = 0 - } + rhs = '<Tab><Esc>', + silent = 0, + }, }, - name = "Test2", - hidden = 0 + name = 'Test2', + hidden = 0, }, { priority = 500, @@ -453,19 +453,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "yA<C-R>0<Tab>xyz<Esc>", - silent = 0 + rhs = 'yA<C-R>0<Tab>xyz<Esc>', + silent = 0, }, v = { sid = 1, noremap = 1, enabled = 1, - rhs = "yA<C-R>0<Tab>xyz<Esc>", - silent = 0 - } + rhs = 'yA<C-R>0<Tab>xyz<Esc>', + silent = 0, + }, }, - name = "Test3", - hidden = 0 + name = 'Test3', + hidden = 0, }, { priority = 500, @@ -474,12 +474,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "<C-R>*", - silent = 0 - } + rhs = '<C-R>*', + silent = 0, + }, }, - name = "Test4", - hidden = 0 + name = 'Test4', + hidden = 0, }, { priority = 500, @@ -488,12 +488,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "<C-R>+", - silent = 0 - } + rhs = '<C-R>+', + silent = 0, + }, }, - name = "Test5", - hidden = 0 + name = 'Test5', + hidden = 0, }, { priority = 500, @@ -502,12 +502,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test6", - hidden = 0 + name = 'Test6', + hidden = 0, }, { priority = 500, @@ -516,12 +516,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test7", - hidden = 0 + name = 'Test7', + hidden = 0, }, { priority = 500, @@ -530,12 +530,12 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "", - silent = 0 - } + rhs = '', + silent = 0, + }, }, - name = "Test8", - hidden = 0 + name = 'Test8', + hidden = 0, }, { priority = 500, @@ -544,17 +544,17 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "\"\"", - silent = 0 - } + rhs = '""', + silent = 0, + }, }, - name = "Test9", - hidden = 0 - } + name = 'Test9', + hidden = 0, + }, }, priority = 500, - name = "Test" - } + name = 'Test', + }, } eq(m, expected) @@ -565,12 +565,12 @@ describe('menu_get', function() command('nnoremenu &Test\\ 1.Test\\ 2 Wargl') command('nnoremenu &Test4.Test<Tab>3 i space<Esc>') - local m = funcs.menu_get(""); + local m = fn.menu_get('') local expected = { { - shortcut = "T", + shortcut = 'T', hidden = 0, - actext = "Y", + actext = 'Y', submenus = { { mappings = { @@ -578,21 +578,21 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "inormal<Alt-j>", - silent = 0 - } + rhs = 'inormal<Alt-j>', + silent = 0, + }, }, hidden = 0, - actext = "X x", + actext = 'X x', priority = 500, - name = "Test" - } + name = 'Test', + }, }, priority = 500, - name = "Test" + name = 'Test', }, { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -602,19 +602,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "Wargl", - silent = 0 - } + rhs = 'Wargl', + silent = 0, + }, }, - name = "Test 2", - hidden = 0 - } + name = 'Test 2', + hidden = 0, + }, }, priority = 500, - name = "Test 1" + name = 'Test 1', }, { - shortcut = "T", + shortcut = 'T', hidden = 0, submenus = { { @@ -623,19 +623,19 @@ describe('menu_get', function() sid = 1, noremap = 1, enabled = 1, - rhs = "i space<Esc>", - silent = 0 - } + rhs = 'i space<Esc>', + silent = 0, + }, }, hidden = 0, - actext = "3", + actext = '3', priority = 500, - name = "Test" - } + name = 'Test', + }, }, priority = 500, - name = "Test4" - } + name = 'Test4', + }, } eq(m, expected) diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 7522d4a99c..6f2e0be3d5 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -6,20 +6,18 @@ local command = helpers.command local get_pathsep = helpers.get_pathsep local eq = helpers.eq local neq = helpers.neq -local funcs = helpers.funcs +local fn = helpers.fn local matches = helpers.matches -local pesc = helpers.pesc +local pesc = vim.pesc local rmdir = helpers.rmdir -local sleep = helpers.sleep -local meths = helpers.meths +local sleep = vim.uv.sleep +local api = helpers.api local skip = helpers.skip local is_os = helpers.is_os local mkdir = helpers.mkdir local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec' -if helpers.skip(helpers.is_os('win')) then return end - describe(':mksession', function() local session_file = file_prefix .. '.vim' local tab_dir = file_prefix .. '.d' @@ -52,8 +50,8 @@ describe(':mksession', function() -- Restore session. command('source ' .. session_file) - eq(funcs.winbufnr(1), funcs.winbufnr(2)) - neq(funcs.winbufnr(1), funcs.winbufnr(3)) + eq(fn.winbufnr(1), fn.winbufnr(2)) + neq(fn.winbufnr(1), fn.winbufnr(3)) end) -- common testing procedure for testing "sessionoptions-=terminal" @@ -68,64 +66,61 @@ describe(':mksession', function() -- Restore session. command('source ' .. session_file) - eq(expected_buf_count, #meths.list_bufs()) + eq(expected_buf_count, #api.nvim_list_bufs()) end - it( - 'do not restore :terminal if not set in sessionoptions, terminal in current window #13078', - function() - local tmpfile_base = file_prefix .. '-tmpfile' - command('edit ' .. tmpfile_base) - command('terminal') + it('do not restore :terminal if not set in sessionoptions, terminal in curwin #13078', function() + local tmpfile_base = file_prefix .. '-tmpfile' + command('edit ' .. tmpfile_base) + command('terminal') - local buf_count = #meths.list_bufs() - eq(2, buf_count) + local buf_count = #api.nvim_list_bufs() + eq(2, buf_count) - eq('terminal', meths.get_option_value('buftype', {})) + eq('terminal', api.nvim_get_option_value('buftype', {})) - test_terminal_session_disabled(2) + test_terminal_session_disabled(2) - -- no terminal should be set. As a side effect we end up with a blank buffer - eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] })) - eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] })) - end - ) + -- no terminal should be set. As a side effect we end up with a blank buffer + eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[1] })) + eq('', api.nvim_get_option_value('buftype', { buf = api.nvim_list_bufs()[2] })) + end) it('do not restore :terminal if not set in sessionoptions, terminal hidden #13078', function() command('terminal') - local terminal_bufnr = meths.get_current_buf() + local terminal_bufnr = api.nvim_get_current_buf() local tmpfile_base = file_prefix .. '-tmpfile' -- make terminal hidden by opening a new file command('edit ' .. tmpfile_base .. '1') - local buf_count = #meths.list_bufs() + local buf_count = #api.nvim_list_bufs() eq(2, buf_count) - eq(1, funcs.getbufinfo(terminal_bufnr)[1].hidden) + eq(1, fn.getbufinfo(terminal_bufnr)[1].hidden) test_terminal_session_disabled(1) -- no terminal should exist here - neq('', meths.buf_get_name(meths.list_bufs()[1])) + neq('', api.nvim_buf_get_name(api.nvim_list_bufs()[1])) end) it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() command('terminal') - eq('terminal', meths.get_option_value('buftype', {})) + eq('terminal', api.nvim_get_option_value('buftype', {})) - local buf_count = #meths.list_bufs() + local buf_count = #api.nvim_list_bufs() eq(1, buf_count) test_terminal_session_disabled(1) -- no terminal should be set - eq('', meths.get_option_value('buftype', {})) + eq('', api.nvim_get_option_value('buftype', {})) end) it('restores tab-local working directories', function() local tmpfile_base = file_prefix .. '-tmpfile' - local cwd_dir = funcs.getcwd() + local cwd_dir = fn.getcwd() -- :mksession does not save empty tabs, so create some buffers. command('edit ' .. tmpfile_base .. '1') @@ -141,15 +136,15 @@ describe(':mksession', function() command('source ' .. session_file) -- First tab should have the original working directory. command('tabnext 1') - eq(cwd_dir, funcs.getcwd()) + eq(cwd_dir, fn.getcwd()) -- Second tab should have the tab-local working directory. command('tabnext 2') - eq(cwd_dir .. get_pathsep() .. tab_dir, funcs.getcwd()) + eq(cwd_dir .. get_pathsep() .. tab_dir, fn.getcwd()) end) it('restores buffers with tab-local CWD', function() local tmpfile_base = file_prefix .. '-tmpfile' - local cwd_dir = funcs.getcwd() + local cwd_dir = fn.getcwd() local session_path = cwd_dir .. get_pathsep() .. session_file command('edit ' .. tmpfile_base .. '1') @@ -165,13 +160,15 @@ describe(':mksession', function() -- Use :silent to avoid press-enter prompt due to long path command('silent source ' .. session_path) command('tabnext 1') - eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', funcs.expand('%:p')) + eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '1', fn.expand('%:p')) command('tabnext 2') - eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', funcs.expand('%:p')) + eq(cwd_dir .. get_pathsep() .. tmpfile_base .. '2', fn.expand('%:p')) end) it('restores CWD for :terminal buffers #11288', function() - local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') + skip(is_os('win'), 'causes rmdir() to fail') + + local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes. local session_path = cwd_dir .. '/' .. session_file @@ -189,7 +186,7 @@ describe(':mksession', function() command('silent source ' .. session_path) local expected_cwd = cwd_dir .. '/' .. tab_dir - matches('^term://' .. pesc(expected_cwd) .. '//%d+:', funcs.expand('%')) + matches('^term://' .. pesc(expected_cwd) .. '//%d+:', fn.expand('%')) command('%bwipeout!') if is_os('win') then sleep(100) -- Make sure all child processes have exited. @@ -200,7 +197,7 @@ describe(':mksession', function() skip(is_os('win'), 'N/A for Windows') local screen - local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') + local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') local session_path = cwd_dir .. '/' .. session_file screen = Screen.new(50, 6) @@ -209,9 +206,7 @@ describe(':mksession', function() ^/ | | [Process exited 0] | - | - | - | + |*3 ]] command('cd /') @@ -238,7 +233,7 @@ describe(':mksession', function() local tmpfile = file_prefix .. '-tmpfile-float' command('edit ' .. tmpfile) - local buf = meths.create_buf(false, true) + local buf = api.nvim_create_buf(false, true) local config = { relative = 'editor', focusable = false, @@ -248,8 +243,8 @@ describe(':mksession', function() col = 1, style = 'minimal', } - meths.open_win(buf, false, config) - local cmdheight = meths.get_option_value('cmdheight', {}) + api.nvim_open_win(buf, false, config) + local cmdheight = api.nvim_get_option_value('cmdheight', {}) command('mksession ' .. session_file) -- Create a new test instance of Nvim. @@ -257,12 +252,12 @@ describe(':mksession', function() command('source ' .. session_file) - eq(tmpfile, funcs.expand('%')) + eq(tmpfile, fn.expand('%')) -- Check that there is only a single window, which indicates the floating -- window was not restored. - eq(1, funcs.winnr('$')) + eq(1, fn.winnr('$')) -- The command-line height should remain the same as it was. - eq(cmdheight, meths.get_option_value('cmdheight', {})) + eq(cmdheight, api.nvim_get_option_value('cmdheight', {})) os.remove(tmpfile) end) diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua index f71b826210..de0a4fe0ea 100644 --- a/test/functional/ex_cmds/mkview_spec.lua +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -4,7 +4,7 @@ local clear = helpers.clear local command = helpers.command local get_pathsep = helpers.get_pathsep local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local rmdir = helpers.rmdir local mkdir = helpers.mkdir @@ -28,9 +28,8 @@ describe(':mkview', function() end) it('viewoption curdir restores local current directory', function() - local cwd_dir = funcs.getcwd() - local set_view_dir_command = 'set viewdir=' .. cwd_dir .. - get_pathsep() .. view_dir + local cwd_dir = fn.getcwd() + local set_view_dir_command = 'set viewdir=' .. cwd_dir .. get_pathsep() .. view_dir -- By default the local current directory should save command(set_view_dir_command) @@ -56,12 +55,11 @@ describe(':mkview', function() command('edit ' .. tmp_file_base .. '2') command('loadview') -- The view's current directory should not have changed - eq(cwd_dir, funcs.getcwd()) + eq(cwd_dir, fn.getcwd()) -- Load the view with a saved local current directory command('edit ' .. tmp_file_base .. '1') command('loadview') -- The view's local directory should have been saved - eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd()) + eq(cwd_dir .. get_pathsep() .. local_dir, fn.getcwd()) end) - end) diff --git a/test/functional/ex_cmds/normal_spec.lua b/test/functional/ex_cmds/normal_spec.lua index 009f1d6516..723bfefcf4 100644 --- a/test/functional/ex_cmds/normal_spec.lua +++ b/test/functional/ex_cmds/normal_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command -local funcs = helpers.funcs +local fn = helpers.fn local feed = helpers.feed local expect = helpers.expect local eq = helpers.eq @@ -29,10 +29,10 @@ describe(':normal!', function() it('can stop Visual mode without closing cmdwin vim-patch:9.0.0234', function() feed('q:') feed('v') - eq('v', funcs.mode(1)) - eq(':', funcs.getcmdwintype()) + eq('v', fn.mode(1)) + eq(':', fn.getcmdwintype()) command('normal! \027') - eq('n', funcs.mode(1)) - eq(':', funcs.getcmdwintype()) + eq('n', fn.mode(1)) + eq(':', fn.getcmdwintype()) end) end) diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index 19611429e0..8d1469f343 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -4,7 +4,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local command = helpers.command local expect_exit = helpers.expect_exit -local buf, eq, feed_command = helpers.curbufmeths, helpers.eq, helpers.feed_command +local api, eq, feed_command = helpers.api, helpers.eq, helpers.feed_command local feed, poke_eventloop = helpers.feed, helpers.poke_eventloop local ok = helpers.ok local eval = helpers.eval @@ -12,9 +12,15 @@ local eval = helpers.eval local shada_file = 'Xtest.shada' local function _clear() - clear{args={'-i', shada_file, -- Need shada for these tests. - '--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'}, - args_rm={'-i', '--cmd'}} + clear { + args = { + '-i', + shada_file, -- Need shada for these tests. + '--cmd', + 'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler', + }, + args_rm = { '-i', '--cmd' }, + } end describe(':oldfiles', function() @@ -36,12 +42,12 @@ describe(':oldfiles', function() feed_command('edit testfile2') feed_command('wshada') feed_command('rshada!') - local oldfiles = helpers.meths.get_vvar('oldfiles') + local oldfiles = api.nvim_get_vvar('oldfiles') feed_command('oldfiles') screen:expect([[ | - 1: ]].. add_padding(oldfiles[1]) ..[[ | - 2: ]].. add_padding(oldfiles[2]) ..[[ | + 1: ]] .. add_padding(oldfiles[1]) .. [[ | + 2: ]] .. add_padding(oldfiles[2]) .. [[ | | Press ENTER or type command to continue^ | ]]) @@ -50,16 +56,16 @@ describe(':oldfiles', function() it('can be filtered with :filter', function() feed_command('edit file_one.txt') - local file1 = buf.get_name() + local file1 = api.nvim_buf_get_name(0) feed_command('edit file_two.txt') - local file2 = buf.get_name() + local file2 = api.nvim_buf_get_name(0) feed_command('edit another.txt') - local another = buf.get_name() + local another = api.nvim_buf_get_name(0) feed_command('wshada') feed_command('rshada!') local function get_oldfiles(cmd) - local t = eval([[split(execute(']]..cmd..[['), "\n")]]) + local t = eval([[split(execute(']] .. cmd .. [['), "\n")]]) for i, _ in ipairs(t) do t[i] = t[i]:gsub('^%d+:%s+', '') end @@ -68,16 +74,16 @@ describe(':oldfiles', function() end local oldfiles = get_oldfiles('oldfiles') - eq({another, file1, file2}, oldfiles) + eq({ another, file1, file2 }, oldfiles) oldfiles = get_oldfiles('filter file_ oldfiles') - eq({file1, file2}, oldfiles) + eq({ file1, file2 }, oldfiles) oldfiles = get_oldfiles('filter /another/ oldfiles') - eq({another}, oldfiles) + eq({ another }, oldfiles) oldfiles = get_oldfiles('filter! file_ oldfiles') - eq({another}, oldfiles) + eq({ another }, oldfiles) end) end) @@ -89,9 +95,9 @@ describe(':browse oldfiles', function() before_each(function() _clear() feed_command('edit testfile1') - filename = buf.get_name() + filename = api.nvim_buf_get_name(0) feed_command('edit testfile2') - filename2 = buf.get_name() + filename2 = api.nvim_buf_get_name(0) feed_command('wshada') poke_eventloop() _clear() @@ -102,7 +108,7 @@ describe(':browse oldfiles', function() -- Ensure v:oldfiles isn't busted. Since things happen so fast, -- the ordering of v:oldfiles is unstable (it uses qsort() under-the-hood). -- Let's verify the contents and the length of v:oldfiles before moving on. - oldfiles = helpers.meths.get_vvar('oldfiles') + oldfiles = helpers.api.nvim_get_vvar('oldfiles') eq(2, #oldfiles) ok(filename == oldfiles[1] or filename == oldfiles[2]) ok(filename2 == oldfiles[1] or filename2 == oldfiles[2]) @@ -117,16 +123,16 @@ describe(':browse oldfiles', function() it('provides a prompt and edits the chosen file', function() feed('2<cr>') - eq(oldfiles[2], buf.get_name()) + eq(oldfiles[2], api.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing on <cr>', function() feed('<cr>') - eq('', buf.get_name()) + eq('', api.nvim_buf_get_name(0)) end) it('provides a prompt and does nothing if choice is out-of-bounds', function() feed('3<cr>') - eq('', buf.get_name()) + eq('', api.nvim_buf_get_name(0)) end) end) diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua index 98c0f74635..ba5ec7d2d1 100644 --- a/test/functional/ex_cmds/print_commands_spec.lua +++ b/test/functional/ex_cmds/print_commands_spec.lua @@ -1,12 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, eq, command, funcs = - helpers.clear, helpers.eq, helpers.command, helpers.funcs +local clear, eq, command, fn = helpers.clear, helpers.eq, helpers.command, helpers.fn describe(':z^', function() before_each(clear) it('correctly sets the cursor after :z^', function() command('z^') - eq(1, funcs.line('.')) + eq(1, fn.line('.')) end) end) diff --git a/test/functional/ex_cmds/profile_spec.lua b/test/functional/ex_cmds/profile_spec.lua index 249373a9c4..f85dcc60ff 100644 --- a/test/functional/ex_cmds/profile_spec.lua +++ b/test/functional/ex_cmds/profile_spec.lua @@ -1,27 +1,27 @@ require('os') -local luv = require('luv') +local uv = vim.uv -local helpers = require('test.functional.helpers')(after_each) -local eval = helpers.eval -local command = helpers.command -local eq, neq = helpers.eq, helpers.neq +local helpers = require('test.functional.helpers')(after_each) +local eval = helpers.eval +local command = helpers.command +local eq, neq = helpers.eq, helpers.neq local tempfile = helpers.tmpname() -local source = helpers.source -local matches = helpers.matches +local source = helpers.source +local matches = helpers.matches local read_file = helpers.read_file -- tmpname() also creates the file on POSIX systems. Remove it again. -- We just need the name, ignoring any race conditions. -if luv.fs_stat(tempfile).uid then +if uv.fs_stat(tempfile).uid then os.remove(tempfile) end local function assert_file_exists(filepath) - neq(nil, luv.fs_stat(filepath).uid) + neq(nil, uv.fs_stat(filepath).uid) end local function assert_file_exists_not(filepath) - eq(nil, luv.fs_stat(filepath)) + eq(nil, uv.fs_stat(filepath)) end describe(':profile', function() @@ -29,7 +29,7 @@ describe(':profile', function() after_each(function() helpers.expect_exit(command, 'qall!') - if luv.fs_stat(tempfile).uid ~= nil then + if uv.fs_stat(tempfile).uid ~= nil then os.remove(tempfile) end end) diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index 4d9d8eeb90..5af0198ffe 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -4,31 +4,35 @@ local Screen = require('test.functional.ui.screen') local feed = helpers.feed local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local exc_exec = helpers.exc_exec local write_file = helpers.write_file -local curbufmeths = helpers.curbufmeths +local api = helpers.api local source = helpers.source local file_base = 'Xtest-functional-ex_cmds-quickfix_commands' before_each(clear) -for _, c in ipairs({'l', 'c'}) do +for _, c in ipairs({ 'l', 'c' }) do local file = ('%s.%s'):format(file_base, c) local filecmd = c .. 'file' local getfcmd = c .. 'getfile' local addfcmd = c .. 'addfile' - local getlist = (c == 'c') and funcs.getqflist or ( - function() return funcs.getloclist(0) end) + local getlist = (c == 'c') and fn.getqflist or function() + return fn.getloclist(0) + end describe((':%s*file commands'):format(c), function() before_each(function() - write_file(file, ([[ + write_file( + file, + ([[ %s-1.res:700:10:Line 700 %s-2.res:800:15:Line 800 - ]]):format(file, file)) + ]]):format(file, file) + ) end) after_each(function() os.remove(file) @@ -39,49 +43,114 @@ for _, c in ipairs({'l', 'c'}) do -- Second line of each entry (i.e. `nr=-1, …`) was obtained from actual -- results. First line (i.e. `{lnum=…`) was obtained from legacy test. local list = { - {lnum=700, end_lnum=0, col=10, end_col=0, text='Line 700', module='', - nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, - {lnum=800, end_lnum=0, col=15, end_col=0, text='Line 800', module='', - nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + { + lnum = 700, + end_lnum = 0, + col = 10, + end_col = 0, + text = 'Line 700', + module = '', + nr = -1, + bufnr = 2, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, + { + lnum = 800, + end_lnum = 0, + col = 15, + end_col = 0, + text = 'Line 800', + module = '', + nr = -1, + bufnr = 3, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, } eq(list, getlist()) - eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) - eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr)) -- Run cfile/lfile from a modified buffer command('set nohidden') command('enew!') - curbufmeths.set_lines(1, 1, true, {'Quickfix'}) - eq(('Vim(%s):E37: No write since last change (add ! to override)'):format( - filecmd), - exc_exec(('%s %s'):format(filecmd, file))) + api.nvim_buf_set_lines(0, 1, 1, true, { 'Quickfix' }) + eq( + ('Vim(%s):E37: No write since last change (add ! to override)'):format(filecmd), + exc_exec(('%s %s'):format(filecmd, file)) + ) - write_file(file, ([[ + write_file( + file, + ([[ %s-3.res:900:30:Line 900 - ]]):format(file)) + ]]):format(file) + ) command(('%s %s'):format(addfcmd, file)) list[#list + 1] = { - lnum=900, end_lnum=0, col=30, end_col=0, text='Line 900', module='', - nr=-1, bufnr=5, valid=1, pattern='', vcol=0, ['type']='', + lnum = 900, + end_lnum = 0, + col = 30, + end_col = 0, + text = 'Line 900', + module = '', + nr = -1, + bufnr = 5, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', } eq(list, getlist()) - eq(('%s-3.res'):format(file), funcs.bufname(list[3].bufnr)) + eq(('%s-3.res'):format(file), fn.bufname(list[3].bufnr)) - write_file(file, ([[ + write_file( + file, + ([[ %s-1.res:222:77:Line 222 %s-2.res:333:88:Line 333 - ]]):format(file, file)) + ]]):format(file, file) + ) command('enew!') command(('%s %s'):format(getfcmd, file)) list = { - {lnum=222, end_lnum=0, col=77, end_col=0, text='Line 222', module='', - nr=-1, bufnr=2, valid=1, pattern='', vcol=0, ['type']=''}, - {lnum=333, end_lnum=0, col=88, end_col=0, text='Line 333', module='', - nr=-1, bufnr=3, valid=1, pattern='', vcol=0, ['type']=''}, + { + lnum = 222, + end_lnum = 0, + col = 77, + end_col = 0, + text = 'Line 222', + module = '', + nr = -1, + bufnr = 2, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, + { + lnum = 333, + end_lnum = 0, + col = 88, + end_col = 0, + text = 'Line 333', + module = '', + nr = -1, + bufnr = 3, + valid = 1, + pattern = '', + vcol = 0, + ['type'] = '', + }, } eq(list, getlist()) - eq(('%s-1.res'):format(file), funcs.bufname(list[1].bufnr)) - eq(('%s-2.res'):format(file), funcs.bufname(list[2].bufnr)) + eq(('%s-1.res'):format(file), fn.bufname(list[1].bufnr)) + eq(('%s-2.res'):format(file), fn.bufname(list[2].bufnr)) end) end) end @@ -109,7 +178,7 @@ describe('quickfix', function() call append(0, ['New line 1', 'New line 2', 'New line 3']) silent ll ]]) - eq({0, 6, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 6, 1, 0, 1 }, fn.getcurpos()) end) it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function() @@ -127,20 +196,20 @@ describe('quickfix', function() end) it(':vimgrep can specify Unicode pattern without delimiters', function() - eq('Vim(vimgrep):E480: No match: →', exc_exec('vimgrep → test/functional/fixtures/tty-test.c')) + eq( + 'Vim(vimgrep):E480: No match: →', + exc_exec('vimgrep → test/functional/fixtures/tty-test.c') + ) local screen = Screen.new(40, 6) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {reverse = true}, -- IncSearch + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { reverse = true }, -- IncSearch }) screen:attach() feed('i→<Esc>:vimgrep →') screen:expect([[ {1:→} | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*4 :vimgrep →^ | ]]) end) diff --git a/test/functional/ex_cmds/quit_spec.lua b/test/functional/ex_cmds/quit_spec.lua index 3680801dae..5a1759dab3 100644 --- a/test/functional/ex_cmds/quit_spec.lua +++ b/test/functional/ex_cmds/quit_spec.lua @@ -11,4 +11,3 @@ describe(':qa', function() -- errors end) end) - diff --git a/test/functional/ex_cmds/script_spec.lua b/test/functional/ex_cmds/script_spec.lua index 62249caa5e..4c963c5da7 100644 --- a/test/functional/ex_cmds/script_spec.lua +++ b/test/functional/ex_cmds/script_spec.lua @@ -5,7 +5,7 @@ local neq = helpers.neq local command = helpers.command local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local dedent = helpers.dedent local exc_exec = helpers.exc_exec @@ -17,7 +17,7 @@ before_each(clear) local function source(code) write_file(tmpfile, code) - command('source '..tmpfile) + command('source ' .. tmpfile) end describe('script_get-based command', function() @@ -30,29 +30,48 @@ describe('script_get-based command', function() local function test_garbage_exec(cmd, check_neq) describe(cmd, function() it('works correctly when skipping oneline variant', function() - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ if 0 %s %s endif - ]])):format(cmd, garbage))) + ]])):format(cmd, garbage) + ) + ) eq('', exec_capture('messages')) if check_neq then - neq(0, exc_exec(dedent([[ + neq( + 0, + exc_exec(dedent([[ %s %s - ]])):format(cmd, garbage)) + ]])):format(cmd, garbage) + ) end end) it('works correctly when skipping HEREdoc variant', function() - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ if 0 %s << EOF %s EOF endif - ]])):format(cmd, garbage))) + ]])):format(cmd, garbage) + ) + ) eq('', exec_capture('messages')) if check_neq then - eq(true, pcall(source, (dedent([[ + eq( + true, + pcall( + source, + (dedent([[ let g:exc = 0 try %s << EOF @@ -61,8 +80,10 @@ describe('script_get-based command', function() catch let g:exc = v:exception endtry - ]])):format(cmd, garbage))) - neq(0, meths.get_var('exc')) + ]])):format(cmd, garbage) + ) + ) + neq(0, api.nvim_get_var('exc')) end end) end) @@ -75,7 +96,7 @@ describe('script_get-based command', function() -- Provider-based scripts test_garbage_exec('ruby', not missing_provider('ruby')) - test_garbage_exec('python3', not missing_provider('python3')) + test_garbage_exec('python3', not missing_provider('python')) -- Missing scripts test_garbage_exec('python', false) diff --git a/test/functional/ex_cmds/sign_spec.lua b/test/functional/ex_cmds/sign_spec.lua index f280a45174..06de7f23a9 100644 --- a/test/functional/ex_cmds/sign_spec.lua +++ b/test/functional/ex_cmds/sign_spec.lua @@ -1,5 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim, eq, assert_alive = helpers.clear, helpers.nvim, helpers.eq, helpers.assert_alive +local clear, eq, assert_alive = helpers.clear, helpers.eq, helpers.assert_alive +local command = helpers.command +local api = helpers.api describe('sign', function() before_each(clear) @@ -7,24 +9,24 @@ describe('sign', function() describe('without specifying buffer', function() it('deletes the sign from all buffers', function() -- place a sign with id 34 to first buffer - nvim('command', 'sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') - local buf1 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf1) + command('sign define Foo text=+ texthl=Delimiter linehl=Comment numhl=Number') + local buf1 = api.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf1) -- create a second buffer and place the sign on it as well - nvim('command', 'new') - local buf2 = nvim('eval', 'bufnr("%")') - nvim('command', 'sign place 34 line=3 name=Foo buffer='..buf2) + command('new') + local buf2 = api.nvim_eval('bufnr("%")') + command('sign place 34 line=3 name=Foo buffer=' .. buf2) -- now unplace without specifying a buffer - nvim('command', 'sign unplace 34') - eq("--- Signs ---\n", nvim('exec', 'sign place buffer='..buf1, true)) - eq("--- Signs ---\n", nvim('exec', 'sign place buffer='..buf2, true)) + command('sign unplace 34') + eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf1, true)) + eq('--- Signs ---\n', api.nvim_exec('sign place buffer=' .. buf2, true)) end) end) end) describe('define {id}', function() - it ('does not leak memory when specifying multiple times the same argument', function() - nvim('command', 'sign define Foo culhl=Normal culhl=Normal') + it('does not leak memory when specifying multiple times the same argument', function() + command('sign define Foo culhl=Normal culhl=Normal') assert_alive() end) end) diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua index 24987354a4..5ce0e395bd 100644 --- a/test/functional/ex_cmds/source_spec.lua +++ b/test/functional/ex_cmds/source_spec.lua @@ -3,7 +3,7 @@ local command = helpers.command local insert = helpers.insert local eq = helpers.eq local clear = helpers.clear -local meths = helpers.meths +local api = helpers.api local feed = helpers.feed local feed_command = helpers.feed_command local write_file = helpers.write_file @@ -49,37 +49,43 @@ describe(':source', function() pending("'shellslash' only works on Windows") return end - meths.set_option_value('shellslash', false, {}) + api.nvim_set_option_value('shellslash', false, {}) mkdir('Xshellslash') - write_file([[Xshellslash/Xstack.vim]], [[ + write_file( + [[Xshellslash/Xstack.vim]], + [[ let g:stack1 = expand('<stack>') set shellslash let g:stack2 = expand('<stack>') set noshellslash let g:stack3 = expand('<stack>') - ]]) + ]] + ) for _ = 1, 2 do command([[source Xshellslash/Xstack.vim]]) - matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack1')) - matches([[Xshellslash/Xstack%.vim]], meths.get_var('stack2')) - matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3')) + matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack1')) + matches([[Xshellslash/Xstack%.vim]], api.nvim_get_var('stack2')) + matches([[Xshellslash\Xstack%.vim]], api.nvim_get_var('stack3')) end - write_file([[Xshellslash/Xstack.lua]], [[ + write_file( + [[Xshellslash/Xstack.lua]], + [[ vim.g.stack1 = vim.fn.expand('<stack>') vim.o.shellslash = true vim.g.stack2 = vim.fn.expand('<stack>') vim.o.shellslash = false vim.g.stack3 = vim.fn.expand('<stack>') - ]]) + ]] + ) for _ = 1, 2 do command([[source Xshellslash/Xstack.lua]]) - matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack1')) - matches([[Xshellslash/Xstack%.lua]], meths.get_var('stack2')) - matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack3')) + matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack1')) + matches([[Xshellslash/Xstack%.lua]], api.nvim_get_var('stack2')) + matches([[Xshellslash\Xstack%.lua]], api.nvim_get_var('stack3')) end rmdir('Xshellslash') @@ -101,11 +107,11 @@ describe(':source', function() eq("{'k': 'v'}", exec_capture('echo b')) -- Script items are created only on script var access - eq("1", exec_capture('echo c')) - eq("0zBEEFCAFE", exec_capture('echo d')) + eq('1', exec_capture('echo c')) + eq('0zBEEFCAFE', exec_capture('echo d')) exec('set cpoptions+=C') - eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec('source')) + eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec('source')) end) it('selection in current buffer', function() @@ -132,14 +138,14 @@ describe(':source', function() feed_command(':source') eq('4', exec_capture('echo a')) eq("{'K': 'V'}", exec_capture('echo b')) - eq("<SNR>1_C()", exec_capture('echo D()')) + eq('<SNR>1_C()', exec_capture('echo D()')) -- Source last line only feed_command(':$source') eq('Vim(echo):E117: Unknown function: s:C', exc_exec('echo D()')) exec('set cpoptions+=C') - eq('Vim(let):E723: Missing end of Dictionary \'}\': ', exc_exec("'<,'>source")) + eq("Vim(let):E723: Missing end of Dictionary '}': ", exc_exec("'<,'>source")) end) it('does not break if current buffer is modified while sourced', function() @@ -163,19 +169,22 @@ describe(':source', function() it('can source lua files', function() local test_file = 'test.lua' - write_file(test_file, [[ + write_file( + test_file, + [[ vim.g.sourced_lua = 1 vim.g.sfile_value = vim.fn.expand('<sfile>') vim.g.stack_value = vim.fn.expand('<stack>') vim.g.script_value = vim.fn.expand('<script>') - ]]) + ]] + ) command('set shellslash') command('source ' .. test_file) eq(1, eval('g:sourced_lua')) - matches([[/test%.lua$]], meths.get_var('sfile_value')) - matches([[/test%.lua$]], meths.get_var('stack_value')) - matches([[/test%.lua$]], meths.get_var('script_value')) + matches([[/test%.lua$]], api.nvim_get_var('sfile_value')) + matches([[/test%.lua$]], api.nvim_get_var('stack_value')) + matches([[/test%.lua$]], api.nvim_get_var('script_value')) os.remove(test_file) end) @@ -220,9 +229,9 @@ describe(':source', function() eq(12, eval('g:c')) eq(' \\ 1\n "\\ 2', exec_lua('return _G.a')) - eq(':source (no file)', meths.get_var('sfile_value')) - eq(':source (no file)', meths.get_var('stack_value')) - eq(':source (no file)', meths.get_var('script_value')) + eq(':source (no file)', api.nvim_get_var('sfile_value')) + eq(':source (no file)', api.nvim_get_var('stack_value')) + eq(':source (no file)', api.nvim_get_var('script_value')) end) end @@ -245,22 +254,22 @@ describe(':source', function() local test_file = 'test.lua' -- Does throw E484 for unreadable files - local ok, result = pcall(exec_capture, ":source "..test_file ..'noexisting') + local ok, result = pcall(exec_capture, ':source ' .. test_file .. 'noexisting') eq(false, ok) - neq(nil, result:find("E484")) + neq(nil, result:find('E484')) -- Doesn't throw for parsing error - write_file (test_file, "vim.g.c = ") - ok, result = pcall(exec_capture, ":source "..test_file) + write_file(test_file, 'vim.g.c = ') + ok, result = pcall(exec_capture, ':source ' .. test_file) eq(false, ok) - eq(nil, result:find("E484")) + eq(nil, result:find('E484')) os.remove(test_file) -- Doesn't throw for runtime error - write_file (test_file, "error('Cause error anyway :D')") - ok, result = pcall(exec_capture, ":source "..test_file) + write_file(test_file, "error('Cause error anyway :D')") + ok, result = pcall(exec_capture, ':source ' .. test_file) eq(false, ok) - eq(nil, result:find("E484")) + eq(nil, result:find('E484')) os.remove(test_file) end) end) diff --git a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua index 436873b464..a6fdb919c5 100644 --- a/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua +++ b/test/functional/ex_cmds/swapfile_preserve_recover_spec.lua @@ -1,19 +1,18 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') -local eq, eval, expect, exec = - helpers.eq, helpers.eval, helpers.expect, helpers.exec +local uv = vim.uv +local eq, eval, expect, exec = helpers.eq, helpers.eval, helpers.expect, helpers.exec local assert_alive = helpers.assert_alive local clear = helpers.clear local command = helpers.command local feed = helpers.feed -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local ok = helpers.ok local rmdir = helpers.rmdir local new_argv = helpers.new_argv local new_pipename = helpers.new_pipename -local pesc = helpers.pesc +local pesc = vim.pesc local os_kill = helpers.os_kill local set_session = helpers.set_session local spawn = helpers.spawn @@ -22,7 +21,7 @@ local expect_msg_seq = helpers.expect_msg_seq local pcall_err = helpers.pcall_err local mkdir = helpers.mkdir local poke_eventloop = helpers.poke_eventloop -local meths = helpers.meths +local api = helpers.api local retry = helpers.retry local write_file = helpers.write_file @@ -32,24 +31,24 @@ describe(':recover', function() it('fails if given a non-existent swapfile', function() local swapname = 'bogus_swapfile' local swapname2 = 'bogus_swapfile.swp' - eq('Vim(recover):E305: No swap file found for '..swapname, - pcall_err(command, 'recover '..swapname)) -- Should not segfault. #2117 + eq( + 'Vim(recover):E305: No swap file found for ' .. swapname, + pcall_err(command, 'recover ' .. swapname) + ) -- Should not segfault. #2117 -- Also check filename ending with ".swp". #9504 - eq('Vim(recover):E306: Cannot open '..swapname2, - pcall_err(command, 'recover '..swapname2)) -- Should not segfault. #2117 + eq('Vim(recover):E306: Cannot open ' .. swapname2, pcall_err(command, 'recover ' .. swapname2)) -- Should not segfault. #2117 assert_alive() end) - end) describe("preserve and (R)ecover with custom 'directory'", function() - local swapdir = luv.cwd()..'/Xtest_recover_dir' + local swapdir = uv.cwd() .. '/Xtest_recover_dir' local testfile = 'Xtest_recover_file1' -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. local init = [[ - set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// + set directory^=]] .. swapdir:gsub([[\]], [[\\]]) .. [[// set swapfile fileformat=unix undolevels=-1 ]] @@ -67,7 +66,7 @@ describe("preserve and (R)ecover with custom 'directory'", function() local function setup_swapname() exec(init) - command('edit! '..testfile) + command('edit! ' .. testfile) feed('isometext<esc>') exec('redir => g:swapname | silent swapname | redir END') return eval('g:swapname') @@ -75,23 +74,23 @@ describe("preserve and (R)ecover with custom 'directory'", function() local function test_recover(swappath1) -- Start another Nvim instance. - local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true) + local nvim2 = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed' }, true) set_session(nvim2) exec(init) -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. command('autocmd SwapExists * let v:swapchoice = "r"') - command('silent edit! '..testfile) + command('silent edit! ' .. testfile) exec('redir => g:swapname | silent swapname | redir END') local swappath2 = eval('g:swapname') expect('sometext') -- swapfile from session 1 should end in .swp - eq(testfile..'.swp', string.match(swappath1, '[^%%]+$')) + eq(testfile .. '.swp', string.match(swappath1, '[^%%]+$')) -- swapfile from session 2 should end in .swo - eq(testfile..'.swo', string.match(swappath2, '[^%%]+$')) + eq(testfile .. '.swo', string.match(swappath2, '[^%%]+$')) -- Verify that :swapname was not truncated (:help 'shortmess'). ok(nil == string.find(swappath1, '%.%.%.')) ok(nil == string.find(swappath2, '%.%.%.')) @@ -115,27 +114,28 @@ describe("preserve and (R)ecover with custom 'directory'", function() local screen0 = Screen.new() screen0:attach() local child_server = new_pipename() - funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server}) - screen0:expect({any = pesc('[No Name]')}) -- Wait for the child process to start. + fn.termopen({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--listen', child_server }, { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, + }) + screen0:expect({ any = pesc('[No Name]') }) -- Wait for the child process to start. local child_session = helpers.connect(child_server) set_session(child_session) local swappath1 = setup_swapname() set_session(nvim0) - command('call chanclose(&channel)') -- Kill the child process. - screen0:expect({any = pesc('[Process exited 1]')}) -- Wait for the child process to stop. + command('call chanclose(&channel)') -- Kill the child process. + screen0:expect({ any = pesc('[Process exited 1]') }) -- Wait for the child process to stop. test_recover(swappath1) end) - end) describe('swapfile detection', function() - local swapdir = luv.cwd()..'/Xtest_swapdialog_dir' + local swapdir = uv.cwd() .. '/Xtest_swapdialog_dir' local nvim0 -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. local init = [[ - set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// + set directory^=]] .. swapdir:gsub([[\]], [[\\]]) .. [[// set swapfile fileformat=unix nomodified undolevels=-1 nohidden ]] before_each(function() @@ -153,67 +153,88 @@ describe('swapfile detection', function() it('always show swapfile dialog #8840 #9027', function() local testfile = 'Xtest_swapdialog_file1' - local expected_no_dialog = '^'..(' '):rep(256)..'|\n' - for _=1,37 do - expected_no_dialog = expected_no_dialog..'~'..(' '):rep(255)..'|\n' + local expected_no_dialog = '^' .. (' '):rep(256) .. '|\n' + for _ = 1, 37 do + expected_no_dialog = expected_no_dialog .. '~' .. (' '):rep(255) .. '|\n' end - expected_no_dialog = expected_no_dialog..testfile..(' '):rep(216)..'0,0-1 All|\n' - expected_no_dialog = expected_no_dialog..(' '):rep(256)..'|\n' + expected_no_dialog = expected_no_dialog .. testfile .. (' '):rep(216) .. '0,0-1 All|\n' + expected_no_dialog = expected_no_dialog .. (' '):rep(256) .. '|\n' exec(init) - command('edit! '..testfile) + command('edit! ' .. testfile) feed('isometext<esc>') command('preserve') -- Start another Nvim instance. - local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'}, true, nil, true) + local nvim2 = spawn({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed' }, true, nil, true) set_session(nvim2) local screen2 = Screen.new(256, 40) screen2:attach() exec(init) - command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). -- With shortmess+=F command('set shortmess+=F') - feed(':edit '..testfile..'<CR>') - screen2:expect{any=[[E325: ATTENTION.*]]..'\n'..[[Found a swap file by the name ".*]] - ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} - feed('e') -- Chose "Edit" at the swap dialog. + feed(':edit ' .. testfile .. '<CR>') + screen2:expect { + any = [[E325: ATTENTION.*]] + .. '\n' + .. [[Found a swap file by the name ".*]] + .. [[Xtest_swapdialog_dir[/\].*]] + .. testfile + .. [[%.swp"]], + } + feed('e') -- Chose "Edit" at the swap dialog. screen2:expect(expected_no_dialog) -- With :silent and shortmess+=F feed(':silent edit %<CR>') - screen2:expect{any=[[Found a swap file by the name ".*]] - ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} - feed('e') -- Chose "Edit" at the swap dialog. + screen2:expect { + any = [[Found a swap file by the name ".*]] + .. [[Xtest_swapdialog_dir[/\].*]] + .. testfile + .. [[%.swp"]], + } + feed('e') -- Chose "Edit" at the swap dialog. screen2:expect(expected_no_dialog) -- With :silent! and shortmess+=F feed(':silent! edit %<CR>') - screen2:expect{any=[[Found a swap file by the name ".*]] - ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} - feed('e') -- Chose "Edit" at the swap dialog. + screen2:expect { + any = [[Found a swap file by the name ".*]] + .. [[Xtest_swapdialog_dir[/\].*]] + .. testfile + .. [[%.swp"]], + } + feed('e') -- Chose "Edit" at the swap dialog. screen2:expect(expected_no_dialog) -- With API (via eval/Vimscript) call and shortmess+=F feed(':call nvim_command("edit %")<CR>') - screen2:expect{any=[[Found a swap file by the name ".*]] - ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} - feed('e') -- Chose "Edit" at the swap dialog. + screen2:expect { + any = [[Found a swap file by the name ".*]] + .. [[Xtest_swapdialog_dir[/\].*]] + .. testfile + .. [[%.swp"]], + } + feed('e') -- Chose "Edit" at the swap dialog. feed('<c-c>') screen2:expect(expected_no_dialog) -- With API call and shortmess+=F - async_meths.command('edit %') - screen2:expect{any=[[Found a swap file by the name ".*]] - ..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]} - feed('e') -- Chose "Edit" at the swap dialog. + async_meths.nvim_command('edit %') + screen2:expect { + any = [[Found a swap file by the name ".*]] + .. [[Xtest_swapdialog_dir[/\].*]] + .. testfile + .. [[%.swp"]], + } + feed('e') -- Chose "Edit" at the swap dialog. expect_msg_seq({ - ignore={'redraw'}, - seqs={ - { {'notification', 'nvim_error_event', {0, 'Vim(edit):E325: ATTENTION'}}, - } - } + ignore = { 'redraw' }, + seqs = { + { { 'notification', 'nvim_error_event', { 0, 'Vim(edit):E325: ATTENTION' } } }, + }, }) feed('<cr>') @@ -224,8 +245,8 @@ describe('swapfile detection', function() exec(init) command('edit Xfile1') command("put ='some text...'") - command('preserve') -- Make sure the swap file exists. - local nvimpid = funcs.getpid() + command('preserve') -- Make sure the swap file exists. + local nvimpid = fn.getpid() local nvim1 = spawn(new_argv(), true, nil, true) set_session(nvim1) @@ -242,44 +263,29 @@ describe('swapfile detection', function() it('selecting "q" in the attention prompt', function() exec(init) command('edit Xfile1') - command('preserve') -- Make sure the swap file exists. + command('preserve') -- Make sure the swap file exists. local screen = Screen.new(75, 18) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg }) local nvim1 = spawn(new_argv(), true, nil, true) set_session(nvim1) screen:attach() exec(init) - command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). feed(':split Xfile1\n') -- The default SwapExists handler does _not_ skip this prompt. screen:expect({ - any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^') + any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), }) feed('q') feed(':<CR>') screen:expect([[ ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*16 : | ]]) nvim1:close() @@ -288,35 +294,20 @@ describe('swapfile detection', function() set_session(nvim2) screen:attach() exec(init) - command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). command('set more') command('au bufadd * let foo_w = wincol()') feed(':e Xfile1<CR>') - screen:expect({any = pesc('{1:-- More --}^')}) + screen:expect({ any = pesc('{1:-- More --}^') }) feed('<Space>') screen:expect({ - any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^') + any = pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), }) feed('q') command([[echo 'hello']]) screen:expect([[ ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*16 hello | ]]) nvim2:close() @@ -327,15 +318,15 @@ describe('swapfile detection', function() local function test_swapfile_after_reboot(swapexists, on_swapfile_running) local screen = Screen.new(75, 30) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg - [2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg + [2] = { background = Screen.colors.Red, foreground = Screen.colors.White }, -- ErrorMsg }) screen:attach() exec(init) if not swapexists then - command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). + command('autocmd! nvim_swapfile') -- Delete the default handler (which skips the dialog). end command('set nohidden') @@ -361,7 +352,7 @@ describe('swapfile detection', function() edit Xswaptest call setline(1, ['a', 'b', 'c']) ]]) - local swname = funcs.CopySwapfile() + local swname = fn.CopySwapfile() -- Forget we edited this file exec([[ @@ -385,14 +376,16 @@ describe('swapfile detection', function() ]]) -- pretend that the swapfile was created before boot - local atime = os.time() - luv.uptime() - 10 - luv.fs_utime(swname, atime, atime) + local atime = os.time() - uv.uptime() - 10 + uv.fs_utime(swname, atime, atime) feed(':edit Xswaptest<CR>') - screen:expect({any = table.concat({ - pesc('{2:E325: ATTENTION}'), - pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: }^'), - }, '.*')}) + screen:expect({ + any = table.concat({ + pesc('{2:E325: ATTENTION}'), + pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: }^'), + }, '.*'), + }) feed('e') end @@ -400,12 +393,14 @@ describe('swapfile detection', function() -- oldtest: Test_nocatch_process_still_running() it('swapfile created before boot vim-patch:8.2.2586', function() test_swapfile_after_reboot(false, function(screen) - screen:expect({any = table.concat({ - pesc('{2:E325: ATTENTION}'), - 'file name: .*Xswaptest', - 'process ID: %d* %(STILL RUNNING%)', - pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), - }, '.*')}) + screen:expect({ + any = table.concat({ + pesc('{2:E325: ATTENTION}'), + 'file name: .*Xswaptest', + 'process ID: %d* %(STILL RUNNING%)', + pesc('{1:[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: }^'), + }, '.*'), + }) end) end) @@ -414,34 +409,36 @@ describe('swapfile detection', function() screen:expect({ any = 'W325: Ignoring swapfile from Nvim process' }) end) end) - end) describe('quitting swapfile dialog on startup stops TUI properly', function() - local swapdir = luv.cwd()..'/Xtest_swapquit_dir' + local swapdir = uv.cwd() .. '/Xtest_swapquit_dir' local testfile = 'Xtest_swapquit_file1' local otherfile = 'Xtest_swapquit_file2' -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. - local init_dir = [[set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//]] + local init_dir = [[set directory^=]] .. swapdir:gsub([[\]], [[\\]]) .. [[//]] local init_set = [[set swapfile fileformat=unix nomodified undolevels=-1 nohidden]] before_each(function() - clear({args = {'--cmd', init_dir, '--cmd', init_set}}) + clear({ args = { '--cmd', init_dir, '--cmd', init_set } }) rmdir(swapdir) mkdir(swapdir) - write_file(testfile, [[ + write_file( + testfile, + [[ first second third - ]]) - command('edit! '..testfile) + ]] + ) + command('edit! ' .. testfile) feed('Gisometext<esc>') poke_eventloop() - clear() -- Leaves a swap file behind - meths.ui_attach(80, 30, {}) + clear() -- Leaves a swap file behind + api.nvim_ui_attach(80, 30, {}) end) after_each(function() rmdir(swapdir) @@ -450,57 +447,100 @@ describe('quitting swapfile dialog on startup stops TUI properly', function() end) it('(Q)uit at first file argument', function() - local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', - '--cmd', init_dir, '--cmd', init_set, - testfile}) + local chan = fn.termopen( + { nvim_prog, '-u', 'NONE', '-i', 'NONE', '--cmd', init_dir, '--cmd', init_set, testfile }, + { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, + } + ) retry(nil, nil, function() - eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', - eval("getline('$')->trim(' ', 2)")) + eq( + '[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)") + ) end) - meths.chan_send(chan, 'q') + api.nvim_chan_send(chan, 'q') retry(nil, nil, function() - eq({'', '[Process exited 1]', ''}, - eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + eq( + { '', '[Process exited 1]', '' }, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})") + ) end) end) it('(A)bort at second file argument with -p', function() - local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', - '--cmd', init_dir, '--cmd', init_set, - '-p', otherfile, testfile}) + local chan = fn.termopen({ + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + init_dir, + '--cmd', + init_set, + '-p', + otherfile, + testfile, + }, { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, + }) retry(nil, nil, function() - eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', - eval("getline('$')->trim(' ', 2)")) + eq( + '[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)") + ) end) - meths.chan_send(chan, 'a') + api.nvim_chan_send(chan, 'a') retry(nil, nil, function() - eq({'', '[Process exited 1]', ''}, - eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + eq( + { '', '[Process exited 1]', '' }, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})") + ) end) end) it('(Q)uit at file opened by -t', function() - write_file(otherfile, ([[ + write_file( + otherfile, + ([[ !_TAG_FILE_ENCODING utf-8 // first %s /^ \zsfirst$/ second %s /^ \zssecond$/ - third %s /^ \zsthird$/]]):format(testfile, testfile, testfile)) - local chan = funcs.termopen({nvim_prog, '-u', 'NONE', '-i', 'NONE', - '--cmd', init_dir, '--cmd', init_set, - '--cmd', 'set tags='..otherfile, '-tsecond'}) + third %s /^ \zsthird$/]]):format(testfile, testfile, testfile) + ) + local chan = fn.termopen({ + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + init_dir, + '--cmd', + init_set, + '--cmd', + 'set tags=' .. otherfile, + '-tsecond', + }, { + env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, + }) retry(nil, nil, function() - eq('[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', - eval("getline('$')->trim(' ', 2)")) + eq( + '[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:', + eval("getline('$')->trim(' ', 2)") + ) end) - meths.chan_send(chan, 'q') + api.nvim_chan_send(chan, 'q') retry(nil, nil, function() - eq('Press ENTER or type command to continue', - eval("getline('$')->trim(' ', 2)")) + eq('Press ENTER or type command to continue', eval("getline('$')->trim(' ', 2)")) end) - meths.chan_send(chan, '\r') + api.nvim_chan_send(chan, '\r') retry(nil, nil, function() - eq({'', '[Process exited 1]', ''}, - eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})")) + eq( + { '', '[Process exited 1]', '' }, + eval("[1, 2, '$']->map({_, lnum -> getline(lnum)->trim(' ', 2)})") + ) end) end) end) diff --git a/test/functional/ex_cmds/syntax_spec.lua b/test/functional/ex_cmds/syntax_spec.lua index c9e96703de..ccdd604c55 100644 --- a/test/functional/ex_cmds/syntax_spec.lua +++ b/test/functional/ex_cmds/syntax_spec.lua @@ -8,10 +8,11 @@ describe(':syntax', function() before_each(clear) describe('keyword', function() - it('does not crash when group name contains unprintable characters', - function() - eq('Vim(syntax):E669: Unprintable character in group name', - exc_exec('syntax keyword \024 foo bar')) + it('does not crash when group name contains unprintable characters', function() + eq( + 'Vim(syntax):E669: Unprintable character in group name', + exc_exec('syntax keyword \024 foo bar') + ) end) end) end) diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua index fe13bd7cd2..2997b504fa 100644 --- a/test/functional/ex_cmds/trust_spec.lua +++ b/test/functional/ex_cmds/trust_spec.lua @@ -7,7 +7,7 @@ local exec_capture = helpers.exec_capture local matches = helpers.matches local pathsep = helpers.get_pathsep() local is_os = helpers.is_os -local funcs = helpers.funcs +local fn = helpers.fn describe(':trust', function() local xstate = 'Xstate' @@ -22,7 +22,7 @@ describe(':trust', function() before_each(function() helpers.write_file('test_file', 'test') - clear{env={XDG_STATE_HOME=xstate}} + clear { env = { XDG_STATE_HOME = xstate } } end) after_each(function() @@ -30,50 +30,53 @@ describe(':trust', function() end) it('trust then deny then remove a file using current buffer', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) command('edit test_file') matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then trust then remove a file using current buffer', function() - local cwd = funcs.getcwd() - local hash = funcs.sha256(helpers.read_file('test_file')) + local cwd = fn.getcwd() + local hash = fn.sha256(helpers.read_file('test_file')) command('edit test_file') matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust)) matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) it('deny then remove a file using file path', function() - local cwd = funcs.getcwd() + local cwd = fn.getcwd() matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file')) - local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + local trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust)) - matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove test_file')) - trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust') + matches( + '^Removed ".*test_file" from trust database%.$', + exec_capture('trust ++remove test_file') + ) + trust = helpers.read_file(fn.stdpath('state') .. pathsep .. 'trust') eq(string.format(''), vim.trim(trust)) end) end) diff --git a/test/functional/ex_cmds/verbose_spec.lua b/test/functional/ex_cmds/verbose_spec.lua index 50077e9e0c..7ceb2460d3 100644 --- a/test/functional/ex_cmds/verbose_spec.lua +++ b/test/functional/ex_cmds/verbose_spec.lua @@ -5,19 +5,21 @@ local eq = helpers.eq local exec = helpers.exec local exec_capture = helpers.exec_capture local write_file = helpers.write_file -local call_viml_function = helpers.meths.call_function +local call_viml_function = helpers.api.nvim_call_function local function last_set_tests(cmd) local script_location, script_file -- All test cases below use the same nvim instance. setup(function() - clear{args={'-V1'}} + clear { args = { '-V1' } } script_file = 'test_verbose.lua' local current_dir = call_viml_function('getcwd', {}) - current_dir = call_viml_function('fnamemodify', {current_dir, ':~'}) - script_location = table.concat{current_dir, helpers.get_pathsep(), script_file} + current_dir = call_viml_function('fnamemodify', { current_dir, ':~' }) + script_location = table.concat { current_dir, helpers.get_pathsep(), script_file } - write_file(script_file, [[ + write_file( + script_file, + [[ vim.api.nvim_set_option_value('hlsearch', false, {}) vim.bo.expandtab = true vim.opt.number = true @@ -45,7 +47,8 @@ function! s:return80()\ endfunction\ let &tw = s:return80()\ ", true) -]]) +]] + ) exec(cmd .. ' ' .. script_file) end) @@ -55,54 +58,84 @@ let &tw = s:return80()\ it('"Last set" for option set by Lua', function() local result = exec_capture(':verbose set hlsearch?') - eq(string.format([[ + eq( + string.format( + [[ nohlsearch Last set from %s line 1]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for option set by vim.o', function() local result = exec_capture(':verbose set expandtab?') - eq(string.format([[ + eq( + string.format( + [[ expandtab Last set from %s line 2]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for option set by vim.opt', function() local result = exec_capture(':verbose set number?') - eq(string.format([[ + eq( + string.format( + [[ number Last set from %s line 3]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for mapping set by Lua', function() local result = exec_capture(':verbose map <leader>key1') - eq(string.format([[ + eq( + string.format( + [[ n \key1 * :echo "test"<CR> Last set from %s line 4]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for mapping set by vim.keymap', function() local result = exec_capture(':verbose map <leader>key2') - eq(string.format([[ + eq( + string.format( + [[ n \key2 * :echo "test"<CR> Last set from %s line 5]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for autocmd by vim.api.nvim_exec', function() local result = exec_capture(':verbose autocmd test_group Filetype c') - eq(string.format([[ + eq( + string.format( + [[ --- Autocommands --- test_group FileType c setl cindent Last set from %s line 7]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for command defined by nvim_command', function() @@ -110,38 +143,58 @@ test_group FileType pending('nvim_command does not set the script context') end local result = exec_capture(':verbose command Bdelete') - eq(string.format([[ + eq( + string.format( + [[ Name Args Address Complete Definition Bdelete 0 :bd Last set from %s line 13]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for command defined by nvim_create_user_command', function() local result = exec_capture(':verbose command TestCommand') - eq(string.format([[ + eq( + string.format( + [[ Name Args Address Complete Definition TestCommand 0 :echo 'Hello' Last set from %s line 14]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" for function', function() local result = exec_capture(':verbose function Close_Window') - eq(string.format([[ + eq( + string.format( + [[ function Close_Window() abort Last set from %s line 16 1 wincmd - endfunction]], - script_location), result) + script_location + ), + result + ) end) it('"Last set" works with anonymous sid', function() local result = exec_capture(':verbose set tw?') - eq(string.format([[ + eq( + string.format( + [[ textwidth=80 Last set from %s line 22]], - script_location), result) + script_location + ), + result + ) end) end @@ -159,10 +212,13 @@ describe('lua verbose:', function() setup(function() clear() script_file = 'test_luafile.lua' - write_file(script_file, [[ + write_file( + script_file, + [[ vim.api.nvim_set_option_value('hlsearch', false, {}) - ]]) - exec(':source '..script_file) + ]] + ) + exec(':source ' .. script_file) end) teardown(function() @@ -171,9 +227,11 @@ describe('lua verbose:', function() it('is disabled when verbose = 0', function() local result = exec_capture(':verbose set hlsearch?') - eq([[ + eq( + [[ nohlsearch - Last set from Lua]], result) + Last set from Lua]], + result + ) end) end) - diff --git a/test/functional/ex_cmds/wincmd_spec.lua b/test/functional/ex_cmds/wincmd_spec.lua index b1f174f445..98c6358f45 100644 --- a/test/functional/ex_cmds/wincmd_spec.lua +++ b/test/functional/ex_cmds/wincmd_spec.lua @@ -1,13 +1,13 @@ -local helpers = require("test.functional.helpers")(after_each) +local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command it(':wincmd accepts a count', function() clear() command('vsplit') - eq(1, funcs.winnr()) + eq(1, fn.winnr()) command('wincmd 2 w') - eq(2, funcs.winnr()) + eq(2, fn.winnr()) end) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 0b8ce93b09..f711731072 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,13 +1,11 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local eq, eval, clear, write_file, source, insert = - helpers.eq, helpers.eval, helpers.clear, helpers.write_file, - helpers.source, helpers.insert + helpers.eq, helpers.eval, helpers.clear, helpers.write_file, helpers.source, helpers.insert local pcall_err = helpers.pcall_err local command = helpers.command local feed_command = helpers.feed_command -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local skip = helpers.skip local is_os = helpers.is_os local is_ci = helpers.is_ci @@ -40,9 +38,9 @@ describe(':write', function() command('set backupcopy=auto') write_file('test_bkc_file.txt', 'content0') if is_os('win') then - command("silent !mklink test_bkc_link.txt test_bkc_file.txt") + command('silent !mklink test_bkc_link.txt test_bkc_file.txt') else - command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") + command('silent !ln -s test_bkc_file.txt test_bkc_link.txt') end if eval('v:shell_error') ~= 0 then pending('Cannot create symlink') @@ -61,9 +59,9 @@ describe(':write', function() command('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') if is_os('win') then - command("silent !mklink test_bkc_link.txt test_bkc_file.txt") + command('silent !mklink test_bkc_link.txt test_bkc_file.txt') else - command("silent !ln -s test_bkc_file.txt test_bkc_link.txt") + command('silent !ln -s test_bkc_file.txt test_bkc_link.txt') end if eval('v:shell_error') ~= 0 then pending('Cannot create symlink') @@ -77,73 +75,80 @@ describe(':write', function() eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')")) end) - it("appends FIFO file", function() + it('appends FIFO file', function() -- mkfifo creates read-only .lnk files on Windows if is_os('win') or eval("executable('mkfifo')") == 0 then pending('missing "mkfifo" command') end - local text = "some fifo text from write_spec" - assert(os.execute("mkfifo test_fifo")) + local text = 'some fifo text from write_spec' + assert(os.execute('mkfifo test_fifo')) insert(text) -- Blocks until a consumer reads the FIFO. - feed_command("write >> test_fifo") + feed_command('write >> test_fifo') -- Read the FIFO, this will unblock the :write above. - local fifo = assert(io.open("test_fifo")) - eq(text.."\n", fifo:read("*all")) + local fifo = assert(io.open('test_fifo')) + eq(text .. '\n', fifo:read('*all')) fifo:close() end) - it("++p creates missing parent directories", function() + it('++p creates missing parent directories', function() eq(0, eval("filereadable('p_opt.txt')")) - command("write ++p p_opt.txt") + command('write ++p p_opt.txt') eq(1, eval("filereadable('p_opt.txt')")) - os.remove("p_opt.txt") + os.remove('p_opt.txt') eq(0, eval("filereadable('p_opt.txt')")) - command("write ++p ./p_opt.txt") + command('write ++p ./p_opt.txt') eq(1, eval("filereadable('p_opt.txt')")) - os.remove("p_opt.txt") + os.remove('p_opt.txt') eq(0, eval("filereadable('test/write/p_opt.txt')")) - command("write ++p test/write/p_opt.txt") + command('write ++p test/write/p_opt.txt') eq(1, eval("filereadable('test/write/p_opt.txt')")) - eq(('Vim(write):E32: No file name'), pcall_err(command, 'write ++p test_write/')) + eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p test_write/')) if not is_os('win') then - eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), - pcall_err(command, 'write ++p .')) - eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), - pcall_err(command, 'write ++p ./')) + eq( + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), + pcall_err(command, 'write ++p .') + ) + eq( + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), + pcall_err(command, 'write ++p ./') + ) end end) it('errors out correctly', function() skip(is_ci('cirrus')) command('let $HOME=""') - eq(funcs.fnamemodify('.', ':p:h'), funcs.fnamemodify('.', ':p:h:~')) + eq(fn.fnamemodify('.', ':p:h'), fn.fnamemodify('.', ':p:h:~')) -- Message from check_overwrite if not is_os('win') then - eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), - pcall_err(command, 'write .')) + eq( + ('Vim(write):E17: "' .. fn.fnamemodify('.', ':p:h') .. '" is a directory'), + pcall_err(command, 'write .') + ) end - meths.set_option_value('writeany', true, {}) + api.nvim_set_option_value('writeany', true, {}) -- Message from buf_write - eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .')) - funcs.mkdir(fname_bak) - meths.set_option_value('backupdir', '.', {}) - meths.set_option_value('backup', true, {}) + eq('Vim(write):E502: "." is a directory', pcall_err(command, 'write .')) + fn.mkdir(fname_bak) + api.nvim_set_option_value('backupdir', '.', {}) + api.nvim_set_option_value('backup', true, {}) write_file(fname, 'content0') command('edit ' .. fname) - funcs.setline(1, 'TTY') - eq('Vim(write):E510: Can\'t make backup file (add ! to override)', - pcall_err(command, 'write')) - meths.set_option_value('backup', false, {}) - funcs.setfperm(fname, 'r--------') - eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', - pcall_err(command, 'write')) + fn.setline(1, 'TTY') + eq("Vim(write):E510: Can't make backup file (add ! to override)", pcall_err(command, 'write')) + api.nvim_set_option_value('backup', false, {}) + fn.setfperm(fname, 'r--------') + eq( + 'Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', + pcall_err(command, 'write') + ) if is_os('win') then eq(0, os.execute('del /q/f ' .. fname)) eq(0, os.execute('rd /q/s ' .. fname_bak)) @@ -153,8 +158,7 @@ describe(':write', function() end write_file(fname_bak, 'TTYX') skip(is_os('win'), [[FIXME: exc_exec('write!') outputs 0 in Windows]]) - luv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) - eq('Vim(write):E166: Can\'t open linked file for writing', - pcall_err(command, 'write!')) + vim.uv.fs_symlink(fname_bak .. ('/xxxxx'):rep(20), fname) + eq("Vim(write):E166: Can't open linked file for writing", pcall_err(command, 'write!')) end) end) diff --git a/test/functional/ex_cmds/wundo_spec.lua b/test/functional/ex_cmds/wundo_spec.lua index b6fcae0cf4..78081fa45f 100644 --- a/test/functional/ex_cmds/wundo_spec.lua +++ b/test/functional/ex_cmds/wundo_spec.lua @@ -2,9 +2,12 @@ local helpers = require('test.functional.helpers')(after_each) local command, clear, eval, spawn, nvim_prog, set_session = - helpers.command, helpers.clear, helpers.eval, helpers.spawn, - helpers.nvim_prog, helpers.set_session - + helpers.command, + helpers.clear, + helpers.eval, + helpers.spawn, + helpers.nvim_prog, + helpers.set_session describe(':wundo', function() before_each(clear) @@ -21,10 +24,18 @@ end) describe('u_* functions', function() it('safely fail on new, non-empty buffer', function() - local session = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', - '-c', 'set undodir=. undofile'}) + local session = spawn({ + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--embed', + '-c', + 'set undodir=. undofile', + }) set_session(session) - command('echo "True"') -- Should not error out due to crashed Neovim + command('echo "True"') -- Should not error out due to crashed Neovim session:close() end) end) diff --git a/test/functional/ex_cmds/wviminfo_spec.lua b/test/functional/ex_cmds/wviminfo_spec.lua index 7525343891..23ae1440e6 100644 --- a/test/functional/ex_cmds/wviminfo_spec.lua +++ b/test/functional/ex_cmds/wviminfo_spec.lua @@ -1,8 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local luv = require('luv') local clear = helpers.clear -local command, eq, neq, write_file = - helpers.command, helpers.eq, helpers.neq, helpers.write_file +local command, eq, neq, write_file = helpers.command, helpers.eq, helpers.neq, helpers.write_file local read_file = helpers.read_file local is_os = helpers.is_os @@ -10,21 +8,27 @@ describe(':wshada', function() local shada_file = 'wshada_test' before_each(function() - clear{args={'-i', is_os('win') and 'nul' or '/dev/null', - -- Need 'swapfile' for these tests. - '--cmd', 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler'}, - args_rm={'-n', '-i', '--cmd'}} + clear { + args = { + '-i', + is_os('win') and 'nul' or '/dev/null', + -- Need 'swapfile' for these tests. + '--cmd', + 'set swapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler', + }, + args_rm = { '-n', '-i', '--cmd' }, + } end) - after_each(function () + after_each(function() os.remove(shada_file) end) it('creates a shada file', function() -- file should _not_ exist - eq(nil, luv.fs_stat(shada_file)) - command('wsh! '..shada_file) + eq(nil, vim.uv.fs_stat(shada_file)) + command('wsh! ' .. shada_file) -- file _should_ exist - neq(nil, luv.fs_stat(shada_file)) + neq(nil, vim.uv.fs_stat(shada_file)) end) it('overwrites existing files', function() @@ -35,16 +39,15 @@ describe(':wshada', function() -- sanity check eq(text, read_file(shada_file)) - neq(nil, luv.fs_stat(shada_file)) + neq(nil, vim.uv.fs_stat(shada_file)) - command('wsh! '..shada_file) + command('wsh! ' .. shada_file) -- File should have been overwritten with a shada file. local fp = io.open(shada_file, 'r') local char1 = fp:read(1) fp:close() -- ShaDa file starts with a “header” entry - assert(char1:byte() == 0x01, - shada_file..' should be a shada file') + assert(char1:byte() == 0x01, shada_file .. ' should be a shada file') end) end) |