diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 64b28e7bf7..10e4a45254 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -1171,8 +1171,6 @@ describe('autocmd api', function() describe('nvim_create_augroup', function() before_each(function() - clear() - api.nvim_set_var('executed', 0) end) diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua index 489f601d31..db45d5b1dc 100644 --- a/test/functional/api/buffer_updates_spec.lua +++ b/test/functional/api/buffer_updates_spec.lua @@ -57,7 +57,6 @@ local function editoriginal(activate, lines) lines = origlines end -- load up the file with the correct contents - clear() return open(activate, lines) end @@ -507,8 +506,6 @@ describe('API: buffer events:', function() end) it('can notify several channels at once', function() - clear() - -- create several new sessions, in addition to our main API local sessions = {} local pipe = n.new_pipename() @@ -781,8 +778,6 @@ describe('API: buffer events:', function() end) it('detaches if the buffer is unloaded/deleted/wiped', function() - -- start with a blank nvim - clear() -- need to make a new window with a buffer because :bunload doesn't let you -- unload the last buffer for _, cmd in ipairs({ 'bunload', 'bdelete', 'bwipeout' }) do @@ -798,20 +793,17 @@ describe('API: buffer events:', function() end) it('does not send the buffer content if not requested', function() - clear() local b, tick = editoriginal(false) ok(api.nvim_buf_attach(b, false, {})) expectn('nvim_buf_changedtick_event', { b, tick }) end) it('returns a proper error on nonempty options dict', function() - clear() local b = editoriginal(false) eq("Invalid key: 'builtin'", pcall_err(api.nvim_buf_attach, b, false, { builtin = 'asfd' })) end) it('nvim_buf_attach returns response after delay #8634', function() - clear() sleep(250) -- response eq(true, n.request('nvim_buf_attach', 0, false, {})) diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 68c4ef7503..01bd08f31c 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -48,8 +48,6 @@ describe("api_info()['version']", function() end) describe('api metadata', function() - before_each(clear) - local function name_table(entries) local by_name = {} for _, e in ipairs(entries) do @@ -131,6 +129,8 @@ describe('api metadata', function() clean_level_0(old_api[level]) end end + -- No Nvim session will be used in the following tests. + n.check_close() end) it('functions are compatible with old metadata or have new level', function() diff --git a/test/functional/autocmd/completedone_spec.lua b/test/functional/autocmd/completedone_spec.lua index 46c52cca8a..cfc1963f8a 100644 --- a/test/functional/autocmd/completedone_spec.lua +++ b/test/functional/autocmd/completedone_spec.lua @@ -13,7 +13,6 @@ describe('CompleteDone', function() describe('sets v:event.reason', function() before_each(function() - clear() command('autocmd CompleteDone * let g:donereason = v:event.reason') feed('i') call('complete', call('col', '.'), { 'foo', 'bar' }) diff --git a/test/functional/core/exit_spec.lua b/test/functional/core/exit_spec.lua index aafad4c8a5..1314916168 100644 --- a/test/functional/core/exit_spec.lua +++ b/test/functional/core/exit_spec.lua @@ -58,6 +58,7 @@ end) describe(':cquit', function() local function test_cq(cmdline, exit_code, redir_msg) if redir_msg then + n.clear() eq( redir_msg, pcall_err(function() @@ -66,16 +67,13 @@ describe(':cquit', function() ) poke_eventloop() assert_alive() + n.check_close() else local p = n.spawn_wait('--cmd', cmdline) eq(exit_code, p.status) end end - before_each(function() - n.clear() - end) - it('exits with non-zero after :cquit', function() test_cq('cquit', 1, nil) end) diff --git a/test/functional/ex_cmds/echo_spec.lua b/test/functional/ex_cmds/echo_spec.lua index 2f0bcb4d9d..fd818286ca 100644 --- a/test/functional/ex_cmds/echo_spec.lua +++ b/test/functional/ex_cmds/echo_spec.lua @@ -27,7 +27,7 @@ describe(':echo :echon :echomsg :echoerr', function() end end - before_each(function() + setup(function() clear() source([[ function String(s) @@ -149,7 +149,7 @@ describe(':echo :echon :echomsg :echoerr', function() end) describe('used to represent funcrefs', function() - before_each(function() + setup(function() source([[ function Test1() endfunction diff --git a/test/functional/legacy/increment_spec.lua b/test/functional/legacy/increment_spec.lua deleted file mode 100644 index c9c2324c42..0000000000 --- a/test/functional/legacy/increment_spec.lua +++ /dev/null @@ -1,762 +0,0 @@ --- Tests for using Ctrl-A/Ctrl-X on visual selections - -local t = require('test.testutil') -local n = require('test.functional.testnvim')() - -local source, command = n.source, n.command -local call, clear = n.call, n.clear -local eq, api = t.eq, n.api - -describe('Ctrl-A/Ctrl-X on visual selections', function() - before_each(function() - clear() - source([=[ - " 1) Ctrl-A on visually selected number - " Text: - " foobar-10 - " Expected: - " 1) Ctrl-A on start of line: - " foobar-9 - " 2) Ctrl-A on visually selected "-10": - " foobar-9 - " 3) Ctrl-A on visually selected "10": - " foobar-11 - " 4) Ctrl-X on visually selected "-10" - " foobar-11 - " 5) Ctrl-X on visually selected "10" - " foobar-9 - func Test_visual_increment_01() - call setline(1, repeat(["foobaar-10"], 5)) - - call cursor(1, 1) - exec "norm! \" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 1, 9, 0], getpos('.')) - - call cursor(2, 1) - exec "norm! f-v$\" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 2, 8, 0], getpos('.')) - - call cursor(3, 1) - exec "norm! f1v$\" - call assert_equal("foobaar-11", getline('.')) - call assert_equal([0, 3, 9, 0], getpos('.')) - - call cursor(4, 1) - exec "norm! f-v$\" - call assert_equal("foobaar-11", getline('.')) - call assert_equal([0, 4, 8, 0], getpos('.')) - - call cursor(5, 1) - exec "norm! f1v$\" - call assert_equal("foobaar-9", getline('.')) - call assert_equal([0, 5, 9, 0], getpos('.')) - endfunc - - " 2) Ctrl-A on visually selected lines - " Text: - " 10 - " 20 - " 30 - " 40 - " - " Expected: - " 1) Ctrl-A on visually selected lines: - " 11 - " 21 - " 31 - " 41 - " - " 2) Ctrl-X on visually selected lines: - " 9 - " 19 - " 29 - " 39 - func Test_visual_increment_02() - call setline(1, ["10", "20", "30", "40"]) - exec "norm! GV3k$\" - call assert_equal(["11", "21", "31", "41"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["10", "20", "30", "40"]) - exec "norm! GV3k$\" - call assert_equal(["9", "19", "29", "39"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 3) g Ctrl-A on visually selected lines, with non-numbers in between - " Text: - " 10 - " - " 20 - " - " 30 - " - " 40 - " - " Expected: - " 1) 2 g Ctrl-A on visually selected lines: - " 12 - " - " 24 - " - " 36 - " - " 48 - " 2) 2 g Ctrl-X on visually selected lines - " 8 - " - " 16 - " - " 24 - " - " 32 - func Test_visual_increment_03() - call setline(1, ["10", "", "20", "", "30", "", "40"]) - exec "norm! GV6k2g\" - call assert_equal(["12", "", "24", "", "36", "", "48"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["10", "", "20", "", "30", "", "40"]) - exec "norm! GV6k2g\" - call assert_equal(["8", "", "16", "", "24", "", "32"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 4) Ctrl-A on non-number - " Text: - " foobar-10 - " Expected: - " 1) visually select foobar: - " foobar-10 - func Test_visual_increment_04() - call setline(1, ["foobar-10"]) - exec "norm! vf-\" - call assert_equal(["foobar-10"], getline(1, '$')) - " NOTE: I think this is correct behavior... - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 5) g on letter - " Test: - " a - " a - " a - " a - " Expected: - " 1) g Ctrl-A on visually selected lines - " b - " c - " d - " e - func Test_visual_increment_05() - set nrformats+=alpha - call setline(1, repeat(["a"], 4)) - exec "norm! GV3kg\" - call assert_equal(["b", "c", "d", "e"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 6) g on letter - " Test: - " z - " z - " z - " z - " Expected: - " 1) g Ctrl-X on visually selected lines - " y - " x - " w - " v - func Test_visual_increment_06() - set nrformats+=alpha - call setline(1, repeat(["z"], 4)) - exec "norm! GV3kg\" - call assert_equal(["y", "x", "w", "v"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 7) on letter - " Test: - " 2 - " 1 - " 0 - " -1 - " -2 - " - " Expected: - " 1) Ctrl-A on visually selected lines - " 3 - " 2 - " 1 - " 0 - " -1 - " - " 2) Ctrl-X on visually selected lines - " 1 - " 0 - " -1 - " -2 - " -3 - func Test_visual_increment_07() - call setline(1, ["2", "1", "0", "-1", "-2"]) - exec "norm! GV4k\" - call assert_equal(["3", "2", "1", "0", "-1"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["2", "1", "0", "-1", "-2"]) - exec "norm! GV4k\" - call assert_equal(["1", "0", "-1", "-2", "-3"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 8) Block increment on 0x9 - " Text: - " 0x9 - " 0x9 - " Expected: - " 1) Ctrl-A on visually block selected region (cursor at beginning): - " 0xa - " 0xa - " 2) Ctrl-A on visually block selected region (cursor at end) - " 0xa - " 0xa - func Test_visual_increment_08() - call setline(1, repeat(["0x9"], 2)) - exec "norm! \j$\" - call assert_equal(["0xa", "0xa"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, repeat(["0x9"], 2)) - exec "norm! gg$\+\" - call assert_equal(["0xa", "0xa"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 9) Increment and redo - " Text: - " 2 - " 2 - " - " 3 - " 3 - " - " Expected: - " 1) 2 Ctrl-A on first 2 visually selected lines - " 4 - " 4 - " 2) redo (.) on 3 - " 5 - " 5 - func Test_visual_increment_09() - call setline(1, ["2", "2", "", "3", "3", ""]) - exec "norm! ggVj2\" - call assert_equal(["4", "4", "", "3", "3", ""], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! 3j." - call assert_equal(["4", "4", "", "5", "5", ""], getline(1, '$')) - call assert_equal([0, 4, 1, 0], getpos('.')) - endfunc - - " 10) sequentially decrement 1 - " Text: - " 1 - " 1 - " 1 - " 1 - " Expected: - " 1) g Ctrl-X on visually selected lines - " 0 - " -1 - " -2 - " -3 - func Test_visual_increment_10() - call setline(1, repeat(["1"], 4)) - exec "norm! GV3kg\" - call assert_equal(["0", "-1", "-2", "-3"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 11) visually block selected indented lines - " Text: - " 1 - " 1 - " 1 - " 1 - " Expected: - " 1) g Ctrl-A on block selected indented lines - " 2 - " 1 - " 3 - " 4 - func Test_visual_increment_11() - call setline(1, [" 1", "1", " 1", " 1"]) - exec "norm! f1\3jg\" - call assert_equal([" 2", "1", " 3", " 4"], getline(1, '$')) - call assert_equal([0, 1, 5, 0], getpos('.')) - endfunc - - " 12) visually selected several columns - " Text: - " 0 0 - " 0 0 - " 0 0 - " Expected: - " 1) 'v' select last zero and first zeroes - " 0 1 - " 1 0 - " 1 0 - func Test_visual_increment_12() - call setline(1, repeat(["0 0"], 3)) - exec "norm! $v++\" - call assert_equal(["0 1", "1 0", "1 0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - endfunc - - " 13) visually selected part of columns - " Text: - " max: 100px - " max: 200px - " max: 300px - " max: 400px - " Expected: - " 1) 'v' on first two numbers Ctrl-A - " max: 110px - " max: 220px - " max: 330px - " max: 400px - " 2) 'v' on first two numbers Ctrl-X - " max: 90px - " max: 190px - " max: 290px - " max: 400px - func Test_visual_increment_13() - call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) - exec "norm! f1\l2j\" - call assert_equal(["max: 110px", "max: 210px", "max: 310px", "max: 400px"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) - - call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) - exec "norm! ggf1\l2j\" - call assert_equal(["max: 90px", "max: 190px", "max: 290px", "max: 400px"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) - endfunc - - " 14) redo in block mode - " Text: - " 1 1 - " 1 1 - " Expected: - " 1) Ctrl-a on first column, redo on second column - " 2 2 - " 2 2 - func Test_visual_increment_14() - call setline(1, repeat(["1 1"], 2)) - exec "norm! G\k\w." - call assert_equal(["2 2", "2 2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - endfunc - - " 15) block select single numbers - " Text: - " 101 - " Expected: - " 1) Ctrl-a on visually selected zero - " 111 - func Test_visual_increment_15() - call setline(1, ["101"]) - exec "norm! lv\" - call assert_equal(["111"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) - endfunc - - " 16) increment right aligned numbers - " Text: - " 1 - " 19 - " 119 - " Expected: - " 1) Ctrl-a on line selected region - " 2 - " 20 - " 120 - func Test_visual_increment_16() - call setline(1, [" 1", " 19", " 119"]) - exec "norm! VG\" - call assert_equal([" 2", " 20", " 120"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 17) block-wise increment and redo - " Text: - " 100 - " 1 - " - " 100 - " 1 - " - " Expected: - " 1) Ctrl-V j $ on first block, afterwards '.' on second - " 101 - " 2 - " - " 101 - " 2 - func Test_visual_increment_17() - call setline(1, [" 100", " 1", "", " 100", " 1"]) - exec "norm! \j$\2j." - call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$')) - call assert_equal([0, 3, 1, 0], getpos('.')) - endfunc - - " 18) repeat of g - " Text: - " 0 - " 0 - " 0 - " 0 - " - " Expected: - " 1) V 4j g, repeat twice afterwards with . - " 3 - " 6 - " 9 - " 12 - func Test_visual_increment_18() - call setline(1, repeat(["0"], 4)) - exec "norm! GV3kg\" - exec "norm! .." - call assert_equal(["3", "6", "9", "12"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 19) increment on number with nrformat including alpha - " Text: - " 1 - " 1a - " - " Expected: - " 1) j$ - " 2 - " 2a - func Test_visual_increment_19() - set nrformats+=alpha - call setline(1, ["1", "1a"]) - exec "norm! \G$\" - call assert_equal(["2", "2a"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 20) increment a single letter - " Text: - " a - " - " Expected: - " 1) and cursor is on a - " b - func Test_visual_increment_20() - set nrformats+=alpha - call setline(1, ["a"]) - exec "norm! \" - call assert_equal(["b"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 21) block-wise increment on part of hexadecimal - " Text: - " 0x123456 - " - " Expected: - " 1) Ctrl-V f3 - " 0x124456 - func Test_visual_increment_21() - call setline(1, ["0x123456"]) - exec "norm! \f3\" - call assert_equal(["0x124456"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 22) Block increment on 0b0 - " Text: - " 0b1 - " 0b1 - " Expected: - " 1) Ctrl-A on visually block selected region (cursor at beginning): - " 0b10 - " 0b10 - " 2) Ctrl-A on visually block selected region (cursor at end) - " 0b10 - " 0b10 - func Test_visual_increment_22() - call setline(1, repeat(["0b1"], 2)) - exec "norm! \j$\" - call assert_equal(repeat(["0b10"], 2), getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, repeat(["0b1"], 2)) - exec "norm! $\+\" - call assert_equal(repeat(["0b10"], 2), getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 23) block-wise increment on part of binary - " Text: - " 0b1001 - " - " Expected: - " 1) Ctrl-V 5l - " 0b1011 - func Test_visual_increment_23() - call setline(1, ["0b1001"]) - exec "norm! \4l\" - call assert_equal(["0b1011"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 24) increment hexadecimal - " Text: - " 0x0b1001 - " - " Expected: - " 1) - " 0x0b1002 - func Test_visual_increment_24() - call setline(1, ["0x0b1001"]) - exec "norm! \$\" - call assert_equal(["0x0b1002"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 25) increment binary with nrformats including alpha - " Text: - " 0b1001a - " - " Expected: - " 1) - " 0b1010a - func Test_visual_increment_25() - set nrformats+=alpha - call setline(1, ["0b1001a"]) - exec "norm! \$\" - call assert_equal(["0b1010a"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " 26) increment binary with 32 bits - " Text: - " 0b11111111111111111111111111111110 - " - " Expected: - " 1) - " 0b11111111111111111111111111111111 - func Test_visual_increment_26() - set nrformats+=alpha - call setline(1, ["0b11111111111111111111111111111110"]) - exec "norm! \$\" - call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - set nrformats-=alpha - endfunc - - " 27) increment with 'rightreft', if supported - func Test_visual_increment_27() - if exists('+rightleft') - set rightleft - call setline(1, ["1234 56"]) - - exec "norm! $\" - call assert_equal(["1234 57"], getline(1, '$')) - call assert_equal([0, 1, 7, 0], getpos('.')) - - exec "norm! \" - call assert_equal(["1234 58"], getline(1, '$')) - call assert_equal([0, 1, 7, 0], getpos('.')) - set norightleft - endif - endfunc - - " Tab code and linewise-visual inc/dec - func Test_visual_increment_28() - call setline(1, ["x\10", "\-1"]) - exec "norm! Vj\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggVj\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " Tab code and linewise-visual inc/dec with 'nrformats'+=alpha - func Test_visual_increment_29() - set nrformats+=alpha - call setline(1, ["x\10", "\-1"]) - exec "norm! Vj\" - call assert_equal(["y\10", "\0"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggVj\" - call assert_equal(["w\10", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " Tab code and character-visual inc/dec - func Test_visual_increment_30() - call setline(1, ["x\10", "\-1"]) - exec "norm! f1vjf1\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggf1vjf1\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - endfunc - - " Tab code and blockwise-visual inc/dec - func Test_visual_increment_31() - call setline(1, ["x\10", "\-1"]) - exec "norm! f1\jl\" - call assert_equal(["x\11", "\0"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - - call setline(1, ["x\10", "\-1"]) - exec "norm! ggf1\jl\" - call assert_equal(["x\9", "\-2"], getline(1, '$')) - call assert_equal([0, 1, 3, 0], getpos('.')) - endfunc - - " Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' - func Test_visual_increment_32() - 28vnew dummy_31 - set linebreak showbreak=+ - call setline(1, ["x\\\10", "\\\\-1"]) - exec "norm! ggf0\jg_\" - call assert_equal(["x\\\1-1", "\\\\-2"], getline(1, '$')) - call assert_equal([0, 1, 6, 0], getpos('.')) - bwipe! - endfunc - - " Tab code and blockwise-visual increment with $ - func Test_visual_increment_33() - call setline(1, ["\123", "456"]) - exec "norm! gg0\j$\" - call assert_equal(["\124", "457"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " Tab code and blockwise-visual increment and redo - func Test_visual_increment_34() - call setline(1, ["\123", " 456789"]) - exec "norm! gg0\j\" - call assert_equal(["\123", " 457789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! .." - call assert_equal(["\123", " 459789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " Tab code, spaces and character-visual increment and redo - func Test_visual_increment_35() - call setline(1, ["\123", " 123", "\123", "\123"]) - exec "norm! ggvjf3\..." - call assert_equal(["\127", " 127", "\123", "\123"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) - endfunc - - " Tab code, spaces and blockwise-visual increment and redo - func Test_visual_increment_36() - call setline(1, [" 123", "\456789"]) - exec "norm! G0\kl\" - call assert_equal([" 123", "\556789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - - exec "norm! ..." - call assert_equal([" 123", "\856789"], getline(1, '$')) - call assert_equal([0, 1, 1, 0], getpos('.')) - endfunc - - " block-wise increment and dot-repeat - " Text: - " 1 23 - " 4 56 - " - " Expected: - " 1) f2 Ctrl-V jl , repeat twice afterwards with . - " 1 26 - " 4 59 - " - " Try with and without indent. - func Test_visual_increment_37() - call setline(1, [" 1 23", " 4 56"]) - exec "norm! ggf2\jl\.." - call assert_equal([" 1 26", " 4 59"], getline(1, 2)) - - call setline(1, ["1 23", "4 56"]) - exec "norm! ggf2\jl\.." - call assert_equal(["1 26", "4 59"], getline(1, 2)) - endfunc - - " Check redo after the normal mode increment - func Test_visual_increment_38() - exec "norm! i10\5\." - call assert_equal(["20"], getline(1, '$')) - call assert_equal([0, 1, 2, 0], getpos('.')) - endfunc - - " Test what patch 7.3.414 fixed. Ctrl-A on "000" drops the leading zeros. - func Test_normal_increment_01() - call setline(1, "000") - exec "norm! gg0\" - call assert_equal("001", getline(1)) - - call setline(1, "000") - exec "norm! gg$\" - call assert_equal("001", getline(1)) - - call setline(1, "001") - exec "norm! gg0\" - call assert_equal("002", getline(1)) - - call setline(1, "001") - exec "norm! gg$\" - call assert_equal("002", getline(1)) - endfunc - - " Test a regression of patch 7.4.1087 fixed. - func Test_normal_increment_02() - call setline(1, ["hello 10", "world"]) - exec "norm! ggl\jx" - call assert_equal(["hello 11", "worl"], getline(1, '$')) - call assert_equal([0, 2, 4, 0], getpos('.')) - endfunc - ]=]) - end) - - for i = 1, 38 do - local id = string.format('%02d', i) - - it('works on Test ' .. id, function() - command('set nrformats&vi') -- &vi makes Vim compatible - call('Test_visual_increment_' .. id) - eq({}, api.nvim_get_vvar('errors')) - end) - end - - it('does not drop leading zeroes', function() - command('set nrformats&vi') -- &vi makes Vim compatible - call('Test_normal_increment_01') - eq({}, api.nvim_get_vvar('errors')) - end) - - it('maintains correct column after CTRL-A', function() - call('Test_normal_increment_02') - eq({}, api.nvim_get_vvar('errors')) - end) -end) diff --git a/test/functional/legacy/undolevels_spec.lua b/test/functional/legacy/undolevels_spec.lua deleted file mode 100644 index 8453921669..0000000000 --- a/test/functional/legacy/undolevels_spec.lua +++ /dev/null @@ -1,64 +0,0 @@ -local t = require('test.testutil') -local n = require('test.functional.testnvim')() - -local source, clear = n.source, n.clear -local eq, api = t.eq, n.api - -describe('undolevel', function() - setup(clear) - - it('is working', function() - source([[ - func FillBuffer() - for i in range(1,13) - put=i - " Set 'undolevels' to split undo. - exe "setg ul=" . &g:ul - endfor - endfunc - - func Test_global_local_undolevels() - new one - set undolevels=5 - call FillBuffer() - " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines - earlier 10 - call assert_equal(5, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - call assert_equal('7', getline('$')) - - new two - setlocal undolevels=2 - call FillBuffer() - " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines - earlier 10 - call assert_equal(5, &g:undolevels) - call assert_equal(2, &l:undolevels) - call assert_equal('10', getline('$')) - - setlocal ul=10 - call assert_equal(5, &g:undolevels) - call assert_equal(10, &l:undolevels) - - " Setting local value in "two" must not change local value in "one" - wincmd p - call assert_equal(5, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - - new three - setglobal ul=50 - call assert_equal(50, &g:undolevels) - call assert_equal(-123456, &l:undolevels) - - " Drop created windows - set ul& - new - only! - endfunc - - call Test_global_local_undolevels() - ]]) - - eq({}, api.nvim_get_vvar('errors')) - end) -end) diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 7d176bcbf5..8b3c7ae591 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -53,7 +53,7 @@ local tests_windows_paths = { 'c:\\users\\foo\\bar\\..\\', } -before_each(clear) +setup(clear) describe('vim.fs', function() describe('parents()', function() @@ -345,6 +345,10 @@ describe('vim.fs', function() command('edit test/functional/fixtures/tty-test.c') end) + after_each(function() + command('bwipe!') + end) + it('works with a single marker', function() eq(test_source_path, exec_lua([[return vim.fs.root(0, 'CMakePresets.json')]])) end) @@ -457,8 +461,9 @@ describe('vim.fs', function() eq( xdg_config_home .. '/nvim', exec_lua(function() - vim.env.XDG_CONFIG_HOME = xdg_config_home - return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') + return vim._with({ env = { XDG_CONFIG_HOME = xdg_config_home } }, function() + return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') + end) end) ) end) diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua index 8302c7334d..96bf8fb971 100644 --- a/test/functional/lua/glob_spec.lua +++ b/test/functional/lua/glob_spec.lua @@ -1,16 +1,10 @@ local t = require('test.testutil') -local n = require('test.functional.testnvim')() local eq = t.eq describe('glob', function() - before_each(n.clear) - after_each(n.clear) - local match = function(pattern, str) - return n.exec_lua(function() - return require('vim.glob').to_lpeg(pattern):match(str) ~= nil - end) + return require('vim.glob').to_lpeg(pattern):match(str) ~= nil end describe('glob matching', function() diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua index 45141739b6..e4324fb6b2 100644 --- a/test/functional/lua/snippet_spec.lua +++ b/test/functional/lua/snippet_spec.lua @@ -33,7 +33,6 @@ describe('vim.snippet', function() set_snippet_jump(-1, '') end) end) - after_each(clear) --- @param snippet string[] --- @param expected string[] diff --git a/test/functional/lua/text_spec.lua b/test/functional/lua/text_spec.lua index 7cdec39338..05eb5cab0c 100644 --- a/test/functional/lua/text_spec.lua +++ b/test/functional/lua/text_spec.lua @@ -1,12 +1,8 @@ local t = require('test.testutil') -local n = require('test.functional.testnvim')() -local clear = n.clear local eq = t.eq describe('vim.text', function() - before_each(clear) - describe('indent()', function() it('validation', function() t.matches('size%: expected number, got string', t.pcall_err(vim.text.indent, 'x', 'x')) diff --git a/test/functional/options/keymap_spec.lua b/test/functional/options/keymap_spec.lua index f76525699f..21e6ab97ff 100644 --- a/test/functional/options/keymap_spec.lua +++ b/test/functional/options/keymap_spec.lua @@ -9,7 +9,6 @@ local exec_capture, dedent = n.exec_capture, t.dedent -- First test it's implemented using the :lmap and :lnoremap commands, then -- check those mappings behave as expected. describe("'keymap' / :lmap", function() - clear() before_each(function() clear() insert('lllaaa') diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index 20ef1cb49e..63c14419ad 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -9,7 +9,6 @@ describe('vim.lsp.codelens', function() n.clear() exec_lua('require("vim.lsp")') end) - after_each(n.clear) it('on_codelens_stores_and_displays_lenses', function() local fake_uri = 'file:///fake/uri' diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 57aea41794..c7f8d290a2 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -863,8 +863,6 @@ describe('vim.lsp.completion: protocol', function() end) end) - after_each(clear) - local function assert_matches(fn) retry(nil, nil, function() fn(exec_lua('return _G.capture.matches')) @@ -1262,8 +1260,6 @@ describe('vim.lsp.completion: integration', function() end) end) - after_each(clear) - it('puts cursor at the end of completed word', function() local completion_list = { isIncomplete = false, diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 8d12eaae80..a5077b671d 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -115,10 +115,6 @@ describe('vim.lsp.diagnostic', function() end) end) - after_each(function() - clear() - end) - describe('vim.lsp.diagnostic.on_publish_diagnostics', function() it('correctly handles UTF-16 offsets', function() local line = 'All 💼 and no 🎉 makes Jack a dull 👦' diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index e60c36cd23..4cba151d3b 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -9,7 +9,6 @@ local exec_lua = n.exec_lua describe('vim.lsp._snippet_grammar', function() before_each(n.clear) - after_each(n.clear) local parse = function(...) local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...) diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index f0fa659372..6161529f5e 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -184,7 +184,6 @@ describe('vim.lsp.util', function() end before_each(function() - n.clear() local _ = Screen.new(80, 80) feed('79i') -- fill screen with empty lines end) @@ -280,7 +279,6 @@ describe('vim.lsp.util', function() describe('open_floating_preview', function() before_each(function() - n.clear() Screen.new(10, 10) feed('9iG4k') end) diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 61ab730da8..6afb370df6 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -11,7 +11,7 @@ local ok = t.ok local NIL = vim.NIL describe('autoload/msgpack.vim', function() - before_each(function() + setup(function() clear { args = { '-u', 'NORC' } } end) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index ca005d9f12..d1cc2b5ff7 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -47,7 +47,7 @@ local wshada_tmp, _, fname_tmp = get_shada_rw('Xtest-functional-plugin-shada.sha describe('autoload/shada.vim', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) - before_each(function() + setup(function() reset() nvim_command([[ function ModifyVal(val) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 5215983755..ec3978d78c 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -3587,6 +3587,10 @@ describe('TUI client', function() it('connects to remote instance (with its own TUI)', function() local server_super = n.new_session(false) local client_super = n.new_session(true) + finally(function() + server_super:close() + client_super:close() + end) set_session(server_super) local server_pipe = new_pipename() @@ -3651,14 +3655,15 @@ describe('TUI client', function() } feed_data(':q!\n') - - server_super:close() - client_super:close() end) it('connects to remote instance (--headless)', function() local server = n.new_session(false) local client_super = n.new_session(true, { env = { NVIM_LOG_FILE = testlog } }) + finally(function() + client_super:close() + server:close() + end) set_session(server) local server_pipe = api.nvim_get_vvar('servername') @@ -3699,8 +3704,6 @@ describe('TUI client', function() fn.system({ nvim_prog, '--remote-ui', '--server', server_pipe }) eq(1, api.nvim_get_vvar('shell_error')) - client_super:close() - server:close() if is_os('mac') then assert_log('uv_tty_set_mode failed: Unknown system error %-102', testlog) end diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua index 0a12cf0920..d033ef96c4 100644 --- a/test/functional/testnvim.lua +++ b/test/functional/testnvim.lua @@ -126,6 +126,7 @@ end --- @return any function M.request(method, ...) assert(session, 'no Nvim session') + assert(not session.eof_err, 'sending request after EOF from Nvim') local status, rv = session:request(method, ...) if not status then if loop_running then @@ -323,10 +324,10 @@ end function M.expect_exit(fn_or_timeout, ...) local eof_err_msg = 'EOF was received from Nvim. Likely the Nvim process crashed.' if type(fn_or_timeout) == 'function' then - t.matches(eof_err_msg, t.pcall_err(fn_or_timeout, ...)) + t.matches(vim.pesc(eof_err_msg), t.pcall_err(fn_or_timeout, ...)) else t.matches( - eof_err_msg, + vim.pesc(eof_err_msg), t.pcall_err(function(timeout, fn, ...) fn(...) assert(session) @@ -696,7 +697,9 @@ end --- @param method string --- @param ... any function M.nvim_async(method, ...) - assert(session):notify(method, ...) + assert(session, 'no Nvim session') + assert(not session.eof_err, 'sending notification after EOF from Nvim') + session:notify(method, ...) end --- Executes a Vimscript function via RPC. diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index 374f93b38b..5d43bfe274 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -14,8 +14,6 @@ local poke_eventloop = n.poke_eventloop before_each(clear) describe('treesitter foldexpr', function() - clear() - before_each(function() -- open folds to avoid deleting entire folded region exec_lua([[vim.opt.foldlevel = 9]]) diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 1354481036..ac930b434d 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -14,8 +14,6 @@ local function lua_eval(lua_expr) end describe('treesitter node API', function() - clear() - it('double free tree', function() insert('F') exec_lua(function() diff --git a/test/functional/treesitter/utils_spec.lua b/test/functional/treesitter/utils_spec.lua index 34bea349f6..6b25bbbf33 100644 --- a/test/functional/treesitter/utils_spec.lua +++ b/test/functional/treesitter/utils_spec.lua @@ -9,8 +9,6 @@ local exec_lua = n.exec_lua before_each(clear) describe('treesitter utils', function() - before_each(clear) - it('can find an ancestor', function() insert([[ int main() { diff --git a/test/functional/vimscript/functions_spec.lua b/test/functional/vimscript/functions_spec.lua index 7d9e80a32b..419f2f4a51 100644 --- a/test/functional/vimscript/functions_spec.lua +++ b/test/functional/vimscript/functions_spec.lua @@ -16,6 +16,5 @@ local is_os = t.is_os before_each(clear) it('windowsversion()', function() - clear() matches(is_os('win') and '^%d+%.%d+$' or '^$', eval('windowsversion()')) end) diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua index 895e722e96..6a3ce82bac 100644 --- a/test/functional/vimscript/json_functions_spec.lua +++ b/test/functional/vimscript/json_functions_spec.lua @@ -13,8 +13,8 @@ local NIL = vim.NIL local source = n.source describe('json_decode() function', function() - local restart = function(...) - clear(...) + setup(function() + clear() source([[ language C function Eq(exp, act) @@ -57,8 +57,7 @@ describe('json_decode() function', function() endif endfunction ]]) - end - before_each(restart) + end) local speq = function(expected, actual_expr) eq(1, fn.EvalEq(expected, actual_expr)) @@ -627,7 +626,7 @@ describe('json_decode() function', function() end) describe('json_encode() function', function() - before_each(function() + setup(function() clear() command('language C') end) diff --git a/test/functional/vimscript/minmax_functions_spec.lua b/test/functional/vimscript/minmax_functions_spec.lua index bf223c436e..22288e5f94 100644 --- a/test/functional/vimscript/minmax_functions_spec.lua +++ b/test/functional/vimscript/minmax_functions_spec.lua @@ -8,7 +8,7 @@ local clear = n.clear local fn = n.fn local pcall_err = t.pcall_err -before_each(clear) +setup(clear) for _, func in ipairs({ 'min', 'max' }) do describe(func .. '()', function() it('gives a single error message when multiple values failed conversions', function() diff --git a/test/functional/vimscript/msgpack_functions_spec.lua b/test/functional/vimscript/msgpack_functions_spec.lua index d2011f9fec..6e85bd466f 100644 --- a/test/functional/vimscript/msgpack_functions_spec.lua +++ b/test/functional/vimscript/msgpack_functions_spec.lua @@ -10,7 +10,7 @@ local exc_exec = n.exc_exec local is_os = t.is_os describe('msgpack*() functions', function() - before_each(clear) + setup(clear) local obj_test = function(msg, obj) it(msg, function() @@ -415,7 +415,7 @@ local parse_eq = function(expect, list_arg) end describe('msgpackparse() function', function() - before_each(clear) + setup(clear) it('restores nil as v:null', function() parse_eq(eval('[v:null]'), { '\192' }) @@ -525,7 +525,7 @@ describe('msgpackparse() function', function() end) it('fails to parse a partial', function() - command('function T() dict\nendfunction') + command('function! T() dict\nendfunction') eq( 'Vim(call):E899: Argument of msgpackparse() must be a List or Blob', exc_exec('call msgpackparse(function("T", [1, 2], {}))') @@ -555,7 +555,7 @@ describe('msgpackparse() function', function() end) describe('msgpackdump() function', function() - before_each(clear) + setup(clear) local dump_eq = function(exp_list, arg_expr) eq(exp_list, eval('msgpackdump(' .. arg_expr .. ')')) @@ -636,7 +636,7 @@ describe('msgpackdump() function', function() end) it('fails to dump a partial', function() - command('function T() dict\nendfunction') + command('function! T() dict\nendfunction') command('let Todump = function("T", [1, 2], {})') eq( 'Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference', @@ -776,7 +776,7 @@ describe('msgpackdump() function', function() end) it('fails to dump a partial', function() - command('function T() dict\nendfunction') + command('function! T() dict\nendfunction') eq( 'Vim(call):E686: Argument of msgpackdump() must be a List', exc_exec('call msgpackdump(function("T", [1, 2], {}))') diff --git a/test/functional/vimscript/operators_spec.lua b/test/functional/vimscript/operators_spec.lua index 9c4a91d655..73bd868b06 100644 --- a/test/functional/vimscript/operators_spec.lua +++ b/test/functional/vimscript/operators_spec.lua @@ -6,7 +6,7 @@ local eval = n.eval local clear = n.clear describe('Division operator', function() - before_each(clear) + setup(clear) it('returns infinity on {positive}/0.0', function() eq("str2float('inf')", eval('string(1.0/0.0)')) diff --git a/test/functional/vimscript/printf_spec.lua b/test/functional/vimscript/printf_spec.lua index 1fd5c3c9b6..91c3b996a4 100644 --- a/test/functional/vimscript/printf_spec.lua +++ b/test/functional/vimscript/printf_spec.lua @@ -9,7 +9,7 @@ local api = n.api local exc_exec = n.exc_exec describe('printf()', function() - before_each(clear) + setup(clear) it('works with zero and %b', function() eq('0', fn.printf('%lb', 0)) diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua index b6137d7741..453ff7b478 100644 --- a/test/functional/vimscript/screenchar_spec.lua +++ b/test/functional/vimscript/screenchar_spec.lua @@ -30,7 +30,7 @@ local setup_floating_windows = function() end describe('screenchar() and family respect floating windows', function() - before_each(function() + setup(function() clear() -- These commands result into visible text `aabc`. -- `aab` - from floating windows, `c` - from text in regular window. diff --git a/test/functional/vimscript/sort_spec.lua b/test/functional/vimscript/sort_spec.lua index c8c1651ed8..c99a6ebadd 100644 --- a/test/functional/vimscript/sort_spec.lua +++ b/test/functional/vimscript/sort_spec.lua @@ -11,7 +11,7 @@ local command = n.command local exc_exec = n.exc_exec local pcall_err = t.pcall_err -before_each(clear) +setup(clear) describe('sort()', function() it('errors out when sorting special values', function() diff --git a/test/functional/vimscript/string_spec.lua b/test/functional/vimscript/string_spec.lua index 4df9104e1e..3667bb71a7 100644 --- a/test/functional/vimscript/string_spec.lua +++ b/test/functional/vimscript/string_spec.lua @@ -13,7 +13,7 @@ local NIL = vim.NIL local source = n.source describe('string() function', function() - before_each(clear) + setup(clear) describe('used to represent floating-point values', function() it('dumps NaN values', function() @@ -103,7 +103,7 @@ describe('string() function', function() end) describe('used to represent funcrefs', function() - before_each(function() + setup(function() source([[ function Test1() endfunction diff --git a/test/functional/vimscript/uniq_spec.lua b/test/functional/vimscript/uniq_spec.lua index 4e1ef699a4..f294fab4dc 100644 --- a/test/functional/vimscript/uniq_spec.lua +++ b/test/functional/vimscript/uniq_spec.lua @@ -7,7 +7,7 @@ local command = n.command local exc_exec = n.exc_exec local pcall_err = t.pcall_err -before_each(clear) +setup(clear) describe('uniq()', function() it('errors out when processing special values', function()