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