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', @:) 660endfunc 661 662func Test_cmdline_complete_user_names() 663 if has('unix') && executable('whoami') 664 let whoami = systemlist('whoami')[0] 665 let first_letter = whoami[0] 666 if len(first_letter) > 0 667 " Trying completion of :e ~x where x is the first letter of 668 " the user name should complete to at least the user name. 669 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 670 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 671 endif 672 elseif has('win32') 673 " Just in case: check that the system has an Administrator account. 674 let names = system('net user') 675 if names =~ 'Administrator' 676 " Trying completion of :e ~A should complete to Administrator. 677 " There could be other names starting with "A" before Administrator. 678 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 679 call assert_match('^"e \~.*Administrator', @:) 680 endif 681 else 682 throw 'Skipped: does not work on this platform' 683 endif 684endfunc 685 686func Test_cmdline_complete_bang() 687 CheckExecutable whoami 688 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') 689 call assert_match('^".*\<whoami\>', @:) 690endfunc 691 692func Test_cmdline_complete_languages() 693 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') 694 call assert_equal(lang, v:lc_time) 695 696 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') 697 call assert_equal(lang, v:ctype) 698 699 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') 700 call assert_equal(lang, v:collate) 701 702 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 703 call assert_equal(lang, v:lang) 704 705 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 706 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) 707 708 call assert_match('^"language .*\<' . lang . '\>', @:) 709 710 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 711 call assert_match('^"language .*\<' . lang . '\>', @:) 712 713 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 714 call assert_match('^"language .*\<' . lang . '\>', @:) 715 716 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 717 call assert_match('^"language .*\<' . lang . '\>', @:) 718 719 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') 720 call assert_match('^"language .*\<' . lang . '\>', @:) 721endfunc 722 723func Test_cmdline_complete_env_variable() 724 let $X_VIM_TEST_COMPLETE_ENV = 'foo' 725 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') 726 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) 727 unlet $X_VIM_TEST_COMPLETE_ENV 728endfunc 729 730func Test_cmdline_complete_expression() 731 let g:SomeVar = 'blah' 732 for cmd in ['exe', 'echo', 'echon', 'echomsg'] 733 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 734 call assert_match('"' .. cmd .. ' SomeVar', @:) 735 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 736 call assert_match('"' .. cmd .. ' foo SomeVar', @:) 737 endfor 738 unlet g:SomeVar 739endfunc 740 741" Test for various command-line completion 742func Test_cmdline_complete_various() 743 " completion for a command starting with a comment 744 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') 745 call assert_equal("\" :|\"\<C-A>", @:) 746 747 " completion for a range followed by a comment 748 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') 749 call assert_equal("\"1,2\"\<C-A>", @:) 750 751 " completion for :k command 752 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') 753 call assert_equal("\"ka\<C-A>", @:) 754 755 " completion for short version of the :s command 756 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') 757 call assert_equal("\"sI \<C-A>", @:) 758 759 " completion for :write command 760 call mkdir('Xdir') 761 call writefile(['one'], 'Xdir/Xfile1') 762 let save_cwd = getcwd() 763 cd Xdir 764 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') 765 call assert_equal("\"w >> Xfile1", @:) 766 call chdir(save_cwd) 767 call delete('Xdir', 'rf') 768 769 " completion for :w ! and :r ! commands 770 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 771 call assert_equal("\"w !invalid_xyz_cmd", @:) 772 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 773 call assert_equal("\"r !invalid_xyz_cmd", @:) 774 775 " completion for :>> and :<< commands 776 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') 777 call assert_equal("\">>>\<C-A>", @:) 778 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') 779 call assert_equal("\"<<<\<C-A>", @:) 780 781 " completion for command with +cmd argument 782 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') 783 call assert_equal("\"buffer +/pat Xabc", @:) 784 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') 785 call assert_equal("\"buffer +/pat\<C-A>", @:) 786 787 " completion for a command with a trailing comment 788 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') 789 call assert_equal("\"ls \" comment\<C-A>", @:) 790 791 " completion for a command with a trailing command 792 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') 793 call assert_equal("\"ls | ls", @:) 794 795 " completion for a command with an CTRL-V escaped argument 796 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') 797 call assert_equal("\"ls \<C-V>a\<C-A>", @:) 798 799 " completion for a command that doesn't take additional arguments 800 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') 801 call assert_equal("\"all abc\<C-A>", @:) 802 803 " completion for a command with a command modifier 804 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') 805 call assert_equal("\"topleft new", @:) 806 807 " completion for vim9 and legacy commands 808 call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt') 809 call assert_equal("\"vim9 call strlen(", @:) 810 call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt') 811 call assert_equal("\"legac call strlen(", @:) 812 813 " completion for the :disassemble command 814 call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt') 815 call assert_equal("\"disas debug", @:) 816 call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt') 817 call assert_equal("\"disas profile", @:) 818 call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') 819 call assert_equal("\"disas debug Test_cmdline_complete_various", @:) 820 call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') 821 call assert_equal("\"disas profile Test_cmdline_complete_various", @:) 822 823 " completion for the :match command 824 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') 825 call assert_equal("\"match Search /pat/\<C-A>", @:) 826 827 " completion for the :s command 828 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt') 829 call assert_equal("\"s/from/to/g\<C-A>", @:) 830 831 " completion for the :dlist command 832 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') 833 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) 834 835 " completion for the :doautocmd command 836 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') 837 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) 838 839 " completion of autocmd group after comma 840 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') 841 call assert_equal("\"doautocmd BufNew,BufEnter", @:) 842 843 " completion for the :augroup command 844 augroup XTest 845 augroup END 846 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') 847 call assert_equal("\"augroup XTest", @:) 848 augroup! XTest 849 850 " completion for the :unlet command 851 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') 852 call assert_equal("\"unlet one two", @:) 853 854 " completion for the :bdelete command 855 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') 856 call assert_equal("\"bdel a b c", @:) 857 858 " completion for the :mapclear command 859 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') 860 call assert_equal("\"mapclear <buffer>", @:) 861 862 " completion for user defined commands with menu names 863 menu Test.foo :ls<CR> 864 com -nargs=* -complete=menu MyCmd 865 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') 866 call assert_equal('"MyCmd Test.', @:) 867 delcom MyCmd 868 unmenu Test 869 870 " completion for user defined commands with mappings 871 mapclear 872 map <F3> :ls<CR> 873 com -nargs=* -complete=mapping MyCmd 874 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') 875 call assert_equal('"MyCmd <F3>', @:) 876 mapclear 877 delcom MyCmd 878 879 " completion for :set path= with multiple backslashes 880 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 881 call assert_equal('"set path=a\\\ b', @:) 882 883 " completion for :set dir= with a backslash 884 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 885 call assert_equal('"set dir=a\ b', @:) 886 887 " completion for the :py3 commands 888 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') 889 call assert_equal('"py3 py3do py3file', @:) 890 891 " completion for the :vim9 commands 892 call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt') 893 call assert_equal('"vim9cmd vim9script', @:) 894 895 " redir @" is not the start of a comment. So complete after that 896 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') 897 call assert_equal('"redir @" | cwindow', @:) 898 899 " completion after a backtick 900 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') 901 call assert_equal('"e `a1b2c', @:) 902 903 " completion for :language command with an invalid argument 904 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') 905 call assert_equal("\"language dummy \t", @:) 906 907 " completion for commands after a :global command 908 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') 909 call assert_equal('"g/a\xb/clearjumps', @:) 910 911 " completion with ambiguous user defined commands 912 com TCmd1 echo 'TCmd1' 913 com TCmd2 echo 'TCmd2' 914 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') 915 call assert_equal('"TCmd ', @:) 916 delcom TCmd1 917 delcom TCmd2 918 919 " completion after a range followed by a pipe (|) character 920 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') 921 call assert_equal('"1,10 | chistory', @:) 922 923 " use <Esc> as the 'wildchar' for completion 924 set wildchar=<Esc> 925 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') 926 call assert_equal('"g/a\xb/clearjumps', @:) 927 " pressing <esc> twice should cancel the command 928 call feedkeys(":chist\<Esc>\<Esc>", 'xt') 929 call assert_equal('"g/a\xb/clearjumps', @:) 930 set wildchar& 931endfunc 932 933func Test_cmdline_write_alternatefile() 934 new 935 call setline('.', ['one', 'two']) 936 f foo.txt 937 new 938 f #-A 939 call assert_equal('foo.txt-A', expand('%')) 940 f #<-B.txt 941 call assert_equal('foo-B.txt', expand('%')) 942 f %< 943 call assert_equal('foo-B', expand('%')) 944 new 945 call assert_fails('f #<', 'E95:') 946 bw! 947 f foo-B.txt 948 f %<-A 949 call assert_equal('foo-B-A', expand('%')) 950 bw! 951 bw! 952endfunc 953 954" using a leading backslash here 955set cpo+=C 956 957func Test_cmdline_search_range() 958 new 959 call setline(1, ['a', 'b', 'c', 'd']) 960 /d 961 1,\/s/b/B/ 962 call assert_equal('B', getline(2)) 963 964 /a 965 $ 966 \?,4s/c/C/ 967 call assert_equal('C', getline(3)) 968 969 call setline(1, ['a', 'b', 'c', 'd']) 970 %s/c/c/ 971 1,\&s/b/B/ 972 call assert_equal('B', getline(2)) 973 974 let @/ = 'apple' 975 call assert_fails('\/print', ['E486:.*apple']) 976 977 bwipe! 978endfunc 979 980" Test for the tick mark (') in an excmd range 981func Test_tick_mark_in_range() 982 " If only the tick is passed as a range and no command is specified, there 983 " should not be an error 984 call feedkeys(":'\<CR>", 'xt') 985 call assert_equal("'", getreg(':')) 986 call assert_fails("',print", 'E78:') 987endfunc 988 989" Test for using a line number followed by a search pattern as range 990func Test_lnum_and_pattern_as_range() 991 new 992 call setline(1, ['foo 1', 'foo 2', 'foo 3']) 993 let @" = '' 994 2/foo/yank 995 call assert_equal("foo 3\n", @") 996 call assert_equal(1, line('.')) 997 close! 998endfunc 999 1000" Tests for getcmdline(), getcmdpos() and getcmdtype() 1001func Check_cmdline(cmdtype) 1002 call assert_equal('MyCmd a', getcmdline()) 1003 call assert_equal(8, getcmdpos()) 1004 call assert_equal(a:cmdtype, getcmdtype()) 1005 return '' 1006endfunc 1007 1008set cpo& 1009 1010func Test_getcmdtype() 1011 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 1012 1013 let cmdtype = '' 1014 debuggreedy 1015 call feedkeys(":debug echo 'test'\<CR>", "t") 1016 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 1017 call feedkeys("cont\<CR>", "xt") 1018 0debuggreedy 1019 call assert_equal('>', cmdtype) 1020 1021 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 1022 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 1023 1024 call feedkeys(":call input('Answer?')\<CR>", "t") 1025 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 1026 1027 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 1028 1029 cnoremap <expr> <F6> Check_cmdline('=') 1030 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 1031 cunmap <F6> 1032 1033 call assert_equal('', getcmdline()) 1034endfunc 1035 1036func Test_getcmdwintype() 1037 CheckFeature cmdwin 1038 1039 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1040 call assert_equal('/', a) 1041 1042 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1043 call assert_equal('?', a) 1044 1045 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1046 call assert_equal(':', a) 1047 1048 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1049 call assert_equal(':', a) 1050 1051 call assert_equal('', getcmdwintype()) 1052endfunc 1053 1054func Test_getcmdwin_autocmd() 1055 CheckFeature cmdwin 1056 1057 let s:seq = [] 1058 augroup CmdWin 1059 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) 1060 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) 1061 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) 1062 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) 1063 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) 1064 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) 1065 1066 let org_winid = win_getid() 1067 let org_bufnr = bufnr() 1068 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') 1069 call assert_equal(':', a) 1070 call assert_equal([ 1071 \ 'WinLeave ' .. org_winid, 1072 \ 'WinEnter ' .. s:cmd_winid, 1073 \ 'BufLeave ' .. org_bufnr, 1074 \ 'BufEnter ' .. s:cmd_bufnr, 1075 \ 'CmdWinEnter ' .. s:cmd_winid, 1076 \ 'CmdWinLeave ' .. s:cmd_winid, 1077 \ 'BufLeave ' .. s:cmd_bufnr, 1078 \ 'WinLeave ' .. s:cmd_winid, 1079 \ 'WinEnter ' .. org_winid, 1080 \ 'BufEnter ' .. org_bufnr, 1081 \ ], s:seq) 1082 1083 au! 1084 augroup END 1085endfunc 1086 1087func Test_verbosefile() 1088 set verbosefile=Xlog 1089 echomsg 'foo' 1090 echomsg 'bar' 1091 set verbosefile= 1092 let log = readfile('Xlog') 1093 call assert_match("foo\nbar", join(log, "\n")) 1094 call delete('Xlog') 1095 call mkdir('Xdir') 1096 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) 1097 call delete('Xdir', 'd') 1098endfunc 1099 1100func Test_verbose_option() 1101 CheckScreendump 1102 1103 let lines =<< trim [SCRIPT] 1104 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 1105 call feedkeys("\r", 't') " for the hit-enter prompt 1106 set verbose=20 1107 [SCRIPT] 1108 call writefile(lines, 'XTest_verbose') 1109 1110 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) 1111 call TermWait(buf, 50) 1112 call term_sendkeys(buf, ":DoSomething\<CR>") 1113 call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) 1114 1115 " clean up 1116 call StopVimInTerminal(buf) 1117 call delete('XTest_verbose') 1118endfunc 1119 1120func Test_setcmdpos() 1121 func InsertTextAtPos(text, pos) 1122 call assert_equal(0, setcmdpos(a:pos)) 1123 return a:text 1124 endfunc 1125 1126 " setcmdpos() with position in the middle of the command line. 1127 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1128 call assert_equal('"1ab2', @:) 1129 1130 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1131 call assert_equal('"1b2a', @:) 1132 1133 " setcmdpos() with position beyond the end of the command line. 1134 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 1135 call assert_equal('"12ab', @:) 1136 1137 " setcmdpos() returns 1 when not editing the command line. 1138 call assert_equal(1, 3->setcmdpos()) 1139endfunc 1140 1141func Test_cmdline_overstrike() 1142 let encodings = ['latin1', 'utf8'] 1143 let encoding_save = &encoding 1144 1145 for e in encodings 1146 exe 'set encoding=' . e 1147 1148 " Test overstrike in the middle of the command line. 1149 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1150 call assert_equal('"0ab1cd4', @:, e) 1151 1152 " Test overstrike going beyond end of command line. 1153 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 1154 call assert_equal('"0ab1cdefgh', @:, e) 1155 1156 " Test toggling insert/overstrike a few times. 1157 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 1158 call assert_equal('"ab0cd3ef4', @:, e) 1159 endfor 1160 1161 " Test overstrike with multi-byte characters. 1162 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1163 call assert_equal('"テabキcdエディタ', @:, e) 1164 1165 let &encoding = encoding_save 1166endfunc 1167 1168func Test_cmdwin_bug() 1169 CheckFeature cmdwin 1170 1171 let winid = win_getid() 1172 sp 1173 try 1174 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') 1175 catch /^Vim\%((\a\+)\)\=:E11/ 1176 endtry 1177 bw! 1178endfunc 1179 1180func Test_cmdwin_restore() 1181 CheckFeature cmdwin 1182 CheckScreendump 1183 1184 let lines =<< trim [SCRIPT] 1185 call setline(1, range(30)) 1186 2split 1187 [SCRIPT] 1188 call writefile(lines, 'XTest_restore') 1189 1190 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) 1191 call TermWait(buf, 50) 1192 call term_sendkeys(buf, "q:") 1193 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) 1194 1195 " normal restore 1196 call term_sendkeys(buf, ":q\<CR>") 1197 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) 1198 1199 " restore after setting 'lines' with one window 1200 call term_sendkeys(buf, ":close\<CR>") 1201 call term_sendkeys(buf, "q:") 1202 call term_sendkeys(buf, ":set lines=18\<CR>") 1203 call term_sendkeys(buf, ":q\<CR>") 1204 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) 1205 1206 " clean up 1207 call StopVimInTerminal(buf) 1208 call delete('XTest_restore') 1209endfunc 1210 1211func Test_cmdwin_no_terminal() 1212 CheckFeature cmdwin 1213 CheckFeature terminal 1214 CheckNotMSWindows 1215 1216 let buf = RunVimInTerminal('', {'rows': 12}) 1217 call TermWait(buf, 50) 1218 call term_sendkeys(buf, ":set cmdheight=2\<CR>") 1219 call term_sendkeys(buf, "q:") 1220 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>") 1221 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {}) 1222 call term_sendkeys(buf, ":q\<CR>") 1223 call StopVimInTerminal(buf) 1224endfunc 1225 1226func Test_buffers_lastused() 1227 " check that buffers are sorted by time when wildmode has lastused 1228 call test_settime(1550020000) " middle 1229 edit bufa 1230 enew 1231 call test_settime(1550030000) " newest 1232 edit bufb 1233 enew 1234 call test_settime(1550010000) " oldest 1235 edit bufc 1236 enew 1237 call test_settime(0) 1238 enew 1239 1240 call assert_equal(['bufa', 'bufb', 'bufc'], 1241 \ getcompletion('', 'buffer')) 1242 1243 let save_wildmode = &wildmode 1244 set wildmode=full:lastused 1245 1246 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" 1247 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1248 call assert_equal('b bufb', X) 1249 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1250 call assert_equal('b bufa', X) 1251 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1252 call assert_equal('b bufc', X) 1253 enew 1254 1255 edit other 1256 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1257 call assert_equal('b bufb', X) 1258 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1259 call assert_equal('b bufa', X) 1260 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1261 call assert_equal('b bufc', X) 1262 enew 1263 1264 let &wildmode = save_wildmode 1265 1266 bwipeout bufa 1267 bwipeout bufb 1268 bwipeout bufc 1269endfunc 1270 1271func Test_cmdwin_feedkeys() 1272 CheckFeature cmdwin 1273 1274 " This should not generate E488 1275 call feedkeys("q:\<CR>", 'x') 1276 " Using feedkeys with q: only should automatically close the cmd window 1277 call feedkeys('q:', 'xt') 1278 call assert_equal(1, winnr('$')) 1279 call assert_equal('', getcmdwintype()) 1280endfunc 1281 1282" Tests for the issues fixed in 7.4.441. 1283" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim 1284func Test_cmdwin_cedit() 1285 CheckFeature cmdwin 1286 1287 exe "set cedit=\<C-c>" 1288 normal! : 1289 call assert_equal(1, winnr('$')) 1290 1291 let g:cmd_wintype = '' 1292 func CmdWinType() 1293 let g:cmd_wintype = getcmdwintype() 1294 let g:wintype = win_gettype() 1295 return '' 1296 endfunc 1297 1298 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") 1299 echo input('') 1300 call assert_equal('@', g:cmd_wintype) 1301 call assert_equal('command', g:wintype) 1302 1303 set cedit&vim 1304 delfunc CmdWinType 1305endfunc 1306 1307" Test for CmdwinEnter autocmd 1308func Test_cmdwin_autocmd() 1309 CheckFeature cmdwin 1310 1311 augroup CmdWin 1312 au! 1313 autocmd BufLeave * if &buftype == '' | update | endif 1314 autocmd CmdwinEnter * startinsert 1315 augroup END 1316 1317 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') 1318 call assert_equal('xyz', @:) 1319 1320 augroup CmdWin 1321 au! 1322 augroup END 1323 augroup! CmdWin 1324endfunc 1325 1326func Test_cmdlineclear_tabenter() 1327 CheckScreendump 1328 1329 let lines =<< trim [SCRIPT] 1330 call setline(1, range(30)) 1331 [SCRIPT] 1332 1333 call writefile(lines, 'XtestCmdlineClearTabenter') 1334 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) 1335 call TermWait(buf, 25) 1336 " in one tab make the command line higher with CTRL-W - 1337 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") 1338 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) 1339 1340 call StopVimInTerminal(buf) 1341 call delete('XtestCmdlineClearTabenter') 1342endfunc 1343 1344" Test for expanding special keywords in cmdline 1345func Test_cmdline_expand_special() 1346 %bwipe! 1347 call assert_fails('e #', 'E499:') 1348 call assert_fails('e <afile>', 'E495:') 1349 call assert_fails('e <abuf>', 'E496:') 1350 call assert_fails('e <amatch>', 'E497:') 1351 1352 call writefile([], 'Xfile.cpp') 1353 call writefile([], 'Xfile.java') 1354 new Xfile.cpp 1355 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt') 1356 call assert_equal('"e Xfile.cpp Xfile.java', @:) 1357 close 1358 call delete('Xfile.cpp') 1359 call delete('Xfile.java') 1360endfunc 1361 1362func Test_cmdwin_jump_to_win() 1363 CheckFeature cmdwin 1364 1365 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') 1366 new 1367 set modified 1368 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:']) 1369 close! 1370 call feedkeys("q/:close\<CR>", "xt") 1371 call assert_equal(1, winnr('$')) 1372 call feedkeys("q/:exit\<CR>", "xt") 1373 call assert_equal(1, winnr('$')) 1374 1375 " opening command window twice should fail 1376 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') 1377 call assert_equal(1, winnr('$')) 1378endfunc 1379 1380func Test_cmdwin_interrupted() 1381 CheckFeature cmdwin 1382 CheckScreendump 1383 1384 " aborting the :smile output caused the cmdline window to use the current 1385 " buffer. 1386 let lines =<< trim [SCRIPT] 1387 au WinNew * smile 1388 [SCRIPT] 1389 call writefile(lines, 'XTest_cmdwin') 1390 1391 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18}) 1392 " open cmdwin 1393 call term_sendkeys(buf, "q:") 1394 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))}) 1395 " quit more prompt for :smile command 1396 call term_sendkeys(buf, "q") 1397 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))}) 1398 " execute a simple command 1399 call term_sendkeys(buf, "aecho 'done'\<CR>") 1400 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {}) 1401 1402 " clean up 1403 call StopVimInTerminal(buf) 1404 call delete('XTest_cmdwin') 1405endfunc 1406 1407" Test for backtick expression in the command line 1408func Test_cmd_backtick() 1409 %argd 1410 argadd `=['a', 'b', 'c']` 1411 call assert_equal(['a', 'b', 'c'], argv()) 1412 %argd 1413endfunc 1414 1415" Test for the :! command 1416func Test_cmd_bang() 1417 CheckUnix 1418 1419 let lines =<< trim [SCRIPT] 1420 " Test for no previous command 1421 call assert_fails('!!', 'E34:') 1422 set nomore 1423 " Test for cmdline expansion with :! 1424 call setline(1, 'foo!') 1425 silent !echo <cWORD> > Xfile.out 1426 call assert_equal(['foo!'], readfile('Xfile.out')) 1427 " Test for using previous command 1428 silent !echo \! ! 1429 call assert_equal(['! echo foo!'], readfile('Xfile.out')) 1430 call writefile(v:errors, 'Xresult') 1431 call delete('Xfile.out') 1432 qall! 1433 [SCRIPT] 1434 call writefile(lines, 'Xscript') 1435 if RunVim([], [], '--clean -S Xscript') 1436 call assert_equal([], readfile('Xresult')) 1437 endif 1438 call delete('Xscript') 1439 call delete('Xresult') 1440endfunc 1441 1442" Test error: "E135: *Filter* Autocommands must not change current buffer" 1443func Test_cmd_bang_E135() 1444 new 1445 call setline(1, ['a', 'b', 'c', 'd']) 1446 augroup test_cmd_filter_E135 1447 au! 1448 autocmd FilterReadPost * help 1449 augroup END 1450 call assert_fails('2,3!echo "x"', 'E135:') 1451 1452 augroup test_cmd_filter_E135 1453 au! 1454 augroup END 1455 %bwipe! 1456endfunc 1457 1458" Test for using ~ for home directory in cmdline completion matches 1459func Test_cmdline_expand_home() 1460 call mkdir('Xdir') 1461 call writefile([], 'Xdir/Xfile1') 1462 call writefile([], 'Xdir/Xfile2') 1463 cd Xdir 1464 let save_HOME = $HOME 1465 let $HOME = getcwd() 1466 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') 1467 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) 1468 let $HOME = save_HOME 1469 cd .. 1470 call delete('Xdir', 'rf') 1471endfunc 1472 1473" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode 1474" or insert mode (when 'insertmode' is set) 1475func Test_cmdline_ctrl_g() 1476 new 1477 call setline(1, 'abc') 1478 call cursor(1, 3) 1479 " If command line is entered from insert mode, using C-\ C-G should back to 1480 " insert mode 1481 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') 1482 call assert_equal('abxyc', getline(1)) 1483 call assert_equal(4, col('.')) 1484 1485 " If command line is entered in 'insertmode', using C-\ C-G should back to 1486 " 'insertmode' 1487 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') 1488 call assert_equal('ab12xyc', getline(1)) 1489 close! 1490endfunc 1491 1492" Test for 'wildmode' 1493func Test_wildmode() 1494 func T(a, c, p) 1495 return "oneA\noneB\noneC" 1496 endfunc 1497 command -nargs=1 -complete=custom,T MyCmd 1498 1499 func SaveScreenLine() 1500 let g:Sline = Screenline(&lines - 1) 1501 return '' 1502 endfunc 1503 cnoremap <expr> <F2> SaveScreenLine() 1504 1505 set nowildmenu 1506 set wildmode=full,list 1507 let g:Sline = '' 1508 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') 1509 call assert_equal('oneA oneB oneC', g:Sline) 1510 call assert_equal('"MyCmd oneA', @:) 1511 1512 set wildmode=longest,full 1513 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 1514 call assert_equal('"MyCmd one', @:) 1515 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') 1516 call assert_equal('"MyCmd oneC', @:) 1517 1518 set wildmode=longest 1519 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') 1520 call assert_equal('"MyCmd one', @:) 1521 1522 set wildmode=list:longest 1523 let g:Sline = '' 1524 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') 1525 call assert_equal('oneA oneB oneC', g:Sline) 1526 call assert_equal('"MyCmd one', @:) 1527 1528 set wildmode="" 1529 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') 1530 call assert_equal('"MyCmd oneA', @:) 1531 1532 " Test for wildmode=longest with 'fileignorecase' set 1533 set wildmode=longest 1534 set fileignorecase 1535 argadd AAA AAAA AAAAA 1536 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') 1537 call assert_equal('"buffer AAA', @:) 1538 set fileignorecase& 1539 1540 " Test for listing files with wildmode=list 1541 set wildmode=list 1542 let g:Sline = '' 1543 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt') 1544 call assert_equal('AAA AAAA AAAAA', g:Sline) 1545 call assert_equal('"b A', @:) 1546 1547 %argdelete 1548 delcommand MyCmd 1549 delfunc T 1550 delfunc SaveScreenLine 1551 cunmap <F2> 1552 set wildmode& 1553 %bwipe! 1554endfunc 1555 1556" Test for interrupting the command-line completion 1557func Test_interrupt_compl() 1558 func F(lead, cmdl, p) 1559 if a:lead =~ 'tw' 1560 call interrupt() 1561 return 1562 endif 1563 return "one\ntwo\nthree" 1564 endfunc 1565 command -nargs=1 -complete=custom,F Tcmd 1566 1567 set nowildmenu 1568 set wildmode=full 1569 let interrupted = 0 1570 try 1571 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') 1572 catch /^Vim:Interrupt$/ 1573 let interrupted = 1 1574 endtry 1575 call assert_equal(1, interrupted) 1576 1577 delcommand Tcmd 1578 delfunc F 1579 set wildmode& 1580endfunc 1581 1582" Test for moving the cursor on the : command line 1583func Test_cmdline_edit() 1584 let str = ":one two\<C-U>" 1585 let str ..= "one two\<C-W>\<C-W>" 1586 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1587 let str ..= "\<Left>five\<Right>" 1588 let str ..= "\<Home>two " 1589 let str ..= "\<C-Left>one " 1590 let str ..= "\<C-Right> three" 1591 let str ..= "\<End>\<S-Left>four " 1592 let str ..= "\<S-Right> six" 1593 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1594 call feedkeys(str, 'xt') 1595 call assert_equal("\"one two three four five six seven", @:) 1596endfunc 1597 1598" Test for moving the cursor on the / command line in 'rightleft' mode 1599func Test_cmdline_edit_rightleft() 1600 CheckFeature rightleft 1601 set rightleft 1602 set rightleftcmd=search 1603 let str = "/one two\<C-U>" 1604 let str ..= "one two\<C-W>\<C-W>" 1605 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1606 let str ..= "\<Right>five\<Left>" 1607 let str ..= "\<Home>two " 1608 let str ..= "\<C-Right>one " 1609 let str ..= "\<C-Left> three" 1610 let str ..= "\<End>\<S-Right>four " 1611 let str ..= "\<S-Left> six" 1612 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1613 call assert_fails("call feedkeys(str, 'xt')", 'E486:') 1614 call assert_equal("\"one two three four five six seven", @/) 1615 set rightleftcmd& 1616 set rightleft& 1617endfunc 1618 1619" Test for using <C-\>e in the command line to evaluate an expression 1620func Test_cmdline_expr() 1621 " Evaluate an expression from the beginning of a command line 1622 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') 1623 call assert_equal('"hello', @:) 1624 1625 " Use an invalid expression for <C-\>e 1626 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 1627 1628 " Insert literal <CTRL-\> in the command line 1629 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') 1630 call assert_equal("\"e \<C-\>\<C-Y>", @:) 1631endfunc 1632 1633" Test for 'imcmdline' and 'imsearch' 1634" This test doesn't actually test the input method functionality. 1635func Test_cmdline_inputmethod() 1636 new 1637 call setline(1, ['', 'abc', '']) 1638 set imcmdline 1639 1640 call feedkeys(":\"abc\<CR>", 'xt') 1641 call assert_equal("\"abc", @:) 1642 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') 1643 call assert_equal("\"abc", @:) 1644 call feedkeys("/abc\<CR>", 'xt') 1645 call assert_equal([2, 1], [line('.'), col('.')]) 1646 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1647 call assert_equal([2, 1], [line('.'), col('.')]) 1648 1649 set imsearch=2 1650 call cursor(1, 1) 1651 call feedkeys("/abc\<CR>", 'xt') 1652 call assert_equal([2, 1], [line('.'), col('.')]) 1653 call cursor(1, 1) 1654 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1655 call assert_equal([2, 1], [line('.'), col('.')]) 1656 set imdisable 1657 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1658 call assert_equal([2, 1], [line('.'), col('.')]) 1659 set imdisable& 1660 set imsearch& 1661 1662 set imcmdline& 1663 %bwipe! 1664endfunc 1665 1666" Test for recursively getting multiple command line inputs 1667func Test_cmdwin_multi_input() 1668 CheckFeature cmdwin 1669 1670 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') 1671 call assert_equal('"cyan', @:) 1672endfunc 1673 1674" Test for using CTRL-_ in the command line with 'allowrevins' 1675func Test_cmdline_revins() 1676 CheckNotMSWindows 1677 CheckFeature rightleft 1678 call feedkeys(":\"abc\<c-_>\<cr>", 'xt') 1679 call assert_equal("\"abc\<c-_>", @:) 1680 set allowrevins 1681 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') 1682 call assert_equal('"abcñèæ', @:) 1683 set allowrevins& 1684endfunc 1685 1686" Test for typing UTF-8 composing characters in the command line 1687func Test_cmdline_composing_chars() 1688 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') 1689 call assert_equal('"ゔ', @:) 1690endfunc 1691 1692" Test for normal mode commands not supported in the cmd window 1693func Test_cmdwin_blocked_commands() 1694 CheckFeature cmdwin 1695 1696 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') 1697 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') 1698 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') 1699 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') 1700 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') 1701 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') 1702 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:') 1703 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:') 1704 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:') 1705 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:') 1706 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:') 1707 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:') 1708 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:') 1709 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:') 1710 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:') 1711 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:') 1712 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:') 1713 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:') 1714 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:') 1715 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:') 1716 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:') 1717 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:') 1718 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:') 1719 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:') 1720 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:') 1721 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:') 1722 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:') 1723endfunc 1724 1725" Close the Cmd-line window in insert mode using CTRL-C 1726func Test_cmdwin_insert_mode_close() 1727 CheckFeature cmdwin 1728 1729 %bw! 1730 let s = '' 1731 exe "normal q:a\<C-C>let s='Hello'\<CR>" 1732 call assert_equal('Hello', s) 1733 call assert_equal(1, winnr('$')) 1734endfunc 1735 1736" test that ";" works to find a match at the start of the first line 1737func Test_zero_line_search() 1738 new 1739 call setline(1, ["1, pattern", "2, ", "3, pattern"]) 1740 call cursor(1,1) 1741 0;/pattern/d 1742 call assert_equal(["2, ", "3, pattern"], getline(1,'$')) 1743 q! 1744endfunc 1745 1746func Test_read_shellcmd() 1747 CheckUnix 1748 if executable('ls') 1749 " There should be ls in the $PATH 1750 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') 1751 call assert_match('^"r! .*\<ls\>', @:) 1752 endif 1753 1754 if executable('rm') 1755 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') 1756 call assert_notmatch('^"r!.*\<runtest.vim\>', @:) 1757 call assert_match('^"r!.*\<rm\>', @:) 1758 1759 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') 1760 call assert_notmatch('^"r.*\<runtest.vim\>', @:) 1761 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) 1762 endif 1763endfunc 1764 1765" Test for going up and down the directory tree using 'wildmenu' 1766func Test_wildmenu_dirstack() 1767 CheckUnix 1768 %bw! 1769 call mkdir('Xdir1/dir2/dir3', 'p') 1770 call writefile([], 'Xdir1/file1_1.txt') 1771 call writefile([], 'Xdir1/file1_2.txt') 1772 call writefile([], 'Xdir1/dir2/file2_1.txt') 1773 call writefile([], 'Xdir1/dir2/file2_2.txt') 1774 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt') 1775 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt') 1776 cd Xdir1/dir2/dir3 1777 set wildmenu 1778 1779 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt') 1780 call assert_equal('"e file3_1.txt', @:) 1781 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt') 1782 call assert_equal('"e ../dir3/', @:) 1783 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') 1784 call assert_equal('"e ../../dir2/', @:) 1785 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt') 1786 call assert_equal('"e ../../dir2/dir3/', @:) 1787 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') 1788 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:) 1789 1790 cd - 1791 call delete('Xdir1', 'rf') 1792 set wildmenu& 1793endfunc 1794 1795" Test for recalling newer or older cmdline from history with <Up>, <Down>, 1796" <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>. 1797func Test_recalling_cmdline() 1798 CheckFeature cmdline_hist 1799 1800 let g:cmdlines = [] 1801 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR> 1802 1803 let histories = [ 1804 \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"}, 1805 \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"}, 1806 \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"}, 1807 \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"}, 1808 "\ TODO: {'name': 'debug', ...} 1809 \] 1810 let keypairs = [ 1811 \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true}, 1812 \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false}, 1813 \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false}, 1814 \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false}, 1815 \] 1816 let prefix = 'vi' 1817 for h in histories 1818 call histadd(h.name, 'vim') 1819 call histadd(h.name, 'virtue') 1820 call histadd(h.name, 'Virgo') 1821 call histadd(h.name, 'vogue') 1822 call histadd(h.name, 'emacs') 1823 for k in keypairs 1824 let g:cmdlines = [] 1825 let keyseqs = h.enter 1826 \ .. prefix 1827 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2) 1828 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2) 1829 \ .. h.exit 1830 call feedkeys(keyseqs, 'xt') 1831 call histdel(h.name, -1) " delete the history added by feedkeys above 1832 let expect = k.prefixmatch 1833 \ ? ['virtue', 'vim', 'virtue', prefix] 1834 \ : ['emacs', 'vogue', 'emacs', prefix] 1835 call assert_equal(expect, g:cmdlines) 1836 endfor 1837 endfor 1838 1839 unlet g:cmdlines 1840 cunmap <Plug>(save-cmdline) 1841endfunc 1842 1843func Test_cmd_map_cmdlineChanged() 1844 let g:log = [] 1845 cnoremap <F1> l<Cmd><CR>s 1846 augroup test 1847 autocmd! 1848 autocmd CmdlineChanged : let g:log += [getcmdline()] 1849 augroup END 1850 1851 call feedkeys(":\<F1>\<CR>", 'xt') 1852 call assert_equal(['l', 'ls'], g:log) 1853 1854 let @b = 'b' 1855 cnoremap <F1> a<C-R>b 1856 let g:log = [] 1857 call feedkeys(":\<F1>\<CR>", 'xt') 1858 call assert_equal(['a', 'ab'], g:log) 1859 1860 unlet g:log 1861 cunmap <F1> 1862 augroup test 1863 autocmd! 1864 augroup END 1865endfunc 1866 1867" Test for the 'suffixes' option 1868func Test_suffixes_opt() 1869 call writefile([], 'Xfile') 1870 call writefile([], 'Xfile.c') 1871 call writefile([], 'Xfile.o') 1872 set suffixes= 1873 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') 1874 call assert_equal('"e Xfile Xfile.c Xfile.o', @:) 1875 set suffixes=.c 1876 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') 1877 call assert_equal('"e Xfile Xfile.o Xfile.c', @:) 1878 set suffixes=,, 1879 call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') 1880 call assert_equal('"e Xfile.c Xfile.o Xfile', @:) 1881 set suffixes& 1882 call delete('Xfile') 1883 call delete('Xfile.c') 1884 call delete('Xfile.o') 1885endfunc 1886 1887" vim: shiftwidth=2 sts=2 expandtab 1888