diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:18 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2024-01-03 02:09:29 +0100 |
commit | 04f2f864e270e772c6326cefdf24947f0130e492 (patch) | |
tree | 46f83f909b888a66c741032ab955afc6eab84292 /test/functional/editor | |
parent | 59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff) | |
download | rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2 rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip |
refactor: format test/*
Diffstat (limited to 'test/functional/editor')
-rw-r--r-- | test/functional/editor/K_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/editor/completion_spec.lua | 238 | ||||
-rw-r--r-- | test/functional/editor/ctrl_c_spec.lua | 28 | ||||
-rw-r--r-- | test/functional/editor/fold_spec.lua | 111 | ||||
-rw-r--r-- | test/functional/editor/jump_spec.lua | 162 | ||||
-rw-r--r-- | test/functional/editor/lang_spec.lua | 46 | ||||
-rw-r--r-- | test/functional/editor/langmap_spec.lua | 42 | ||||
-rw-r--r-- | test/functional/editor/macro_spec.lua | 64 | ||||
-rw-r--r-- | test/functional/editor/mark_spec.lua | 382 | ||||
-rw-r--r-- | test/functional/editor/meta_key_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/editor/mode_cmdline_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/editor/mode_insert_spec.lua | 34 | ||||
-rw-r--r-- | test/functional/editor/put_spec.lua | 305 | ||||
-rw-r--r-- | test/functional/editor/search_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/editor/tabpage_spec.lua | 31 | ||||
-rw-r--r-- | test/functional/editor/undo_spec.lua | 34 |
16 files changed, 817 insertions, 702 deletions
diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index b964fb3467..92a00b28b6 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -30,13 +30,15 @@ describe('K', function() set keywordprg=echo\ fnord>>]]) -- K on the text "K_spec_out" resolves to `!echo fnord >> K_spec_out`. - feed('i'..test_file..'<ESC>K') - retry(nil, nil, function() eq(1, eval('filereadable("'..test_file..'")')) end) - eq({'fnord'}, eval("readfile('"..test_file.."')")) + feed('i' .. test_file .. '<ESC>K') + retry(nil, nil, function() + eq(1, eval('filereadable("' .. test_file .. '")')) + end) + eq({ 'fnord' }, eval("readfile('" .. test_file .. "')")) -- Confirm that Neovim is still in terminal mode after K is pressed (#16692). helpers.sleep(500) eq('t', eval('mode()')) - feed('<space>') -- Any key, not just <space>, can be used here to escape. + feed('<space>') -- Any key, not just <space>, can be used here to escape. eq('n', eval('mode()')) end) @@ -60,9 +62,8 @@ describe('K', function() it('empty string falls back to :help #19298', function() meths.set_option_value('keywordprg', '', {}) - meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'}) + meths.buf_set_lines(0, 0, -1, true, { 'doesnotexist' }) feed('K') eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg')) end) - end) diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 8f14a2db83..fbb63fdba6 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -18,17 +18,17 @@ describe('completion', function() screen = Screen.new(60, 8) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {background = Screen.colors.LightMagenta}, - [2] = {background = Screen.colors.Grey}, - [3] = {bold = true}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen}, - [5] = {foreground = Screen.colors.Red}, - [6] = {background = Screen.colors.Black}, - [7] = {foreground = Screen.colors.White, background = Screen.colors.Red}, - [8] = {reverse = true}, - [9] = {bold = true, reverse = true}, - [10] = {foreground = Screen.colors.Grey0, background = Screen.colors.Yellow}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.LightMagenta }, + [2] = { background = Screen.colors.Grey }, + [3] = { bold = true }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen }, + [5] = { foreground = Screen.colors.Red }, + [6] = { background = Screen.colors.Black }, + [7] = { foreground = Screen.colors.White, background = Screen.colors.Red }, + [8] = { reverse = true }, + [9] = { bold = true, reverse = true }, + [10] = { foreground = Screen.colors.Grey0, background = Screen.colors.Yellow }, }) end) @@ -57,9 +57,10 @@ describe('completion', function() it('returns expected dict in normal completion', function() feed('ifoo<ESC>o<C-x><C-n>') eq('foo', eval('getline(2)')) - eq({word = 'foo', abbr = '', menu = '', - info = '', kind = '', user_data = ''}, - eval('v:completed_item')) + eq( + { word = 'foo', abbr = '', menu = '', info = '', kind = '', user_data = '' }, + eval('v:completed_item') + ) end) it('is readonly', function() screen:try_resize(80, 8) @@ -107,9 +108,14 @@ describe('completion', function() {0:~ }|*4 {3:-- Omni completion (^O^N^P) }{4:match 1 of 2} | ]]) - eq({word = 'foo', abbr = 'bar', menu = 'baz', - info = 'foobar', kind = 'foobaz', user_data = ''}, - eval('v:completed_item')) + eq({ + word = 'foo', + abbr = 'bar', + menu = 'baz', + info = 'foobar', + kind = 'foobaz', + user_data = '', + }, eval('v:completed_item')) end) end) @@ -286,8 +292,8 @@ describe('completion', function() end) local tests = { - ['<up>, <down>, <cr>'] = {'<down><cr>', '<up><cr>'}, - ['<c-n>, <c-p>, <c-y>'] = {'<c-n><c-y>', '<c-p><c-y>'}, + ['<up>, <down>, <cr>'] = { '<down><cr>', '<up><cr>' }, + ['<c-n>, <c-p>, <c-y>'] = { '<c-n><c-y>', '<c-p><c-y>' }, } for name, seq in pairs(tests) do @@ -303,13 +309,13 @@ describe('completion', function() feed('A<right><esc>A<right><esc>') local expected = { - {'foo', 'bar', 'foo'}, - {'foo', 'bar', 'ccc'}, - {'foo', 'bar'}, - {'foo', 'bbb'}, - {'foo'}, - {'aaa'}, - {''}, + { 'foo', 'bar', 'foo' }, + { 'foo', 'bar', 'ccc' }, + { 'foo', 'bar' }, + { 'foo', 'bbb' }, + { 'foo' }, + { 'aaa' }, + { '' }, } for i = 1, #expected do @@ -329,7 +335,7 @@ describe('completion', function() end end) - describe("refresh:always", function() + describe('refresh:always', function() before_each(function() source([[ function! TestCompletion(findstart, base) abort @@ -354,9 +360,9 @@ describe('completion', function() set completeopt=menuone,noselect set completefunc=TestCompletion ]]) - end ) + end) - it('completes on each input char', function () + it('completes on each input char', function() feed('i<C-x><C-u>') screen:expect([[ ^ | @@ -402,7 +408,7 @@ describe('completion', function() expect('August') end) - it("repeats correctly after backspace #2674", function () + it('repeats correctly after backspace #2674', function() feed('o<C-x><C-u>Ja') screen:expect([[ | @@ -471,10 +477,10 @@ describe('completion', function() return '' endfunction ]]) - feed_command("set completeopt=menuone,noselect") + feed_command('set completeopt=menuone,noselect') end) - it("works", function() + it('works', function() feed('i<C-r>=TestComplete()<CR>') screen:expect([[ ^ | @@ -630,7 +636,7 @@ describe('completion', function() end) end) - it("does not indent until an item is selected #8345", function () + it('does not indent until an item is selected #8345', function() -- Indents on "ind", unindents on "unind". source([[ function! TestIndent() @@ -649,14 +655,14 @@ describe('completion', function() ]]) -- Give some words to complete. - feed("iinc uninc indent unindent<CR>") + feed('iinc uninc indent unindent<CR>') -- Does not indent when "ind" is typed. - feed("in<C-X><C-N>") + feed('in<C-X><C-N>') -- Completion list is generated incorrectly if we send everything at once -- via nvim_input(). So poke_eventloop() before sending <BS>. #8480 poke_eventloop() - feed("<BS>d") + feed('<BS>d') screen:expect([[ inc uninc indent unindent | @@ -667,7 +673,7 @@ describe('completion', function() ]]) -- Indents when the item is selected - feed("<C-Y>") + feed('<C-Y>') screen:expect([[ inc uninc indent unindent | indent^ | @@ -675,7 +681,7 @@ describe('completion', function() {3:-- INSERT --} | ]]) -- Indents when completion is exited using ESC. - feed("<CR>in<C-N><BS>d<Esc>") + feed('<CR>in<C-N><BS>d<Esc>') screen:expect([[ inc uninc indent unindent | indent | @@ -684,9 +690,9 @@ describe('completion', function() | ]]) -- Works for unindenting too. - feed("ounin<C-X><C-N>") + feed('ounin<C-X><C-N>') helpers.poke_eventloop() - feed("<BS>d") + feed('<BS>d') screen:expect([[ inc uninc indent unindent | indent | @@ -697,7 +703,7 @@ describe('completion', function() {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) -- Works when going back and forth. - feed("<BS>c") + feed('<BS>c') screen:expect([[ inc uninc indent unindent | indent | @@ -707,7 +713,7 @@ describe('completion', function() {0:~ }|*2 {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) - feed("<BS>d") + feed('<BS>d') screen:expect([[ inc uninc indent unindent | indent | @@ -717,7 +723,7 @@ describe('completion', function() {0:~ }|*2 {3:-- Keyword Local completion (^N^P) }{4:match 1 of 2} | ]]) - feed("<C-N><C-N><C-Y><Esc>") + feed('<C-N><C-N><C-Y><Esc>') screen:expect([[ inc uninc indent unindent | indent | @@ -728,8 +734,8 @@ describe('completion', function() ]]) end) - it('disables folding during completion', function () - feed_command("set foldmethod=indent") + it('disables folding during completion', function() + feed_command('set foldmethod=indent') feed('i<Tab>foo<CR><Tab>bar<Esc>gg') screen:expect([[ ^foo | @@ -747,8 +753,8 @@ describe('completion', function() eq(-1, eval('foldclosed(1)')) end) - it('popupmenu is not interrupted by events', function () - feed_command("set complete=.") + it('popupmenu is not interrupted by events', function() + feed_command('set complete=.') feed('ifoobar fooegg<cr>f<c-p>') screen:expect([[ @@ -762,14 +768,17 @@ describe('completion', function() assert_alive() -- popupmenu still visible - screen:expect{grid=[[ + screen:expect { + grid = [[ foobar fooegg | fooegg^ | {1:foobar }{0: }| {2:fooegg }{0: }| {0:~ }|*3 {3:-- Keyword completion (^N^P) }{4:match 1 of 2} | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<c-p>') -- Didn't restart completion: old matches still used @@ -787,47 +796,52 @@ describe('completion', function() it('expands when there is only one match', function() feed(':lua CURRENT_TESTING_VAR = 1<CR>') feed(':lua CURRENT_TESTING_<TAB>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }|*6 :lua CURRENT_TESTING_VAR^ | - ]]} + ]], + } end) it('expands when there is only one match', function() feed(':lua CURRENT_TESTING_FOO = 1<CR>') feed(':lua CURRENT_TESTING_BAR = 1<CR>') feed(':lua CURRENT_TESTING_<TAB>') - screen:expect{ grid = [[ + screen:expect { + grid = [[ | {0:~ }|*5 {10:CURRENT_TESTING_BAR}{9: CURRENT_TESTING_FOO }| :lua CURRENT_TESTING_BAR^ | - ]], unchanged = true } + ]], + unchanged = true, + } end) it('provides completion from `getcompletion()`', function() - eq({'vim'}, funcs.getcompletion('vi', 'lua')) - eq({'api'}, funcs.getcompletion('vim.ap', 'lua')) - eq({'tbl_filter'}, funcs.getcompletion('vim.tbl_fil', 'lua')) - eq({'vim'}, funcs.getcompletion('print(vi', 'lua')) + eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) + eq({ 'api' }, funcs.getcompletion('vim.ap', 'lua')) + eq({ 'tbl_filter' }, funcs.getcompletion('vim.tbl_fil', 'lua')) + eq({ 'vim' }, funcs.getcompletion('print(vi', 'lua')) -- fuzzy completion is not supported, so the result should be the same command('set wildoptions+=fuzzy') - eq({'vim'}, funcs.getcompletion('vi', 'lua')) + eq({ 'vim' }, funcs.getcompletion('vi', 'lua')) end) end) it('cmdline completion supports various string options', function() eq('auto', funcs.getcompletion('set foldcolumn=', 'cmdline')[2]) - eq({'nosplit', 'split'}, funcs.getcompletion('set inccommand=', 'cmdline')) - eq({'ver:3,hor:6', 'hor:', 'ver:'}, funcs.getcompletion('set mousescroll=', 'cmdline')) + eq({ 'nosplit', 'split' }, funcs.getcompletion('set inccommand=', 'cmdline')) + eq({ 'ver:3,hor:6', 'hor:', 'ver:' }, funcs.getcompletion('set mousescroll=', 'cmdline')) eq('BS', funcs.getcompletion('set termpastefilter=', 'cmdline')[2]) eq('SpecialKey', funcs.getcompletion('set winhighlight=', 'cmdline')[1]) eq('SpecialKey', funcs.getcompletion('set winhighlight=NonText:', 'cmdline')[1]) end) describe('from the commandline window', function() - it('is cleared after CTRL-C', function () + it('is cleared after CTRL-C', function() feed('q:') feed('ifoo faa fee f') screen:expect([[ @@ -837,7 +851,7 @@ describe('completion', function() {0:~ }|*3 {9:[Command Line] }| {3:-- INSERT --} | - ]] ) + ]]) feed('<c-x><c-n>') screen:expect([[ | @@ -870,16 +884,18 @@ describe('completion', function() endfunction ]]) meths.set_option_value('completeopt', 'menuone,noselect', {}) - meths.set_var('_complist', {{ - word=0, - abbr=1, - menu=2, - kind=3, - info=4, - icase=5, - dup=6, - empty=7, - }}) + meths.set_var('_complist', { + { + word = 0, + abbr = 1, + menu = 2, + kind = 3, + info = 4, + icase = 5, + dup = 6, + empty = 7, + }, + }) end) it('shows correct variant as word', function() @@ -897,7 +913,8 @@ describe('completion', function() feed_command('set ignorecase infercase') feed_command('edit runtime/doc/backers.txt') feed('oX<C-X><C-N>') - screen:expect{grid=[[ + screen:expect { + grid = [[ *backers.txt* Nvim | Xnull^ | {2:Xnull }{6: } | @@ -906,11 +923,12 @@ describe('completion', function() {1:Xpayn }{2: } | {1:Xinity }{2: } | {3:-- Keyword Local completion (^N^P) }{4:match 1 of 7} | - ]]} + ]], + } end) it('CompleteChanged autocommand', function() - curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', ''}) + curbufmeths.set_lines(0, 1, false, { 'foo', 'bar', 'foobar', '' }) source([[ set complete=. completeopt=noinsert,noselect,menuone function! OnPumChange() @@ -925,39 +943,45 @@ describe('completion', function() -- v:event.size should be set with ext_popupmenu #20646 screen:set_option('ext_popupmenu', true) feed('Sf<C-N>') - screen:expect({grid = [[ + screen:expect({ + grid = [[ foo | bar | foobar | f^ | {0:~ }|*3 {3:-- Keyword completion (^N^P) }{5:Back at original} | - ]], popupmenu = { - anchor = { 1, 3, 0 }, - items = { { "foo", "", "", "" }, { "foobar", "", "", "" } }, - pos = -1 - }}) - eq({completed_item = {}, width = 0, - height = 2, size = 2, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + ]], + popupmenu = { + anchor = { 1, 3, 0 }, + items = { { 'foo', '', '', '' }, { 'foobar', '', '', '' } }, + pos = -1, + }, + }) + eq( + { completed_item = {}, width = 0, height = 2, size = 2, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('oob') - screen:expect({grid = [[ + screen:expect({ + grid = [[ foo | bar | foobar | foob^ | {0:~ }|*3 {3:-- Keyword completion (^N^P) }{5:Back at original} | - ]], popupmenu = { - anchor = { 1, 3, 0 }, - items = { { "foobar", "", "", "" } }, - pos = -1 - }}) - eq({completed_item = {}, width = 0, - height = 1, size = 1, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + ]], + popupmenu = { + anchor = { 1, 3, 0 }, + items = { { 'foobar', '', '', '' } }, + pos = -1, + }, + }) + eq( + { completed_item = {}, width = 0, height = 1, size = 1, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('<Esc>') screen:set_option('ext_popupmenu', false) @@ -972,10 +996,10 @@ describe('completion', function() {0:~ }| {3:-- Keyword completion (^N^P) }{5:Back at original} | ]]) - eq({completed_item = {}, width = 15, - height = 2, size = 2, - col = 0, row = 4, scrollbar = false}, - eval('g:event')) + eq( + { completed_item = {}, width = 15, height = 2, size = 2, col = 0, row = 4, scrollbar = false }, + eval('g:event') + ) feed('<C-N>') screen:expect([[ foo | @@ -1028,7 +1052,7 @@ describe('completion', function() end) it('is stopped by :stopinsert from timer #12976', function() - screen:try_resize(32,14) + screen:try_resize(32, 14) command([[call setline(1, ['hello', 'hullo', 'heeee', ''])]]) feed('Gah<c-x><c-n>') screen:expect([[ @@ -1044,7 +1068,7 @@ describe('completion', function() ]]) command([[call timer_start(100, { -> execute('stopinsert') })]]) helpers.sleep(200) - feed('k') -- cursor should move up in Normal mode + feed('k') -- cursor should move up in Normal mode screen:expect([[ hello | hullo | @@ -1084,7 +1108,8 @@ describe('completion', function() screen:try_resize(20, 9) command('set complete+=f | edit foo | edit bar |edit foa |edit .hidden') feed('i<C-n>') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo^ | {2:foo }{0: }| {1:bar }{0: }| @@ -1092,15 +1117,18 @@ describe('completion', function() {1:.hidden }{0: }| {0:~ }|*3 {3:-- }{4:match 1 of 4} | - ]]} + ]], + } feed('<Esc>ccf<C-n>') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo^ | {2:foo }{0: }| {1:foa }{0: }| {0:~ }|*5 {3:-- }{4:match 1 of 2} | - ]]} + ]], + } end) it('restores extmarks if original text is restored #23653', function() diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index c399a35462..0321a21b35 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -5,7 +5,7 @@ local command = helpers.command local poke_eventloop = helpers.poke_eventloop local sleep = helpers.sleep -describe("CTRL-C (mapped)", function() +describe('CTRL-C (mapped)', function() local screen before_each(function() @@ -14,7 +14,7 @@ describe("CTRL-C (mapped)", function() screen:attach() end) - it("interrupts :global", function() + it('interrupts :global', function() -- Crashes luajit. if helpers.skip_fragile(pending) then return @@ -25,7 +25,7 @@ describe("CTRL-C (mapped)", function() nnoremap <C-C> <NOP> ]]) - command("silent edit! test/functional/fixtures/bigfile.txt") + command('silent edit! test/functional/fixtures/bigfile.txt') screen:expect([[ ^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; | @@ -37,19 +37,21 @@ describe("CTRL-C (mapped)", function() ]]) local function test_ctrl_c(ms) - feed(":global/^/p<CR>") + feed(':global/^/p<CR>') screen:sleep(ms) - feed("<C-C>") - screen:expect{any="Interrupt"} + feed('<C-C>') + screen:expect { any = 'Interrupt' } end -- The test is time-sensitive. Try different sleep values. - local ms_values = {100, 1000, 10000} + local ms_values = { 100, 1000, 10000 } for i, ms in ipairs(ms_values) do if i < #ms_values then local status, _ = pcall(test_ctrl_c, ms) - if status then break end - else -- Call the last attempt directly. + if status then + break + end + else -- Call the last attempt directly. test_ctrl_c(ms) end end @@ -58,9 +60,9 @@ describe("CTRL-C (mapped)", function() it('interrupts :sleep', function() command('nnoremap <C-C> <Nop>') feed(':sleep 100<CR>') - poke_eventloop() -- wait for :sleep to start + poke_eventloop() -- wait for :sleep to start feed('foo<C-C>') - poke_eventloop() -- wait for input buffer to be flushed + poke_eventloop() -- wait for input buffer to be flushed feed('i') screen:expect([[ ^ | @@ -73,9 +75,9 @@ describe("CTRL-C (mapped)", function() command('nnoremap <C-C> <Nop>') command('nmap <F2> <Ignore><F2>') feed('<F2>') - sleep(10) -- wait for the key to enter typeahead + sleep(10) -- wait for the key to enter typeahead feed('foo<C-C>') - poke_eventloop() -- wait for input buffer to be flushed + poke_eventloop() -- wait for input buffer to be flushed feed('i') screen:expect([[ ^ | diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua index 424ce839a2..3889067fd4 100644 --- a/test/functional/editor/fold_spec.lua +++ b/test/functional/editor/fold_spec.lua @@ -13,8 +13,12 @@ describe('Folds', function() local tempfname = 'Xtest-fold.txt' setup(clear) - before_each(function() command('bwipe! | new') end) - after_each(function() os.remove(tempfname) end) + before_each(function() + command('bwipe! | new') + end) + after_each(function() + os.remove(tempfname) + end) it('manual folding adjusts with filter', function() insert([[ @@ -94,7 +98,8 @@ describe('Folds', function() end it('neither closes nor corrupts folds', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -112,7 +117,9 @@ a a a a - a]], '7,12m0') + a]], + '7,12m0' + ) expect([[ a a @@ -133,7 +140,7 @@ a a a]]) -- lines are not closed, folds are correct - for i = 1,funcs.line('$') do + for i = 1, funcs.line('$') do eq(-1, funcs.foldclosed(i)) if i == 1 or i == 7 or i == 13 then eq(0, funcs.foldlevel(i)) @@ -151,7 +158,8 @@ a end) it("doesn't split a fold when the move is within it", function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -161,24 +169,30 @@ a a a a -a]], '5m6') - eq({0, 1, 1, 2, 2, 2, 2, 1, 1, 0}, get_folds()) +a]], + '5m6' + ) + eq({ 0, 1, 1, 2, 2, 2, 2, 1, 1, 0 }, get_folds()) end) it('truncates folds that end in the moved range', function() - test_move_indent([[ + test_move_indent( + [[ a a a a a a -a]], '4,5m6') - eq({0, 1, 2, 0, 0, 0, 0}, get_folds()) +a]], + '4,5m6' + ) + eq({ 0, 1, 2, 0, 0, 0, 0 }, get_folds()) end) it('moves folds that start between moved range and destination', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -191,12 +205,15 @@ a a a a - a]], '3,4m$') - eq({0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0}, get_folds()) + a]], + '3,4m$' + ) + eq({ 0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 0, 0 }, get_folds()) end) it('does not affect folds outside changed lines', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -205,12 +222,15 @@ a a a a - a]], '4m5') - eq({1, 1, 1, 0, 0, 0, 1, 1, 1}, get_folds()) + a]], + '4m5' + ) + eq({ 1, 1, 1, 0, 0, 0, 1, 1, 1 }, get_folds()) end) it('moves and truncates folds that start in moved range', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -220,34 +240,43 @@ a a a a -a]], '1,3m7') - eq({0, 0, 0, 0, 0, 1, 2, 0, 0, 0}, get_folds()) +a]], + '1,3m7' + ) + eq({ 0, 0, 0, 0, 0, 1, 2, 0, 0, 0 }, get_folds()) end) it('breaks a fold when moving text into it', function() - test_move_indent([[ + test_move_indent( + [[ a a a a a a -a]], '$m4') - eq({0, 1, 2, 2, 0, 0, 0}, get_folds()) +a]], + '$m4' + ) + eq({ 0, 1, 2, 2, 0, 0, 0 }, get_folds()) end) it('adjusts correctly when moving a range backwards', function() - test_move_indent([[ + test_move_indent( + [[ a a a a -a]], '2,3m0') - eq({1, 2, 0, 0, 0}, get_folds()) +a]], + '2,3m0' + ) + eq({ 1, 2, 0, 0, 0 }, get_folds()) end) it('handles shifting all remaining folds', function() - test_move_indent([[ + test_move_indent( + [[ a a a @@ -262,18 +291,23 @@ a]], '2,3m0') a a a -a]], '13m7') - eq({1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0}, get_folds()) +a]], + '13m7' + ) + eq({ 1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0 }, get_folds()) end) end) it('updates correctly on :read', function() -- luacheck: ignore 621 - helpers.write_file(tempfname, [[ + helpers.write_file( + tempfname, + [[ a - a]]) + a]] + ) insert([[ a a @@ -295,13 +329,13 @@ a]], '13m7') a a ]]) - for i = 1,2 do + for i = 1, 2 do eq(1, funcs.foldlevel(i)) end - for i = 3,5 do + for i = 3, 5 do eq(0, funcs.foldlevel(i)) end - for i = 6,8 do + for i = 6, 8 do eq(1, funcs.foldlevel(i)) end end) @@ -356,7 +390,9 @@ a]], '13m7') return 0 endfunction ]]) - helpers.write_file(tempfname, [[ + helpers.write_file( + tempfname, + [[ b b a @@ -364,7 +400,8 @@ a]], '13m7') d a a - c]]) + c]] + ) insert([[ a a @@ -388,7 +425,7 @@ a]], '13m7') it('no folds remain if :delete makes buffer empty #19671', function() command('setlocal foldmethod=manual') - funcs.setline(1, {'foo', 'bar', 'baz'}) + funcs.setline(1, { 'foo', 'bar', 'baz' }) command('2,3fold') command('%delete') eq(0, funcs.foldlevel(1)) diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index dc056cb252..e063924018 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -12,7 +12,7 @@ local curbufmeths = helpers.curbufmeths describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' - local fname2 = fname1..'2' + local fname2 = fname1 .. '2' before_each(clear) after_each(function() os.remove(fname1) @@ -27,7 +27,7 @@ describe('jumplist', function() write_file(fname1, 'first file contents') write_file(fname2, 'second file contents') - command('args '..fname1..' '..fname2) + command('args ' .. fname1 .. ' ' .. fname2) local buf1 = funcs.bufnr(fname1) local buf2 = funcs.bufnr(fname2) @@ -44,7 +44,7 @@ describe('jumplist', function() feed('<C-O>') eq(buf1, funcs.bufnr('%')) - command('drop '..fname2) + command('drop ' .. fname2) feed('<C-O>') eq(buf1, funcs.bufnr('%')) end) @@ -56,11 +56,12 @@ describe('jumplist', function() local screen = Screen.new(5, 25) screen:attach() command('set number') - command('edit '..fname1) + command('edit ' .. fname1) feed('35gg') - command('edit '..fname2) + command('edit ' .. fname2) feed('<C-O>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: 24 }foobar | {1: 25 }foobar | {1: 26 }foobar | @@ -86,9 +87,11 @@ describe('jumplist', function() {1: 46 }foobar | {1: 47 }foobar | | - ]], attr_ids={ - [1] = {foreground = Screen.colors.Brown}; - }} + ]], + attr_ids = { + [1] = { foreground = Screen.colors.Brown }, + }, + } end) end) @@ -98,9 +101,8 @@ describe("jumpoptions=stack behaves like 'tagstack'", function() feed(':clearjumps<cr>') -- Add lines so that we have locations to jump to. - for i = 1,101,1 - do - feed('iLine ' .. i .. '<cr><esc>') + for i = 1, 101, 1 do + feed('iLine ' .. i .. '<cr><esc>') end -- Jump around to add some locations to the jump list. @@ -115,82 +117,90 @@ describe("jumpoptions=stack behaves like 'tagstack'", function() end) after_each(function() - feed('set jumpoptions=') + feed('set jumpoptions=') end) it('discards the tail when navigating from the middle', function() feed('<C-O>') feed('<C-O>') - eq( '' - .. ' jump line col file/text\n' - .. ' 4 102 0 \n' - .. ' 3 1 0 Line 1\n' - .. ' 2 10 0 Line 10\n' - .. ' 1 20 0 Line 20\n' - .. '> 0 30 0 Line 30\n' - .. ' 1 40 0 Line 40\n' - .. ' 2 50 0 Line 50', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 4 102 0 \n' + .. ' 3 1 0 Line 1\n' + .. ' 2 10 0 Line 10\n' + .. ' 1 20 0 Line 20\n' + .. '> 0 30 0 Line 30\n' + .. ' 1 40 0 Line 40\n' + .. ' 2 50 0 Line 50', + exec_capture('jumps') + ) feed('90gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 5 102 0 \n' - .. ' 4 1 0 Line 1\n' - .. ' 3 10 0 Line 10\n' - .. ' 2 20 0 Line 20\n' - .. ' 1 30 0 Line 30\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 5 102 0 \n' + .. ' 4 1 0 Line 1\n' + .. ' 3 10 0 Line 10\n' + .. ' 2 20 0 Line 20\n' + .. ' 1 30 0 Line 30\n' + .. '>', + exec_capture('jumps') + ) end) it('does not add the same location twice adjacently', function() feed('60gg') feed('60gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 7 102 0 \n' - .. ' 6 1 0 Line 1\n' - .. ' 5 10 0 Line 10\n' - .. ' 4 20 0 Line 20\n' - .. ' 3 30 0 Line 30\n' - .. ' 2 40 0 Line 40\n' - .. ' 1 50 0 Line 50\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 7 102 0 \n' + .. ' 6 1 0 Line 1\n' + .. ' 5 10 0 Line 10\n' + .. ' 4 20 0 Line 20\n' + .. ' 3 30 0 Line 30\n' + .. ' 2 40 0 Line 40\n' + .. ' 1 50 0 Line 50\n' + .. '>', + exec_capture('jumps') + ) end) it('does add the same location twice nonadjacently', function() feed('10gg') feed('20gg') - eq( '' - .. ' jump line col file/text\n' - .. ' 8 102 0 \n' - .. ' 7 1 0 Line 1\n' - .. ' 6 10 0 Line 10\n' - .. ' 5 20 0 Line 20\n' - .. ' 4 30 0 Line 30\n' - .. ' 3 40 0 Line 40\n' - .. ' 2 50 0 Line 50\n' - .. ' 1 10 0 Line 10\n' - .. '>', - exec_capture('jumps')) + eq( + '' + .. ' jump line col file/text\n' + .. ' 8 102 0 \n' + .. ' 7 1 0 Line 1\n' + .. ' 6 10 0 Line 10\n' + .. ' 5 20 0 Line 20\n' + .. ' 4 30 0 Line 30\n' + .. ' 3 40 0 Line 40\n' + .. ' 2 50 0 Line 50\n' + .. ' 1 10 0 Line 10\n' + .. '>', + exec_capture('jumps') + ) end) end) -describe("jumpoptions=view", function() +describe('jumpoptions=view', function() local file1 = 'Xtestfile-functional-editor-jumps' local file2 = 'Xtestfile-functional-editor-jumps-2' local function content() local c = {} - for i=1,30 do - c[i] = i .. " line" + for i = 1, 30 do + c[i] = i .. ' line' end - return table.concat(c, "\n") + return table.concat(c, '\n') end before_each(function() clear() @@ -206,9 +216,9 @@ describe("jumpoptions=view", function() it('restores the view', function() local screen = Screen.new(5, 8) screen:attach() - command("edit " .. file1) - feed("12Gztj") - feed("gg<C-o>") + command('edit ' .. file1) + feed('12Gztj') + feed('gg<C-o>') screen:expect([[ 12 line | ^13 line | @@ -224,10 +234,10 @@ describe("jumpoptions=view", function() it('restores the view across files', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("12Gzt") - command("next") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('12Gzt') + command('next') + feed('G') screen:expect([[ 27 line | 28 line | @@ -235,7 +245,7 @@ describe("jumpoptions=view", function() ^30 line | | ]]) - feed("<C-o><C-o>") + feed('<C-o><C-o>') screen:expect([[ ^12 line | 13 line | @@ -248,10 +258,10 @@ describe("jumpoptions=view", function() it('restores the view across files with <C-^>', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("12Gzt") - command("next") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('12Gzt') + command('next') + feed('G') screen:expect([[ 27 line | 28 line | @@ -259,7 +269,7 @@ describe("jumpoptions=view", function() ^30 line | | ]]) - feed("<C-^>") + feed('<C-^>') screen:expect([[ ^12 line | 13 line | @@ -269,11 +279,11 @@ describe("jumpoptions=view", function() ]]) end) - it('falls back to standard behavior when view can\'t be recovered', function() + it("falls back to standard behavior when view can't be recovered", function() local screen = Screen.new(5, 8) screen:attach() - command("edit " .. file1) - feed("7GzbG") + command('edit ' .. file1) + feed('7GzbG') curbufmeths.set_lines(0, 2, true, {}) -- Move to line 7, and set it as the last line visible on the view with zb, meaning to recover -- the view it needs to put the cursor 7 lines from the top line. Then go to the end of the @@ -281,7 +291,7 @@ describe("jumpoptions=view", function() -- Therefore when trying to jump back to it it's not possible to set a 7 line offset from the -- mark position to the top line, since there's only 5 lines from the mark position to line 0. -- Therefore falls back to standard behavior which is centering the view/line. - feed("<C-o>") + feed('<C-o>') screen:expect([[ 4 line | 5 line | diff --git a/test/functional/editor/lang_spec.lua b/test/functional/editor/lang_spec.lua index 24d1262f5f..ee7cfac057 100644 --- a/test/functional/editor/lang_spec.lua +++ b/test/functional/editor/lang_spec.lua @@ -9,11 +9,11 @@ describe('gu and gU', function() it('works in any locale with default casemap', function() eq('internal,keepascii', eval('&casemap')) - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') end) describe('works in Turkish locale', function() @@ -21,7 +21,7 @@ describe('gu and gU', function() local err = exc_exec('lang ctype tr_TR.UTF-8') if err ~= 0 then - pending("Locale tr_TR.UTF-8 not supported", function() end) + pending('Locale tr_TR.UTF-8 not supported', function() end) return end @@ -32,29 +32,29 @@ describe('gu and gU', function() it('with default casemap', function() eq('internal,keepascii', eval('&casemap')) -- expect ASCII behavior - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') end) it('with casemap=""', function() command('set casemap=') -- expect either Turkish locale behavior or ASCII behavior local iupper = eval("toupper('i')") - if iupper == "İ" then - insert("iI") - feed("VgU") - expect("İI") - feed("Vgu") - expect("iı") - elseif iupper == "I" then - insert("iI") - feed("VgU") - expect("II") - feed("Vgu") - expect("ii") + if iupper == 'İ' then + insert('iI') + feed('VgU') + expect('İI') + feed('Vgu') + expect('iı') + elseif iupper == 'I' then + insert('iI') + feed('VgU') + expect('II') + feed('Vgu') + expect('ii') else error("expected toupper('i') to be either 'I' or 'İ'") end diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index b1070ecddc..e697140889 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -14,13 +14,13 @@ describe("'langmap'", function() feed('gg0') end) - it("converts keys in normal mode", function() + it('converts keys in normal mode', function() feed('ix') expect('iii ww') feed('whello<esc>') expect('iii helloww') end) - it("gives characters that are mapped by :nmap.", function() + it('gives characters that are mapped by :nmap.', function() command('map i 0x') feed('w') expect('ii www') @@ -32,20 +32,18 @@ describe("'langmap'", function() it("'langnoremap' is by default ON", function() eq(1, eval('&langnoremap')) end) - it("Results of maps are not converted when 'langnoremap' ON.", - function() + it("Results of maps are not converted when 'langnoremap' ON.", function() command('nmap x i') feed('xdl<esc>') expect('dliii www') end) - it("applies when deciding whether to map recursively", function() + it('applies when deciding whether to map recursively', function() command('nmap l i') command('nmap w j') feed('ll') expect('liii www') end) - it("does not stop applying 'langmap' on first character of a mapping", - function() + it("does not stop applying 'langmap' on first character of a mapping", function() command('1t1') command('1t1') command('goto 1') @@ -56,8 +54,7 @@ describe("'langmap'", function() iii www ihelloii www]]) end) - it("Results of maps are converted when 'langnoremap' OFF.", - function() + it("Results of maps are converted when 'langnoremap' OFF.", function() command('set nolangnoremap') command('nmap x i') feed('xdl<esc>') @@ -65,8 +62,7 @@ describe("'langmap'", function() end) end) -- e.g. CTRL-W_j , mj , 'j and "jp - it('conversions are applied to keys in middle of command', - function() + it('conversions are applied to keys in middle of command', function() -- Works in middle of window command feed('<C-w>s') local origwin = curwin() @@ -74,12 +70,12 @@ describe("'langmap'", function() neq(origwin, curwin()) -- Works when setting a mark feed('yy3p3gg0mwgg0mi') - eq({0, 3, 1, 0}, call('getpos', "'i")) - eq({0, 1, 1, 0}, call('getpos', "'w")) + eq({ 0, 3, 1, 0 }, call('getpos', "'i")) + eq({ 0, 1, 1, 0 }, call('getpos', "'w")) feed('3dd') -- Works when moving to a mark feed("'i") - eq({0, 1, 1, 0}, call('getpos', '.')) + eq({ 0, 1, 1, 0 }, call('getpos', '.')) -- Works when selecting a register feed('qillqqwhhq') eq('hh', eval('@i')) @@ -193,8 +189,7 @@ describe("'langmap'", function() eq(1, eval('gotten_one')) end) end) - it('conversions are not applied during setreg()', - function() + it('conversions are not applied during setreg()', function() call('setreg', 'i', 'ww') eq('ww', eval('@i')) end) @@ -214,12 +209,18 @@ describe("'langmap'", function() end) local function testrecording(command_string, expect_string, setup_function, expect_macro) - if setup_function then setup_function() end + if setup_function then + setup_function() + end feed('qa' .. command_string .. 'q') expect(expect_string) - eq(expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), - eval('@a')) - if setup_function then setup_function() end + eq( + expect_macro or helpers.funcs.nvim_replace_termcodes(command_string, true, true, true), + eval('@a') + ) + if setup_function then + setup_function() + end -- n.b. may need nvim_replace_termcodes() here. feed('@a') expect(expect_string) @@ -276,5 +277,4 @@ describe("'langmap'", function() testrecording('<C-w>', 'whello', local_setup, eval([["\<*C-w>"]])) testrecording('<C-i>', 'ihello', local_setup, eval([["\<*C-i>"]])) end) - end) diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index 151d803faa..421bd3ebb8 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -11,10 +11,9 @@ local meths = helpers.meths local insert = helpers.insert local curbufmeths = helpers.curbufmeths - describe('macros', function() before_each(function() - clear({args_rm = {'--cmd'}}) + clear({ args_rm = { '--cmd' } }) end) it('can be recorded and replayed', function() feed('qiahello<esc>q') @@ -42,16 +41,16 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({'helloFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[Q]] - eq({'helloFOOFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + feed [[Q]] + eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[G3Q]] - eq({'helloFOOFOO', 'hello', 'helloFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[G3Q]] + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) - feed[[ggV3jQ]] - eq({'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[ggV3jQ]] + eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @', function() @@ -61,37 +60,36 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>q]] - eq({'helloFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'helloFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[Q]] - eq({'helloFOOFOO', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + feed [[Q]] + eq({ 'helloFOOFOO', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[G3@@]] - eq({'helloFOOFOO', 'hello', 'helloFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[G3@@]] + eq({ 'helloFOOFOO', 'hello', 'helloFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) - feed[[ggV2j@@]] - eq({'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[ggV2j@@]] + eq({ 'helloFOOFOOFOO', 'helloFOO', 'helloFOOFOOFOOFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @q and @w', function() - insert [[hello hello hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) feed [[qwA123<esc>qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[V3j@q]] - eq({'helloFOO', 'helloFOO', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[V3j@q]] + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) feed [[gg]] - feed[[Vj@w]] - eq({'helloFOO123', 'helloFOO123', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[Vj@w]] + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) end) it('can be replayed with @q and @w visual-block', function() @@ -101,17 +99,17 @@ hello]] feed [[gg]] feed [[qqAFOO<esc>qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) feed [[qwA123<esc>qu]] - eq({'hello', 'hello', 'hello'}, curbufmeths.get_lines(0, -1, false)) + eq({ 'hello', 'hello', 'hello' }, curbufmeths.get_lines(0, -1, false)) - feed[[<C-v>3j@q]] - eq({'helloFOO', 'helloFOO', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[<C-v>3j@q]] + eq({ 'helloFOO', 'helloFOO', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) feed [[gg]] - feed[[<C-v>j@w]] - eq({'helloFOO123', 'helloFOO123', 'helloFOO'}, curbufmeths.get_lines(0, -1, false)) + feed [[<C-v>j@w]] + eq({ 'helloFOO123', 'helloFOO123', 'helloFOO' }, curbufmeths.get_lines(0, -1, false)) end) end) @@ -140,16 +138,16 @@ describe('immediately after a macro has finished executing,', function() end) it('if the macro does not end with a <Nop> mapping', function() - feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({mode = 'n', blocking = false}, meths.get_mode()) + feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op + eq({ mode = 'n', blocking = false }, meths.get_mode()) expect('') eq('', eval('@a')) end) it('if the macro ends with a <Nop> mapping', function() command('nnoremap 0 <Nop>') - feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op - eq({mode = 'n', blocking = false}, meths.get_mode()) + feed('@asq') -- "q" from "s" mapping should start recording a macro instead of being no-op + eq({ mode = 'n', blocking = false }, meths.get_mode()) expect('') eq('', eval('@a')) end) diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 7f7d62a90a..67d8cc58ad 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -9,7 +9,9 @@ local eq = helpers.eq local feed = helpers.feed local write_file = helpers.write_file local pcall_err = helpers.pcall_err -local cursor = function() return helpers.meths.win_get_cursor(0) end +local cursor = function() + return helpers.meths.win_get_cursor(0) +end describe('named marks', function() local file1 = 'Xtestfile-functional-editor-marks' @@ -24,153 +26,153 @@ describe('named marks', function() os.remove(file2) end) - it("can be set", function() - command("edit " .. file1) - command("mark a") - eq({1, 0}, curbufmeths.get_mark("a")) - feed("jmb") - eq({2, 0}, curbufmeths.get_mark("b")) - feed("jmB") - eq({3, 0}, curbufmeths.get_mark("B")) - command("4kc") - eq({4, 0}, curbufmeths.get_mark("c")) + it('can be set', function() + command('edit ' .. file1) + command('mark a') + eq({ 1, 0 }, curbufmeths.get_mark('a')) + feed('jmb') + eq({ 2, 0 }, curbufmeths.get_mark('b')) + feed('jmB') + eq({ 3, 0 }, curbufmeths.get_mark('B')) + command('4kc') + eq({ 4, 0 }, curbufmeths.get_mark('c')) end) - it("errors when set out of range with :mark", function() - command("edit " .. file1) - local err = pcall_err(helpers.exec_capture, "1000mark x") - eq("nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x", err) + it('errors when set out of range with :mark', function() + command('edit ' .. file1) + local err = pcall_err(helpers.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") - eq("nvim_exec2(): Vim(k):E16: Invalid range: 1000kx", err) + it('errors when set out of range with :k', function() + command('edit ' .. file1) + local err = pcall_err(helpers.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 #") - eq("nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote", err) + it('errors on unknown mark name with :mark', function() + command('edit ' .. file1) + local err = pcall_err(helpers.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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! '#") - eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err) + 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! `#") - eq("nvim_exec2(): Vim(normal):E78: Unknown mark", err) + it('errors on unknown mark name with `', function() + command('edit ' .. file1) + local err = pcall_err(helpers.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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'z") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) err = pcall_err(helpers.exec_capture, "normal! '.") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + 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") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) - err = pcall_err(helpers.exec_capture, "normal! `>") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + 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') + eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) + err = pcall_err(helpers.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) + command('edit ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'Z") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + 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") - eq("nvim_exec2(): Vim(normal):E20: Mark not set", err) + 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') + eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it("can move to them using '", function() - command("args " .. file1 .. " " .. file2) - feed("j") - feed("ma") + command('args ' .. file1 .. ' ' .. file2) + feed('j') + feed('ma') feed("G'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') feed("'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) - end) - - it("can move to them using `", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") - feed("G`a") - eq({2, 2}, cursor()) - feed("mA") - command("next") - feed("`A") + eq({ 2, 0 }, cursor()) + end) + + it('can move to them using `', function() + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') + feed('G`a') + eq({ 2, 2 }, cursor()) + feed('mA') + command('next') + feed('`A') eq(1, meths.get_current_buf().id) - eq({2, 2}, cursor()) + eq({ 2, 2 }, cursor()) end) it("can move to them using g'", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') feed("Gg'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') feed("g'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) - end) - - it("can move to them using g`", function() - command("args " .. file1 .. " " .. file2) - feed("jll") - feed("ma") - feed("Gg`a") - eq({2, 2}, cursor()) - feed("mA") - command("next") - feed("g`A") + eq({ 2, 0 }, cursor()) + end) + + it('can move to them using g`', function() + command('args ' .. file1 .. ' ' .. file2) + feed('jll') + feed('ma') + feed('Gg`a') + eq({ 2, 2 }, cursor()) + feed('mA') + command('next') + feed('g`A') eq(1, meths.get_current_buf().id) - eq({2, 2}, cursor()) + eq({ 2, 2 }, cursor()) end) it("can move to them using :'", function() - command("args " .. file1 .. " " .. file2) - feed("j") - feed("ma") - feed("G") + command('args ' .. file1 .. ' ' .. file2) + feed('j') + feed('ma') + feed('G') command("'a") - eq({2, 0}, cursor()) - feed("mA") - command("next") + eq({ 2, 0 }, cursor()) + feed('mA') + command('next') command("'A") eq(1, meths.get_current_buf().id) - eq({2, 0}, cursor()) + eq({ 2, 0 }, cursor()) end) it("errors when it can't find the buffer", function() - command("args " .. file1 .. " " .. file2) - feed("mA") - command("next") - command("bw! " .. file1 ) + command('args ' .. file1 .. ' ' .. file2) + feed('mA') + command('next') + command('bw! ' .. file1) local err = pcall_err(helpers.exec_capture, "normal! 'A") - eq("nvim_exec2(): Vim(normal):E92: Buffer 1 not found", err) + eq('nvim_exec2(): Vim(normal):E92: Buffer 1 not found', err) os.remove(file1) end) - it("errors when using a mark in another buffer in command range", function() + it('errors when using a mark in another buffer in command range', function() feed('ifoo<Esc>mA') command('enew') feed('ibar<Esc>') @@ -178,147 +180,147 @@ describe('named marks', function() end) it("leave a context mark when moving with '", function() - command("edit " .. file1) - feed("llmamA") - feed("10j0") -- first col, last line + command('edit ' .. file1) + feed('llmamA') + feed('10j0') -- first col, last line local pos = cursor() feed("'a") - feed("<C-o>") + feed('<C-o>') eq(pos, cursor()) feed("'A") - feed("<C-o>") + feed('<C-o>') eq(pos, cursor()) end) - it("leave a context mark when moving with `", function() - command("edit " .. file1) - feed("llmamA") - feed("10j0") -- first col, last line + it('leave a context mark when moving with `', function() + command('edit ' .. file1) + feed('llmamA') + feed('10j0') -- first col, last line local pos = cursor() - feed("`a") - feed("<C-o>") + feed('`a') + feed('<C-o>') eq(pos, cursor()) - feed("`A") - feed("<C-o>") + feed('`A') + feed('<C-o>') eq(pos, cursor()) end) it("leave a context mark when the mark changes buffer with g'", function() - command("args " .. file1 .. " " .. file2) + command('args ' .. file1 .. ' ' .. file2) local pos - feed("GmA") - command("next") + feed('GmA') + command('next') pos = cursor() - command("clearjumps") - feed("g'A") -- since the mark is in another buffer, it leaves a context mark - feed("<C-o>") + command('clearjumps') + feed("g'A") -- since the mark is in another buffer, it leaves a context mark + feed('<C-o>') eq(pos, cursor()) end) - it("leave a context mark when the mark changes buffer with g`", function() - command("args " .. file1 .. " " .. file2) + it('leave a context mark when the mark changes buffer with g`', function() + command('args ' .. file1 .. ' ' .. file2) local pos - feed("GmA") - command("next") + feed('GmA') + command('next') pos = cursor() - command("clearjumps") - feed("g`A") -- since the mark is in another buffer, it leaves a context mark - feed("<C-o>") + command('clearjumps') + feed('g`A') -- since the mark is in another buffer, it leaves a context mark + feed('<C-o>') eq(pos, cursor()) end) it("do not leave a context mark when moving with g'", function() - command("edit " .. file1) + command('edit ' .. file1) local pos - feed("ma") + feed('ma') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("<C-o>") -- should do nothing + feed('<C-o>') -- should do nothing eq(pos, cursor()) - feed("mA") + feed('mA') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("<C-o>") -- should do nothing + feed('<C-o>') -- should do nothing eq(pos, cursor()) end) - it("do not leave a context mark when moving with g`", function() - command("edit " .. file1) + it('do not leave a context mark when moving with g`', function() + command('edit ' .. file1) local pos - feed("ma") + feed('ma') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line - feed("g`a") - feed("<C-o>") -- should do nothing + feed('10j0') -- first col, last line + feed('g`a') + feed('<C-o>') -- should do nothing eq(pos, cursor()) - feed("mA") + feed('mA') pos = cursor() -- Mark pos - feed("10j0") -- first col, last line + feed('10j0') -- first col, last line feed("g'a") - feed("<C-o>") -- should do nothing + feed('<C-o>') -- should do nothing eq(pos, cursor()) end) - it("open folds when moving to them", function() - command("edit " .. file1) - feed("jzfG") -- Fold from the second line to the end - command("3mark a") - feed("G") -- On top of the fold + it('open folds when moving to them', function() + command('edit ' .. file1) + feed('jzfG') -- Fold from the second line to the end + command('3mark a') + feed('G') -- On top of the fold assert(funcs.foldclosed('.') ~= -1) -- folded feed("'a") eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded -- TODO: remove this workaround after fixing #15873 - feed("k`a") + feed('k`a') eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded feed("kg'a") eq(-1, funcs.foldclosed('.')) - feed("zc") + feed('zc') assert(funcs.foldclosed('.') ~= -1) -- folded - feed("kg`a") + feed('kg`a') eq(-1, funcs.foldclosed('.')) end) it("do not open folds when moving to them doesn't move the cursor", function() - command("edit " .. file1) - feed("jzfG") -- Fold from the second line to the end + command('edit ' .. file1) + feed('jzfG') -- Fold from the second line to the end assert(funcs.foldclosed('.') == 2) -- folded - feed("ma") + feed('ma') feed("'a") - feed("`a") + feed('`a') feed("g'a") - feed("g`a") + feed('g`a') -- should still be folded eq(2, funcs.foldclosed('.')) end) it("getting '{ '} '( ') does not move cursor", function() - meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) - meths.win_set_cursor(0, {2, 0}) + meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + meths.win_set_cursor(0, { 2, 0 }) funcs.getpos("'{") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("'}") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("'(") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) funcs.getpos("')") - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) end) it('in command range does not move cursor #19248', function() - meths.create_user_command('Test', ':', {range = true}) - meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) - meths.win_set_cursor(0, {2, 0}) + meths.create_user_command('Test', ':', { range = true }) + meths.buf_set_lines(0, 0, 0, true, { 'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee' }) + meths.win_set_cursor(0, { 2, 0 }) command([['{,'}Test]]) - eq({2, 0}, meths.win_get_cursor(0)) + eq({ 2, 0 }, meths.win_get_cursor(0)) end) end) @@ -327,16 +329,16 @@ describe('named marks view', function() local file2 = 'Xtestfile-functional-editor-marks-2' local function content() local c = {} - for i=1,30 do - c[i] = i .. " line" + for i = 1, 30 do + c[i] = i .. ' line' end - return table.concat(c, "\n") + return table.concat(c, '\n') end before_each(function() clear() write_file(file1, content(), false, false) write_file(file2, content(), false, false) - command("set jumpoptions+=view") + command('set jumpoptions+=view') end) after_each(function() os.remove(file1) @@ -344,12 +346,12 @@ describe('named marks view', function() end) it('is restored in normal mode but not op-pending mode', function() - local screen = Screen.new(5, 8) - screen:attach() - command("edit " .. file1) - feed("<C-e>jWma") - feed("G'a") - local expected = [[ + local screen = Screen.new(5, 8) + screen:attach() + command('edit ' .. file1) + feed('<C-e>jWma') + feed("G'a") + local expected = [[ 2 line | ^3 line | 4 line | @@ -359,9 +361,9 @@ describe('named marks view', function() 8 line | | ]] - screen:expect({grid=expected}) - feed("G`a") - screen:expect([[ + screen:expect({ grid = expected }) + feed('G`a') + screen:expect([[ 2 line | 3 ^line | 4 line | @@ -371,9 +373,9 @@ describe('named marks view', function() 8 line | | ]]) - -- not in op-pending mode #20886 - feed("ggj=`a") - screen:expect([[ + -- not in op-pending mode #20886 + feed('ggj=`a') + screen:expect([[ 1 line | ^2 line | 3 line | @@ -388,8 +390,8 @@ describe('named marks view', function() it('is restored across files', function() local screen = Screen.new(5, 5) screen:attach() - command("args " .. file1 .. " " .. file2) - feed("<C-e>mA") + command('args ' .. file1 .. ' ' .. file2) + feed('<C-e>mA') local mark_view = [[ ^2 line | 3 line | @@ -398,7 +400,7 @@ describe('named marks view', function() | ]] screen:expect(mark_view) - command("next") + command('next') screen:expect([[ ^1 line | 2 line | @@ -410,14 +412,14 @@ describe('named marks view', function() screen:expect(mark_view) end) - it('fallback to standard behavior when view can\'t be recovered', function() - local screen = Screen.new(10, 10) - screen:attach() - command("edit " .. file1) - feed("7GzbmaG") -- Seven lines from the top - command("new") -- Screen size for window is now half the height can't be restored - feed("<C-w>p'a") - screen:expect([[ + it("fallback to standard behavior when view can't be recovered", function() + local screen = Screen.new(10, 10) + screen:attach() + command('edit ' .. file1) + feed('7GzbmaG') -- Seven lines from the top + command('new') -- Screen size for window is now half the height can't be restored + feed("<C-w>p'a") + screen:expect([[ | ~ |*3 [No Name] | diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index 825b20138a..3b66c8fc05 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -66,11 +66,11 @@ describe('meta-keys #8226 #13042', function() command('inoremap <A-j> alt-j') feed('i<M-l> xxx <A-j><M-h>a<A-h>') expect('meta-l xxx alt-j') - eq({ 0, 1, 14, 0, }, funcs.getpos('.')) + eq({ 0, 1, 14, 0 }, funcs.getpos('.')) -- Unmapped ALT-chord behaves as ESC+c. command('iunmap <M-l>') feed('0i<M-l>') - eq({ 0, 1, 2, 0, }, funcs.getpos('.')) + eq({ 0, 1, 2, 0 }, funcs.getpos('.')) -- Unmapped ALT-chord has same `undo` characteristics as ESC+<key> command('0,$d') feed('ahello<M-.>') @@ -101,7 +101,7 @@ describe('meta-keys #8226 #13042', function() eq(meta_l_seq .. 'yyy' .. meta_l_seq .. 'alt-j', exec_lua([[return _G.input_data]])) eq('t', eval('mode(1)')) feed('<Esc>j') - eq({ 0, 2, 1, 0, }, funcs.getpos('.')) + eq({ 0, 2, 1, 0 }, funcs.getpos('.')) eq('nt', eval('mode(1)')) end) diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index e1fe8dead7..d36db80bdf 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -48,25 +48,29 @@ describe('cmdline', function() it('redraws statusline when toggling overstrike', function() local screen = Screen.new(60, 4) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText - [1] = {reverse = true, bold = true}, -- StatusLine + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { reverse = true, bold = true }, -- StatusLine }) screen:attach() command('set laststatus=2 statusline=%!mode(1)') feed(':') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }| {1:c }| :^ | - ]]} + ]], + } feed('<Insert>') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {0:~ }| {1:cr }| :^ | - ]]} + ]], + } end) describe('history', function() diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index 463a6fa9ca..e96813b6f7 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -53,13 +53,13 @@ describe('insert-mode', function() 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 + [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 }) screen:attach() feed('i<C-R>') @@ -187,10 +187,10 @@ describe('insert-mode', function() it('multi-char mapping updates screen properly #25626', function() local screen = Screen.new(60, 6) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText - [1] = {bold = true, reverse = true}; -- StatusLine - [2] = {reverse = true}; -- StatusLineNC - [3] = {bold = true}; -- ModeMsg + [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText + [1] = { bold = true, reverse = true }, -- StatusLine + [2] = { reverse = true }, -- StatusLineNC + [3] = { bold = true }, -- ModeMsg }) screen:attach() command('vnew') @@ -199,22 +199,26 @@ describe('insert-mode', function() command('set timeoutlen=10000') command('inoremap jk <Esc>') feed('i<CR>βββ<Left><Left>j') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo │ | foo │β^jβ | foo │{0:~ }| {0:~ }│{0:~ }| {2:[No Name] [+] }{1:[No Name] [+] }| {3:-- INSERT --} | - ]]} + ]], + } feed('k') - screen:expect{grid=[[ + screen:expect { + grid = [[ foo │ | foo │^βββ | foo │{0:~ }| {0:~ }│{0:~ }| {2:[No Name] [+] }{1:[No Name] [+] }| | - ]]} + ]], + } end) end) diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 47068470bb..8e06794093 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -35,12 +35,12 @@ describe('put command', function() before_each(reset) local function visual_marks_zero() - for _,v in pairs(funcs.getpos("'<")) do + for _, v in pairs(funcs.getpos("'<")) do if v ~= 0 then return false end end - for _,v in pairs(funcs.getpos("'>")) do + for _, v in pairs(funcs.getpos("'>")) do if v ~= 0 then return false end @@ -51,10 +51,12 @@ describe('put command', function() -- {{{ Where test definitions are run local function run_test_variations(test_variations, extra_setup) reset() - if extra_setup then extra_setup() end + if extra_setup then + extra_setup() + end local init_contents = curbuf_contents() local init_cursorpos = funcs.getcurpos() - local assert_no_change = function (exception_table, after_undo) + local assert_no_change = function(exception_table, after_undo) expect(init_contents) -- When putting the ". register forwards, undo doesn't move -- the cursor back to where it was before. @@ -69,7 +71,9 @@ describe('put command', function() for _, test in pairs(test_variations) do it(test.description, function() - if extra_setup then extra_setup() end + if extra_setup then + extra_setup() + end local orig_dotstr = funcs.getreg('.') helpers.ok(visual_marks_zero()) -- Make sure every test starts from the same conditions @@ -115,8 +119,13 @@ describe('put command', function() end -- run_test_variations() -- }}} - local function create_test_defs(test_defs, command_base, command_creator, -- {{{ - expect_base, expect_creator) + local function create_test_defs( + test_defs, + command_base, + command_creator, -- {{{ + expect_base, + expect_creator + ) local rettab = {} local exceptions for _, v in pairs(test_defs) do @@ -125,8 +134,7 @@ describe('put command', function() else exceptions = {} end - table.insert(rettab, - { + table.insert(rettab, { test_action = command_creator(command_base, v[1]), test_assertions = expect_creator(expect_base, v[2]), description = v[3], @@ -146,7 +154,7 @@ describe('put command', function() for linenum, line in pairs(funcs.split(expect_string, '\n', 1)) do local column = line:find('x') if column then - return {linenum, column}, expect_string:gsub('x', '') + return { linenum, column }, expect_string:gsub('x', '') end end end -- find_cursor_position() }}} @@ -186,7 +194,7 @@ describe('put command', function() -- '.' command. if not (exception_table.redo_position and after_redo) then local actual_position = funcs.getcurpos() - eq(cursor_position, {actual_position[2], actual_position[5]}) + eq(cursor_position, { actual_position[2], actual_position[5] }) end end end -- expect_creator() }}} @@ -195,13 +203,13 @@ describe('put command', function() local function copy_def(def) local rettab = { '', {}, '', nil } rettab[1] = def[1] - for k,v in pairs(def[2]) do + for k, v in pairs(def[2]) do rettab[2][k] = v end rettab[3] = def[3] if def[4] then rettab[4] = {} - for k,v in pairs(def[4]) do + for k, v in pairs(def[4]) do rettab[4][k] = v end end @@ -211,52 +219,52 @@ describe('put command', function() local normal_command_defs = { { 'p', - {cursor_after = false, put_backwards = false, dot_register = false}, + { cursor_after = false, put_backwards = false, dot_register = false }, 'pastes after cursor with p', }, { 'gp', - {cursor_after = true, put_backwards = false, dot_register = false}, + { cursor_after = true, put_backwards = false, dot_register = false }, 'leaves cursor after text with gp', }, { '".p', - {cursor_after = false, put_backwards = false, dot_register = true}, + { cursor_after = false, put_backwards = false, dot_register = true }, 'works with the ". register', }, { '".gp', - {cursor_after = true, put_backwards = false, dot_register = true}, + { cursor_after = true, put_backwards = false, dot_register = true }, 'gp works with the ". register', - {redo_position = true}, + { redo_position = true }, }, { 'P', - {cursor_after = false, put_backwards = true, dot_register = false}, + { cursor_after = false, put_backwards = true, dot_register = false }, 'pastes before cursor with P', }, { 'gP', - {cursor_after = true, put_backwards = true, dot_register = false}, + { cursor_after = true, put_backwards = true, dot_register = false }, 'gP pastes before cursor and leaves cursor after text', }, { '".P', - {cursor_after = false, put_backwards = true, dot_register = true}, + { cursor_after = false, put_backwards = true, dot_register = true }, 'P works with ". register', }, { '".gP', - {cursor_after = true, put_backwards = true, dot_register = true}, + { cursor_after = true, put_backwards = true, dot_register = true }, 'gP works with ". register', - {redo_position = true}, + { redo_position = true }, }, } -- Add a definition applying a count for each definition above. -- Could do this for each transformation (p -> P, p -> gp etc), but I think -- it's neater this way (balance between being explicit and too verbose). - for i = 1,#normal_command_defs do + for i = 1, #normal_command_defs do local cur = normal_command_defs[i] -- Make modified copy of current definition that includes a count. @@ -279,35 +287,36 @@ describe('put command', function() local ex_command_defs = { { 'put', - {put_backwards = false, dot_register = false}, + { put_backwards = false, dot_register = false }, 'pastes linewise forwards with :put', }, { 'put!', - {put_backwards = true, dot_register = false}, + { put_backwards = true, dot_register = false }, 'pastes linewise backwards with :put!', }, { 'put .', - {put_backwards = false, dot_register = true}, + { put_backwards = false, dot_register = true }, 'pastes linewise with the dot register', }, { 'put! .', - {put_backwards = true, dot_register = true}, + { put_backwards = true, dot_register = true }, 'pastes linewise backwards with the dot register', }, } local function non_dotdefs(def_table) - return filter(function(d) return not d[2].dot_register end, def_table) + return filter(function(d) + return not d[2].dot_register + end, def_table) end -- }}} -- Conversion functions {{{ - local function convert_charwise(expect_base, conversion_table, - virtualedit_end, visual_put) + local function convert_charwise(expect_base, conversion_table, virtualedit_end, visual_put) expect_base = dedent(expect_base) -- There is no difference between 'P' and 'p' when VIsual_active if not visual_put then @@ -324,7 +333,7 @@ describe('put command', function() end if conversion_table.count > 1 then local rep_string = 'test_string"' - local extra_puts = rep_string:rep(conversion_table.count - 1) + local extra_puts = rep_string:rep(conversion_table.count - 1) expect_base = expect_base:gsub('test_stringx"', extra_puts .. 'test_stringx"') end if conversion_table.cursor_after then @@ -395,7 +404,7 @@ describe('put command', function() indent = '' end local rep_string = indent .. p_str .. '\n' - local extra_puts = rep_string:rep(conversion_table.count - 1) + local extra_puts = rep_string:rep(conversion_table.count - 1) local orig_string, new_string if conversion_table.cursor_after then orig_string = indent .. p_str .. '\nx' @@ -420,8 +429,13 @@ describe('put command', function() return orig_line:sub(1, prev_end - 1) .. 'x' .. orig_line:sub(prev_end) end - local function convert_blockwise(expect_base, conversion_table, visual, - use_b, trailing_whitespace) + local function convert_blockwise( + expect_base, + conversion_table, + visual, + use_b, + trailing_whitespace + ) expect_base = dedent(expect_base) local p_str = 'test_string"' if use_b then @@ -452,11 +466,9 @@ describe('put command', function() if conversion_table.count and conversion_table.count > 1 then local p_pattern = p_str:gsub('%.', '%%.') - expect_base = expect_base:gsub(p_pattern, - p_str:rep(conversion_table.count)) - expect_base = expect_base:gsub('test_stringx([b".])', - p_str:rep(conversion_table.count - 1) - .. '%0') + expect_base = expect_base:gsub(p_pattern, p_str:rep(conversion_table.count)) + expect_base = + expect_base:gsub('test_stringx([b".])', p_str:rep(conversion_table.count - 1) .. '%0') end if conversion_table.cursor_after then @@ -496,8 +508,13 @@ describe('put command', function() -- }}} -- Convenience functions {{{ - local function run_normal_mode_tests(test_string, base_map, extra_setup, - virtualedit_end, selection_string) + local function run_normal_mode_tests( + test_string, + base_map, + extra_setup, + virtualedit_end, + selection_string + ) local function convert_closure(e, c) return convert_charwise(e, c, virtualedit_end, selection_string) end @@ -532,8 +549,12 @@ describe('put command', function() local function run_linewise_tests(expect_base, base_command, extra_setup) local linewise_test_defs = create_test_defs( - ex_command_defs, base_command, - create_put_action, expect_base, convert_linewiseer) + ex_command_defs, + base_command, + create_put_action, + expect_base, + convert_linewiseer + ) run_test_variations(linewise_test_defs, extra_setup) end -- run_linewise_tests() -- }}} @@ -545,7 +566,8 @@ describe('put command', function() Line of words 2]] run_normal_mode_tests(expect_string, 'p') - run_linewise_tests([[ + run_linewise_tests( + [[ Line of words 1 xtest_string" Line of words 2]], @@ -585,11 +607,12 @@ describe('put command', function() run_test_variations( create_test_defs( linewise_put_defs, - 'put a', create_put_action, - base_expect_string, convert_linewiseer + 'put a', + create_put_action, + base_expect_string, + convert_linewiseer ) ) - end) describe('blockwise register', function() @@ -600,18 +623,13 @@ describe('put command', function() test_stringb]] local function expect_block_creator(expect_base, conversion_table) - return expect_creator(function(e,c) return convert_blockwise(e,c,nil,true) end, - expect_base, conversion_table) + return expect_creator(function(e, c) + return convert_blockwise(e, c, nil, true) + end, expect_base, conversion_table) end run_test_variations( - create_test_defs( - blockwise_put_defs, - '"bp', - create_p_action, - test_base, - expect_block_creator - ) + create_test_defs(blockwise_put_defs, '"bp', create_p_action, test_base, expect_block_creator) ) end) @@ -632,17 +650,17 @@ describe('put command', function() describe('linewise paste with autoindent', function() -- luacheck: ignore - run_linewise_tests([[ + run_linewise_tests( + [[ Line of words 1 Line of words 2 xtest_string"]], - 'put' - , + 'put', function() funcs.setline('$', ' Line of words 2') -- Set curswant to '8' to be at the end of the tab character -- This is where the cursor is put back after the 'u' command. - funcs.setpos('.', {0, 2, 1, 0, 8}) + funcs.setpos('.', { 0, 2, 1, 0, 8 }) command('set autoindent') end ) @@ -655,7 +673,7 @@ describe('put command', function() run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', {0, 2, 1, 2, 3}) + funcs.setpos('.', { 0, 2, 1, 2, 3 }) end) end) @@ -667,7 +685,7 @@ describe('put command', function() run_normal_mode_tests(test_string, 'p', function() funcs.setline('$', ' Line of words 2') command('setlocal virtualedit=all') - funcs.setpos('.', {0, 1, 16, 1, 17}) + funcs.setpos('.', { 0, 1, 16, 1, 17 }) end, true) end) @@ -679,12 +697,10 @@ describe('put command', function() run_normal_mode_tests(test_string, 'v2ep', nil, nil, 'Line of') end) describe('over trailing newline', function() - local test_string = 'Line of test_stringx"Line of words 2' + local test_string = 'Line of test_stringx"Line of words 2' run_normal_mode_tests(test_string, 'v$p', function() - funcs.setpos('.', {0, 1, 9, 0, 9}) - end, - nil, - 'words 1\n') + funcs.setpos('.', { 0, 1, 9, 0, 9 }) + end, nil, 'words 1\n') end) describe('linewise mode', function() local test_string = [[ @@ -693,8 +709,7 @@ describe('put command', function() local function expect_vis_linewise(expect_base, conversion_table) return expect_creator(function(e, c) return convert_linewise(e, c, nil, nil) - end, - expect_base, conversion_table) + end, expect_base, conversion_table) end run_test_variations( create_test_defs( @@ -704,15 +719,16 @@ describe('put command', function() test_string, expect_vis_linewise ), - function() funcs.setpos('.', {0, 1, 1, 0, 1}) end + function() + funcs.setpos('.', { 0, 1, 1, 0, 1 }) + end ) describe('with whitespace at bol', function() local function expect_vis_lineindented(expect_base, conversion_table) local test_expect = expect_creator(function(e, c) - return convert_linewise(e, c, nil, nil, ' ') - end, - expect_base, conversion_table) + return convert_linewise(e, c, nil, nil, ' ') + end, expect_base, conversion_table) return function(exception_table, after_redo) test_expect(exception_table, after_redo) if not conversion_table.put_backwards then @@ -737,7 +753,6 @@ describe('put command', function() end ) end) - end) describe('blockwise visual mode', function() @@ -747,10 +762,10 @@ describe('put command', function() local function expect_block_creator(expect_base, conversion_table) local test_expect = expect_creator(function(e, c) - return convert_blockwise(e, c, true) - end, expect_base, conversion_table) - return function(e,c) - test_expect(e,c) + return convert_blockwise(e, c, true) + end, expect_base, conversion_table) + return function(e, c) + test_expect(e, c) if not conversion_table.put_backwards then eq('Lin\nLin', funcs.getreg('"')) end @@ -758,28 +773,26 @@ describe('put command', function() end local select_down_test_defs = create_test_defs( - normal_command_defs, - '<C-v>jllp', - create_p_action, - test_base, - expect_block_creator + normal_command_defs, + '<C-v>jllp', + create_p_action, + test_base, + expect_block_creator ) run_test_variations(select_down_test_defs) - -- Undo and redo of a visual block put leave the cursor in the top -- left of the visual block area no matter where the cursor was -- when it started. local undo_redo_no = map(function(table) - local rettab = copy_def(table) - if not rettab[4] then - rettab[4] = {} - end - rettab[4].undo_position = true - rettab[4].redo_position = true - return rettab - end, - normal_command_defs) + local rettab = copy_def(table) + if not rettab[4] then + rettab[4] = {} + end + rettab[4].undo_position = true + rettab[4].redo_position = true + return rettab + end, normal_command_defs) -- Selection direction doesn't matter run_test_variations( @@ -790,7 +803,9 @@ describe('put command', function() test_base, expect_block_creator ), - function() funcs.setpos('.', {0, 2, 1, 0, 1}) end + function() + funcs.setpos('.', { 0, 2, 1, 0, 1 }) + end ) describe('blockwise cursor after undo', function() @@ -800,62 +815,45 @@ describe('put command', function() -- the same pattern as everything else. -- Here we fix this by directly checking the undo/redo position -- in the test_assertions of our test definitions. - local function assertion_creator(_,_) - return function(_,_) + local function assertion_creator(_, _) + return function(_, _) feed('u') -- Have to use feed('u') here to set curswant, because -- ex_undo() doesn't do that. - eq({0, 1, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) feed('<C-r>') - eq({0, 1, 1, 0, 1}, funcs.getcurpos()) + eq({ 0, 1, 1, 0, 1 }, funcs.getcurpos()) end end run_test_variations( - create_test_defs( - undo_redo_no, - '<C-v>kllp', - create_p_action, - test_base, - assertion_creator - ), - function() funcs.setpos('.', {0, 2, 1, 0, 1}) end + create_test_defs(undo_redo_no, '<C-v>kllp', create_p_action, test_base, assertion_creator), + function() + funcs.setpos('.', { 0, 2, 1, 0, 1 }) + end ) end) end) - describe("with 'virtualedit'", function() describe('splitting a tab character', function() local base_expect_string = [[ Line of words 1 test_stringx" Line of words 2]] - run_normal_mode_tests( - base_expect_string, - 'vp', - function() - funcs.setline('$', ' Line of words 2') - command('setlocal virtualedit=all') - funcs.setpos('.', {0, 2, 1, 2, 3}) - end, - nil, - ' ' - ) + run_normal_mode_tests(base_expect_string, 'vp', function() + funcs.setline('$', ' Line of words 2') + command('setlocal virtualedit=all') + funcs.setpos('.', { 0, 2, 1, 2, 3 }) + end, nil, ' ') end) describe('after end of line', function() local base_expect_string = [[ Line of words 1 test_stringx" Line of words 2]] - run_normal_mode_tests( - base_expect_string, - 'vp', - function() - command('setlocal virtualedit=all') - funcs.setpos('.', {0, 1, 16, 2, 18}) - end, - true, - ' ' - ) + run_normal_mode_tests(base_expect_string, 'vp', function() + command('setlocal virtualedit=all') + funcs.setpos('.', { 0, 1, 16, 2, 18 }) + end, true, ' ') end) end) end) @@ -873,9 +871,12 @@ describe('put command', function() Line of words 1 Line of words 2]]) feed('u1go<C-v>j".p') - eq([[ + eq( + [[ ine of words 1 - ine of words 2]], curbuf_contents()) + ine of words 2]], + curbuf_contents() + ) end) local screen @@ -891,33 +892,42 @@ describe('put command', function() end helpers.ok(not screen.bell and not screen.visualbell) actions() - screen:expect{condition=function() - if should_ring then - if not screen.bell and not screen.visualbell then - error('Bell was not rung after action') - end - else - if screen.bell or screen.visualbell then - error('Bell was rung after action') + screen:expect { + condition = function() + if should_ring then + if not screen.bell and not screen.visualbell then + error('Bell was not rung after action') + end + else + if screen.bell or screen.visualbell then + error('Bell was rung after action') + end end - end - end, unchanged=(not should_ring)} + end, + unchanged = not should_ring, + } screen.bell = false screen.visualbell = false end it('should not ring the bell with gp at end of line', function() - bell_test(function() feed('$".gp') end) + bell_test(function() + feed('$".gp') + end) -- Even if the last character is a multibyte character. reset() funcs.setline(1, 'helloม') - bell_test(function() feed('$".gp') end) + bell_test(function() + feed('$".gp') + end) end) it('should not ring the bell with gp and end of file', function() - funcs.setpos('.', {0, 2, 1, 0}) - bell_test(function() feed('$vl".gp') end) + funcs.setpos('.', { 0, 2, 1, 0 }) + bell_test(function() + feed('$vl".gp') + end) end) it('should ring the bell when deleting if not appropriate', function() @@ -926,7 +936,9 @@ describe('put command', function() expect([[ ine of words 1 Line of words 2]]) - bell_test(function() feed('".P') end, true) + bell_test(function() + feed('".P') + end, true) end) it('should restore cursor position after undo of ".p', function() @@ -946,4 +958,3 @@ describe('put command', function() end) end) end) - diff --git a/test/functional/editor/search_spec.lua b/test/functional/editor/search_spec.lua index d5df131725..46a3e298b7 100644 --- a/test/functional/editor/search_spec.lua +++ b/test/functional/editor/search_spec.lua @@ -8,10 +8,7 @@ describe('search (/)', function() before_each(clear) it('fails with huge column (%c) value #9930', function() - eq([[Vim:E951: \% value too large]], - pcall_err(command, "/\\v%18446744071562067968c")) - eq([[Vim:E951: \% value too large]], - pcall_err(command, "/\\v%2147483648c")) + eq([[Vim:E951: \% value too large]], pcall_err(command, '/\\v%18446744071562067968c')) + eq([[Vim:E951: \% value too large]], pcall_err(command, '/\\v%2147483648c')) end) end) - diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 263b753a16..f632bbb40f 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -58,7 +58,9 @@ describe('tabpage', function() end) it('no segfault with strange WinClosed autocommand #20290', function() - pcall(exec, [[ + pcall( + exec, + [[ set nohidden edit Xa split Xb @@ -66,45 +68,46 @@ describe('tabpage', function() new autocmd WinClosed * tabprev | bwipe! close - ]]) + ]] + ) assert_alive() end) it('nvim_win_close and nvim_win_hide update tabline #20285', function() eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) local win1 = curwin().id command('tabnew') eq(2, #meths.list_tabpages()) - eq({2, 1}, funcs.win_screenpos(0)) + eq({ 2, 1 }, funcs.win_screenpos(0)) local win2 = curwin().id meths.win_close(win1, true) eq(win2, curwin().id) eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) command('tabnew') eq(2, #meths.list_tabpages()) - eq({2, 1}, funcs.win_screenpos(0)) + eq({ 2, 1 }, funcs.win_screenpos(0)) local win3 = curwin().id meths.win_hide(win2) eq(win3, curwin().id) eq(1, #meths.list_tabpages()) - eq({1, 1}, funcs.win_screenpos(0)) + eq({ 1, 1 }, funcs.win_screenpos(0)) end) it('switching tabpage after setting laststatus=3 #19591', function() local screen = Screen.new(40, 8) screen:set_default_attr_ids({ - [0] = {bold = true, foreground = Screen.colors.Blue}, - [1] = {bold = true, reverse = true}, -- StatusLine - [2] = {reverse = true}, -- TabLineFill - [3] = {bold = true}, -- TabLineSel - [4] = {background = Screen.colors.LightGrey, underline = true}, -- TabLine - [5] = {bold = true, foreground = Screen.colors.Magenta}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { bold = true, reverse = true }, -- StatusLine + [2] = { reverse = true }, -- TabLineFill + [3] = { bold = true }, -- TabLineSel + [4] = { background = Screen.colors.LightGrey, underline = true }, -- TabLine + [5] = { bold = true, foreground = Screen.colors.Magenta }, }) screen:attach() @@ -130,7 +133,7 @@ describe('tabpage', function() ]]) end) - it(":tabmove handles modifiers and addr", function() + it(':tabmove handles modifiers and addr', function() command('tabnew | tabnew | tabnew') eq(4, funcs.nvim_tabpage_get_number(0)) command(' silent :keepalt :: ::: silent! - tabmove') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index d66ab352ef..a2dc34a6b9 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -21,15 +21,23 @@ describe('u CTRL-R g- g+', function() before_each(clear) local function create_history(num_steps) - if num_steps == 0 then return end + if num_steps == 0 then + return + end insert('1') - if num_steps == 1 then return end + if num_steps == 1 then + return + end feed('o2<esc>') feed('o3<esc>') feed('u') - if num_steps == 2 then return end + if num_steps == 2 then + return + end feed('o4<esc>') - if num_steps == 3 then return end + if num_steps == 3 then + return + end feed('u') end @@ -57,13 +65,23 @@ describe('u CTRL-R g- g+', function() undo_and_redo(2, 'g-', 'g+', '1') end) it('undoes properly around a branch point', function() - undo_and_redo(3, 'u', '<C-r>', [[ + undo_and_redo( + 3, + 'u', + '<C-r>', + [[ 1 - 2]]) - undo_and_redo(3, 'g-', 'g+', [[ + 2]] + ) + undo_and_redo( + 3, + 'g-', + 'g+', + [[ 1 2 - 3]]) + 3]] + ) end) it('can find the previous sequence after undoing to a branch', function() undo_and_redo(4, 'u', '<C-r>', '1') |