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