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