diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/api/vim_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/autocmd/autocmd_spec.lua | 29 | ||||
-rw-r--r-- | test/functional/editor/undo_spec.lua | 67 | ||||
-rw-r--r-- | test/functional/ex_cmds/quickfix_commands_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/legacy/ex_mode_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/legacy/mapping_spec.lua | 15 | ||||
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 33 | ||||
-rw-r--r-- | test/functional/options/cursorbind_spec.lua | 91 | ||||
-rw-r--r-- | test/functional/treesitter/language_spec.lua | 11 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/options_spec.lua | 40 | ||||
-rw-r--r-- | test/functional/ui/searchhl_spec.lua | 140 |
13 files changed, 453 insertions, 21 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e6ed0f939b..04b79a7157 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1085,6 +1085,12 @@ describe('API', function() eq('aabbccdd', funcs.getcmdline()) expect('') end) + it('mappings are disabled in Cmdline mode', function() + command('cnoremap a b') + feed(':') + nvim('paste', 'a', true, -1) + eq('a', funcs.getcmdline()) + end) it('pasting with empty last chunk in Cmdline mode', function() local screen = Screen.new(20, 4) screen:attach() diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua index 6111654b5e..90254b7415 100644 --- a/test/functional/autocmd/autocmd_spec.lua +++ b/test/functional/autocmd/autocmd_spec.lua @@ -60,6 +60,23 @@ describe('autocmd', function() eq(expected, eval('g:evs')) end) + it('first edit causes BufUnload on NoName', function() + local expected = { + {'BufUnload', ''}, + {'BufDelete', ''}, + {'BufWipeout', ''}, + {'BufEnter', 'testfile1'}, + } + command('let g:evs = []') + command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])') + command('autocmd BufDelete * :call add(g:evs, ["BufDelete", expand("<afile>")])') + command('autocmd BufLeave * :call add(g:evs, ["BufLeave", expand("<afile>")])') + command('autocmd BufUnload * :call add(g:evs, ["BufUnload", expand("<afile>")])') + command('autocmd BufWipeout * :call add(g:evs, ["BufWipeout", expand("<afile>")])') + command('edit testfile1') + eq(expected, eval('g:evs')) + end) + it('WinClosed is non-recursive', function() command('let g:triggered = 0') command('autocmd WinClosed * :let g:triggered+=1 | :bdelete 2') @@ -548,18 +565,6 @@ describe('autocmd', function() neq({}, meths.get_autocmds { group = "filetypedetect" }) end) - it('should not access freed mem', function() - source [[ - au BufEnter,BufLeave,WinEnter,WinLeave 0 vs xxx - arg 0 - argadd - all - all - au! - bwipe xxx - ]] - end) - it('should allow comma-separated patterns', function() source [[ augroup TestingPatterns diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index a023ca3d90..a041428cdc 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -2,9 +2,18 @@ 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 funcs = helpers.funcs + +local function lastmessage() + local messages = funcs.split(funcs.execute('messages'), '\n') + return messages[#messages] +end describe('u CTRL-R g- g+', function() before_each(clear) @@ -59,3 +68,61 @@ describe('u CTRL-R g- g+', function() undo_and_redo(4, 'g-', 'g+', '1') end) end) + +describe(':undo! command', function() + before_each(function() + clear() + feed('i1 little bug in the code<Esc>') + feed('o1 little bug in the code<Esc>') + feed('oTake 1 down, patch it around<Esc>') + feed('o99 little bugs in the code<Esc>') + end) + it('works', function() + feed_command('undo!') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around]]) + feed('<C-r>') + eq('Already at newest change', lastmessage()) + end) + it('works with arguments', function() + feed_command('undo! 2') + expect([[ + 1 little bug in the code + 1 little bug in the code]]) + feed('<C-r>') + eq('Already at newest change', lastmessage()) + end) + it('correctly sets alternative redo', function() + feed('uo101 little bugs in the code<Esc>') + feed_command('undo!') + feed('<C-r>') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around + 99 little bugs in the code]]) + + feed('uuoTake 2 down, patch them around<Esc>') + feed('o101 little bugs in the code<Esc>') + feed_command('undo! 2') + feed('<C-r><C-r>') + expect([[ + 1 little bug in the code + 1 little bug in the code + Take 1 down, patch it around + 99 little bugs in the code]]) + end) + it('fails when attempting to redo or move to different undo branch', function() + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + feed('u') + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + feed('o101 little bugs in the code<Esc>') + feed('o101 little bugs in the code<Esc>') + feed_command('undo! 4') + eq('E5767: Cannot use :undo! to redo or move to a different undo branch', eval('v:errmsg')) + end) +end) diff --git a/test/functional/ex_cmds/quickfix_commands_spec.lua b/test/functional/ex_cmds/quickfix_commands_spec.lua index c956a2df2d..94b7fa1a84 100644 --- a/test/functional/ex_cmds/quickfix_commands_spec.lua +++ b/test/functional/ex_cmds/quickfix_commands_spec.lua @@ -109,4 +109,17 @@ describe('quickfix', function() ]]) eq({0, 6, 1, 0, 1}, funcs.getcurpos()) end) + + it('BufAdd does not cause E16 when reusing quickfix buffer #18135', function() + local file = file_base .. '_reuse_qfbuf_BufAdd' + write_file(file, ('\n'):rep(100) .. 'foo') + source([[ + set grepprg=internal + autocmd BufAdd * call and(0, 0) + autocmd QuickFixCmdPost grep ++nested cclose | cwindow + ]]) + command('grep foo ' .. file) + command('grep foo ' .. file) + os.remove(file) + end) end) diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua index 44719027a6..244b6bf00f 100644 --- a/test/functional/legacy/ex_mode_spec.lua +++ b/test/functional/legacy/ex_mode_spec.lua @@ -32,5 +32,11 @@ describe('Ex mode', function() test_ex_edit(' foo', ' foo<C-d>') test_ex_edit(' foo0', ' foo0<C-d>') test_ex_edit(' foo^', ' foo^<C-d>') + test_ex_edit('foo', '<BS><C-H><Del><kDel>foo') + -- default wildchar <Tab> interferes with this test + command('set wildchar=<c-e>') + test_ex_edit('a\tb', 'a\t\t<C-H>b') + test_ex_edit('\tm<C-T>n', '\tm<C-T>n') + command('set wildchar&') end) end) diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index aa29698589..0f65d5eb65 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -129,10 +129,23 @@ describe('mapping', function() ]]) end) + it('dragging starts Select mode even if coming from mapping vim-patch:8.2.4806', function() + command('set mouse=a') + command('set selectmode=mouse') + + command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>') + sleep(10) + meths.input_mouse('left', 'press', '', 0, 0, 0) + sleep(10) + meths.input_mouse('left', 'drag', '', 0, 0, 1) + sleep(10) + eq('s', eval('mode()')) + end) + it('<LeftDrag> mapping in Insert mode works correctly vim-patch:8.2.4692', function() command('set mouse=a') - command([[inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>]]) + command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>') feed('i') sleep(10) meths.input_mouse('left', 'press', '', 0, 0, 0) diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index b58fad1cab..7f929db8bf 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1939,24 +1939,31 @@ describe('vim.diagnostic', function() end) it('triggers the autocommand when diagnostics are set', function() - eq(1, exec_lua [[ + eq(true, exec_lua [[ + -- Set a different buffer as current to test that <abuf> is being set properly in + -- DiagnosticChanged callbacks + local tmp = vim.api.nvim_create_buf(false, true) + vim.api.nvim_set_current_buf(tmp) + vim.g.diagnostic_autocmd_triggered = 0 - vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = 1') + vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = +expand("<abuf>")') vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test") vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic', 0, 0, 0, 0) }) - return vim.g.diagnostic_autocmd_triggered + return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr ]]) end) it('triggers the autocommand when diagnostics are cleared', function() - eq(1, exec_lua [[ + eq(true, exec_lua [[ + local tmp = vim.api.nvim_create_buf(false, true) + vim.api.nvim_set_current_buf(tmp) vim.g.diagnostic_autocmd_triggered = 0 - vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = 1') + vim.cmd('autocmd DiagnosticChanged * let g:diagnostic_autocmd_triggered = +expand("<abuf>")') vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test") vim.diagnostic.reset(diagnostic_ns, diagnostic_bufnr) - return vim.g.diagnostic_autocmd_triggered + return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr ]]) end) end) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 1547f3244e..ae6a1d5765 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2755,6 +2755,39 @@ describe('vim.keymap', function() eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) end) + it('works with buffer-local mappings', function() + eq(0, exec_lua [[ + GlobalCount = 0 + vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end, {buffer=true}) + return GlobalCount + ]]) + + feed('asdf\n') + + eq(1, exec_lua[[return GlobalCount]]) + + exec_lua [[ + vim.keymap.del('n', 'asdf', {buffer=true}) + ]] + + feed('asdf\n') + + eq(1, exec_lua[[return GlobalCount]]) + eq('\nNo mapping found', helpers.exec_capture('nmap asdf')) + end) + + it('does not mutate the opts parameter', function() + eq(true, exec_lua [[ + opts = {buffer=true} + vim.keymap.set('n', 'asdf', function() end, opts) + return opts.buffer + ]]) + eq(true, exec_lua [[ + vim.keymap.del('n', 'asdf', opts) + return opts.buffer + ]]) + end) + it('can do <Plug> mappings', function() eq(0, exec_lua [[ GlobalCount = 0 diff --git a/test/functional/options/cursorbind_spec.lua b/test/functional/options/cursorbind_spec.lua new file mode 100644 index 0000000000..f762808dd6 --- /dev/null +++ b/test/functional/options/cursorbind_spec.lua @@ -0,0 +1,91 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local command = helpers.command +local exec = helpers.exec +local feed = helpers.feed + +before_each(clear) + +describe("'cursorbind'", function() + it("behaves consistently whether 'cursorline' is set or not vim-patch:8.2.4795", function() + local screen = Screen.new(60, 8) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [2] = {bold = true, reverse = true}, -- StatusLine + [3] = {reverse = true}, -- StatusLineNC, VertSplit + [4] = {background = Screen.colors.Grey90}, -- CursorLine, CursorColumn + }) + screen:attach() + exec([[ + call setline(1, 'aa bb cc dd ee ff gg hh ii jj kk ll mm' .. + \ ' nn oo pp qq rr ss tt uu vv ww xx yy zz') + set nowrap + " The following makes the cursor apparent on the screen dump + set sidescroll=1 cursorcolumn + " add empty lines, required for cursorcolumn + call append(1, ['','','','']) + 20vsp + windo :set cursorbind + ]]) + feed('20l') + screen:expect([[ + a bb cc dd ee ff gg {3:│}aa bb cc dd ee ff gg^ hh ii jj kk ll mm | + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {1:~ }{3:│}{1:~ }| + {3:[No Name] [+] }{2:[No Name] [+] }| + | + ]]) + feed('10l') + screen:expect([[ + hh ii jj kk ll mm n{3:│}aa bb cc dd ee ff gg hh ii jj ^kk ll mm | + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {1:~ }{3:│}{1:~ }| + {3:[No Name] [+] }{2:[No Name] [+] }| + | + ]]) + command('windo :set cursorline') + feed('0') + feed('20l') + screen:expect([[ + {4:a bb cc dd ee ff gg }{3:│}{4:aa bb cc dd ee ff gg^ hh ii jj kk ll mm }| + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {4: }{3:│} {4: } | + {1:~ }{3:│}{1:~ }| + {3:[No Name] [+] }{2:[No Name] [+] }| + | + ]]) + feed('10l') + screen:expect([[ + {4: hh ii jj kk ll mm n}{3:│}{4:aa bb cc dd ee ff gg hh ii jj ^kk ll mm }| + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {4: } {3:│} {4: } | + {1:~ }{3:│}{1:~ }| + {3:[No Name] [+] }{2:[No Name] [+] }| + | + ]]) + command('windo :set nocursorline nocursorcolumn') + feed('0') + feed('40l') + screen:expect([[ + kk ll mm nn oo pp qq{3:│} bb cc dd ee ff gg hh ii jj kk ll mm n^n| + {3:│} | + {3:│} | + {3:│} | + {3:│} | + {1:~ }{3:│}{1:~ }| + {3:[No Name] [+] }{2:[No Name] [+] }| + | + ]]) + end) +end) diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua index afb17dd2cf..84e4fa5c49 100644 --- a/test/functional/treesitter/language_spec.lua +++ b/test/functional/treesitter/language_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq +local command = helpers.command local exec_lua = helpers.exec_lua local pcall_err = helpers.pcall_err local matches = helpers.matches @@ -67,5 +68,15 @@ describe('treesitter API', function() end eq({true,true}, {has_named,has_anonymous}) end) + + it('checks if vim.treesitter.get_parser tries to create a new parser on filetype change', function () + command("set filetype=c") + -- Should not throw an error when filetype is c + eq('c', exec_lua("return vim.treesitter.get_parser(0):lang()")) + command("set filetype=borklang") + -- Should throw an error when filetype changes to borklang + eq("Error executing lua: .../language.lua:0: no parser for 'borklang' language, see :help treesitter-parsers", + pcall_err(exec_lua, "new_parser = vim.treesitter.get_parser(0)")) + end) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 4c51547e2c..92300a8fa2 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -212,10 +212,10 @@ describe('ui/cursor', function() if m.blinkwait then m.blinkwait = 700 end end if m.hl_id then - m.hl_id = 61 + m.hl_id = 62 m.attr = {background = Screen.colors.DarkGray} end - if m.id_lm then m.id_lm = 62 end + if m.id_lm then m.id_lm = 63 end end -- Assert the new expectation. diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index 2f113f6ac6..82f856e4df 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -4,6 +4,7 @@ local clear = helpers.clear local command = helpers.command local eq = helpers.eq local shallowcopy = helpers.shallowcopy +local eval = helpers.eval describe('UI receives option updates', function() local screen @@ -168,3 +169,42 @@ describe('UI receives option updates', function() it('from startup options with --headless', function() startup_test(true) end) it('from startup options with --embed', function() startup_test(false) end) end) + +describe('UI can set terminal option', function() + local screen + before_each(function() + -- by default we implicity "--cmd 'set bg=light'" which ruins everything + clear{args_rm={'--cmd'}} + screen = Screen.new(20,5) + end) + + it('term_background', function() + eq('dark', eval '&background') + + screen:attach {term_background='light'} + eq('light', eval '&background') + end) + + it("term_background but not if 'background' already set by user", function() + eq('dark', eval '&background') + command 'set background=dark' + + screen:attach {term_background='light'} + + eq('dark', eval '&background') + end) + + it('term_name', function() + eq('nvim', eval '&term') + + screen:attach {term_name='xterm'} + eq('xterm', eval '&term') + end) + + it('term_colors', function() + eq('256', eval '&t_Co') + + screen:attach {term_colors=8} + eq('8', eval '&t_Co') + end) +end) diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index 2e60930127..56ff8a4101 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -109,6 +109,146 @@ describe('search highlighting', function() ]]) end) + describe('CurSearch highlight', function() + before_each(function() + screen:set_default_attr_ids({ + [1] = {background = Screen.colors.Yellow}, -- Search + [2] = {foreground = Screen.colors.White, background = Screen.colors.Black}, -- CurSearch + [3] = {foreground = Screen.colors.Red}, -- WarningMsg + }) + command('highlight CurSearch guibg=Black guifg=White') + end) + + it('works for match under cursor', function() + insert([[ + There is no way that a bee should be + able to fly. Its wings are too small + to get its fat little body off the + ground. The bee, of course, flies + anyway because bees don't care what + humans think is impossible.]]) + + feed('/bee<CR>') + screen:expect{grid=[[ + There is no way that a {2:^bee} should be | + able to fly. Its wings are too small | + to get its fat little body off the | + ground. The {1:bee}, of course, flies | + anyway because {1:bee}s don't care what | + humans think is impossible. | + {3:search hit BOTTOM, continuing at TOP} | + ]]} + + feed('nn') + screen:expect{grid=[[ + There is no way that a {1:bee} should be | + able to fly. Its wings are too small | + to get its fat little body off the | + ground. The {1:bee}, of course, flies | + anyway because {2:^bee}s don't care what | + humans think is impossible. | + /bee | + ]]} + + feed('N') + screen:expect{grid=[[ + There is no way that a {1:bee} should be | + able to fly. Its wings are too small | + to get its fat little body off the | + ground. The {2:^bee}, of course, flies | + anyway because {1:bee}s don't care what | + humans think is impossible. | + ?bee | + ]]} + end) + + it('works for multiline match', function() + command([[call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar'])]]) + feed('gg/foo<CR>') + screen:expect([[ + one | + {2:^foo} | + bar | + baz | + {1:foo} the {1:foo} and {1:foo} | + bar | + /foo | + ]]) + feed('n') + screen:expect([[ + one | + {1:foo} | + bar | + baz | + {2:^foo} the {1:foo} and {1:foo} | + bar | + /foo | + ]]) + feed('n') + screen:expect([[ + one | + {1:foo} | + bar | + baz | + {1:foo} the {2:^foo} and {1:foo} | + bar | + /foo | + ]]) + feed('n') + screen:expect([[ + one | + {1:foo} | + bar | + baz | + {1:foo} the {1:foo} and {2:^foo} | + bar | + /foo | + ]]) + command([[call setline(5, 'foo')]]) + feed('0?<CR>') + screen:expect([[ + one | + {2:^foo} | + bar | + baz | + {1:foo} | + bar | + ?foo | + ]]) + feed('gg/foo\\nbar<CR>') + screen:expect([[ + one | + {2:^foo} | + {2:bar} | + baz | + {1:foo} | + {1:bar} | + /foo\nbar | + ]]) + command([[call setline(1, ['---', 'abcdefg', 'hijkl', '---', 'abcdefg', 'hijkl'])]]) + feed('gg/efg\\nhij<CR>') + screen:expect([[ + --- | + abcd{2:^efg} | + {2:hij}kl | + --- | + abcd{1:efg} | + {1:hij}kl | + /efg\nhij | + ]]) + feed('n') + screen:expect([[ + --- | + abcd{1:efg} | + {1:hij}kl | + --- | + abcd{2:^efg} | + {2:hij}kl | + /efg\nhij | + ]]) + end) + end) + it('highlights after EOL', function() insert("\n\n\n\n\n\n") |