test_cmdline.vim (180842B)
1 " Tests for editing the command line. 2 3 source check.vim 4 source screendump.vim 5 source view_util.vim 6 source shared.vim 7 8 func SetUp() 9 func SaveLastScreenLine() 10 let g:Sline = Screenline(&lines - 1) 11 return '' 12 endfunc 13 cnoremap <expr> <F4> SaveLastScreenLine() 14 endfunc 15 16 func TearDown() 17 delfunc SaveLastScreenLine 18 cunmap <F4> 19 endfunc 20 21 func Test_complete_tab() 22 call writefile(['testfile'], 'Xtestfile') 23 call feedkeys(":e Xtest\t\r", "tx") 24 call assert_equal('testfile', getline(1)) 25 26 " Pressing <Tab> after '%' completes the current file, also on MS-Windows 27 call feedkeys(":e %\t\r", "tx") 28 call assert_equal('e Xtestfile', @:) 29 call delete('Xtestfile') 30 endfunc 31 32 func Test_complete_list() 33 " We can't see the output, but at least we check the code runs properly. 34 call feedkeys(":e test\<C-D>\r", "tx") 35 call assert_equal('test', expand('%:t')) 36 37 " If a command doesn't support completion, then CTRL-D should be literally 38 " used. 39 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') 40 call assert_equal("\"chistory \<C-D>", @:) 41 42 " Test for displaying the tail of the completion matches 43 set wildmode=longest,full 44 call mkdir('Xtest') 45 call writefile([], 'Xtest/a.c') 46 call writefile([], 'Xtest/a.h') 47 let g:Sline = '' 48 call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') 49 call assert_equal('a.c a.h', g:Sline) 50 call assert_equal('"e Xtest/', @:) 51 if has('win32') 52 " Test for 'completeslash' 53 set completeslash=backslash 54 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt') 55 call assert_equal('"e Xtest\', @:) 56 call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt') 57 call assert_equal('"e Xtest\a.', @:) 58 set completeslash=slash 59 call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt') 60 call assert_equal('"e Xtest/', @:) 61 call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt') 62 call assert_equal('"e Xtest/a.', @:) 63 set completeslash& 64 endif 65 66 " Test for displaying the tail with wildcards 67 let g:Sline = '' 68 call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') 69 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) 70 call assert_equal('"e Xtes?/', @:) 71 let g:Sline = '' 72 call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') 73 call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) 74 call assert_equal('"e Xtes*/', @:) 75 let g:Sline = '' 76 call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') 77 call assert_equal(':e Xtes[/', g:Sline) 78 call assert_equal('"e Xtes[/', @:) 79 80 call delete('Xtest', 'rf') 81 set wildmode& 82 endfunc 83 84 func Test_complete_wildmenu() 85 call mkdir('Xwilddir1/Xdir2', 'pR') 86 call writefile(['testfile1'], 'Xwilddir1/Xtestfile1') 87 call writefile(['testfile2'], 'Xwilddir1/Xtestfile2') 88 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3') 89 call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4') 90 set wildmenu 91 92 " Pressing <Tab> completes, and moves to next files when pressing again. 93 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx') 94 call assert_equal('testfile1', getline(1)) 95 call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') 96 call assert_equal('testfile2', getline(1)) 97 98 " <S-Tab> is like <Tab> but begin with the last match and then go to 99 " previous. 100 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx') 101 call assert_equal('testfile2', getline(1)) 102 call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') 103 call assert_equal('testfile1', getline(1)) 104 105 " <Left>/<Right> to move to previous/next file. 106 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx') 107 call assert_equal('testfile1', getline(1)) 108 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') 109 call assert_equal('testfile2', getline(1)) 110 call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') 111 call assert_equal('testfile1', getline(1)) 112 113 " <Up>/<Down> to go up/down directories. 114 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx') 115 call assert_equal('testfile3', getline(1)) 116 call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') 117 call assert_equal('testfile1', getline(1)) 118 119 " this fails in some Unix GUIs, not sure why 120 if !has('unix') || !has('gui_running') 121 " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is 122 " different than 'wildchar'. 123 set wildcharm=<C-Z> 124 cnoremap <C-J> <Down><C-Z> 125 cnoremap <C-K> <Up><C-Z> 126 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx') 127 call assert_equal('testfile3', getline(1)) 128 call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx') 129 call assert_equal('testfile1', getline(1)) 130 set wildcharm=0 131 cunmap <C-J> 132 cunmap <C-K> 133 endif 134 135 " Test for canceling the wild menu by adding a character 136 redrawstatus 137 call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt') 138 call assert_equal('"e Xwilddir1/Xdir2/x', @:) 139 140 " Completion using a relative path 141 cd Xwilddir1/Xdir2 142 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') 143 call assert_equal('"e Xtestfile3 Xtestfile4', @:) 144 cd - 145 146 " test for wildmenumode() 147 cnoremap <expr> <F2> wildmenumode() 148 call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') 149 call assert_equal('"cd Xwilddir1/0', @:) 150 call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') 151 call assert_equal('"e Xwilddir1/Xdir2/1', @:) 152 cunmap <F2> 153 154 " Test for canceling the wild menu by pressing <PageDown> or <PageUp>. 155 " After this pressing <Left> or <Right> should not change the selection. 156 call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx') 157 call assert_equal('"sign define', @:) 158 call histadd('cmd', 'TestWildMenu') 159 call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx') 160 call assert_equal('"TestWildMenu', @:) 161 162 " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match 163 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx') 164 call assert_equal('"sign un yy zz', @:) 165 166 call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx') 167 call assert_equal('"sign unplace yy zz', @:) 168 169 " This used to crash 170 call feedkeys(":sign un\<Tab>\<S-Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx') 171 " Ctrl-Y is inserted literally like before 9.1.1714 172 call assert_equal("\"sign undefine unplace\<C-Y>", @:) 173 " Also test Ctrl-Y after Ctrl-A with selected item (the result is the same) 174 call feedkeys(":sign un\<Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx') 175 call assert_equal("\"sign undefine unplace\<C-Y>", @:) 176 call feedkeys(":sign un\<Tab>\<Tab>\<C-A>\<C-Y>\<C-B>\"\<CR>", 'tx') 177 call assert_equal("\"sign undefine unplace\<C-Y>", @:) 178 179 " cleanup 180 %bwipe 181 set nowildmenu 182 endfunc 183 184 func Test_wildmenu_screendump() 185 CheckScreendump 186 187 let lines =<< trim [SCRIPT] 188 set wildmenu hlsearch 189 [SCRIPT] 190 call writefile(lines, 'XTest_wildmenu', 'D') 191 192 " Test simple wildmenu 193 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8}) 194 call term_sendkeys(buf, ":vim\<Tab>") 195 call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) 196 197 call term_sendkeys(buf, "\<Tab>") 198 call VerifyScreenDump(buf, 'Test_wildmenu_2', {}) 199 200 call term_sendkeys(buf, "\<Tab>") 201 call VerifyScreenDump(buf, 'Test_wildmenu_3', {}) 202 203 " Looped back to the original value 204 call term_sendkeys(buf, "\<Tab>\<Tab>") 205 call VerifyScreenDump(buf, 'Test_wildmenu_4', {}) 206 207 " Test that the wild menu is cleared properly 208 call term_sendkeys(buf, " ") 209 call VerifyScreenDump(buf, 'Test_wildmenu_5', {}) 210 211 " Test that a different wildchar still works 212 call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>") 213 call term_sendkeys(buf, ":vim\<Esc>") 214 call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) 215 216 " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make 217 " sure clean up is properly done in edge case like this. 218 call term_sendkeys(buf, "\<Esc>") 219 call VerifyScreenDump(buf, 'Test_wildmenu_6', {}) 220 221 " clean up 222 call StopVimInTerminal(buf) 223 endfunc 224 225 func Test_wildmenu_with_input_func() 226 CheckScreendump 227 228 let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8}) 229 230 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>") 231 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {}) 232 call term_sendkeys(buf, "ech\<Tab>") 233 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {}) 234 call term_sendkeys(buf, "\<Space>") 235 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {}) 236 call term_sendkeys(buf, "bufn\<Tab>") 237 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {}) 238 call term_sendkeys(buf, "\<CR>") 239 240 call term_sendkeys(buf, ":set wildoptions+=pum\<CR>") 241 242 call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>") 243 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {}) 244 call term_sendkeys(buf, "ech\<Tab>") 245 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {}) 246 call term_sendkeys(buf, "\<Space>") 247 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {}) 248 call term_sendkeys(buf, "bufn\<Tab>") 249 call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {}) 250 call term_sendkeys(buf, "\<CR>") 251 252 " clean up 253 call StopVimInTerminal(buf) 254 endfunc 255 256 func Test_redraw_in_autocmd() 257 CheckScreendump 258 259 let lines =<< trim END 260 set cmdheight=2 261 autocmd CmdlineChanged * redraw 262 END 263 call writefile(lines, 'XTest_redraw', 'D') 264 265 let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8}) 266 call term_sendkeys(buf, ":for i in range(3)\<CR>") 267 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {}) 268 269 call term_sendkeys(buf, "let i =") 270 call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {}) 271 272 " clean up 273 call term_sendkeys(buf, "\<CR>") 274 call StopVimInTerminal(buf) 275 endfunc 276 277 func Test_redrawstatus_in_autocmd() 278 CheckScreendump 279 280 let lines =<< trim END 281 set laststatus=2 282 set statusline=%=:%{getcmdline()} 283 autocmd CmdlineChanged * redrawstatus 284 END 285 call writefile(lines, 'XTest_redrawstatus', 'D') 286 287 let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8}) 288 " :redrawstatus is postponed if messages have scrolled 289 call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>") 290 call term_sendkeys(buf, ":foobar") 291 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) 292 " it is not postponed if messages have not scrolled 293 call term_sendkeys(buf, "\<Esc>:for in in range(3)") 294 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {}) 295 " with cmdheight=1 messages have scrolled when typing :endfor 296 call term_sendkeys(buf, "\<CR>:endfor") 297 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {}) 298 call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>") 299 " with cmdheight=2 messages haven't scrolled when typing :for or :endfor 300 call term_sendkeys(buf, ":for in in range(3)") 301 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {}) 302 call term_sendkeys(buf, "\<CR>:endfor") 303 call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {}) 304 305 " clean up 306 call term_sendkeys(buf, "\<CR>") 307 call StopVimInTerminal(buf) 308 endfunc 309 310 func Test_changing_cmdheight() 311 CheckScreendump 312 313 let lines =<< trim END 314 set cmdheight=1 laststatus=2 315 func EchoOne() 316 set laststatus=2 cmdheight=1 317 echo 'foo' 318 echo 'bar' 319 set cmdheight=2 320 endfunc 321 func EchoTwo() 322 set laststatus=2 323 set cmdheight=5 324 echo 'foo' 325 echo 'bar' 326 set cmdheight=1 327 endfunc 328 END 329 call writefile(lines, 'XTest_cmdheight', 'D') 330 331 let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8}) 332 call term_sendkeys(buf, ":resize -3\<CR>") 333 call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {}) 334 335 " :resize now also changes 'cmdheight' accordingly 336 call term_sendkeys(buf, ":set cmdheight+=1\<CR>") 337 call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {}) 338 339 " using more space moves the status line up 340 call term_sendkeys(buf, ":set cmdheight+=1\<CR>") 341 call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {}) 342 343 " reducing cmdheight moves status line down 344 call term_sendkeys(buf, ":set cmdheight-=3\<CR>") 345 call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) 346 347 " reducing window size and then setting cmdheight 348 call term_sendkeys(buf, ":resize -1\<CR>") 349 call term_sendkeys(buf, ":set cmdheight=1\<CR>") 350 call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {}) 351 352 " setting 'cmdheight' works after outputting two messages 353 call term_sendkeys(buf, ":call EchoTwo()\<CR>") 354 call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {}) 355 356 " increasing 'cmdheight' doesn't clear the messages that need hit-enter 357 call term_sendkeys(buf, ":call EchoOne()\<CR>") 358 call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {}) 359 360 " window commands do not reduce 'cmdheight' to value lower than :set by user 361 call term_sendkeys(buf, "\<CR>:wincmd _\<CR>") 362 call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {}) 363 364 " clean up 365 call StopVimInTerminal(buf) 366 endfunc 367 368 func Test_cmdheight_tabline() 369 CheckScreendump 370 371 let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6}) 372 call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {}) 373 374 " clean up 375 call StopVimInTerminal(buf) 376 endfunc 377 378 func Test_map_completion() 379 call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') 380 call assert_equal('"map <unique> <silent>', getreg(':')) 381 call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') 382 call assert_equal('"map <script> <unique>', getreg(':')) 383 call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') 384 call assert_equal('"map <expr> <script>', getreg(':')) 385 call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') 386 call assert_equal('"map <buffer> <expr>', getreg(':')) 387 call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') 388 call assert_equal('"map <nowait> <buffer>', getreg(':')) 389 call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') 390 call assert_equal('"map <special> <nowait>', getreg(':')) 391 call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') 392 call assert_equal('"map <silent> <special>', getreg(':')) 393 394 map <Middle>x middle 395 396 map ,f commaf 397 map ,g commaf 398 map <Left> left 399 map <A-Left>x shiftleft 400 call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') 401 call assert_equal('"map ,f', getreg(':')) 402 call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') 403 call assert_equal('"map ,g', getreg(':')) 404 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 405 call assert_equal('"map <Left>', getreg(':')) 406 call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') 407 call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) 408 call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt') 409 call assert_equal("\"map <M-Left>x", getreg(':')) 410 unmap ,f 411 unmap ,g 412 unmap <Left> 413 unmap <A-Left>x 414 415 set cpo-=< cpo-=k 416 map <Left> left 417 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 418 call assert_equal('"map <Left>', getreg(':')) 419 call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') 420 call assert_equal("\"map <M\<Tab>", getreg(':')) 421 call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt') 422 call assert_equal("\"map \<C-V><Middle>x", getreg(':')) 423 unmap <Left> 424 425 " set cpo+=< 426 map <Left> left 427 exe "set t_k6=\<Esc>[17~" 428 call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') 429 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 430 call assert_equal('"map <Left>', getreg(':')) 431 if !has('gui_running') 432 call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') 433 " call assert_equal("\"map <F6>x", getreg(':')) 434 endif 435 unmap <Left> 436 call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') 437 set cpo-=< 438 439 set cpo+=B 440 map <Left> left 441 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 442 call assert_equal('"map <Left>', getreg(':')) 443 unmap <Left> 444 set cpo-=B 445 446 " set cpo+=k 447 map <Left> left 448 call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') 449 call assert_equal('"map <Left>', getreg(':')) 450 unmap <Left> 451 set cpo-=k 452 453 call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:') 454 455 unmap <Middle>x 456 set cpo&vim 457 endfunc 458 459 func Test_match_completion() 460 hi Aardig ctermfg=green 461 " call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') 462 call feedkeys(":match A\<Tab>\<Home>\"\<CR>", 'xt') 463 call assert_equal('"match Aardig', @:) 464 call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') 465 call assert_equal('"match none', @:) 466 call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt') 467 call assert_equal('"match | chistory', @:) 468 endfunc 469 470 func Test_highlight_completion() 471 hi Aardig ctermfg=green 472 " call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') 473 call feedkeys(":hi A\<Tab>\<Home>\"\<CR>", 'xt') 474 call assert_equal('"hi Aardig', getreg(':')) 475 " call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') 476 call feedkeys(":hi default A\<Tab>\<Home>\"\<CR>", 'xt') 477 call assert_equal('"hi default Aardig', getreg(':')) 478 call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') 479 call assert_equal('"hi clear Aardig', getreg(':')) 480 call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') 481 call assert_equal('"hi link', getreg(':')) 482 call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') 483 call assert_equal('"hi default', getreg(':')) 484 call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') 485 call assert_equal('"hi clear', getreg(':')) 486 487 " A cleared group does not show up in completions. 488 hi clear Added 489 hi Anders ctermfg=green 490 call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) 491 hi clear Aardig 492 call assert_equal(['Anders'], getcompletion('A', 'highlight')) 493 hi clear Anders 494 call assert_equal([], getcompletion('A', 'highlight')) 495 endfunc 496 497 func Test_getcompletion() 498 let groupcount = len(getcompletion('', 'event')) 499 call assert_true(groupcount > 0) 500 let matchcount = len('File'->getcompletion('event')) 501 call assert_true(matchcount > 0) 502 call assert_true(groupcount > matchcount) 503 504 if has('menu') 505 source $VIMRUNTIME/menu.vim 506 let matchcount = len(getcompletion('', 'menu')) 507 call assert_true(matchcount > 0) 508 call assert_equal(['File.'], getcompletion('File', 'menu')) 509 call assert_true(matchcount > 0) 510 let matchcount = len(getcompletion('File.', 'menu')) 511 call assert_true(matchcount > 0) 512 source $VIMRUNTIME/delmenu.vim 513 endif 514 515 let l = getcompletion('v:n', 'var') 516 call assert_true(index(l, 'v:null') >= 0) 517 let l = getcompletion('v:notexists', 'var') 518 call assert_equal([], l) 519 520 args a.c b.c 521 let l = getcompletion('', 'arglist') 522 call assert_equal(['a.c', 'b.c'], l) 523 let l = getcompletion('a.', 'buffer') 524 call assert_equal(['a.c'], l) 525 %argdelete 526 527 let l = getcompletion('', 'augroup') 528 call assert_true(index(l, 'END') >= 0) 529 let l = getcompletion('blahblah', 'augroup') 530 call assert_equal([], l) 531 532 " let l = getcompletion('', 'behave') 533 " call assert_true(index(l, 'mswin') >= 0) 534 " let l = getcompletion('not', 'behave') 535 " call assert_equal([], l) 536 537 let l = getcompletion('', 'color') 538 call assert_true(index(l, 'default') >= 0) 539 let l = getcompletion('dirty', 'color') 540 call assert_equal([], l) 541 542 let l = getcompletion('', 'command') 543 call assert_true(index(l, 'sleep') >= 0) 544 let l = getcompletion('awake', 'command') 545 call assert_equal([], l) 546 547 let l = getcompletion('', 'dir') 548 call assert_true(index(l, 'sautest/') >= 0) 549 let l = getcompletion('NoMatch', 'dir') 550 call assert_equal([], l) 551 552 if glob('~/*') !=# '' 553 let l = getcompletion('~/', 'dir') 554 call assert_true(l[0][0] ==# '~') 555 endif 556 557 let l = getcompletion('exe', 'expression') 558 call assert_true(index(l, 'executable(') >= 0) 559 let l = getcompletion('kill', 'expression') 560 call assert_equal([], l) 561 562 let l = getcompletion('', 'filetypecmd') 563 call assert_equal(["indent", "off", "on", "plugin"], l) 564 let l = getcompletion('not', 'filetypecmd') 565 call assert_equal([], l) 566 let l = getcompletion('o', 'filetypecmd') 567 call assert_equal(['off', 'on'], l) 568 569 let l = getcompletion('tag', 'function') 570 call assert_true(index(l, 'taglist(') >= 0) 571 let l = getcompletion('paint', 'function') 572 call assert_equal([], l) 573 574 let Flambda = {-> 'hello'} 575 let l = getcompletion('', 'function') 576 let l = filter(l, {i, v -> v =~ 'lambda'}) 577 call assert_equal(0, len(l)) 578 579 let l = getcompletion('run', 'file') 580 call assert_true(index(l, 'runtest.vim') >= 0) 581 let l = getcompletion('walk', 'file') 582 call assert_equal([], l) 583 set wildignore=*.vim 584 let l = getcompletion('run', 'file', 1) 585 call assert_true(index(l, 'runtest.vim') < 0) 586 set wildignore& 587 " Directory name with space character 588 call mkdir('Xdir with space') 589 call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd')) 590 call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd')) 591 call delete('Xdir with space', 'd') 592 593 let l = getcompletion('ha', 'filetype') 594 call assert_true(index(l, 'hamster') >= 0) 595 let l = getcompletion('horse', 'filetype') 596 call assert_equal([], l) 597 598 if has('keymap') 599 let l = getcompletion('acc', 'keymap') 600 call assert_true(index(l, 'accents') >= 0) 601 let l = getcompletion('nullkeymap', 'keymap') 602 call assert_equal([], l) 603 endif 604 605 let l = getcompletion('z', 'syntax') 606 call assert_true(index(l, 'zimbu') >= 0) 607 let l = getcompletion('emacs', 'syntax') 608 call assert_equal([], l) 609 610 let l = getcompletion('jikes', 'compiler') 611 call assert_true(index(l, 'jikes') >= 0) 612 let l = getcompletion('break', 'compiler') 613 call assert_equal([], l) 614 615 let l = getcompletion('last', 'help') 616 call assert_true(index(l, ':tablast') >= 0) 617 let l = getcompletion('giveup', 'help') 618 call assert_equal([], l) 619 620 let l = getcompletion('time', 'option') 621 call assert_true(index(l, 'timeoutlen') >= 0) 622 let l = getcompletion('space', 'option') 623 call assert_equal([], l) 624 625 let l = getcompletion('er', 'highlight') 626 call assert_true(index(l, 'ErrorMsg') >= 0) 627 let l = getcompletion('dark', 'highlight') 628 call assert_equal([], l) 629 630 let l = getcompletion('', 'messages') 631 call assert_true(index(l, 'clear') >= 0) 632 let l = getcompletion('not', 'messages') 633 call assert_equal([], l) 634 635 let l = getcompletion('', 'mapclear') 636 call assert_true(index(l, '<buffer>') >= 0) 637 let l = getcompletion('not', 'mapclear') 638 call assert_equal([], l) 639 640 let l = getcompletion('', 'retab') 641 call assert_true(index(l, '-indentonly') >= 0) 642 let l = getcompletion('not', 'retab') 643 call assert_equal([], l) 644 645 let l = getcompletion('.', 'shellcmd') 646 call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) 647 call assert_equal(-1, match(l[2:], '^\.\.\?/$')) 648 let root = has('win32') ? 'C:\\' : '/' 649 let l = getcompletion(root, 'shellcmd') 650 let expected = map(filter(glob(root . '*', 0, 1), 651 \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') 652 call assert_equal(expected, l) 653 654 if has('cscope') 655 let l = getcompletion('', 'cscope') 656 let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] 657 call assert_equal(cmds, l) 658 " using cmdline completion must not change the result 659 call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') 660 let l = getcompletion('', 'cscope') 661 call assert_equal(cmds, l) 662 let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] 663 let l = getcompletion('find ', 'cscope') 664 call assert_equal(keys, l) 665 endif 666 667 if has('signs') 668 sign define Testing linehl=Comment 669 let l = getcompletion('', 'sign') 670 let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] 671 call assert_equal(cmds, l) 672 " using cmdline completion must not change the result 673 call feedkeys(":sign list \<c-d>\<c-c>", 'xt') 674 let l = getcompletion('', 'sign') 675 call assert_equal(cmds, l) 676 let l = getcompletion('list ', 'sign') 677 call assert_equal(['Testing'], l) 678 let l = getcompletion('de*', 'sign') 679 call assert_equal(['define'], l) 680 let l = getcompletion('p?', 'sign') 681 call assert_equal(['place'], l) 682 let l = getcompletion('j.', 'sign') 683 call assert_equal(['jump'], l) 684 endif 685 686 " Command line completion tests 687 let l = getcompletion('cd ', 'cmdline') 688 call assert_true(index(l, 'samples/') >= 0) 689 let l = getcompletion('cd NoMatch', 'cmdline') 690 call assert_equal([], l) 691 let l = getcompletion('let v:n', 'cmdline') 692 call assert_true(index(l, 'v:null') >= 0) 693 let l = getcompletion('let v:notexists', 'cmdline') 694 call assert_equal([], l) 695 let l = getcompletion('call tag', 'cmdline') 696 call assert_true(index(l, 'taglist(') >= 0) 697 let l = getcompletion('call paint', 'cmdline') 698 call assert_equal([], l) 699 let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline') 700 call assert_equal(['<buffer>'], l) 701 let l = getcompletion('retab! ', 'cmdline') 702 call assert_true(index(l, '-indentonly') >= 0) 703 704 func T(a, c, p) 705 let g:cmdline_compl_params = [a:a, a:c, a:p] 706 return "oneA\noneB\noneC" 707 endfunc 708 command -nargs=1 -complete=custom,T MyCmd 709 let l = getcompletion('MyCmd ', 'cmdline') 710 call assert_equal(['oneA', 'oneB', 'oneC'], l) 711 call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params) 712 713 delcommand MyCmd 714 delfunc T 715 unlet g:cmdline_compl_params 716 717 " For others test if the name is recognized. 718 let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag', 719 \ 'tag_listfiles', 'user'] 720 if has('cmdline_hist') 721 call add(names, 'history') 722 endif 723 if has('gettext') 724 call add(names, 'locale') 725 endif 726 if has('profile') 727 call add(names, 'syntime') 728 endif 729 730 set tags=Xtags 731 call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') 732 733 for name in names 734 let matchcount = len(getcompletion('', name)) 735 call assert_true(matchcount >= 0, 'No matches for ' . name) 736 endfor 737 738 call delete('Xtags') 739 set tags& 740 741 edit a~b 742 enew 743 call assert_equal(['a~b'], getcompletion('a~', 'buffer')) 744 bw a~b 745 746 if has('unix') 747 edit Xtest\ 748 enew 749 call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer')) 750 bw Xtest\ 751 endif 752 753 call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:') 754 call assert_fails('call getcompletion("", "burp")', 'E475:') 755 call assert_fails('call getcompletion("abc", [])', 'E1174:') 756 endfunc 757 758 func Test_getcompletiontype() 759 call assert_fails('call getcompletiontype()', 'E119:') 760 call assert_fails('call getcompletiontype({})', 'E1174:') 761 call assert_equal('command', getcompletiontype('')) 762 call assert_equal('', getcompletiontype('dummy ')) 763 call assert_equal('', getcompletiontype('ls ')) 764 call assert_equal('dir_in_path', getcompletiontype('cd ')) 765 call assert_equal('var', getcompletiontype('let v:n')) 766 call assert_equal('function', getcompletiontype('call tag')) 767 call assert_equal('help', getcompletiontype('help ')) 768 endfunc 769 770 func Test_multibyte_expression() 771 " Get a dialog in the GUI 772 CheckNotGui 773 774 " This was using uninitialized memory. 775 let lines =<< trim END 776 set verbose=6 777 norm @=ٷ 778 qall! 779 END 780 call writefile(lines, 'XmultiScript', 'D') 781 call RunVim('', '', '-u NONE -n -e -s -S XmultiScript') 782 endfunc 783 784 " Test for getcompletion() with "fuzzy" in 'wildoptions' 785 func Test_getcompletion_wildoptions() 786 let save_wildoptions = &wildoptions 787 set wildoptions& 788 let l = getcompletion('space', 'option') 789 call assert_equal([], l) 790 let l = getcompletion('ier', 'command') 791 call assert_equal([], l) 792 set wildoptions=fuzzy 793 let l = getcompletion('space', 'option') 794 call assert_true(index(l, 'backspace') >= 0) 795 let l = getcompletion('ier', 'command') 796 call assert_true(index(l, 'compiler') >= 0) 797 let &wildoptions = save_wildoptions 798 endfunc 799 800 func Test_fullcommand() 801 let tests = { 802 \ '': '', 803 \ ':': '', 804 \ ':::': '', 805 \ ':::5': '', 806 \ 'not_a_cmd': '', 807 \ 'Check': '', 808 \ 'syntax': 'syntax', 809 \ ':syntax': 'syntax', 810 \ '::::syntax': 'syntax', 811 \ 'sy': 'syntax', 812 \ 'syn': 'syntax', 813 \ 'synt': 'syntax', 814 \ ':sy': 'syntax', 815 \ '::::sy': 'syntax', 816 \ 'match': 'match', 817 \ '2match': 'match', 818 \ '3match': 'match', 819 \ 'aboveleft': 'aboveleft', 820 \ 'abo': 'aboveleft', 821 \ 's': 'substitute', 822 \ '5s': 'substitute', 823 \ ':5s': 'substitute', 824 \ "'<,'>s": 'substitute', 825 \ ":'<,'>s": 'substitute', 826 \ 'CheckLin': 'CheckLinux', 827 \ 'CheckLinux': 'CheckLinux', 828 \ } 829 830 for [in, want] in items(tests) 831 call assert_equal(want, fullcommand(in)) 832 endfor 833 call assert_equal('', fullcommand(v:_null_string)) 834 835 call assert_equal('syntax', 'syn'->fullcommand()) 836 837 command -buffer BufferLocalCommand : 838 command GlobalCommand : 839 call assert_equal('GlobalCommand', fullcommand('GlobalCom')) 840 call assert_equal('BufferLocalCommand', fullcommand('BufferL')) 841 delcommand BufferLocalCommand 842 delcommand GlobalCommand 843 endfunc 844 845 func Test_shellcmd_completion() 846 let save_path = $PATH 847 848 call mkdir('Xpathdir/Xpathsubdir', 'pR') 849 call writefile([''], 'Xpathdir/Xfile.exe') 850 call setfperm('Xpathdir/Xfile.exe', 'rwx------') 851 852 " Set PATH to example directory without trailing slash. 853 let $PATH = getcwd() . '/Xpathdir' 854 855 " Test for the ":!<TAB>" case. Previously, this would include subdirs of 856 " dirs in the PATH, even though they won't be executed. We check that only 857 " subdirs of the PWD and executables from the PATH are included in the 858 " suggestions. 859 let actual = getcompletion('X', 'shellcmd') 860 let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') 861 call insert(expected, 'Xfile.exe') 862 call assert_equal(expected, actual) 863 864 let $PATH = save_path 865 endfunc 866 867 func Test_expand_star_star() 868 call mkdir('a/b/c', 'pR') 869 call writefile(['asdfasdf'], 'a/b/c/fileXname') 870 call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt') 871 call assert_equal('find a/b/c/fileXname', @:) 872 bwipe! 873 endfunc 874 875 func Test_cmdline_paste() 876 let @a = "def" 877 call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') 878 call assert_equal('"abc def ghi', @:) 879 880 new 881 call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') 882 883 call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 884 call assert_equal('"aaa asdf bbb', @:) 885 886 call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') 887 call assert_equal('"aaa /tmp/some bbb', @:) 888 889 call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') 890 call assert_equal('"aaa '.getline(1).' bbb', @:) 891 892 set incsearch 893 call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') 894 call assert_equal('"aaa verylongword bbb', @:) 895 896 call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') 897 call assert_equal('"aaa a;b-c*d bbb', @:) 898 899 call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') 900 call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) 901 bwipe! 902 903 " Error while typing a command used to cause that it was not executed 904 " in the end. 905 new 906 try 907 call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') 908 catch /^Vim\%((\a\+)\)\=:E32/ 909 " ignore error E32 910 endtry 911 call assert_equal("Xtestfile", bufname("%")) 912 913 " Try to paste an invalid register using <C-R> 914 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') 915 call assert_equal('"onetwo', @:) 916 917 " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R 918 let @a = "xy\<C-H>z" 919 call feedkeys(":\"\<C-R>=@a\<CR>\<CR>", 'xt') 920 call assert_equal('"xz', @:) 921 call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') 922 call assert_equal("\"xy\<C-H>z", @:) 923 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') 924 call assert_equal("\"xy\<C-H>z", @:) 925 926 " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R 927 let @a = "xy\<C-V>z" 928 call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') 929 call assert_equal('"xyz', @:) 930 call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') 931 call assert_equal("\"xy\<C-V>z", @:) 932 933 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') 934 935 bwipe! 936 endfunc 937 938 func Test_cmdline_remove_char() 939 let encoding_save = &encoding 940 941 " for e in ['utf8', 'latin1'] 942 for e in ['utf8'] 943 exe 'set encoding=' . e 944 945 call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') 946 call assert_equal('"abc ef', @:, e) 947 948 call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') 949 call assert_equal('"abcdef', @:) 950 951 call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') 952 call assert_equal('"abc ghi', @:, e) 953 954 call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') 955 call assert_equal('"def', @:, e) 956 957 " This was going before the start in latin1. 958 call feedkeys(": \<C-W>\<CR>", 'tx') 959 endfor 960 961 let &encoding = encoding_save 962 endfunc 963 964 func Test_cmdline_del_utf8() 965 let @s = '⒌' 966 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') 967 call assert_equal('",,', @:) 968 969 let @s = 'a̳' 970 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') 971 call assert_equal('",,', @:) 972 973 let @s = 'β̳' 974 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') 975 call assert_equal('",,', @:) 976 977 if has('arabic') 978 let @s = 'لا' 979 call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') 980 call assert_equal('",,', @:) 981 endif 982 endfunc 983 984 func Test_cmdline_keymap_ctrl_hat() 985 CheckFeature keymap 986 987 set keymap=esperanto 988 call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') 989 call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) 990 set keymap= 991 endfunc 992 993 func Test_illegal_address1() 994 new 995 2;'( 996 2;') 997 quit 998 endfunc 999 1000 func Test_illegal_address2() 1001 call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') 1002 new 1003 source Xtest.vim 1004 " Trigger calling validate_cursor() 1005 diffsp Xtest.vim 1006 quit! 1007 bwipe! 1008 call delete('Xtest.vim') 1009 endfunc 1010 1011 func Test_mark_from_line_zero() 1012 " this was reading past the end of the first (empty) line 1013 new 1014 norm oxxxx 1015 call assert_fails("0;'(", 'E20:') 1016 bwipe! 1017 endfunc 1018 1019 func Test_cmdline_complete_wildoptions() 1020 help 1021 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 1022 let a = join(sort(split(@:)),' ') 1023 set wildoptions=tagfile 1024 call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') 1025 let b = join(sort(split(@:)),' ') 1026 call assert_equal(a, b) 1027 bw! 1028 endfunc 1029 1030 func Test_cmdline_complete_user_cmd() 1031 command! -complete=color -nargs=1 Foo : 1032 call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') 1033 call assert_equal('"Foo blue', @:) 1034 call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') 1035 call assert_equal('"Foo blue', @:) 1036 call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx') 1037 call assert_equal('"Foo a blue', @:) 1038 call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx') 1039 call assert_equal('"Foo b\', @:) 1040 call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx') 1041 call assert_equal('"Foo b\x', @:) 1042 delcommand Foo 1043 1044 redraw 1045 call assert_equal('~', Screenline(&lines - 1)) 1046 command! FooOne : 1047 command! FooTwo : 1048 1049 set nowildmenu 1050 call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx') 1051 call assert_equal('"FooOne', @:) 1052 call assert_equal('~', Screenline(&lines - 1)) 1053 1054 call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx') 1055 call assert_equal('"FooTwo', @:) 1056 call assert_equal('~', Screenline(&lines - 1)) 1057 1058 delcommand FooOne 1059 delcommand FooTwo 1060 set wildmenu& 1061 endfunc 1062 1063 func Test_complete_user_cmd() 1064 command FooBar echo 'global' 1065 command -buffer FooBar echo 'local' 1066 call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx') 1067 call assert_equal('"FooBar', @:) 1068 1069 delcommand -buffer FooBar 1070 delcommand FooBar 1071 endfunc 1072 1073 func s:ScriptLocalFunction() 1074 echo 'yes' 1075 endfunc 1076 1077 func Test_cmdline_complete_user_func() 1078 call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') 1079 call assert_match('"func Test_cmdline_complete_user_', @:) 1080 call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') 1081 call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) 1082 1083 " g: prefix also works 1084 call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx') 1085 call assert_match('"echo g:Test_cmdline_complete_user_func', @:) 1086 1087 " using g: prefix does not result in just "g:" matches from a lambda 1088 let Fx = { a -> a } 1089 call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx') 1090 call assert_match('"echo g:[A-Z]', @:) 1091 1092 " existence of script-local dict function does not break user function name 1093 " completion 1094 function s:a_dict_func() dict 1095 endfunction 1096 call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') 1097 call assert_match('"call Test_cmdline_complete_user_', @:) 1098 delfunction s:a_dict_func 1099 endfunc 1100 1101 func Test_cmdline_complete_user_names() 1102 if has('unix') && executable('whoami') 1103 let whoami = systemlist('whoami')[0] 1104 let first_letter = whoami[0] 1105 if len(first_letter) > 0 1106 " Trying completion of :e ~x where x is the first letter of 1107 " the user name should complete to at least the user name. 1108 call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') 1109 call assert_match('^"e \~.*\<' . whoami . '\>', @:) 1110 endif 1111 elseif has('win32') 1112 " Just in case: check that the system has an Administrator account. 1113 let names = system('net user') 1114 if names =~ 'Administrator' 1115 " Trying completion of :e ~A should complete to Administrator. 1116 " There could be other names starting with "A" before Administrator. 1117 call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') 1118 call assert_match('^"e \~.*Administrator', @:) 1119 endif 1120 else 1121 throw 'Skipped: does not work on this platform' 1122 endif 1123 endfunc 1124 1125 func Test_cmdline_complete_shellcmdline() 1126 CheckExecutable whoami 1127 command -nargs=1 -complete=shellcmdline MyCmd 1128 1129 call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx') 1130 call assert_match('^".*\<whoami\>', @:) 1131 let l = getcompletion('whoam', 'shellcmdline') 1132 call assert_match('\<whoami\>', join(l, ' ')) 1133 1134 delcommand MyCmd 1135 endfunc 1136 1137 func Test_cmdline_complete_bang() 1138 CheckExecutable whoami 1139 call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') 1140 call assert_match('^".*\<whoami\>', @:) 1141 endfunc 1142 1143 func Test_cmdline_complete_languages() 1144 let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') 1145 call assert_equal(lang, v:lc_time) 1146 1147 let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') 1148 call assert_equal(lang, v:ctype) 1149 1150 let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') 1151 call assert_equal(lang, v:collate) 1152 1153 let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') 1154 call assert_equal(lang, v:lang) 1155 1156 call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') 1157 call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) 1158 1159 if has('unix') 1160 " TODO: these tests don't work on Windows. lang appears to be 'C' 1161 " but C does not appear in the completion. Why? 1162 call assert_match('^"language .*\<' . lang . '\>', @:) 1163 1164 call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') 1165 call assert_match('^"language .*\<' . lang . '\>', @:) 1166 1167 call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') 1168 call assert_match('^"language .*\<' . lang . '\>', @:) 1169 1170 call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') 1171 call assert_match('^"language .*\<' . lang . '\>', @:) 1172 1173 call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') 1174 call assert_match('^"language .*\<' . lang . '\>', @:) 1175 endif 1176 endfunc 1177 1178 func Test_cmdline_complete_env_variable() 1179 let $X_VIM_TEST_COMPLETE_ENV = 'foo' 1180 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') 1181 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) 1182 unlet $X_VIM_TEST_COMPLETE_ENV 1183 endfunc 1184 1185 func Test_cmdline_complete_expression() 1186 let g:SomeVar = 'blah' 1187 for cmd in ['exe', 'echo', 'echon', 'echomsg', 'echoerr', 1188 "\ 'echoconsole', 'echowindow'] 1189 \ ] 1190 call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 1191 call assert_match('"' .. cmd .. ' SomeVar', @:, cmd) 1192 call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx') 1193 call assert_match('"' .. cmd .. ' foo SomeVar', @:, cmd) 1194 endfor 1195 unlet g:SomeVar 1196 endfunc 1197 1198 func Test_cmdline_complete_argopt() 1199 " completion for ++opt=arg for file commands 1200 call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0]) 1201 call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0]) 1202 call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0]) 1203 1204 call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline')) 1205 " Test ++ff in the middle of the cmdline 1206 call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt') 1207 call assert_equal("\"edit ++fileformat= zz", @:) 1208 1209 call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0]) 1210 call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0]) 1211 call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0]) 1212 call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0]) 1213 call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0]) 1214 1215 call assert_equal([], getcompletion('edit ++bogus=', 'cmdline')) 1216 1217 " completion should skip the ++opt and continue 1218 call writefile([], 'Xaaaaa.txt', 'D') 1219 call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt') 1220 call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:) 1221 1222 if has('terminal') 1223 " completion for terminal's [options] 1224 call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0]) 1225 call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0]) 1226 call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0]) 1227 1228 call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline')) 1229 1230 " :terminal completion should skip the ++opt when considering what is the 1231 " first option, which is a list of shell commands, unlike second option 1232 " onwards. 1233 let first_param = getcompletion('terminal ', 'cmdline') 1234 let second_param = getcompletion('terminal foo ', 'cmdline') 1235 let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline') 1236 call assert_equal(first_param, skipped_opt_param) 1237 call assert_notequal(first_param, second_param) 1238 endif 1239 endfunc 1240 1241 " Unique function name for completion below 1242 func s:WeirdFunc() 1243 echo 'weird' 1244 endfunc 1245 1246 " Test for various command-line completion 1247 func Test_cmdline_complete_various() 1248 " completion for a command starting with a comment 1249 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') 1250 call assert_equal("\" :|\"\<C-A>", @:) 1251 1252 " completion for a range followed by a comment 1253 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') 1254 call assert_equal("\"1,2\"\<C-A>", @:) 1255 1256 " completion for :k command 1257 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') 1258 call assert_equal("\"ka\<C-A>", @:) 1259 1260 " completion for :keepmarks command 1261 call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt') 1262 call assert_equal("\"kee edit", @:) 1263 1264 " completion for short version of the :s command 1265 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') 1266 call assert_equal("\"sI \<C-A>", @:) 1267 1268 " completion for :write command 1269 call mkdir('Xcwdir') 1270 call writefile(['one'], 'Xcwdir/Xfile1') 1271 let save_cwd = getcwd() 1272 cd Xcwdir 1273 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') 1274 call assert_equal("\"w >> Xfile1", @:) 1275 call chdir(save_cwd) 1276 call delete('Xcwdir', 'rf') 1277 1278 " completion for :w ! and :r ! commands 1279 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 1280 call assert_equal("\"w !invalid_xyz_cmd", @:) 1281 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') 1282 call assert_equal("\"r !invalid_xyz_cmd", @:) 1283 1284 " completion for :>> and :<< commands 1285 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') 1286 call assert_equal("\">>>\<C-A>", @:) 1287 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') 1288 call assert_equal("\"<<<\<C-A>", @:) 1289 1290 " completion for command with +cmd argument 1291 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') 1292 call assert_equal("\"buffer +/pat Xabc", @:) 1293 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') 1294 call assert_equal("\"buffer +/pat\<C-A>", @:) 1295 1296 " completion for a command with a trailing comment 1297 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') 1298 call assert_equal("\"ls \" comment\<C-A>", @:) 1299 1300 " completion for a command with a trailing command 1301 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') 1302 call assert_equal("\"ls | ls lsp", @:) 1303 1304 " completion for a command with an CTRL-V escaped argument 1305 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') 1306 call assert_equal("\"ls \<C-V>a\<C-A>", @:) 1307 1308 " completion for a command that doesn't take additional arguments 1309 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') 1310 call assert_equal("\"all abc\<C-A>", @:) 1311 1312 " completion for :wincmd with :horizontal modifier 1313 call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt') 1314 call assert_equal("\"horizontal wincmd", @:) 1315 1316 " completion for a command with a command modifier 1317 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') 1318 call assert_equal("\"topleft new", @:) 1319 1320 " completion for the :disassemble command 1321 " call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt') 1322 " call assert_equal("\"disas debug", @:) 1323 " call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt') 1324 " call assert_equal("\"disas profile", @:) 1325 " call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') 1326 " call assert_equal("\"disas debug Test_cmdline_complete_various", @:) 1327 " call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') 1328 " call assert_equal("\"disas profile Test_cmdline_complete_various", @:) 1329 " call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') 1330 " call assert_equal("\"disas Test_cmdline_complete_various", @:) 1331 1332 " call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt') 1333 " call assert_match('"disas <SNR>\d\+_WeirdFunc', @:) 1334 1335 " call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt') 1336 " call assert_match('"disas <SNR>\d\+_', @:) 1337 " call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt') 1338 " call assert_match('"disas debug <SNR>\d\+_', @:) 1339 1340 " completion for the :match command 1341 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') 1342 call assert_equal("\"match Search /pat/\<C-A>", @:) 1343 1344 " completion for the :doautocmd command 1345 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') 1346 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) 1347 1348 " completion of autocmd group after comma 1349 call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') 1350 call assert_equal("\"doautocmd BufNew,BufEnter", @:) 1351 1352 " completion of file name in :doautocmd 1353 call writefile([], 'Xvarfile1') 1354 call writefile([], 'Xvarfile2') 1355 call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt') 1356 call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:) 1357 call delete('Xvarfile1') 1358 call delete('Xvarfile2') 1359 1360 " completion for the :augroup command 1361 augroup XTest.test 1362 augroup END 1363 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') 1364 call assert_equal("\"augroup XTest.test", @:) 1365 call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt') 1366 call assert_equal("\"au XTest.test", @:) 1367 augroup! XTest.test 1368 1369 " completion for the :unlet command 1370 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') 1371 call assert_equal("\"unlet one two", @:) 1372 1373 " completion for the :buffer command with curlies 1374 " FIXME: what should happen on MS-Windows? 1375 if !has('win32') 1376 edit \{someFile} 1377 call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt') 1378 call assert_equal("\"buf {someFile}", @:) 1379 bwipe {someFile} 1380 endif 1381 1382 " completion for the :bdelete command 1383 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') 1384 call assert_equal("\"bdel a b c", @:) 1385 1386 " completion for the :mapclear command 1387 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') 1388 call assert_equal("\"mapclear <buffer>", @:) 1389 1390 " completion for user defined commands with menu names 1391 menu Test.foo :ls<CR> 1392 com -nargs=* -complete=menu MyCmd 1393 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') 1394 call assert_equal('"MyCmd Test.', @:) 1395 delcom MyCmd 1396 unmenu Test 1397 1398 " completion for user defined commands with mappings 1399 mapclear 1400 map <F3> :ls<CR> 1401 com -nargs=* -complete=mapping MyCmd 1402 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') 1403 call assert_equal('"MyCmd <F3> <F4>', @:) 1404 mapclear 1405 delcom MyCmd 1406 1407 " Prepare for path completion 1408 call mkdir('Xa b c', 'D') 1409 defer delete('Xcomma,foobar.txt') 1410 call writefile([], 'Xcomma,foobar.txt') 1411 1412 " completion for :set path= with multiple backslashes 1413 call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1414 call assert_equal('"set path=Xa\\\ b\\\ c/', @:) 1415 set path& 1416 1417 " completion for :set dir= with a backslash 1418 call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1419 call assert_equal('"set dir=Xa\ b\ c/', @:) 1420 set dir& 1421 1422 " completion for :set tags= / set dictionary= with escaped commas 1423 if has('win32') 1424 " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to 1425 " '\,' 1426 call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1427 call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:) 1428 1429 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1430 call assert_equal('"set tags=Xcomma\,foobar.txt', @:) 1431 1432 call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1433 call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match 1434 1435 " completion for :set dictionary= with escaped commas (same behavior, but 1436 " different internal code path from 'set tags=' for escaping the output) 1437 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1438 call assert_equal('"set tags=Xcomma\,foobar.txt', @:) 1439 else 1440 " In other platforms, backslashes are rounded down (since '\,' itself will 1441 " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'. 1442 call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1443 call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match 1444 1445 call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1446 call assert_equal('"set tags=Xcomma\\,foobar.txt', @:) 1447 1448 call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1449 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) 1450 1451 " completion for :set dictionary= with escaped commas (same behavior, but 1452 " different internal code path from 'set tags=' for escaping the output) 1453 call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1454 call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) 1455 endif 1456 set tags& 1457 set dictionary& 1458 1459 " completion for :set makeprg= with no escaped commas 1460 call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1461 call assert_equal('"set makeprg=Xcomma,foobar.txt', @:) 1462 1463 if !has('win32') 1464 " Cannot create file with backslash in file name in Windows, so only test 1465 " this elsewhere. 1466 defer delete('Xcomma\,fooslash.txt') 1467 call writefile([], 'Xcomma\,fooslash.txt') 1468 call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') 1469 call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:) 1470 endif 1471 set makeprg& 1472 1473 " completion for the :py3 commands 1474 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') 1475 call assert_equal('"py3 py3do py3file', @:) 1476 1477 " redir @" is not the start of a comment. So complete after that 1478 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') 1479 call assert_equal('"redir @" | cwindow', @:) 1480 1481 " completion after a backtick 1482 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') 1483 call assert_equal('"e `a1b2c', @:) 1484 1485 " completion for :language command with an invalid argument 1486 call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') 1487 call assert_equal("\"language dummy \t", @:) 1488 1489 " completion for commands after a :global command 1490 call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') 1491 call assert_equal('"g/a\xb/clearjumps', @:) 1492 1493 " completion with ambiguous user defined commands 1494 com TCmd1 echo 'TCmd1' 1495 com TCmd2 echo 'TCmd2' 1496 call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') 1497 call assert_equal('"TCmd ', @:) 1498 delcom TCmd1 1499 delcom TCmd2 1500 1501 " completion after a range followed by a pipe (|) character 1502 call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') 1503 call assert_equal('"1,10 | chistory', @:) 1504 1505 " completion after a :global command 1506 call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt') 1507 call assert_equal('"g/a/chistory', @:) 1508 set wildchar=0 1509 call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt') 1510 call assert_equal("\"g/a\\/chist\t", @:) 1511 set wildchar& 1512 1513 " use <Esc> as the 'wildchar' for completion 1514 set wildchar=<Esc> 1515 call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') 1516 call assert_equal('"g/a\xb/clearjumps', @:) 1517 " pressing <esc> twice should cancel the command 1518 call feedkeys(":chist\<Esc>\<Esc>", 'xt') 1519 call assert_equal('"g/a\xb/clearjumps', @:) 1520 set wildchar& 1521 1522 if has('unix') 1523 " should be able to complete a file name that starts with a '~'. 1524 call writefile([], '~Xtest') 1525 call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt') 1526 call assert_equal('"e \~Xtest', @:) 1527 call delete('~Xtest') 1528 1529 " should be able to complete a file name that has a '*' 1530 call writefile([], 'Xx*Yy') 1531 call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt') 1532 call assert_equal('"e Xx\*Yy', @:) 1533 call delete('Xx*Yy') 1534 1535 " use a literal star 1536 call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt') 1537 call assert_equal('"e \*', @:) 1538 endif 1539 1540 call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt') 1541 call assert_equal('"py3file', @:) 1542 endfunc 1543 1544 " Test that expanding a pattern doesn't interfere with cmdline completion. 1545 func Test_expand_during_cmdline_completion() 1546 func ExpandStuff() 1547 badd <script>:p:h/README.* 1548 call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$')) 1549 $bwipe 1550 call assert_equal('README.txt', expand('README.*')) 1551 call assert_equal(['README.txt'], getcompletion('README.*', 'file')) 1552 endfunc 1553 augroup test_CmdlineChanged 1554 autocmd! 1555 autocmd CmdlineChanged * call ExpandStuff() 1556 augroup END 1557 1558 call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 1559 call assert_equal('"sign place', @:) 1560 1561 augroup test_CmdlineChanged 1562 au! 1563 augroup END 1564 augroup! test_CmdlineChanged 1565 delfunc ExpandStuff 1566 endfunc 1567 1568 " Test for 'wildignorecase' 1569 func Test_cmdline_wildignorecase() 1570 CheckUnix 1571 call writefile([], 'XTEST') 1572 set wildignorecase 1573 call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt') 1574 call assert_equal('"e XTEST', @:) 1575 call assert_equal(['XTEST'], getcompletion('xt', 'file')) 1576 let g:Sline = '' 1577 call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt') 1578 call assert_equal('"e xt', @:) 1579 call assert_equal('XTEST', g:Sline) 1580 set wildignorecase& 1581 call delete('XTEST') 1582 endfunc 1583 1584 func Test_cmdline_write_alternatefile() 1585 new 1586 call setline('.', ['one', 'two']) 1587 f foo.txt 1588 new 1589 f #-A 1590 call assert_equal('foo.txt-A', expand('%')) 1591 f #<-B.txt 1592 call assert_equal('foo-B.txt', expand('%')) 1593 f %< 1594 call assert_equal('foo-B', expand('%')) 1595 new 1596 call assert_fails('f #<', 'E95') 1597 bw! 1598 f foo-B.txt 1599 f %<-A 1600 call assert_equal('foo-B-A', expand('%')) 1601 bw! 1602 bw! 1603 endfunc 1604 1605 func Test_cmdline_expand_cur_alt_file() 1606 enew 1607 file http://some.com/file.txt 1608 call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt') 1609 call assert_equal('"e http://some.com/file.txt', @:) 1610 edit another 1611 call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt') 1612 call assert_equal('"e http://some.com/file.txt', @:) 1613 bwipe 1614 bwipe http://some.com/file.txt 1615 endfunc 1616 1617 " using a leading backslash here 1618 set cpo+=C 1619 1620 func Test_cmdline_search_range() 1621 new 1622 call setline(1, ['a', 'b', 'c', 'd']) 1623 /d 1624 1,\/s/b/B/ 1625 call assert_equal('B', getline(2)) 1626 1627 /a 1628 $ 1629 \?,4s/c/C/ 1630 call assert_equal('C', getline(3)) 1631 1632 call setline(1, ['a', 'b', 'c', 'd']) 1633 %s/c/c/ 1634 1,\&s/b/B/ 1635 call assert_equal('B', getline(2)) 1636 1637 let @/ = 'apple' 1638 call assert_fails('\/print', ['E486:.*apple']) 1639 1640 bwipe! 1641 endfunc 1642 1643 " Test for the tick mark (') in an excmd range 1644 func Test_tick_mark_in_range() 1645 " If only the tick is passed as a range and no command is specified, there 1646 " should not be an error 1647 call feedkeys(":'\<CR>", 'xt') 1648 call assert_equal("'", @:) 1649 call assert_fails("',print", 'E78:') 1650 endfunc 1651 1652 " Test for using a line number followed by a search pattern as range 1653 func Test_lnum_and_pattern_as_range() 1654 new 1655 call setline(1, ['foo 1', 'foo 2', 'foo 3']) 1656 let @" = '' 1657 2/foo/yank 1658 call assert_equal("foo 3\n", @") 1659 call assert_equal(1, line('.')) 1660 close! 1661 endfunc 1662 1663 " Tests for getcmdline(), getcmdpos() and getcmdtype() 1664 func Check_cmdline(cmdtype) 1665 call assert_equal('MyCmd a', getcmdline()) 1666 call assert_equal(8, getcmdpos()) 1667 call assert_equal(a:cmdtype, getcmdtype()) 1668 return '' 1669 endfunc 1670 1671 set cpo& 1672 1673 func Test_getcmdtype_getcmdprompt() 1674 call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") 1675 1676 let cmdtype = '' 1677 debuggreedy 1678 call feedkeys(":debug echo 'test'\<CR>", "t") 1679 call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") 1680 call feedkeys("cont\<CR>", "xt") 1681 0debuggreedy 1682 call assert_equal('>', cmdtype) 1683 1684 call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") 1685 call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") 1686 1687 call feedkeys(":call input('Answer?')\<CR>", "t") 1688 call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") 1689 1690 call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") 1691 1692 cnoremap <expr> <F6> Check_cmdline('=') 1693 call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") 1694 cunmap <F6> 1695 1696 call assert_equal('', getcmdline()) 1697 1698 call assert_equal('', getcmdprompt()) 1699 augroup test_CmdlineEnter 1700 autocmd! 1701 autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt() 1702 augroup END 1703 call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt") 1704 call assert_equal('Answer?', g:cmdprompt) 1705 call assert_equal('', getcmdprompt()) 1706 call feedkeys(":\<CR>\<ESC>", "xt") 1707 call assert_equal('', g:cmdprompt) 1708 call assert_equal('', getcmdprompt()) 1709 1710 let str = "C" .. repeat("c", 1023) .. "xyz" 1711 call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt") 1712 call assert_equal(str, g:cmdprompt) 1713 1714 call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt") 1715 call assert_equal('Ans?', g:cmdprompt) 1716 call assert_equal('', getcmdprompt()) 1717 1718 augroup test_CmdlineEnter 1719 au! 1720 augroup END 1721 augroup! test_CmdlineEnter 1722 endfunc 1723 1724 func Test_getcmdwintype() 1725 call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1726 call assert_equal('/', a) 1727 1728 call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1729 call assert_equal('?', a) 1730 1731 call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1732 call assert_equal(':', a) 1733 1734 call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') 1735 call assert_equal(':', a) 1736 1737 call assert_equal('', getcmdwintype()) 1738 endfunc 1739 1740 func Test_getcmdwin_autocmd() 1741 let s:seq = [] 1742 augroup CmdWin 1743 au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) 1744 au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) 1745 au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) 1746 au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) 1747 au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) 1748 au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) 1749 1750 let org_winid = win_getid() 1751 let org_bufnr = bufnr() 1752 call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') 1753 call assert_equal(':', a) 1754 call assert_equal([ 1755 \ 'WinLeave ' .. org_winid, 1756 \ 'WinEnter ' .. s:cmd_winid, 1757 \ 'BufLeave ' .. org_bufnr, 1758 \ 'BufEnter ' .. s:cmd_bufnr, 1759 \ 'CmdWinEnter ' .. s:cmd_winid, 1760 \ 'CmdWinLeave ' .. s:cmd_winid, 1761 \ 'BufLeave ' .. s:cmd_bufnr, 1762 \ 'WinLeave ' .. s:cmd_winid, 1763 \ 'WinEnter ' .. org_winid, 1764 \ 'BufEnter ' .. org_bufnr, 1765 \ ], s:seq) 1766 1767 au! 1768 augroup END 1769 endfunc 1770 1771 func Test_verbosefile() 1772 set verbosefile=Xlog 1773 echomsg 'foo' 1774 echomsg 'bar' 1775 set verbosefile= 1776 let log = readfile('Xlog') 1777 call assert_match("foo\nbar", join(log, "\n")) 1778 call delete('Xlog') 1779 call mkdir('Xdir') 1780 if !has('win32') " FIXME: no error on Windows, libuv bug? 1781 call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) 1782 endif 1783 call delete('Xdir', 'd') 1784 endfunc 1785 1786 func Test_verbose_option() 1787 " See test/functional/legacy/cmdline_spec.lua 1788 CheckScreendump 1789 1790 let lines =<< trim [SCRIPT] 1791 command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 1792 call feedkeys("\r", 't') " for the hit-enter prompt 1793 set verbose=20 1794 [SCRIPT] 1795 call writefile(lines, 'XTest_verbose') 1796 1797 let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) 1798 call TermWait(buf, 50) 1799 call term_sendkeys(buf, ":DoSomething\<CR>") 1800 call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) 1801 1802 " clean up 1803 call StopVimInTerminal(buf) 1804 call delete('XTest_verbose') 1805 endfunc 1806 1807 func Test_setcmdpos() 1808 func InsertTextAtPos(text, pos) 1809 call assert_equal(0, setcmdpos(a:pos)) 1810 return a:text 1811 endfunc 1812 1813 " setcmdpos() with position in the middle of the command line. 1814 call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1815 call assert_equal('"1ab2', @:) 1816 1817 call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') 1818 call assert_equal('"1b2a', @:) 1819 1820 " setcmdpos() with position beyond the end of the command line. 1821 call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') 1822 call assert_equal('"12ab', @:) 1823 1824 " setcmdpos() returns 1 when not editing the command line. 1825 call assert_equal(1, 3->setcmdpos()) 1826 endfunc 1827 1828 func Test_cmdline_overstrike() 1829 " Nvim: only utf8 is supported. 1830 let encodings = ['utf8'] 1831 let encoding_save = &encoding 1832 1833 for e in encodings 1834 exe 'set encoding=' . e 1835 1836 " Test overstrike in the middle of the command line. 1837 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1838 call assert_equal('"0ab1cd4', @:, e) 1839 1840 " Test overstrike going beyond end of command line. 1841 call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') 1842 call assert_equal('"0ab1cdefgh', @:, e) 1843 1844 " Test toggling insert/overstrike a few times. 1845 call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') 1846 call assert_equal('"ab0cd3ef4', @:, e) 1847 endfor 1848 1849 " Test overstrike with multi-byte characters. 1850 call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') 1851 call assert_equal('"テabキcdエディタ', @:, e) 1852 1853 let &encoding = encoding_save 1854 endfunc 1855 1856 func Test_cmdwin_bug() 1857 let winid = win_getid() 1858 sp 1859 try 1860 call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') 1861 catch /^Vim\%((\a\+)\)\=:E11/ 1862 endtry 1863 bw! 1864 endfunc 1865 1866 func Test_cmdwin_restore() 1867 CheckScreendump 1868 1869 let lines =<< trim [SCRIPT] 1870 call setline(1, range(30)) 1871 2split 1872 [SCRIPT] 1873 call writefile(lines, 'XTest_restore') 1874 1875 let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) 1876 call TermWait(buf, 50) 1877 call term_sendkeys(buf, "q:") 1878 call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) 1879 1880 " normal restore 1881 call term_sendkeys(buf, ":q\<CR>") 1882 call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) 1883 1884 " restore after setting 'lines' with one window 1885 call term_sendkeys(buf, ":close\<CR>") 1886 call term_sendkeys(buf, "q:") 1887 call term_sendkeys(buf, ":set lines=18\<CR>") 1888 call term_sendkeys(buf, ":q\<CR>") 1889 call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) 1890 1891 " clean up 1892 call StopVimInTerminal(buf) 1893 call delete('XTest_restore') 1894 endfunc 1895 1896 func Test_cmdwin_no_terminal() 1897 CheckFeature cmdwin 1898 CheckFeature terminal 1899 CheckNotMSWindows 1900 1901 let buf = RunVimInTerminal('', {'rows': 12}) 1902 call TermWait(buf, 50) 1903 call term_sendkeys(buf, ":set cmdheight=2\<CR>") 1904 call term_sendkeys(buf, "q:") 1905 call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>") 1906 call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {}) 1907 call term_sendkeys(buf, ":q\<CR>") 1908 call StopVimInTerminal(buf) 1909 endfunc 1910 1911 func Test_buffers_lastused() 1912 " check that buffers are sorted by time when wildmode has lastused 1913 edit bufc " oldest 1914 1915 sleep 1200m 1916 enew 1917 edit bufa " middle 1918 1919 sleep 1200m 1920 enew 1921 edit bufb " newest 1922 1923 enew 1924 1925 call assert_equal(['bufc', 'bufa', 'bufb'], 1926 \ getcompletion('', 'buffer')) 1927 1928 let save_wildmode = &wildmode 1929 set wildmode=full:lastused 1930 1931 let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" 1932 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1933 call assert_equal('b bufb', X) 1934 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1935 call assert_equal('b bufa', X) 1936 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1937 call assert_equal('b bufc', X) 1938 enew 1939 1940 sleep 1200m 1941 edit other 1942 call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') 1943 call assert_equal('b bufb', X) 1944 call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1945 call assert_equal('b bufa', X) 1946 call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') 1947 call assert_equal('b bufc', X) 1948 enew 1949 1950 let &wildmode = save_wildmode 1951 1952 bwipeout bufa 1953 bwipeout bufb 1954 bwipeout bufc 1955 endfunc 1956 1957 func Test_cmdwin_feedkeys() 1958 " This should not generate E488 1959 call feedkeys("q:\<CR>", 'x') 1960 " Using feedkeys with q: only should automatically close the cmd window 1961 call feedkeys('q:', 'xt') 1962 call assert_equal(1, winnr('$')) 1963 call assert_equal('', getcmdwintype()) 1964 endfunc 1965 1966 " Tests for the issues fixed in 7.4.441. 1967 " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim 1968 func Test_cmdwin_cedit() 1969 exe "set cedit=\<C-c>" 1970 normal! : 1971 call assert_equal(1, winnr('$')) 1972 1973 let g:cmd_wintype = '' 1974 func CmdWinType() 1975 let g:cmd_wintype = getcmdwintype() 1976 let g:wintype = win_gettype() 1977 return '' 1978 endfunc 1979 1980 call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") 1981 echo input('') 1982 call assert_equal('@', g:cmd_wintype) 1983 call assert_equal('command', g:wintype) 1984 1985 set cedit&vim 1986 delfunc CmdWinType 1987 endfunc 1988 1989 " Test for CmdwinEnter autocmd 1990 func Test_cmdwin_autocmd() 1991 CheckFeature cmdwin 1992 1993 augroup CmdWin 1994 au! 1995 autocmd BufLeave * if &buftype == '' | update | endif 1996 autocmd CmdwinEnter * startinsert 1997 augroup END 1998 1999 call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') 2000 call assert_equal('xyz', @:) 2001 2002 augroup CmdWin 2003 au! 2004 augroup END 2005 augroup! CmdWin 2006 endfunc 2007 2008 func Test_cmdlineclear_tabenter() 2009 " See test/functional/legacy/cmdline_spec.lua 2010 CheckScreendump 2011 2012 let lines =<< trim [SCRIPT] 2013 call setline(1, range(30)) 2014 [SCRIPT] 2015 2016 call writefile(lines, 'XtestCmdlineClearTabenter') 2017 let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) 2018 call TermWait(buf, 25) 2019 " in one tab make the command line higher with CTRL-W - 2020 call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") 2021 call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) 2022 2023 call StopVimInTerminal(buf) 2024 call delete('XtestCmdlineClearTabenter') 2025 endfunc 2026 2027 " Test for expanding special keywords in cmdline 2028 func Test_cmdline_expand_special() 2029 new 2030 %bwipe! 2031 call assert_fails('e #', 'E194:') 2032 call assert_fails('e <afile>', 'E495:') 2033 call assert_fails('e <abuf>', 'E496:') 2034 call assert_fails('e <amatch>', 'E497:') 2035 2036 call writefile([], 'Xfile.cpp') 2037 call writefile([], 'Xfile.java') 2038 new Xfile.cpp 2039 call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt') 2040 call assert_equal('"e Xfile.cpp Xfile.java', @:) 2041 close 2042 call delete('Xfile.cpp') 2043 call delete('Xfile.java') 2044 endfunc 2045 2046 func Test_cmdwin_jump_to_win() 2047 call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') 2048 new 2049 set modified 2050 call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:']) 2051 close! 2052 call feedkeys("q/:close\<CR>", "xt") 2053 call assert_equal(1, winnr('$')) 2054 call feedkeys("q/:exit\<CR>", "xt") 2055 call assert_equal(1, winnr('$')) 2056 2057 " opening command window twice should fail 2058 call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') 2059 call assert_equal(1, winnr('$')) 2060 endfunc 2061 2062 func Test_cmdwin_tabpage() 2063 tabedit 2064 call assert_fails("silent norm q/g :I\<Esc>", 'E11:') 2065 tabclose! 2066 endfunc 2067 2068 func Test_cmdwin_interrupted_more_prompt() 2069 CheckScreendump 2070 2071 " aborting the :smile output caused the cmdline window to use the current 2072 " buffer. 2073 let lines =<< trim [SCRIPT] 2074 au WinNew * smile 2075 [SCRIPT] 2076 call writefile(lines, 'XTest_cmdwin') 2077 2078 let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18}) 2079 " open cmdwin 2080 call term_sendkeys(buf, "q:") 2081 call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))}) 2082 " quit more prompt for :smile command 2083 call term_sendkeys(buf, "q") 2084 call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))}) 2085 " execute a simple command 2086 call term_sendkeys(buf, "aecho 'done'\<CR>") 2087 call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {}) 2088 2089 " clean up 2090 call StopVimInTerminal(buf) 2091 call delete('XTest_cmdwin') 2092 endfunc 2093 2094 " Test for backtick expression in the command line 2095 func Test_cmd_backtick() 2096 CheckNotMSWindows " FIXME: see #19297 2097 %argd 2098 argadd `=['a', 'b', 'c']` 2099 call assert_equal(['a', 'b', 'c'], argv()) 2100 %argd 2101 2102 argadd `echo abc def` 2103 call assert_equal(['abc def'], argv()) 2104 %argd 2105 endfunc 2106 2107 " Test for the :! command 2108 func Test_cmd_bang() 2109 CheckUnix 2110 2111 let lines =<< trim [SCRIPT] 2112 " Test for no previous command 2113 call assert_fails('!!', 'E34:') 2114 set nomore 2115 " Test for cmdline expansion with :! 2116 call setline(1, 'foo!') 2117 silent !echo <cWORD> > Xfile.out 2118 call assert_equal(['foo!'], readfile('Xfile.out')) 2119 " Test for using previous command 2120 silent !echo \! ! 2121 call assert_equal(['! echo foo!'], readfile('Xfile.out')) 2122 call writefile(v:errors, 'Xresult') 2123 call delete('Xfile.out') 2124 qall! 2125 [SCRIPT] 2126 call writefile(lines, 'Xscript') 2127 if RunVim([], [], '--clean -S Xscript') 2128 call assert_equal([], readfile('Xresult')) 2129 endif 2130 call delete('Xscript') 2131 call delete('Xresult') 2132 endfunc 2133 2134 " Test error: "E135: *Filter* Autocommands must not change current buffer" 2135 func Test_cmd_bang_E135() 2136 new 2137 call setline(1, ['a', 'b', 'c', 'd']) 2138 augroup test_cmd_filter_E135 2139 au! 2140 autocmd FilterReadPost * help 2141 augroup END 2142 call assert_fails('2,3!echo "x"', 'E135:') 2143 2144 augroup test_cmd_filter_E135 2145 au! 2146 augroup END 2147 augroup! test_cmd_filter_E135 2148 %bwipe! 2149 endfunc 2150 2151 func Test_cmd_bang_args() 2152 new 2153 :.! 2154 call assert_equal(0, v:shell_error) 2155 2156 " Note that below there is one space char after the '!'. This caused a 2157 " shell error in the past, see https://github.com/vim/vim/issues/11495. 2158 :.! 2159 call assert_equal(0, v:shell_error) 2160 bwipe! 2161 2162 CheckUnix 2163 :.!pwd 2164 call assert_equal(0, v:shell_error) 2165 :.! pwd 2166 call assert_equal(0, v:shell_error) 2167 2168 " Note there is one space after 'pwd'. 2169 :.! pwd 2170 call assert_equal(0, v:shell_error) 2171 2172 " Note there are two spaces after 'pwd'. 2173 :.! pwd 2174 call assert_equal(0, v:shell_error) 2175 :.!ls ~ 2176 call assert_equal(0, v:shell_error) 2177 2178 " Note there is one space char after '~'. 2179 :.!ls ~ 2180 call assert_equal(0, v:shell_error) 2181 2182 " Note there are two spaces after '~'. 2183 :.!ls ~ 2184 call assert_equal(0, v:shell_error) 2185 2186 :.!echo "foo" 2187 call assert_equal(getline('.'), "foo") 2188 :.!echo "foo " 2189 call assert_equal(getline('.'), "foo ") 2190 :.!echo " foo " 2191 call assert_equal(getline('.'), " foo ") 2192 :.!echo " foo " 2193 call assert_equal(getline('.'), " foo ") 2194 2195 %bwipe! 2196 endfunc 2197 2198 " Test for using ~ for home directory in cmdline completion matches 2199 func Test_cmdline_expand_home() 2200 call mkdir('Xexpdir') 2201 call writefile([], 'Xexpdir/Xfile1') 2202 call writefile([], 'Xexpdir/Xfile2') 2203 cd Xexpdir 2204 let save_HOME = $HOME 2205 let $HOME = getcwd() 2206 call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') 2207 call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) 2208 let $HOME = save_HOME 2209 cd .. 2210 call delete('Xexpdir', 'rf') 2211 endfunc 2212 2213 " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode 2214 " or insert mode (when 'insertmode' is set) 2215 func Test_cmdline_ctrl_g() 2216 new 2217 call setline(1, 'abc') 2218 call cursor(1, 3) 2219 " If command line is entered from insert mode, using C-\ C-G should back to 2220 " insert mode 2221 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') 2222 call assert_equal('abxyc', getline(1)) 2223 call assert_equal(4, col('.')) 2224 2225 " If command line is entered in 'insertmode', using C-\ C-G should back to 2226 " 'insertmode' 2227 " call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') 2228 " call assert_equal('ab12xyc', getline(1)) 2229 close! 2230 endfunc 2231 2232 " Test for 'wildmode' 2233 func Wildmode_tests() 2234 func T(a, c, p) 2235 return "oneA\noneB\noneC" 2236 endfunc 2237 command -nargs=1 -complete=custom,T MyCmd 2238 2239 set nowildmenu 2240 set wildmode=full,list 2241 let g:Sline = '' 2242 call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt') 2243 call assert_equal('oneA oneB oneC', g:Sline) 2244 call assert_equal('"MyCmd oneA', @:) 2245 2246 set wildmode=longest,full 2247 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2248 call assert_equal('"MyCmd one', @:) 2249 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') 2250 call assert_equal('"MyCmd oneC', @:) 2251 2252 set wildmode=longest 2253 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') 2254 call assert_equal('"MyCmd one', @:) 2255 2256 set wildmode=list:longest 2257 let g:Sline = '' 2258 call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt') 2259 call assert_equal('oneA oneB oneC', g:Sline) 2260 call assert_equal('"MyCmd one', @:) 2261 2262 set wildmode="" 2263 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') 2264 call assert_equal('"MyCmd oneA', @:) 2265 2266 " Test for wildmode=longest with 'fileignorecase' set 2267 set wildmode=longest 2268 set fileignorecase 2269 argadd AAA AAAA AAAAA 2270 call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') 2271 call assert_equal('"buffer AAA', @:) 2272 set fileignorecase& 2273 2274 " Test for listing files with wildmode=list 2275 set wildmode=list 2276 let g:Sline = '' 2277 call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt') 2278 call assert_equal('AAA AAAA AAAAA', g:Sline) 2279 call assert_equal('"b A', @:) 2280 2281 " When 'wildmenu' is not set, 'noselect' completes first item 2282 set wildmode=noselect 2283 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2284 call assert_equal('"MyCmd oneA', @:) 2285 2286 " When 'noselect' is present, do not complete first <tab>. 2287 set wildmenu 2288 set wildmode=noselect 2289 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2290 call assert_equal('"MyCmd o', @:) 2291 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') 2292 call assert_equal('"MyCmd o', @:) 2293 call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt') 2294 call assert_equal('"MyCmd o', @:) 2295 2296 " When 'full' is present, complete after first <tab>. 2297 set wildmode=noselect,full 2298 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2299 call assert_equal('"MyCmd o', @:) 2300 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') 2301 call assert_equal('"MyCmd oneA', @:) 2302 call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt') 2303 call assert_equal('"MyCmd oneB', @:) 2304 call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt') 2305 call assert_equal('"MyCmd oneB', @:) 2306 2307 " 'noselect' has no effect when 'longest' is present. 2308 set wildmode=noselect:longest 2309 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2310 call assert_equal('"MyCmd one', @:) 2311 2312 " Complete 'noselect' value in 'wildmode' option 2313 set wildmode& 2314 call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt') 2315 call assert_equal('"set wildmode=noselect', @:) 2316 call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt') 2317 call assert_equal('"set wildmode=noselect', @:) 2318 2319 " when using longest completion match, matches shorter than the argument 2320 " should be ignored (happens with :help) 2321 set wildmode=longest,full 2322 " XXX: This test is incorrect. ':help a*' will never yield 'help a' 2323 " because '`a' exists as a menu item. The intent was to test a case 2324 " handled by nextwild(). 2325 " call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt') 2326 " call assert_equal('"help a', @:) 2327 " non existing file 2328 call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt') 2329 call assert_equal('"e a1b2y3z4', @:) 2330 2331 " Test for longest file name completion with 'fileignorecase' 2332 " On MS-Windows, file names are case insensitive. 2333 if has('unix') 2334 call writefile([], 'XTESTfoo', 'D') 2335 call writefile([], 'Xtestbar', 'D') 2336 set nofileignorecase 2337 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt') 2338 call assert_equal('"e XTESTfoo', @:) 2339 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt') 2340 call assert_equal('"e Xtestbar', @:) 2341 set fileignorecase 2342 call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt') 2343 call assert_equal('"e Xtest', @:) 2344 call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt') 2345 call assert_equal('"e Xtest', @:) 2346 set fileignorecase& 2347 endif 2348 2349 " If 'noselect' is present, single item menu should not insert item 2350 func! T(a, c, p) 2351 return "oneA" 2352 endfunc 2353 command! -nargs=1 -complete=custom,T MyCmd 2354 set wildmode=noselect,full 2355 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2356 call assert_equal('"MyCmd o', @:) 2357 call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') 2358 call assert_equal('"MyCmd oneA', @:) 2359 " 'nowildmenu' should make 'noselect' ineffective 2360 set nowildmenu 2361 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') 2362 call assert_equal('"MyCmd oneA', @:) 2363 2364 %argdelete 2365 delcommand MyCmd 2366 delfunc T 2367 set wildmode& 2368 %bwipe! 2369 endfunc 2370 2371 func Test_wildmode() 2372 " Test with utf-8 encoding 2373 call Wildmode_tests() 2374 2375 " Test with latin1 encoding 2376 let save_encoding = &encoding 2377 " set encoding=latin1 2378 " call Wildmode_tests() 2379 let &encoding = save_encoding 2380 endfunc 2381 2382 func Test_custom_complete_autoload() 2383 call mkdir('Xcustdir/autoload', 'p') 2384 let save_rtp = &rtp 2385 exe 'set rtp=' .. getcwd() .. '/Xcustdir' 2386 let lines =<< trim END 2387 func vim8#Complete(a, c, p) 2388 return "oneA\noneB\noneC" 2389 endfunc 2390 END 2391 call writefile(lines, 'Xcustdir/autoload/vim8.vim') 2392 2393 command -nargs=1 -complete=custom,vim8#Complete MyCmd 2394 set nowildmenu 2395 set wildmode=full,list 2396 call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt') 2397 call assert_equal('"MyCmd oneA oneB oneC', @:) 2398 2399 let &rtp = save_rtp 2400 set wildmode& wildmenu& 2401 delcommand MyCmd 2402 call delete('Xcustdir', 'rf') 2403 endfunc 2404 2405 " Test for interrupting the command-line completion 2406 func Test_interrupt_compl() 2407 func F(lead, cmdl, p) 2408 if a:lead =~ 'tw' 2409 call interrupt() 2410 return 2411 endif 2412 return "one\ntwo\nthree" 2413 endfunc 2414 command -nargs=1 -complete=custom,F Tcmd 2415 2416 set nowildmenu 2417 set wildmode=full 2418 let interrupted = 0 2419 try 2420 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') 2421 catch /^Vim:Interrupt$/ 2422 let interrupted = 1 2423 endtry 2424 call assert_equal(1, interrupted) 2425 2426 let interrupted = 0 2427 try 2428 call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt') 2429 catch /^Vim:Interrupt$/ 2430 let interrupted = 1 2431 endtry 2432 call assert_equal(1, interrupted) 2433 2434 delcommand Tcmd 2435 delfunc F 2436 set wildmode& 2437 endfunc 2438 2439 " Test for moving the cursor on the : command line 2440 func Test_cmdline_edit() 2441 let str = ":one two\<C-U>" 2442 let str ..= "one two\<C-W>\<C-W>" 2443 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 2444 let str ..= "\<Left>five\<Right>" 2445 let str ..= "\<Home>two " 2446 let str ..= "\<C-Left>one " 2447 let str ..= "\<C-Right> three" 2448 let str ..= "\<End>\<S-Left>four " 2449 let str ..= "\<S-Right> six" 2450 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 2451 call feedkeys(str, 'xt') 2452 call assert_equal("\"one two three four five six seven", @:) 2453 endfunc 2454 2455 " Test for moving the cursor on the / command line in 'rightleft' mode 2456 func Test_cmdline_edit_rightleft() 2457 CheckFeature rightleft 2458 set rightleft 2459 set rightleftcmd=search 2460 let str = "/one two\<C-U>" 2461 let str ..= "one two\<C-W>\<C-W>" 2462 let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" 2463 let str ..= "\<Right>five\<Left>" 2464 let str ..= "\<Home>two " 2465 let str ..= "\<C-Right>one " 2466 let str ..= "\<C-Left> three" 2467 let str ..= "\<End>\<S-Right>four " 2468 let str ..= "\<S-Left> six" 2469 let str ..= "\<C-B>\"\<C-E> seven\<CR>" 2470 call assert_fails("call feedkeys(str, 'xt')", 'E486:') 2471 call assert_equal("\"one two three four five six seven", @/) 2472 set rightleftcmd& 2473 set rightleft& 2474 endfunc 2475 2476 " Test for using <C-\>e in the command line to evaluate an expression 2477 func Test_cmdline_expr() 2478 " Evaluate an expression from the beginning of a command line 2479 call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') 2480 call assert_equal('"hello', @:) 2481 2482 " Use an invalid expression for <C-\>e 2483 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 2484 2485 " Insert literal <CTRL-\> in the command line 2486 call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') 2487 call assert_equal("\"e \<C-\>\<C-Y>", @:) 2488 endfunc 2489 2490 " This was making the insert position negative 2491 func Test_cmdline_expr_register() 2492 exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>" 2493 endfunc 2494 2495 " Test for 'imcmdline' and 'imsearch' 2496 " This test doesn't actually test the input method functionality. 2497 func Test_cmdline_inputmethod() 2498 throw 'Skipped: Nvim does not allow setting the value of a hidden option' 2499 new 2500 call setline(1, ['', 'abc', '']) 2501 set imcmdline 2502 2503 call feedkeys(":\"abc\<CR>", 'xt') 2504 call assert_equal("\"abc", @:) 2505 call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') 2506 call assert_equal("\"abc", @:) 2507 call feedkeys("/abc\<CR>", 'xt') 2508 call assert_equal([2, 1], [line('.'), col('.')]) 2509 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 2510 call assert_equal([2, 1], [line('.'), col('.')]) 2511 2512 " set imsearch=2 2513 call cursor(1, 1) 2514 call feedkeys("/abc\<CR>", 'xt') 2515 call assert_equal([2, 1], [line('.'), col('.')]) 2516 call cursor(1, 1) 2517 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 2518 call assert_equal([2, 1], [line('.'), col('.')]) 2519 set imdisable 2520 call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') 2521 call assert_equal([2, 1], [line('.'), col('.')]) 2522 set imdisable& 2523 set imsearch& 2524 2525 set imcmdline& 2526 %bwipe! 2527 endfunc 2528 2529 " Test for recursively getting multiple command line inputs 2530 func Test_cmdwin_multi_input() 2531 call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') 2532 call assert_equal('"cyan', @:) 2533 endfunc 2534 2535 " Test for using CTRL-_ in the command line with 'allowrevins' 2536 func Test_cmdline_revins() 2537 CheckNotMSWindows 2538 CheckFeature rightleft 2539 call feedkeys(":\"abc\<c-_>\<cr>", 'xt') 2540 call assert_equal("\"abc\<c-_>", @:) 2541 set allowrevins 2542 call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') 2543 " call assert_equal('"abcñèæ', @:) 2544 call assert_equal('"abcxyz', @:) 2545 set allowrevins& 2546 endfunc 2547 2548 " Test for typing UTF-8 composing characters in the command line 2549 func Test_cmdline_composing_chars() 2550 call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') 2551 call assert_equal('"ゔ', @:) 2552 endfunc 2553 2554 " Test for normal mode commands not supported in the cmd window 2555 func Test_cmdwin_blocked_commands() 2556 call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') 2557 call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') 2558 call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') 2559 call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') 2560 call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') 2561 call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') 2562 call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:') 2563 call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:') 2564 call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:') 2565 call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:') 2566 call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:') 2567 call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:') 2568 call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:') 2569 call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:') 2570 call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:') 2571 call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:') 2572 call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:') 2573 call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:') 2574 call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:') 2575 call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:') 2576 call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:') 2577 call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:') 2578 call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:') 2579 call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:') 2580 call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:') 2581 call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:') 2582 call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:') 2583 endfunc 2584 2585 " Close the Cmd-line window in insert mode using CTRL-C 2586 func Test_cmdwin_insert_mode_close() 2587 %bw! 2588 let s = '' 2589 exe "normal q:a\<C-C>let s='Hello'\<CR>" 2590 call assert_equal('Hello', s) 2591 call assert_equal(1, winnr('$')) 2592 endfunc 2593 2594 func Test_cmdwin_ex_mode_with_modifier() 2595 " this was accessing memory after allocated text in Ex mode 2596 new 2597 call setline(1, ['some', 'text', 'lines']) 2598 silent! call feedkeys("gQnormal vq:atopleft\<C-V>\<CR>\<CR>", 'xt') 2599 bwipe! 2600 endfunc 2601 2602 " test that ";" works to find a match at the start of the first line 2603 func Test_zero_line_search() 2604 new 2605 call setline(1, ["1, pattern", "2, ", "3, pattern"]) 2606 call cursor(1,1) 2607 0;/pattern/d 2608 call assert_equal(["2, ", "3, pattern"], getline(1,'$')) 2609 q! 2610 endfunc 2611 2612 func Test_read_shellcmd() 2613 CheckUnix 2614 if executable('ls') 2615 " There should be ls in the $PATH 2616 call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') 2617 call assert_match('^"r! .*\<ls\>', @:) 2618 endif 2619 2620 if executable('rm') 2621 call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') 2622 call assert_notmatch('^"r!.*\<runtest.vim\>', @:) 2623 call assert_match('^"r!.*\<rm\>', @:) 2624 2625 call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') 2626 call assert_notmatch('^"r.*\<runtest.vim\>', @:) 2627 call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) 2628 endif 2629 endfunc 2630 2631 " Test for going up and down the directory tree using 'wildmenu' 2632 func Test_wildmenu_dirstack() 2633 CheckUnix 2634 %bw! 2635 call mkdir('Xdir1/dir2/dir3/dir4', 'p') 2636 call writefile([], 'Xdir1/file1_1.txt') 2637 call writefile([], 'Xdir1/file1_2.txt') 2638 call writefile([], 'Xdir1/dir2/file2_1.txt') 2639 call writefile([], 'Xdir1/dir2/file2_2.txt') 2640 call writefile([], 'Xdir1/dir2/dir3/file3_1.txt') 2641 call writefile([], 'Xdir1/dir2/dir3/file3_2.txt') 2642 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt') 2643 call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt') 2644 set wildmenu 2645 2646 cd Xdir1/dir2/dir3/dir4 2647 call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt') 2648 call assert_equal('"e file4_1.txt', @:) 2649 call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt') 2650 call assert_equal('"e ../dir4/', @:) 2651 call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') 2652 call assert_equal('"e ../../dir3/', @:) 2653 call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') 2654 call assert_equal('"e ../../../dir2/', @:) 2655 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt') 2656 call assert_equal('"e ../../dir3/dir4/', @:) 2657 call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') 2658 call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:) 2659 cd - 2660 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') 2661 call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:) 2662 2663 call delete('Xdir1', 'rf') 2664 set wildmenu& 2665 endfunc 2666 2667 " Test for recalling newer or older cmdline from history with <Up>, <Down>, 2668 " <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or 2669 " <C-n>. 2670 func Test_recalling_cmdline() 2671 CheckFeature cmdline_hist 2672 2673 let g:cmdlines = [] 2674 cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR> 2675 2676 let histories = [ 2677 \ #{name: 'cmd', enter: ':', exit: "\<Esc>"}, 2678 \ #{name: 'search', enter: '/', exit: "\<Esc>"}, 2679 \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"}, 2680 \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"}, 2681 "\ TODO: {'name': 'debug', ...} 2682 \] 2683 let keypairs = [ 2684 \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true}, 2685 \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false}, 2686 \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false}, 2687 \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false}, 2688 \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false}, 2689 \] 2690 let prefix = 'vi' 2691 for h in histories 2692 call histadd(h.name, 'vim') 2693 call histadd(h.name, 'virtue') 2694 call histadd(h.name, 'Virgo') 2695 call histadd(h.name, 'vogue') 2696 call histadd(h.name, 'emacs') 2697 for k in keypairs 2698 let g:cmdlines = [] 2699 let keyseqs = h.enter 2700 \ .. prefix 2701 \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2) 2702 \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2) 2703 \ .. h.exit 2704 call feedkeys(keyseqs, 'xt') 2705 call histdel(h.name, -1) " delete the history added by feedkeys above 2706 let expect = k.prefixmatch 2707 \ ? ['virtue', 'vim', 'virtue', prefix] 2708 \ : ['emacs', 'vogue', 'emacs', prefix] 2709 call assert_equal(expect, g:cmdlines) 2710 endfor 2711 endfor 2712 2713 unlet g:cmdlines 2714 cunmap <Plug>(save-cmdline) 2715 endfunc 2716 2717 func Test_recalling_cmdline_with_mappings() 2718 CheckFeature cmdline_hist 2719 2720 cnoremap <F2> <Cmd>let g:cmdline = getcmdline()<CR> 2721 cnoremap <CR> <CR> 2722 cnoremap <Up> <Up> 2723 let save_a = ['a', getreg('a'), getregtype('a')] 2724 2725 call feedkeys(":echo 'foo'\<CR>", 'tx') 2726 call assert_equal("echo 'foo'", @:) 2727 call feedkeys(":echo 'bar'\<CR>", 'tx') 2728 call assert_equal("echo 'bar'", @:) 2729 2730 call assert_equal("echo 'bar'", histget(':', -1)) 2731 call assert_equal("echo 'foo'", histget(':', -2)) 2732 2733 let g:cmdline = '' 2734 " This command comes completely from a mapping. 2735 nmap <F3> :echo 'baz'<F2><CR> 2736 call feedkeys("\<F3>", 'tx') 2737 call assert_equal('baz', Screenline(&lines)->trim()) 2738 call assert_equal("echo 'baz'", g:cmdline) 2739 call assert_equal("echo 'bar'", @:) 2740 call assert_equal("echo 'bar'", histget(':', -1)) 2741 call assert_equal("echo 'foo'", histget(':', -2)) 2742 2743 let g:cmdline = '' 2744 " A command coming from :normal is ignored in the history even if the keys 2745 " don't explicitly leave Cmdline mode. 2746 exe "normal :echo 'baz'\<F2>" 2747 call assert_equal("echo 'baz'", g:cmdline) 2748 call assert_equal("echo 'bar'", @:) 2749 call assert_equal("echo 'bar'", histget(':', -1)) 2750 call assert_equal("echo 'foo'", histget(':', -2)) 2751 2752 if has('unix') 2753 new 2754 call setline(1, ['aaa']) 2755 setlocal formatprg=cat 2756 " Formatting with non-typed "gq" should not change cmdline history. 2757 normal! gqgq 2758 call assert_equal(":.!cat", Screenline(&lines)->trim()) 2759 call assert_equal("echo 'bar'", @:) 2760 call assert_equal("echo 'bar'", histget(':', -1)) 2761 call assert_equal("echo 'foo'", histget(':', -2)) 2762 bwipe! 2763 endif 2764 2765 " This case can still be considered a typed command. 2766 call timer_start(1, {-> feedkeys("\<CR>", 't')}) 2767 call feedkeys(":\<Up>\<Up>", 'tx!') 2768 call assert_equal('foo', Screenline(&lines)->trim()) 2769 call assert_equal("echo 'foo'", @:) 2770 call assert_equal("echo 'foo'", histget(':', -1)) 2771 call assert_equal("echo 'bar'", histget(':', -2)) 2772 2773 call feedkeys(":\<Up>\<F2>\<Esc>", 'tx') 2774 call assert_equal("echo 'foo'", g:cmdline) 2775 call assert_equal("echo 'foo'", @:) 2776 2777 " A command from an executed register is also ignored in the history. 2778 call feedkeys(':let @a=":echo ''zzz''\<cr>"' .. "\<CR>", 'tx') 2779 call feedkeys(":norm @a\<cr>", 'tx') 2780 call assert_equal('zzz', Screenline(&lines)->trim()) 2781 call assert_equal('norm @a', @:) 2782 call assert_equal('norm @a', histget(':', -1)) 2783 call assert_equal('let @a=":echo ''zzz''\<cr>"', histget(':', -2)) 2784 call assert_equal("echo 'foo'", histget(':', -3)) 2785 call assert_equal("echo 'bar'", histget(':', -4)) 2786 2787 unlet g:cmdline 2788 call call('setreg', save_a) 2789 cunmap <F2> 2790 cunmap <CR> 2791 cunmap <Up> 2792 nunmap <F3> 2793 endfunc 2794 2795 func Test_cmd_map_cmdlineChanged() 2796 let g:log = [] 2797 cnoremap <F1> l<Cmd><CR>s 2798 augroup test_CmdlineChanged 2799 autocmd! 2800 autocmd CmdlineChanged : let g:log += [getcmdline()] 2801 augroup END 2802 2803 call feedkeys(":\<F1>\<CR>", 'xt') 2804 call assert_equal(['l', 'ls'], g:log) 2805 2806 let @b = 'b' 2807 cnoremap <F1> a<C-R>b 2808 let g:log = [] 2809 call feedkeys(":\<F1>\<CR>", 'xt') 2810 call assert_equal(['a', 'ab'], g:log) 2811 2812 unlet g:log 2813 cunmap <F1> 2814 augroup test_CmdlineChanged 2815 autocmd! 2816 augroup END 2817 augroup! test_CmdlineChanged 2818 endfunc 2819 2820 " Test for the 'suffixes' option 2821 func Test_suffixes_opt() 2822 call writefile([], 'Xsuffile') 2823 call writefile([], 'Xsuffile.c') 2824 call writefile([], 'Xsuffile.o') 2825 set suffixes= 2826 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') 2827 call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:) 2828 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 2829 call assert_equal('"e Xsuffile.c', @:) 2830 set suffixes=.c 2831 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') 2832 call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:) 2833 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 2834 call assert_equal('"e Xsuffile.o', @:) 2835 set suffixes=,, 2836 call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') 2837 call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:) 2838 call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 2839 call assert_equal('"e Xsuffile.o', @:) 2840 set suffixes& 2841 " Test for getcompletion() with different patterns 2842 call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file')) 2843 call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file')) 2844 call delete('Xsuffile') 2845 call delete('Xsuffile.c') 2846 call delete('Xsuffile.o') 2847 endfunc 2848 2849 " Test for using a popup menu for the command line completion matches 2850 " (wildoptions=pum) 2851 func Test_wildmenu_pum() 2852 CheckScreendump 2853 CheckRunVimInTerminal 2854 2855 let commands =<< trim [CODE] 2856 set wildmenu 2857 set wildoptions=pum 2858 set shm+=I 2859 set noruler 2860 set noshowcmd 2861 2862 func CmdCompl(a, b, c) 2863 return repeat(['aaaa'], 120) 2864 endfunc 2865 command -nargs=* -complete=customlist,CmdCompl Tcmd 2866 2867 func MyStatusLine() abort 2868 return 'status' 2869 endfunc 2870 func SetupStatusline() 2871 set statusline=%!MyStatusLine() 2872 set laststatus=2 2873 endfunc 2874 2875 func MyTabLine() 2876 return 'my tab line' 2877 endfunc 2878 func SetupTabline() 2879 set statusline= 2880 set tabline=%!MyTabLine() 2881 set showtabline=2 2882 endfunc 2883 2884 func DoFeedKeys() 2885 let &wildcharm = char2nr("\t") 2886 call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>") 2887 endfunc 2888 [CODE] 2889 call writefile(commands, 'Xtest', 'D') 2890 2891 let buf = RunVimInTerminal('-S Xtest', #{rows: 10}) 2892 2893 call term_sendkeys(buf, ":sign \<Tab>") 2894 call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {}) 2895 2896 " going down the popup menu using <Down> 2897 call term_sendkeys(buf, "\<Down>\<Down>") 2898 call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {}) 2899 2900 " going down the popup menu using <C-N> 2901 call term_sendkeys(buf, "\<C-N>") 2902 call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {}) 2903 2904 " going up the popup menu using <C-P> 2905 call term_sendkeys(buf, "\<C-P>") 2906 call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {}) 2907 2908 " going up the popup menu using <Up> 2909 call term_sendkeys(buf, "\<Up>") 2910 call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {}) 2911 2912 " pressing <C-E> should end completion and go back to the original match 2913 call term_sendkeys(buf, "\<C-E>") 2914 call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {}) 2915 2916 " pressing <C-Y> should select the current match and end completion 2917 call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>") 2918 call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {}) 2919 2920 " With 'wildmode' set to 'longest,full', completing a match should display 2921 " the longest match, the wildmenu should not be displayed. 2922 call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>") 2923 call TermWait(buf) 2924 call term_sendkeys(buf, ":sign u\<Tab>") 2925 call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {}) 2926 2927 " pressing <Tab> should display the wildmenu 2928 call term_sendkeys(buf, "\<Tab>") 2929 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {}) 2930 2931 " pressing <Tab> second time should select the next entry in the menu 2932 call term_sendkeys(buf, "\<Tab>") 2933 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {}) 2934 2935 call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>") 2936 " showing popup menu in different columns in the cmdline 2937 call term_sendkeys(buf, ":sign define \<Tab>") 2938 call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {}) 2939 2940 call term_sendkeys(buf, " \<Tab>") 2941 call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {}) 2942 2943 call term_sendkeys(buf, " \<Tab>") 2944 call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {}) 2945 2946 " Directory name completion 2947 call mkdir('Xnamedir/XdirA/XdirB', 'pR') 2948 call writefile([], 'Xnamedir/XfileA') 2949 call writefile([], 'Xnamedir/XdirA/XfileB') 2950 call writefile([], 'Xnamedir/XdirA/XdirB/XfileC') 2951 2952 call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>") 2953 call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {}) 2954 2955 " Pressing <Right> on a directory name should go into that directory 2956 call term_sendkeys(buf, "\<Right>") 2957 call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {}) 2958 2959 " Pressing <Left> on a directory name should go to the parent directory 2960 call term_sendkeys(buf, "\<Left>") 2961 call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {}) 2962 2963 " Pressing <C-A> when the popup menu is displayed should list all the 2964 " matches but the popup menu should still remain 2965 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>") 2966 call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {}) 2967 2968 " Pressing <C-D> when the popup menu is displayed should remove the popup 2969 " menu 2970 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>") 2971 call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {}) 2972 2973 " Pressing <S-Tab> should open the popup menu with the last entry selected 2974 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>") 2975 call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {}) 2976 2977 " Pressing <Esc> should close the popup menu and cancel the cmd line 2978 call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>") 2979 call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {}) 2980 2981 " Typing a character when the popup is open, should close the popup 2982 call term_sendkeys(buf, ":sign \<Tab>x") 2983 call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {}) 2984 2985 " When the popup is open, entering the cmdline window should close the popup 2986 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>") 2987 call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {}) 2988 call term_sendkeys(buf, ":q\<CR>") 2989 2990 " After the last popup menu item, <C-N> should show the original string 2991 call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>") 2992 call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {}) 2993 2994 " Use the popup menu for the command name 2995 call term_sendkeys(buf, "\<C-U>bu\<Tab>") 2996 call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {}) 2997 2998 " Pressing the left arrow should remove the popup menu 2999 call term_sendkeys(buf, "\<Left>\<Left>") 3000 call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {}) 3001 3002 " Pressing <BS> should remove the popup menu and erase the last character 3003 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>") 3004 call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {}) 3005 3006 " Pressing <C-W> should remove the popup menu and erase the previous word 3007 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>") 3008 call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {}) 3009 3010 " Pressing <C-U> should remove the popup menu and erase the entire line 3011 call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>") 3012 call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {}) 3013 3014 " Using <C-E> to cancel the popup menu and then pressing <Up> should recall 3015 " the cmdline from history 3016 call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>") 3017 call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {}) 3018 3019 " Check that when "longest" produces no result, "list" works 3020 call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>") 3021 call term_sendkeys(buf, ":cn\<Tab>") 3022 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {}) 3023 call term_sendkeys(buf, "\<Tab>") 3024 call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {}) 3025 call term_sendkeys(buf, "s") 3026 call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {}) 3027 3028 " Tests a directory name contained full-width characters. 3029 call mkdir('Xnamedir/あいう', 'p') 3030 call writefile([], 'Xnamedir/あいう/abc') 3031 call writefile([], 'Xnamedir/あいう/xyz') 3032 call writefile([], 'Xnamedir/あいう/123') 3033 3034 call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>") 3035 call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>") 3036 call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {}) 3037 3038 " Pressing <C-A> when the popup menu is displayed should list all the 3039 " matches and pressing a key after that should remove the popup menu 3040 call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>") 3041 call term_sendkeys(buf, ":sign \<Tab>\<C-A>x") 3042 call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {}) 3043 3044 " Pressing <C-A> when the popup menu is displayed should list all the 3045 " matches and pressing <Left> after that should move the cursor 3046 call term_sendkeys(buf, "\<C-U>abc\<Esc>") 3047 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>") 3048 call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {}) 3049 3050 " When <C-A> displays a lot of matches (screen scrolls), all the matches 3051 " should be displayed correctly on the screen. 3052 call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>") 3053 call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {}) 3054 3055 " After using <C-A> to expand all the filename matches, pressing <Up> 3056 " should not open the popup menu again. 3057 call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>") 3058 call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>") 3059 call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {}) 3060 call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>") 3061 3062 " After using <C-A> to expand all the matches, pressing <S-Tab> used to 3063 " crash Vim 3064 call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>") 3065 call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {}) 3066 3067 " After removing the pum the command line is redrawn 3068 call term_sendkeys(buf, ":edit foo\<CR>") 3069 call term_sendkeys(buf, ":edit bar\<CR>") 3070 call term_sendkeys(buf, ":ls\<CR>") 3071 call term_sendkeys(buf, ":com\<Tab> ") 3072 call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {}) 3073 call term_sendkeys(buf, "\<C-U>\<CR>") 3074 3075 " Esc still works to abort the command when 'statusline' is set 3076 call term_sendkeys(buf, ":call SetupStatusline()\<CR>") 3077 call term_sendkeys(buf, ":si\<Tab>") 3078 call term_sendkeys(buf, "\<Esc>") 3079 call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {}) 3080 3081 " Esc still works to abort the command when 'tabline' is set 3082 call term_sendkeys(buf, ":call SetupTabline()\<CR>") 3083 call term_sendkeys(buf, ":si\<Tab>") 3084 call term_sendkeys(buf, "\<Esc>") 3085 call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {}) 3086 3087 " popup is cleared also when 'lazyredraw' is set 3088 call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>") 3089 call term_sendkeys(buf, ":call DoFeedKeys()\<CR>") 3090 call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {}) 3091 call term_sendkeys(buf, "\<Esc>") 3092 3093 " Pressing <PageDown> should scroll the menu downward 3094 call term_sendkeys(buf, ":sign \<Tab>\<PageDown>") 3095 call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {}) 3096 call term_sendkeys(buf, "\<PageDown>") 3097 call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {}) 3098 call term_sendkeys(buf, "\<PageDown>") 3099 call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {}) 3100 call term_sendkeys(buf, "\<PageDown>") 3101 call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {}) 3102 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>") 3103 call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {}) 3104 3105 " Pressing <PageUp> should scroll the menu upward 3106 call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>") 3107 call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {}) 3108 call term_sendkeys(buf, "\<PageUp>") 3109 call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {}) 3110 call term_sendkeys(buf, "\<PageUp>") 3111 call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {}) 3112 call term_sendkeys(buf, "\<PageUp>") 3113 call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {}) 3114 3115 " pressing <C-E> to end completion should work in middle of the line too 3116 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>") 3117 call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {}) 3118 call term_sendkeys(buf, "\<C-E>") 3119 call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {}) 3120 3121 " pressing <C-Y> should select the current match and end completion 3122 call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>") 3123 call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {}) 3124 3125 call term_sendkeys(buf, "\<Esc>:set showtabline& laststatus& lazyredraw&\<CR>") 3126 3127 " "longest:list" shows list whether it finds a candidate or not 3128 call term_sendkeys(buf, ":set wildmode=longest:list,full wildoptions&\<CR>") 3129 call term_sendkeys(buf, ":cn\<Tab>") 3130 call TermWait(buf, 50) 3131 call VerifyScreenDump(buf, 'Test_wildmenu_pum_55', {}) 3132 call term_sendkeys(buf, "\<Tab>") 3133 call TermWait(buf, 50) 3134 call VerifyScreenDump(buf, 'Test_wildmenu_pum_56', {}) 3135 call term_sendkeys(buf, "\<Esc>:sign u\<Tab>") 3136 call TermWait(buf, 50) 3137 call VerifyScreenDump(buf, 'Test_wildmenu_pum_57', {}) 3138 3139 " "longest:full" shows wildmenu whether it finds a candidate or not; item not selected 3140 call term_sendkeys(buf, "\<Esc>:set wildmode=longest:full,full\<CR>") 3141 call term_sendkeys(buf, ":sign u\<Tab>") 3142 call TermWait(buf, 50) 3143 call VerifyScreenDump(buf, 'Test_wildmenu_pum_58', {}) 3144 call term_sendkeys(buf, "\<Tab>") 3145 call TermWait(buf, 50) 3146 call VerifyScreenDump(buf, 'Test_wildmenu_pum_59', {}) 3147 call term_sendkeys(buf, "\<Esc>:cn\<Tab>") 3148 call TermWait(buf, 50) 3149 call VerifyScreenDump(buf, 'Test_wildmenu_pum_60', {}) 3150 call term_sendkeys(buf, "\<Tab>") 3151 call TermWait(buf, 50) 3152 call VerifyScreenDump(buf, 'Test_wildmenu_pum_61', {}) 3153 3154 " If "longest,full" finds a candidate, wildmenu is not shown 3155 call term_sendkeys(buf, "\<Esc>:set wildmode=longest,full\<CR>") 3156 call term_sendkeys(buf, ":sign u\<Tab>") 3157 call VerifyScreenDump(buf, 'Test_wildmenu_pum_62', {}) 3158 " Subsequent wildchar shows wildmenu 3159 call term_sendkeys(buf, "\<Tab>") 3160 call VerifyScreenDump(buf, 'Test_wildmenu_pum_63', {}) 3161 3162 " 'longest' does not find candidate, and displays menu without selecting item 3163 call term_sendkeys(buf, "\<Esc>:set wildmode=longest,noselect\<CR>") 3164 call term_sendkeys(buf, ":cn\<Tab>") 3165 call VerifyScreenDump(buf, 'Test_wildmenu_pum_64', {}) 3166 3167 " If "longest" finds no candidate in "longest,full", "full" is used 3168 call term_sendkeys(buf, "\<Esc>:set wildmode=longest,full\<CR>") 3169 call term_sendkeys(buf, ":set wildoptions=pum\<CR>") 3170 call term_sendkeys(buf, ":sign un\<Tab>") 3171 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {}) 3172 call term_sendkeys(buf, "\<Tab>") 3173 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {}) 3174 3175 " Similarly for "longest,noselect:full" 3176 call term_sendkeys(buf, "\<Esc>:set wildmode=longest,noselect:full\<CR>") 3177 call term_sendkeys(buf, ":sign un\<Tab>") 3178 call VerifyScreenDump(buf, 'Test_wildmenu_pum_65', {}) 3179 call term_sendkeys(buf, "\<Tab>") 3180 call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {}) 3181 call term_sendkeys(buf, "\<Tab>") 3182 call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {}) 3183 3184 call term_sendkeys(buf, "\<C-U>\<Esc>") 3185 call StopVimInTerminal(buf) 3186 endfunc 3187 3188 " Test for wildmenumode() with the cmdline popup menu 3189 func Test_wildmenumode_with_pum() 3190 set wildmenu 3191 set wildoptions=pum 3192 cnoremap <expr> <F2> wildmenumode() 3193 call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt') 3194 call assert_equal('"sign define10', @:) 3195 call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt') 3196 call assert_equal('"sign define jump list place undefine unplace0', @:) 3197 call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt') 3198 call assert_equal('"sign 0', @:) 3199 call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt') 3200 call assert_equal('"sign define0', @:) 3201 set nowildmenu wildoptions& 3202 cunmap <F2> 3203 endfunc 3204 3205 func Test_wildmenu_with_pum_foldexpr() 3206 CheckScreendump 3207 CheckRunVimInTerminal 3208 3209 let lines =<< trim END 3210 call setline(1, ['folded one', 'folded two', 'some more text']) 3211 func MyFoldText() 3212 return 'foo' 3213 endfunc 3214 set foldtext=MyFoldText() wildoptions=pum 3215 normal ggzfj 3216 END 3217 call writefile(lines, 'Xpumfold') 3218 let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10}) 3219 call term_sendkeys(buf, ":set\<Tab>") 3220 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {}) 3221 3222 call term_sendkeys(buf, "\<Esc>") 3223 call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {}) 3224 3225 call StopVimInTerminal(buf) 3226 call delete('Xpumfold') 3227 endfunc 3228 3229 " Test for opening the cmdline completion popup menu from the terminal window. 3230 " The popup menu should be positioned correctly over the status line of the 3231 " bottom-most window. 3232 func Test_wildmenu_pum_from_terminal() 3233 CheckScreendump 3234 CheckRunVimInTerminal 3235 let python = PythonProg() 3236 call CheckPython(python) 3237 3238 %bw! 3239 let cmds = ['set wildmenu wildoptions=pum'] 3240 let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"' 3241 call add(cmds, "call term_start('" .. pcmd .. "')") 3242 call writefile(cmds, 'Xtest', 'D') 3243 let buf = RunVimInTerminal('-S Xtest', #{rows: 10}) 3244 call term_sendkeys(buf, "\r\r\r") 3245 call term_wait(buf) 3246 call term_sendkeys(buf, "\<C-W>:sign \<Tab>") 3247 call term_wait(buf) 3248 call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {}) 3249 call term_wait(buf) 3250 call StopVimInTerminal(buf) 3251 endfunc 3252 3253 func Test_wildmenu_pum_odd_wildchar() 3254 CheckScreendump 3255 CheckRunVimInTerminal 3256 3257 " Test odd wildchar interactions with pum. Make sure they behave properly 3258 " and don't lead to memory corruption due to improperly cleaned up memory. 3259 let lines =<< trim END 3260 set wildoptions=pum 3261 set wildchar=<C-E> 3262 END 3263 call writefile(lines, 'XwildmenuTest', 'D') 3264 let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10}) 3265 3266 call term_sendkeys(buf, ":\<C-E>") 3267 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) 3268 3269 " <C-E> being a wildchar takes priority over its original functionality 3270 call term_sendkeys(buf, "\<C-E>") 3271 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {}) 3272 3273 call term_sendkeys(buf, "\<Esc>") 3274 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) 3275 3276 " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape 3277 " command-line, and we need to make sure to clean up properly. 3278 call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>") 3279 call term_sendkeys(buf, ":\<Esc>") 3280 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) 3281 3282 call term_sendkeys(buf, "\<Esc>") 3283 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) 3284 3285 " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline 3286 " and we again need to make sure we clean up properly. 3287 call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>") 3288 call term_sendkeys(buf, ":\<C-\>\<C-\>") 3289 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) 3290 3291 call term_sendkeys(buf, "\<C-N>") 3292 call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) 3293 3294 call StopVimInTerminal(buf) 3295 endfunc 3296 3297 " Test that 'rightleft' should not affect cmdline completion popup menu. 3298 func Test_wildmenu_pum_rightleft() 3299 CheckFeature rightleft 3300 CheckScreendump 3301 3302 let lines =<< trim END 3303 set wildoptions=pum 3304 set rightleft 3305 END 3306 call writefile(lines, 'Xwildmenu_pum_rl', 'D') 3307 let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50}) 3308 3309 call term_sendkeys(buf, ":sign \<Tab>") 3310 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {}) 3311 3312 " Behavior is the same when using 'keymap'. 3313 call term_sendkeys(buf, "\<Esc>:set keymap=dvorak\<CR>") 3314 call TermWait(buf) 3315 " ";gul" -> "sign" when using Dvorak keymap. 3316 call term_sendkeys(buf, ":\<C-^>;gul \<Tab>") 3317 call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {}) 3318 call term_sendkeys(buf, "\<Esc>:set keymap&\<CR>") 3319 3320 call StopVimInTerminal(buf) 3321 endfunc 3322 3323 " Test highlighting when pattern matches non-first character of item 3324 func Test_wildmenu_pum_hl_nonfirst() 3325 CheckScreendump 3326 let lines =<< trim END 3327 set wildoptions=pum wildchar=<tab> wildmode=noselect,full 3328 hi PmenuMatchSel ctermfg=6 ctermbg=7 3329 hi PmenuMatch ctermfg=4 ctermbg=225 3330 func T(a, c, p) 3331 return ["oneA", "o neBneB", "aoneC"] 3332 endfunc 3333 command -nargs=1 -complete=customlist,T MyCmd 3334 END 3335 3336 call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D') 3337 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50}) 3338 3339 call term_sendkeys(buf, ":MyCmd ne\<tab>") 3340 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {}) 3341 call term_sendkeys(buf, "\<Esc>") 3342 call StopVimInTerminal(buf) 3343 endfunc 3344 3345 " Test highlighting matched text in cmdline completion popup menu. 3346 func Test_wildmenu_pum_hl_match() 3347 CheckScreendump 3348 3349 let lines =<< trim END 3350 set wildoptions=pum,fuzzy 3351 hi PmenuMatchSel ctermfg=6 ctermbg=7 3352 hi PmenuMatch ctermfg=4 ctermbg=225 3353 END 3354 call writefile(lines, 'Xwildmenu_pum_hl', 'D') 3355 let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50}) 3356 3357 call term_sendkeys(buf, ":sign plc\<Tab>") 3358 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {}) 3359 call term_sendkeys(buf, "\<Tab>") 3360 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {}) 3361 call term_sendkeys(buf, "\<Tab>") 3362 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {}) 3363 call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>") 3364 call TermWait(buf) 3365 call term_sendkeys(buf, ":sign un\<Tab>") 3366 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {}) 3367 call term_sendkeys(buf, "\<Tab>") 3368 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {}) 3369 call term_sendkeys(buf, "\<Tab>") 3370 call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {}) 3371 call term_sendkeys(buf, "\<Esc>") 3372 3373 call StopVimInTerminal(buf) 3374 endfunc 3375 3376 " Test for completion after a :substitute command followed by a pipe (|) 3377 " character 3378 func Test_cmdline_complete_substitute() 3379 set wildchar=0 3380 call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt') 3381 call assert_equal("\"s | \t", @:) 3382 call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt') 3383 call assert_equal("\"s/ | \t", @:) 3384 call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt') 3385 call assert_equal("\"s/one | \t", @:) 3386 set wildchar& 3387 call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt') 3388 call assert_equal("\"s/one/ | \t", @:) 3389 call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt') 3390 call assert_equal("\"s/one/two | \t", @:) 3391 call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt') 3392 call assert_equal('"s/one/two/ | chistory', @:) 3393 call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt') 3394 call assert_equal("\"s/one/two/g \t", @:) 3395 call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt') 3396 call assert_equal("\"s/one/two/g | chistory", @:) 3397 call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt') 3398 call assert_equal("\"s/one/t\\/ | \t", @:) 3399 call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt') 3400 call assert_equal('"s/one/t"o/ | chistory', @:) 3401 call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt') 3402 call assert_equal('"s/one/t|o/ | chistory', @:) 3403 call feedkeys(":&\t\<C-B>\"\<CR>", 'xt') 3404 call assert_equal("\"&\t", @:) 3405 endfunc 3406 3407 " Test for the :dlist command completion 3408 func Test_cmdline_complete_dlist() 3409 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') 3410 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) 3411 call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt') 3412 call assert_equal("\"dlist 10 /pat/ \t", @:) 3413 call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt') 3414 call assert_equal("\"dlist 10 /pa\\t/\t", @:) 3415 call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt') 3416 call assert_equal("\"dlist 10 /pat\\\t", @:) 3417 call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt') 3418 call assert_equal("\"dlist 10 /pat/ | chistory", @:) 3419 endfunc 3420 3421 " argument list (only for :argdel) fuzzy completion 3422 func Test_fuzzy_completion_arglist() 3423 argadd change.py count.py charge.py 3424 set wildoptions& 3425 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx') 3426 call assert_equal('"argdel cge', @:) 3427 set wildoptions=fuzzy 3428 call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx') 3429 call assert_equal('"argdel change.py charge.py', @:) 3430 %argdelete 3431 set wildoptions& 3432 endfunc 3433 3434 " autocmd group name fuzzy completion 3435 func Test_fuzzy_completion_autocmd() 3436 set wildoptions& 3437 augroup MyFuzzyGroup 3438 augroup END 3439 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx') 3440 call assert_equal('"augroup mfg', @:) 3441 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx') 3442 call assert_equal('"augroup MyFuzzyGroup', @:) 3443 set wildoptions=fuzzy 3444 call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx') 3445 call assert_equal('"augroup MyFuzzyGroup', @:) 3446 call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx') 3447 call assert_equal('"augroup My*p', @:) 3448 augroup! MyFuzzyGroup 3449 set wildoptions& 3450 endfunc 3451 3452 " buffer name fuzzy completion 3453 func Test_fuzzy_completion_bufname() 3454 set wildoptions& 3455 " Use a long name to reduce the risk of matching a random directory name 3456 edit SomeRandomFileWithLetters.txt 3457 enew 3458 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') 3459 call assert_equal('"b SRFWL', @:) 3460 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') 3461 call assert_equal('"b SomeRandomFileWithLetters.txt', @:) 3462 set wildoptions=fuzzy 3463 call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') 3464 call assert_equal('"b SomeRandomFileWithLetters.txt', @:) 3465 call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') 3466 call assert_equal('"b S*FileWithLetters.txt', @:) 3467 %bw! 3468 set wildoptions& 3469 endfunc 3470 3471 " buffer name (full path) fuzzy completion 3472 func Test_fuzzy_completion_bufname_fullpath() 3473 CheckUnix 3474 set wildoptions& 3475 call mkdir('Xcmd/Xstate/Xfile.js', 'pR') 3476 edit Xcmd/Xstate/Xfile.js 3477 cd Xcmd/Xstate 3478 enew 3479 call feedkeys(":b cmdstatefile\<Tab>\<C-B>\"\<CR>", 'tx') 3480 call assert_equal('"b cmdstatefile', @:) 3481 set wildoptions=fuzzy 3482 call feedkeys(":b cmdstatefile\<Tab>\<C-B>\"\<CR>", 'tx') 3483 call assert_match('Xcmd/Xstate/Xfile.js$', @:) 3484 cd - 3485 set wildoptions& 3486 endfunc 3487 3488 " :behave suboptions fuzzy completion 3489 func Test_fuzzy_completion_behave() 3490 throw 'Skipped: Nvim removed :behave' 3491 set wildoptions& 3492 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx') 3493 call assert_equal('"behave xm', @:) 3494 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx') 3495 call assert_equal('"behave xterm', @:) 3496 set wildoptions=fuzzy 3497 call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx') 3498 call assert_equal('"behave xterm', @:) 3499 call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx') 3500 call assert_equal('"behave xt*m', @:) 3501 let g:Sline = '' 3502 call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx') 3503 call assert_equal('mswin', g:Sline) 3504 call assert_equal('"behave win', @:) 3505 set wildoptions& 3506 endfunc 3507 3508 " :filetype suboptions completion 3509 func Test_completion_filetypecmd() 3510 set wildoptions& 3511 call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx') 3512 call assert_equal('"filetype indent off on plugin', @:) 3513 call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx') 3514 call assert_equal('"filetype plugin indent off on', @:) 3515 call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx') 3516 call assert_equal('"filetype indent off on plugin', @:) 3517 call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx') 3518 call assert_equal('"filetype indent', @:) 3519 call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx') 3520 call assert_equal('"filetype plugin', @:) 3521 call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx') 3522 call assert_equal('"filetype off on', @:) 3523 call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx') 3524 call assert_equal('"filetype indent off', @:) 3525 set wildoptions& 3526 endfunc 3527 3528 " " colorscheme name fuzzy completion - NOT supported 3529 " func Test_fuzzy_completion_colorscheme() 3530 " endfunc 3531 3532 " built-in command name fuzzy completion 3533 func Test_fuzzy_completion_cmdname() 3534 set wildoptions& 3535 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx') 3536 call assert_equal('"sbwin', @:) 3537 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx') 3538 call assert_equal('"sbrewind', @:) 3539 set wildoptions=fuzzy 3540 call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx') 3541 call assert_equal('"sbrewind', @:) 3542 call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx') 3543 call assert_equal('"sbr*d', @:) 3544 set wildoptions& 3545 endfunc 3546 3547 " " compiler name fuzzy completion - NOT supported 3548 " func Test_fuzzy_completion_compiler() 3549 " endfunc 3550 3551 " :cscope suboptions fuzzy completion 3552 func Test_fuzzy_completion_cscope() 3553 CheckFeature cscope 3554 set wildoptions& 3555 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx') 3556 call assert_equal('"cscope ret', @:) 3557 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx') 3558 call assert_equal('"cscope reset', @:) 3559 set wildoptions=fuzzy 3560 call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx') 3561 call assert_equal('"cscope reset', @:) 3562 call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx') 3563 call assert_equal('"cscope re*t', @:) 3564 set wildoptions& 3565 endfunc 3566 3567 " :diffget/:diffput buffer name fuzzy completion 3568 func Test_fuzzy_completion_diff() 3569 new SomeBuffer 3570 diffthis 3571 new OtherBuffer 3572 diffthis 3573 set wildoptions& 3574 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx') 3575 call assert_equal('"diffget sbuf', @:) 3576 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx') 3577 call assert_equal('"diffput sbuf', @:) 3578 set wildoptions=fuzzy 3579 call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx') 3580 call assert_equal('"diffget SomeBuffer', @:) 3581 call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx') 3582 call assert_equal('"diffput SomeBuffer', @:) 3583 %bw! 3584 set wildoptions& 3585 endfunc 3586 3587 " " directory name fuzzy completion - NOT supported 3588 " func Test_fuzzy_completion_dirname() 3589 " endfunc 3590 3591 " environment variable name fuzzy completion 3592 func Test_fuzzy_completion_env() 3593 set wildoptions& 3594 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx') 3595 call assert_equal('"echo $VUT', @:) 3596 set wildoptions=fuzzy 3597 call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx') 3598 call assert_equal('"echo $VIMRUNTIME', @:) 3599 set wildoptions& 3600 endfunc 3601 3602 " autocmd event fuzzy completion 3603 func Test_fuzzy_completion_autocmd_event() 3604 set wildoptions& 3605 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx') 3606 call assert_equal('"autocmd BWout', @:) 3607 set wildoptions=fuzzy 3608 call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx') 3609 call assert_equal('"autocmd BufWipeout', @:) 3610 set wildoptions& 3611 endfunc 3612 3613 " vim expression fuzzy completion 3614 func Test_fuzzy_completion_expr() 3615 let g:PerPlaceCount = 10 3616 set wildoptions& 3617 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx') 3618 call assert_equal('"let c = ppc', @:) 3619 set wildoptions=fuzzy 3620 call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx') 3621 call assert_equal('"let c = PerPlaceCount', @:) 3622 set wildoptions& 3623 endfunc 3624 3625 " " file name fuzzy completion - NOT supported 3626 " func Test_fuzzy_completion_filename() 3627 " endfunc 3628 3629 " " files in path fuzzy completion - NOT supported 3630 " func Test_fuzzy_completion_filesinpath() 3631 " endfunc 3632 3633 " " filetype name fuzzy completion - NOT supported 3634 " func Test_fuzzy_completion_filetype() 3635 " endfunc 3636 3637 " user defined function name completion 3638 func Test_fuzzy_completion_userdefined_func() 3639 set wildoptions& 3640 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx') 3641 call assert_equal('"call Test_f_u_f', @:) 3642 set wildoptions=fuzzy 3643 call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx') 3644 call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:) 3645 set wildoptions& 3646 endfunc 3647 3648 " <SNR> functions should be sorted to the end 3649 func Test_fuzzy_completion_userdefined_snr_func() 3650 func s:Sendmail() 3651 endfunc 3652 func SendSomemail() 3653 endfunc 3654 func S1e2n3dmail() 3655 endfunc 3656 set wildoptions=fuzzy 3657 call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx') 3658 call assert_equal('"call SendSomemail() S1e2n3dmail() ' 3659 \ .. expand("<SID>") .. 'Sendmail()', @:) 3660 set wildoptions& 3661 delfunc s:Sendmail 3662 delfunc SendSomemail 3663 delfunc S1e2n3dmail 3664 endfunc 3665 3666 " user defined command name completion 3667 func Test_fuzzy_completion_userdefined_cmd() 3668 set wildoptions& 3669 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx') 3670 call assert_equal('"MsFeat', @:) 3671 set wildoptions=fuzzy 3672 call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx') 3673 call assert_equal('"MissingFeature', @:) 3674 set wildoptions& 3675 endfunc 3676 3677 " " :help tag fuzzy completion - NOT supported 3678 " func Test_fuzzy_completion_helptag() 3679 " endfunc 3680 3681 " highlight group name fuzzy completion 3682 func Test_fuzzy_completion_hlgroup() 3683 set wildoptions& 3684 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx') 3685 call assert_equal('"highlight SKey', @:) 3686 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx') 3687 call assert_equal('"highlight SpecialKey', @:) 3688 set wildoptions=fuzzy 3689 call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx') 3690 call assert_equal('"highlight SpecialKey', @:) 3691 call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx') 3692 call assert_equal('"highlight Sp*Key', @:) 3693 set wildoptions& 3694 endfunc 3695 3696 " :history suboptions fuzzy completion 3697 func Test_fuzzy_completion_history() 3698 set wildoptions& 3699 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx') 3700 call assert_equal('"history dg', @:) 3701 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx') 3702 call assert_equal('"history search', @:) 3703 set wildoptions=fuzzy 3704 call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx') 3705 call assert_equal('"history debug', @:) 3706 call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx') 3707 call assert_equal('"history se*h', @:) 3708 set wildoptions& 3709 endfunc 3710 3711 " :language locale name fuzzy completion 3712 func Test_fuzzy_completion_lang() 3713 CheckUnix 3714 set wildoptions& 3715 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx') 3716 call assert_equal('"lang psx', @:) 3717 set wildoptions=fuzzy 3718 call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx') 3719 call assert_equal('"lang POSIX', @:) 3720 set wildoptions& 3721 endfunc 3722 3723 " :mapclear buffer argument fuzzy completion 3724 func Test_fuzzy_completion_mapclear() 3725 set wildoptions& 3726 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx') 3727 call assert_equal('"mapclear buf', @:) 3728 set wildoptions=fuzzy 3729 call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx') 3730 call assert_equal('"mapclear <buffer>', @:) 3731 set wildoptions& 3732 endfunc 3733 3734 " map name fuzzy completion 3735 func Test_fuzzy_completion_mapname() 3736 " test regex completion works 3737 set wildoptions=fuzzy 3738 call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx') 3739 call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:) 3740 nmap <plug>MyLongMap :p<CR> 3741 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx') 3742 call assert_equal("\"nmap <Plug>MyLongMap", @:) 3743 call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx') 3744 call assert_equal("\"nmap MLM \t", @:) 3745 call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx') 3746 call assert_equal("\"nmap <F2> one two \t", @:) 3747 " duplicate entries should be removed 3748 vmap <plug>MyLongMap :<C-U>#<CR> 3749 call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx') 3750 call assert_equal("\"nmap <Plug>MyLongMap", @:) 3751 nunmap <plug>MyLongMap 3752 vunmap <plug>MyLongMap 3753 call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx') 3754 call assert_equal("\"nmap ABC\t", @:) 3755 " results should be sorted by best match 3756 nmap <Plug>format : 3757 nmap <Plug>goformat : 3758 nmap <Plug>TestFOrmat : 3759 nmap <Plug>fendoff : 3760 nmap <Plug>state : 3761 nmap <Plug>FendingOff : 3762 call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx') 3763 call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>fendoff <Plug>goformat", @:) 3764 nunmap <Plug>format 3765 nunmap <Plug>goformat 3766 nunmap <Plug>TestFOrmat 3767 nunmap <Plug>fendoff 3768 nunmap <Plug>state 3769 nunmap <Plug>FendingOff 3770 set wildoptions& 3771 endfunc 3772 3773 " abbreviation fuzzy completion 3774 func Test_fuzzy_completion_abbr() 3775 set wildoptions=fuzzy 3776 call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx') 3777 call assert_equal("\"iabbr <nowait>", @:) 3778 iabbr WaitForCompletion WFC 3779 call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx') 3780 call assert_equal("\"iabbr WaitForCompletion", @:) 3781 call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx') 3782 call assert_equal("\"iabbr a1z\t", @:) 3783 3784 iunabbrev WaitForCompletion 3785 set wildoptions& 3786 endfunc 3787 3788 " menu name fuzzy completion 3789 func Test_fuzzy_completion_menu() 3790 CheckFeature menu 3791 3792 source $VIMRUNTIME/menu.vim 3793 set wildoptions& 3794 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx') 3795 call assert_equal('"menu pup', @:) 3796 set wildoptions=fuzzy 3797 call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx') 3798 call assert_equal('"menu PopUp.', @:) 3799 3800 set wildoptions& 3801 source $VIMRUNTIME/delmenu.vim 3802 endfunc 3803 3804 " :messages suboptions fuzzy completion 3805 func Test_fuzzy_completion_messages() 3806 set wildoptions& 3807 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx') 3808 call assert_equal('"messages clr', @:) 3809 set wildoptions=fuzzy 3810 call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx') 3811 call assert_equal('"messages clear', @:) 3812 set wildoptions& 3813 endfunc 3814 3815 " :set option name fuzzy completion 3816 func Test_fuzzy_completion_option() 3817 set wildoptions& 3818 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx') 3819 call assert_equal('"set brkopt', @:) 3820 set wildoptions=fuzzy 3821 call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx') 3822 call assert_equal('"set breakindentopt', @:) 3823 set wildoptions& 3824 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx') 3825 call assert_equal('"set fixendofline', @:) 3826 set wildoptions=fuzzy 3827 call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx') 3828 call assert_equal('"set fixendofline', @:) 3829 set wildoptions& 3830 endfunc 3831 3832 " :set <term_option> 3833 func Test_fuzzy_completion_term_option() 3834 throw 'Skipped: Nvim does not support term options' 3835 set wildoptions& 3836 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx') 3837 call assert_equal('"set t_EC', @:) 3838 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx') 3839 call assert_equal('"set <t_EC>', @:) 3840 set wildoptions=fuzzy 3841 call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx') 3842 call assert_equal('"set t_EC', @:) 3843 call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx') 3844 call assert_equal('"set <t_EC>', @:) 3845 set wildoptions& 3846 endfunc 3847 3848 " " :packadd directory name fuzzy completion - NOT supported 3849 " func Test_fuzzy_completion_packadd() 3850 " endfunc 3851 3852 " " shell command name fuzzy completion - NOT supported 3853 " func Test_fuzzy_completion_shellcmd() 3854 " endfunc 3855 3856 " :sign suboptions fuzzy completion 3857 func Test_fuzzy_completion_sign() 3858 set wildoptions& 3859 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx') 3860 call assert_equal('"sign ufe', @:) 3861 set wildoptions=fuzzy 3862 call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx') 3863 call assert_equal('"sign undefine', @:) 3864 set wildoptions& 3865 endfunc 3866 3867 " :syntax suboptions fuzzy completion 3868 func Test_fuzzy_completion_syntax_cmd() 3869 set wildoptions& 3870 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx') 3871 call assert_equal('"syntax kwd', @:) 3872 set wildoptions=fuzzy 3873 call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx') 3874 call assert_equal('"syntax keyword', @:) 3875 set wildoptions& 3876 endfunc 3877 3878 " syntax group name fuzzy completion 3879 func Test_fuzzy_completion_syntax_group() 3880 set wildoptions& 3881 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx') 3882 call assert_equal('"syntax list mpar', @:) 3883 set wildoptions=fuzzy 3884 call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx') 3885 call assert_equal('"syntax list MatchParen', @:) 3886 set wildoptions& 3887 endfunc 3888 3889 " :syntime suboptions fuzzy completion 3890 func Test_fuzzy_completion_syntime() 3891 CheckFeature profile 3892 set wildoptions& 3893 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx') 3894 call assert_equal('"syntime clr', @:) 3895 set wildoptions=fuzzy 3896 call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx') 3897 call assert_equal('"syntime clear', @:) 3898 set wildoptions& 3899 endfunc 3900 3901 " " tag name fuzzy completion - NOT supported 3902 " func Test_fuzzy_completion_tagname() 3903 " endfunc 3904 3905 " " tag name and file fuzzy completion - NOT supported 3906 " func Test_fuzzy_completion_tagfile() 3907 " endfunc 3908 3909 " " user names fuzzy completion - how to test this functionality? 3910 " func Test_fuzzy_completion_username() 3911 " endfunc 3912 3913 " user defined variable name fuzzy completion 3914 func Test_fuzzy_completion_userdefined_var() 3915 let g:SomeVariable=10 3916 set wildoptions& 3917 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx') 3918 call assert_equal('"let SVar', @:) 3919 set wildoptions=fuzzy 3920 call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx') 3921 call assert_equal('"let SomeVariable', @:) 3922 set wildoptions& 3923 endfunc 3924 3925 " Test for sorting the results by the best match 3926 func Test_fuzzy_completion_cmd_sort_results() 3927 %bw! 3928 command T123format : 3929 command T123goformat : 3930 command T123TestFOrmat : 3931 command T123fendoff : 3932 command T123state : 3933 command T123FendingOff : 3934 set wildoptions=fuzzy 3935 call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx') 3936 call assert_equal('"T123format T123TestFOrmat T123FendingOff T123fendoff T123goformat', @:) 3937 delcommand T123format 3938 delcommand T123goformat 3939 delcommand T123TestFOrmat 3940 delcommand T123fendoff 3941 delcommand T123state 3942 delcommand T123FendingOff 3943 %bw 3944 set wildoptions& 3945 endfunc 3946 3947 " Test for fuzzy completion of a command with lower case letters and a number 3948 func Test_fuzzy_completion_cmd_alnum() 3949 command Foo2Bar : 3950 set wildoptions=fuzzy 3951 call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx') 3952 call assert_equal('"Foo2Bar', @:) 3953 call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx') 3954 call assert_equal('"Foo2Bar', @:) 3955 call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx') 3956 call assert_equal('"Foo2Bar', @:) 3957 delcommand Foo2Bar 3958 set wildoptions& 3959 endfunc 3960 3961 " Test for command completion for a command starting with 'k' 3962 func Test_fuzzy_completion_cmd_k() 3963 command KillKillKill : 3964 set wildoptions& 3965 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx') 3966 call assert_equal("\"killkill\<Tab>", @:) 3967 set wildoptions=fuzzy 3968 call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx') 3969 call assert_equal('"KillKillKill', @:) 3970 delcom KillKillKill 3971 set wildoptions& 3972 endfunc 3973 3974 " Test for fuzzy completion for user defined custom completion function 3975 func Test_fuzzy_completion_custom_func() 3976 func Tcompl(a, c, p) 3977 return "format\ngoformat\nTestFOrmat\nfendoff\nstate" 3978 endfunc 3979 command -nargs=* -complete=custom,Tcompl Fuzzy : 3980 set wildoptions& 3981 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx') 3982 call assert_equal("\"Fuzzy format", @:) 3983 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx') 3984 call assert_equal("\"Fuzzy xy", @:) 3985 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx') 3986 call assert_equal("\"Fuzzy ttt", @:) 3987 set wildoptions=fuzzy 3988 call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx') 3989 call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:) 3990 call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx') 3991 call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:) 3992 call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx') 3993 call assert_equal("\"Fuzzy xy", @:) 3994 call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx') 3995 call assert_equal("\"Fuzzy TestFOrmat", @:) 3996 delcom Fuzzy 3997 set wildoptions& 3998 endfunc 3999 4000 " Test for fuzzy completion in the middle of a cmdline instead of at the end 4001 func Test_fuzzy_completion_in_middle() 4002 set wildoptions=fuzzy 4003 call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx') 4004 call assert_equal("\"set wildchar wildcharm wrap", @:) 4005 4006 call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx') 4007 call assert_equal("\"args ++encoding= zz", @:) 4008 set wildoptions& 4009 endfunc 4010 4011 " Test for :breakadd argument completion 4012 func Test_cmdline_complete_breakadd() 4013 call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx') 4014 call assert_equal("\"breakadd expr file func here", @:) 4015 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx') 4016 call assert_equal("\"breakadd expr", @:) 4017 call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx') 4018 call assert_equal("\"breakadd expr", @:) 4019 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx') 4020 call assert_equal("\"breakadd here", @:) 4021 call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx') 4022 call assert_equal("\"breakadd here", @:) 4023 call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx') 4024 call assert_equal("\"breakadd abc", @:) 4025 call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint')) 4026 let l = getcompletion('not', 'breakpoint') 4027 call assert_equal([], l) 4028 4029 " Test for :breakadd file [lnum] <file> 4030 call writefile([], 'Xscript') 4031 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4032 call assert_equal("\"breakadd file Xscript", @:) 4033 call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4034 call assert_equal("\"breakadd file Xscript", @:) 4035 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4036 call assert_equal("\"breakadd file 20 Xscript", @:) 4037 call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4038 call assert_equal("\"breakadd file 20 Xscript", @:) 4039 call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4040 call assert_equal("\"breakadd file 20x Xsc\t", @:) 4041 call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx') 4042 call assert_equal("\"breakadd file 20\t", @:) 4043 call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx') 4044 call assert_equal("\"breakadd file 20x\t", @:) 4045 call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx') 4046 call assert_equal("\"breakadd file Xscript ", @:) 4047 call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') 4048 call assert_equal("\"breakadd file X1B2C3", @:) 4049 call delete('Xscript') 4050 4051 " Test for :breakadd func [lnum] <function> 4052 func Xbreak_func() 4053 endfunc 4054 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4055 call assert_equal("\"breakadd func Xbreak_func", @:) 4056 call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4057 call assert_equal("\"breakadd func Xbreak_func", @:) 4058 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4059 call assert_equal("\"breakadd func 20 Xbreak_func", @:) 4060 call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4061 call assert_equal("\"breakadd func 20 Xbreak_func", @:) 4062 call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4063 call assert_equal("\"breakadd func 20x Xbr\t", @:) 4064 call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx') 4065 call assert_equal("\"breakadd func 20\t", @:) 4066 call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx') 4067 call assert_equal("\"breakadd func 20x\t", @:) 4068 call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx') 4069 call assert_equal("\"breakadd func Xbreak_func ", @:) 4070 call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') 4071 call assert_equal("\"breakadd func X1B2C3", @:) 4072 delfunc Xbreak_func 4073 4074 " Test for :breakadd expr <expression> 4075 let g:Xtest_var = 10 4076 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4077 call assert_equal("\"breakadd expr Xtest_var", @:) 4078 call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4079 call assert_equal("\"breakadd expr Xtest_var", @:) 4080 call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx') 4081 call assert_equal("\"breakadd expr Xtest_var ", @:) 4082 call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') 4083 call assert_equal("\"breakadd expr X1B2C3", @:) 4084 unlet g:Xtest_var 4085 4086 " Test for :breakadd here 4087 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4088 call assert_equal("\"breakadd here Xtest", @:) 4089 call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4090 call assert_equal("\"breakadd here Xtest", @:) 4091 call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx') 4092 call assert_equal("\"breakadd here ", @:) 4093 endfunc 4094 4095 " Test for :breakdel argument completion 4096 func Test_cmdline_complete_breakdel() 4097 call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx') 4098 call assert_equal("\"breakdel file func here", @:) 4099 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx') 4100 call assert_equal("\"breakdel file", @:) 4101 call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx') 4102 call assert_equal("\"breakdel file", @:) 4103 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx') 4104 call assert_equal("\"breakdel here", @:) 4105 call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx') 4106 call assert_equal("\"breakdel here", @:) 4107 call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx') 4108 call assert_equal("\"breakdel abc", @:) 4109 4110 " Test for :breakdel file [lnum] <file> 4111 call writefile([], 'Xscript') 4112 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4113 call assert_equal("\"breakdel file Xscript", @:) 4114 call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4115 call assert_equal("\"breakdel file Xscript", @:) 4116 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4117 call assert_equal("\"breakdel file 20 Xscript", @:) 4118 call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4119 call assert_equal("\"breakdel file 20 Xscript", @:) 4120 call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx') 4121 call assert_equal("\"breakdel file 20x Xsc\t", @:) 4122 call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx') 4123 call assert_equal("\"breakdel file 20\t", @:) 4124 call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx') 4125 call assert_equal("\"breakdel file 20x\t", @:) 4126 call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx') 4127 call assert_equal("\"breakdel file Xscript ", @:) 4128 call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') 4129 call assert_equal("\"breakdel file X1B2C3", @:) 4130 call delete('Xscript') 4131 4132 " Test for :breakdel func [lnum] <function> 4133 func Xbreak_func() 4134 endfunc 4135 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4136 call assert_equal("\"breakdel func Xbreak_func", @:) 4137 call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4138 call assert_equal("\"breakdel func Xbreak_func", @:) 4139 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4140 call assert_equal("\"breakdel func 20 Xbreak_func", @:) 4141 call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4142 call assert_equal("\"breakdel func 20 Xbreak_func", @:) 4143 call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx') 4144 call assert_equal("\"breakdel func 20x Xbr\t", @:) 4145 call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx') 4146 call assert_equal("\"breakdel func 20\t", @:) 4147 call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx') 4148 call assert_equal("\"breakdel func 20x\t", @:) 4149 call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx') 4150 call assert_equal("\"breakdel func Xbreak_func ", @:) 4151 call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') 4152 call assert_equal("\"breakdel func X1B2C3", @:) 4153 delfunc Xbreak_func 4154 4155 " Test for :breakdel here 4156 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4157 call assert_equal("\"breakdel here Xtest", @:) 4158 call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') 4159 call assert_equal("\"breakdel here Xtest", @:) 4160 call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx') 4161 call assert_equal("\"breakdel here ", @:) 4162 endfunc 4163 4164 " Test for :scriptnames argument completion 4165 func Test_cmdline_complete_scriptnames() 4166 set wildmenu 4167 call writefile(['let a = 1'], 'Xa1b2c3.vim') 4168 source Xa1b2c3.vim 4169 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx') 4170 call assert_match("\"script .*Xa1b2c3.vim$", @:) 4171 call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx') 4172 call assert_match("\"script .*Xa1b2c3.vim$", @:) 4173 call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx') 4174 call assert_equal("\"script b2c3", @:) 4175 call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx') 4176 call assert_match("\"script 2\<Tab>$", @:) 4177 call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx') 4178 call assert_match("\"script .*Xa1b2c3.vim $", @:) 4179 call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx') 4180 call assert_equal("\"script ", @:) 4181 call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0]) 4182 call assert_equal([], getcompletion('Xa1b2', 'scriptnames')) 4183 new 4184 call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx') 4185 call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t')) 4186 bw! 4187 call delete('Xa1b2c3.vim') 4188 set wildmenu& 4189 endfunc 4190 4191 " this was going over the end of IObuff 4192 func Test_report_error_with_composing() 4193 let caught = 'no' 4194 try 4195 exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80" 4196 catch /E492:/ 4197 let caught = 'yes' 4198 endtry 4199 call assert_equal('yes', caught) 4200 endfunc 4201 4202 " Test for expanding 2-letter and 3-letter :substitute command arguments. 4203 " These commands don't accept an argument. 4204 func Test_cmdline_complete_substitute_short() 4205 for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl', 4206 \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr', 4207 \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir', 4208 \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr', 4209 \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr'] 4210 call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx') 4211 call assert_equal('"' .. cmd .. " \<Tab>", @:) 4212 endfor 4213 endfunc 4214 4215 " Test for shellcmdline command argument completion 4216 func Test_cmdline_complete_shellcmdline_argument() 4217 command -nargs=+ -complete=shellcmdline MyCmd 4218 4219 set wildoptions=fuzzy 4220 4221 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') 4222 call assert_equal('"MyCmd vim test_cmdline.vim', @:) 4223 call assert_equal(['test_cmdline.vim'], 4224 \ getcompletion('vim test_cmdline.', 'shellcmdline')) 4225 4226 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt') 4227 call assert_equal('"MyCmd vim nonexistentfile', @:) 4228 call assert_equal([], 4229 \ getcompletion('vim nonexistentfile', 'shellcmdline')) 4230 4231 let compl1 = getcompletion('', 'file')[0] 4232 let compl2 = getcompletion('', 'file')[1] 4233 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt') 4234 call assert_equal('"MyCmd vim ' .. compl1, @:) 4235 4236 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt') 4237 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:) 4238 4239 let compl = getcompletion('', 'file')[1] 4240 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 4241 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:) 4242 4243 set wildoptions& 4244 call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') 4245 call assert_equal('"MyCmd vim test_cmdline.vim', @:) 4246 call assert_equal(['test_cmdline.vim'], 4247 \ getcompletion('vim test_cmdline.', 'shellcmdline')) 4248 4249 call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt') 4250 call assert_equal('"MyCmd vim nonexistentfile', @:) 4251 call assert_equal([], 4252 \ getcompletion('vim nonexistentfile', 'shellcmdline')) 4253 4254 let compl1 = getcompletion('', 'file')[0] 4255 let compl2 = getcompletion('', 'file')[1] 4256 call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt') 4257 call assert_equal('"MyCmd vim ' .. compl1, @:) 4258 4259 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt') 4260 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:) 4261 4262 let compl = getcompletion('', 'file')[1] 4263 call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') 4264 call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:) 4265 4266 delcommand MyCmd 4267 endfunc 4268 4269 " Test for :! shell command argument completion 4270 func Test_cmdline_complete_bang_cmd_argument() 4271 set wildoptions=fuzzy 4272 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') 4273 call assert_equal('"!vim test_cmdline.vim', @:) 4274 set wildoptions& 4275 call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') 4276 call assert_equal('"!vim test_cmdline.vim', @:) 4277 endfunc 4278 4279 func Call_cmd_funcs() 4280 return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()] 4281 endfunc 4282 4283 func Test_screenpos_and_completion() 4284 call assert_equal(0, getcmdpos()) 4285 call assert_equal(0, getcmdscreenpos()) 4286 call assert_equal('', getcmdcompltype()) 4287 call assert_equal('', getcmdcomplpat()) 4288 4289 cnoremap <expr> <F2> string(Call_cmd_funcs()) 4290 call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt") 4291 call assert_equal("\"let a[6, 7, 'var', 'a']", @:) 4292 call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt") 4293 call assert_equal("\"quit [6, 7, '', '']", @:) 4294 call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt") 4295 call assert_equal("\"nosuchcommand [15, 16, '', '']", @:) 4296 4297 " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with 4298 " cmdline completion. 4299 let g:results = [] 4300 cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR> 4301 call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt") 4302 call assert_equal([ 4303 \ ['sign undefine', 14, 15, 'sign', 'undefine'], 4304 \ ['sign unplace', 13, 14, 'sign', 'unplace'], 4305 \ ['sign un', 8, 9, 'sign', 'un']], g:results) 4306 4307 unlet g:results 4308 cunmap <F2> 4309 endfunc 4310 4311 func Test_recursive_register() 4312 let @= = '' 4313 silent! ?e/ 4314 let caught = 'no' 4315 try 4316 normal // 4317 catch /E169:/ 4318 let caught = 'yes' 4319 endtry 4320 call assert_equal('yes', caught) 4321 endfunc 4322 4323 func Test_long_error_message() 4324 " the error should be truncated, not overrun IObuff 4325 silent! norm Q00000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 4326 endfunc 4327 4328 func Test_cmdline_redraw_tabline() 4329 CheckRunVimInTerminal 4330 4331 let lines =<< trim END 4332 set showtabline=2 4333 autocmd CmdlineEnter * set tabline=foo 4334 END 4335 call writefile(lines, 'Xcmdline_redraw_tabline') 4336 let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6}) 4337 call term_sendkeys(buf, ':') 4338 call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))}) 4339 4340 call StopVimInTerminal(buf) 4341 call delete('Xcmdline_redraw_tabline') 4342 endfunc 4343 4344 func Test_wildmenu_pum_disable_while_shown() 4345 set wildoptions=pum 4346 set wildmenu 4347 cnoremap <F2> <Cmd>set nowildmenu<CR> 4348 call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx') 4349 call assert_equal(0, pumvisible()) 4350 cunmap <F2> 4351 set wildoptions& wildmenu& 4352 endfunc 4353 4354 func Test_setcmdline() 4355 func SetText(text, pos) 4356 call assert_equal(0, setcmdline(v:_null_string)) 4357 call assert_equal('', getcmdline()) 4358 call assert_equal(1, getcmdpos()) 4359 4360 call assert_equal(0, setcmdline(''[: -1])) 4361 call assert_equal('', getcmdline()) 4362 call assert_equal(1, getcmdpos()) 4363 4364 autocmd CmdlineChanged * let g:cmdtype = expand('<afile>') 4365 call assert_equal(0, setcmdline(a:text)) 4366 call assert_equal(a:text, getcmdline()) 4367 call assert_equal(len(a:text) + 1, getcmdpos()) 4368 call assert_equal(getcmdtype(), g:cmdtype) 4369 unlet g:cmdtype 4370 autocmd! CmdlineChanged 4371 4372 call assert_equal(0, setcmdline(a:text, a:pos)) 4373 call assert_equal(a:text, getcmdline()) 4374 call assert_equal(a:pos, getcmdpos()) 4375 4376 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:') 4377 call assert_fails('call setcmdline({}, 0)', 'E1174:') 4378 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:') 4379 4380 return '' 4381 endfunc 4382 4383 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt') 4384 call assert_equal('set rtp?', @:) 4385 4386 call feedkeys(":let g:str = input('? ')\<CR>", 't') 4387 call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt') 4388 call assert_equal('foo', g:str) 4389 unlet g:str 4390 4391 delfunc SetText 4392 4393 " setcmdline() returns 1 when not editing the command line. 4394 call assert_equal(1, 'foo'->setcmdline()) 4395 4396 " Called in custom function 4397 func CustomComplete(A, L, P) 4398 call assert_equal(0, setcmdline("DoCmd ")) 4399 return "January\nFebruary\nMars\n" 4400 endfunc 4401 4402 com! -nargs=* -complete=custom,CustomComplete DoCmd : 4403 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') 4404 call assert_equal('"DoCmd January February Mars', @:) 4405 delcom DoCmd 4406 delfunc CustomComplete 4407 4408 " Called in <expr> 4409 cnoremap <expr>a setcmdline('let foo=') 4410 call feedkeys(":a\<CR>", 'tx') 4411 call assert_equal('let foo=0', @:) 4412 cunmap a 4413 endfunc 4414 4415 func Test_rulerformat_position() 4416 CheckScreendump 4417 4418 let buf = RunVimInTerminal('', #{rows: 2, cols: 20}) 4419 call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>") 4420 call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>") 4421 call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p") 4422 call VerifyScreenDump(buf, 'Test_rulerformat_position', {}) 4423 4424 " clean up 4425 call StopVimInTerminal(buf) 4426 endfunc 4427 4428 " Test for using "%!" in 'rulerformat' to use a function 4429 func Test_rulerformat_function() 4430 CheckScreendump 4431 4432 let lines =<< trim END 4433 func TestRulerFn() 4434 return '10,20%=30%%' 4435 endfunc 4436 END 4437 call writefile(lines, 'Xrulerformat_function', 'D') 4438 4439 let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40}) 4440 call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>") 4441 call term_sendkeys(buf, ":redraw!\<CR>") 4442 call term_wait(buf) 4443 call VerifyScreenDump(buf, 'Test_rulerformat_function', {}) 4444 4445 " clean up 4446 call StopVimInTerminal(buf) 4447 endfunc 4448 4449 func Test_getcompletion_usercmd() 4450 command! -nargs=* -complete=command TestCompletion echo <q-args> 4451 4452 call assert_equal(getcompletion('', 'cmdline'), 4453 \ getcompletion('TestCompletion ', 'cmdline')) 4454 call assert_equal(['<buffer>'], 4455 \ getcompletion('TestCompletion map <bu', 'cmdline')) 4456 4457 delcom TestCompletion 4458 endfunc 4459 4460 func Test_custom_completion() 4461 func CustomComplete1(lead, line, pos) 4462 return "a\nb\nc" 4463 endfunc 4464 func CustomComplete2(lead, line, pos) 4465 return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 }) 4466 endfunc 4467 func Check_custom_completion() 4468 call assert_equal('custom,CustomComplete1', getcmdcompltype()) 4469 return '' 4470 endfunc 4471 func Check_customlist_completion() 4472 call assert_equal('customlist,CustomComplete2', getcmdcompltype()) 4473 return '' 4474 endfunc 4475 4476 command -nargs=1 -complete=custom,CustomComplete1 Test1 echo 4477 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo 4478 4479 call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt") 4480 call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt") 4481 call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 ')) 4482 call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 ')) 4483 4484 call assert_fails("call getcompletion('', 'custom')", 'E475:') 4485 call assert_fails("call getcompletion('', 'customlist')", 'E475:') 4486 4487 call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1')) 4488 call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2')) 4489 call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2')) 4490 4491 delcom Test1 4492 delcom Test2 4493 4494 delfunc CustomComplete1 4495 delfunc CustomComplete2 4496 delfunc Check_custom_completion 4497 delfunc Check_customlist_completion 4498 endfunc 4499 4500 func Test_custom_completion_with_glob() 4501 func TestGlobComplete(A, L, P) 4502 return split(glob('Xglob*'), "\n") 4503 endfunc 4504 4505 command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete : 4506 call writefile([], 'Xglob1', 'D') 4507 call writefile([], 'Xglob2', 'D') 4508 4509 call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt') 4510 call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:) 4511 4512 delcommand TestGlobComplete 4513 delfunc TestGlobComplete 4514 endfunc 4515 4516 func Test_window_size_stays_same_after_changing_cmdheight() 4517 set laststatus=2 4518 let expected = winheight(0) 4519 function! Function_name() abort 4520 call feedkeys(":"..repeat('x', &columns), 'x') 4521 let &cmdheight=2 4522 let &cmdheight=1 4523 redraw 4524 endfunction 4525 call Function_name() 4526 call assert_equal(expected, winheight(0)) 4527 endfunc 4528 4529 " verify that buffer-completion finds all buffer names matching a pattern 4530 func Test_buffer_completion() 4531 " should return empty list 4532 call assert_equal([], getcompletion('', 'buffer')) 4533 4534 call mkdir('Xbuf_complete', 'R') 4535 e Xbuf_complete/Foobar.c 4536 e Xbuf_complete/MyFoobar.c 4537 e AFoobar.h 4538 let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"] 4539 4540 call assert_equal(3, len(getcompletion('Foo', 'buffer'))) 4541 call assert_equal(expected, getcompletion('Foo', 'buffer')) 4542 call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt') 4543 call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:) 4544 endfunc 4545 4546 " :set t_?? 4547 func Test_term_option() 4548 throw 'Skipped: Nvim does not support termcap options' 4549 set wildoptions& 4550 let _cpo = &cpo 4551 set cpo-=C 4552 " There may be more, test only until t_xo 4553 let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm' 4554 \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe' 4555 \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC' 4556 \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr' 4557 \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi' 4558 \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*' 4559 call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx') 4560 call assert_match(expected, @:) 4561 let &cpo = _cpo 4562 endfunc 4563 4564 func Test_ex_command_completion() 4565 " required for :* 4566 " set cpo+=* 4567 let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0') 4568 " :++ and :-- are only valid in Vim9 script context, so they can be ignored 4569 " call assert_equal(['++', '--'], sort(list)) 4570 call assert_equal([], sort(list)) 4571 call assert_equal(2, exists(':k')) 4572 call assert_equal(0, exists(':ke')) 4573 call assert_equal(1, exists(':kee')) 4574 call assert_equal(1, exists(':keep')) 4575 call assert_equal(1, exists(':keepm')) 4576 call assert_equal(1, exists(':keepma')) 4577 call assert_equal(1, exists(':keepmar')) 4578 call assert_equal(1, exists(':keepmark')) 4579 call assert_equal(2, exists(':keepmarks')) 4580 call assert_equal(2, exists(':keepalt')) 4581 call assert_equal(2, exists(':keepjumps')) 4582 call assert_equal(2, exists(':keeppatterns')) 4583 set cpo-=* 4584 endfunc 4585 4586 func Test_cd_bslash_completion_windows() 4587 CheckMSWindows 4588 let save_shellslash = &shellslash 4589 set noshellslash 4590 call system('mkdir XXXa\_b') 4591 defer delete('XXXa', 'rf') 4592 call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx') 4593 call assert_equal('"cd XXXa\_b\', @:) 4594 let &shellslash = save_shellslash 4595 endfunc 4596 4597 " Test cmdcomplete_info() with CmdlineLeavePre autocmd 4598 func Test_cmdcomplete_info() 4599 augroup test_CmdlineLeavePre 4600 autocmd! 4601 " Calling expand() should not interfere with cmdcomplete_info(). 4602 autocmd CmdlineLeavePre * call expand('test_cmdline.*') 4603 autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info()) 4604 augroup END 4605 4606 " Disable char_avail so that wildtrigger() does not bail out 4607 call Ntest_override("char_avail", 1) 4608 4609 cnoremap <F8> <C-R>=wildtrigger()[-1]<CR> 4610 4611 call assert_equal({}, cmdcomplete_info()) 4612 4613 for trig in ["\<Tab>", "\<F8>"] 4614 new 4615 call assert_equal({}, cmdcomplete_info()) 4616 call feedkeys(":h echom\<cr>", "tx") " No expansion 4617 call assert_equal('{}', g:cmdcomplete_info) 4618 call feedkeys($":h echoms{trig}\<cr>", "tx") 4619 call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info) 4620 call feedkeys($":h echom{trig}\<cr>", "tx") 4621 call assert_equal( 4622 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}', 4623 \ g:cmdcomplete_info) 4624 call feedkeys($":h echom{trig}\<tab>\<cr>", "tx") 4625 call assert_equal( 4626 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}', 4627 \ g:cmdcomplete_info) 4628 call feedkeys($":h echom{trig}\<tab>\<tab>\<cr>", "tx") 4629 call assert_equal( 4630 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}', 4631 \ g:cmdcomplete_info) 4632 4633 set wildoptions=pum 4634 call feedkeys($":h echoms{trig}\<cr>", "tx") 4635 call assert_equal('{''cmdline_orig'': ''h echoms'', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info) 4636 call feedkeys($":h echom{trig}\<cr>", "tx") 4637 call assert_equal( 4638 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}', 4639 \ g:cmdcomplete_info) 4640 call feedkeys($":h echom{trig}\<tab>\<cr>", "tx") 4641 call assert_equal( 4642 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}', 4643 \ g:cmdcomplete_info) 4644 call feedkeys($":h echom{trig}\<tab>\<tab>\<cr>", "tx") 4645 call assert_equal( 4646 \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}', 4647 \ g:cmdcomplete_info) 4648 bw! 4649 " set wildoptions& 4650 set wildoptions= " Accommodate Nvim default 4651 endfor 4652 4653 " wildtrigger() should not show matches when prefix is invalid 4654 for pat in ["", " ", "22"] 4655 call feedkeys($":{pat}\<F8>\<cr>", "tx") " No expansion 4656 call assert_equal('{}', g:cmdcomplete_info) 4657 endfor 4658 4659 augroup test_CmdlineLeavePre | autocmd! | augroup END 4660 call Ntest_override("char_avail", 0) 4661 unlet g:cmdcomplete_info 4662 cunmap <F8> 4663 endfunc 4664 4665 " Test wildcharm completion for '/' and '?' search 4666 func Test_search_complete() 4667 CheckOption incsearch 4668 set wildcharm=<c-z> 4669 4670 " Disable char_avail so that expansion of commandline works 4671 call Ntest_override("char_avail", 1) 4672 4673 func GetComplInfo() 4674 let g:compl_info = cmdcomplete_info() 4675 return '' 4676 endfunc 4677 4678 new 4679 cnoremap <buffer><expr> <F9> GetComplInfo() 4680 cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR> 4681 4682 " Pressing <Tab> inserts tab character 4683 set wildchar=0 4684 call setline(1, "x\t") 4685 call feedkeys("/x\t\r", "tx") 4686 call assert_equal("x\t", @/) 4687 set wildchar& 4688 4689 call setline(1, ['the', 'these', 'thethe', 'thethere', 'foobar']) 4690 4691 for trig in ["\<tab>", "\<c-z>", "\<F8>"] 4692 " Test menu first item and order 4693 call feedkeys($"gg2j/t{trig}\<f9>", 'tx') 4694 call assert_equal(['the', 'thethere', 'there', 'these', 'thethe'], g:compl_info.matches) 4695 call feedkeys($"gg2j?t{trig}\<f9>", 'tx') 4696 call assert_equal(['these', 'the', 'there', 'thethere', 'thethe'], g:compl_info.matches) 4697 4698 " <c-n> and <c-p> cycle through menu items 4699 call feedkeys($"gg/the{trig}\<cr>", 'tx') 4700 call assert_equal('these', getline('.')) 4701 call feedkeys($"gg/the{trig}\<c-n>\<cr>", 'tx') 4702 call assert_equal('thethe', getline('.')) 4703 call feedkeys($"gg/the{trig}".repeat("\<c-n>", 5)."\<cr>", 'tx') 4704 call assert_equal('these', getline('.')) 4705 call feedkeys($"G?the{trig}\<cr>", 'tx') 4706 call assert_equal('thethere', getline('.')) 4707 call feedkeys($"G?the{trig}".repeat("\<c-p>", 5)."\<cr>", 'tx') 4708 call assert_equal('thethere', getline('.')) 4709 4710 " Beginning of word pattern (<) retains '<' 4711 call feedkeys($"gg2j/\\<t{trig}\<f9>", 'tx') 4712 call assert_equal(['\<thethere', '\<the', '\<these', '\<thethe'], g:compl_info.matches) 4713 call feedkeys($"gg2j?\\<t{trig}\<f9>", 'tx') 4714 call assert_equal(['\<these', '\<the', '\<thethere', '\<thethe'], g:compl_info.matches) 4715 call feedkeys($"gg2j/\\v<t{trig}\<f9>", 'tx') 4716 call assert_equal(['\v<thethere', '\v<the', '\v<these', '\v<thethe'], g:compl_info.matches) 4717 call feedkeys($"gg2j?\\v<th{trig}\<f9>", 'tx') 4718 call assert_equal(['\v<these', '\v<the', '\v<thethere', '\v<thethe'], g:compl_info.matches) 4719 endfor 4720 4721 " Ctrl-G goes from one match to the next, after menu is opened 4722 set incsearch 4723 " first match 4724 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<cr>", 'tx') 4725 call assert_equal('thethe', getline('.')) 4726 " second match 4727 call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<c-g>\<cr>", 'tx') 4728 call assert_equal('thethere', getline('.')) 4729 call assert_equal([0, 0, 0, 0], getpos('"')) 4730 4731 " CTRL-T goes to the previous match 4732 " first match 4733 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2)."\<c-t>\<cr>", 'tx') 4734 call assert_equal('thethere', getline('.')) 4735 " second match 4736 call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2).repeat("\<c-t>", 2)."\<cr>", 'tx') 4737 call assert_equal('thethe', getline('.')) 4738 4739 " wild menu is cleared properly 4740 call feedkeys("/the\<c-z>\<esc>/\<f9>", 'tx') 4741 call assert_equal({}, g:compl_info) 4742 call feedkeys("/the\<c-z>\<c-e>\<f9>", 'tx') 4743 call assert_equal([], g:compl_info.matches) 4744 4745 " Do not expand if offset is present (/pattern/offset and ?pattern?offset) 4746 for pat in ["/", "/2", "/-3", "\\/"] 4747 call feedkeys("/the" . pat . "\<c-z>\<f9>", 'tx') 4748 call assert_equal({}, g:compl_info) 4749 endfor 4750 for pat in ["?", "?2", "?-3", "\\\\?"] 4751 call feedkeys("?the" . pat . "\<c-z>\<f9>", 'tx') 4752 call assert_equal({}, g:compl_info) 4753 endfor 4754 4755 " Last letter of match is multibyte 4756 call setline('$', ['theΩ']) 4757 call feedkeys("gg/th\<c-z>\<f9>", 'tx') 4758 call assert_equal(['these', 'thethe', 'the', 'thethere', 'there', 'theΩ'], 4759 \ g:compl_info.matches) 4760 4761 " Identical words 4762 call setline(1, ["foo", "foo", "foo", "foobar"]) 4763 call feedkeys("gg/f\<c-z>\<f9>", 'tx') 4764 call assert_equal(['foo', 'foobar'], g:compl_info.matches) 4765 4766 " Exact match 4767 call feedkeys("/foo\<c-z>\<f9>", 'tx') 4768 call assert_equal(['foo', 'foobar'], g:compl_info.matches) 4769 4770 " Match case correctly 4771 %d 4772 call setline(1, ["foobar", "Foobar", "fooBAr", "FooBARR"]) 4773 4774 call feedkeys("gg/f\<tab>\<f9>", 'tx') 4775 call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches) 4776 call feedkeys("gg/Fo\<tab>\<f9>", 'tx') 4777 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) 4778 call feedkeys("gg/FO\<tab>\<f9>", 'tx') 4779 call assert_equal({}, g:compl_info) 4780 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx') 4781 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches) 4782 4783 set ignorecase 4784 call feedkeys("gg/f\<tab>\<f9>", 'tx') 4785 call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches) 4786 call feedkeys("gg/Fo\<tab>\<f9>", 'tx') 4787 call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches) 4788 call feedkeys("gg/FO\<tab>\<f9>", 'tx') 4789 call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches) 4790 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx') 4791 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches) 4792 4793 set smartcase 4794 call feedkeys("gg/f\<tab>\<f9>", 'tx') 4795 call assert_equal(['foobar', 'fooBAr', 'foobarr'], g:compl_info.matches) 4796 call feedkeys("gg/Fo\<tab>\<f9>", 'tx') 4797 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) 4798 call feedkeys("gg/FO\<tab>\<f9>", 'tx') 4799 call assert_equal({}, g:compl_info) 4800 4801 " Issue #17680 (getcompletion() does not support search completion) 4802 let result = getcompletion('%s/', 'cmdline') 4803 call assert_equal([], result) 4804 4805 call feedkeys("gg/foob\<tab>\<f9>", 'tx') 4806 call assert_equal(['foobar', 'foobarr'], g:compl_info.matches) 4807 call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx') 4808 call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches) 4809 call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx') 4810 call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches) 4811 4812 set wildoptions+=exacttext ignorecase& smartcase& 4813 call feedkeys("gg/F\<tab>\<f9>", 'tx') 4814 call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) 4815 call feedkeys("gg/foob\<tab>\<f9>", 'tx') 4816 call assert_equal([], g:compl_info.matches) 4817 call feedkeys("gg/r\\n.\<tab>\<f9>", 'tx') 4818 call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches) 4819 4820 set ignorecase 4821 call feedkeys("gg/F\<tab>\<f9>", 'tx') 4822 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) 4823 call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx') 4824 call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches) 4825 4826 set smartcase 4827 call feedkeys("gg/f\<tab>\<f9>", 'tx') 4828 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) 4829 call feedkeys("gg/foob\<tab>\<f9>", 'tx') 4830 call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) 4831 call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx') 4832 call assert_equal({}, g:compl_info) 4833 call feedkeys("gg/r\\n.*\\n\<tab>\<f9>", 'tx') 4834 call assert_equal(['r\nFoobar\nfooBAr', 'r\nfooBAr\nFooBARR'], g:compl_info.matches) 4835 4836 " Issue #17858 4837 %d 4838 set wildcharm=0 incsearch& ignorecase& smartcase& wildoptions& 4839 setlocal iskeyword=!-~,192-255 4840 let l:lines = ['th=~/foo', 'these', 'tho'] 4841 call setline(1, l:lines) 4842 call feedkeys("G/th\<tab>\<f9>", 'tx') 4843 call assert_equal(l:lines, g:compl_info.matches) 4844 4845 bw! 4846 call Ntest_override("char_avail", 0) 4847 delfunc GetComplInfo 4848 unlet! g:compl_info 4849 endfunc 4850 4851 func Test_search_wildmenu_screendump() 4852 CheckScreendump 4853 4854 let lines =<< trim [SCRIPT] 4855 call test_override('alloc_lines', 1) 4856 set wildmenu wildcharm=<f5> 4857 call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere']) 4858 [SCRIPT] 4859 call writefile(lines, 'XTest_search_wildmenu', 'D') 4860 let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10}) 4861 4862 " Pattern has newline at EOF 4863 call term_sendkeys(buf, "gg2j/e\\n\<f5>") 4864 call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {}) 4865 4866 " longest:full 4867 call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>") 4868 call term_sendkeys(buf, "gg/t\<f5>") 4869 call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {}) 4870 4871 " list:full 4872 call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>") 4873 call term_sendkeys(buf, "gg/t\<f5>") 4874 call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {}) 4875 4876 " noselect:full 4877 call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>") 4878 call term_sendkeys(buf, "gg/t\<f5>") 4879 call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {}) 4880 4881 " Multiline 4882 call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>") 4883 call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {}) 4884 4885 " 'incsearch' is redrawn after accepting completion 4886 call term_sendkeys(buf, "\<esc>:set wim=full\<cr>") 4887 call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") 4888 call term_sendkeys(buf, "/th") 4889 call VerifyScreenDump(buf, 'Test_search_wildmenu_6', {}) 4890 call term_sendkeys(buf, "\<f5>") 4891 call VerifyScreenDump(buf, 'Test_search_wildmenu_7', {}) 4892 call term_sendkeys(buf, "\<c-n>\<c-y>") 4893 call VerifyScreenDump(buf, 'Test_search_wildmenu_8', {}) 4894 4895 " 'incsearch' highlight is restored after dismissing popup (Ctrl_E) 4896 call term_sendkeys(buf, "\<esc>:set wop=pum is hls&\<cr>") 4897 call term_sendkeys(buf, "gg/th\<tab>\<c-e>") 4898 call TermWait(buf, 50) 4899 call VerifyScreenDump(buf, 'Test_search_wildmenu_9', {}) 4900 4901 call term_sendkeys(buf, "\<esc>") 4902 call StopVimInTerminal(buf) 4903 endfunc 4904 4905 " Issue #17858 4906 func Test_search_wildmenu_iminsert() 4907 CheckScreendump 4908 4909 let lines =<< trim [SCRIPT] 4910 set wop=pum imi=1 4911 setlocal iskeyword=!-~,192-255 4912 call setline(1, [ 4913 \ "global toggle global-local global/local glyphs toggles English", 4914 \ "accordingly. toggled accordingly single-byte", 4915 \ ]) 4916 call cursor(2, 42) 4917 [SCRIPT] 4918 call writefile(lines, 'XTest_search_wildmenu', 'D') 4919 let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 12}) 4920 4921 call term_sendkeys(buf, "/gl\<Tab>") 4922 call TermWait(buf, 50) 4923 call VerifyScreenDump(buf, 'Test_search_wildmenu_iminsert', {}) 4924 4925 call term_sendkeys(buf, "\<esc>") 4926 call StopVimInTerminal(buf) 4927 endfunc 4928 4929 " Test wildcharm completion for :s and :g with range 4930 func Test_range_complete() 4931 set wildcharm=<c-z> 4932 4933 " Disable char_avail so that expansion of commandline works 4934 call Ntest_override("char_avail", 1) 4935 4936 func GetComplInfo() 4937 let g:compl_info = cmdcomplete_info() 4938 return '' 4939 endfunc 4940 new 4941 cnoremap <buffer><expr> <F9> GetComplInfo() 4942 cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR> 4943 4944 call setline(1, ['ab', 'ba', 'ca', 'af']) 4945 4946 for trig in ["\<tab>", "\<c-z>", "\<F8>"] 4947 call feedkeys($":%s/a{trig}\<f9>", 'xt') 4948 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches) 4949 " call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt') 4950 call feedkeys($":verbose :%s/a{trig}\<f9>", 'xt') 4951 call assert_equal(['ab', 'a', 'af'], g:compl_info.matches) 4952 endfor 4953 4954 call feedkeys(":%s/\<c-z>\<f9>", 'xt') 4955 call assert_equal({}, g:compl_info) 4956 4957 for cmd in ['s', 'g'] 4958 call feedkeys($":1,2{cmd}/a\<c-z>\<f9>", 'xt') 4959 call assert_equal(['ab', 'a'], g:compl_info.matches) 4960 endfor 4961 4962 1 4963 call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt') 4964 call assert_equal(['ab', 'a'], g:compl_info.matches) 4965 4966 /f 4967 call feedkeys(":1,s/b\<c-z>\<f9>", 'xt') 4968 call assert_equal(['b', 'ba'], g:compl_info.matches) 4969 4970 /c 4971 call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt') 4972 call assert_equal(['a', 'af'], g:compl_info.matches) 4973 4974 %s/c/c/ 4975 call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt') 4976 call assert_equal(['ab', 'a'], g:compl_info.matches) 4977 4978 3 4979 normal! ma 4980 call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt') 4981 call assert_equal(['a', 'af'], g:compl_info.matches) 4982 4983 " Line number followed by a search pattern ([start]/pattern/[command]) 4984 call feedkeys("3/a\<c-z>\<f9>", 'xt') 4985 call assert_equal(['a', 'af', 'ab'], g:compl_info.matches) 4986 4987 bw! 4988 call Ntest_override("char_avail", 0) 4989 delfunc GetComplInfo 4990 unlet! g:compl_info 4991 set wildcharm=0 4992 endfunc 4993 4994 " With 'noselect' in 'wildmode', ensure that the popup menu (pum) does not retain 4995 " its scroll position after reopening. The menu should open showing the top items, 4996 " regardless of previous scrolling. 4997 func Test_pum_scroll_noselect() 4998 CheckScreendump 4999 5000 let lines =<< trim [SCRIPT] 5001 command! -nargs=* -complete=customlist,TestFn TestCmd echo 5002 func TestFn(a, b, c) 5003 return map(range(1, 50), 'printf("a%d", v:val)') 5004 endfunc 5005 set wildmode=noselect,full 5006 set wildoptions=pum 5007 set wildmenu 5008 set noruler 5009 [SCRIPT] 5010 call writefile(lines, 'XTest_pum_scroll', 'D') 5011 let buf = RunVimInTerminal('-S XTest_pum_scroll', {'rows': 10}) 5012 5013 call term_sendkeys(buf, ":TestCmd \<tab>" . repeat("\<c-n>", 20)) 5014 call TermWait(buf, 50) 5015 call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_1', {}) 5016 5017 call term_sendkeys(buf, "\<esc>:TestCmd \<tab>") 5018 call TermWait(buf, 50) 5019 call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_2', {}) 5020 5021 call term_sendkeys(buf, "\<esc>") 5022 call StopVimInTerminal(buf) 5023 endfunc 5024 5025 " CmdlineChanged shouldn't trigger if command-line text is unchanged 5026 func Test_cmdline_changed() 5027 let g:cmdchg_count = 0 5028 let g:cmdprefix = '' 5029 augroup test_CmdlineAugrp | autocmd! 5030 autocmd CmdlineChanged * if getcmdline() =~ g:cmdprefix | let g:cmdchg_count += 1 | endif 5031 augroup END 5032 5033 " Disable char_avail so that wildtrigger() does not bail out 5034 call Ntest_override("char_avail", 1) 5035 5036 new 5037 cnoremap <buffer> <F8> <C-R>=wildtrigger()[-1]<CR> 5038 set wildmenu 5039 set wildmode=full 5040 5041 let g:cmdprefix = 'echomsg' 5042 for trig in ["\<Tab>", "\<F8>"] 5043 let g:cmdchg_count = 0 5044 call feedkeys($":echomsg{trig}", "tx") 5045 call assert_equal(1, g:cmdchg_count) " once only for 'g', not again for <Tab> 5046 endfor 5047 5048 let g:cmdprefix = 'echo' 5049 for trig in ["\<Tab>", "\<F8>"] 5050 let g:cmdchg_count = 0 5051 call feedkeys($":ech{trig}", "tx") 5052 call assert_equal(1, g:cmdchg_count) " (once for 'h' and) once for 'o' 5053 endfor 5054 5055 set wildmode=noselect,full 5056 let g:cmdprefix = 'ech' 5057 for trig in ["\<Tab>", "\<F8>"] 5058 let g:cmdchg_count = 0 5059 call feedkeys($":ech{trig}", "tx") 5060 call assert_equal(1, g:cmdchg_count) " once for 'h', not again for <tab> 5061 endfor 5062 5063 command! -nargs=+ -complete=custom,TestComplete Test echo 5064 5065 func TestComplete(arglead, cmdline, cursorpos) 5066 return "AbC" 5067 endfunc 5068 5069 set wildoptions=fuzzy wildmode=full 5070 let g:cmdprefix = 'Test \(AbC\|abc\)' 5071 for trig in ["\<Tab>", "\<F8>"] 5072 let g:cmdchg_count = 0 5073 call feedkeys($":Test abc{trig}", "tx") 5074 call assert_equal(2, g:cmdchg_count) " once for 'c', again for 'AbC' 5075 endfor 5076 5077 bw! 5078 set wildmode& wildmenu& wildoptions& 5079 augroup test_CmdlineAugrp | autocmd! | augroup END 5080 unlet g:cmdchg_count 5081 unlet g:cmdprefix 5082 delfunc TestComplete 5083 delcommand Test 5084 call Ntest_override("char_avail", 0) 5085 endfunc 5086 5087 func Test_wildtrigger_update_screen() 5088 CheckScreendump 5089 5090 let lines =<< trim [SCRIPT] 5091 command! -nargs=* -complete=customlist,TestFn TestCmd echo 5092 func TestFn(cmdarg, b, c) 5093 if a:cmdarg == 'ax' 5094 return [] 5095 else 5096 return map(range(1, 5), 'printf("abc%d", v:val)') 5097 endif 5098 endfunc 5099 set wildmode=noselect,full 5100 set wildoptions=pum 5101 set wildmenu 5102 cnoremap <F8> <C-R>=wildtrigger()[-1]<CR> 5103 [SCRIPT] 5104 call writefile(lines, 'XTest_wildtrigger', 'D') 5105 let buf = RunVimInTerminal('-S XTest_wildtrigger', {'rows': 10}) 5106 5107 call term_sendkeys(buf, ":TestCmd a\<F8>") 5108 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_1', {}) 5109 5110 " Typing a character when pum is open does not close the pum window 5111 " This is needed to prevent pum window from flickering during 5112 " ':h cmdline-autocompletion'. 5113 call term_sendkeys(buf, "x") 5114 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_2', {}) 5115 5116 " pum is closed when no completion candidates are available 5117 call term_sendkeys(buf, "\<F8>") 5118 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_3', {}) 5119 5120 call term_sendkeys(buf, "\<BS>\<F8>") 5121 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_1', {}) 5122 5123 call term_sendkeys(buf, "x") 5124 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_2', {}) 5125 5126 " pum is closed when leaving cmdline mode 5127 call term_sendkeys(buf, "\<Esc>") 5128 call VerifyScreenDump(buf, 'Test_wildtrigger_update_screen_4', {}) 5129 5130 call StopVimInTerminal(buf) 5131 endfunc 5132 5133 " Issue #18035: long lines should not get listed twice in the menu when 5134 " 'wildmode' contains 'noselect' 5135 func Test_long_line_noselect() 5136 CheckScreendump 5137 5138 let lines =<< trim [SCRIPT] 5139 set wildmenu wildoptions=pum wildmode=noselect,full 5140 command -nargs=1 -complete=custom,Entries DoubleEntry echo 5141 func Entries(a, b, c) 5142 return 'loooooooooooooooong quite loooooooooooong, really loooooooooooong, probably too looooooooooooooooooooooooooong entry' 5143 endfunc 5144 [SCRIPT] 5145 call writefile(lines, 'XTest_wildmenu', 'D') 5146 let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8, 'cols': 60}) 5147 5148 call term_sendkeys(buf, ":DoubleEntry \<Tab>") 5149 call VerifyScreenDump(buf, 'Test_long_line_noselect_1', {}) 5150 5151 call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>") 5152 call VerifyScreenDump(buf, 'Test_long_line_noselect_2', {}) 5153 5154 call term_sendkeys(buf, "\<Esc>:DoubleEntry \<Tab>\<C-N>\<C-N>") 5155 call VerifyScreenDump(buf, 'Test_long_line_noselect_3', {}) 5156 5157 " clean up 5158 call term_sendkeys(buf, "\<Esc>") 5159 call StopVimInTerminal(buf) 5160 endfunc 5161 5162 func Test_CmdlineLeave_vchar_keys() 5163 func OnLeave() 5164 let g:leave_key = v:char 5165 endfunction 5166 5167 new 5168 for event in ["CmdlineLeavePre", "CmdlineLeave"] 5169 exec "autocmd" event "* :call OnLeave()" 5170 for key in ["\<C-C>", "\<Esc>", "\<CR>"] 5171 call feedkeys($":echo{key}", 'tx') 5172 call assert_equal(key, g:leave_key) 5173 endfor 5174 exec "autocmd!" event 5175 endfor 5176 bwipe! 5177 delfunc OnLeave 5178 unlet g:leave_key 5179 endfunc 5180 5181 " Skip wildmenu during history navigation via Up/Down keys 5182 func Test_skip_wildtrigger_hist_navigation() 5183 call Ntest_override("char_avail", 1) 5184 set wildmenu wildmode=noselect,full 5185 augroup TestSkipWildtrigger | autocmd! 5186 autocmd CmdlineChanged : call wildtrigger() 5187 augroup END 5188 cnoremap <expr> <Up> wildmenumode() ? "\<C-E>\<Up>" : "\<Up>" 5189 cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>" 5190 5191 call feedkeys(":echom \"foo\"", "tx") 5192 call feedkeys(":echom \"foobar\"", "tx") 5193 5194 call feedkeys(":ech\<Up>\<C-B>\"\<CR>", "tx") 5195 call assert_equal('"echom "foobar"', @:) 5196 call feedkeys(":ech\<Up>\<Up>\<C-B>\"\<CR>", "tx") 5197 call assert_equal('"echom "foo"', @:) 5198 call feedkeys(":ech\<Up>\<Up>\<Down>\<C-B>\"\<CR>", "tx") 5199 call assert_equal('"echom "foobar"', @:) 5200 call feedkeys(":ech\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", "tx") 5201 call assert_equal('"ech', @:) 5202 5203 call Ntest_override("char_avail", 0) 5204 set wildmenu& wildmode& wildoptions& 5205 augroup TestSkipWildtrigger | autocmd! | augroup END 5206 cunmap <Up> 5207 cunmap <Down> 5208 endfunc 5209 5210 " Issue 18298: wildmenu should be dismissed after wildtrigger and whitespace 5211 func Test_update_screen_after_wildtrigger() 5212 CheckScreendump 5213 let lines =<< trim [SCRIPT] 5214 call test_override("char_avail", 1) 5215 set wildmode=noselect:lastused,full wildmenu wildoptions=pum 5216 autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif 5217 [SCRIPT] 5218 call writefile(lines, 'XTest_wildtrigger', 'D') 5219 let buf = RunVimInTerminal('-S XTest_wildtrigger', {'rows': 10}) 5220 5221 call term_sendkeys(buf, ":term foo") 5222 call TermWait(buf, 50) 5223 call VerifyScreenDump(buf, 'Test_update_screen_wildtrigger_1', {}) 5224 5225 call term_sendkeys(buf, "\<esc>") 5226 call StopVimInTerminal(buf) 5227 endfunc 5228 5229 func Test_breaklist_args_fails() 5230 call assert_match('No breakpoints defined', execute(':breaklist')) 5231 call assert_fails(':breaklist extra', 'E488:') 5232 endfunc 5233 5234 " vim: shiftwidth=2 sts=2 expandtab