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>") 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_shellcmd_completion() 446 let save_path = $PATH 447 448 call mkdir('Xpathdir/Xpathsubdir', 'p') 449 call writefile([''], 'Xpathdir/Xfile.exe') 450 call setfperm('Xpathdir/Xfile.exe', 'rwx------') 451 452 " Set PATH to example directory without trailing slash. 453 let $PATH = getcwd() . '/Xpathdir' 454 455 " Test for the ":!<TAB>" case. Previously, this would include subdirs of 456 " dirs in the PATH, even though they won't be executed. We check that only 457 " subdirs of the PWD and executables from the PATH are included in the 458 " suggestions. 459 let actual = getcompletion('X', 'shellcmd') 460 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') 461 call insert(expected, 'Xfile.exe') 462 call assert_equal(expected, actual) 463 464 call delete('Xpathdir', 'rf') 465 let $PATH = save_path 466endfunc 467 468func Test_expand_star_star() 469 call mkdir('a/b', 'p') 470 call writefile(['asdfasdf'], 'a/b/fileXname') 471 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') 472 call assert_equal('find a/b/fileXname', getreg(':')) 473 bwipe! 474 call delete('a', 'rf') 475endfunc 476 477func Test_cmdline_paste() 478 let @a = "def" 479 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') 480 call assert_equal('"abc def ghi', @:) 481 482 new 483 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') 484 485 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 486 call assert_equal('"aaa asdf bbb', @:) 487 488 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') 489 call assert_equal('"aaa /tmp/some bbb', @:) 490 491 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') 492 call assert_equal('"aaa '.getline(1).' bbb', @:) 493 494 set incsearch 495 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 496 call assert_equal('"aaa verylongword bbb', @:) 497 498 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') 499 call assert_equal('"aaa a;b-c*d bbb', @:) 500 501 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') 502 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) 503 bwipe! 504 505 " Error while typing a command used to cause that it was not executed 506 " in the end. 507 new 508 try 509 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') 510 catch /^Vim\%((\a\+)\)\=:E32/ 511 " ignore error E32 512 endtry 513 call assert_equal("Xtestfile", bufname("%")) 514 515 " Try to paste an invalid register using <C-R> 516 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') 517 call assert_equal('"onetwo', @:) 518 519 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R 520 let @a = "xy\<C-H>z" 521 call feedkeys(":\"\<C-R>a\<CR>", 'xt') 522 call assert_equal('"xz', @:) 523 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') 524 call assert_equal("\"xy\<C-H>z", @:) 525 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') 526 call assert_equal("\"xy\<C-H>z", @:) 527 528 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R 529 let @a = "xy\<C-V>z" 530 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') 531 call assert_equal('"xyz', @:) 532 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') 533 call assert_equal("\"xy\<C-V>z", @:) 534 535 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') 536 537 bwipe! 538endfunc 539 540func Test_cmdline_remove_char() 541 let encoding_save = &encoding 542 543 for e in ['utf8', 'latin1'] 544 exe 'set encoding=' . e 545 546 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') 547 call assert_equal('"abc ef', @:, e) 548 549 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') 550 call assert_equal('"abcdef', @:) 551 552 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') 553 call assert_equal('"abc ghi', @:, e) 554 555 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') 556 call assert_equal('"def', @:, e) 557 endfor 558 559 let &encoding = encoding_save 560endfunc 561 562func Test_cmdline_keymap_ctrl_hat() 563 CheckFeature keymap 564 565 set keymap=esperanto 566 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') 567 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) 568 set keymap= 569endfunc 570 571func Test_illegal_address1() 572 new 573 2;'( 574 2;') 575 quit 576endfunc 577 578func Test_illegal_address2() 579 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') 580 new 581 source Xtest.vim 582 " Trigger calling validate_cursor() 583 diffsp Xtest.vim 584 quit! 585 bwipe! 586 call delete('Xtest.vim') 587endfunc 588 589func Test_cmdline_complete_wildoptions() 590 help 591 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 592 let a = join(sort(split(@:)),' ') 593 set wildoptions=tagfile 594 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 595 let b = join(sort(split(@:)),' ') 596 call assert_equal(a, b) 597 bw! 598endfunc 599 600func Test_cmdline_complete_user_cmd() 601 command! -complete=color -nargs=1 Foo : 602 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') 603 call assert_equal('"Foo blue', @:) 604 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') 605 call assert_equal('"Foo blue', @:) 606 delcommand Foo 607endfunc 608 609func s:ScriptLocalFunction() 610 echo 'yes' 611endfunc 612 613func Test_cmdline_complete_user_func() 614 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') 615 call assert_match('"func Test_cmdline_complete_user', @:) 616 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') 617 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) 618 619 " g: prefix also works 620 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx') 621 call assert_match('"echo g:Test_cmdline_complete_user_func', @:) 622endfunc 623 624func Test_cmdline_complete_user_names() 625 if has('unix') && executable('whoami') 626 let whoami = systemlist('whoami')[0] 627 let first_letter = whoami[0] 628 if len(first_letter) > 0 629 " Trying completion of :e ~x where x is the first letter of 630 " the user name should complete to at least the user name. 631 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 632 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 633 endif 634 elseif has('win32') 635 " Just in case: check that the system has an Administrator account. 636 let names = system('net user') 637 if names =~ 'Administrator' 638 " Trying completion of :e ~A should complete to Administrator. 639 " There could be other names starting with "A" before Administrator. 640 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 641 call assert_match('^"e \~.*Administrator', @:) 642 endif 643 else 644 throw 'Skipped: does not work on this platform' 645 endif 646endfunc 647 648func Test_cmdline_complete_bang() 649 CheckExecutable whoami 650 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') 651 call assert_match('^".*\<whoami\>', @:) 652endfunc 653 654func Test_cmdline_complete_languages() 655 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') 656 call assert_equal(lang, v:lc_time) 657 658 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') 659 call assert_equal(lang, v:ctype) 660 661 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') 662 call assert_equal(lang, v:collate) 663 664 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 665 call assert_equal(lang, v:lang) 666 667 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 668 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) 669 670 call assert_match('^"language .*\<' . lang . '\>', @:) 671 672 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 673 call assert_match('^"language .*\<' . lang . '\>', @:) 674 675 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 676 call assert_match('^"language .*\<' . lang . '\>', @:) 677 678 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 679 call assert_match('^"language .*\<' . lang . '\>', @:) 680 681 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') 682 call assert_match('^"language .*\<' . lang . '\>', @:) 683endfunc 684 685func Test_cmdline_complete_env_variable() 686 let $X_VIM_TEST_COMPLETE_ENV = 'foo' 687 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') 688 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) 689 unlet $X_VIM_TEST_COMPLETE_ENV 690endfunc 691 692func Test_cmdline_complete_expression() 693 let g:SomeVar = 'blah' 694 for cmd in ['exe', 'echo', 'echon', 'echomsg'] 695 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 696 call assert_match('"' .. cmd .. ' SomeVar', @:) 697 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 698 call assert_match('"' .. cmd .. ' foo SomeVar', @:) 699 endfor 700 unlet g:SomeVar 701endfunc 702 703" Test for various command-line completion 704func Test_cmdline_complete_various() 705 " completion for a command starting with a comment 706 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') 707 call assert_equal("\" :|\"\<C-A>", @:) 708 709 " completion for a range followed by a comment 710 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') 711 call assert_equal("\"1,2\"\<C-A>", @:) 712 713 " completion for :k command 714 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') 715 call assert_equal("\"ka\<C-A>", @:) 716 717 " completion for short version of the :s command 718 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') 719 call assert_equal("\"sI \<C-A>", @:) 720 721 " completion for :write command 722 call mkdir('Xdir') 723 call writefile(['one'], 'Xdir/Xfile1') 724 let save_cwd = getcwd() 725 cd Xdir 726 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') 727 call assert_equal("\"w >> Xfile1", @:) 728 call chdir(save_cwd) 729 call delete('Xdir', 'rf') 730 731 " completion for :w ! and :r ! commands 732 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 733 call assert_equal("\"w !invalid_xyz_cmd", @:) 734 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 735 call assert_equal("\"r !invalid_xyz_cmd", @:) 736 737 " completion for :>> and :<< commands 738 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') 739 call assert_equal("\">>>\<C-A>", @:) 740 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') 741 call assert_equal("\"<<<\<C-A>", @:) 742 743 " completion for command with +cmd argument 744 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') 745 call assert_equal("\"buffer +/pat Xabc", @:) 746 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') 747 call assert_equal("\"buffer +/pat\<C-A>", @:) 748 749 " completion for a command with a trailing comment 750 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') 751 call assert_equal("\"ls \" comment\<C-A>", @:) 752 753 " completion for a command with a trailing command 754 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') 755 call assert_equal("\"ls | ls", @:) 756 757 " completion for a command with an CTRL-V escaped argument 758 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') 759 call assert_equal("\"ls \<C-V>a\<C-A>", @:) 760 761 " completion for a command that doesn't take additional arguments 762 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') 763 call assert_equal("\"all abc\<C-A>", @:) 764 765 " completion for a command with a command modifier 766 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') 767 call assert_equal("\"topleft new", @:) 768 769 " completion for the :match command 770 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') 771 call assert_equal("\"match Search /pat/\<C-A>", @:) 772 773 " completion for the :s command 774 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt') 775 call assert_equal("\"s/from/to/g\<C-A>", @:) 776 777 " completion for the :dlist command 778 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') 779 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) 780 781 " completion for the :doautocmd command 782 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') 783 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) 784 785 " completion of autocmd group after comma 786 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') 787 call assert_equal("\"doautocmd BufNew,BufEnter", @:) 788 789 " completion for the :augroup command 790 augroup XTest 791 augroup END 792 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') 793 call assert_equal("\"augroup XTest", @:) 794 augroup! XTest 795 796 " completion for the :unlet command 797 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') 798 call assert_equal("\"unlet one two", @:) 799 800 " completion for the :bdelete command 801 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') 802 call assert_equal("\"bdel a b c", @:) 803 804 " completion for the :mapclear command 805 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') 806 call assert_equal("\"mapclear <buffer>", @:) 807 808 " completion for user defined commands with menu names 809 menu Test.foo :ls<CR> 810 com -nargs=* -complete=menu MyCmd 811 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') 812 call assert_equal('"MyCmd Test.', @:) 813 delcom MyCmd 814 unmenu Test 815 816 " completion for user defined commands with mappings 817 mapclear 818 map <F3> :ls<CR> 819 com -nargs=* -complete=mapping MyCmd 820 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') 821 call assert_equal('"MyCmd <F3>', @:) 822 mapclear 823 delcom MyCmd 824 825 " completion for :set path= with multiple backslashes 826 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 827 call assert_equal('"set path=a\\\ b', @:) 828 829 " completion for :set dir= with a backslash 830 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') 831 call assert_equal('"set dir=a\ b', @:) 832 833 " completion for the :py3 commands 834 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') 835 call assert_equal('"py3 py3do py3file', @:) 836 837 " redir @" is not the start of a comment. So complete after that 838 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') 839 call assert_equal('"redir @" | cwindow', @:) 840 841 " completion after a backtick 842 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') 843 call assert_equal('"e `a1b2c', @:) 844 845 " completion for :language command with an invalid argument 846 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') 847 call assert_equal("\"language dummy \t", @:) 848 849 " completion for commands after a :global command 850 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') 851 call assert_equal('"g/a\xb/clearjumps', @:) 852 853 " completion with ambiguous user defined commands 854 com TCmd1 echo 'TCmd1' 855 com TCmd2 echo 'TCmd2' 856 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') 857 call assert_equal('"TCmd ', @:) 858 delcom TCmd1 859 delcom TCmd2 860 861 " completion after a range followed by a pipe (|) character 862 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') 863 call assert_equal('"1,10 | chistory', @:) 864 865 " use <Esc> as the 'wildchar' for completion 866 set wildchar=<Esc> 867 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') 868 call assert_equal('"g/a\xb/clearjumps', @:) 869 " pressing <esc> twice should cancel the command 870 call feedkeys(":chist\<Esc>\<Esc>", 'xt') 871 call assert_equal('"g/a\xb/clearjumps', @:) 872 set wildchar& 873endfunc 874 875func Test_cmdline_write_alternatefile() 876 new 877 call setline('.', ['one', 'two']) 878 f foo.txt 879 new 880 f #-A 881 call assert_equal('foo.txt-A', expand('%')) 882 f #<-B.txt 883 call assert_equal('foo-B.txt', expand('%')) 884 f %< 885 call assert_equal('foo-B', expand('%')) 886 new 887 call assert_fails('f #<', 'E95:') 888 bw! 889 f foo-B.txt 890 f %<-A 891 call assert_equal('foo-B-A', expand('%')) 892 bw! 893 bw! 894endfunc 895 896" using a leading backslash here 897set cpo+=C 898 899func Test_cmdline_search_range() 900 new 901 call setline(1, ['a', 'b', 'c', 'd']) 902 /d 903 1,\/s/b/B/ 904 call assert_equal('B', getline(2)) 905 906 /a 907 $ 908 \?,4s/c/C/ 909 call assert_equal('C', getline(3)) 910 911 call setline(1, ['a', 'b', 'c', 'd']) 912 %s/c/c/ 913 1,\&s/b/B/ 914 call assert_equal('B', getline(2)) 915 916 let @/ = 'apple' 917 call assert_fails('\/print', ['E486:.*apple']) 918 919 bwipe! 920endfunc 921 922" Test for the tick mark (') in an excmd range 923func Test_tick_mark_in_range() 924 " If only the tick is passed as a range and no command is specified, there 925 " should not be an error 926 call feedkeys(":'\<CR>", 'xt') 927 call assert_equal("'", getreg(':')) 928 call assert_fails("',print", 'E78:') 929endfunc 930 931" Test for using a line number followed by a search pattern as range 932func Test_lnum_and_pattern_as_range() 933 new 934 call setline(1, ['foo 1', 'foo 2', 'foo 3']) 935 let @" = '' 936 2/foo/yank 937 call assert_equal("foo 3\n", @") 938 call assert_equal(1, line('.')) 939 close! 940endfunc 941 942" Tests for getcmdline(), getcmdpos() and getcmdtype() 943func Check_cmdline(cmdtype) 944 call assert_equal('MyCmd a', getcmdline()) 945 call assert_equal(8, getcmdpos()) 946 call assert_equal(a:cmdtype, getcmdtype()) 947 return '' 948endfunc 949 950set cpo& 951 952func Test_getcmdtype() 953 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 954 955 let cmdtype = '' 956 debuggreedy 957 call feedkeys(":debug echo 'test'\<CR>", "t") 958 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 959 call feedkeys("cont\<CR>", "xt") 960 0debuggreedy 961 call assert_equal('>', cmdtype) 962 963 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 964 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 965 966 call feedkeys(":call input('Answer?')\<CR>", "t") 967 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 968 969 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 970 971 cnoremap <expr> <F6> Check_cmdline('=') 972 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 973 cunmap <F6> 974 975 call assert_equal('', getcmdline()) 976endfunc 977 978func Test_getcmdwintype() 979 CheckFeature cmdwin 980 981 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 982 call assert_equal('/', a) 983 984 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 985 call assert_equal('?', a) 986 987 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 988 call assert_equal(':', a) 989 990 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 991 call assert_equal(':', a) 992 993 call assert_equal('', getcmdwintype()) 994endfunc 995 996func Test_getcmdwin_autocmd() 997 CheckFeature cmdwin 998 999 let s:seq = [] 1000 augroup CmdWin 1001 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) 1002 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) 1003 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) 1004 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) 1005 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) 1006 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) 1007 1008 let org_winid = win_getid() 1009 let org_bufnr = bufnr() 1010 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') 1011 call assert_equal(':', a) 1012 call assert_equal([ 1013 \ 'WinLeave ' .. org_winid, 1014 \ 'WinEnter ' .. s:cmd_winid, 1015 \ 'BufLeave ' .. org_bufnr, 1016 \ 'BufEnter ' .. s:cmd_bufnr, 1017 \ 'CmdWinEnter ' .. s:cmd_winid, 1018 \ 'CmdWinLeave ' .. s:cmd_winid, 1019 \ 'BufLeave ' .. s:cmd_bufnr, 1020 \ 'WinLeave ' .. s:cmd_winid, 1021 \ 'WinEnter ' .. org_winid, 1022 \ 'BufEnter ' .. org_bufnr, 1023 \ ], s:seq) 1024 1025 au! 1026 augroup END 1027endfunc 1028 1029func Test_verbosefile() 1030 set verbosefile=Xlog 1031 echomsg 'foo' 1032 echomsg 'bar' 1033 set verbosefile= 1034 let log = readfile('Xlog') 1035 call assert_match("foo\nbar", join(log, "\n")) 1036 call delete('Xlog') 1037 call mkdir('Xdir') 1038 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) 1039 call delete('Xdir', 'd') 1040endfunc 1041 1042func Test_verbose_option() 1043 CheckScreendump 1044 1045 let lines =<< trim [SCRIPT] 1046 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 1047 call feedkeys("\r", 't') " for the hit-enter prompt 1048 set verbose=20 1049 [SCRIPT] 1050 call writefile(lines, 'XTest_verbose') 1051 1052 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) 1053 call TermWait(buf, 50) 1054 call term_sendkeys(buf, ":DoSomething\<CR>") 1055 call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) 1056 1057 " clean up 1058 call StopVimInTerminal(buf) 1059 call delete('XTest_verbose') 1060endfunc 1061 1062func Test_setcmdpos() 1063 func InsertTextAtPos(text, pos) 1064 call assert_equal(0, setcmdpos(a:pos)) 1065 return a:text 1066 endfunc 1067 1068 " setcmdpos() with position in the middle of the command line. 1069 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1070 call assert_equal('"1ab2', @:) 1071 1072 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1073 call assert_equal('"1b2a', @:) 1074 1075 " setcmdpos() with position beyond the end of the command line. 1076 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 1077 call assert_equal('"12ab', @:) 1078 1079 " setcmdpos() returns 1 when not editing the command line. 1080 call assert_equal(1, 3->setcmdpos()) 1081endfunc 1082 1083func Test_cmdline_overstrike() 1084 let encodings = ['latin1', 'utf8'] 1085 let encoding_save = &encoding 1086 1087 for e in encodings 1088 exe 'set encoding=' . e 1089 1090 " Test overstrike in the middle of the command line. 1091 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1092 call assert_equal('"0ab1cd4', @:, e) 1093 1094 " Test overstrike going beyond end of command line. 1095 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 1096 call assert_equal('"0ab1cdefgh', @:, e) 1097 1098 " Test toggling insert/overstrike a few times. 1099 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 1100 call assert_equal('"ab0cd3ef4', @:, e) 1101 endfor 1102 1103 " Test overstrike with multi-byte characters. 1104 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1105 call assert_equal('"テabキcdエディタ', @:, e) 1106 1107 let &encoding = encoding_save 1108endfunc 1109 1110func Test_cmdwin_bug() 1111 CheckFeature cmdwin 1112 1113 let winid = win_getid() 1114 sp 1115 try 1116 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') 1117 catch /^Vim\%((\a\+)\)\=:E11/ 1118 endtry 1119 bw! 1120endfunc 1121 1122func Test_cmdwin_restore() 1123 CheckFeature cmdwin 1124 CheckScreendump 1125 1126 let lines =<< trim [SCRIPT] 1127 call setline(1, range(30)) 1128 2split 1129 [SCRIPT] 1130 call writefile(lines, 'XTest_restore') 1131 1132 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) 1133 call TermWait(buf, 50) 1134 call term_sendkeys(buf, "q:") 1135 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) 1136 1137 " normal restore 1138 call term_sendkeys(buf, ":q\<CR>") 1139 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) 1140 1141 " restore after setting 'lines' with one window 1142 call term_sendkeys(buf, ":close\<CR>") 1143 call term_sendkeys(buf, "q:") 1144 call term_sendkeys(buf, ":set lines=18\<CR>") 1145 call term_sendkeys(buf, ":q\<CR>") 1146 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) 1147 1148 " clean up 1149 call StopVimInTerminal(buf) 1150 call delete('XTest_restore') 1151endfunc 1152 1153func Test_buffers_lastused() 1154 " check that buffers are sorted by time when wildmode has lastused 1155 call test_settime(1550020000) " middle 1156 edit bufa 1157 enew 1158 call test_settime(1550030000) " newest 1159 edit bufb 1160 enew 1161 call test_settime(1550010000) " oldest 1162 edit bufc 1163 enew 1164 call test_settime(0) 1165 enew 1166 1167 call assert_equal(['bufa', 'bufb', 'bufc'], 1168 \ getcompletion('', 'buffer')) 1169 1170 let save_wildmode = &wildmode 1171 set wildmode=full:lastused 1172 1173 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" 1174 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1175 call assert_equal('b bufb', X) 1176 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1177 call assert_equal('b bufa', X) 1178 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1179 call assert_equal('b bufc', X) 1180 enew 1181 1182 edit other 1183 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1184 call assert_equal('b bufb', X) 1185 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1186 call assert_equal('b bufa', X) 1187 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1188 call assert_equal('b bufc', X) 1189 enew 1190 1191 let &wildmode = save_wildmode 1192 1193 bwipeout bufa 1194 bwipeout bufb 1195 bwipeout bufc 1196endfunc 1197 1198func Test_cmdwin_feedkeys() 1199 CheckFeature cmdwin 1200 1201 " This should not generate E488 1202 call feedkeys("q:\<CR>", 'x') 1203 " Using feedkeys with q: only should automatically close the cmd window 1204 call feedkeys('q:', 'xt') 1205 call assert_equal(1, winnr('$')) 1206 call assert_equal('', getcmdwintype()) 1207endfunc 1208 1209" Tests for the issues fixed in 7.4.441. 1210" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim 1211func Test_cmdwin_cedit() 1212 CheckFeature cmdwin 1213 1214 exe "set cedit=\<C-c>" 1215 normal! : 1216 call assert_equal(1, winnr('$')) 1217 1218 let g:cmd_wintype = '' 1219 func CmdWinType() 1220 let g:cmd_wintype = getcmdwintype() 1221 let g:wintype = win_gettype() 1222 return '' 1223 endfunc 1224 1225 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") 1226 echo input('') 1227 call assert_equal('@', g:cmd_wintype) 1228 call assert_equal('command', g:wintype) 1229 1230 set cedit&vim 1231 delfunc CmdWinType 1232endfunc 1233 1234" Test for CmdwinEnter autocmd 1235func Test_cmdwin_autocmd() 1236 CheckFeature cmdwin 1237 1238 augroup CmdWin 1239 au! 1240 autocmd CmdwinEnter * startinsert 1241 augroup END 1242 1243 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') 1244 call assert_equal('xyz', @:) 1245 1246 augroup CmdWin 1247 au! 1248 augroup END 1249 augroup! CmdWin 1250endfunc 1251 1252func Test_cmdlineclear_tabenter() 1253 CheckScreendump 1254 1255 let lines =<< trim [SCRIPT] 1256 call setline(1, range(30)) 1257 [SCRIPT] 1258 1259 call writefile(lines, 'XtestCmdlineClearTabenter') 1260 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) 1261 call TermWait(buf, 25) 1262 " in one tab make the command line higher with CTRL-W - 1263 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") 1264 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) 1265 1266 call StopVimInTerminal(buf) 1267 call delete('XtestCmdlineClearTabenter') 1268endfunc 1269 1270" Test for failure in expanding special keywords in cmdline 1271func Test_cmdline_expand_special() 1272 %bwipe! 1273 call assert_fails('e #', 'E499:') 1274 call assert_fails('e <afile>', 'E495:') 1275 call assert_fails('e <abuf>', 'E496:') 1276 call assert_fails('e <amatch>', 'E497:') 1277endfunc 1278 1279func Test_cmdwin_jump_to_win() 1280 CheckFeature cmdwin 1281 1282 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') 1283 new 1284 set modified 1285 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:']) 1286 close! 1287 call feedkeys("q/:close\<CR>", "xt") 1288 call assert_equal(1, winnr('$')) 1289 call feedkeys("q/:exit\<CR>", "xt") 1290 call assert_equal(1, winnr('$')) 1291 1292 " opening command window twice should fail 1293 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') 1294 call assert_equal(1, winnr('$')) 1295endfunc 1296 1297func Test_cmdwin_interrupted() 1298 CheckFeature cmdwin 1299 CheckScreendump 1300 1301 " aborting the :smile output caused the cmdline window to use the current 1302 " buffer. 1303 let lines =<< trim [SCRIPT] 1304 au WinNew * smile 1305 [SCRIPT] 1306 call writefile(lines, 'XTest_cmdwin') 1307 1308 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18}) 1309 " open cmdwin 1310 call term_sendkeys(buf, "q:") 1311 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))}) 1312 " quit more prompt for :smile command 1313 call term_sendkeys(buf, "q") 1314 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))}) 1315 " execute a simple command 1316 call term_sendkeys(buf, "aecho 'done'\<CR>") 1317 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {}) 1318 1319 " clean up 1320 call StopVimInTerminal(buf) 1321 call delete('XTest_cmdwin') 1322endfunc 1323 1324" Test for backtick expression in the command line 1325func Test_cmd_backtick() 1326 %argd 1327 argadd `=['a', 'b', 'c']` 1328 call assert_equal(['a', 'b', 'c'], argv()) 1329 %argd 1330endfunc 1331 1332" Test for the :! command 1333func Test_cmd_bang() 1334 CheckUnix 1335 1336 let lines =<< trim [SCRIPT] 1337 " Test for no previous command 1338 call assert_fails('!!', 'E34:') 1339 set nomore 1340 " Test for cmdline expansion with :! 1341 call setline(1, 'foo!') 1342 silent !echo <cWORD> > Xfile.out 1343 call assert_equal(['foo!'], readfile('Xfile.out')) 1344 " Test for using previous command 1345 silent !echo \! ! 1346 call assert_equal(['! echo foo!'], readfile('Xfile.out')) 1347 call writefile(v:errors, 'Xresult') 1348 call delete('Xfile.out') 1349 qall! 1350 [SCRIPT] 1351 call writefile(lines, 'Xscript') 1352 if RunVim([], [], '--clean -S Xscript') 1353 call assert_equal([], readfile('Xresult')) 1354 endif 1355 call delete('Xscript') 1356 call delete('Xresult') 1357endfunc 1358 1359" Test error: "E135: *Filter* Autocommands must not change current buffer" 1360func Test_cmd_bang_E135() 1361 new 1362 call setline(1, ['a', 'b', 'c', 'd']) 1363 augroup test_cmd_filter_E135 1364 au! 1365 autocmd FilterReadPost * help 1366 augroup END 1367 call assert_fails('2,3!echo "x"', 'E135:') 1368 1369 augroup test_cmd_filter_E135 1370 au! 1371 augroup END 1372 %bwipe! 1373endfunc 1374 1375" Test for using ~ for home directory in cmdline completion matches 1376func Test_cmdline_expand_home() 1377 call mkdir('Xdir') 1378 call writefile([], 'Xdir/Xfile1') 1379 call writefile([], 'Xdir/Xfile2') 1380 cd Xdir 1381 let save_HOME = $HOME 1382 let $HOME = getcwd() 1383 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') 1384 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) 1385 let $HOME = save_HOME 1386 cd .. 1387 call delete('Xdir', 'rf') 1388endfunc 1389 1390" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode 1391" or insert mode (when 'insertmode' is set) 1392func Test_cmdline_ctrl_g() 1393 new 1394 call setline(1, 'abc') 1395 call cursor(1, 3) 1396 " If command line is entered from insert mode, using C-\ C-G should back to 1397 " insert mode 1398 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') 1399 call assert_equal('abxyc', getline(1)) 1400 call assert_equal(4, col('.')) 1401 1402 " If command line is entered in 'insertmode', using C-\ C-G should back to 1403 " 'insertmode' 1404 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') 1405 call assert_equal('ab12xyc', getline(1)) 1406 close! 1407endfunc 1408 1409" Test for 'wildmode' 1410func Test_wildmode() 1411 func T(a, c, p) 1412 return "oneA\noneB\noneC" 1413 endfunc 1414 command -nargs=1 -complete=custom,T MyCmd 1415 1416 func SaveScreenLine() 1417 let g:Sline = Screenline(&lines - 1) 1418 return '' 1419 endfunc 1420 cnoremap <expr> <F2> SaveScreenLine() 1421 1422 set nowildmenu 1423 set wildmode=full,list 1424 let g:Sline = '' 1425 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') 1426 call assert_equal('oneA oneB oneC', g:Sline) 1427 call assert_equal('"MyCmd oneA', @:) 1428 1429 set wildmode=longest,full 1430 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 1431 call assert_equal('"MyCmd one', @:) 1432 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') 1433 call assert_equal('"MyCmd oneC', @:) 1434 1435 set wildmode=longest 1436 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') 1437 call assert_equal('"MyCmd one', @:) 1438 1439 set wildmode=list:longest 1440 let g:Sline = '' 1441 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') 1442 call assert_equal('oneA oneB oneC', g:Sline) 1443 call assert_equal('"MyCmd one', @:) 1444 1445 set wildmode="" 1446 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') 1447 call assert_equal('"MyCmd oneA', @:) 1448 1449 " Test for wildmode=longest with 'fileignorecase' set 1450 set wildmode=longest 1451 set fileignorecase 1452 argadd AAA AAAA AAAAA 1453 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') 1454 call assert_equal('"buffer AAA', @:) 1455 set fileignorecase& 1456 1457 " Test for listing files with wildmode=list 1458 set wildmode=list 1459 let g:Sline = '' 1460 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt') 1461 call assert_equal('AAA AAAA AAAAA', g:Sline) 1462 call assert_equal('"b A', @:) 1463 1464 %argdelete 1465 delcommand MyCmd 1466 delfunc T 1467 delfunc SaveScreenLine 1468 cunmap <F2> 1469 set wildmode& 1470 %bwipe! 1471endfunc 1472 1473" Test for interrupting the command-line completion 1474func Test_interrupt_compl() 1475 func F(lead, cmdl, p) 1476 if a:lead =~ 'tw' 1477 call interrupt() 1478 return 1479 endif 1480 return "one\ntwo\nthree" 1481 endfunc 1482 command -nargs=1 -complete=custom,F Tcmd 1483 1484 set nowildmenu 1485 set wildmode=full 1486 let interrupted = 0 1487 try 1488 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') 1489 catch /^Vim:Interrupt$/ 1490 let interrupted = 1 1491 endtry 1492 call assert_equal(1, interrupted) 1493 1494 delcommand Tcmd 1495 delfunc F 1496 set wildmode& 1497endfunc 1498 1499" Test for moving the cursor on the : command line 1500func Test_cmdline_edit() 1501 let str = ":one two\<C-U>" 1502 let str ..= "one two\<C-W>\<C-W>" 1503 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1504 let str ..= "\<Left>five\<Right>" 1505 let str ..= "\<Home>two " 1506 let str ..= "\<C-Left>one " 1507 let str ..= "\<C-Right> three" 1508 let str ..= "\<End>\<S-Left>four " 1509 let str ..= "\<S-Right> six" 1510 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1511 call feedkeys(str, 'xt') 1512 call assert_equal("\"one two three four five six seven", @:) 1513endfunc 1514 1515" Test for moving the cursor on the / command line in 'rightleft' mode 1516func Test_cmdline_edit_rightleft() 1517 CheckFeature rightleft 1518 set rightleft 1519 set rightleftcmd=search 1520 let str = "/one two\<C-U>" 1521 let str ..= "one two\<C-W>\<C-W>" 1522 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 1523 let str ..= "\<Right>five\<Left>" 1524 let str ..= "\<Home>two " 1525 let str ..= "\<C-Right>one " 1526 let str ..= "\<C-Left> three" 1527 let str ..= "\<End>\<S-Right>four " 1528 let str ..= "\<S-Left> six" 1529 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1530 call assert_fails("call feedkeys(str, 'xt')", 'E486:') 1531 call assert_equal("\"one two three four five six seven", @/) 1532 set rightleftcmd& 1533 set rightleft& 1534endfunc 1535 1536" Test for using <C-\>e in the command line to evaluate an expression 1537func Test_cmdline_expr() 1538 " Evaluate an expression from the beginning of a command line 1539 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') 1540 call assert_equal('"hello', @:) 1541 1542 " Use an invalid expression for <C-\>e 1543 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 1544 1545 " Insert literal <CTRL-\> in the command line 1546 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') 1547 call assert_equal("\"e \<C-\>\<C-Y>", @:) 1548endfunc 1549 1550" Test for 'imcmdline' and 'imsearch' 1551" This test doesn't actually test the input method functionality. 1552func Test_cmdline_inputmethod() 1553 new 1554 call setline(1, ['', 'abc', '']) 1555 set imcmdline 1556 1557 call feedkeys(":\"abc\<CR>", 'xt') 1558 call assert_equal("\"abc", @:) 1559 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') 1560 call assert_equal("\"abc", @:) 1561 call feedkeys("/abc\<CR>", 'xt') 1562 call assert_equal([2, 1], [line('.'), col('.')]) 1563 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1564 call assert_equal([2, 1], [line('.'), col('.')]) 1565 1566 set imsearch=2 1567 call cursor(1, 1) 1568 call feedkeys("/abc\<CR>", 'xt') 1569 call assert_equal([2, 1], [line('.'), col('.')]) 1570 call cursor(1, 1) 1571 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1572 call assert_equal([2, 1], [line('.'), col('.')]) 1573 set imdisable 1574 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1575 call assert_equal([2, 1], [line('.'), col('.')]) 1576 set imdisable& 1577 set imsearch& 1578 1579 set imcmdline& 1580 %bwipe! 1581endfunc 1582 1583" Test for recursively getting multiple command line inputs 1584func Test_cmdwin_multi_input() 1585 CheckFeature cmdwin 1586 1587 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') 1588 call assert_equal('"cyan', @:) 1589endfunc 1590 1591" Test for using CTRL-_ in the command line with 'allowrevins' 1592func Test_cmdline_revins() 1593 CheckNotMSWindows 1594 CheckFeature rightleft 1595 call feedkeys(":\"abc\<c-_>\<cr>", 'xt') 1596 call assert_equal("\"abc\<c-_>", @:) 1597 set allowrevins 1598 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') 1599 call assert_equal('"abcñèæ', @:) 1600 set allowrevins& 1601endfunc 1602 1603" Test for typing UTF-8 composing characters in the command line 1604func Test_cmdline_composing_chars() 1605 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') 1606 call assert_equal('"ゔ', @:) 1607endfunc 1608 1609" Test for normal mode commands not supported in the cmd window 1610func Test_cmdwin_blocked_commands() 1611 CheckFeature cmdwin 1612 1613 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') 1614 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') 1615 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') 1616 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') 1617 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') 1618 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') 1619 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:') 1620 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:') 1621 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:') 1622 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:') 1623 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:') 1624 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:') 1625 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:') 1626 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:') 1627 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:') 1628 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:') 1629 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:') 1630 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:') 1631 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:') 1632 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:') 1633 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:') 1634 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:') 1635 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:') 1636 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:') 1637 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:') 1638 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:') 1639 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:') 1640endfunc 1641 1642" Close the Cmd-line window in insert mode using CTRL-C 1643func Test_cmdwin_insert_mode_close() 1644 CheckFeature cmdwin 1645 1646 %bw! 1647 let s = '' 1648 exe "normal q:a\<C-C>let s='Hello'\<CR>" 1649 call assert_equal('Hello', s) 1650 call assert_equal(1, winnr('$')) 1651endfunc 1652 1653" test that ";" works to find a match at the start of the first line 1654func Test_zero_line_search() 1655 new 1656 call setline(1, ["1, pattern", "2, ", "3, pattern"]) 1657 call cursor(1,1) 1658 0;/pattern/d 1659 call assert_equal(["2, ", "3, pattern"], getline(1,'$')) 1660 q! 1661endfunc 1662 1663func Test_read_shellcmd() 1664 CheckUnix 1665 if executable('ls') 1666 " There should be ls in the $PATH 1667 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') 1668 call assert_match('^"r! .*\<ls\>', @:) 1669 endif 1670 1671 if executable('rm') 1672 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') 1673 call assert_notmatch('^"r!.*\<runtest.vim\>', @:) 1674 call assert_match('^"r!.*\<rm\>', @:) 1675 1676 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') 1677 call assert_notmatch('^"r.*\<runtest.vim\>', @:) 1678 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) 1679 endif 1680endfunc 1681 1682" Test for going up and down the directory tree using 'wildmenu' 1683func Test_wildmenu_dirstack() 1684 CheckUnix 1685 %bw! 1686 call mkdir('Xdir1/dir2/dir3', 'p') 1687 call writefile([], 'Xdir1/file1_1.txt') 1688 call writefile([], 'Xdir1/file1_2.txt') 1689 call writefile([], 'Xdir1/dir2/file2_1.txt') 1690 call writefile([], 'Xdir1/dir2/file2_2.txt') 1691 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt') 1692 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt') 1693 cd Xdir1/dir2/dir3 1694 set wildmenu 1695 1696 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt') 1697 call assert_equal('"e file3_1.txt', @:) 1698 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt') 1699 call assert_equal('"e ../dir3/', @:) 1700 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') 1701 call assert_equal('"e ../../dir2/', @:) 1702 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt') 1703 call assert_equal('"e ../../dir2/dir3/', @:) 1704 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') 1705 call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:) 1706 1707 cd - 1708 call delete('Xdir1', 'rf') 1709 set wildmenu& 1710endfunc 1711 1712" vim: shiftwidth=2 sts=2 expandtab 1713