1" Tests for editing the command line. 2 3source check.vim 4source screendump.vim 5 6func Test_complete_tab() 7 call writefile(['testfile'], 'Xtestfile') 8 call feedkeys(":e Xtest\t\r", "tx") 9 call assert_equal('testfile', getline(1)) 10 call delete('Xtestfile') 11endfunc 12 13func Test_complete_list() 14 " We can't see the output, but at least we check the code runs properly. 15 call feedkeys(":e test\<C-D>\r", "tx") 16 call assert_equal('test', expand('%:t')) 17 18 " If a command doesn't support completion, then CTRL-D should be literally 19 " used. 20 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') 21 call assert_equal("\"chistory \<C-D>", @:) 22endfunc 23 24func Test_complete_wildmenu() 25 call mkdir('Xdir1/Xdir2', 'p') 26 call writefile(['testfile1'], 'Xdir1/Xtestfile1') 27 call writefile(['testfile2'], 'Xdir1/Xtestfile2') 28 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') 29 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') 30 set wildmenu 31 32 " Pressing <Tab> completes, and moves to next files when pressing again. 33 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') 34 call assert_equal('testfile1', getline(1)) 35 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') 36 call assert_equal('testfile2', getline(1)) 37 38 " <S-Tab> is like <Tab> but begin with the last match and then go to 39 " previous. 40 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') 41 call assert_equal('testfile2', getline(1)) 42 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') 43 call assert_equal('testfile1', getline(1)) 44 45 " <Left>/<Right> to move to previous/next file. 46 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') 47 call assert_equal('testfile1', getline(1)) 48 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') 49 call assert_equal('testfile2', getline(1)) 50 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') 51 call assert_equal('testfile1', getline(1)) 52 53 " <Up>/<Down> to go up/down directories. 54 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') 55 call assert_equal('testfile3', getline(1)) 56 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') 57 call assert_equal('testfile1', getline(1)) 58 59 " Test for canceling the wild menu by adding a character 60 redrawstatus 61 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt') 62 call assert_equal('"e Xdir1/Xdir2/x', @:) 63 64 " Completion using a relative path 65 cd Xdir1/Xdir2 66 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') 67 call assert_equal('"e Xtestfile3 Xtestfile4', @:) 68 cd - 69 70 " cleanup 71 %bwipe 72 call delete('Xdir1/Xdir2/Xtestfile4') 73 call delete('Xdir1/Xdir2/Xtestfile3') 74 call delete('Xdir1/Xtestfile2') 75 call delete('Xdir1/Xtestfile1') 76 call delete('Xdir1/Xdir2', 'd') 77 call delete('Xdir1', 'd') 78 set nowildmenu 79endfunc 80 81func Test_map_completion() 82 if !has('cmdline_compl') 83 return 84 endif 85 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') 86 call assert_equal('"map <unique> <silent>', getreg(':')) 87 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') 88 call assert_equal('"map <script> <unique>', getreg(':')) 89 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') 90 call assert_equal('"map <expr> <script>', getreg(':')) 91 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') 92 call assert_equal('"map <buffer> <expr>', getreg(':')) 93 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') 94 call assert_equal('"map <nowait> <buffer>', getreg(':')) 95 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') 96 call assert_equal('"map <special> <nowait>', getreg(':')) 97 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') 98 call assert_equal('"map <silent> <special>', getreg(':')) 99 100 map <Middle>x middle 101 102 map ,f commaf 103 map ,g commaf 104 map <Left> left 105 map <A-Left>x shiftleft 106 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') 107 call assert_equal('"map ,f', getreg(':')) 108 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') 109 call assert_equal('"map ,g', getreg(':')) 110 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 111 call assert_equal('"map <Left>', getreg(':')) 112 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') 113 call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) 114 unmap ,f 115 unmap ,g 116 unmap <Left> 117 unmap <A-Left>x 118 119 set cpo-=< cpo-=B cpo-=k 120 map <Left> left 121 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 122 call assert_equal('"map <Left>', getreg(':')) 123 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') 124 call assert_equal("\"map <M\<Tab>", getreg(':')) 125 unmap <Left> 126 127 set cpo+=< 128 map <Left> left 129 exe "set t_k6=\<Esc>[17~" 130 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') 131 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 132 call assert_equal('"map <Left>', getreg(':')) 133 if !has('gui_running') 134 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') 135 call assert_equal("\"map <F6>x", getreg(':')) 136 endif 137 unmap <Left> 138 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') 139 set cpo-=< 140 141 set cpo+=B 142 map <Left> left 143 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 144 call assert_equal('"map <Left>', getreg(':')) 145 unmap <Left> 146 set cpo-=B 147 148 set cpo+=k 149 map <Left> left 150 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 151 call assert_equal('"map <Left>', getreg(':')) 152 unmap <Left> 153 set cpo-=k 154 155 unmap <Middle>x 156 set cpo&vim 157endfunc 158 159func Test_match_completion() 160 if !has('cmdline_compl') 161 return 162 endif 163 hi Aardig ctermfg=green 164 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') 165 call assert_equal('"match Aardig', getreg(':')) 166 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') 167 call assert_equal('"match none', getreg(':')) 168endfunc 169 170func Test_highlight_completion() 171 if !has('cmdline_compl') 172 return 173 endif 174 hi Aardig ctermfg=green 175 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') 176 call assert_equal('"hi Aardig', getreg(':')) 177 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') 178 call assert_equal('"hi default Aardig', getreg(':')) 179 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') 180 call assert_equal('"hi clear Aardig', getreg(':')) 181 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') 182 call assert_equal('"hi link', getreg(':')) 183 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') 184 call assert_equal('"hi default', getreg(':')) 185 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') 186 call assert_equal('"hi clear', getreg(':')) 187 188 " A cleared group does not show up in completions. 189 hi Anders ctermfg=green 190 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) 191 hi clear Aardig 192 call assert_equal(['Anders'], getcompletion('A', 'highlight')) 193 hi clear Anders 194 call assert_equal([], getcompletion('A', 'highlight')) 195endfunc 196 197func Test_expr_completion() 198 if !has('cmdline_compl') 199 return 200 endif 201 for cmd in [ 202 \ 'let a = ', 203 \ 'const a = ', 204 \ 'if', 205 \ 'elseif', 206 \ 'while', 207 \ 'for', 208 \ 'echo', 209 \ 'echon', 210 \ 'execute', 211 \ 'echomsg', 212 \ 'echoerr', 213 \ 'call', 214 \ 'return', 215 \ 'cexpr', 216 \ 'caddexpr', 217 \ 'cgetexpr', 218 \ 'lexpr', 219 \ 'laddexpr', 220 \ 'lgetexpr'] 221 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') 222 call assert_equal('"' . cmd . ' getline(', getreg(':')) 223 endfor 224endfunc 225 226func Test_getcompletion() 227 if !has('cmdline_compl') 228 return 229 endif 230 let groupcount = len(getcompletion('', 'event')) 231 call assert_true(groupcount > 0) 232 let matchcount = len('File'->getcompletion('event')) 233 call assert_true(matchcount > 0) 234 call assert_true(groupcount > matchcount) 235 236 if has('menu') 237 source $VIMRUNTIME/menu.vim 238 let matchcount = len(getcompletion('', 'menu')) 239 call assert_true(matchcount > 0) 240 call assert_equal(['File.'], getcompletion('File', 'menu')) 241 call assert_true(matchcount > 0) 242 let matchcount = len(getcompletion('File.', 'menu')) 243 call assert_true(matchcount > 0) 244 endif 245 246 let l = getcompletion('v:n', 'var') 247 call assert_true(index(l, 'v:null') >= 0) 248 let l = getcompletion('v:notexists', 'var') 249 call assert_equal([], l) 250 251 args a.c b.c 252 let l = getcompletion('', 'arglist') 253 call assert_equal(['a.c', 'b.c'], l) 254 %argdelete 255 256 let l = getcompletion('', 'augroup') 257 call assert_true(index(l, 'END') >= 0) 258 let l = getcompletion('blahblah', 'augroup') 259 call assert_equal([], l) 260 261 let l = getcompletion('', 'behave') 262 call assert_true(index(l, 'mswin') >= 0) 263 let l = getcompletion('not', 'behave') 264 call assert_equal([], l) 265 266 let l = getcompletion('', 'color') 267 call assert_true(index(l, 'default') >= 0) 268 let l = getcompletion('dirty', 'color') 269 call assert_equal([], l) 270 271 let l = getcompletion('', 'command') 272 call assert_true(index(l, 'sleep') >= 0) 273 let l = getcompletion('awake', 'command') 274 call assert_equal([], l) 275 276 let l = getcompletion('', 'dir') 277 call assert_true(index(l, 'samples/') >= 0) 278 let l = getcompletion('NoMatch', 'dir') 279 call assert_equal([], l) 280 281 let l = getcompletion('exe', 'expression') 282 call assert_true(index(l, 'executable(') >= 0) 283 let l = getcompletion('kill', 'expression') 284 call assert_equal([], l) 285 286 let l = getcompletion('tag', 'function') 287 call assert_true(index(l, 'taglist(') >= 0) 288 let l = getcompletion('paint', 'function') 289 call assert_equal([], l) 290 291 let Flambda = {-> 'hello'} 292 let l = getcompletion('', 'function') 293 let l = filter(l, {i, v -> v =~ 'lambda'}) 294 call assert_equal([], l) 295 296 let l = getcompletion('run', 'file') 297 call assert_true(index(l, 'runtest.vim') >= 0) 298 let l = getcompletion('walk', 'file') 299 call assert_equal([], l) 300 set wildignore=*.vim 301 let l = getcompletion('run', 'file', 1) 302 call assert_true(index(l, 'runtest.vim') < 0) 303 set wildignore& 304 305 let l = getcompletion('ha', 'filetype') 306 call assert_true(index(l, 'hamster') >= 0) 307 let l = getcompletion('horse', 'filetype') 308 call assert_equal([], l) 309 310 let l = getcompletion('z', 'syntax') 311 call assert_true(index(l, 'zimbu') >= 0) 312 let l = getcompletion('emacs', 'syntax') 313 call assert_equal([], l) 314 315 let l = getcompletion('jikes', 'compiler') 316 call assert_true(index(l, 'jikes') >= 0) 317 let l = getcompletion('break', 'compiler') 318 call assert_equal([], l) 319 320 let l = getcompletion('last', 'help') 321 call assert_true(index(l, ':tablast') >= 0) 322 let l = getcompletion('giveup', 'help') 323 call assert_equal([], l) 324 325 let l = getcompletion('time', 'option') 326 call assert_true(index(l, 'timeoutlen') >= 0) 327 let l = getcompletion('space', 'option') 328 call assert_equal([], l) 329 330 let l = getcompletion('er', 'highlight') 331 call assert_true(index(l, 'ErrorMsg') >= 0) 332 let l = getcompletion('dark', 'highlight') 333 call assert_equal([], l) 334 335 let l = getcompletion('', 'messages') 336 call assert_true(index(l, 'clear') >= 0) 337 let l = getcompletion('not', 'messages') 338 call assert_equal([], l) 339 340 let l = getcompletion('', 'mapclear') 341 call assert_true(index(l, '<buffer>') >= 0) 342 let l = getcompletion('not', 'mapclear') 343 call assert_equal([], l) 344 345 let l = getcompletion('.', 'shellcmd') 346 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) 347 call assert_equal(-1, match(l[2:], '^\.\.\?/$')) 348 let root = has('win32') ? 'C:\\' : '/' 349 let l = getcompletion(root, 'shellcmd') 350 let expected = map(filter(glob(root . '*', 0, 1), 351 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') 352 call assert_equal(expected, l) 353 354 if has('cscope') 355 let l = getcompletion('', 'cscope') 356 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] 357 call assert_equal(cmds, l) 358 " using cmdline completion must not change the result 359 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') 360 let l = getcompletion('', 'cscope') 361 call assert_equal(cmds, l) 362 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] 363 let l = getcompletion('find ', 'cscope') 364 call assert_equal(keys, l) 365 endif 366 367 if has('signs') 368 sign define Testing linehl=Comment 369 let l = getcompletion('', 'sign') 370 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] 371 call assert_equal(cmds, l) 372 " using cmdline completion must not change the result 373 call feedkeys(":sign list \<c-d>\<c-c>", 'xt') 374 let l = getcompletion('', 'sign') 375 call assert_equal(cmds, l) 376 let l = getcompletion('list ', 'sign') 377 call assert_equal(['Testing'], l) 378 endif 379 380 " For others test if the name is recognized. 381 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] 382 if has('cmdline_hist') 383 call add(names, 'history') 384 endif 385 if has('gettext') 386 call add(names, 'locale') 387 endif 388 if has('profile') 389 call add(names, 'syntime') 390 endif 391 392 set tags=Xtags 393 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') 394 395 for name in names 396 let matchcount = len(getcompletion('', name)) 397 call assert_true(matchcount >= 0, 'No matches for ' . name) 398 endfor 399 400 call delete('Xtags') 401 set tags& 402 403 call assert_fails('call getcompletion("", "burp")', 'E475:') 404endfunc 405 406func Test_shellcmd_completion() 407 let save_path = $PATH 408 409 call mkdir('Xpathdir/Xpathsubdir', 'p') 410 call writefile([''], 'Xpathdir/Xfile.exe') 411 call setfperm('Xpathdir/Xfile.exe', 'rwx------') 412 413 " Set PATH to example directory without trailing slash. 414 let $PATH = getcwd() . '/Xpathdir' 415 416 " Test for the ":!<TAB>" case. Previously, this would include subdirs of 417 " dirs in the PATH, even though they won't be executed. We check that only 418 " subdirs of the PWD and executables from the PATH are included in the 419 " suggestions. 420 let actual = getcompletion('X', 'shellcmd') 421 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') 422 call insert(expected, 'Xfile.exe') 423 call assert_equal(expected, actual) 424 425 call delete('Xpathdir', 'rf') 426 let $PATH = save_path 427endfunc 428 429func Test_expand_star_star() 430 call mkdir('a/b', 'p') 431 call writefile(['asdfasdf'], 'a/b/fileXname') 432 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') 433 call assert_equal('find a/b/fileXname', getreg(':')) 434 bwipe! 435 call delete('a', 'rf') 436endfunc 437 438func Test_cmdline_paste() 439 let @a = "def" 440 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') 441 call assert_equal('"abc def ghi', @:) 442 443 new 444 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') 445 446 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 447 call assert_equal('"aaa asdf bbb', @:) 448 449 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') 450 call assert_equal('"aaa /tmp/some bbb', @:) 451 452 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') 453 call assert_equal('"aaa '.getline(1).' bbb', @:) 454 455 set incsearch 456 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 457 call assert_equal('"aaa verylongword bbb', @:) 458 459 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') 460 call assert_equal('"aaa a;b-c*d bbb', @:) 461 462 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') 463 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) 464 bwipe! 465 466 " Error while typing a command used to cause that it was not executed 467 " in the end. 468 new 469 try 470 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') 471 catch /^Vim\%((\a\+)\)\=:E32/ 472 " ignore error E32 473 endtry 474 call assert_equal("Xtestfile", bufname("%")) 475 476 " Try to paste an invalid register using <C-R> 477 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') 478 call assert_equal('"onetwo', @:) 479 480 let @a = "xy\<C-H>z" 481 call feedkeys(":\"\<C-R>a\<CR>", 'xt') 482 call assert_equal('"xz', @:) 483 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') 484 call assert_equal("\"xy\<C-H>z", @:) 485 486 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') 487 488 bwipe! 489endfunc 490 491func Test_cmdline_remove_char() 492 let encoding_save = &encoding 493 494 for e in ['utf8', 'latin1'] 495 exe 'set encoding=' . e 496 497 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') 498 call assert_equal('"abc ef', @:, e) 499 500 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') 501 call assert_equal('"abcdef', @:) 502 503 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') 504 call assert_equal('"abc ghi', @:, e) 505 506 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') 507 call assert_equal('"def', @:, e) 508 endfor 509 510 let &encoding = encoding_save 511endfunc 512 513func Test_cmdline_keymap_ctrl_hat() 514 if !has('keymap') 515 return 516 endif 517 518 set keymap=esperanto 519 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') 520 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) 521 set keymap= 522endfunc 523 524func Test_illegal_address1() 525 new 526 2;'( 527 2;') 528 quit 529endfunc 530 531func Test_illegal_address2() 532 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') 533 new 534 source Xtest.vim 535 " Trigger calling validate_cursor() 536 diffsp Xtest.vim 537 quit! 538 bwipe! 539 call delete('Xtest.vim') 540endfunc 541 542func Test_cmdline_complete_wildoptions() 543 help 544 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 545 let a = join(sort(split(@:)),' ') 546 set wildoptions=tagfile 547 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 548 let b = join(sort(split(@:)),' ') 549 call assert_equal(a, b) 550 bw! 551endfunc 552 553func Test_cmdline_complete_user_cmd() 554 command! -complete=color -nargs=1 Foo : 555 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') 556 call assert_equal('"Foo blue', @:) 557 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') 558 call assert_equal('"Foo blue', @:) 559 delcommand Foo 560endfunc 561 562func s:ScriptLocalFunction() 563 echo 'yes' 564endfunc 565 566func Test_cmdline_complete_user_func() 567 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') 568 call assert_match('"func Test_cmdline_complete_user', @:) 569 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') 570 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) 571endfunc 572 573func Test_cmdline_complete_user_names() 574 if has('unix') && executable('whoami') 575 let whoami = systemlist('whoami')[0] 576 let first_letter = whoami[0] 577 if len(first_letter) > 0 578 " Trying completion of :e ~x where x is the first letter of 579 " the user name should complete to at least the user name. 580 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 581 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 582 endif 583 endif 584 if has('win32') 585 " Just in case: check that the system has an Administrator account. 586 let names = system('net user') 587 if names =~ 'Administrator' 588 " Trying completion of :e ~A should complete to Administrator. 589 " There could be other names starting with "A" before Administrator. 590 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 591 call assert_match('^"e \~.*Administrator', @:) 592 endif 593 endif 594endfunc 595 596func Test_cmdline_complete_bang() 597 if executable('whoami') 598 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') 599 call assert_match('^".*\<whoami\>', @:) 600 endif 601endfunc 602 603funct Test_cmdline_complete_languages() 604 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 605 606 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 607 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) 608 609 if has('unix') 610 " TODO: these tests don't work on Windows. lang appears to be 'C' 611 " but C does not appear in the completion. Why? 612 call assert_match('^"language .*\<' . lang . '\>', @:) 613 614 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 615 call assert_match('^"language .*\<' . lang . '\>', @:) 616 617 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 618 call assert_match('^"language .*\<' . lang . '\>', @:) 619 620 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 621 call assert_match('^"language .*\<' . lang . '\>', @:) 622 endif 623endfunc 624 625func Test_cmdline_complete_env_variable() 626 let $X_VIM_TEST_COMPLETE_ENV = 'foo' 627 628 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') 629 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) 630 631 unlet $X_VIM_TEST_COMPLETE_ENV 632endfunc 633 634func Test_cmdline_write_alternatefile() 635 new 636 call setline('.', ['one', 'two']) 637 f foo.txt 638 new 639 f #-A 640 call assert_equal('foo.txt-A', expand('%')) 641 f #<-B.txt 642 call assert_equal('foo-B.txt', expand('%')) 643 f %< 644 call assert_equal('foo-B', expand('%')) 645 new 646 call assert_fails('f #<', 'E95') 647 bw! 648 f foo-B.txt 649 f %<-A 650 call assert_equal('foo-B-A', expand('%')) 651 bw! 652 bw! 653endfunc 654 655" using a leading backslash here 656set cpo+=C 657 658func Test_cmdline_search_range() 659 new 660 call setline(1, ['a', 'b', 'c', 'd']) 661 /d 662 1,\/s/b/B/ 663 call assert_equal('B', getline(2)) 664 665 /a 666 $ 667 \?,4s/c/C/ 668 call assert_equal('C', getline(3)) 669 670 call setline(1, ['a', 'b', 'c', 'd']) 671 %s/c/c/ 672 1,\&s/b/B/ 673 call assert_equal('B', getline(2)) 674 675 let @/ = 'apple' 676 call assert_fails('\/print', 'E486:') 677 678 bwipe! 679endfunc 680 681" Test for the tick mark (') in an excmd range 682func Test_tick_mark_in_range() 683 " If only the tick is passed as a range and no command is specified, there 684 " should not be an error 685 call feedkeys(":'\<CR>", 'xt') 686 call assert_equal("'", getreg(':')) 687 call assert_fails("',print", 'E78:') 688endfunc 689 690" Test for using a line number followed by a search pattern as range 691func Test_lnum_and_pattern_as_range() 692 new 693 call setline(1, ['foo 1', 'foo 2', 'foo 3']) 694 let @" = '' 695 2/foo/yank 696 call assert_equal("foo 3\n", @") 697 call assert_equal(1, line('.')) 698 close! 699endfunc 700 701" Tests for getcmdline(), getcmdpos() and getcmdtype() 702func Check_cmdline(cmdtype) 703 call assert_equal('MyCmd a', getcmdline()) 704 call assert_equal(8, getcmdpos()) 705 call assert_equal(a:cmdtype, getcmdtype()) 706 return '' 707endfunc 708 709set cpo& 710 711func Test_getcmdtype() 712 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 713 714 let cmdtype = '' 715 debuggreedy 716 call feedkeys(":debug echo 'test'\<CR>", "t") 717 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 718 call feedkeys("cont\<CR>", "xt") 719 0debuggreedy 720 call assert_equal('>', cmdtype) 721 722 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 723 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 724 725 call feedkeys(":call input('Answer?')\<CR>", "t") 726 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 727 728 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 729 730 cnoremap <expr> <F6> Check_cmdline('=') 731 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 732 cunmap <F6> 733 734 call assert_equal('', getcmdline()) 735endfunc 736 737func Test_getcmdwintype() 738 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 739 call assert_equal('/', a) 740 741 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 742 call assert_equal('?', a) 743 744 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 745 call assert_equal(':', a) 746 747 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 748 call assert_equal(':', a) 749 750 call assert_equal('', getcmdwintype()) 751endfunc 752 753func Test_getcmdwin_autocmd() 754 let s:seq = [] 755 augroup CmdWin 756 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) 757 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) 758 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) 759 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) 760 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) 761 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) 762 763 let org_winid = win_getid() 764 let org_bufnr = bufnr() 765 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') 766 call assert_equal(':', a) 767 call assert_equal([ 768 \ 'WinLeave ' .. org_winid, 769 \ 'WinEnter ' .. s:cmd_winid, 770 \ 'BufLeave ' .. org_bufnr, 771 \ 'BufEnter ' .. s:cmd_bufnr, 772 \ 'CmdWinEnter ' .. s:cmd_winid, 773 \ 'CmdWinLeave ' .. s:cmd_winid, 774 \ 'BufLeave ' .. s:cmd_bufnr, 775 \ 'WinLeave ' .. s:cmd_winid, 776 \ 'WinEnter ' .. org_winid, 777 \ 'BufEnter ' .. org_bufnr, 778 \ ], s:seq) 779 780 au! 781 augroup END 782endfunc 783 784func Test_verbosefile() 785 set verbosefile=Xlog 786 echomsg 'foo' 787 echomsg 'bar' 788 set verbosefile= 789 let log = readfile('Xlog') 790 call assert_match("foo\nbar", join(log, "\n")) 791 call delete('Xlog') 792endfunc 793 794func Test_verbose_option() 795 CheckScreendump 796 797 let lines =<< trim [SCRIPT] 798 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 799 call feedkeys("\r", 't') " for the hit-enter prompt 800 set verbose=20 801 [SCRIPT] 802 call writefile(lines, 'XTest_verbose') 803 804 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) 805 call term_wait(buf, 100) 806 call term_sendkeys(buf, ":DoSomething\<CR>") 807 call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) 808 809 " clean up 810 call StopVimInTerminal(buf) 811 call delete('XTest_verbose') 812endfunc 813 814func Test_setcmdpos() 815 func InsertTextAtPos(text, pos) 816 call assert_equal(0, setcmdpos(a:pos)) 817 return a:text 818 endfunc 819 820 " setcmdpos() with position in the middle of the command line. 821 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 822 call assert_equal('"1ab2', @:) 823 824 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 825 call assert_equal('"1b2a', @:) 826 827 " setcmdpos() with position beyond the end of the command line. 828 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 829 call assert_equal('"12ab', @:) 830 831 " setcmdpos() returns 1 when not editing the command line. 832 call assert_equal(1, 3->setcmdpos()) 833endfunc 834 835func Test_cmdline_overstrike() 836 let encodings = ['latin1', 'utf8'] 837 let encoding_save = &encoding 838 839 for e in encodings 840 exe 'set encoding=' . e 841 842 " Test overstrike in the middle of the command line. 843 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 844 call assert_equal('"0ab1cd4', @:, e) 845 846 " Test overstrike going beyond end of command line. 847 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 848 call assert_equal('"0ab1cdefgh', @:, e) 849 850 " Test toggling insert/overstrike a few times. 851 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 852 call assert_equal('"ab0cd3ef4', @:, e) 853 endfor 854 855 " Test overstrike with multi-byte characters. 856 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 857 call assert_equal('"テabキcdエディタ', @:, e) 858 859 let &encoding = encoding_save 860endfunc 861 862func Test_cmdwin_bug() 863 let winid = win_getid() 864 sp 865 try 866 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') 867 catch /^Vim\%((\a\+)\)\=:E11/ 868 endtry 869 bw! 870endfunc 871 872func Test_cmdwin_restore() 873 CheckScreendump 874 875 let lines =<< trim [SCRIPT] 876 call setline(1, range(30)) 877 2split 878 [SCRIPT] 879 call writefile(lines, 'XTest_restore') 880 881 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) 882 call term_wait(buf, 100) 883 call term_sendkeys(buf, "q:") 884 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) 885 886 " normal restore 887 call term_sendkeys(buf, ":q\<CR>") 888 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) 889 890 " restore after setting 'lines' with one window 891 call term_sendkeys(buf, ":close\<CR>") 892 call term_sendkeys(buf, "q:") 893 call term_sendkeys(buf, ":set lines=18\<CR>") 894 call term_sendkeys(buf, ":q\<CR>") 895 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) 896 897 " clean up 898 call StopVimInTerminal(buf) 899 call delete('XTest_restore') 900endfunc 901 902func Test_buffers_lastused() 903 " check that buffers are sorted by time when wildmode has lastused 904 call test_settime(1550020000) " middle 905 edit bufa 906 enew 907 call test_settime(1550030000) " newest 908 edit bufb 909 enew 910 call test_settime(1550010000) " oldest 911 edit bufc 912 enew 913 call test_settime(0) 914 enew 915 916 call assert_equal(['bufa', 'bufb', 'bufc'], 917 \ getcompletion('', 'buffer')) 918 919 let save_wildmode = &wildmode 920 set wildmode=full:lastused 921 922 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" 923 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 924 call assert_equal('b bufb', X) 925 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 926 call assert_equal('b bufa', X) 927 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 928 call assert_equal('b bufc', X) 929 enew 930 931 edit other 932 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 933 call assert_equal('b bufb', X) 934 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 935 call assert_equal('b bufa', X) 936 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 937 call assert_equal('b bufc', X) 938 enew 939 940 let &wildmode = save_wildmode 941 942 bwipeout bufa 943 bwipeout bufb 944 bwipeout bufc 945endfunc 946 947func Test_cmdwin_feedkeys() 948 " This should not generate E488 949 call feedkeys("q:\<CR>", 'x') 950endfunc 951 952" Tests for the issues fixed in 7.4.441. 953" When 'cedit' is set to Ctrl-C, opening the command window hangs Vim 954func Test_cmdwin_cedit() 955 exe "set cedit=\<C-c>" 956 normal! : 957 call assert_equal(1, winnr('$')) 958 959 let g:cmd_wintype = '' 960 func CmdWinType() 961 let g:cmd_wintype = getcmdwintype() 962 let g:wintype = win_gettype() 963 return '' 964 endfunc 965 966 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") 967 echo input('') 968 call assert_equal('@', g:cmd_wintype) 969 call assert_equal('command', g:wintype) 970 971 set cedit&vim 972 delfunc CmdWinType 973endfunc 974 975" Test for CmdwinEnter autocmd 976func Test_cmdwin_autocmd() 977 augroup CmdWin 978 au! 979 autocmd CmdwinEnter * startinsert 980 augroup END 981 982 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') 983 call assert_equal('xyz', @:) 984 985 augroup CmdWin 986 au! 987 augroup END 988 augroup! CmdWin 989endfunc 990 991func Test_cmdlineclear_tabenter() 992 CheckScreendump 993 994 let lines =<< trim [SCRIPT] 995 call setline(1, range(30)) 996 [SCRIPT] 997 998 call writefile(lines, 'XtestCmdlineClearTabenter') 999 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) 1000 call term_wait(buf, 50) 1001 " in one tab make the command line higher with CTRL-W - 1002 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") 1003 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) 1004 1005 call StopVimInTerminal(buf) 1006 call delete('XtestCmdlineClearTabenter') 1007endfunc 1008 1009" Test for failure in expanding special keywords in cmdline 1010func Test_cmdline_expand_special() 1011 %bwipe! 1012 call assert_fails('e #', 'E499:') 1013 call assert_fails('e <afile>', 'E495:') 1014 call assert_fails('e <abuf>', 'E496:') 1015 call assert_fails('e <amatch>', 'E497:') 1016endfunc 1017 1018func Test_cmdwin_jump_to_win() 1019 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') 1020 new 1021 set modified 1022 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', 'E162:') 1023 close! 1024 call feedkeys("q/:close\<CR>", "xt") 1025 call assert_equal(1, winnr('$')) 1026 call feedkeys("q/:exit\<CR>", "xt") 1027 call assert_equal(1, winnr('$')) 1028 1029 " opening command window twice should fail 1030 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') 1031 call assert_equal(1, winnr('$')) 1032endfunc 1033 1034" Test for backtick expression in the command line 1035func Test_cmd_backtick() 1036 %argd 1037 argadd `=['a', 'b', 'c']` 1038 call assert_equal(['a', 'b', 'c'], argv()) 1039 %argd 1040endfunc 1041 1042" Test for the :! command 1043func Test_cmd_bang() 1044 if !has('unix') 1045 return 1046 endif 1047 1048 let lines =<< trim [SCRIPT] 1049 " Test for no previous command 1050 call assert_fails('!!', 'E34:') 1051 set nomore 1052 " Test for cmdline expansion with :! 1053 call setline(1, 'foo!') 1054 silent !echo <cWORD> > Xfile.out 1055 call assert_equal(['foo!'], readfile('Xfile.out')) 1056 " Test for using previous command 1057 silent !echo \! ! 1058 call assert_equal(['! echo foo!'], readfile('Xfile.out')) 1059 call writefile(v:errors, 'Xresult') 1060 call delete('Xfile.out') 1061 qall! 1062 [SCRIPT] 1063 call writefile(lines, 'Xscript') 1064 if RunVim([], [], '--clean -S Xscript') 1065 call assert_equal([], readfile('Xresult')) 1066 endif 1067 call delete('Xscript') 1068 call delete('Xresult') 1069endfunc 1070 1071" Test for using ~ for home directory in cmdline completion matches 1072func Test_cmdline_expand_home() 1073 call mkdir('Xdir') 1074 call writefile([], 'Xdir/Xfile1') 1075 call writefile([], 'Xdir/Xfile2') 1076 cd Xdir 1077 let save_HOME = $HOME 1078 let $HOME = getcwd() 1079 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') 1080 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) 1081 let $HOME = save_HOME 1082 cd .. 1083 call delete('Xdir', 'rf') 1084endfunc 1085 1086" Test for using CTRL-\ CTRL-G in the command line to go back to normal mode 1087" or insert mode (when 'insertmode' is set) 1088func Test_cmdline_ctrl_g() 1089 new 1090 call setline(1, 'abc') 1091 call cursor(1, 3) 1092 " If command line is entered from insert mode, using C-\ C-G should back to 1093 " insert mode 1094 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') 1095 call assert_equal('abxyc', getline(1)) 1096 call assert_equal(4, col('.')) 1097 1098 " If command line is entered in 'insertmode', using C-\ C-G should back to 1099 " 'insertmode' 1100 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') 1101 call assert_equal('ab12xyc', getline(1)) 1102 close! 1103endfunc 1104 1105" Return the 'len' characters in screen starting from (row,col) 1106func s:ScreenLine(row, col, len) 1107 let s = '' 1108 for i in range(a:len) 1109 let s .= nr2char(screenchar(a:row, a:col + i)) 1110 endfor 1111 return s 1112endfunc 1113 1114" Test for 'wildmode' 1115func Test_wildmode() 1116 func T(a, c, p) 1117 return "oneA\noneB\noneC" 1118 endfunc 1119 command -nargs=1 -complete=custom,T MyCmd 1120 1121 func SaveScreenLine() 1122 let g:Sline = s:ScreenLine(&lines - 1, 1, 20) 1123 return '' 1124 endfunc 1125 cnoremap <expr> <F2> SaveScreenLine() 1126 1127 set nowildmenu 1128 set wildmode=full,list 1129 let g:Sline = '' 1130 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') 1131 call assert_equal('oneA oneB oneC ', g:Sline) 1132 call assert_equal('"MyCmd oneA', @:) 1133 1134 set wildmode=longest,full 1135 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 1136 call assert_equal('"MyCmd one', @:) 1137 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') 1138 call assert_equal('"MyCmd oneC', @:) 1139 1140 set wildmode=longest 1141 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') 1142 call assert_equal('"MyCmd one', @:) 1143 1144 set wildmode=list:longest 1145 let g:Sline = '' 1146 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') 1147 call assert_equal('oneA oneB oneC ', g:Sline) 1148 call assert_equal('"MyCmd one', @:) 1149 1150 set wildmode="" 1151 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') 1152 call assert_equal('"MyCmd oneA', @:) 1153 1154 delcommand MyCmd 1155 delfunc T 1156 delfunc SaveScreenLine 1157 cunmap <F2> 1158 set wildmode& 1159endfunc 1160 1161" Test for interrupting the command-line completion 1162func Test_interrupt_compl() 1163 func F(lead, cmdl, p) 1164 if a:lead =~ 'tw' 1165 call interrupt() 1166 return 1167 endif 1168 return "one\ntwo\nthree" 1169 endfunc 1170 command -nargs=1 -complete=custom,F Tcmd 1171 1172 set nowildmenu 1173 set wildmode=full 1174 let interrupted = 0 1175 try 1176 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') 1177 catch /^Vim:Interrupt$/ 1178 let interrupted = 1 1179 endtry 1180 call assert_equal(1, interrupted) 1181 1182 delcommand Tcmd 1183 delfunc F 1184 set wildmode& 1185endfunc 1186 1187" Test for moving the cursor on the : command line 1188func Test_cmdline_edit() 1189 let str = ":one two\<C-U>" 1190 let str ..= "one two\<C-W>\<C-W>" 1191 let str ..= "one\<BS>\<C-H>\<Del>" 1192 let str ..= "\<Left>five\<Right>" 1193 let str ..= "\<Home>two " 1194 let str ..= "\<C-Left>one " 1195 let str ..= "\<C-Right> three" 1196 let str ..= "\<End>\<S-Left>four " 1197 let str ..= "\<S-Right> six" 1198 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1199 call feedkeys(str, 'xt') 1200 call assert_equal("\"one two three four five six seven", @:) 1201endfunc 1202 1203" Test for moving the cursor on the / command line in 'rightleft' mode 1204func Test_cmdline_edit_rightleft() 1205 CheckFeature rightleft 1206 set rightleft 1207 set rightleftcmd=search 1208 let str = "/one two\<C-U>" 1209 let str ..= "one two\<C-W>\<C-W>" 1210 let str ..= "one\<BS>\<C-H>\<Del>" 1211 let str ..= "\<Right>five\<Left>" 1212 let str ..= "\<Home>two " 1213 let str ..= "\<C-Right>one " 1214 let str ..= "\<C-Left> three" 1215 let str ..= "\<End>\<S-Right>four " 1216 let str ..= "\<S-Left> six" 1217 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 1218 call assert_fails("call feedkeys(str, 'xt')", 'E486:') 1219 call assert_equal("\"one two three four five six seven", @/) 1220 set rightleftcmd& 1221 set rightleft& 1222endfunc 1223 1224" Test for using <C-\>e in the command line to evaluate an expression 1225func Test_cmdline_expr() 1226 " Evaluate an expression from the beginning of a command line 1227 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') 1228 call assert_equal('"hello', @:) 1229 1230 " Use an invalid expression for <C-\>e 1231 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 1232 1233 " Insert literal <CTRL-\> in the command line 1234 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') 1235 call assert_equal("\"e \<C-\>\<C-Y>", @:) 1236endfunc 1237 1238" Test for 'imcmdline' and 'imsearch' 1239" This test doesn't actually test the input method functionality. 1240func Test_cmdline_inputmethod() 1241 new 1242 call setline(1, ['', 'abc', '']) 1243 set imcmdline 1244 1245 call feedkeys(":\"abc\<CR>", 'xt') 1246 call assert_equal("\"abc", @:) 1247 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') 1248 call assert_equal("\"abc", @:) 1249 call feedkeys("/abc\<CR>", 'xt') 1250 call assert_equal([2, 1], [line('.'), col('.')]) 1251 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1252 call assert_equal([2, 1], [line('.'), col('.')]) 1253 1254 set imsearch=2 1255 call cursor(1, 1) 1256 call feedkeys("/abc\<CR>", 'xt') 1257 call assert_equal([2, 1], [line('.'), col('.')]) 1258 call cursor(1, 1) 1259 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1260 call assert_equal([2, 1], [line('.'), col('.')]) 1261 set imdisable 1262 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 1263 call assert_equal([2, 1], [line('.'), col('.')]) 1264 set imdisable& 1265 set imsearch& 1266 1267 set imcmdline& 1268 %bwipe! 1269endfunc 1270 1271" vim: shiftwidth=2 sts=2 expandtab 1272