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