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