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