diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-12 14:45:36 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-07-12 16:23:32 +0800 |
commit | 4aa4675fbface275224d178ebb436bc214dd1056 (patch) | |
tree | c54a5272b2cc8415b82549ba48381e423791090c | |
parent | 01afd43bc90408b43db906845245a4959c8ee3a0 (diff) | |
download | rneovim-4aa4675fbface275224d178ebb436bc214dd1056.tar.gz rneovim-4aa4675fbface275224d178ebb436bc214dd1056.tar.bz2 rneovim-4aa4675fbface275224d178ebb436bc214dd1056.zip |
vim-patch:8.2.0293: various Ex commands not sufficiently tested
Problem: Various Ex commands not sufficiently tested.
Solution: Add more test cases. (Yegappan Lakshmanan, closes vim/vim#5673)
https://github.com/vim/vim/commit/818fc9ad143911b2faa0d7cee86724aa70a02080
Needs to assert E170 instead of E580 because patch 8.2.3486 has been
ported but patch 8.2.1183 hasn't.
-rw-r--r-- | src/nvim/testdir/test_arglist.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 29 | ||||
-rw-r--r-- | src/nvim/testdir/test_excmd.vim | 36 | ||||
-rw-r--r-- | src/nvim/testdir/test_expand.vim | 18 | ||||
-rw-r--r-- | src/nvim/testdir/test_filetype.vim | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_filter_cmd.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_global.vim | 12 | ||||
-rw-r--r-- | src/nvim/testdir/test_plus_arg_edit.vim | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_trycatch.vim | 41 | ||||
-rw-r--r-- | src/nvim/testdir/test_vimscript.vim | 23 | ||||
-rw-r--r-- | test/functional/legacy/arglist_spec.lua | 1 |
12 files changed, 180 insertions, 3 deletions
diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index b8a1fe4ebd..ef8d0a88fd 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -520,8 +520,10 @@ func Test_quit_with_arglist() throw 'Skipped: cannot run vim in terminal' endif let buf = RunVimInTerminal('', {'rows': 6}) + call term_sendkeys(buf, ":set nomore\n") call term_sendkeys(buf, ":args a b c\n") call term_sendkeys(buf, ":quit\n") + call term_wait(buf) call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))}) call StopVimInTerminal(buf) @@ -530,14 +532,18 @@ func Test_quit_with_arglist() call term_sendkeys(buf, ":set nomore\n") call term_sendkeys(buf, ":args a b c\n") call term_sendkeys(buf, ":confirm quit\n") + call term_wait(buf) call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$', \ term_getline(buf, 6))}) call term_sendkeys(buf, "N") + call term_wait(buf) call term_sendkeys(buf, ":confirm quit\n") call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$', \ term_getline(buf, 6))}) call term_sendkeys(buf, "Y") - call StopVimInTerminal(buf) + call term_wait(buf) + call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))}) + only! endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 9885d356fd..3863d25ee7 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1385,6 +1385,35 @@ func Test_cmdwin_tabpage() tabclose! endfunc +" Test for the :! command +func Test_cmd_bang() + if !has('unix') + return + endif + + let lines =<< trim [SCRIPT] + " Test for no previous command + call assert_fails('!!', 'E34:') + set nomore + " Test for cmdline expansion with :! + call setline(1, 'foo!') + silent !echo <cWORD> > Xfile.out + call assert_equal(['foo!'], readfile('Xfile.out')) + " Test for using previous command + silent !echo \! ! + call assert_equal(['! echo foo!'], readfile('Xfile.out')) + call writefile(v:errors, 'Xresult') + call delete('Xfile.out') + qall! + [SCRIPT] + call writefile(lines, 'Xscript') + if RunVim([], [], '--clean -S Xscript') + call assert_equal([], readfile('Xresult')) + endif + call delete('Xscript') + call delete('Xresult') +endfunc + " Test error: "E135: *Filter* Autocommands must not change current buffer" func Test_cmd_bang_E135() new diff --git a/src/nvim/testdir/test_excmd.vim b/src/nvim/testdir/test_excmd.vim index 5513892dc7..8b1c44c2b8 100644 --- a/src/nvim/testdir/test_excmd.vim +++ b/src/nvim/testdir/test_excmd.vim @@ -507,6 +507,42 @@ func Test_run_excmd_with_text_locked() call assert_fails("call feedkeys(\":\<C-R>=execute('bnext')\<CR>\", 'xt')", 'E565:') endfunc +" Test for the :verbose command +func Test_verbose_cmd() + call assert_equal([' verbose=1'], split(execute('verbose set vbs'), "\n")) + call assert_equal([' verbose=0'], split(execute('0verbose set vbs'), "\n")) + let l = execute("4verbose set verbose | set verbose") + call assert_equal([' verbose=4', ' verbose=0'], split(l, "\n")) +endfunc + +" Test for the :delete command and the related abbreviated commands +func Test_excmd_delete() + new + call setline(1, ['foo', "\tbar"]) + call assert_equal(['^Ibar$'], split(execute('dl'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal(['^Ibar$'], split(execute('dell'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal(['^Ibar$'], split(execute('delel'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal(['^Ibar$'], split(execute('deletl'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal(['^Ibar$'], split(execute('deletel'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('dp'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('dep'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('delp'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('delep'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('deletp'), "\n")) + call setline(1, ['foo', "\tbar"]) + call assert_equal([' bar'], split(execute('deletep'), "\n")) + close! +endfunc + func Test_not_break_expression_register() call setreg('=', '1+1') if 0 diff --git a/src/nvim/testdir/test_expand.vim b/src/nvim/testdir/test_expand.vim index 5a51903712..d86fea4f45 100644 --- a/src/nvim/testdir/test_expand.vim +++ b/src/nvim/testdir/test_expand.vim @@ -81,7 +81,11 @@ func Test_expandcmd() call assert_fails('call expandcmd("make <afile>")', 'E495:') enew call assert_fails('call expandcmd("make %")', 'E499:') - close + let $FOO="blue\tsky" + call setline(1, "$FOO") + call assert_equal("grep pat blue\tsky", expandcmd('grep pat <cfile>')) + unlet $FOO + close! endfunc " Test for expanding <sfile>, <slnum> and <sflnum> outside of sourcing a script @@ -108,5 +112,17 @@ func Test_source_sfile() call delete('Xresult') endfunc +" Test for expanding filenames multiple times in a command line +func Test_expand_filename_multicmd() + edit foo + call setline(1, 'foo!') + new + call setline(1, 'foo!') + new <cword> | new <cWORD> + call assert_equal(4, winnr('$')) + call assert_equal('foo!', bufname(winbufnr(1))) + call assert_equal('foo', bufname(winbufnr(2))) + %bwipe! +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim index 6574876356..dee04e66dc 100644 --- a/src/nvim/testdir/test_filetype.vim +++ b/src/nvim/testdir/test_filetype.vim @@ -772,8 +772,12 @@ func Test_filetype_indent_off() new Xtest.vim filetype indent on call assert_equal(1, g:did_indent_on) + call assert_equal(['filetype detection:ON plugin:OFF indent:ON'], + \ execute('filetype')->split("\n")) filetype indent off call assert_equal(0, exists('g:did_indent_on')) + call assert_equal(['filetype detection:ON plugin:OFF indent:OFF'], + \ execute('filetype')->split("\n")) close endfunc diff --git a/src/nvim/testdir/test_filter_cmd.vim b/src/nvim/testdir/test_filter_cmd.vim index d465e48c7b..dae164b11c 100644 --- a/src/nvim/testdir/test_filter_cmd.vim +++ b/src/nvim/testdir/test_filter_cmd.vim @@ -45,6 +45,14 @@ func Test_filter_fails() call assert_fails('filter /pat', 'E476:') call assert_fails('filter /pat/', 'E476:') call assert_fails('filter /pat/ asdf', 'E492:') + " Using assert_fails() causes E476 instead of E866. So use a try-catch. + let caught_e866 = 0 + try + filter /\@>b/ ls + catch /E866:/ + let caught_e866 = 1 + endtry + call assert_equal(1, caught_e866) call assert_fails('filter!', 'E471:') call assert_fails('filter! pat', 'E476:') diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim index ad561baf4a..feddf85346 100644 --- a/src/nvim/testdir/test_global.vim +++ b/src/nvim/testdir/test_global.vim @@ -66,6 +66,18 @@ func Test_global_print() close! endfunc +" Test for global command with newline character +func Test_global_newline() + new + call setline(1, ['foo']) + exe "g/foo/s/f/h/\<NL>s/o$/w/" + call assert_equal('how', getline(1)) + call setline(1, ["foo\<NL>bar"]) + exe "g/foo/s/foo\\\<NL>bar/xyz/" + call assert_equal('xyz', getline(1)) + close! +endfunc + func Test_wrong_delimiter() call assert_fails('g x^bxd', 'E146:') endfunc diff --git a/src/nvim/testdir/test_plus_arg_edit.vim b/src/nvim/testdir/test_plus_arg_edit.vim index 64533e71cf..c52044d064 100644 --- a/src/nvim/testdir/test_plus_arg_edit.vim +++ b/src/nvim/testdir/test_plus_arg_edit.vim @@ -18,7 +18,7 @@ func Test_edit_bad() e! ++enc=utf8 Xfile call assert_equal('[?][?][???][??]', getline(1)) - e! ++enc=utf8 ++bad=_ Xfile + e! ++encoding=utf8 ++bad=_ Xfile call assert_equal('[_][_][___][__]', getline(1)) e! ++enc=utf8 ++bad=drop Xfile diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index b325122001..5649652fd2 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -499,6 +499,7 @@ func Xtest_browse(cchar) \ 'RegularLine2'] Xfirst + call assert_fails('-5Xcc', 'E16:') call assert_fails('Xprev', 'E553') call assert_fails('Xpfile', 'E553') Xnfile diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index 205ed095ea..598402fafe 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -1996,6 +1996,47 @@ func Test_reload_in_try_catch() call delete('Xreload') endfunc +" Test for errors with :catch, :throw, :finally {{{1 +func Test_try_catch_errors() + call assert_fails('throw |', 'E471:') + call assert_fails("throw \n ", 'E471:') + call assert_fails('catch abc', 'E603:') + call assert_fails('try | let i = 1| finally | catch | endtry', 'E604:') + call assert_fails('finally', 'E606:') + call assert_fails('try | finally | finally | endtry', 'E607:') + " v8.2.3486 has been ported, but v8.2.1183 hasn't, so E170 appears here. + " call assert_fails('try | for i in range(5) | endif | endtry', 'E580:') + call assert_fails('try | for i in range(5) | endif | endtry', 'E170:') + call assert_fails('try | while v:true | endtry', 'E170:') + call assert_fails('try | if v:true | endtry', 'E171:') +endfunc + +" Test for verbose messages with :try :catch, and :finally {{{1 +func Test_try_catch_verbose() + " This test works only when the language is English + if v:lang != "C" && v:lang !~ '^[Ee]n' + return + endif + + set verbose=14 + redir => msg + try + echo i + catch /E121:/ + finally + endtry + redir END + let expected = [ + \ 'Exception thrown: Vim(echo):E121: Undefined variable: i', + \ '', + \ 'Exception caught: Vim(echo):E121: Undefined variable: i', + \ '', + \ 'Exception finished: Vim(echo):E121: Undefined variable: i' + \ ] + call assert_equal(expected, split(msg, "\n")) + set verbose& +endfunc + " Test for using throw in a called function with following error {{{1 func Test_user_command_throw_in_function_call() let lines =<< trim END diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index 1bca5c420c..1323288676 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1782,6 +1782,29 @@ func Test_missing_end() call writefile(['try', 'echo "."'], 'Xscript') call assert_fails('source Xscript', 'E600:') call delete('Xscript') + + " Using endfor with :while + let caught_e732 = 0 + try + while v:true + endfor + catch /E732:/ + let caught_e732 = 1 + endtry + call assert_equal(1, caught_e732) + + " Using endwhile with :for + let caught_e733 = 0 + try + for i in range(1) + endwhile + catch /E733:/ + let caught_e733 = 1 + endtry + call assert_equal(1, caught_e733) + + " Missing 'in' in a :for statement + call assert_fails('for i range(1) | endfor', 'E690:') endfunc " Test for deep nesting of if/for/while/try statements {{{1 diff --git a/test/functional/legacy/arglist_spec.lua b/test/functional/legacy/arglist_spec.lua index 6acbaf03b2..8379e426e0 100644 --- a/test/functional/legacy/arglist_spec.lua +++ b/test/functional/legacy/arglist_spec.lua @@ -238,6 +238,7 @@ describe('argument list commands', function() end) it('quitting Vim with unedited files in the argument list throws E173', function() + command('set nomore') command('args a b c') eq('Vim(quit):E173: 2 more files to edit', pcall_err(command, 'quit')) end) |