diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-05-24 19:18:11 +0000 |
commit | ff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch) | |
tree | 729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/editor | |
parent | 376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff) | |
parent | 28c04948a1c887a1cc0cb64de79fa32631700466 (diff) | |
download | rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2 rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/editor')
-rw-r--r-- | test/functional/editor/K_spec.lua | 17 | ||||
-rw-r--r-- | test/functional/editor/completion_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/editor/count_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/editor/ctrl_c_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/editor/fold_spec.lua | 29 | ||||
-rw-r--r-- | test/functional/editor/jump_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/editor/lang_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/editor/langmap_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/editor/macro_spec.lua | 159 | ||||
-rw-r--r-- | test/functional/editor/mark_spec.lua | 54 | ||||
-rw-r--r-- | test/functional/editor/meta_key_spec.lua | 43 | ||||
-rw-r--r-- | test/functional/editor/mode_cmdline_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/editor/mode_insert_spec.lua | 202 | ||||
-rw-r--r-- | test/functional/editor/mode_normal_spec.lua | 34 | ||||
-rw-r--r-- | test/functional/editor/put_spec.lua | 27 | ||||
-rw-r--r-- | test/functional/editor/search_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/editor/tabpage_spec.lua | 25 | ||||
-rw-r--r-- | test/functional/editor/undo_spec.lua | 29 |
18 files changed, 508 insertions, 244 deletions
diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index 1fbdd1c142..3c58892731 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -1,6 +1,7 @@ -local helpers = require('test.functional.helpers')(after_each) -local eq, clear, eval, feed, api, retry = - helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.api, helpers.retry +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local eq, clear, eval, feed, api, retry = t.eq, n.clear, n.eval, n.feed, n.api, t.retry describe('K', function() local test_file = 'K_spec_out' @@ -13,19 +14,19 @@ describe('K', function() end) it("invokes colon-prefixed 'keywordprg' as Vim command", function() - helpers.source([[ + n.source([[ let @a='fnord' set keywordprg=:put]]) -- K on the text "a" resolves to `:put a`. feed('ia<ESC>K') - helpers.expect([[ + n.expect([[ a fnord]]) end) it("invokes non-prefixed 'keywordprg' as shell command", function() - helpers.source([[ + n.source([[ let @a='fnord' set keywordprg=echo\ fnord>>]]) @@ -43,7 +44,7 @@ describe('K', function() end) it("<esc> kills the buffer for a running 'keywordprg' command", function() - helpers.source('set keywordprg=less') + n.source('set keywordprg=less') eval('writefile(["hello", "world"], "' .. test_file .. '")') feed('i' .. test_file .. '<esc>K') eq('t', eval('mode()')) @@ -57,7 +58,7 @@ describe('K', function() local bufnr = eval('bufnr()') feed('<esc>') eq('n', eval('mode()')) - helpers.neq(bufnr, eval('bufnr()')) + t.neq(bufnr, eval('bufnr()')) end) it('empty string falls back to :help #19298', function() diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 33d0d47499..62bb7e19f3 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -1,13 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local assert_alive = helpers.assert_alive -local clear, feed = helpers.clear, helpers.feed -local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq -local feed_command, source, expect = helpers.feed_command, helpers.source, helpers.expect -local fn = helpers.fn -local command = helpers.command -local api = helpers.api -local poke_eventloop = helpers.poke_eventloop + +local assert_alive = n.assert_alive +local clear, feed = n.clear, n.feed +local eval, eq, neq = n.eval, t.eq, t.neq +local feed_command, source, expect = n.feed_command, n.source, n.expect +local fn = n.fn +local command = n.command +local api = n.api +local poke_eventloop = n.poke_eventloop describe('completion', function() local screen diff --git a/test/functional/editor/count_spec.lua b/test/functional/editor/count_spec.lua index 94f741250a..d158497cb8 100644 --- a/test/functional/editor/count_spec.lua +++ b/test/functional/editor/count_spec.lua @@ -1,10 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local command = helpers.command +local eq = t.eq +local eval = n.eval +local feed = n.feed +local clear = n.clear +local command = n.command describe('v:count/v:count1', function() before_each(function() diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index e6a6ea808a..e1258c7df8 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -1,8 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, feed, source = helpers.clear, helpers.feed, helpers.source -local command = helpers.command -local poke_eventloop = helpers.poke_eventloop + +local clear, feed, source = n.clear, n.feed, n.source +local command = n.command +local poke_eventloop = n.poke_eventloop local sleep = vim.uv.sleep describe('CTRL-C (mapped)', function() @@ -16,7 +18,7 @@ describe('CTRL-C (mapped)', function() it('interrupts :global', function() -- Crashes luajit. - if helpers.skip_fragile(pending) then + if t.skip_fragile(pending) then return end @@ -66,8 +68,8 @@ describe('CTRL-C (mapped)', function() feed('i') screen:expect([[ ^ | - ~ |*4 - -- INSERT -- | + {1:~ }|*4 + {5:-- INSERT --} | ]]) end) @@ -81,8 +83,8 @@ describe('CTRL-C (mapped)', function() feed('i') screen:expect([[ ^ | - ~ |*4 - -- INSERT -- | + {1:~ }|*4 + {5:-- INSERT --} | ]]) end) end) diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua index 7950f6aea4..ee3f268a2a 100644 --- a/test/functional/editor/fold_spec.lua +++ b/test/functional/editor/fold_spec.lua @@ -1,14 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local insert = helpers.insert -local exec = helpers.exec -local feed = helpers.feed -local expect = helpers.expect -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq -local neq = helpers.neq +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local insert = n.insert +local exec = n.exec +local feed = n.feed +local expect = n.expect +local command = n.command +local fn = n.fn +local eq = t.eq +local neq = t.neq describe('Folding', function() local tempfname = 'Xtest-fold.txt' @@ -301,7 +302,7 @@ a]], it('updates correctly on :read', function() -- luacheck: ignore 621 - helpers.write_file( + t.write_file( tempfname, [[ a @@ -376,7 +377,7 @@ a]], end) it('splits folds according to >N and <N with foldexpr', function() - helpers.source([[ + n.source([[ function TestFoldExpr(lnum) let thisline = getline(a:lnum) if thisline == 'a' @@ -391,7 +392,7 @@ a]], return 0 endfunction ]]) - helpers.write_file( + t.write_file( tempfname, [[ b diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index fe03d82164..880831d9f8 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -1,15 +1,16 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local dedent = helpers.dedent -local eq = helpers.eq -local fn = helpers.fn -local feed = helpers.feed -local exec_capture = helpers.exec_capture -local write_file = helpers.write_file -local api = helpers.api +local clear = n.clear +local command = n.command +local dedent = t.dedent +local eq = t.eq +local fn = n.fn +local feed = n.feed +local exec_capture = n.exec_capture +local write_file = t.write_file +local api = n.api describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' diff --git a/test/functional/editor/lang_spec.lua b/test/functional/editor/lang_spec.lua index ee7cfac057..74d83bcfa8 100644 --- a/test/functional/editor/lang_spec.lua +++ b/test/functional/editor/lang_spec.lua @@ -1,8 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq -local command, expect = helpers.command, helpers.expect -local feed, eval = helpers.feed, helpers.eval -local exc_exec = helpers.exc_exec +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear, insert, eq = n.clear, n.insert, t.eq +local command, expect = n.command, n.expect +local feed, eval = n.feed, n.eval +local exc_exec = n.exc_exec describe('gu and gU', function() before_each(clear) diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index b2a4b21a89..e50e19a468 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -1,10 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local eq, neq, call = helpers.eq, helpers.neq, helpers.call -local eval, feed, clear = helpers.eval, helpers.feed, helpers.clear -local command, insert, expect = helpers.command, helpers.insert, helpers.expect -local feed_command = helpers.feed_command -local curwin = helpers.api.nvim_get_current_win +local eq, neq, call = t.eq, t.neq, n.call +local eval, feed, clear = n.eval, n.feed, n.clear +local command, insert, expect = n.command, n.insert, n.expect +local feed_command = n.feed_command +local curwin = n.api.nvim_get_current_win describe("'langmap'", function() before_each(function() @@ -133,7 +134,7 @@ describe("'langmap'", function() hello]]) end) it('command-line CTRL-R', function() - helpers.source([[ + n.source([[ let i_value = 0 let j_value = 0 call setreg('i', 'i_value') @@ -171,7 +172,7 @@ describe("'langmap'", function() end) it('prompt for number', function() command('set langmap=12,21') - helpers.source([[ + n.source([[ let gotten_one = 0 function Map() let answer = inputlist(['a', '1.', '2.', '3.']) @@ -214,10 +215,7 @@ describe("'langmap'", function() end feed('qa' .. command_string .. 'q') expect(expect_string) - eq( - expect_macro or helpers.fn.nvim_replace_termcodes(command_string, true, true, true), - eval('@a') - ) + eq(expect_macro or n.fn.nvim_replace_termcodes(command_string, true, true, true), eval('@a')) if setup_function then setup_function() end diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index c97befdf07..27c5eddac8 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -1,19 +1,21 @@ -local helpers = require('test.functional.helpers')(after_each) - -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local clear = helpers.clear -local expect = helpers.expect -local command = helpers.command -local fn = helpers.fn -local api = helpers.api -local insert = helpers.insert - -describe('macros', function() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local eq = t.eq +local eval = n.eval +local feed = n.feed +local clear = n.clear +local expect = n.expect +local command = n.command +local fn = n.fn +local api = n.api +local insert = n.insert + +describe('macros with default mappings', function() before_each(function() clear({ args_rm = { '--cmd' } }) end) + it('can be recorded and replayed', function() feed('qiahello<esc>q') expect('hello') @@ -22,6 +24,7 @@ describe('macros', function() expect('hellohello') eq('ahello', eval('@i')) end) + it('applies maps', function() command('imap x l') command('nmap l a') @@ -34,87 +37,147 @@ describe('macros', function() end) it('can be replayed with Q', function() - insert [[hello + insert [[ +hello hello hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOO +hello +hello]] feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOOFOO +hello +hello]] feed [[G3Q]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOOFOO +hello +helloFOOFOOFOO]] feed [[ggV3jQ]] - eq( - { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, - api.nvim_buf_get_lines(0, 0, -1, false) - ) + expect [[ +helloFOOFOOFOO +helloFOO +helloFOOFOOFOOFOO]] end) - it('can be replayed with @', function() - insert [[hello + it('can be replayed with Q and @@', function() + insert [[ +hello hello hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({ 'helloFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOO +hello +hello]] feed [[Q]] - eq({ 'helloFOOFOO', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOOFOO +hello +hello]] feed [[G3@@]] - eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOOFOO +hello +helloFOOFOOFOO]] feed [[ggV2j@@]] - eq( - { 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, - api.nvim_buf_get_lines(0, 0, -1, false) - ) + expect [[ +helloFOOFOOFOO +helloFOO +helloFOOFOOFOOFOO]] end) - it('can be replayed with @q and @w', function() - insert [[hello + it('can be replayed with @ in linewise Visual mode', function() + insert [[ +hello hello hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +hello +hello +hello]] feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +hello +hello +hello]] feed [[V3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +helloFOO +helloFOO +helloFOO]] + + feed [[ggVj@w]] + expect [[ +helloFOO123 +helloFOO123 +helloFOO]] + end) - feed [[gg]] - feed [[Vj@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + it('can be recorded and replayed in Visual mode', function() + insert('foo BAR BAR foo BAR foo BAR BAR BAR foo BAR BAR') + feed('0vqifofRq') + eq({ 0, 1, 7, 0 }, fn.getpos('.')) + eq({ 0, 1, 1, 0 }, fn.getpos('v')) + feed('Q') + eq({ 0, 1, 19, 0 }, fn.getpos('.')) + eq({ 0, 1, 1, 0 }, fn.getpos('v')) + feed('Q') + eq({ 0, 1, 27, 0 }, fn.getpos('.')) + eq({ 0, 1, 1, 0 }, fn.getpos('v')) + feed('@i') + eq({ 0, 1, 43, 0 }, fn.getpos('.')) + eq({ 0, 1, 1, 0 }, fn.getpos('v')) end) - it('can be replayed with @q and @w visual-block', function() - insert [[hello + it('can be replayed with @ in blockwise Visual mode', function() + insert [[ +hello hello hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +hello +hello +hello]] feed [[qwA123<esc>qu]] - eq({ 'hello', 'hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, false)) - - feed [[<C-v>3j@q]] - eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + expect [[ +hello +hello +hello]] - feed [[gg]] - feed [[<C-v>j@w]] - eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, api.nvim_buf_get_lines(0, 0, -1, false)) + feed [[0<C-v>3jl@q]] + expect [[ +heFOOllo +heFOOllo +heFOOllo]] + + feed [[gg0<C-v>j@w]] + expect [[ +h123eFOOllo +h123eFOOllo +heFOOllo]] end) end) diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 6b20a736c0..69cb95e1c3 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -1,15 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local api = helpers.api -local clear = helpers.clear -local command = helpers.command -local fn = helpers.fn -local eq = helpers.eq -local feed = helpers.feed -local write_file = helpers.write_file -local pcall_err = helpers.pcall_err + +local api = n.api +local clear = n.clear +local command = n.command +local fn = n.fn +local eq = t.eq +local feed = n.feed +local write_file = t.write_file +local pcall_err = t.pcall_err local cursor = function() - return helpers.api.nvim_win_get_cursor(0) + return n.api.nvim_win_get_cursor(0) end describe('named marks', function() @@ -39,59 +41,59 @@ describe('named marks', function() it('errors when set out of range with :mark', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, '1000mark x') + local err = pcall_err(n.exec_capture, '1000mark x') eq('nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x', err) end) it('errors when set out of range with :k', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, '1000kx') + local err = pcall_err(n.exec_capture, '1000kx') eq('nvim_exec2(): Vim(k):E16: Invalid range: 1000kx', err) end) it('errors on unknown mark name with :mark', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'mark #') + local err = pcall_err(n.exec_capture, 'mark #') eq('nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote', err) end) it("errors on unknown mark name with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! '#") + local err = pcall_err(n.exec_capture, "normal! '#") eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it('errors on unknown mark name with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `#') + local err = pcall_err(n.exec_capture, 'normal! `#') eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it("errors when moving to a mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'z") + local err = pcall_err(n.exec_capture, "normal! 'z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(helpers.exec_capture, "normal! '.") + err = pcall_err(n.exec_capture, "normal! '.") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `z') + local err = pcall_err(n.exec_capture, 'normal! `z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(helpers.exec_capture, 'normal! `>') + err = pcall_err(n.exec_capture, 'normal! `>') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it("errors when moving to a global mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'Z") + local err = pcall_err(n.exec_capture, "normal! 'Z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a global mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(helpers.exec_capture, 'normal! `Z') + local err = pcall_err(n.exec_capture, 'normal! `Z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) @@ -166,7 +168,7 @@ describe('named marks', function() feed('mA') command('next') command('bw! ' .. file1) - local err = pcall_err(helpers.exec_capture, "normal! 'A") + local err = pcall_err(n.exec_capture, "normal! 'A") eq('nvim_exec2(): Vim(normal):E92: Buffer 1 not found', err) os.remove(file1) end) @@ -420,12 +422,12 @@ describe('named marks view', function() feed("<C-w>p'a") screen:expect([[ | - ~ |*3 - [No Name] | + {1:~ }|*3 + {2:[No Name] }| 6 line | ^7 line | 8 line | - {MATCH:.*marks} | + {3:<itor-marks }| | ]]) end) @@ -453,7 +455,7 @@ describe('named marks view', function() command('bwipe!') screen:expect([[ ^ | - ~ |*4 + {1:~ }|*4 | ]]) command('rshada!') diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index b57f5c3c35..87fe395608 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -1,11 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local command = helpers.command -local exec_lua = helpers.exec_lua -local eval = helpers.eval -local expect = helpers.expect -local fn = helpers.fn -local eq = helpers.eq +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear, feed, insert = n.clear, n.feed, n.insert +local command = n.command +local exec_lua = n.exec_lua +local eval = n.eval +local expect = n.expect +local fn = n.fn +local eq = t.eq describe('meta-keys #8226 #13042', function() before_each(function() @@ -141,4 +143,29 @@ describe('meta-keys #8226 #13042', function() // This is some text: bar // This is some text: baz]]) end) + + it('ALT/META with vim.on_key()', function() + feed('ifoo<CR>bar<CR>baz<Esc>gg0') + + exec_lua [[ + keys = {} + typed = {} + + vim.on_key(function(buf, typed_buf) + table.insert(keys, vim.fn.keytrans(buf)) + table.insert(typed, vim.fn.keytrans(typed_buf)) + end) + ]] + + -- <M-"> is reinterpreted as <Esc>" + feed('qrviw"ayc$FOO.<M-">apq') + expect([[ + FOO.foo + bar + baz]]) + + -- vim.on_key() callback should only receive <Esc>" + eq('qrviw"ayc$FOO.<Esc>"apq', exec_lua [[return table.concat(keys, '')]]) + eq('qrviw"ayc$FOO.<Esc>"apq', exec_lua [[return table.concat(typed, '')]]) + end) end) diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index 06efe53718..70bdc5d4c2 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -1,12 +1,13 @@ -- Cmdline-mode tests. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, insert, fn, eq, feed = - helpers.clear, helpers.insert, helpers.fn, helpers.eq, helpers.feed -local eval = helpers.eval -local command = helpers.command -local api = helpers.api + +local clear, insert, fn, eq, feed = n.clear, n.insert, n.fn, t.eq, n.feed +local eval = n.eval +local command = n.command +local api = n.api describe('cmdline', function() before_each(clear) diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index e96813b6f7..fb3dda4bf4 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -1,13 +1,16 @@ -- Insert-mode tests. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert -local expect = helpers.expect -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local curbuf_contents = helpers.curbuf_contents + +local clear, feed, insert = n.clear, n.feed, n.insert +local expect = n.expect +local command = n.command +local eq = t.eq +local eval = n.eval +local curbuf_contents = n.curbuf_contents +local api = n.api describe('insert-mode', function() before_each(function() @@ -51,43 +54,34 @@ describe('insert-mode', function() end) it('double quote is removed after hit-enter prompt #22609', function() - local screen = Screen.new(60, 6) - screen:set_default_attr_ids({ - [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText - [1] = { foreground = Screen.colors.Blue }, -- SpecialKey - [2] = { foreground = Screen.colors.SlateBlue }, - [3] = { bold = true }, -- ModeMsg - [4] = { reverse = true, bold = true }, -- MsgSeparator - [5] = { background = Screen.colors.Red, foreground = Screen.colors.White }, -- ErrorMsg - [6] = { foreground = Screen.colors.SeaGreen, bold = true }, -- MoreMsg - }) + local screen = Screen.new(50, 6) screen:attach() feed('i<C-R>') screen:expect([[ - {1:^"} | - {0:~ }|*4 - {3:-- INSERT --} | + {18:^"} | + {1:~ }|*4 + {5:-- INSERT --} | ]]) - feed('={}') + feed("=function('add')") screen:expect([[ - {1:"} | - {0:~ }|*4 - ={2:{}}^ | + {18:"} | + {1:~ }|*4 + ={25:function}{16:(}{26:'add'}{16:)}^ | ]]) feed('<CR>') screen:expect([[ - {1:"} | - {0:~ }| - {4: }| - ={2:{}} | - {5:E731: Using a Dictionary as a String} | - {6:Press ENTER or type command to continue}^ | + {18:"} | + {1:~ }| + {3: }| + ={25:function}{16:(}{26:'add'}{16:)} | + {9:E729: Using a Funcref as a String} | + {6:Press ENTER or type command to continue}^ | ]]) feed('<CR>') screen:expect([[ - ^ | - {0:~ }|*4 - {3:-- INSERT --} | + ^ | + {1:~ }|*4 + {5:-- INSERT --} | ]]) end) end) @@ -221,4 +215,146 @@ describe('insert-mode', function() ]], } end) + + describe('backspace', function() + local function set_lines(line_b, line_e, ...) + api.nvim_buf_set_lines(0, line_b, line_e, true, { ... }) + end + local function s(count) + return (' '):rep(count) + end + + local function test_cols(expected_cols) + local cols = { { n.fn.col('.'), n.fn.virtcol('.') } } + for _ = 2, #expected_cols do + feed('<BS>') + table.insert(cols, { n.fn.col('.'), n.fn.virtcol('.') }) + end + eq(expected_cols, cols) + end + + it('works with tabs and spaces', function() + local screen = Screen.new(30, 2) + screen:attach() + command('setl ts=4 sw=4') + set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') + feed('$i') + test_cols({ + { 18, 26 }, + { 17, 25 }, + { 15, 21 }, + { 11, 17 }, + { 7, 13 }, + { 6, 9 }, + { 2, 5 }, + { 1, 1 }, + }) + end) + + it('works with varsofttabstop', function() + local screen = Screen.new(30, 2) + screen:attach() + command('setl vsts=6,2,5,3') + set_lines(0, 1, 'a\t' .. s(4) .. '\t a') + feed('$i') + test_cols({ + { 9, 18 }, + { 8, 17 }, + { 8, 14 }, + { 3, 9 }, + { 7, 7 }, + { 2, 2 }, + { 1, 1 }, + }) + end) + + it('works with tab as ^I', function() + local screen = Screen.new(30, 2) + screen:attach() + command('set list listchars=space:.') + command('setl ts=4 sw=4') + set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') + feed('$i') + test_cols({ + { 18, 21 }, + { 15, 17 }, + { 11, 13 }, + { 7, 9 }, + { 4, 5 }, + { 1, 1 }, + }) + end) + + it('works in replace mode', function() + local screen = Screen.new(50, 2) + screen:attach() + command('setl ts=8 sw=8 sts=8') + set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') + feed('$R') + test_cols({ + { 18, 34 }, + { 17, 33 }, + { 15, 25 }, + { 7, 17 }, + { 2, 9 }, + { 1, 8 }, -- last screen cell of first tab is at vcol 8 + }) + end) + + it('works with breakindent', function() + local screen = Screen.new(17, 4) + screen:attach() + command('setl ts=4 sw=4 bri briopt=min:5') + set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') + feed('$i') + test_cols({ + { 18, 50 }, + { 17, 49 }, + { 15, 33 }, + { 11, 17 }, + { 7, 13 }, + { 6, 9 }, + { 2, 5 }, + { 1, 1 }, + }) + end) + + it('works with inline virtual text', function() + local screen = Screen.new(50, 2) + screen:attach() + command('setl ts=4 sw=4') + set_lines(0, 1, '\t' .. s(4) .. '\t' .. s(9) .. '\t a') + local ns = api.nvim_create_namespace('') + local vt_opts = { virt_text = { { 'text' } }, virt_text_pos = 'inline' } + api.nvim_buf_set_extmark(0, ns, 0, 2, vt_opts) + feed('$i') + test_cols({ + { 18, 30 }, + { 17, 29 }, + { 15, 25 }, + { 11, 21 }, + { 7, 17 }, + { 6, 13 }, + { 2, 9 }, + { 1, 5 }, + }) + end) + + it("works with 'revins'", function() + local screen = Screen.new(30, 3) + screen:attach() + command('setl ts=4 sw=4 revins') + set_lines(0, 1, ('a'):rep(16), s(3) .. '\t' .. s(4) .. '\t a') + feed('j$i') + test_cols({ + { 11, 14 }, + { 10, 13 }, + { 9, 9 }, + { 5, 5 }, + { 1, 1 }, + { 1, 1 }, -- backspace on empty line does nothing + }) + eq(2, api.nvim_win_get_cursor(0)[1]) + end) + end) end) diff --git a/test/functional/editor/mode_normal_spec.lua b/test/functional/editor/mode_normal_spec.lua index 89bab3f6c9..b3ef4866dc 100644 --- a/test/functional/editor/mode_normal_spec.lua +++ b/test/functional/editor/mode_normal_spec.lua @@ -1,11 +1,14 @@ -- Normal mode tests. -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local feed = helpers.feed -local fn = helpers.fn -local command = helpers.command -local eq = helpers.eq +local t = require('test.testutil') +local n = require('test.functional.testnvim')() +local Screen = require('test.functional.ui.screen') + +local clear = n.clear +local feed = n.feed +local fn = n.fn +local command = n.command +local eq = t.eq describe('Normal mode', function() before_each(clear) @@ -19,4 +22,23 @@ describe('Normal mode', function() feed('k') eq(pos, fn.getcurpos()) end) + + it('&showcmd does not crash with :startinsert #28419', function() + local screen = Screen.new(60, 17) + screen:attach() + fn.termopen( + { n.nvim_prog, '--clean', '--cmd', 'startinsert' }, + { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } } + ) + screen:expect({ + grid = [[ + ^ | + ~ |*13 + [No Name] 0,1 All| + -- INSERT -- | + | + ]], + attr_ids = {}, + }) + end) end) diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 414b289222..0f6936cd31 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -1,18 +1,19 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local insert = helpers.insert -local feed = helpers.feed -local expect = helpers.expect -local eq = helpers.eq +local clear = n.clear +local insert = n.insert +local feed = n.feed +local expect = n.expect +local eq = t.eq local map = vim.tbl_map local filter = vim.tbl_filter -local feed_command = helpers.feed_command -local command = helpers.command -local curbuf_contents = helpers.curbuf_contents -local fn = helpers.fn -local dedent = helpers.dedent +local feed_command = n.feed_command +local command = n.command +local curbuf_contents = n.curbuf_contents +local fn = n.fn +local dedent = t.dedent local function reset() command('bwipe! | new') @@ -75,7 +76,7 @@ describe('put command', function() extra_setup() end local orig_dotstr = fn.getreg('.') - helpers.ok(visual_marks_zero()) + t.ok(visual_marks_zero()) -- Make sure every test starts from the same conditions assert_no_change(test.exception_table, false) local was_cli = test.test_action() @@ -890,7 +891,7 @@ describe('put command', function() -- check bell is not set by nvim before the action screen:sleep(50) end - helpers.ok(not screen.bell and not screen.visualbell) + t.ok(not screen.bell and not screen.visualbell) actions() screen:expect { condition = function() diff --git a/test/functional/editor/search_spec.lua b/test/functional/editor/search_spec.lua index 46a3e298b7..770a4f387d 100644 --- a/test/functional/editor/search_spec.lua +++ b/test/functional/editor/search_spec.lua @@ -1,8 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local pcall_err = helpers.pcall_err +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command +local eq = t.eq +local pcall_err = t.pcall_err describe('search (/)', function() before_each(clear) diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 0cbc2dbf3d..0b26494436 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -1,17 +1,18 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local neq = helpers.neq -local feed = helpers.feed -local eval = helpers.eval -local exec = helpers.exec -local fn = helpers.fn -local api = helpers.api -local curwin = helpers.api.nvim_get_current_win -local assert_alive = helpers.assert_alive +local clear = n.clear +local command = n.command +local eq = t.eq +local neq = t.neq +local feed = n.feed +local eval = n.eval +local exec = n.exec +local fn = n.fn +local api = n.api +local curwin = n.api.nvim_get_current_win +local assert_alive = n.assert_alive describe('tabpage', function() before_each(clear) diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index c101bf02a0..12056394d2 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -1,16 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) - -local clear = helpers.clear -local command = helpers.command -local eval = helpers.eval -local expect = helpers.expect -local eq = helpers.eq -local feed = helpers.feed -local feed_command = helpers.feed_command -local insert = helpers.insert -local fn = helpers.fn -local exec = helpers.exec -local exec_lua = helpers.exec_lua +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command +local eval = n.eval +local expect = n.expect +local eq = t.eq +local feed = n.feed +local feed_command = n.feed_command +local insert = n.insert +local fn = n.fn +local exec = n.exec +local exec_lua = n.exec_lua local function lastmessage() local messages = fn.split(fn.execute('messages'), '\n') @@ -44,7 +45,7 @@ describe('u CTRL-R g- g+', function() local function undo_and_redo(hist_pos, undo, redo, expect_str) command('enew!') create_history(hist_pos) - local cur_contents = helpers.curbuf_contents() + local cur_contents = n.curbuf_contents() feed(undo) expect(expect_str) feed(redo) |