diff options
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r-- | src/nvim/testdir/Makefile | 130 | ||||
-rw-r--r-- | src/nvim/testdir/test_blockedit.vim | 20 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufwintabinfo.vim | 22 | ||||
-rw-r--r-- | src/nvim/testdir/test_cd.vim | 54 | ||||
-rw-r--r-- | src/nvim/testdir/test_cindent.vim | 31 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 71 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 12 | ||||
-rw-r--r-- | src/nvim/testdir/test_gf.vim | 7 | ||||
-rw-r--r-- | src/nvim/testdir/test_gn.vim | 46 | ||||
-rw-r--r-- | src/nvim/testdir/test_ins_complete.vim | 19 | ||||
-rw-r--r-- | src/nvim/testdir/test_normal.vim | 130 | ||||
-rw-r--r-- | src/nvim/testdir/test_options.vim | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_preview.vim | 13 | ||||
-rw-r--r-- | src/nvim/testdir/test_startup.vim | 24 | ||||
-rw-r--r-- | src/nvim/testdir/test_tabpage.vim | 66 | ||||
-rw-r--r-- | src/nvim/testdir/test_textobjects.vim | 105 | ||||
-rw-r--r-- | src/nvim/testdir/test_undo.vim | 44 | ||||
-rw-r--r-- | src/nvim/testdir/test_winbuf_close.vim | 36 | ||||
-rw-r--r-- | src/nvim/testdir/test_window_cmd.vim | 13 |
19 files changed, 685 insertions, 174 deletions
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 1e3dc04049..10cbd91e36 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -14,117 +14,42 @@ export NVIM_PRG := $(NVIM_PRG) export TMPDIR := $(abspath ../../../Xtest-tmpdir) SCRIPTS_DEFAULT = \ - test14.out \ - test24.out \ - test37.out \ - test42.out \ - test48.out \ - test52.out \ - test64.out \ + test14.out \ + test24.out \ + test37.out \ + test42.out \ + test48.out \ + test52.out \ + test64.out \ ifneq ($(OS),Windows_NT) SCRIPTS_DEFAULTS := $(SCRIPTS_DEFAULT) \ - test17.out \ - test49.out \ + test17.out \ + test49.out \ endif SCRIPTS ?= $(SCRIPTS_DEFAULT) # Tests using runtest.vim. -# Keep test_alot*.res as the last one, sort the others. -NEW_TESTS ?= \ - test_arabic.res \ - test_autocmd.res \ - test_bufwintabinfo.res \ - test_changedtick.res \ - test_charsearch.res \ - test_cindent.res \ - test_clientserver.res \ - test_close_count.res \ - test_cmdline.res \ - test_command_count.res \ - test_cscope.res \ - test_curswant.res \ - test_digraph.res \ - test_edit.res \ - test_erasebackword.res \ - test_exists.res \ - test_diffmode.res \ - test_farsi.res \ - test_file_size.res \ - test_filter_map.res \ - test_find_complete.res \ - test_fixeol.res \ - test_findfile.res \ - test_fnameescape.res \ - test_fold.res \ - test_ga.res \ - test_getvar.res \ - test_glob2regpat.res \ - test_gf.res \ - test_gn.res \ - test_hardcopy.res \ - test_help_tagjump.res \ - test_hide.res \ - test_highlight.res \ - test_history.res \ - test_hlsearch.res \ - test_increment.res \ - test_increment_dbcs.res \ - test_ins_complete.res \ - test_lambda.res \ - test_langmap.res \ - test_let.res \ - test_lineending.res \ - test_listdict.res \ - test_listchars.res \ - test_makeencoding.res \ - test_marks.res \ - test_match.res \ - test_matchadd_conceal.res \ - test_mksession.res \ - test_nested_function.res \ - test_normal.res \ - test_number.res \ - test_options.res \ - test_profile.res \ - test_put.res \ - test_python2.res \ - test_python3.res \ - test_quickfix.res \ - test_quotestar.res \ - test_recover.res \ - test_registers.res \ - test_retab.res \ - test_scrollbind.res \ - test_search.res \ - test_signs.res \ - test_smartindent.res \ - test_spell.res \ - test_stat.res \ - test_startup.res \ - test_substitute.res \ - test_swap.res \ - test_syntax.res \ - test_system.res \ - test_tab.res \ - test_tabpage.res \ - test_textobjects.res \ - test_timers.res \ - test_undo.res \ - test_usercommands.res \ - test_user_func.res \ - test_vimscript.res \ - test_visual.res \ - test_winbuf_close.res \ - test_window_id.res \ - test_windows_home.res \ - test_wordcount.res \ - test_writefile.res \ - test_alot_latin.res \ - test_alot_utf8.res \ - test_alot.res +NEW_TESTS_ALOT := test_alot_utf8 test_alot +NEW_TESTS_IN_ALOT := $(shell sed '/^source/ s/^source //;s/\.vim$$//' test_alot*.vim) +# Ignored tests. +# test_alot_latin1: Nvim does not allow setting encoding. +# test_arglist: ported to Lua, but kept for easier merging. +# test_autochdir: ported to Lua, but kept for easier merging. +# test_eval_func: used as include in old-style test (test_eval.in). +# test_listlbr: Nvim does not allow setting encoding. +# test_largefile: uses too much resources to run on CI. +NEW_TESTS_IGNORE := $(NEW_TESTS_IN_ALOT) $(NEW_TESTS_ALOT) \ + test_alot_latin \ + test_arglist \ + test_autochdir \ + test_eval_func \ + test_listlbr \ + test_largefile \ + +NEW_TESTS = $(addsuffix .res,$(sort $(filter-out $(NEW_TESTS_IGNORE),$(basename $(notdir $(wildcard test_*.vim))))) $(NEW_TESTS_ALOT)) SCRIPTS_GUI := test16.out @@ -218,6 +143,7 @@ test1.out: .gdbinit test1.in @/bin/sh runnvim.sh --oldesttest $(ROOT) $(NVIM_PRG) $* $(RUN_VIM) $*.in @rm -rf X* test.ok viminfo +# Explicit dependencies. test49.out: test49.vim nolog: diff --git a/src/nvim/testdir/test_blockedit.vim b/src/nvim/testdir/test_blockedit.vim new file mode 100644 index 0000000000..4a8d59952e --- /dev/null +++ b/src/nvim/testdir/test_blockedit.vim @@ -0,0 +1,20 @@ +" Test for block inserting +" +" TODO: rewrite test39.in into this new style test + +func Test_blockinsert_indent() + new + filetype plugin indent on + setlocal sw=2 et ft=vim + call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']']) + call cursor(2, 3) + exe "norm! \<c-v>2jI\\ \<esc>" + call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'], + \ getline(1,'$')) + " reset to sane state + filetype off + bwipe! +endfunc + + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_bufwintabinfo.vim b/src/nvim/testdir/test_bufwintabinfo.vim index a592cd7b11..a6b4524cc0 100644 --- a/src/nvim/testdir/test_bufwintabinfo.vim +++ b/src/nvim/testdir/test_bufwintabinfo.vim @@ -39,17 +39,35 @@ function Test_getbufwintabinfo() let w2_id = win_getid() tabnew | let w3_id = win_getid() new | let w4_id = win_getid() - new | let w5_id = win_getid() + vert new | let w5_id = win_getid() call setwinvar(0, 'signal', 'green') tabfirst let winlist = getwininfo() call assert_equal(5, len(winlist)) + call assert_equal(winwidth(1), winlist[0].width) + call assert_equal(0, winlist[0].wincol) + let tablineheight = winlist[0].winrow == 1 ? 1 : 0 + call assert_equal(tablineheight, winlist[0].winrow) " tabline adds one + call assert_equal(winbufnr(2), winlist[1].bufnr) call assert_equal(winheight(2), winlist[1].height) + call assert_equal(0, winlist[1].wincol) + call assert_equal(tablineheight + winheight(1) + 1, winlist[1].winrow) + call assert_equal(1, winlist[2].winnr) + call assert_equal(tablineheight, winlist[2].winrow) + call assert_equal(0, winlist[2].wincol) + + call assert_equal(winlist[2].width + 1, winlist[3].wincol) + call assert_equal(0, winlist[4].wincol) + + call assert_equal(1, winlist[0].tabnr) + call assert_equal(1, winlist[1].tabnr) + call assert_equal(2, winlist[2].tabnr) call assert_equal(2, winlist[3].tabnr) + call assert_equal(2, winlist[4].tabnr) + call assert_equal('green', winlist[2].variables.signal) - call assert_equal(winwidth(1), winlist[0].width) call assert_equal(w4_id, winlist[3].winid) let winfo = getwininfo(w5_id)[0] call assert_equal(2, winfo.tabnr) diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index e573419bd0..770ed55b8d 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -8,6 +8,60 @@ endfunc func Test_cd_up_and_down() let path = getcwd() cd .. + call assert_notequal(path, getcwd()) exe 'cd ' . path call assert_equal(path, getcwd()) endfunc + +func Test_cd_no_arg() + if has('unix') + " Test that cd without argument goes to $HOME directory on Unix systems. + let path = getcwd() + cd + call assert_equal($HOME, getcwd()) + call assert_notequal(path, getcwd()) + exe 'cd ' . path + call assert_equal(path, getcwd()) + else + " Test that cd without argument echoes cwd on non-Unix systems. + call assert_match(getcwd(), execute('cd')) + endif +endfunc + +func Test_cd_minus() + " Test the :cd - goes back to the previous directory. + let path = getcwd() + cd .. + let path_dotdot = getcwd() + call assert_notequal(path, path_dotdot) + cd - + call assert_equal(path, getcwd()) + cd - + call assert_equal(path_dotdot, getcwd()) + cd - + call assert_equal(path, getcwd()) +endfunc + +func Test_cd_with_cpo_chdir() + e Xfoo + call setline(1, 'foo') + let path = getcwd() + " set cpo+=. + + " :cd should fail when buffer is modified and 'cpo' contains dot. + " call assert_fails('cd ..', 'E747:') + call assert_equal(path, getcwd()) + + " :cd with exclamation mark should succeed. + cd! .. + call assert_notequal(path, getcwd()) + + " :cd should succeed when buffer has been written. + w! + exe 'cd ' . path + call assert_equal(path, getcwd()) + + call delete('Xfoo') + set cpo& + bw! +endfunc diff --git a/src/nvim/testdir/test_cindent.vim b/src/nvim/testdir/test_cindent.vim index 444c4c4109..7c2c5e341c 100644 --- a/src/nvim/testdir/test_cindent.vim +++ b/src/nvim/testdir/test_cindent.vim @@ -68,9 +68,38 @@ func Test_cino_extern_c() call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') endfor + bwipe! +endfunc +func Test_cindent_rawstring() + new + setl cindent + call feedkeys("i" . + \ "int main() {\<CR>" . + \ "R\"(\<CR>" . + \ ")\";\<CR>" . + \ "statement;\<Esc>", "x") + call assert_equal("\tstatement;", getline(line('.'))) + bw! +endfunc - bwipe! +func Test_cindent_expr() + new + func! MyIndentFunction() + return v:lnum == 1 ? shiftwidth() : 0 + endfunc + setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction() + call setline(1, ['var_a = something()', 'b = something()']) + call cursor(1, 1) + call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') + call assert_equal([' var_a = something();', 'b = something();'], getline(1, '$')) + + %d + call setline(1, [' var_a = something()', ' b = something()']) + call cursor(1, 1) + call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') + call assert_equal([' var_a = something();', ' b = something()'], getline(1, '$')) + bw! endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 5a43838218..c302948ba3 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -137,6 +137,11 @@ func Test_getcompletion() let l = getcompletion('v:notexists', 'var') call assert_equal([], l) + args a.c b.c + let l = getcompletion('', 'arglist') + call assert_equal(['a.c', 'b.c'], l) + %argdelete + let l = getcompletion('', 'augroup') call assert_true(index(l, 'END') >= 0) let l = getcompletion('blahblah', 'augroup') @@ -222,6 +227,11 @@ func Test_getcompletion() let l = getcompletion('not', 'messages') call assert_equal([], l) + let l = getcompletion('', 'mapclear') + call assert_true(index(l, '<buffer>') >= 0) + let l = getcompletion('not', 'mapclear') + call assert_equal([], l) + if has('cscope') let l = getcompletion('', 'cscope') let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] @@ -311,6 +321,9 @@ func Test_paste_in_cmdline() call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') call assert_equal('"aaa /tmp/some bbb', @:) + call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa '.getline(1).' bbb', @:) + set incsearch call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') call assert_equal('"aaa verylongword bbb', @:) @@ -375,6 +388,27 @@ func Test_cmdline_complete_user_cmd() delcommand Foo endfunc +func Test_cmdline_write_alternatefile() + new + call setline('.', ['one', 'two']) + f foo.txt + new + f #-A + call assert_equal('foo.txt-A', expand('%')) + f #<-B.txt + call assert_equal('foo-B.txt', expand('%')) + f %< + call assert_equal('foo-B', expand('%')) + new + call assert_fails('f #<', 'E95') + bw! + f foo-B.txt + f %<-A + call assert_equal('foo-B-A', expand('%')) + bw! + bw! +endfunc + " using a leading backslash here set cpo+=C @@ -430,6 +464,22 @@ func Test_getcmdtype() cunmap <F6> endfunc +func Test_getcmdwintype() + call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal('/', a) + + call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal('?', a) + + call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal(':', a) + + call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal(':', a) + + call assert_equal('', getcmdwintype()) +endfunc + func Test_verbosefile() set verbosefile=Xlog echomsg 'foo' @@ -440,4 +490,25 @@ func Test_verbosefile() call delete('Xlog') endfunc +func Test_setcmdpos() + func InsertTextAtPos(text, pos) + call assert_equal(0, setcmdpos(a:pos)) + return a:text + endfunc + + " setcmdpos() with position in the middle of the command line. + call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') + call assert_equal('"1ab2', @:) + + call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') + call assert_equal('"1b2a', @:) + + " setcmdpos() with position beyond the end of the command line. + call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') + call assert_equal('"12ab', @:) + + " setcmdpos() returns 1 when not editing the command line. + call assert_equal(1, setcmdpos(3)) +endfunc + set cpo& diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index e2a035b0b2..8fde63b55f 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -701,6 +701,7 @@ endfunc func Test_byte2line_line2byte() new + set endofline call setline(1, ['a', 'bc', 'd']) set fileformat=unix @@ -721,7 +722,16 @@ func Test_byte2line_line2byte() call assert_equal([-1, -1, 1, 4, 8, 11, -1], \ map(range(-1, 5), 'line2byte(v:val)')) - set fileformat& + bw! + set noendofline nofixendofline + normal a- + for ff in ["unix", "mac", "dos"] + let &fileformat = ff + call assert_equal(1, line2byte(1)) + call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). + endfor + + set endofline& fixendofline& fileformat& bw! endfunc diff --git a/src/nvim/testdir/test_gf.vim b/src/nvim/testdir/test_gf.vim index ef1bf1075b..c352379697 100644 --- a/src/nvim/testdir/test_gf.vim +++ b/src/nvim/testdir/test_gf.vim @@ -7,7 +7,8 @@ func Test_gf_url() \ "first test for URL://machine.name/tmp/vimtest2a and other text", \ "second test for URL://machine.name/tmp/vimtest2b. And other text", \ "third test for URL:\\\\machine.name\\vimtest2c and other text", - \ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text" + \ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text", + \ "fifth test for URL://machine.name/tmp?q=vim&opt=yes and other text", \ ]) call cursor(1,1) call search("^first") @@ -28,6 +29,10 @@ func Test_gf_url() call search("URL") call assert_equal("URL:\\\\machine.name\\tmp\\vimtest2d", expand("<cfile>")) + call search("^fifth") + call search("URL") + call assert_equal("URL://machine.name/tmp?q=vim&opt=yes", expand("<cfile>")) + set isf&vim enew! endfunc diff --git a/src/nvim/testdir/test_gn.vim b/src/nvim/testdir/test_gn.vim index b2a2937d88..405425a42b 100644 --- a/src/nvim/testdir/test_gn.vim +++ b/src/nvim/testdir/test_gn.vim @@ -5,51 +5,51 @@ func Test_gn_command() noautocmd new " replace a single char by itsself quoted: call setline('.', 'abc x def x ghi x jkl') - let @/='x' + let @/ = 'x' exe "norm! cgn'x'\<esc>.." call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) sil! %d_ " simple search match call setline('.', 'foobar') - let @/='foobar' + let @/ = 'foobar' exe "norm! gncsearchmatch" call assert_equal('searchmatch', getline('.')) sil! %d _ " replace a multi-line match call setline('.', ['', 'one', 'two']) - let @/='one\_s*two\_s' + let @/ = 'one\_s*two\_s' exe "norm! gnceins\<CR>zwei" call assert_equal(['','eins','zwei'], getline(1,'$')) sil! %d _ " test count argument call setline('.', ['', 'abcdx | abcdx | abcdx']) - let @/='[a]bcdx' + let @/ = '[a]bcdx' exe "norm! 2gnd" call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) sil! %d _ " join lines call setline('.', ['join ', 'lines']) - let @/='$' + let @/ = '$' exe "norm! 0gnd" call assert_equal(['join lines'], getline(1,'$')) sil! %d _ " zero-width match call setline('.', ['', 'zero width pattern']) - let @/='\>\zs' + let @/ = '\>\zs' exe "norm! 0gnd" call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) sil! %d _ " delete first and last chars call setline('.', ['delete first and last chars']) - let @/='^' + let @/ = '^' exe "norm! 0gnd$" - let @/='\zs' + let @/ = '\zs' exe "norm! gnd" call assert_equal(['elete first and last char'], getline(1,'$')) sil! %d _ @@ -62,14 +62,14 @@ func Test_gn_command() " backwards search call setline('.', ['my very excellent mother just served us nachos']) - let @/='mother' + let @/ = 'mother' exe "norm! $cgNmongoose" call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) sil! %d _ " search for single char call setline('.', ['','for (i=0; i<=10; i++)']) - let @/='i' + let @/ = 'i' exe "norm! cgnj" call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) sil! %d _ @@ -77,28 +77,28 @@ func Test_gn_command() " search hex char call setline('.', ['','Y']) set noignorecase - let @/='\%x59' + let @/ = '\%x59' exe "norm! gnd" call assert_equal(['',''], getline(1,'$')) sil! %d _ " test repeating gdn call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) - let @/='Johnny' + let @/ = 'Johnny' exe "norm! dgn." call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) sil! %d _ " test repeating gUgn call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) - let @/='Depp' + let @/ = 'Depp' exe "norm! gUgn." call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) sil! %d _ " test using look-ahead assertions call setline('.', ['a:10', '', 'a:1', '', 'a:20']) - let @/='a:0\@!\zs\d\+' + let @/ = 'a:0\@!\zs\d\+' exe "norm! 2nygno\<esc>p" call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) sil! %d _ @@ -111,6 +111,24 @@ func Test_gn_command() call assert_equal(['foo baz'], getline(1,'$')) sil! %d_ + " search upwards with nowrapscan set + call setline('.', ['foo', 'bar', 'foo', 'baz']) + set nowrapscan + let @/ = 'foo' + $ + norm! dgN + call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$')) + sil! %d_ + + " search using the \zs atom + call setline(1, [' nnoremap', '' , 'nnoremap']) + set wrapscan&vim + let @/ = '\_s\zsnnoremap' + $ + norm! cgnmatch + call assert_equal([' nnoremap', '', 'match'], getline(1,'$')) + sil! %d_ + set wrapscan&vim set belloff&vim endfu diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index c307e33cbf..5ff63e58ba 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -217,3 +217,22 @@ function Test_CompleteDoneList() let s:called_completedone = 0 au! CompleteDone endfunc + +func Test_omni_dash() + func Omni(findstart, base) + if a:findstart + return 5 + else + echom a:base + return ['-help', '-v'] + endif + endfunc + set omnifunc=Omni + new + exe "normal Gofind -\<C-x>\<C-o>" + call assert_equal("\n-\nmatch 1 of 2", execute(':2mess')) + + bwipe! + delfunc Omni + set omnifunc= +endfunc diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 4c63bd1f71..d07b3fdbce 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -392,10 +392,31 @@ func! Test_normal10_expand() call setline(1, ['1', 'ifooar,,cbar']) 2 norm! $ - let a=expand('<cword>') - let b=expand('<cWORD>') - call assert_equal('cbar', a) - call assert_equal('ifooar,,cbar', b) + call assert_equal('cbar', expand('<cword>')) + call assert_equal('ifooar,,cbar', expand('<cWORD>')) + + call setline(1, ['prx = list[idx];']) + 1 + let expected = ['', 'prx', 'prx', 'prx', + \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', + \ 'idx', 'idx', 'idx', 'idx', + \ 'list[idx]', + \ '];', + \ ] + for i in range(1, 16) + exe 'norm ' . i . '|' + call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) + endfor + + if executable('echo') + " Test expand(`...`) i.e. backticks command expansion. + " MS-Windows has a trailing space. + call assert_match('^abcde *$', expand('`echo abcde`')) + endif + + " Test expand(`=...`) i.e. backticks expression expansion + call assert_equal('5', expand('`=2+3`')) + " clean up bw! endfunc @@ -1536,12 +1557,12 @@ fun! Test_normal29_brace() \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', \ 'paragraph boundary |posix|.', \ '{', - \ 'This is no paragaraph', + \ 'This is no paragraph', \ 'unless the ''{'' is set', \ 'in ''cpoptions''', \ '}', \ '.IP', - \ 'The nroff macros IP seperates a paragraph', + \ 'The nroff macros IP separates a paragraph', \ 'That means, it must be a ''.''', \ 'followed by IP', \ '.LPIt does not matter, if afterwards some', @@ -1556,7 +1577,7 @@ fun! Test_normal29_brace() 1 norm! 0d2} call assert_equal(['.IP', - \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP', + \ 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', 'followed by IP', \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) norm! 0d} @@ -1576,21 +1597,21 @@ fun! Test_normal29_brace() " set cpo+={ " 1 " norm! 0d2} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', - " \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + " \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', " \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', " \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', " \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) " $ " norm! d} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', - " \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + " \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', " \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', " \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', " \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) " norm! gg} " norm! d5} - " call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) + " call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) " clean up set cpo-={ @@ -1809,11 +1830,6 @@ fun! Test_normal33_g_cmd2() call assert_equal(15, col('.')) call assert_equal('l', getreg(0)) - " Test for g Ctrl-G - set ff=unix - let a=execute(":norm! g\<c-g>") - call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a) - " Test for gI norm! gIfoo call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) @@ -1832,6 +1848,81 @@ fun! Test_normal33_g_cmd2() bw! endfunc +func! Test_g_ctrl_g() + new + + let a = execute(":norm! g\<c-g>") + call assert_equal("\n--No lines in buffer--", a) + + call setline(1, ['first line', 'second line']) + + " Test g CTRL-g with dos, mac and unix file type. + norm! gojll + set ff=dos + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) + + set ff=mac + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) + + set ff=unix + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) + + " Test g CTRL-g in visual mode (v) + let a = execute(":norm! gojllvlg\<c-g>") + call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) + + " Test g CTRL-g in visual mode (CTRL-V) with end col > start col + let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") + call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) + + " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col + let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") + call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) + + " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL + let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") + call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) + + " There should be one byte less with noeol + set bin noeol + let a = execute(":norm! \<Esc>gog\<c-g>") + call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) + set bin & eol& + + if has('multi_byte') + call setline(1, ['Français', '日本語']) + + let a = execute(":norm! \<Esc>gojlg\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a) + + let a = execute(":norm! \<Esc>gojvlg\<c-g>") + call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) + + let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") + call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) + + set fenc=utf8 bomb + let a = execute(":norm! \<Esc>gojlg\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a) + + set fenc=utf16 bomb + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a) + + set fenc=utf32 bomb + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a) + + set fenc& bomb& + endif + + set ff& + bwipe! +endfunc + fun! Test_normal34_g_cmd3() if !has("multi_byte") return @@ -2180,10 +2271,11 @@ func! Test_normal44_textobjects2() endfunc func! Test_normal45_drop() - if !has("dnd") + if !has('dnd') return endif - " basic test for :drop command + + " basic test for drag-n-drop " unfortunately, without a gui, we can't really test much here, " so simply test that ~p fails (which uses the drop register) new diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index f0aec42ae1..62d40f71af 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -338,4 +338,20 @@ func Test_copy_winopt() bnext call assert_equal(4,&numberwidth) bw! + + set hidden& +endfunc + +func Test_shortmess_F() + new + call assert_match('\[No Name\]', execute('file')) + set shortmess+=F + call assert_match('\[No Name\]', execute('file')) + call assert_match('^\s*$', execute('file foo')) + call assert_match('foo', execute('file')) + set shortmess-=F + call assert_match('bar', execute('file bar')) + call assert_match('bar', execute('file')) + set shortmess& + bwipe endfunc diff --git a/src/nvim/testdir/test_preview.vim b/src/nvim/testdir/test_preview.vim new file mode 100644 index 0000000000..91923fb1e9 --- /dev/null +++ b/src/nvim/testdir/test_preview.vim @@ -0,0 +1,13 @@ +" Tests for the preview window + +func Test_Psearch() + " this used to cause ml_get errors + help + let wincount = winnr('$') + 0f + ps. + call assert_equal(wincount + 1, winnr('$')) + pclose + call assert_equal(wincount, winnr('$')) + bwipe +endfunc diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 7b77402115..638c6802d4 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -264,3 +264,27 @@ func Test_default_term() call assert_match('nvim', out) let $TERM = save_term endfunc + +func Test_zzz_startinsert() + " Test :startinsert + call writefile(['123456'], 'Xtestout') + let after = [ + \ ':startinsert', + \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' + \ ] + if RunVim([], after, 'Xtestout') + let lines = readfile('Xtestout') + call assert_equal(['foobar123456'], lines) + endif + " Test :startinsert! + call writefile(['123456'], 'Xtestout') + let after = [ + \ ':startinsert!', + \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' + \ ] + if RunVim([], after, 'Xtestout') + let lines = readfile('Xtestout') + call assert_equal(['123456foobar'], lines) + endif + call delete('Xtestout') +endfunc diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index a2eec2cc11..add9b3d7cf 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -42,40 +42,38 @@ function Test_tabpage() call assert_true(t:val_num == 100 && t:val_str == 'SetTabVar test' && t:val_list == ['red', 'blue', 'green']) tabclose - if has('nvim') || has('gui') || has('clientserver') - " Test for ":tab drop exist-file" to keep current window. - sp test1 - tab drop test1 - call assert_true(tabpagenr('$') == 1 && winnr('$') == 2 && winnr() == 1) - close - " - " - " Test for ":tab drop new-file" to keep current window of tabpage 1. - split - tab drop newfile - call assert_true(tabpagenr('$') == 2 && tabpagewinnr(1, '$') == 2 && tabpagewinnr(1) == 1) - tabclose - q - " - " - " Test for ":tab drop multi-opend-file" to keep current tabpage and window. - new test1 - tabnew - new test1 - tab drop test1 - call assert_true(tabpagenr() == 2 && tabpagewinnr(2, '$') == 2 && tabpagewinnr(2) == 1) - tabclose - q - " - " - " Test for ":tab drop vertical-split-window" to jump test1 buffer - tabedit test1 - vnew - tabfirst - tab drop test1 - call assert_equal([2, 2, 2, 2], [tabpagenr('$'), tabpagenr(), tabpagewinnr(2, '$'), tabpagewinnr(2)]) - 1tabonly - endif + " Test for ":tab drop exist-file" to keep current window. + sp test1 + tab drop test1 + call assert_true(tabpagenr('$') == 1 && winnr('$') == 2 && winnr() == 1) + close + " + " + " Test for ":tab drop new-file" to keep current window of tabpage 1. + split + tab drop newfile + call assert_true(tabpagenr('$') == 2 && tabpagewinnr(1, '$') == 2 && tabpagewinnr(1) == 1) + tabclose + q + " + " + " Test for ":tab drop multi-opend-file" to keep current tabpage and window. + new test1 + tabnew + new test1 + tab drop test1 + call assert_true(tabpagenr() == 2 && tabpagewinnr(2, '$') == 2 && tabpagewinnr(2) == 1) + tabclose + q + " + " + " Test for ":tab drop vertical-split-window" to jump test1 buffer + tabedit test1 + vnew + tabfirst + tab drop test1 + call assert_equal([2, 2, 2, 2], [tabpagenr('$'), tabpagenr(), tabpagewinnr(2, '$'), tabpagewinnr(2)]) + 1tabonly " " for i in range(9) | tabnew | endfor diff --git a/src/nvim/testdir/test_textobjects.vim b/src/nvim/testdir/test_textobjects.vim index 684f197f5f..6a2f5044cc 100644 --- a/src/nvim/testdir/test_textobjects.vim +++ b/src/nvim/testdir/test_textobjects.vim @@ -121,6 +121,23 @@ func Test_string_html_objects() enew! endfunc +func Test_empty_html_tag() + new + call setline(1, '<div></div>') + normal 0citxxx + call assert_equal('<div>xxx</div>', getline(1)) + + call setline(1, '<div></div>') + normal 0f<cityyy + call assert_equal('<div>yyy</div>', getline(1)) + + call setline(1, '<div></div>') + normal 0f<vitsaaa + call assert_equal('aaa', getline(1)) + + bwipe! +endfunc + " Tests for match() and matchstr() func Test_match() call assert_equal("b", matchstr("abcd", ".", 0, 2)) @@ -152,3 +169,91 @@ func Test_match() call assert_equal(3 , match('abc', '\zs', 3, 1)) call assert_equal(-1, match('abc', '\zs', 4, 1)) endfunc + +" This was causing an illegal memory access +func Test_inner_tag() + new + norm ixxx + call feedkeys("v", 'xt') + insert +x +x +. + norm it + q! +endfunc + +func Test_sentence() + enew! + call setline(1, 'A sentence. A sentence? A sentence!') + + normal yis + call assert_equal('A sentence.', @") + normal yas + call assert_equal('A sentence. ', @") + + normal ) + + normal yis + call assert_equal('A sentence?', @") + normal yas + call assert_equal('A sentence? ', @") + + normal ) + + normal yis + call assert_equal('A sentence!', @") + normal yas + call assert_equal(' A sentence!', @") + + normal 0 + normal 2yis + call assert_equal('A sentence. ', @") + normal 3yis + call assert_equal('A sentence. A sentence?', @") + normal 2yas + call assert_equal('A sentence. A sentence? ', @") + + %delete _ +endfunc + +func Test_sentence_with_quotes() + enew! + call setline(1, 'A "sentence." A sentence.') + + normal yis + call assert_equal('A "sentence."', @") + normal yas + call assert_equal('A "sentence." ', @") + + normal ) + + normal yis + call assert_equal('A sentence.', @") + normal yas + call assert_equal(' A sentence.', @") + + %delete _ +endfunc + +func! Test_sentence_with_cursor_on_delimiter() + enew! + call setline(1, "A '([sentence.])' A sentence.") + + normal! 15|yis + call assert_equal("A '([sentence.])'", @") + normal! 15|yas + call assert_equal("A '([sentence.])' ", @") + + normal! 16|yis + call assert_equal("A '([sentence.])'", @") + normal! 16|yas + call assert_equal("A '([sentence.])' ", @") + + normal! 17|yis + call assert_equal("A '([sentence.])'", @") + normal! 17|yas + call assert_equal("A '([sentence.])' ", @") + + %delete _ +endfunc diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index f31499607b..83ede1dc37 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -390,3 +390,47 @@ funct Test_undofile() set undodir& endfunc + +func Test_undo_0() + new + set ul=100 + normal i1 + undo + normal i2 + undo + normal i3 + + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('3', getline(1)) + call assert_equal(3, d.seq_cur) + + undo 2 + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('2', getline(1)) + call assert_equal(2, d.seq_cur) + + undo 1 + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('1', getline(1)) + call assert_equal(1, d.seq_cur) + + bwipe! +endfunc diff --git a/src/nvim/testdir/test_winbuf_close.vim b/src/nvim/testdir/test_winbuf_close.vim index ed64dd79b7..e4618610cd 100644 --- a/src/nvim/testdir/test_winbuf_close.vim +++ b/src/nvim/testdir/test_winbuf_close.vim @@ -122,3 +122,39 @@ func Test_winbuf_close() call delete('Xtest2') call delete('Xtest3') endfunc + +" Test that ":close" will respect 'winfixheight' when possible. +func Test_winfixheight_on_close() + set nosplitbelow nosplitright + + split | split | vsplit + + $wincmd w + setlocal winfixheight + let l:height = winheight(0) + + 3close + + call assert_equal(l:height, winheight(0)) + + %bwipeout! + setlocal nowinfixheight splitbelow& splitright& +endfunc + +" Test that ":close" will respect 'winfixwidth' when possible. +func Test_winfixwidth_on_close() + set nosplitbelow nosplitright + + vsplit | vsplit | split + + $wincmd w + setlocal winfixwidth + let l:width = winwidth(0) + + 3close + + call assert_equal(l:width, winwidth(0)) + + %bwipeout! + setlocal nowinfixwidth splitbelow& splitright& +endfunction diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index ad60c8d3c7..b3ab6957dc 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -374,6 +374,19 @@ func Test_equalalways_on_close() set equalalways& endfunc +func Test_win_screenpos() + call assert_equal(1, winnr('$')) + split + vsplit + 10wincmd _ + 30wincmd | + call assert_equal([1, 1], win_screenpos(1)) + call assert_equal([1, 32], win_screenpos(2)) + call assert_equal([12, 1], win_screenpos(3)) + call assert_equal([0, 0], win_screenpos(4)) + only +endfunc + func Test_window_jump_tag() help /iccf |