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