1" Tests for editing the command line. 2 3source check.vim 4source screendump.vim 5source view_util.vim 6source shared.vim 7 8func Test_complete_tab() 9 call writefile(['testfile'], 'Xtestfile') 10 call feedkeys(":e Xtest\t\r", "tx") 11 call assert_equal('testfile', getline(1)) 12 call delete('Xtestfile') 13endfunc 14 15func Test_complete_list() 16 " We can't see the output, but at least we check the code runs properly. 17 call feedkeys(":e test\<C-D>\r", "tx") 18 call assert_equal('test', expand('%:t')) 19 20 " If a command doesn't support completion, then CTRL-D should be literally 21 " used. 22 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') 23 call assert_equal("\"chistory \<C-D>", @:) 24endfunc 25 26func Test_complete_wildmenu() 27 call mkdir('Xdir1/Xdir2', 'p') 28 call writefile(['testfile1'], 'Xdir1/Xtestfile1') 29 call writefile(['testfile2'], 'Xdir1/Xtestfile2') 30 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') 31 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') 32 set wildmenu 33 34 " Pressing <Tab> completes, and moves to next files when pressing again. 35 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') 36 call assert_equal('testfile1', getline(1)) 37 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') 38 call assert_equal('testfile2', getline(1)) 39 40 " <S-Tab> is like <Tab> but begin with the last match and then go to 41 " previous. 42 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') 43 call assert_equal('testfile2', getline(1)) 44 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') 45 call assert_equal('testfile1', getline(1)) 46 47 " <Left>/<Right> to move to previous/next file. 48 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') 49 call assert_equal('testfile1', getline(1)) 50 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') 51 call assert_equal('testfile2', getline(1)) 52 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') 53 call assert_equal('testfile1', getline(1)) 54 55 " <Up>/<Down> to go up/down directories. 56 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') 57 call assert_equal('testfile3', getline(1)) 58 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') 59 call assert_equal('testfile1', getline(1)) 60 61 " Test for canceling the wild menu by adding a character 62 redrawstatus 63 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt') 64 call assert_equal('"e Xdir1/Xdir2/x', @:) 65 66 " Completion using a relative path 67 cd Xdir1/Xdir2 68 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') 69 call assert_equal('"e Xtestfile3 Xtestfile4', @:) 70 cd - 71 72 cnoremap <expr> <F2> wildmenumode() 73 call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') 74 call assert_equal('"cd Xdir1/1', @:) 75 cunmap <F2> 76 77 " cleanup 78 %bwipe 79 call delete('Xdir1/Xdir2/Xtestfile4') 80 call delete('Xdir1/Xdir2/Xtestfile3') 81 call delete('Xdir1/Xtestfile2') 82 call delete('Xdir1/Xtestfile1') 83 call delete('Xdir1/Xdir2', 'd') 84 call delete('Xdir1', 'd') 85 set nowildmenu 86endfunc 87f 88func Test_wildmenu_screendump() 89 CheckScreendump 90 91 let lines =<< trim [SCRIPT] 92 set wildmenu hlsearch 93 [SCRIPT] 94 call writefile(lines, 'XTest_wildmenu') 95 96 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8}) 97 call term_sendkeys(buf, ":vim\<Tab>") 98 call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) 99 100 call term_sendkeys(buf, "\<Tab>") 101 call VerifyScreenDump(buf, 'Test_wildmenu_2', {}) 102 103 call term_sendkeys(buf, "\<Tab>") 104 call VerifyScreenDump(buf, 'Test_wildmenu_3', {}) 105 106 call term_sendkeys(buf, "\<Tab>") 107 call VerifyScreenDump(buf, 'Test_wildmenu_4', {}) 108 call term_sendkeys(buf, "\<Esc>") 109 110 " clean up 111 call StopVimInTerminal(buf) 112 call delete('XTest_wildmenu') 113endfunc 114 115 116func Test_map_completion() 117 CheckFeature cmdline_compl 118 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') 119 call assert_equal('"map <unique> <silent>', getreg(':')) 120 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') 121 call assert_equal('"map <script> <unique>', getreg(':')) 122 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') 123 call assert_equal('"map <expr> <script>', getreg(':')) 124 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') 125 call assert_equal('"map <buffer> <expr>', getreg(':')) 126 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') 127 call assert_equal('"map <nowait> <buffer>', getreg(':')) 128 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') 129 call assert_equal('"map <special> <nowait>', getreg(':')) 130 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') 131 call assert_equal('"map <silent> <special>', getreg(':')) 132 133 map <Middle>x middle 134 135 map ,f commaf 136 map ,g commaf 137 map <Left> left 138 map <A-Left>x shiftleft 139 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') 140 call assert_equal('"map ,f', getreg(':')) 141 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') 142 call assert_equal('"map ,g', getreg(':')) 143 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 144 call assert_equal('"map <Left>', getreg(':')) 145 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') 146 call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) 147 unmap ,f 148 unmap ,g 149 unmap <Left> 150 unmap <A-Left>x 151 152 set cpo-=< cpo-=B cpo-=k 153 map <Left> left 154 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 155 call assert_equal('"map <Left>', getreg(':')) 156 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') 157 call assert_equal("\"map <M\<Tab>", getreg(':')) 158 unmap <Left> 159 160 set cpo+=< 161 map <Left> left 162 exe "set t_k6=\<Esc>[17~" 163 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') 164 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 165 call assert_equal('"map <Left>', getreg(':')) 166 if !has('gui_running') 167 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') 168 call assert_equal("\"map <F6>x", getreg(':')) 169 endif 170 unmap <Left> 171 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') 172 set cpo-=< 173 174 set cpo+=B 175 map <Left> left 176 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 177 call assert_equal('"map <Left>', getreg(':')) 178 unmap <Left> 179 set cpo-=B 180 181 set cpo+=k 182 map <Left> left 183 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 184 call assert_equal('"map <Left>', getreg(':')) 185 unmap <Left> 186 set cpo-=k 187 188 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:') 189 190 unmap <Middle>x 191 set cpo&vim 192endfunc 193 194func Test_match_completion() 195 CheckFeature cmdline_compl 196 hi Aardig ctermfg=green 197 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') 198 call assert_equal('"match Aardig', getreg(':')) 199 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') 200 call assert_equal('"match none', getreg(':')) 201endfunc 202 203func Test_highlight_completion() 204 CheckFeature cmdline_compl 205 hi Aardig ctermfg=green 206 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') 207 call assert_equal('"hi Aardig', getreg(':')) 208 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') 209 call assert_equal('"hi default Aardig', getreg(':')) 210 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') 211 call assert_equal('"hi clear Aardig', getreg(':')) 212 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') 213 call assert_equal('"hi link', getreg(':')) 214 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') 215 call assert_equal('"hi default', getreg(':')) 216 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') 217 call assert_equal('"hi clear', getreg(':')) 218 call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt') 219 call assert_equal('"hi clear Aardig Aardig', getreg(':')) 220 call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt') 221 call assert_equal("\"hi Aardig \t", getreg(':')) 222 223 " A cleared group does not show up in completions. 224 hi Anders ctermfg=green 225 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) 226 hi clear Aardig 227 call assert_equal(['Anders'], getcompletion('A', 'highlight')) 228 hi clear Anders 229 call assert_equal([], getcompletion('A', 'highlight')) 230endfunc 231 232" Test for command-line expansion of "hi Ni " (easter egg) 233func Test_highlight_easter_egg() 234 call test_override('ui_delay', 1) 235 call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt') 236 call assert_equal("\"hi Ni \<Tab>", @:) 237 call test_override('ALL', 0) 238endfunc 239 240func Test_getcompletion() 241 CheckFeature cmdline_compl 242 let groupcount = len(getcompletion('', 'event')) 243 call assert_true(groupcount > 0) 244 let matchcount = len('File'->getcompletion('event')) 245 call assert_true(matchcount > 0) 246 call assert_true(groupcount > matchcount) 247 248 if has('menu') 249 source $VIMRUNTIME/menu.vim 250 let matchcount = len(getcompletion('', 'menu')) 251 call assert_true(matchcount > 0) 252 call assert_equal(['File.'], getcompletion('File', 'menu')) 253 call assert_true(matchcount > 0) 254 let matchcount = len(getcompletion('File.', 'menu')) 255 call assert_true(matchcount > 0) 256 endif 257 258 let l = getcompletion('v:n', 'var') 259 call assert_true(index(l, 'v:null') >= 0) 260 let l = getcompletion('v:notexists', 'var') 261 call assert_equal([], l) 262 263 args a.c b.c 264 let l = getcompletion('', 'arglist') 265 call assert_equal(['a.c', 'b.c'], l) 266 %argdelete 267 268 let l = getcompletion('', 'augroup') 269 call assert_true(index(l, 'END') >= 0) 270 let l = getcompletion('blahblah', 'augroup') 271 call assert_equal([], l) 272 273 let l = getcompletion('', 'behave') 274 call assert_true(index(l, 'mswin') >= 0) 275 let l = getcompletion('not', 'behave') 276 call assert_equal([], l) 277 278 let l = getcompletion('', 'color') 279 call assert_true(index(l, 'default') >= 0) 280 let l = getcompletion('dirty', 'color') 281 call assert_equal([], l) 282 283 let l = getcompletion('', 'command') 284 call assert_true(index(l, 'sleep') >= 0) 285 let l = getcompletion('awake', 'command') 286 call assert_equal([], l) 287 288 let l = getcompletion('', 'dir') 289 call assert_true(index(l, 'samples/') >= 0) 290 let l = getcompletion('NoMatch', 'dir') 291 call assert_equal([], l) 292 293 let l = getcompletion('exe', 'expression') 294 call assert_true(index(l, 'executable(') >= 0) 295 let l = getcompletion('kill', 'expression') 296 call assert_equal([], l) 297 298 let l = getcompletion('tag', 'function') 299 call assert_true(index(l, 'taglist(') >= 0) 300 let l = getcompletion('paint', 'function') 301 call assert_equal([], l) 302 303 let Flambda = {-> 'hello'} 304 let l = getcompletion('', 'function') 305 let l = filter(l, {i, v -> v =~ 'lambda'}) 306 call assert_equal([], l) 307 308 let l = getcompletion('run', 'file') 309 call assert_true(index(l, 'runtest.vim') >= 0) 310 let l = getcompletion('walk', 'file') 311 call assert_equal([], l) 312 set wildignore=*.vim 313 let l = getcompletion('run', 'file', 1) 314 call assert_true(index(l, 'runtest.vim') < 0) 315 set wildignore& 316 317 let l = getcompletion('ha', 'filetype') 318 call assert_true(index(l, 'hamster') >= 0) 319 let l = getcompletion('horse', 'filetype') 320 call assert_equal([], l) 321 322 let l = getcompletion('z', 'syntax') 323 call assert_true(index(l, 'zimbu') >= 0) 324 let l = getcompletion('emacs', 'syntax') 325 call assert_equal([], l) 326 327 let l = getcompletion('jikes', 'compiler') 328 call assert_true(index(l, 'jikes') >= 0) 329 let l = getcompletion('break', 'compiler') 330 call assert_equal([], l) 331 332 let l = getcompletion('last', 'help') 333 call assert_true(index(l, ':tablast') >= 0) 334 let l = getcompletion('giveup', 'help') 335 call assert_equal([], l) 336 337 let l = getcompletion('time', 'option') 338 call assert_true(index(l, 'timeoutlen') >= 0) 339 let l = getcompletion('space', 'option') 340 call assert_equal([], l) 341 342 let l = getcompletion('er', 'highlight') 343 call assert_true(index(l, 'ErrorMsg') >= 0) 344 let l = getcompletion('dark', 'highlight') 345 call assert_equal([], l) 346 347 let l = getcompletion('', 'messages') 348 call assert_true(index(l, 'clear') >= 0) 349 let l = getcompletion('not', 'messages') 350 call assert_equal([], l) 351 352 let l = getcompletion('', 'mapclear') 353 call assert_true(index(l, '<buffer>') >= 0) 354 let l = getcompletion('not', 'mapclear') 355 call assert_equal([], l) 356 357 let l = getcompletion('.', 'shellcmd') 358 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) 359 call assert_equal(-1, match(l[2:], '^\.\.\?/$')) 360 let root = has('win32') ? 'C:\\' : '/' 361 let l = getcompletion(root, 'shellcmd') 362 let expected = map(filter(glob(root . '*', 0, 1), 363 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') 364 call assert_equal(expected, l) 365 366 if has('cscope') 367 let l = getcompletion('', 'cscope') 368 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] 369 call assert_equal(cmds, l) 370 " using cmdline completion must not change the result 371 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') 372 let l = getcompletion('', 'cscope') 373 call assert_equal(cmds, l) 374 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] 375 let l = getcompletion('find ', 'cscope') 376 call assert_equal(keys, l) 377 endif 378 379 if has('signs') 380 sign define Testing linehl=Comment 381 let l = getcompletion('', 'sign') 382 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] 383 call assert_equal(cmds, l) 384 " using cmdline completion must not change the result 385 call feedkeys(":sign list \<c-d>\<c-c>", 'xt') 386 let l = getcompletion('', 'sign') 387 call assert_equal(cmds, l) 388 let l = getcompletion('list ', 'sign') 389 call assert_equal(['Testing'], l) 390 endif 391 392 " Command line completion tests 393 let l = getcompletion('cd ', 'cmdline') 394 call assert_true(index(l, 'samples/') >= 0) 395 let l = getcompletion('cd NoMatch', 'cmdline') 396 call assert_equal([], l) 397 let l = getcompletion('let v:n', 'cmdline') 398 call assert_true(index(l, 'v:null') >= 0) 399 let l = getcompletion('let v:notexists', 'cmdline') 400 call assert_equal([], l) 401 let l = getcompletion('call tag', 'cmdline') 402 call assert_true(index(l, 'taglist(') >= 0) 403 let l = getcompletion('call paint', 'cmdline') 404 call assert_equal([], l) 405 406 " For others test if the name is recognized. 407 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] 408 if has('cmdline_hist') 409 call add(names, 'history') 410 endif 411 if has('gettext') 412 call add(names, 'locale') 413 endif 414 if has('profile') 415 call add(names, 'syntime') 416 endif 417 418 set tags=Xtags 419 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') 420 421 for name in names 422 let matchcount = len(getcompletion('', name)) 423 call assert_true(matchcount >= 0, 'No matches for ' . name) 424 endfor 425 426 call delete('Xtags') 427 set tags& 428 429 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:') 430 call assert_fails('call getcompletion("", "burp")', 'E475:') 431 call assert_fails('call getcompletion("abc", [])', 'E475:') 432endfunc 433 434func Test_shellcmd_completion() 435 let save_path = $PATH 436 437 call mkdir('Xpathdir/Xpathsubdir', 'p') 438 call writefile([''], 'Xpathdir/Xfile.exe') 439 call setfperm('Xpathdir/Xfile.exe', 'rwx------') 440 441 " Set PATH to example directory without trailing slash. 442 let $PATH = getcwd() . '/Xpathdir' 443 444 " Test for the ":!<TAB>" case. Previously, this would include subdirs of 445 " dirs in the PATH, even though they won't be executed. We check that only 446 " subdirs of the PWD and executables from the PATH are included in the 447 " suggestions. 448 let actual = getcompletion('X', 'shellcmd') 449 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') 450 call insert(expected, 'Xfile.exe') 451 call assert_equal(expected, actual) 452 453 call delete('Xpathdir', 'rf') 454 let $PATH = save_path 455endfunc 456 457func Test_expand_star_star() 458 call mkdir('a/b', 'p') 459 call writefile(['asdfasdf'], 'a/b/fileXname') 460 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') 461 call assert_equal('find a/b/fileXname', getreg(':')) 462 bwipe! 463 call delete('a', 'rf') 464endfunc 465 466func Test_cmdline_paste() 467 let @a = "def" 468 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') 469 call assert_equal('"abc def ghi', @:) 470 471 new 472 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') 473 474 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 475 call assert_equal('"aaa asdf bbb', @:) 476 477 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') 478 call assert_equal('"aaa /tmp/some bbb', @:) 479 480 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') 481 call assert_equal('"aaa '.getline(1).' bbb', @:) 482 483 set incsearch 484 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 485 call assert_equal('"aaa verylongword bbb', @:) 486 487 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') 488 call assert_equal('"aaa a;b-c*d bbb', @:) 489 490 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') 491 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) 492 bwipe! 493 494 " Error while typing a command used to cause that it was not executed 495 " in the end. 496 new 497 try 498 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') 499 catch /^Vim\%((\a\+)\)\=:E32/ 500 " ignore error E32 501 endtry 502 call assert_equal("Xtestfile", bufname("%")) 503 504 " Try to paste an invalid register using <C-R> 505 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') 506 call assert_equal('"onetwo', @:) 507 508 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R 509 let @a = "xy\<C-H>z" 510 call feedkeys(":\"\<C-R>a\<CR>", 'xt') 511 call assert_equal('"xz', @:) 512 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') 513 call assert_equal("\"xy\<C-H>z", @:) 514 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') 515 call assert_equal("\"xy\<C-H>z", @:) 516 517 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R 518 let @a = "xy\<C-V>z" 519 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') 520 call assert_equal('"xyz', @:) 521 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') 522 call assert_equal("\"xy\<C-V>z", @:) 523 524 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') 525 526 bwipe! 527endfunc 528 529func Test_cmdline_remove_char() 530 let encoding_save = &encoding 531 532 for e in ['utf8', 'latin1'] 533 exe 'set encoding=' . e 534 535 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') 536 call assert_equal('"abc ef', @:, e) 537 538 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') 539 call assert_equal('"abcdef', @:) 540 541 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') 542 call assert_equal('"abc ghi', @:, e) 543 544 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') 545 call assert_equal('"def', @:, e) 546 endfor 547 548 let &encoding = encoding_save 549endfunc 550 551func Test_cmdline_keymap_ctrl_hat() 552 CheckFeature keymap 553 554 set keymap=esperanto 555 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') 556 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) 557 set keymap= 558endfunc 559 560func Test_illegal_address1() 561 new 562 2;'( 563 2;') 564 quit 565endfunc 566 567func Test_illegal_address2() 568 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') 569 new 570 source Xtest.vim 571 " Trigger calling validate_cursor() 572 diffsp Xtest.vim 573 quit! 574 bwipe! 575 call delete('Xtest.vim') 576endfunc 577 578func Test_cmdline_complete_wildoptions() 579 help 580 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 581 let a = join(sort(split(@:)),' ') 582 set wildoptions=tagfile 583 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 584 let b = join(sort(split(@:)),' ') 585 call assert_equal(a, b) 586 bw! 587endfunc 588 589func Test_cmdline_complete_user_cmd() 590 command! -complete=color -nargs=1 Foo : 591 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') 592 call assert_equal('"Foo blue', @:) 593 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') 594 call assert_equal('"Foo blue', @:) 595 delcommand Foo 596endfunc 597 598func s:ScriptLocalFunction() 599 echo 'yes' 600endfunc 601 602func Test_cmdline_complete_user_func() 603 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') 604 call assert_match('"func Test_cmdline_complete_user', @:) 605 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') 606 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) 607endfunc 608 609func Test_cmdline_complete_user_names() 610 if has('unix') && executable('whoami') 611 let whoami = systemlist('whoami')[0] 612 let first_letter = whoami[0] 613 if len(first_letter) > 0 614 " Trying completion of :e ~x where x is the first letter of 615 " the user name should complete to at least the user name. 616 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 617 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 618 endif 619 elseif has('win32') 620 " Just in case: check that the system has an Administrator account. 621 let names = system('net user') 622 if names =~ 'Administrator' 623 " Trying completion of :e ~A should complete to Administrator. 624 " There could be other names starting with "A" before Administrator. 625 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 626 call assert_match('^"e \~.*Administrator', @:) 627 endif 628 else 629 throw 'Skipped: does not work on this platform' 630 endif 631endfunc 632 633func Test_cmdline_complete_bang() 634 CheckExecutable whoami 635 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') 636 call assert_match('^".*\<whoami\>', @:) 637endfunc 638 639func Test_cmdline_complete_languages() 640 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') 641 call assert_equal(lang, v:lc_time) 642 643 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') 644 call assert_equal(lang, v:ctype) 645 646 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') 647 call assert_equal(lang, v:collate) 648 649 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 650 call assert_equal(lang, v:lang) 651 652 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 653 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) 654 655 call assert_match('^"language .*\<' . lang . '\>', @:) 656 657 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 658 call assert_match('^"language .*\<' . lang . '\>', @:) 659 660 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 661 call assert_match('^"language .*\<' . lang . '\>', @:) 662 663 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 664 call assert_match('^"language .*\<' . lang . '\>', @:) 665 666 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') 667 call assert_match('^"language .*\<' . lang . '\>', @:) 668endfunc 669 670func Test_cmdline_complete_env_variable() 671 let $X_VIM_TEST_COMPLETE_ENV = 'foo' 672 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') 673 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) 674 unlet $X_VIM_TEST_COMPLETE_ENV 675endfunc 676 677" Test for various command-line completion 678func Test_cmdline_complete_various() 679 " completion for a command starting with a comment 680 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') 681 call assert_equal("\" :|\"\<C-A>", @:) 682 683 " completion for a range followed by a comment 684 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') 685 call assert_equal("\"1,2\"\<C-A>", @:) 686 687 " completion for :k command 688 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') 689 call assert_equal("\"ka\<C-A>", @:) 690 691 " completion for short version of the :s command 692 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') 693 call assert_equal("\"sI \<C-A>", @:) 694 695 " completion for :write command 696 call mkdir('Xdir') 697 call writefile(['one'], 'Xdir/Xfile1') 698 let save_cwd = getcwd() 699 cd Xdir 700 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') 701 call assert_equal("\"w >> Xfile1", @:) 702 call chdir(save_cwd) 703 call delete('Xdir', 'rf') 704 705 " completion for :w ! and :r ! commands 706 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 707 call assert_equal("\"w !invalid_xyz_cmd", @:) 708 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 709 call assert_equal("\"r !invalid_xyz_cmd", @:) 710 711 " completion for :>> and :<< commands 712 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') 713 call assert_equal("\">>>\<C-A>", @:) 714 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') 715 call assert_equal("\"<<<\<C-A>", @:) 716 717 " completion for command with +cmd argument 718 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') 719 call assert_equal("\"buffer +/pat Xabc", @:) 720 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') 721 call assert_equal("\"buffer +/pat\<C-A>", @:) 722 723 " completion for a command with a trailing comment 724 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') 725 call assert_equal("\"ls \" comment\<C-A>", @:) 726 727 " completion for a command with a trailing command 728 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') 729 call assert_equal("\"ls | ls", @:) 730 731 " completion for a command with an CTRL-V escaped argument 732 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') 733 call assert_equal("\"ls \<C-V>a\<C-A>", @:) 734 735 " completion for a command that doesn't take additional arguments 736 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') 737 call assert_equal("\"all abc\<C-A>", @:) 738 739 " completion for a command with a command modifier 740 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') 741 call assert_equal("\"topleft new", @:) 742 743 " completion for the :match command 744 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') 745 call assert_equal("\"match Search /pat/\<C-A>", @:) 746 747 " completion for the :s command 748 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt') 749 call assert_equal("\"s/from/to/g\<C-A>", @:) 750 751 " completion for the :dlist command 752 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') 753 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) 754 755 " completion for the :doautocmd command 756 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') 757 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) 758 759 " completion of autocmd group after comma 760 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') 761 call assert_equal("\"doautocmd BufNew,BufEnter", @:) 762 763 " completion for the :augroup command 764 augroup XTest 765 augroup END 766 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') 767 call assert_equal("\"augroup XTest", @:) 768 augroup! XTest 769 770 " completion for the :unlet command 771 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') 772 call assert_equal("\"unlet one two", @:) 773 774 " completion for the :bdelete command 775 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') 776 call assert_equal("\"bdel a b c", @:) 777 778 " completion for the :mapclear command 779 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') 780 call assert_equal("\"mapclear <buffer>", @:) 781 782 " completion for user defined commands with menu names 783 menu Test.foo :ls<CR> 784 com -nargs=* -complete=menu MyCmd 785 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') 786 call assert_equal('"MyCmd Test.', @:) 787 delcom MyCmd 788 unmenu Test 789 790 " completion for user defined commands with mappings 791 mapclear 792 map <F3> :ls<CR> 793 com -nargs=* -complete=mapping MyCmd 794 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') 795 call assert_equal('"MyCmd <F3>', @:) 796 mapclear 797 delcom MyCmd 798 799 " completion for :set path= with multiple backslashes 800 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 801 call assert_equal('"set path=a\\\ b', @:) 802 803 " completion for :set dir= with a backslash 804 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 805 call assert_equal('"set dir=a\ b', @:) 806 807 " completion for the :py3 commands 808 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') 809 call assert_equal('"py3 py3do py3file', @:) 810 811 " redir @" is not the start of a comment. So complete after that 812 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') 813 call assert_equal('"redir @" | cwindow', @:) 814 815 " completion after a backtick 816 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') 817 call assert_equal('"e `a1b2c', @:) 818 819 " completion for :language command with an invalid argument 820 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') 821 call assert_equal("\"language dummy \t", @:) 822 823 " completion for commands after a :global command 824 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') 825 call assert_equal('"g/a\xb/clearjumps', @:) 826 827 " completion with ambiguous user defined commands 828 com TCmd1 echo 'TCmd1' 829 com TCmd2 echo 'TCmd2' 830 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') 831 call assert_equal('"TCmd ', @:) 832 delcom TCmd1 833 delcom TCmd2 834 835 " completion after a range followed by a pipe (|) character 836 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') 837 call assert_equal('"1,10 | chistory', @:) 838 839 " use <Esc> as the 'wildchar' for completion 840 set wildchar=<Esc> 841 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') 842 call assert_equal('"g/a\xb/clearjumps', @:) 843 " pressing <esc> twice should cancel the command 844 call feedkeys(":chist\<Esc>\<Esc>", 'xt') 845 call assert_equal('"g/a\xb/clearjumps', @:) 846 set wildchar& 847endfunc 848 849func Test_cmdline_write_alternatefile() 850 new 851 call setline('.', ['one', 'two']) 852 f foo.txt 853 new 854 f #-A 855 call assert_equal('foo.txt-A', expand('%')) 856 f #<-B.txt 857 call assert_equal('foo-B.txt', expand('%')) 858 f %< 859 call assert_equal('foo-B', expand('%')) 860 new 861 call assert_fails('f #<', 'E95:') 862 bw! 863 f foo-B.txt 864 f %<-A 865 call assert_equal('foo-B-A', expand('%')) 866 bw! 867 bw! 868endfunc 869 870" using a leading backslash here 871set cpo+=C 872 873func Test_cmdline_search_range() 874 new 875 call setline(1, ['a', 'b', 'c', 'd']) 876 /d 877 1,\/s/b/B/ 878 call assert_equal('B', getline(2)) 879 880 /a 881 $ 882 \?,4s/c/C/ 883 call assert_equal('C', getline(3)) 884 885 call setline(1, ['a', 'b', 'c', 'd']) 886 %s/c/c/ 887 1,\&s/b/B/ 888 call assert_equal('B', getline(2)) 889 890 let @/ = 'apple' 891 call assert_fails('\/print', ['E486:.*apple']) 892 893 bwipe! 894endfunc 895 896" Test for the tick mark (') in an excmd range 897func Test_tick_mark_in_range() 898 " If only the tick is passed as a range and no command is specified, there 899 " should not be an error 900 call feedkeys(":'\<CR>", 'xt') 901 call assert_equal("'", getreg(':')) 902 call assert_fails("',print", 'E78:') 903endfunc 904 905" Test for using a line number followed by a search pattern as range 906func Test_lnum_and_pattern_as_range() 907 new 908 call setline(1, ['foo 1', 'foo 2', 'foo 3']) 909 let @" = '' 910 2/foo/yank 911 call assert_equal("foo 3\n", @") 912 call assert_equal(1, line('.')) 913 close! 914endfunc 915 916" Tests for getcmdline(), getcmdpos() and getcmdtype() 917func Check_cmdline(cmdtype) 918 call assert_equal('MyCmd a', getcmdline()) 919 call assert_equal(8, getcmdpos()) 920 call assert_equal(a:cmdtype, getcmdtype()) 921 return '' 922endfunc 923 924set cpo& 925 926func Test_getcmdtype() 927 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 928 929 let cmdtype = '' 930 debuggreedy 931 call feedkeys(":debug echo 'test'\<CR>", "t") 932 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 933 call feedkeys("cont\<CR>", "xt") 934 0debuggreedy 935 call assert_equal('>', cmdtype) 936 937 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 938 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 939 940 call feedkeys(":call input('Answer?')\<CR>", "t") 941 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 942 943 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 944 945 cnoremap <expr> <F6> Check_cmdline('=') 946 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 947 cunmap <F6> 948 949 call assert_equal('', getcmdline()) 950endfunc 951 952func Test_getcmdwintype() 953 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 954 call assert_equal('/', a) 955 956 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 957 call assert_equal('?', a) 958 959 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 960 call assert_equal(':', a) 961 962 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 963 call assert_equal(':', a) 964 965 call assert_equal('', getcmdwintype()) 966endfunc 967 968func Test_getcmdwin_autocmd() 969 let s:seq = [] 970 augroup CmdWin 971 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) 972 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) 973 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) 974 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) 975 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) 976 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) 977 978 let org_winid = win_getid() 979 let org_bufnr = bufnr() 980 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') 981 call assert_equal(':', a) 982 call assert_equal([ 983 \ 'WinLeave ' .. org_winid, 984 \ 'WinEnter ' .. s:cmd_winid, 985 \ 'BufLeave ' .. org_bufnr, 986 \ 'BufEnter ' .. s:cmd_bufnr, 987 \ 'CmdWinEnter ' .. s:cmd_winid, 988 \ 'CmdWinLeave ' .. s:cmd_winid, 989 \ 'BufLeave ' .. s:cmd_bufnr, 990 \ 'WinLeave ' .. s:cmd_winid, 991 \ 'WinEnter ' .. org_winid, 992 \ 'BufEnter ' .. org_bufnr, 993 \ ], s:seq) 994 995 au! 996 augroup END 997endfunc 998 999func Test_verbosefile() 1000 set verbosefile=Xlog 1001 echomsg 'foo' 1002 echomsg 'bar' 1003 set verbosefile= 1004 let log = readfile('Xlog') 1005 call assert_match("foo\nbar", join(log, "\n")) 1006 call delete('Xlog') 1007 call mkdir('Xdir') 1008 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) 1009 call delete('Xdir', 'd') 1010endfunc 1011 1012func Test_verbose_option() 1013 CheckScreendump 1014 1015 let lines =<< trim [SCRIPT] 1016 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 1017 call feedkeys("\r", 't') " for the hit-enter prompt 1018 set verbose=20 1019 [SCRIPT] 1020 call writefile(lines, 'XTest_verbose') 1021 1022 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) 1023 call TermWait(buf, 50) 1024 call term_sendkeys(buf, ":DoSomething\<CR>") 1025 call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) 1026 1027 " clean up 1028 call StopVimInTerminal(buf) 1029 call delete('XTest_verbose') 1030endfunc 1031 1032func Test_setcmdpos() 1033 func InsertTextAtPos(text, pos) 1034 call assert_equal(0, setcmdpos(a:pos)) 1035 return a:text 1036 endfunc 1037 1038 " setcmdpos() with position in the middle of the command line. 1039 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1040 call assert_equal('"1ab2', @:) 1041 1042 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1043 call assert_equal('"1b2a', @:) 1044 1045 " setcmdpos() with position beyond the end of the command line. 1046 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 1047 call assert_equal('"12ab', @:) 1048 1049 " setcmdpos() returns 1 when not editing the command line. 1050 call assert_equal(1, 3->setcmdpos()) 1051endfunc 1052 1053func Test_cmdline_overstrike() 1054 let encodings = ['latin1', 'utf8'] 1055 let encoding_save = &encoding 1056 1057 for e in encodings 1058 exe 'set encoding=' . e 1059 1060 " Test overstrike in the middle of the command line. 1061 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1062 call assert_equal('"0ab1cd4', @:, e) 1063 1064 " Test overstrike going beyond end of command line. 1065 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 1066 call assert_equal('"0ab1cdefgh', @:, e) 1067 1068 " Test toggling insert/overstrike a few times. 1069 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 1070 call assert_equal('"ab0cd3ef4', @:, e) 1071 endfor 1072 1073 " Test overstrike with multi-byte characters. 1074 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1075 call assert_equal('"テabキcdエディタ', @:, e) 1076 1077 let &encoding = encoding_save 1078endfunc 1079 1080func Test_cmdwin_bug() 1081 let winid = win_getid() 1082 sp 1083 try 1084 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') 1085 catch /^Vim\%((\a\+)\)\=:E11/ 1086 endtry 1087 bw! 1088endfunc 1089 1090func Test_cmdwin_restore() 1091 CheckScreendump 1092 1093 let lines =<< trim [SCRIPT] 1094 call setline(1, range(30)) 1095 2split 1096 [SCRIPT] 1097 call writefile(lines, 'XTest_restore') 1098 1099 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) 1100 call TermWait(buf, 50) 1101 call term_sendkeys(buf, "q:") 1102 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) 1103 1104 " normal restore 1105 call term_sendkeys(buf, ":q\<CR>") 1106 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) 1107 1108 " restore after setting 'lines' with one window 1109 call term_sendkeys(buf, ":close\<CR>") 1110 call term_sendkeys(buf, "q:") 1111 call term_sendkeys(buf, ":set lines=18\<CR>") 1112 call term_sendkeys(buf, ":q\<CR>") 1113 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) 1114 1115 " clean up 1116 call StopVimInTerminal(buf) 1117 call delete('XTest_restore') 1118endfunc 1119 1120func Test_buffers_lastused() 1121 " check that buffers are sorted by time when wildmode has lastused 1122 call test_settime(1550020000) " middle 1123 edit bufa 1124 enew 1125 call test_settime(1550030000) " newest 1126 edit bufb 1127 enew 1128 call test_settime(1550010000) " oldest 1129 edit bufc 1130 enew 1131 call test_settime(0) 1132 enew 1133 1134 call assert_equal(['bufa', 'bufb', 'bufc'], 1135 \ getcompletion('', 'buffer')) 1136 1137 let save_wildmode = &wildmode 1138 set wildmode=full:lastused 1139 1140 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" 1141 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1142 call assert_equal('b bufb', X) 1143 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1144 call assert_equal('b bufa', X) 1145 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1146 call assert_equal('b bufc', X) 1147 enew 1148 1149 edit other 1150 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1151 call assert_equal('b bufb', X) 1152 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1153 call assert_equal('b bufa', X) 1154 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1155 call assert_equal('b bufc', X) 1156 enew 1157 1158 let &wildmode = save_wildmode 1159 1160 bwipeout bufa 1161 bwipeout bufb 1162 bwipeout bufc 1163endfunc 1164 1165func Test_cmdwin_feedkeys() 1166 " This should not generate E488 1167 call feedkeys("q:\<CR>", 'x') 1168 " Using feedkeys with q: only should automatically close the cmd window 1169 call feedkeys('q:', 'xt') 1170 call assert_equal(1, winnr('$')) 1171 call assert_equal('', getcmdwintype()) 1172endfunc 1173 1174" Tests for the issues fixed in 7.4.441. 1175" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim 1176func Test_cmdwin_cedit() 1177 exe "set cedit=\<C-c>" 1178 normal! : 1179 call assert_equal(1, winnr('$')) 1180 1181 let g:cmd_wintype = '' 1182 func CmdWinType() 1183 let g:cmd_wintype = getcmdwintype() 1184 let g:wintype = win_gettype() 1185 return '' 1186 endfunc 1187 1188 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") 1189 echo input('') 1190 call assert_equal('@', g:cmd_wintype) 1191 call assert_equal('command', g:wintype) 1192 1193 set cedit&vim 1194 delfunc CmdWinType 1195endfunc 1196 1197" Test for CmdwinEnter autocmd 1198func Test_cmdwin_autocmd() 1199 augroup CmdWin 1200 au! 1201 autocmd CmdwinEnter * startinsert 1202 augroup END 1203 1204 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') 1205 call assert_equal('xyz', @:) 1206 1207 augroup CmdWin 1208 au! 1209 augroup END 1210 augroup! CmdWin 1211endfunc 1212 1213func Test_cmdlineclear_tabenter() 1214 CheckScreendump 1215 1216 let lines =<< trim [SCRIPT] 1217 call setline(1, range(30)) 1218 [SCRIPT] 1219 1220 call writefile(lines, 'XtestCmdlineClearTabenter') 1221 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) 1222 call TermWait(buf, 25) 1223 " in one tab make the command line higher with CTRL-W - 1224 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") 1225 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) 1226 1227 call StopVimInTerminal(buf) 1228 call delete('XtestCmdlineClearTabenter') 1229endfunc 1230 1231" Test for failure in expanding special keywords in cmdline 1232func Test_cmdline_expand_special() 1233 %bwipe! 1234 call assert_fails('e #', 'E499:') 1235 call assert_fails('e <afile>', 'E495:') 1236 call assert_fails('e <abuf>', 'E496:') 1237 call assert_fails('e <amatch>', 'E497:') 1238endfunc 1239 1240func Test_cmdwin_jump_to_win() 1241 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') 1242 new 1243 set modified 1244 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:']) 1245 close! 1246 call feedkeys("q/:close\<CR>", "xt") 1247 call assert_equal(1, winnr('$')) 1248 call feedkeys("q/:exit\<CR>", "xt") 1249 call assert_equal(1, winnr('$')) 1250 1251 " opening command window twice should fail 1252 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') 1253 call assert_equal(1, winnr('$')) 1254endfunc 1255 1256func Test_cmdwin_interrupted() 1257 CheckScreendump 1258 1259 " aborting the :smile output caused the cmdline window to use the current 1260 " buffer. 1261 let lines =<< trim [SCRIPT] 1262 au WinNew * smile 1263 [SCRIPT] 1264 call writefile(lines, 'XTest_cmdwin') 1265 1266 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18}) 1267 " open cmdwin 1268 call term_sendkeys(buf, "q:") 1269 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))}) 1270 " quit more prompt for :smile command 1271 call term_sendkeys(buf, "q") 1272 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))}) 1273 " execute a simple command 1274 call term_sendkeys(buf, "aecho 'done'\<CR>") 1275 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {}) 1276 1277 " clean up 1278 call StopVimInTerminal(buf) 1279 call delete('XTest_cmdwin') 1280endfunc 1281 1282" Test for backtick expression in the command line 1283func Test_cmd_backtick() 1284 %argd 1285 argadd `=['a', 'b', 'c']` 1286 call assert_equal(['a', 'b', 'c'], argv()) 1287 %argd 1288endfunc 1289 1290" Test for the :! command 1291func Test_cmd_bang() 1292 CheckUnix 1293 1294 let lines =<< trim [SCRIPT] 1295 " Test for no previous command 1296 call assert_fails('!!', 'E34:') 1297 set nomore 1298 " Test for cmdline expansion with :! 1299 call setline(1, 'foo!') 1300 silent !echo <cWORD> > Xfile.out 1301 call assert_equal(['foo!'], readfile('Xfile.out')) 1302 " Test for using previous command 1303 silent !echo \! ! 1304 call assert_equal(['! echo foo!'], readfile('Xfile.out')) 1305 call writefile(v:errors, 'Xresult') 1306 call delete('Xfile.out') 1307 qall! 1308 [SCRIPT] 1309 call writefile(lines, 'Xscript') 1310 if RunVim([], [], '--clean -S Xscript') 1311 call assert_equal([], readfile('Xresult')) 1312 endif 1313 call delete('Xscript') 1314 call delete('Xresult') 1315endfunc 1316 1317" Test error: "E135: *Filter* Autocommands must not change current buffer" 1318func Test_cmd_bang_E135() 1319 new 1320 call setline(1, ['a', 'b', 'c', 'd']) 1321 augroup test_cmd_filter_E135 1322 au! 1323 autocmd FilterReadPost * help 1324 augroup END 1325 call assert_fails('2,3!echo "x"', 'E135:') 1326 1327 augroup test_cmd_filter_E135 1328 au! 1329 augroup END 1330 %bwipe! 1331endfunc 1332 1333" Test for using ~ for home directory in cmdline completion matches 1334func Test_cmdline_expand_home() 1335 call mkdir('Xdir') 1336 call writefile([], 'Xdir/Xfile1') 1337 call writefile([], 'Xdir/Xfile2') 1338 cd Xdir 1339 let save_HOME = $HOME 1340 let $HOME = getcwd() 1341 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') 1342 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) 1343 let $HOME = save_HOME 1344 cd .. 1345 call delete('Xdir', 'rf') 1346endfunc 1347 1348" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode 1349" or insert mode (when 'insertmode' is set) 1350func Test_cmdline_ctrl_g() 1351 new 1352 call setline(1, 'abc') 1353 call cursor(1, 3) 1354 " If command line is entered from insert mode, using C-\ C-G should back to 1355 " insert mode 1356 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') 1357 call assert_equal('abxyc', getline(1)) 1358 call assert_equal(4, col('.')) 1359 1360 " If command line is entered in 'insertmode', using C-\ C-G should back to 1361 " 'insertmode' 1362 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') 1363 call assert_equal('ab12xyc', getline(1)) 1364 close! 1365endfunc 1366 1367" Test for 'wildmode' 1368func Test_wildmode() 1369 func T(a, c, p) 1370 return "oneA\noneB\noneC" 1371 endfunc 1372 command -nargs=1 -complete=custom,T MyCmd 1373 1374 func SaveScreenLine() 1375 let g:Sline = Screenline(&lines - 1) 1376 return '' 1377 endfunc 1378 cnoremap <expr> <F2> SaveScreenLine() 1379 1380 set nowildmenu 1381 set wildmode=full,list 1382 let g:Sline = '' 1383 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') 1384 call assert_equal('oneA oneB oneC', g:Sline) 1385 call assert_equal('"MyCmd oneA', @:) 1386 1387 set wildmode=longest,full 1388 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 1389 call assert_equal('"MyCmd one', @:) 1390 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') 1391 call assert_equal('"MyCmd oneC', @:) 1392 1393 set wildmode=longest 1394 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') 1395 call assert_equal('"MyCmd one', @:) 1396 1397 set wildmode=list:longest 1398 let g:Sline = '' 1399 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') 1400 call assert_equal('oneA oneB oneC', g:Sline) 1401 call assert_equal('"MyCmd one', @:) 1402 1403 set wildmode="" 1404 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') 1405 call assert_equal('"MyCmd oneA', @:) 1406 1407 " Test for wildmode=longest with 'fileignorecase' set 1408 set wildmode=longest 1409 set fileignorecase 1410 argadd AAA AAAA AAAAA 1411 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') 1412 call assert_equal('"buffer AAA', @:) 1413 set fileignorecase& 1414 1415 " Test for listing files with wildmode=list 1416 set wildmode=list 1417 let g:Sline = '' 1418 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt') 1419 call assert_equal('AAA AAAA AAAAA', g:Sline) 1420 call assert_equal('"b A', @:) 1421 1422 %argdelete 1423 delcommand MyCmd 1424 delfunc T 1425 delfunc SaveScreenLine 1426 cunmap <F2> 1427 set wildmode& 1428 %bwipe! 1429endfunc 1430 1431" Test for interrupting the command-line completion 1432func Test_interrupt_compl() 1433 func F(lead, cmdl, p) 1434 if a:lead =~ 'tw' 1435 call interrupt() 1436 return 1437 endif 1438 return "one\ntwo\nthree" 1439 endfunc 1440 command -nargs=1 -complete=custom,F Tcmd 1441 1442 set nowildmenu 1443 set wildmode=full 1444 let interrupted = 0 1445 try 1446 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') 1447 catch /^Vim:Interrupt$/ 1448 let interrupted = 1 1449 endtry 1450 call assert_equal(1, interrupted) 1451 1452 delcommand Tcmd 1453 delfunc F 1454 set wildmode& 1455endfunc 1456 1457" Test for moving the cursor on the : command line 1458func Test_cmdline_edit() 1459 let str = ":one two\<C-U>" 1460 let str ..= "one two\<C-W>\<C-W>" 1461 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1462 let str ..= "\<Left>five\<Right>" 1463 let str ..= "\<Home>two " 1464 let str ..= "\<C-Left>one " 1465 let str ..= "\<C-Right> three" 1466 let str ..= "\<End>\<S-Left>four " 1467 let str ..= "\<S-Right> six" 1468 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1469 call feedkeys(str, 'xt') 1470 call assert_equal("\"one two three four five six seven", @:) 1471endfunc 1472 1473" Test for moving the cursor on the / command line in 'rightleft' mode 1474func Test_cmdline_edit_rightleft() 1475 CheckFeature rightleft 1476 set rightleft 1477 set rightleftcmd=search 1478 let str = "/one two\<C-U>" 1479 let str ..= "one two\<C-W>\<C-W>" 1480 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1481 let str ..= "\<Right>five\<Left>" 1482 let str ..= "\<Home>two " 1483 let str ..= "\<C-Right>one " 1484 let str ..= "\<C-Left> three" 1485 let str ..= "\<End>\<S-Right>four " 1486 let str ..= "\<S-Left> six" 1487 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1488 call assert_fails("call feedkeys(str, 'xt')", 'E486:') 1489 call assert_equal("\"one two three four five six seven", @/) 1490 set rightleftcmd& 1491 set rightleft& 1492endfunc 1493 1494" Test for using <C-\>e in the command line to evaluate an expression 1495func Test_cmdline_expr() 1496 " Evaluate an expression from the beginning of a command line 1497 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') 1498 call assert_equal('"hello', @:) 1499 1500 " Use an invalid expression for <C-\>e 1501 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 1502 1503 " Insert literal <CTRL-\> in the command line 1504 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') 1505 call assert_equal("\"e \<C-\>\<C-Y>", @:) 1506endfunc 1507 1508" Test for 'imcmdline' and 'imsearch' 1509" This test doesn't actually test the input method functionality. 1510func Test_cmdline_inputmethod() 1511 new 1512 call setline(1, ['', 'abc', '']) 1513 set imcmdline 1514 1515 call feedkeys(":\"abc\<CR>", 'xt') 1516 call assert_equal("\"abc", @:) 1517 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') 1518 call assert_equal("\"abc", @:) 1519 call feedkeys("/abc\<CR>", 'xt') 1520 call assert_equal([2, 1], [line('.'), col('.')]) 1521 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1522 call assert_equal([2, 1], [line('.'), col('.')]) 1523 1524 set imsearch=2 1525 call cursor(1, 1) 1526 call feedkeys("/abc\<CR>", 'xt') 1527 call assert_equal([2, 1], [line('.'), col('.')]) 1528 call cursor(1, 1) 1529 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1530 call assert_equal([2, 1], [line('.'), col('.')]) 1531 set imdisable 1532 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1533 call assert_equal([2, 1], [line('.'), col('.')]) 1534 set imdisable& 1535 set imsearch& 1536 1537 set imcmdline& 1538 %bwipe! 1539endfunc 1540 1541" Test for recursively getting multiple command line inputs 1542func Test_cmdwin_multi_input() 1543 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') 1544 call assert_equal('"cyan', @:) 1545endfunc 1546 1547" Test for using CTRL-_ in the command line with 'allowrevins' 1548func Test_cmdline_revins() 1549 CheckNotMSWindows 1550 CheckFeature rightleft 1551 call feedkeys(":\"abc\<c-_>\<cr>", 'xt') 1552 call assert_equal("\"abc\<c-_>", @:) 1553 set allowrevins 1554 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') 1555 call assert_equal('"abcñèæ', @:) 1556 set allowrevins& 1557endfunc 1558 1559" Test for typing UTF-8 composing characters in the command line 1560func Test_cmdline_composing_chars() 1561 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') 1562 call assert_equal('"ゔ', @:) 1563endfunc 1564 1565" Test for normal mode commands not supported in the cmd window 1566func Test_cmdwin_blocked_commands() 1567 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') 1568 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') 1569 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') 1570 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') 1571 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') 1572 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') 1573 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:') 1574 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:') 1575 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:') 1576 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:') 1577 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:') 1578 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:') 1579 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:') 1580 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:') 1581 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:') 1582 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:') 1583 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:') 1584 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:') 1585 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:') 1586 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:') 1587 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:') 1588 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:') 1589 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:') 1590 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:') 1591 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:') 1592 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:') 1593 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:') 1594endfunc 1595 1596" Close the Cmd-line window in insert mode using CTRL-C 1597func Test_cmdwin_insert_mode_close() 1598 %bw! 1599 let s = '' 1600 exe "normal q:a\<C-C>let s='Hello'\<CR>" 1601 call assert_equal('Hello', s) 1602 call assert_equal(1, winnr('$')) 1603endfunc 1604 1605" test that ";" works to find a match at the start of the first line 1606func Test_zero_line_search() 1607 new 1608 call setline(1, ["1, pattern", "2, ", "3, pattern"]) 1609 call cursor(1,1) 1610 0;/pattern/d 1611 call assert_equal(["2, ", "3, pattern"], getline(1,'$')) 1612 q! 1613endfunc 1614 1615func Test_read_shellcmd() 1616 CheckUnix 1617 if executable('ls') 1618 " There should be ls in the $PATH 1619 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') 1620 call assert_match('^"r! .*\<ls\>', @:) 1621 endif 1622 1623 if executable('rm') 1624 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') 1625 call assert_notmatch('^"r!.*\<runtest.vim\>', @:) 1626 call assert_match('^"r!.*\<rm\>', @:) 1627 1628 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') 1629 call assert_notmatch('^"r.*\<runtest.vim\>', @:) 1630 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) 1631 endif 1632endfunc 1633 1634" vim: shiftwidth=2 sts=2 expandtab 1635