1" Tests for editing the command line. 2 3func Test_complete_tab() 4 call writefile(['testfile'], 'Xtestfile') 5 call feedkeys(":e Xtest\t\r", "tx") 6 call assert_equal('testfile', getline(1)) 7 call delete('Xtestfile') 8endfunc 9 10func Test_complete_list() 11 " We can't see the output, but at least we check the code runs properly. 12 call feedkeys(":e test\<C-D>\r", "tx") 13 call assert_equal('test', expand('%:t')) 14endfunc 15 16func Test_complete_wildmenu() 17 call mkdir('Xdir1/Xdir2', 'p') 18 call writefile(['testfile1'], 'Xdir1/Xtestfile1') 19 call writefile(['testfile2'], 'Xdir1/Xtestfile2') 20 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') 21 call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') 22 set wildmenu 23 24 " Pressing <Tab> completes, and moves to next files when pressing again. 25 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') 26 call assert_equal('testfile1', getline(1)) 27 call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') 28 call assert_equal('testfile2', getline(1)) 29 30 " <S-Tab> is like <Tab> but begin with the last match and then go to 31 " previous. 32 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') 33 call assert_equal('testfile2', getline(1)) 34 call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') 35 call assert_equal('testfile1', getline(1)) 36 37 " <Left>/<Right> to move to previous/next file. 38 call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') 39 call assert_equal('testfile1', getline(1)) 40 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') 41 call assert_equal('testfile2', getline(1)) 42 call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') 43 call assert_equal('testfile1', getline(1)) 44 45 " <Up>/<Down> to go up/down directories. 46 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') 47 call assert_equal('testfile3', getline(1)) 48 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') 49 call assert_equal('testfile1', getline(1)) 50 51 " cleanup 52 %bwipe 53 call delete('Xdir1/Xdir2/Xtestfile4') 54 call delete('Xdir1/Xdir2/Xtestfile3') 55 call delete('Xdir1/Xtestfile2') 56 call delete('Xdir1/Xtestfile1') 57 call delete('Xdir1/Xdir2', 'd') 58 call delete('Xdir1', 'd') 59 set nowildmenu 60endfunc 61 62func Test_map_completion() 63 if !has('cmdline_compl') 64 return 65 endif 66 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') 67 call assert_equal('"map <unique> <silent>', getreg(':')) 68 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') 69 call assert_equal('"map <script> <unique>', getreg(':')) 70 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') 71 call assert_equal('"map <expr> <script>', getreg(':')) 72 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') 73 call assert_equal('"map <buffer> <expr>', getreg(':')) 74 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') 75 call assert_equal('"map <nowait> <buffer>', getreg(':')) 76 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') 77 call assert_equal('"map <special> <nowait>', getreg(':')) 78 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') 79 call assert_equal('"map <silent> <special>', getreg(':')) 80endfunc 81 82func Test_match_completion() 83 if !has('cmdline_compl') 84 return 85 endif 86 hi Aardig ctermfg=green 87 call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') 88 call assert_equal('"match Aardig', getreg(':')) 89 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') 90 call assert_equal('"match none', getreg(':')) 91endfunc 92 93func Test_highlight_completion() 94 if !has('cmdline_compl') 95 return 96 endif 97 hi Aardig ctermfg=green 98 call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') 99 call assert_equal('"hi Aardig', getreg(':')) 100 call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') 101 call assert_equal('"hi default Aardig', getreg(':')) 102 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') 103 call assert_equal('"hi clear Aardig', getreg(':')) 104 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') 105 call assert_equal('"hi link', getreg(':')) 106 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') 107 call assert_equal('"hi default', getreg(':')) 108 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') 109 call assert_equal('"hi clear', getreg(':')) 110 111 " A cleared group does not show up in completions. 112 hi Anders ctermfg=green 113 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) 114 hi clear Aardig 115 call assert_equal(['Anders'], getcompletion('A', 'highlight')) 116 hi clear Anders 117 call assert_equal([], getcompletion('A', 'highlight')) 118endfunc 119 120func Test_expr_completion() 121 if !has('cmdline_compl') 122 return 123 endif 124 for cmd in [ 125 \ 'let a = ', 126 \ 'if', 127 \ 'elseif', 128 \ 'while', 129 \ 'for', 130 \ 'echo', 131 \ 'echon', 132 \ 'execute', 133 \ 'echomsg', 134 \ 'echoerr', 135 \ 'call', 136 \ 'return', 137 \ 'cexpr', 138 \ 'caddexpr', 139 \ 'cgetexpr', 140 \ 'lexpr', 141 \ 'laddexpr', 142 \ 'lgetexpr'] 143 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') 144 call assert_equal('"' . cmd . ' getline(', getreg(':')) 145 endfor 146endfunc 147 148func Test_getcompletion() 149 if !has('cmdline_compl') 150 return 151 endif 152 let groupcount = len(getcompletion('', 'event')) 153 call assert_true(groupcount > 0) 154 let matchcount = len(getcompletion('File', 'event')) 155 call assert_true(matchcount > 0) 156 call assert_true(groupcount > matchcount) 157 158 if has('menu') 159 source $VIMRUNTIME/menu.vim 160 let matchcount = len(getcompletion('', 'menu')) 161 call assert_true(matchcount > 0) 162 call assert_equal(['File.'], getcompletion('File', 'menu')) 163 call assert_true(matchcount > 0) 164 let matchcount = len(getcompletion('File.', 'menu')) 165 call assert_true(matchcount > 0) 166 endif 167 168 let l = getcompletion('v:n', 'var') 169 call assert_true(index(l, 'v:null') >= 0) 170 let l = getcompletion('v:notexists', 'var') 171 call assert_equal([], l) 172 173 args a.c b.c 174 let l = getcompletion('', 'arglist') 175 call assert_equal(['a.c', 'b.c'], l) 176 %argdelete 177 178 let l = getcompletion('', 'augroup') 179 call assert_true(index(l, 'END') >= 0) 180 let l = getcompletion('blahblah', 'augroup') 181 call assert_equal([], l) 182 183 let l = getcompletion('', 'behave') 184 call assert_true(index(l, 'mswin') >= 0) 185 let l = getcompletion('not', 'behave') 186 call assert_equal([], l) 187 188 let l = getcompletion('', 'color') 189 call assert_true(index(l, 'default') >= 0) 190 let l = getcompletion('dirty', 'color') 191 call assert_equal([], l) 192 193 let l = getcompletion('', 'command') 194 call assert_true(index(l, 'sleep') >= 0) 195 let l = getcompletion('awake', 'command') 196 call assert_equal([], l) 197 198 let l = getcompletion('', 'dir') 199 call assert_true(index(l, 'samples/') >= 0) 200 let l = getcompletion('NoMatch', 'dir') 201 call assert_equal([], l) 202 203 let l = getcompletion('exe', 'expression') 204 call assert_true(index(l, 'executable(') >= 0) 205 let l = getcompletion('kill', 'expression') 206 call assert_equal([], l) 207 208 let l = getcompletion('tag', 'function') 209 call assert_true(index(l, 'taglist(') >= 0) 210 let l = getcompletion('paint', 'function') 211 call assert_equal([], l) 212 213 let Flambda = {-> 'hello'} 214 let l = getcompletion('', 'function') 215 let l = filter(l, {i, v -> v =~ 'lambda'}) 216 call assert_equal([], l) 217 218 let l = getcompletion('run', 'file') 219 call assert_true(index(l, 'runtest.vim') >= 0) 220 let l = getcompletion('walk', 'file') 221 call assert_equal([], l) 222 set wildignore=*.vim 223 let l = getcompletion('run', 'file', 1) 224 call assert_true(index(l, 'runtest.vim') < 0) 225 set wildignore& 226 227 let l = getcompletion('ha', 'filetype') 228 call assert_true(index(l, 'hamster') >= 0) 229 let l = getcompletion('horse', 'filetype') 230 call assert_equal([], l) 231 232 let l = getcompletion('z', 'syntax') 233 call assert_true(index(l, 'zimbu') >= 0) 234 let l = getcompletion('emacs', 'syntax') 235 call assert_equal([], l) 236 237 let l = getcompletion('jikes', 'compiler') 238 call assert_true(index(l, 'jikes') >= 0) 239 let l = getcompletion('break', 'compiler') 240 call assert_equal([], l) 241 242 let l = getcompletion('last', 'help') 243 call assert_true(index(l, ':tablast') >= 0) 244 let l = getcompletion('giveup', 'help') 245 call assert_equal([], l) 246 247 let l = getcompletion('time', 'option') 248 call assert_true(index(l, 'timeoutlen') >= 0) 249 let l = getcompletion('space', 'option') 250 call assert_equal([], l) 251 252 let l = getcompletion('er', 'highlight') 253 call assert_true(index(l, 'ErrorMsg') >= 0) 254 let l = getcompletion('dark', 'highlight') 255 call assert_equal([], l) 256 257 let l = getcompletion('', 'messages') 258 call assert_true(index(l, 'clear') >= 0) 259 let l = getcompletion('not', 'messages') 260 call assert_equal([], l) 261 262 let l = getcompletion('', 'mapclear') 263 call assert_true(index(l, '<buffer>') >= 0) 264 let l = getcompletion('not', 'mapclear') 265 call assert_equal([], l) 266 267 let l = getcompletion('.', 'shellcmd') 268 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) 269 call assert_equal(-1, match(l[2:], '^\.\.\?/$')) 270 let root = has('win32') ? 'C:\\' : '/' 271 let l = getcompletion(root, 'shellcmd') 272 let expected = map(filter(glob(root . '*', 0, 1), 273 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') 274 call assert_equal(expected, l) 275 276 if has('cscope') 277 let l = getcompletion('', 'cscope') 278 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] 279 call assert_equal(cmds, l) 280 " using cmdline completion must not change the result 281 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') 282 let l = getcompletion('', 'cscope') 283 call assert_equal(cmds, l) 284 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] 285 let l = getcompletion('find ', 'cscope') 286 call assert_equal(keys, l) 287 endif 288 289 if has('signs') 290 sign define Testing linehl=Comment 291 let l = getcompletion('', 'sign') 292 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] 293 call assert_equal(cmds, l) 294 " using cmdline completion must not change the result 295 call feedkeys(":sign list \<c-d>\<c-c>", 'xt') 296 let l = getcompletion('', 'sign') 297 call assert_equal(cmds, l) 298 let l = getcompletion('list ', 'sign') 299 call assert_equal(['Testing'], l) 300 endif 301 302 " For others test if the name is recognized. 303 let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] 304 if has('cmdline_hist') 305 call add(names, 'history') 306 endif 307 if has('gettext') 308 call add(names, 'locale') 309 endif 310 if has('profile') 311 call add(names, 'syntime') 312 endif 313 314 set tags=Xtags 315 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') 316 317 for name in names 318 let matchcount = len(getcompletion('', name)) 319 call assert_true(matchcount >= 0, 'No matches for ' . name) 320 endfor 321 322 call delete('Xtags') 323 324 call assert_fails('call getcompletion("", "burp")', 'E475:') 325endfunc 326 327func Test_shellcmd_completion() 328 let save_path = $PATH 329 330 call mkdir('Xpathdir/Xpathsubdir', 'p') 331 call writefile([''], 'Xpathdir/Xfile.exe') 332 call setfperm('Xpathdir/Xfile.exe', 'rwx------') 333 334 " Set PATH to example directory without trailing slash. 335 let $PATH = getcwd() . '/Xpathdir' 336 337 " Test for the ":!<TAB>" case. Previously, this would include subdirs of 338 " dirs in the PATH, even though they won't be executed. We check that only 339 " subdirs of the PWD and executables from the PATH are included in the 340 " suggestions. 341 let actual = getcompletion('X', 'shellcmd') 342 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') 343 call insert(expected, 'Xfile.exe') 344 call assert_equal(expected, actual) 345 346 call delete('Xpathdir', 'rf') 347 let $PATH = save_path 348endfunc 349 350func Test_expand_star_star() 351 call mkdir('a/b', 'p') 352 call writefile(['asdfasdf'], 'a/b/fileXname') 353 call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') 354 call assert_equal('find a/b/fileXname', getreg(':')) 355 bwipe! 356 call delete('a', 'rf') 357endfunc 358 359func Test_paste_in_cmdline() 360 let @a = "def" 361 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') 362 call assert_equal('"abc def ghi', @:) 363 364 new 365 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') 366 367 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 368 call assert_equal('"aaa asdf bbb', @:) 369 370 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') 371 call assert_equal('"aaa /tmp/some bbb', @:) 372 373 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') 374 call assert_equal('"aaa '.getline(1).' bbb', @:) 375 376 set incsearch 377 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 378 call assert_equal('"aaa verylongword bbb', @:) 379 380 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') 381 call assert_equal('"aaa a;b-c*d bbb', @:) 382 383 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') 384 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) 385 bwipe! 386 387 " Error while typing a command used to cause that it was not executed 388 " in the end. 389 new 390 try 391 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') 392 catch /^Vim\%((\a\+)\)\=:E32/ 393 " ignore error E32 394 endtry 395 call assert_equal("Xtestfile", bufname("%")) 396 bwipe! 397endfunc 398 399func Test_remove_char_in_cmdline() 400 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') 401 call assert_equal('"abc ef', @:) 402 403 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') 404 call assert_equal('"abcdef', @:) 405 406 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') 407 call assert_equal('"abc ghi', @:) 408 409 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') 410 call assert_equal('"def', @:) 411endfunc 412 413func Test_illegal_address1() 414 new 415 2;'( 416 2;') 417 quit 418endfunc 419 420func Test_illegal_address2() 421 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') 422 new 423 source Xtest.vim 424 " Trigger calling validate_cursor() 425 diffsp Xtest.vim 426 quit! 427 bwipe! 428 call delete('Xtest.vim') 429endfunc 430 431func Test_cmdline_complete_wildoptions() 432 help 433 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 434 let a = join(sort(split(@:)),' ') 435 set wildoptions=tagfile 436 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 437 let b = join(sort(split(@:)),' ') 438 call assert_equal(a, b) 439 bw! 440endfunc 441 442func Test_cmdline_complete_user_cmd() 443 command! -complete=color -nargs=1 Foo : 444 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') 445 call assert_equal('"Foo blue', @:) 446 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') 447 call assert_equal('"Foo blue', @:) 448 delcommand Foo 449endfunc 450 451func Test_cmdline_complete_user_names() 452 if has('unix') && executable('whoami') 453 let whoami = systemlist('whoami')[0] 454 let first_letter = whoami[0] 455 if len(first_letter) > 0 456 " Trying completion of :e ~x where x is the first letter of 457 " the user name should complete to at least the user name. 458 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 459 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 460 endif 461 endif 462 if has('win32') 463 " Just in case: check that the system has an Administrator account. 464 let names = system('net user') 465 if names =~ 'Administrator' 466 " Trying completion of :e ~A should complete to Administrator. 467 " There could be other names starting with "A" before Administrator. 468 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 469 call assert_match('^"e \~.*Administrator', @:) 470 endif 471 endif 472endfunc 473 474funct Test_cmdline_complete_languages() 475 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 476 477 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 478 call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) 479 480 if has('unix') 481 " TODO: these tests don't work on Windows. lang appears to be 'C' 482 " but C does not appear in the completion. Why? 483 call assert_match('^"language .*\<' . lang . '\>', @:) 484 485 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 486 call assert_match('^"language .*\<' . lang . '\>', @:) 487 488 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 489 call assert_match('^"language .*\<' . lang . '\>', @:) 490 491 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 492 call assert_match('^"language .*\<' . lang . '\>', @:) 493 endif 494endfunc 495 496func Test_cmdline_write_alternatefile() 497 new 498 call setline('.', ['one', 'two']) 499 f foo.txt 500 new 501 f #-A 502 call assert_equal('foo.txt-A', expand('%')) 503 f #<-B.txt 504 call assert_equal('foo-B.txt', expand('%')) 505 f %< 506 call assert_equal('foo-B', expand('%')) 507 new 508 call assert_fails('f #<', 'E95') 509 bw! 510 f foo-B.txt 511 f %<-A 512 call assert_equal('foo-B-A', expand('%')) 513 bw! 514 bw! 515endfunc 516 517" using a leading backslash here 518set cpo+=C 519 520func Test_cmdline_search_range() 521 new 522 call setline(1, ['a', 'b', 'c', 'd']) 523 /d 524 1,\/s/b/B/ 525 call assert_equal('B', getline(2)) 526 527 /a 528 $ 529 \?,4s/c/C/ 530 call assert_equal('C', getline(3)) 531 532 call setline(1, ['a', 'b', 'c', 'd']) 533 %s/c/c/ 534 1,\&s/b/B/ 535 call assert_equal('B', getline(2)) 536 537 bwipe! 538endfunc 539 540" Tests for getcmdline(), getcmdpos() and getcmdtype() 541func Check_cmdline(cmdtype) 542 call assert_equal('MyCmd a', getcmdline()) 543 call assert_equal(8, getcmdpos()) 544 call assert_equal(a:cmdtype, getcmdtype()) 545 return '' 546endfunc 547 548func Test_getcmdtype() 549 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 550 551 let cmdtype = '' 552 debuggreedy 553 call feedkeys(":debug echo 'test'\<CR>", "t") 554 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 555 call feedkeys("cont\<CR>", "xt") 556 0debuggreedy 557 call assert_equal('>', cmdtype) 558 559 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 560 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 561 562 call feedkeys(":call input('Answer?')\<CR>", "t") 563 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 564 565 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 566 567 cnoremap <expr> <F6> Check_cmdline('=') 568 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 569 cunmap <F6> 570endfunc 571 572func Test_getcmdwintype() 573 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 574 call assert_equal('/', a) 575 576 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 577 call assert_equal('?', a) 578 579 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 580 call assert_equal(':', a) 581 582 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 583 call assert_equal(':', a) 584 585 call assert_equal('', getcmdwintype()) 586endfunc 587 588func Test_verbosefile() 589 set verbosefile=Xlog 590 echomsg 'foo' 591 echomsg 'bar' 592 set verbosefile= 593 let log = readfile('Xlog') 594 call assert_match("foo\nbar", join(log, "\n")) 595 call delete('Xlog') 596endfunc 597 598func Test_setcmdpos() 599 func InsertTextAtPos(text, pos) 600 call assert_equal(0, setcmdpos(a:pos)) 601 return a:text 602 endfunc 603 604 " setcmdpos() with position in the middle of the command line. 605 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 606 call assert_equal('"1ab2', @:) 607 608 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 609 call assert_equal('"1b2a', @:) 610 611 " setcmdpos() with position beyond the end of the command line. 612 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 613 call assert_equal('"12ab', @:) 614 615 " setcmdpos() returns 1 when not editing the command line. 616 call assert_equal(1, setcmdpos(3)) 617endfunc 618 619func Test_cmdline_overstrike() 620 let encodings = ['latin1', 'utf8'] 621 let encoding_save = &encoding 622 623 for e in encodings 624 exe 'set encoding=' . e 625 626 " Test overstrike in the middle of the command line. 627 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 628 call assert_equal('"0ab1cd4', @:) 629 630 " Test overstrike going beyond end of command line. 631 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 632 call assert_equal('"0ab1cdefgh', @:) 633 634 " Test toggling insert/overstrike a few times. 635 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 636 call assert_equal('"ab0cd3ef4', @:) 637 endfor 638 639 " Test overstrike with multi-byte characters. 640 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 641 call assert_equal('"テabキcdエディタ', @:) 642 643 let &encoding = encoding_save 644endfunc 645 646set cpo& 647