robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1" Test for options 2 3source shared.vim 4source check.vim 5source view_util.vim 6 7scriptencoding utf-8 8 9func Test_whichwrap () 10set whichwrap = b,s 11call assert_equal ( 'b,s' , & whichwrap ) 12 13set whichwrap += h,l 14call assert_equal ( 'b,s,h,l' , & whichwrap ) 15 16set whichwrap += h,l 17call assert_equal ( 'b,s,h,l' , & whichwrap ) 18 19set whichwrap += h,l 20call assert_equal ( 'b,s,h,l' , & whichwrap ) 21 22set whichwrap = h,h 23call assert_equal ( 'h' , & whichwrap ) 24 25set whichwrap = h,h,h 26call assert_equal ( 'h' , & whichwrap ) 27 28" " For compatibility with Vim 3.0 and before, number values are also 29" " supported for 'whichwrap' 30" set whichwrap=1 31" call assert_equal('b', &whichwrap) 32" set whichwrap=2 33" call assert_equal('s', &whichwrap) 34" set whichwrap=4 35" call assert_equal('h,l', &whichwrap) 36" set whichwrap=8 37" call assert_equal('<,>', &whichwrap) 38" set whichwrap=16 39" call assert_equal('[,]', &whichwrap) 40" set whichwrap=31 41" call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) 42 43set whichwrap & 44endfunc 45 46func Test_isfname () 47" This used to cause Vim to access uninitialized memory. 48set isfname = 49call assert_equal ( "~X" , expand ( "~X" )) 50set isfname & 51" Test for setting 'isfname' to an unsupported character 52let save_isfname = & isfname 53call assert_fails ( 'exe $"set isfname+={"\u1234"}"' , 'E474:' ) 54call assert_equal ( save_isfname , & isfname ) 55endfunc 56 57" Test for getting the value of 'pastetoggle' 58func Test_pastetoggle () 59throw "Skipped: 'pastetoggle' is removed from Nvim" 60" character with K_SPECIAL byte 61let & pastetoggle = '…' 62call assert_equal ( '…' , & pastetoggle ) 63call assert_equal ( "\n pastetoggle=…" , execute ( 'set pastetoggle?' )) 64 65" modified character with K_SPECIAL byte 66let & pastetoggle = '<M-…>' 67call assert_equal ( '<M-…>' , & pastetoggle ) 68call assert_equal ( "\n pastetoggle=<M-…>" , execute ( 'set pastetoggle?' )) 69 70" illegal bytes 71let str = ":\x7f:\x80:\x90:\xd0:" 72let & pastetoggle = str 73call assert_equal ( str , & pastetoggle ) 74call assert_equal ( "\n pastetoggle=" .. strtrans ( str ), execute ( 'set pastetoggle?' )) 75 76unlet str 77set pastetoggle & 78endfunc 79 80func Test_wildchar () 81" Empty 'wildchar' used to access invalid memory. 82call assert_fails ( 'set wildchar=' , 'E521:' ) 83call assert_fails ( 'set wildchar=abc' , 'E521:' ) 84set wildchar = <Esc> 85let a = execute ( 'set wildchar?' ) 86call assert_equal ( "\n wildchar=<Esc>" , a ) 87set wildchar = 27 88let a = execute ( 'set wildchar?' ) 89call assert_equal ( "\n wildchar=<Esc>" , a ) 90set wildchar & 91endfunc 92 93func Test_wildoptions () 94set wildoptions = 95set wildoptions += tagfile 96set wildoptions += tagfile 97call assert_equal ( 'tagfile' , & wildoptions ) 98endfunc 99 100func Test_options_command () 101let caught = 'ok' 102try 103 options 104catch 105let caught = v: throwpoint . "\n" . v: exception 106endtry 107call assert_equal ( 'ok' , caught ) 108 109" Check if the option-window is opened horizontally. 110wincmd j 111call assert_notequal ( 'nvim-optwin://optwin' , bufname ( '' )) 112wincmd k 113call assert_equal ( 'nvim-optwin://optwin' , bufname ( '' )) 114" close option-window 115close 116 117" Open the option-window vertically. 118vert options 119" Check if the option-window is opened vertically. 120wincmd l 121call assert_notequal ( 'nvim-optwin://optwin' , bufname ( '' )) 122wincmd h 123call assert_equal ( 'nvim-optwin://optwin' , bufname ( '' )) 124" close option-window 125close 126 127" Open the option-window at the top. 128set splitbelow 129topleft options 130call assert_equal ( 1 , winnr ()) 131close 132 133" Open the option-window at the bottom. 134set nosplitbelow 135botright options 136call assert_equal ( winnr ( '$' ), winnr ()) 137close 138set splitbelow & 139 140" Open the option-window in a new tab. 141tab options 142" Check if the option-window is opened in a tab. 143normal gT 144call assert_notequal ( 'nvim-optwin://optwin' , bufname ( '' )) 145normal gt 146call assert_equal ( 'nvim-optwin://optwin' , bufname ( '' )) 147" close option-window 148close 149 150" Open the options window browse 151if has ( 'browse' ) 152 browseset 153call assert_equal ( 'nvim-optwin://optwin' , bufname ( '' )) 154close 155endif 156endfunc 157 158func Test_path_keep_commas () 159" Test that changing 'path' keeps two commas. 160set path = foo,,bar 161set path -= bar 162set path += bar 163call assert_equal ( 'foo,,bar' , & path ) 164 165set path & 166endfunc 167 168func Test_path_too_long () 169exe 'set path=' .. repeat ( 'x' , 10000 ) 170call assert_fails ( 'find x' , 'E854:' ) 171set path & 172endfunc 173 174func Test_signcolumn () 175CheckFeature signs 176call assert_equal ( "auto" , & signcolumn ) 177set signcolumn = yes 178set signcolumn = no 179call assert_fails ( 'set signcolumn=nope' , 'E474: Invalid argument: signcolumn=nope' ) 180endfunc 181 182func Test_filetype_valid () 183set ft = valid_name 184call assert_equal ( "valid_name" , & filetype ) 185set ft = valid-name 186call assert_equal ( "valid-name" , & filetype ) 187 188call assert_fails ( ":set ft=wrong;name" , "E474:" ) 189call assert_fails ( ":set ft=wrong\\\\name" , "E474:" ) 190call assert_fails ( ":set ft=wrong\\|name" , "E474:" ) 191call assert_fails ( ":set ft=wrong/name" , "E474:" ) 192call assert_fails ( ":set ft=wrong\\\nname" , "E474:" ) 193call assert_equal ( "valid-name" , & filetype ) 194 195exe "set ft=trunc\x00name" 196call assert_equal ( "trunc" , & filetype ) 197endfunc 198 199func Test_syntax_valid () 200if ! has ( 'syntax' ) 201return 202endif 203set syn = valid_name 204call assert_equal ( "valid_name" , & syntax ) 205set syn = valid-name 206call assert_equal ( "valid-name" , & syntax ) 207 208call assert_fails ( ":set syn=wrong;name" , "E474:" ) 209call assert_fails ( ":set syn=wrong\\\\name" , "E474:" ) 210call assert_fails ( ":set syn=wrong\\|name" , "E474:" ) 211call assert_fails ( ":set syn=wrong/name" , "E474:" ) 212call assert_fails ( ":set syn=wrong\\\nname" , "E474:" ) 213call assert_equal ( "valid-name" , & syntax ) 214 215exe "set syn=trunc\x00name" 216call assert_equal ( "trunc" , & syntax ) 217endfunc 218 219func Test_keymap_valid () 220if ! has ( 'keymap' ) 221return 222endif 223call assert_fails ( ":set kmp=valid_name" , "E544:" ) 224call assert_fails ( ":set kmp=valid_name" , "valid_name" ) 225call assert_fails ( ":set kmp=valid-name" , "E544:" ) 226call assert_fails ( ":set kmp=valid-name" , "valid-name" ) 227 228call assert_fails ( ":set kmp=wrong;name" , "E474:" ) 229call assert_fails ( ":set kmp=wrong\\\\name" , "E474:" ) 230call assert_fails ( ":set kmp=wrong\\|name" , "E474:" ) 231call assert_fails ( ":set kmp=wrong/name" , "E474:" ) 232call assert_fails ( ":set kmp=wrong\\\nname" , "E474:" ) 233 234call assert_fails ( ":set kmp=trunc\x00name" , "E544:" ) 235call assert_fails ( ":set kmp=trunc\x00name" , "trunc" ) 236endfunc 237 238func Test_wildchar_valid () 239call assert_fails ( "set wildchar=<CR>" , "E474:" ) 240call assert_fails ( "set wildcharm=<C-C>" , "E474:" ) 241endfunc 242 243func Check_dir_option ( name ) 244" Check that it's possible to set the option. 245exe 'set ' . a: name . '=/usr/share/dict/words' 246call assert_equal ( '/usr/share/dict/words' , eval ( '&' . a: name )) 247exe 'set ' . a: name . '=/usr/share/dict/words,/and/there' 248call assert_equal ( '/usr/share/dict/words,/and/there' , eval ( '&' . a: name )) 249exe 'set ' . a: name . '=/usr/share/dict\ words' 250call assert_equal ( '/usr/share/dict words' , eval ( '&' . a: name )) 251 252" Check rejecting weird characters. 253call assert_fails ( "set " . a: name . "=/not&there" , "E474:" ) 254call assert_fails ( "set " . a: name . "=/not>there" , "E474:" ) 255call assert_fails ( "set " . a: name . "=/not.*there" , "E474:" ) 256endfunc 257 258func Test_cinkeys () 259" This used to cause invalid memory access 260set cindent cinkeys = 0 261norm a 262set cindent & cinkeys & 263endfunc 264 265func Test_dictionary () 266call Check_dir_option ( 'dictionary' ) 267endfunc 268 269func Test_thesaurus () 270call Check_dir_option ( 'thesaurus' ) 271endfun 272 273func Test_complete () 274" Trailing single backslash used to cause invalid memory access. 275set complete = s\ 276new 277call feedkeys ( "i\<C-N>\<Esc>" , 'xt' ) 278bwipe ! 279call assert_fails ( 'set complete=ix' , 'E535: Illegal character after <i>' ) 280call assert_fails ( 'set complete=x' , 'E539: Illegal character <x>' ) 281call assert_fails ( 'set complete=..' , 'E535: Illegal character after <.>' ) 282set complete = .,w,b,u,k,\ s,i,d,],t,U,F,o 283call assert_fails ( 'set complete=i^-10' , 'E535: Illegal character after <^>' ) 284call assert_fails ( 'set complete=i^x' , 'E535: Illegal character after <^>' ) 285call assert_fails ( 'set complete=k^2,t^-1,s^' , 'E535: Illegal character after <^>' ) 286call assert_fails ( 'set complete=t^-1' , 'E535: Illegal character after <^>' ) 287call assert_fails ( 'set complete=kfoo^foo2' , 'E535: Illegal character after <^>' ) 288call assert_fails ( 'set complete=kfoo^' , 'E535: Illegal character after <^>' ) 289call assert_fails ( 'set complete=.^' , 'E535: Illegal character after <^>' ) 290set complete = .,w,b,u,k,s,i,d,],t,U,F,o 291set complete = . 292set complete = .^10,t^0 293 294func Foo ( a , b ) 295return '' 296endfunc 297 298set complete += Ffuncref('Foo'\\,\ [10]) 299set complete = Ffuncref('Foo'\\,\ [10])^10 300set complete & 301set complete += Ffunction('g:Foo'\\,\ [10\\,\ 20]) 302set complete & 303delfunc Foo 304endfun 305 306func Test_set_completion () 307call feedkeys ( ":set di\<C-A>\<C-B>\"\<CR>" , 'tx' ) 308call assert_equal ( '"set dictionary diff diffanchors diffexpr diffopt digraph directory display' , @:) 309 310call feedkeys ( ":setlocal di\<C-A>\<C-B>\"\<CR>" , 'tx' ) 311call assert_equal ( '"setlocal dictionary diff diffanchors diffexpr diffopt digraph directory display' , @:) 312 313call feedkeys ( ":setglobal di\<C-A>\<C-B>\"\<CR>" , 'tx' ) 314call assert_equal ( '"setglobal dictionary diff diffanchors diffexpr diffopt digraph directory display' , @:) 315 316" Expand boolean options. When doing :set no<Tab> Vim prefixes the option 317" names with "no". 318call feedkeys ( ":set nodi\<C-A>\<C-B>\"\<CR>" , 'tx' ) 319call assert_equal ( '"set nodiff nodigraph' , @:) 320 321call feedkeys ( ":set invdi\<C-A>\<C-B>\"\<CR>" , 'tx' ) 322call assert_equal ( '"set invdiff invdigraph' , @:) 323 324" Expanding "set noinv" does nothing. 325call feedkeys ( ":set noinv\<C-A>\<C-B>\"\<CR>" , 'tx' ) 326call assert_equal ( '"set noinv' , @:) 327 328" Expand abbreviation of options. 329call feedkeys ( ":set ts\<C-A>\<C-B>\"\<CR>" , 'tx' ) 330call assert_equal ( '"set tabstop thesaurus thesaurusfunc' , @:) 331 332" Expand current value 333call feedkeys ( ":set suffixes=\<C-A>\<C-B>\"\<CR>" , 'tx' ) 334call assert_equal ( '"set suffixes=.bak,~,.o,.h,.info,.swp,.obj' , @:) 335 336call feedkeys ( ":set suffixes:\<C-A>\<C-B>\"\<CR>" , 'tx' ) 337call assert_equal ( '"set suffixes:.bak,~,.o,.h,.info,.swp,.obj' , @:) 338 339" " Expand key codes. 340" call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') 341" call assert_equal('"set <Help> <Home>', @:) 342" " <BackSpace> (alt name) and <BS> should both show up in auto-complete 343" call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx') 344" call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:) 345" " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here 346" " nor show up as duplicates 347" call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx') 348" call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:) 349" 350" " Expand terminal options. 351" call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') 352" call assert_equal('"set t_AB t_AF t_AU t_AL', @:) 353" call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:') 354 355" Expand directories. 356call feedkeys ( ":set cdpath=./\<C-A>\<C-B>\"\<CR>" , 'tx' ) 357call assert_match ( ' ./samples/ ' , @:) 358call assert_notmatch ( ' ./summarize.vim ' , @:) 359set cdpath & 360 361" Expand files and directories. 362call feedkeys ( ":set tags=./\<C-A>\<C-B>\"\<CR>" , 'tx' ) 363call assert_match ( ' ./samples/.* ./summarize.vim' , @:) 364 365call feedkeys ( ":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>" , 'tx' ) 366call assert_equal ( '"set tags=./\\ diff diffanchors diffexpr diffopt' , @:) 367 368" Expand files with spaces/commas in them. Make sure we delimit correctly. 369" 370" 'tags' allow for for spaces/commas to both act as delimiters, with actual 371" spaces requiring double escape, and commas need a single escape. 372" 'dictionary' is a normal comma-separated option where only commas act as 373" delimiters, and both space/comma need one single escape. 374" 'makeprg' is a non-comma-separated option. Commas don't need escape. 375defer delete('Xfoo Xspace.txt') 376defer delete('Xsp_dummy') 377defer delete('Xbar,Xcomma.txt') 378defer delete('Xcom_dummy') 379call writefile ([], 'Xfoo Xspace.txt' ) 380call writefile ([], 'Xsp_dummy' ) 381call writefile ([], 'Xbar,Xcomma.txt' ) 382call writefile ([], 'Xcom_dummy' ) 383 384call feedkeys ( ':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 385call assert_equal ( '"set tags=./Xfoo\ Xsp_dummy' , @:) 386call feedkeys ( ':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 387call assert_equal ( '"set tags=./Xfoo\\\ Xspace.txt' , @:) 388call feedkeys ( ':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 389call assert_equal ( '"set dictionary=./Xfoo\ Xspace.txt' , @:) 390 391call feedkeys ( ':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 392call assert_equal ( '"set dictionary=./Xbar,Xcom_dummy' , @:) 393if has ( 'win32' ) 394" In Windows, '\,' is literal, see `:help filename-backslash`, so this 395" means we treat it as one file name. 396call feedkeys ( ':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 397call assert_equal ( '"set dictionary=Xbar\,Xcomma.txt' , @:) 398else 399" In other platforms, '\,' simply escape to ',', and indicate a delimiter 400" to split into a separate file name. You need '\\,' to escape the comma 401" as part of the file name. 402call feedkeys ( ':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 403call assert_equal ( '"set dictionary=Xbar\,Xcom_dummy' , @:) 404 405call feedkeys ( ':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>" , 'tx' ) 406call assert_equal ( '"set dictionary=Xbar\\,Xcomma.txt' , @:) 407endif 408call feedkeys ( ":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>" , 'tx' ) 409call assert_equal ( '"set makeprg=./Xbar,Xcomma.txt' , @:) 410set tags & dictionary & makeprg & 411 412" Expanding the option names 413call feedkeys ( ":set \<Tab>\<C-B>\"\<CR>" , 'xt' ) 414call assert_equal ( '"set all' , @:) 415 416" Expanding a second set of option names 417call feedkeys ( ":set wrapscan \<Tab>\<C-B>\"\<CR>" , 'xt' ) 418call assert_equal ( '"set wrapscan all' , @:) 419 420" Expanding a special keycode 421" call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') 422" call assert_equal('"set <Home>', @:) 423 424" Expanding an invalid special keycode 425call feedkeys ( ":set <abcd>\<Tab>\<C-B>\"\<CR>" , 'xt' ) 426call assert_equal ( "\"set <abcd>\<Tab>" , @:) 427 428" Expanding a terminal keycode 429" call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') 430" call assert_equal("\"set t_AB", @:) 431 432" Expanding an invalid option name 433call feedkeys ( ":set abcde=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 434call assert_equal ( "\"set abcde=\<Tab>" , @:) 435 436" Expanding after a = for a boolean option 437call feedkeys ( ":set wrapscan=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 438call assert_equal ( "\"set wrapscan=\<Tab>" , @:) 439 440" Expanding a numeric option 441call feedkeys ( ":set tabstop+=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 442call assert_equal ( "\"set tabstop+=" .. & tabstop , @:) 443 444" Expanding a non-boolean option 445call feedkeys ( ":set invtabstop=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 446call assert_equal ( "\"set invtabstop=" , @:) 447 448" Expand options for 'spellsuggest' 449call feedkeys ( ":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>" , 'xt' ) 450call assert_equal ( "\"set spellsuggest=file:test_options.vim" , @:) 451call feedkeys ( ":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>" , 'xt' ) 452call assert_equal ( "\"set spellsuggest=best,file:test_options.vim" , @:) 453 454" Expanding value for 'key' is disallowed 455if exists ( '+key' ) 456set key = abcd 457call feedkeys ( ":set key=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 458call assert_equal ( '"set key=' , @:) 459call feedkeys ( ":set key-=\<Tab>\<C-B>\"\<CR>" , 'xt' ) 460call assert_equal ( '"set key-=' , @:) 461set key = 462endif 463 464" Expand values for 'filetype' 465call feedkeys ( ":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>" , 'xt' ) 466call assert_equal ( '"set filetype=sshdconfig' , @:) 467call feedkeys ( ":set filetype=a\<C-A>\<C-B>\"\<CR>" , 'xt' ) 468call assert_equal ( '"set filetype=' .. getcompletion ( 'a*' , 'filetype' ) ->join (), @:) 469 470" Expand values for 'syntax' 471call feedkeys ( ":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>" , 'xt' ) 472call assert_equal ( '"set syntax=sshdconfig' , @:) 473call feedkeys ( ":set syntax=a\<C-A>\<C-B>\"\<CR>" , 'xt' ) 474call assert_equal ( '"set syntax=' .. getcompletion ( 'a*' , 'syntax' ) ->join (), @:) 475 476if has ( 'keymap' ) 477" Expand values for 'keymap' 478call feedkeys ( ":set keymap=acc\<Tab>\<C-B>\"\<CR>" , 'xt' ) 479call assert_equal ( '"set keymap=accents' , @:) 480call feedkeys ( ":set keymap=a\<C-A>\<C-B>\"\<CR>" , 'xt' ) 481call assert_equal ( '"set keymap=' .. getcompletion ( 'a*' , 'keymap' ) ->join (), @:) 482endif 483endfunc 484 485" Test handling of expanding individual string option values 486func Test_set_completion_string_values () 487" 488" Test basic enum string options that have well-defined enum names 489" 490 491" call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) 492call assert_equal ([ 'lastline' , 'truncate' , 'uhex' , 'msgsep' ], getcompletion ( 'set display=' , 'cmdline' )) 493call assert_equal ([ 'truncate' ], getcompletion ( 'set display=t' , 'cmdline' )) 494call assert_equal ([ 'uhex' ], getcompletion ( 'set display=*ex*' , 'cmdline' )) 495 496" Test that if a value is set, it will populate the results, but only if 497" typed value is empty. 498set display = uhex,lastline 499" call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) 500call assert_equal ([ 'uhex,lastline' , 'lastline' , 'truncate' , 'uhex' , 'msgsep' ], getcompletion ( 'set display=' , 'cmdline' )) 501call assert_equal ([ 'uhex' ], getcompletion ( 'set display=u' , 'cmdline' )) 502" If the set value is part of the enum list, it will show as the first 503" result with no duplicate. 504set display = uhex 505" call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline')) 506call assert_equal ([ 'uhex' , 'lastline' , 'truncate' , 'msgsep' ], getcompletion ( 'set display=' , 'cmdline' )) 507" If empty value, will just show the normal list without an empty item 508set display = 509" call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline')) 510call assert_equal ([ 'lastline' , 'truncate' , 'uhex' , 'msgsep' ], getcompletion ( 'set display=' , 'cmdline' )) 511" Test escaping of the values 512" call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0]) 513call assert_equal ( 'vert:\|,foldsep:\|,fold:-' , getcompletion ( 'set fillchars=' , 'cmdline' )[ 0 ]) 514 515" Test comma-separated lists will expand after a comma. 516call assert_equal ([ 'uhex' ], getcompletion ( 'set display=truncate,*ex*' , 'cmdline' )) 517" Also test the positioning of the expansion is correct 518call feedkeys ( ":set display=truncate,l\<Tab>\<C-B>\"\<CR>" , 'xt' ) 519call assert_equal ( '"set display=truncate,lastline' , @:) 520set display & 521 522" Test single-value options will not expand after a comma 523call assert_equal ([], getcompletion ( 'set ambw=single,' , 'cmdline' )) 524 525" Test the other simple options to make sure they have basic auto-complete, 526" but don't exhaustively validate their results. 527call assert_equal ( 'single' , getcompletion ( 'set ambw=' , 'cmdline' )[ 0 ]) 528call assert_match ( 'light\|dark' , getcompletion ( 'set bg=' , 'cmdline' )[ 1 ]) 529call assert_equal ( 'indent,eol,start' , getcompletion ( 'set backspace=' , 'cmdline' )[ 0 ]) 530call assert_equal ( 'yes' , getcompletion ( 'set backupcopy=' , 'cmdline' )[ 1 ]) 531call assert_equal ( 'backspace' , getcompletion ( 'set belloff=' , 'cmdline' )[ 1 ]) 532call assert_equal ( 'min:' , getcompletion ( 'set briopt=' , 'cmdline' )[ 1 ]) 533if exists ( '+browsedir' ) 534call assert_equal ( 'current' , getcompletion ( 'set browsedir=' , 'cmdline' )[ 1 ]) 535endif 536call assert_equal ( 'unload' , getcompletion ( 'set bufhidden=' , 'cmdline' )[ 1 ]) 537"call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1]) 538call assert_equal ( 'help' , getcompletion ( 'set buftype=' , 'cmdline' )[ 1 ]) 539call assert_equal ( 'internal' , getcompletion ( 'set casemap=' , 'cmdline' )[ 1 ]) 540if exists ( '+clipboard' ) 541" call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1]) 542call assert_match ( 'unnamed' , getcompletion ( 'set clipboard=' , 'cmdline' )[ 0 ]) 543endif 544call assert_equal ( '.' , getcompletion ( 'set complete=' , 'cmdline' )[ 1 ]) 545call assert_equal ( 'fuzzy' , getcompletion ( 'set completeopt=' , 'cmdline' )[ 1 ]) 546" call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0]) 547if exists ( '+completeslash' ) 548call assert_equal ( 'backslash' , getcompletion ( 'set completeslash=' , 'cmdline' )[ 1 ]) 549endif 550if exists ( '+cryptmethod' ) 551call assert_equal ( 'zip' , getcompletion ( 'set cryptmethod=' , 'cmdline' )[ 1 ]) 552endif 553if exists ( '+cursorlineopt' ) 554call assert_equal ( 'line' , getcompletion ( 'set cursorlineopt=' , 'cmdline' )[ 1 ]) 555endif 556call assert_equal ( 'throw' , getcompletion ( 'set debug=' , 'cmdline' )[ 1 ]) 557call assert_equal ( 'ver' , getcompletion ( 'set eadirection=' , 'cmdline' )[ 1 ]) 558call assert_equal ( 'mac' , getcompletion ( 'set fileformat=' , 'cmdline' )[ 2 ]) 559if exists ( '+foldclose' ) 560call assert_equal ( 'all' , getcompletion ( 'set foldclose=' , 'cmdline' )[ 0 ]) 561endif 562if exists ( '+foldmethod' ) 563call assert_equal ( 'expr' , getcompletion ( 'set foldmethod=' , 'cmdline' )[ 1 ]) 564endif 565if exists ( '+foldopen' ) 566call assert_equal ( 'all' , getcompletion ( 'set foldopen=' , 'cmdline' )[ 1 ]) 567endif 568call assert_equal ( 'stack' , getcompletion ( 'set jumpoptions=' , 'cmdline' )[ 0 ]) 569call assert_equal ( 'stopsel' , getcompletion ( 'set keymodel=' , 'cmdline' )[ 1 ]) 570call assert_equal ( 'expr:1' , getcompletion ( 'set lispoptions=' , 'cmdline' )[ 1 ]) 571call assert_match ( 'popup' , getcompletion ( 'set mousemodel=' , 'cmdline' )[ 2 ]) 572call assert_equal ( 'bin' , getcompletion ( 'set nrformats=' , 'cmdline' )[ 1 ]) 573if exists ( '+rightleftcmd' ) 574call assert_equal ( 'search' , getcompletion ( 'set rightleftcmd=' , 'cmdline' )[ 0 ]) 575endif 576call assert_equal ( 'ver' , getcompletion ( 'set scrollopt=' , 'cmdline' )[ 1 ]) 577call assert_equal ( 'exclusive' , getcompletion ( 'set selection=' , 'cmdline' )[ 1 ]) 578call assert_equal ( 'key' , getcompletion ( 'set selectmode=' , 'cmdline' )[ 1 ]) 579if exists ( '+ssop' ) 580call assert_equal ( 'buffers' , getcompletion ( 'set ssop=' , 'cmdline' )[ 1 ]) 581endif 582call assert_equal ( 'statusline' , getcompletion ( 'set showcmdloc=' , 'cmdline' )[ 1 ]) 583if exists ( '+signcolumn' ) 584call assert_equal ( 'yes' , getcompletion ( 'set signcolumn=' , 'cmdline' )[ 1 ]) 585endif 586if exists ( '+spelloptions' ) 587call assert_equal ( 'camel' , getcompletion ( 'set spelloptions=' , 'cmdline' )[ 0 ]) 588endif 589if exists ( '+spellsuggest' ) 590call assert_equal ( 'best' , getcompletion ( 'set spellsuggest+=' , 'cmdline' )[ 0 ]) 591endif 592call assert_equal ( 'screen' , getcompletion ( 'set splitkeep=' , 'cmdline' )[ 1 ]) 593" call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1]) 594call assert_equal ( 'usetab' , getcompletion ( 'set switchbuf=' , 'cmdline' )[ 1 ]) 595call assert_equal ( 'ignore' , getcompletion ( 'set tagcase=' , 'cmdline' )[ 1 ]) 596if exists ( '+tabclose' ) 597call assert_equal ( 'left uselast' , join ( sort ( getcompletion ( 'set tabclose=' , 'cmdline' ))), ' ' ) 598endif 599if exists ( '+termwintype' ) 600call assert_equal ( 'conpty' , getcompletion ( 'set termwintype=' , 'cmdline' )[ 1 ]) 601endif 602if exists ( '+toolbar' ) 603call assert_equal ( 'text' , getcompletion ( 'set toolbar=' , 'cmdline' )[ 1 ]) 604endif 605if exists ( '+tbis' ) 606call assert_equal ( 'medium' , getcompletion ( 'set tbis=' , 'cmdline' )[ 2 ]) 607endif 608if exists ( '+ttymouse' ) 609set ttymouse = 610call assert_equal ( 'xterm2' , getcompletion ( 'set ttymouse=' , 'cmdline' )[ 1 ]) 611set ttymouse & 612endif 613call assert_equal ( 'insert' , getcompletion ( 'set virtualedit=' , 'cmdline' )[ 1 ]) 614call assert_equal ( 'longest' , getcompletion ( 'set wildmode=' , 'cmdline' )[ 1 ]) 615call assert_equal ( 'full' , getcompletion ( 'set wildmode=list,longest:' , 'cmdline' )[ 0 ]) 616call assert_equal ( 'tagfile' , getcompletion ( 'set wildoptions=' , 'cmdline' )[ 1 ]) 617if exists ( '+winaltkeys' ) 618call assert_equal ( 'yes' , getcompletion ( 'set winaltkeys=' , 'cmdline' )[ 1 ]) 619endif 620 621" Other string options that queries the system rather than fixed enum names 622call assert_equal ([ 'all' , 'BufAdd' ], getcompletion ( 'set eventignore=' , 'cmdline' )[ 0 : 1 ]) 623call assert_equal ([ '-BufAdd' , '-BufCreate' ], getcompletion ( 'set eventignore=all,-' , 'cmdline' )[ 0 : 1 ]) 624call assert_equal ([ 'WinLeave' , 'WinResized' , 'WinScrolled' ], getcompletion ( 'set eiw=' , 'cmdline' )[ -3 : -1 ]) 625call assert_equal ( 'latin1' , getcompletion ( 'set fileencodings=' , 'cmdline' )[ 1 ]) 626" call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0]) 627" call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0]) 628 629call assert_equal ( 'eol' , getcompletion ( 'set listchars+=' , 'cmdline' )[ 0 ]) 630call assert_equal ([ 'multispace' , 'leadmultispace' ], getcompletion ( 'set listchars+=' , 'cmdline' )[ -2 :]) 631call assert_equal ([ 'tab' , 'leadtab' ], getcompletion ( 'set listchars+=' , 'cmdline' )[ 5 : 6 ]) 632call assert_equal ( 'eol' , getcompletion ( 'setl listchars+=' , 'cmdline' )[ 0 ]) 633call assert_equal ([ 'tab' , 'leadtab' ], getcompletion ( 'setl listchars+=' , 'cmdline' )[ 5 : 6 ]) 634call assert_equal ([ 'multispace' , 'leadmultispace' ], getcompletion ( 'setl listchars+=' , 'cmdline' )[ -2 :]) 635call assert_equal ( 'stl' , getcompletion ( 'set fillchars+=' , 'cmdline' )[ 0 ]) 636call assert_equal ( 'stl' , getcompletion ( 'setl fillchars+=' , 'cmdline' )[ 0 ]) 637 638" 639" Unique string options below 640" 641 642" keyprotocol: only auto-complete when after ':' with known protocol types 643" call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline')) 644" call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt') 645" call assert_equal('"set keyprotocol+=someterm:mok2', @:) 646" set keyprotocol& 647 648" previewpopup / completepopup 649" call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0]) 650" call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0]) 651" call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt') 652" call assert_equal('"set previewpopup+=border:on', @:) 653" call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt') 654" call assert_equal('"set completepopup=height:10,align:item', @:) 655" call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline')) 656" set previewpopup& completepopup& 657 658" diffopt: special handling of algorithm:<alg_list> and inline:<inline_type> 659call assert_equal ( 'filler' , getcompletion ( 'set diffopt+=' , 'cmdline' )[ 0 ]) 660call assert_equal ([], getcompletion ( 'set diffopt+=iblank,foldcolumn:' , 'cmdline' )) 661call assert_equal ( 'patience' , getcompletion ( 'set diffopt+=iblank,algorithm:pat*' , 'cmdline' )[ 0 ]) 662call assert_equal ( 'char' , getcompletion ( 'set diffopt+=iwhite,inline:ch*' , 'cmdline' )[ 0 ]) 663 664" highlight: special parsing, including auto-completing highlight groups 665" after ':' 666" call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1]) 667" call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0]) 668" call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2]) 669" call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0]) 670" call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0]) 671" If all the display modes are used up we should be suggesting nothing. Make 672" a hl typed option with all the modes which will look like '8bi-nrsuc2d=t', 673" and make sure nothing is suggested from that. 674" let hl_display_modes = join( 675" \ filter(map(getcompletion('set hl+=8', 'cmdline'), 676" \ {idx, val -> val[1]}), 677" \ {idx, val -> val != ':'}), 678" \ '') 679" call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline')) 680" Test completion in middle of the line 681" call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt') 682" call assert_equal("\"set hl=8bi i", @:) 683 684" messagesopt 685call assert_equal ([ 'history:' , 'hit-enter' , 'maxheight:' , 'pager:' , 'progress:' , 'timeout:' , 'wait:' ], 686 \getcompletion ( 'set messagesopt+=' , 'cmdline' ) ->sort ()) 687 688" 689" Test flag lists 690" 691 692" Test set=. Show the original value if nothing is typed after '='. 693" Otherwise, the list should avoid showing what's already typed. 694set mouse = v 695call assert_equal ([ 'v' , 'a' , 'n' , 'i' , 'c' , 'h' , 'r' ], getcompletion ( 'set mouse=' , 'cmdline' )) 696set mouse = nvi 697call assert_equal ([ 'nvi' , 'a' , 'n' , 'v' , 'i' , 'c' , 'h' , 'r' ], getcompletion ( 'set mouse=' , 'cmdline' )) 698call assert_equal ([ 'a' , 'v' , 'i' , 'c' , 'r' ], getcompletion ( 'set mouse=hn' , 'cmdline' )) 699 700" Test set+=. Never show original value, and it also tries to avoid listing 701" flags that's already in the option value. 702call assert_equal ([ 'a' , 'c' , 'h' , 'r' ], getcompletion ( 'set mouse+=' , 'cmdline' )) 703call assert_equal ([ 'a' , 'c' , 'r' ], getcompletion ( 'set mouse+=hn' , 'cmdline' )) 704call assert_equal ([], getcompletion ( 'set mouse+=acrhn' , 'cmdline' )) 705 706" Test that the position of the expansion is correct (even if there are 707" additional values after the current cursor) 708call feedkeys ( ":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>" , 'xt' ) 709call assert_equal ( '"set mouse=han' , @:) 710set mouse & 711 712" Test that other flag list options have auto-complete, but don't 713" exhaustively validate their results. 714if exists ( '+concealcursor' ) 715call assert_equal ( 'n' , getcompletion ( 'set cocu=' , 'cmdline' )[ 0 ]) 716endif 717call assert_equal ( 'a' , getcompletion ( 'set cpo=' , 'cmdline' )[ 1 ]) 718call assert_equal ( 't' , getcompletion ( 'set fo=' , 'cmdline' )[ 1 ]) 719if exists ( '+guioptions' ) 720call assert_equal ( '!' , getcompletion ( 'set go=' , 'cmdline' )[ 1 ]) 721endif 722call assert_equal ( 'r' , getcompletion ( 'set shortmess=' , 'cmdline' )[ 1 ]) 723call assert_equal ( 'b' , getcompletion ( 'set whichwrap=' , 'cmdline' )[ 1 ]) 724 725" 726"Test set-= 727" 728 729" Normal single-value option just shows the existing value 730set ambiwidth = double 731call assert_equal ([ 'double' ], getcompletion ( 'set ambw-=' , 'cmdline' )) 732set ambiwidth & 733 734" Works on numbers and term options as well 735call assert_equal ([ string ( & laststatus )], getcompletion ( 'set laststatus-=' , 'cmdline' )) 736set t_Ce = testCe 737" call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline')) 738set t_Ce & 739 740" Comma-separated lists should present each option 741set diffopt = context:123,,,,,iblank,iwhiteall 742call assert_equal ([ 'context:123' , 'iblank' , 'iwhiteall' ], getcompletion ( 'set diffopt-=' , 'cmdline' )) 743call assert_equal ([ 'context:123' , 'iblank' ], getcompletion ( 'set diffopt-=*n*' , 'cmdline' )) 744call assert_equal ([ 'iblank' , 'iwhiteall' ], getcompletion ( 'set diffopt-=i' , 'cmdline' )) 745" Don't present more than one option as it doesn't make sense in set-= 746call assert_equal ([], getcompletion ( 'set diffopt-=iblank,' , 'cmdline' )) 747" Test empty option 748set diffopt = 749call assert_equal ([], getcompletion ( 'set diffopt-=' , 'cmdline' )) 750" Test all possible values 751call assert_equal ([ 'filler' , 'anchor' , 'context:' , 'iblank' , 'icase' , 'iwhite' , 'iwhiteall' , 'iwhiteeol' , 'horizontal' , 752 \'vertical' , 'closeoff' , 'hiddenoff' , 'foldcolumn:' , 'followwrap' , 'internal' , 'indent-heuristic' , 'algorithm:' , 'inline:' , 'linematch:' ], 753 \getcompletion ( 'set diffopt=' , 'cmdline' )) 754set diffopt & 755 756" Test escaping output 757call assert_equal ( 'vert:\|' , getcompletion ( 'set fillchars-=' , 'cmdline' )[ 0 ]) 758 759" Test files with commas in name are being parsed and escaped properly 760set path = has\\\ space,file\\,with\\,comma,normal_file 761if exists ( '+completeslash' ) 762call assert_equal ([ 'has\\\ space' , 'file\,with\,comma' , 'normal_file' ], getcompletion ( 'set path-=' , 'cmdline' )) 763else 764call assert_equal ([ 'has\\\ space' , 'file\\,with\\,comma' , 'normal_file' ], getcompletion ( 'set path-=' , 'cmdline' )) 765endif 766set path & 767 768" Flag list should present orig value, then individual flags 769set mouse = v 770call assert_equal ([ 'v' ], getcompletion ( 'set mouse-=' , 'cmdline' )) 771set mouse = avn 772call assert_equal ([ 'avn' , 'a' , 'v' , 'n' ], getcompletion ( 'set mouse-=' , 'cmdline' )) 773" Don't auto-complete when we have at least one flags already 774call assert_equal ([], getcompletion ( 'set mouse-=n' , 'cmdline' )) 775" Test empty option 776set mouse = 777call assert_equal ([], getcompletion ( 'set mouse-=' , 'cmdline' )) 778set mouse & 779 780" 'whichwrap' is an odd case where it's both flag list and comma-separated 781set ww = b,h 782call assert_equal ([ 'b' , 'h' ], getcompletion ( 'set ww-=' , 'cmdline' )) 783set ww & 784endfunc 785 786func Test_set_option_errors () 787call assert_fails ( 'set scroll=-1' , 'E49:' ) 788call assert_fails ( 'set backupcopy=' , 'E474:' ) 789call assert_fails ( 'set regexpengine=3' , 'E474:' ) 790call assert_fails ( 'set history=10001' , 'E474:' ) 791call assert_fails ( 'set numberwidth=21' , 'E474:' ) 792call assert_fails ( 'set colorcolumn=-a' , 'E474:' ) 793call assert_fails ( 'set colorcolumn=a' , 'E474:' ) 794call assert_fails ( 'set colorcolumn=1,' , 'E474:' ) 795call assert_fails ( 'set colorcolumn=1;' , 'E474:' ) 796call assert_fails ( 'set cmdheight=-1' , 'E487:' ) 797call assert_fails ( 'set cmdwinheight=-1' , 'E487:' ) 798if has ( 'conceal' ) 799call assert_fails ( 'set conceallevel=-1' , 'E487:' ) 800call assert_fails ( 'set conceallevel=4' , 'E474:' ) 801endif 802call assert_fails ( 'set helpheight=-1' , 'E487:' ) 803call assert_fails ( 'set history=-1' , 'E487:' ) 804call assert_fails ( 'set report=-1' , 'E487:' ) 805call assert_fails ( 'set shiftwidth=-1' , 'E487:' ) 806call assert_fails ( 'set sidescroll=-1' , 'E487:' ) 807call assert_fails ( 'set tabstop=-1' , 'E487:' ) 808call assert_fails ( 'set tabstop=10000' , 'E474:' ) 809call assert_fails ( 'let &tabstop = 10000' , 'E474:' ) 810call assert_fails ( 'set tabstop=5500000000' , 'E474:' ) 811call assert_fails ( 'set textwidth=-1' , 'E487:' ) 812call assert_fails ( 'set timeoutlen=-1' , 'E487:' ) 813call assert_fails ( 'set updatecount=-1' , 'E487:' ) 814call assert_fails ( 'set updatetime=-1' , 'E487:' ) 815call assert_fails ( 'set winheight=-1' , 'E487:' ) 816call assert_fails ( 'set tabstop!' , 'E488:' ) 817 818" Test for setting unknown option errors 819call assert_fails ( 'set xxx' , 'E518:' ) 820call assert_fails ( 'setlocal xxx' , 'E518:' ) 821call assert_fails ( 'setglobal xxx' , 'E518:' ) 822call assert_fails ( 'set xxx=' , 'E518:' ) 823call assert_fails ( 'setlocal xxx=' , 'E518:' ) 824call assert_fails ( 'setglobal xxx=' , 'E518:' ) 825call assert_fails ( 'set xxx:' , 'E518:' ) 826call assert_fails ( 'setlocal xxx:' , 'E518:' ) 827call assert_fails ( 'setglobal xxx:' , 'E518:' ) 828call assert_fails ( 'set xxx!' , 'E518:' ) 829call assert_fails ( 'setlocal xxx!' , 'E518:' ) 830call assert_fails ( 'setglobal xxx!' , 'E518:' ) 831call assert_fails ( 'set xxx?' , 'E518:' ) 832call assert_fails ( 'setlocal xxx?' , 'E518:' ) 833call assert_fails ( 'setglobal xxx?' , 'E518:' ) 834call assert_fails ( 'set xxx&' , 'E518:' ) 835call assert_fails ( 'setlocal xxx&' , 'E518:' ) 836call assert_fails ( 'setglobal xxx&' , 'E518:' ) 837call assert_fails ( 'set xxx<' , 'E518:' ) 838call assert_fails ( 'setlocal xxx<' , 'E518:' ) 839call assert_fails ( 'setglobal xxx<' , 'E518:' ) 840 841" Test for missing-options errors. 842" call assert_fails('set autoprint?', 'E519:') 843" call assert_fails('set beautify?', 'E519:') 844" call assert_fails('set flash?', 'E519:') 845" call assert_fails('set graphic?', 'E519:') 846" call assert_fails('set hardtabs?', 'E519:') 847" call assert_fails('set mesg?', 'E519:') 848" call assert_fails('set novice?', 'E519:') 849" call assert_fails('set open?', 'E519:') 850" call assert_fails('set optimize?', 'E519:') 851" call assert_fails('set redraw?', 'E519:') 852" call assert_fails('set slowopen?', 'E519:') 853" call assert_fails('set sourceany?', 'E519:') 854" call assert_fails('set w300?', 'E519:') 855" call assert_fails('set w1200?', 'E519:') 856" call assert_fails('set w9600?', 'E519:') 857 858call assert_fails ( 'set undolevels=x' , 'E521:' ) 859call assert_fails ( 'set tabstop=' , 'E521:' ) 860call assert_fails ( 'set comments=-' , 'E524:' ) 861call assert_fails ( 'set comments=a' , 'E525:' ) 862call assert_fails ( 'set foldmarker=x' , 'E536:' ) 863call assert_fails ( 'set commentstring=x' , 'E537:' ) 864call assert_fails ( 'let &commentstring = "x"' , 'E537:' ) 865call assert_fails ( 'set complete=x' , 'E539:' ) 866 867" Test for 'statusline' errors 868call assert_fails ( 'set statusline=%^' , 'E539:' ) " Nvim: supports %$ 869call assert_fails ( 'set statusline=%{' , 'E540:' ) 870call assert_fails ( 'set statusline=%{%' , 'E540:' ) 871call assert_fails ( 'set statusline=%{%}' , 'E539:' ) 872call assert_fails ( 'set statusline=%(' , 'E542:' ) 873call assert_fails ( 'set statusline=%)' , 'E542:' ) 874 875" Test for 'tabline' errors 876call assert_fails ( 'set tabline=%^' , 'E539:' ) " Nvim: supports %$ 877call assert_fails ( 'set tabline=%{' , 'E540:' ) 878call assert_fails ( 'set tabline=%{%' , 'E540:' ) 879call assert_fails ( 'set tabline=%{%}' , 'E539:' ) 880call assert_fails ( 'set tabline=%(' , 'E542:' ) 881call assert_fails ( 'set tabline=%)' , 'E542:' ) 882 883" Test for 'rulerformat' errors 884call assert_fails ( 'set rulerformat=%-' , 'E539:' ) 885call assert_fails ( 'set rulerformat=%(' , 'E542:' ) 886call assert_fails ( 'set rulerformat=%15(%%' , 'E542:' ) 887 888if has ( 'cursorshape' ) 889" This invalid value for 'guicursor' used to cause Vim to crash. 890call assert_fails ( 'set guicursor=i-ci,r-cr:h' , 'E545:' ) 891call assert_fails ( 'set guicursor=i-ci' , 'E545:' ) 892call assert_fails ( 'set guicursor=x' , 'E545:' ) 893call assert_fails ( 'set guicursor=x:' , 'E546:' ) 894call assert_fails ( 'set guicursor=r-cr:horx' , 'E548:' ) 895call assert_fails ( 'set guicursor=r-cr:hor0' , 'E549:' ) 896endif 897 898if has ( 'mouseshape' ) 899call assert_fails ( 'se mouseshape=i-r:x' , 'E547:' ) 900endif 901 902" Test for 'backupext' and 'patchmode' set to the same value 903set backupext = .bak 904set patchmode = .patch 905call assert_fails ( 'set patchmode=.bak' , 'E589:' ) 906call assert_equal ( '.patch' , & patchmode ) 907call assert_fails ( 'set backupext=.patch' , 'E589:' ) 908call assert_equal ( '.bak' , & backupext ) 909set backupext & patchmode & 910 911" 'winheight' cannot be smaller than 'winminheight' 912call assert_fails ( 'set winminheight=10 winheight=9' , 'E591:' ) 913set winminheight & winheight & 914set winheight = 10 winminheight = 10 915call assert_fails ( 'set winheight=9' , 'E591:' ) 916set winminheight & winheight & 917 918" 'winwidth' cannot be smaller than 'winminwidth' 919call assert_fails ( 'set winminwidth=10 winwidth=9' , 'E592:' ) 920set winminwidth & winwidth & 921call assert_fails ( 'set winwidth=9 winminwidth=10' , 'E592:' ) 922set winwidth & winminwidth & 923 924call assert_fails ( "set showbreak=\x01" , 'E595:' ) 925" call assert_fails('set t_foo=', 'E846:') 926call assert_fails ( 'set tabstop??' , 'E488:' ) 927call assert_fails ( 'set wrapscan!!' , 'E488:' ) 928call assert_fails ( 'set tabstop&&' , 'E488:' ) 929call assert_fails ( 'set wrapscan<<' , 'E488:' ) 930call assert_fails ( 'set wrapscan=1' , 'E474:' ) 931call assert_fails ( 'set autoindent@' , 'E488:' ) 932call assert_fails ( 'set wildchar=<abc>' , 'E474:' ) 933call assert_fails ( 'set cmdheight=1a' , 'E521:' ) 934call assert_fails ( 'set invcmdheight' , 'E474:' ) 935if has ( 'python' ) || has ( 'python3' ) 936call assert_fails ( 'set pyxversion=6' , 'E474:' ) 937endif 938call assert_fails ( "let &tabstop='ab'" , [ 'E521:' , 'E521:' ]) 939call assert_fails ( 'set spellcapcheck=%\\(' , 'E54:' ) 940call assert_fails ( 'set sessionoptions=curdir,sesdir' , 'E474:' ) 941call assert_fails ( 'set foldmarker={{{,' , 'E474:' ) 942call assert_fails ( 'set sessionoptions=sesdir,curdir' , 'E474:' ) 943 944" 'ambiwidth' conflict 'listchars' 945setlocal listchars = trail:· 946call assert_fails ( 'set ambiwidth=double' , 'E834:' ) 947setlocal listchars = trail:- 948setglobal listchars=trail:· 949call assert_fails ( 'set ambiwidth=double' , 'E834:' ) 950set listchars & 951 952" 'ambiwidth' conflict 'fillchars' 953setlocal fillchars = stl:· 954call assert_fails ( 'set ambiwidth=double' , 'E835:' ) 955setlocal fillchars = stl:- 956setglobal fillchars=stl:· 957call assert_fails ( 'set ambiwidth=double' , 'E835:' ) 958set fillchars & 959 960call assert_fails ( 'set fileencoding=latin1,utf-8' , 'E474:' ) 961set nomodifiable 962call assert_fails ( 'set fileencoding=latin1' , 'E21:' ) 963set modifiable & 964" call assert_fails('set t_#-&', 'E522:') 965call assert_fails ( 'let &formatoptions = "?"' , 'E539:' ) 966call assert_fails ( 'call setbufvar("", "&formatoptions", "?")' , 'E539:' ) 967 968" Should raises only one error if passing a wrong variable type. 969call assert_fails ( 'call setwinvar(0, "&scrolloff", [])' , [ 'E745:' , 'E745:' ]) 970call assert_fails ( 'call setwinvar(0, "&list", [])' , [ 'E745:' , 'E745:' ]) 971call assert_fails ( 'call setwinvar(0, "&listchars", [])' , [ 'E730:' , 'E730:' ]) 972call assert_fails ( 'call setwinvar(0, "&nosuchoption", 0)' , [ 'E355:' , 'E355:' ]) 973call assert_fails ( 'call setwinvar(0, "&nosuchoption", "")' , [ 'E355:' , 'E355:' ]) 974call assert_fails ( 'call setwinvar(0, "&nosuchoption", [])' , [ 'E355:' , 'E355:' ]) 975endfunc 976 977func Test_set_encoding () 978throw 'skipped: Nvim supports ''utf8'' encoding only' 979let save_encoding = & encoding 980 981set enc = iso8859-1 982call assert_equal ( 'latin1' , & enc ) 983set enc = iso8859_1 984call assert_equal ( 'latin1' , & enc ) 985set enc = iso-8859-1 986call assert_equal ( 'latin1' , & enc ) 987set enc = iso_8859_1 988call assert_equal ( 'latin1' , & enc ) 989set enc = iso88591 990call assert_equal ( 'latin1' , & enc ) 991set enc = iso8859 992call assert_equal ( 'latin1' , & enc ) 993set enc = iso-8859 994call assert_equal ( 'latin1' , & enc ) 995set enc = iso_8859 996call assert_equal ( 'latin1' , & enc ) 997call assert_fails ( 'set enc=iso8858' , 'E474:' ) 998call assert_equal ( 'latin1' , & enc ) 999 1000let & encoding = save_encoding 1001endfunc 1002 1003func CheckWasSet ( name ) 1004let verb_cm = execute ( 'verbose set ' .. a: name .. '?' ) 1005call assert_match ( 'Last set from.*test_options.vim' , verb_cm ) 1006endfunc 1007func CheckWasNotSet ( name ) 1008let verb_cm = execute ( 'verbose set ' .. a: name .. '?' ) 1009call assert_notmatch ( 'Last set from' , verb_cm ) 1010endfunc 1011 1012" Must be executed before other tests that set 'term'. 1013func Test_000_term_option_verbose () 1014throw "Skipped: Nvim does not support setting 'term'" 1015CheckNotGui 1016 1017call CheckWasNotSet ( 't_cm' ) 1018 1019let term_save = & term 1020set term = ansi 1021call CheckWasSet ( 't_cm' ) 1022let & term = term_save 1023endfunc 1024 1025func Test_copy_context () 1026setlocal list 1027call CheckWasSet ( 'list' ) 1028split 1029call CheckWasSet ( 'list' ) 1030quit 1031setlocal nolist 1032 1033set ai 1034call CheckWasSet ( 'ai' ) 1035set filetype = perl 1036call CheckWasSet ( 'filetype' ) 1037set fo = tcroq 1038call CheckWasSet ( 'fo' ) 1039 1040split Xsomebuf 1041call CheckWasSet ( 'ai' ) 1042call CheckWasNotSet ( 'filetype' ) 1043call CheckWasSet ( 'fo' ) 1044endfunc 1045 1046func Test_set_ttytype () 1047throw "Skipped: Nvim does not support 'ttytype'" 1048CheckUnix 1049CheckNotGui 1050 1051" Setting 'ttytype' used to cause a double-free when exiting vim and 1052" when vim is compiled with -DEXITFREE. 1053set ttytype = ansi 1054call assert_equal ( 'ansi' , & ttytype ) 1055call assert_equal ( & ttytype , & term ) 1056set ttytype = xterm 1057call assert_equal ( 'xterm' , & ttytype ) 1058call assert_equal ( & ttytype , & term ) 1059try 1060set ttytype = 1061call assert_report ( 'set ttytype= did not fail' ) 1062catch /E529/ 1063endtry 1064 1065" Some systems accept any terminal name and return dumb settings, 1066" check for failure of finding the entry and for missing 'cm' entry. 1067try 1068set ttytype = xxx 1069call assert_report ( 'set ttytype=xxx did not fail' ) 1070catch /E522\|E437/ 1071endtry 1072 1073set ttytype & 1074call assert_equal ( & ttytype , & term ) 1075 1076if has ( 'gui' ) && ! has ( 'gui_running' ) 1077call assert_fails ( 'set term=gui' , 'E531:' ) 1078endif 1079endfunc 1080 1081" Test for :set all 1082func Test_set_all () 1083set tw = 75 1084set iskeyword = a-z,A-Z 1085set nosplitbelow 1086let out = execute ( 'set all' ) 1087call assert_match ( 'textwidth=75' , out ) 1088call assert_match ( 'iskeyword=a-z,A-Z' , out ) 1089call assert_match ( 'nosplitbelow' , out ) 1090set tw & iskeyword & splitbelow & 1091endfunc 1092 1093" Test for :set! all 1094func Test_set_all_one_column () 1095let out_mult = execute ( 'set all' ) ->split ( "\n" ) 1096let out_one = execute ( 'set! all' ) ->split ( "\n" ) 1097call assert_true ( len ( out_mult ) < len ( out_one )) 1098call assert_equal ( out_one [ 0 ], '--- Options ---' ) 1099let options = out_one [ 1 :] ->mapnew ({ _ , line ->line [ 2 :]}) 1100call assert_equal ( sort ( copy ( options )), options ) 1101endfunc 1102 1103func Test_renderoptions () 1104throw 'skipped: Nvim does not support renderoptions' 1105" Only do this for Windows Vista and later, fails on Windows XP and earlier. 1106" Doesn't hurt to do this on a non-Windows system. 1107if windowsversion () !~ '^[345]\.' 1108set renderoptions = type:directx 1109set rop = type:directx 1110endif 1111endfunc 1112 1113func ResetIndentexpr () 1114set indentexpr = 1115endfunc 1116 1117func Test_set_indentexpr () 1118" this was causing usage of freed memory 1119set indentexpr = ResetIndentexpr () 1120new 1121call feedkeys ( "i\<c-f>" , 'x' ) 1122call assert_equal ( '' , & indentexpr ) 1123bwipe ! 1124endfunc 1125 1126func Test_backupskip () 1127" Option 'backupskip' may contain several comma-separated path 1128" specifications if one or more of the environment variables TMPDIR, TMP, 1129" or TEMP is defined. To simplify testing, convert the string value into a 1130" list. 1131let bsklist = split ( & bsk , ',' ) 1132 1133if has ( "mac" ) 1134let found = ( index ( bsklist , '/private/tmp/*' ) >= 0 ) 1135call assert_true ( found , '/private/tmp not in option bsk: ' . & bsk ) 1136elseif has ( "unix" ) 1137let found = ( index ( bsklist , '/tmp/*' ) >= 0 ) 1138call assert_true ( found , '/tmp not in option bsk: ' . & bsk ) 1139endif 1140 1141" If our test platform is Windows, the path(s) in option bsk will use 1142" backslash for the path separator and the components could be in short 1143" (8.3) format. As such, we need to replace the backslashes with forward 1144" slashes and convert the path components to long format. The expand() 1145" function will do this but it cannot handle comma-separated paths. This is 1146" why bsk was converted from a string into a list of strings above. 1147" 1148" One final complication is that the wildcard "/*" is at the end of each 1149" path and so expand() might return a list of matching files. To prevent 1150" this, we need to remove the wildcard before calling expand() and then 1151" append it afterwards. 1152if has ( 'win32' ) 1153let item_nbr = 0 1154while item_nbr < len ( bsklist ) 1155let path_spec = bsklist [ item_nbr ] 1156let path_spec = strcharpart ( path_spec , 0 , strlen ( path_spec ) - 2 ) 1157let path_spec = substitute ( expand ( path_spec ), '\\' , '/' , 'g' ) 1158let bsklist [ item_nbr ] = path_spec . '/*' 1159let item_nbr += 1 1160endwhile 1161endif 1162 1163" Option bsk will also include these environment variables if defined. 1164" If they're defined, verify they appear in the option value. 1165for var in [ '$TMPDIR' , '$TMP' , '$TEMP' ] 1166if exists ( var ) 1167let varvalue = substitute ( expand ( var ), '\\' , '/' , 'g' ) 1168let varvalue = substitute ( varvalue , '/$' , '' , '' ) 1169let varvalue .= '/*' 1170let found = ( index ( bsklist , varvalue ) >= 0 ) 1171call assert_true ( found , var . ' (' . varvalue . ') not in option bsk: ' . & bsk ) 1172endif 1173endfor 1174 1175" Duplicates from environment variables should be filtered out (option has 1176" P_NODUP). Run this in a separate instance and write v:errors in a file, 1177" so that we see what happens on startup. 1178let after =<< trim [CODE] 1179let bsklist = split(&backupskip, ',') 1180call assert_equal(uniq(copy(bsklist)), bsklist) 1181call writefile(['errors:'] + v:errors, 'Xtestout') 1182qall 1183[CODE] 1184call writefile ( after , 'Xafter' , 'D' ) 1185" let cmd = GetVimProg() . ' --clean --not-a-term -S Xafter --cmd "set enc=utf8"' 1186let cmd = GetVimProg () . ' --clean -S Xafter --cmd "set enc=utf8"' 1187 1188let saveenv = {} 1189for var in [ 'TMPDIR' , 'TMP' , 'TEMP' ] 1190let saveenv [ var ] = getenv ( var ) 1191call setenv ( var , '/duplicate/path' ) 1192endfor 1193 1194" set $HOME='', so that Vim won't try to read init files 1195let saveenv [ 'HOME' ] = getenv ( "HOME" ) 1196call setenv ( 'HOME' , '' ) 1197exe 'silent !' . cmd 1198call assert_equal ([ 'errors:' ], readfile ( 'Xtestout' )) 1199 1200" restore environment variables 1201for var in [ 'TMPDIR' , 'TMP' , 'TEMP' , 'HOME' ] 1202call setenv ( var , saveenv [ var ]) 1203endfor 1204 1205call delete ( 'Xtestout' ) 1206 1207" Duplicates should be filtered out (option has P_NODUP) 1208let backupskip = & backupskip 1209set backupskip = 1210set backupskip += /test/dir 1211set backupskip += /other/dir 1212set backupskip += /test/dir 1213call assert_equal ( '/test/dir,/other/dir' , & backupskip ) 1214let & backupskip = backupskip 1215endfunc 1216 1217func Test_buf_copy_winopt () 1218set hidden 1219 1220" Test copy option from current buffer in window 1221split 1222enew 1223setlocal numberwidth = 5 1224wincmd w 1225call assert_equal ( 4 , & numberwidth ) 1226bnext 1227call assert_equal ( 5 , & numberwidth ) 1228bw ! 1229call assert_equal ( 4 , & numberwidth ) 1230 1231" Test copy value from window that used to be display the buffer 1232split 1233enew 1234setlocal numberwidth = 6 1235bnext 1236wincmd w 1237call assert_equal ( 4 , & numberwidth ) 1238bnext 1239call assert_equal ( 6 , & numberwidth ) 1240bw ! 1241 1242" Test that if buffer is current, don't use the stale cached value 1243" from the last time the buffer was displayed. 1244split 1245enew 1246setlocal numberwidth = 7 1247bnext 1248bnext 1249setlocal numberwidth = 8 1250wincmd w 1251call assert_equal ( 4 , & numberwidth ) 1252bnext 1253call assert_equal ( 8 , & numberwidth ) 1254bw ! 1255 1256" Test value is not copied if window already has seen the buffer 1257enew 1258split 1259setlocal numberwidth = 9 1260bnext 1261setlocal numberwidth = 10 1262wincmd w 1263call assert_equal ( 4 , & numberwidth ) 1264bnext 1265call assert_equal ( 4 , & numberwidth ) 1266bw ! 1267 1268set hidden & 1269endfunc 1270 1271func Test_split_copy_options () 1272let values = [ 1273 \[ 'cursorbind' , 1 , 0 ], 1274 \[ 'fillchars' , '"vert:-"' , '"' .. & fillchars .. '"' ], 1275 \[ 'list' , 1 , 0 ], 1276 \[ 'listchars' , '"space:-"' , '"' .. & listchars .. '"' ], 1277 \[ 'number' , 1 , 0 ], 1278 \[ 'relativenumber' , 1 , 0 ], 1279 \[ 'scrollbind' , 1 , 0 ], 1280 \[ 'smoothscroll' , 1 , 0 ], 1281 \[ 'virtualedit' , '"block"' , '"' .. & virtualedit .. '"' ], 1282"\ ['wincolor', '"Search"', '"' .. &wincolor .. '"'], 1283 \[ 'wrap' , 0 , 1 ], 1284 \] 1285if has ( 'linebreak' ) 1286let values += [ 1287 \[ 'breakindent' , 1 , 0 ], 1288 \[ 'breakindentopt' , '"min:5"' , '"' .. & breakindentopt .. '"' ], 1289 \[ 'linebreak' , 1 , 0 ], 1290 \[ 'numberwidth' , 7 , 4 ], 1291 \[ 'showbreak' , '"++"' , '"' .. & showbreak .. '"' ], 1292 \] 1293endif 1294if has ( 'rightleft' ) 1295let values += [ 1296 \[ 'rightleft' , 1 , 0 ], 1297 \[ 'rightleftcmd' , '"search"' , '"' .. & rightleftcmd .. '"' ], 1298 \] 1299endif 1300if has ( 'statusline' ) 1301let values += [ 1302 \[ 'statusline' , '"---%f---"' , '"' .. & statusline .. '"' ], 1303 \] 1304endif 1305if has ( 'spell' ) 1306let values += [ 1307 \[ 'spell' , 1 , 0 ], 1308 \] 1309endif 1310if has ( 'syntax' ) 1311let values += [ 1312 \[ 'cursorcolumn' , 1 , 0 ], 1313 \[ 'cursorline' , 1 , 0 ], 1314 \[ 'cursorlineopt' , '"screenline"' , '"' .. & cursorlineopt .. '"' ], 1315 \[ 'colorcolumn' , '"+1"' , '"' .. & colorcolumn .. '"' ], 1316 \] 1317endif 1318if has ( 'diff' ) 1319let values += [ 1320 \[ 'diff' , 1 , 0 ], 1321 \] 1322endif 1323if has ( 'conceal' ) 1324let values += [ 1325 \[ 'concealcursor' , '"nv"' , '"' .. & concealcursor .. '"' ], 1326 \[ 'conceallevel' , '3' , & conceallevel ], 1327 \] 1328endif 1329if has ( 'terminal' ) 1330let values += [ 1331 \[ 'termwinkey' , '"<C-X>"' , '"' .. & termwinkey .. '"' ], 1332 \[ 'termwinsize' , '"10x20"' , '"' .. & termwinsize .. '"' ], 1333 \] 1334endif 1335if has ( 'folding' ) 1336let values += [ 1337 \[ 'foldcolumn' , '"5"' , & foldcolumn ], 1338 \[ 'foldenable' , 0 , 1 ], 1339 \[ 'foldexpr' , '"2 + 3"' , '"' .. & foldexpr .. '"' ], 1340 \[ 'foldignore' , '"+="' , '"' .. & foldignore .. '"' ], 1341 \[ 'foldlevel' , 4 , & foldlevel ], 1342 \[ 'foldmarker' , '">>,<<"' , '"' .. & foldmarker .. '"' ], 1343 \[ 'foldmethod' , '"marker"' , '"' .. & foldmethod .. '"' ], 1344 \[ 'foldminlines' , 3 , & foldminlines ], 1345 \[ 'foldnestmax' , 17 , & foldnestmax ], 1346 \[ 'foldtext' , '"closed"' , '"' .. & foldtext .. '"' ], 1347 \] 1348endif 1349if has ( 'signs' ) 1350let values += [ 1351 \[ 'signcolumn' , '"number"' , '"' .. & signcolumn .. '"' ], 1352 \] 1353endif 1354 1355" set options to non-default value 1356for item in values 1357exe $ "let &{item[0]} = {item[1]}" 1358endfor 1359 1360" check values are set in new window 1361split 1362for item in values 1363exe $ 'call assert_equal({item[1]}, &{item[0]}, "{item[0]}")' 1364endfor 1365 1366" restore 1367close 1368for item in values 1369exe $ "let &{item[0]} = {item[1]}" 1370endfor 1371endfunc 1372 1373func Test_shortmess_F () 1374new 1375call assert_match ( '\[No Name\]' , execute ( 'file' )) 1376set shortmess += F 1377call assert_match ( '\[No Name\]' , execute ( 'file' )) 1378call assert_match ( '^\s*$' , execute ( 'file foo' )) 1379call assert_match ( 'foo' , execute ( 'file' )) 1380set shortmess -= F 1381call assert_match ( 'bar' , execute ( 'file bar' )) 1382call assert_match ( 'bar' , execute ( 'file' )) 1383set shortmess & 1384bwipe 1385endfunc 1386 1387func Test_shortmess_F2 () 1388e file1 1389e file2 1390call assert_match ( 'file1' , execute ( 'bn' , '' )) 1391call assert_match ( 'file2' , execute ( 'bn' , '' )) 1392set shortmess += F 1393call assert_true ( empty ( execute ( 'bn' , '' ))) 1394" call assert_false(test_getvalue('need_fileinfo')) 1395call assert_true ( empty ( execute ( 'bn' , '' ))) 1396" call assert_false(test_getvalue('need_fileinfo')) 1397set hidden 1398call assert_true ( empty ( execute ( 'bn' , '' ))) 1399" call assert_false(test_getvalue('need_fileinfo')) 1400call assert_true ( empty ( execute ( 'bn' , '' ))) 1401" call assert_false(test_getvalue('need_fileinfo')) 1402set nohidden 1403call assert_true ( empty ( execute ( 'bn' , '' ))) 1404" call assert_false(test_getvalue('need_fileinfo')) 1405call assert_true ( empty ( execute ( 'bn' , '' ))) 1406" call assert_false(test_getvalue('need_fileinfo')) 1407set shortmess -= F" Accommodate Nvim default. 1408call assert_match ( 'file1' , execute ( 'bn' , '' )) 1409call assert_match ( 'file2' , execute ( 'bn' , '' )) 1410bwipe 1411bwipe 1412" call assert_fails('call test_getvalue("abc")', 'E475:') 1413endfunc 1414 1415func Test_shortmess_F3 () 1416call writefile ([ 'foo' ], 'X_dummy' , 'D' ) 1417 1418set hidden 1419set autoread 1420e X_dummy 1421e Xotherfile 1422call assert_equal ([ 'foo' ], getbufline ( 'X_dummy' , 1 , '$' )) 1423set shortmess += F 1424echo '' 1425 1426if has ( 'nanotime' ) 1427sleep 10m 1428else 1429sleep 3 1430endif 1431call writefile ([ 'bar' ], 'X_dummy' ) 1432bprev 1433call assert_equal ( '' , Screenline ( & lines )) 1434call assert_equal ([ 'bar' ], getbufline ( 'X_dummy' , 1 , '$' )) 1435 1436if has ( 'nanotime' ) 1437sleep 10m 1438else 1439sleep 3 1440endif 1441call writefile ([ 'baz' ], 'X_dummy' ) 1442checktime 1443call assert_equal ( '' , Screenline ( & lines )) 1444call assert_equal ([ 'baz' ], getbufline ( 'X_dummy' , 1 , '$' )) 1445 1446set shortmess & 1447set autoread & 1448set hidden & 1449bwipe X_dummy 1450bwipe Xotherfile 1451endfunc 1452 1453func Test_local_scrolloff () 1454set so = 5 1455set siso = 7 1456split 1457call assert_equal ( 5 , & so ) 1458setlocal so = 3 1459call assert_equal ( 3 , & so ) 1460wincmd w 1461call assert_equal ( 5 , & so ) 1462wincmd w 1463call assert_equal ( 3 , & so ) 1464"setlocal so< 1465set so < 1466call assert_equal ( 5 , & so ) 1467setglob so=8 1468call assert_equal ( 8 , & so ) 1469call assert_equal ( -1 , & l: so ) 1470setlocal so = 0 1471call assert_equal ( 0 , & so ) 1472setlocal so = -1 1473call assert_equal ( 8 , & so ) 1474 1475call assert_equal ( 7 , & siso ) 1476setlocal siso = 3 1477call assert_equal ( 3 , & siso ) 1478wincmd w 1479call assert_equal ( 7 , & siso ) 1480wincmd w 1481call assert_equal ( 3 , & siso ) 1482"setlocal siso< 1483set siso < 1484call assert_equal ( 7 , & siso ) 1485setglob siso=4 1486call assert_equal ( 4 , & siso ) 1487call assert_equal ( -1 , & l: siso ) 1488setlocal siso = 0 1489call assert_equal ( 0 , & siso ) 1490setlocal siso = -1 1491call assert_equal ( 4 , & siso ) 1492 1493close 1494set so & 1495set siso & 1496endfunc 1497 1498func Test_local_scrolloffpad () 1499let save_g_sop = & g: sop 1500let save_l_sop = & l: sop 1501set sop = 0 1502call assert_equal ( 0 , & g: sop ) 1503call assert_equal ( -1 , & l: sop ) 1504call assert_equal ( 0 , & sop ) 1505setglobal sop=1 1506call assert_equal ( 1 , & g: sop ) 1507call assert_equal ( 1 , & sop ) 1508split 1509call assert_equal ( 1 , & g: sop ) 1510call assert_equal ( -1 , & l: sop ) 1511call assert_equal ( 1 , & sop ) 1512setlocal sop = 0 1513call assert_equal ( 0 , & l: sop ) 1514call assert_equal ( 0 , & sop ) 1515call assert_equal ( 1 , & g: sop ) 1516wincmd p 1517call assert_equal ( 1 , & sop ) 1518wincmd p 1519"setlocal sop< 1520set sop < 1521call assert_equal ( -1 , & l: sop ) 1522call assert_equal ( 1 , & sop ) 1523setlocal sop = 2 1524call assert_equal ( 2 , & l: sop ) 1525call assert_equal ( 2 , & sop ) 1526setlocal sop = -1 1527call assert_equal ( -1 , & l: sop ) 1528call assert_equal ( 1 , & sop ) " Uses global value because local is -1 1529call assert_fails ( "setlocal sop=-2" , 'E474:' ) 1530call assert_equal ( -1 , & l: sop ) 1531call assert_equal ( 1 , & sop ) 1532call assert_fails ( "setlocal sop=foo" , 'E521:' ) 1533close 1534let & g: sop = save_g_sop 1535let & l: sop = save_l_sop 1536endfunc 1537 1538func Test_writedelay () 1539CheckFunction reltimefloat 1540 1541new 1542call setline ( 1 , 'empty' ) 1543" Nvim: 'writedelay' is applied per screen line. 1544" Create 7 vertical splits first. 1545vs |vs |vs |vs |vs |vs 1546redraw 1547set writedelay = 10 1548let start = reltime () 1549" call setline(1, repeat('x', 70)) 1550" Nvim: enable 'writedelay' per screen line. 1551" In each of the 7 vertical splits, 10 screen lines need to be drawn. 1552set redrawdebug += line 1553call setline ( 1 , repeat ([ 'x' ], 10 )) 1554redraw 1555let elapsed = reltimefloat ( reltime ( start )) 1556set writedelay = 0 1557" With 'writedelay' set should take at least 30 * 10 msec 1558call assert_inrange ( 30 * 0.01 , 999.0 , elapsed ) 1559 1560bwipe ! 1561endfunc 1562 1563func Test_visualbell () 1564set belloff = 1565set visualbell 1566call assert_beeps ( 'normal 0h' ) 1567set novisualbell 1568set belloff = all 1569endfunc 1570 1571" Test for the 'write' option 1572func Test_write () 1573new 1574call setline ( 1 , [ 'L1' ]) 1575set nowrite 1576call assert_fails ( 'write Xwrfile' , 'E142:' ) 1577set write 1578" close swapfile 1579bw ! 1580endfunc 1581 1582" Test for 'buftype' option 1583func Test_buftype () 1584new 1585call setline ( 1 , [ 'L1' ]) 1586set buftype = nowrite 1587call assert_fails ( 'write' , 'E382:' ) 1588 1589" for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] 1590for val in [ '' , 'nofile' , 'nowrite' , 'acwrite' , 'quickfix' , 'help' , 'prompt' ] 1591exe 'set buftype=' .. val 1592call writefile ([ 'something' ], 'XBuftype' ) 1593call assert_fails ( 'write XBuftype' , 'E13:' , 'with buftype=' .. val ) 1594endfor 1595 1596call delete ( 'XBuftype' ) 1597bwipe ! 1598endfunc 1599 1600" Test for the 'rightleftcmd' option 1601func Test_rightleftcmd () 1602CheckFeature rightleft 1603set rightleft 1604 1605let g: l = [] 1606func AddPos () 1607call add ( g: l , screencol ()) 1608return '' 1609endfunc 1610cmap <expr> < F2 > AddPos () 1611 1612set rightleftcmd = 1613call feedkeys ( "/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" .. 1614 \"\<Right>\<F2>\<Esc>" , 'xt' ) 1615call assert_equal ([ 2 , 5 , 3 , 4 ], g: l ) 1616 1617let g: l = [] 1618set rightleftcmd = search 1619call feedkeys ( "/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. 1620 \"\<Left>\<F2>\<Esc>" , 'xt' ) 1621call assert_equal ([ & co - 1 , & co - 4 , & co - 2 , & co - 3 ], g: l ) 1622 1623cunmap <F2> 1624unlet g: l 1625set rightleftcmd & 1626set rightleft & 1627endfunc 1628 1629" Test for the 'debug' option 1630func Test_debug_option () 1631" redraw to avoid matching previous messages 1632redraw 1633set debug = beep 1634exe "normal \<C-c>" 1635call assert_equal ( 'Beep!' , Screenline ( & lines )) 1636call assert_equal ( 'line 4:' , Screenline ( & lines - 1 )) 1637" also check a line above, with a certain window width the colon is there 1638call assert_match ( 'Test_debug_option:$' , 1639 \Screenline ( & lines - 3 ) .. Screenline ( & lines - 2 )) 1640set debug & 1641endfunc 1642 1643" Test for the default CDPATH option 1644func Test_opt_default_cdpath () 1645let after =<< trim [CODE] 1646call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) 1647call writefile(v:errors, 'Xtestout') 1648qall 1649[CODE] 1650if has ( 'unix' ) 1651let $ CDPATH = '/path/to/dir1:/path/to/dir2' 1652else 1653let $ CDPATH = '/path/to/dir1;/path/to/dir2' 1654endif 1655if RunVim ([], after , '' ) 1656call assert_equal ([], readfile ( 'Xtestout' )) 1657call delete ( 'Xtestout' ) 1658endif 1659endfunc 1660 1661" Test for setting keycodes using set 1662func Test_opt_set_keycode () 1663" call assert_fails('set <t_k1=l', 'E474:') 1664" call assert_fails('set <Home=l', 'E474:') 1665call assert_fails ( 'set <t_k1=l' , 'E518:' ) 1666call assert_fails ( 'set <Home=l' , 'E518:' ) 1667set <t_k9>=abcd 1668" call assert_equal('abcd', &t_k9) 1669set <t_k9>& 1670set <F9>=xyz 1671" call assert_equal('xyz', &t_k9) 1672set <t_k9>& 1673endfunc 1674 1675" Test for changing options in a sandbox 1676func Test_opt_sandbox () 1677for opt in [ 'backupdir' , 'cdpath' , 'exrc' , 'findfunc' ] 1678call assert_fails ( 'sandbox set ' .. opt .. '?' , 'E48:' ) 1679call assert_fails ( 'sandbox let &' .. opt .. ' = 1' , 'E48:' ) 1680endfor 1681call assert_fails ( 'sandbox let &modelineexpr = 1' , 'E48:' ) 1682endfunc 1683 1684" Test for setting string global-local option value 1685func Test_set_string_global_local_option () 1686setglobal equalprg=gprg 1687setlocal equalprg = lprg 1688call assert_equal ( 'gprg' , & g: equalprg ) 1689call assert_equal ( 'lprg' , & l: equalprg ) 1690call assert_equal ( 'lprg' , & equalprg ) 1691 1692" :set {option}< removes the local value, so that the global value will be used. 1693set equalprg < 1694call assert_equal ( '' , & l: equalprg ) 1695call assert_equal ( 'gprg' , & equalprg ) 1696 1697" :setlocal {option}< set the effective value of {option} to its global value. 1698setglobal equalprg=gnewprg 1699setlocal equalprg = lnewprg 1700setlocal equalprg < 1701call assert_equal ( 'gnewprg' , & l: equalprg ) 1702call assert_equal ( 'gnewprg' , & equalprg ) 1703 1704set equalprg & 1705endfunc 1706 1707" Test for setting number global-local option value 1708func Test_set_number_global_local_option () 1709setglobal scrolloff=10 1710setlocal scrolloff = 12 1711call assert_equal ( 10 , & g: scrolloff ) 1712call assert_equal ( 12 , & l: scrolloff ) 1713call assert_equal ( 12 , & scrolloff ) 1714 1715" :setlocal {option}< set the effective value of {option} to its global value. 1716"set scrolloff< 1717setlocal scrolloff < 1718call assert_equal ( 10 , & l: scrolloff ) 1719call assert_equal ( 10 , & scrolloff ) 1720 1721" :set {option}< removes the local value, so that the global value will be used. 1722setglobal scrolloff=15 1723setlocal scrolloff = 18 1724"setlocal scrolloff< 1725set scrolloff < 1726call assert_equal ( -1 , & l: scrolloff ) 1727call assert_equal ( 15 , & scrolloff ) 1728 1729set scrolloff & 1730endfunc 1731 1732" Test for setting boolean global-local option value 1733func Test_set_boolean_global_local_option () 1734CheckUnix 1735 1736setglobal autoread fsync 1737setlocal noautoread nofsync 1738call assert_equal ( 1 , & g: autoread ) 1739call assert_equal ( 0 , & l: autoread ) 1740call assert_equal ( 0 , & autoread ) 1741call assert_equal ( 1 , & g: fsync ) 1742call assert_equal ( 0 , & l: fsync ) 1743call assert_equal ( 0 , & fsync ) 1744 1745" :setlocal {option}< set the effective value of {option} to its global value. 1746"set autoread< fsync< 1747setlocal autoread < fsync< 1748call assert_equal ( 1 , & l: autoread ) 1749call assert_equal ( 1 , & autoread ) 1750call assert_equal ( 1 , & l: fsync ) 1751call assert_equal ( 1 , & fsync ) 1752 1753" :set {option}< removes the local value, so that the global value will be used. 1754setglobal noautoread nofsync 1755setlocal autoread fsync 1756"setlocal autoread< fsync< 1757set autoread < fsync< 1758call assert_equal ( -1 , & l: autoread ) 1759call assert_equal ( 0 , & autoread ) 1760call assert_equal ( -1 , & l: fsync ) 1761call assert_equal ( 0 , & fsync ) 1762 1763set autoread & fsync & 1764endfunc 1765 1766func Test_set_in_sandbox () 1767" Some boolean options cannot be set in sandbox, some can. 1768call assert_fails ( 'sandbox set modelineexpr' , 'E48:' ) 1769sandbox set number 1770call assert_true ( & number ) 1771set number & 1772 1773" Some boolean options cannot be set in sandbox, some can. 1774if has ( 'python' ) || has ( 'python3' ) 1775call assert_fails ( 'sandbox set pyxversion=3' , 'E48:' ) 1776endif 1777sandbox set tabstop=4 1778call assert_equal ( 4 , & tabstop ) 1779set tabstop & 1780 1781" Some string options cannot be set in sandbox, some can. 1782call assert_fails ( 'sandbox set backupdir=/tmp' , 'E48:' ) 1783sandbox set filetype=perl 1784call assert_equal ( 'perl' , & filetype ) 1785set filetype & 1786endfunc 1787 1788" Test for setting string option value 1789func Test_set_string_option () 1790" :set {option}= 1791set makeprg = 1792call assert_equal ( '' , & mp ) 1793set makeprg = abc 1794call assert_equal ( 'abc' , & mp ) 1795 1796" :set {option}: 1797set makeprg : 1798call assert_equal ( '' , & mp ) 1799set makeprg : abc 1800call assert_equal ( 'abc' , & mp ) 1801 1802" Let string 1803let & makeprg = '' 1804call assert_equal ( '' , & mp ) 1805let & makeprg = 'abc' 1806call assert_equal ( 'abc' , & mp ) 1807 1808" Let number converts to string 1809let & makeprg = 42 1810call assert_equal ( '42' , & mp ) 1811 1812" Appending 1813set makeprg = abc 1814set makeprg += def 1815call assert_equal ( 'abcdef' , & mp ) 1816set makeprg += def 1817call assert_equal ( 'abcdefdef' , & mp , ':set+= appends a value even if it already contained' ) 1818let & makeprg .= 'gh' 1819call assert_equal ( 'abcdefdefgh' , & mp ) 1820let & makeprg ..= 'ij' 1821call assert_equal ( 'abcdefdefghij' , & mp ) 1822 1823" Removing 1824set makeprg = abcdefghi 1825set makeprg -= def 1826call assert_equal ( 'abcghi' , & mp ) 1827set makeprg -= def 1828call assert_equal ( 'abcghi' , & mp , ':set-= does not remove a value if it is not contained' ) 1829 1830" Prepending 1831set makeprg = abc 1832set makeprg ^=def 1833call assert_equal ( 'defabc' , & mp ) 1834set makeprg ^=def 1835call assert_equal ( 'defdefabc' , & mp , ':set+= prepends a value even if it already contained' ) 1836 1837set makeprg & 1838endfunc 1839 1840" Test for setting string comma-separated list option value 1841func Test_set_string_comma_list_option () 1842" :set {option}= 1843set wildignore = 1844call assert_equal ( '' , & wildignore ) 1845set wildignore = *.png 1846call assert_equal ( '*.png' , & wildignore ) 1847 1848" :set {option}: 1849set wildignore : 1850call assert_equal ( '' , & wildignore ) 1851set wildignore : *.png 1852call assert_equal ( '*.png' , & wildignore ) 1853 1854" Let string 1855let & wildignore = '' 1856call assert_equal ( '' , & wildignore ) 1857let & wildignore = '*.png' 1858call assert_equal ( '*.png' , & wildignore ) 1859 1860" Let number converts to string 1861let & wildignore = 42 1862call assert_equal ( '42' , & wildignore ) 1863 1864" Appending 1865set wildignore = *.png 1866set wildignore += *.jpg 1867call assert_equal ( '*.png,*.jpg' , & wildignore , ':set+= prepends a comma to append a value' ) 1868set wildignore += *.jpg 1869call assert_equal ( '*.png,*.jpg' , & wildignore , ':set+= does not append a value if it already contained' ) 1870set wildignore += jpg 1871call assert_equal ( '*.png,*.jpg,jpg' , & wildignore , ':set+= prepends a comma to append a value if it is not exactly match to item' ) 1872let & wildignore .= 'foo' 1873call assert_equal ( '*.png,*.jpg,jpgfoo' , & wildignore , ':let-& .= appends a value without a comma' ) 1874let & wildignore ..= 'bar' 1875call assert_equal ( '*.png,*.jpg,jpgfoobar' , & wildignore , ':let-& ..= appends a value without a comma' ) 1876 1877" Removing 1878set wildignore = *.png,*.jpg,*.obj 1879set wildignore -= *.jpg 1880call assert_equal ( '*.png,*.obj' , & wildignore ) 1881set wildignore -= *.jpg 1882call assert_equal ( '*.png,*.obj' , & wildignore , ':set-= does not remove a value if it is not contained' ) 1883set wildignore -= jpg 1884call assert_equal ( '*.png,*.obj' , & wildignore , ':set-= does not remove a value if it is not exactly match to item' ) 1885 1886" Prepending 1887set wildignore = *.png 1888set wildignore ^=*.jpg 1889call assert_equal ( '*.jpg,*.png' , & wildignore ) 1890set wildignore ^=*.jpg 1891call assert_equal ( '*.jpg,*.png' , & wildignore , ':set+= does not prepend a value if it already contained' ) 1892set wildignore ^=jpg 1893call assert_equal ( 'jpg,*.jpg,*.png' , & wildignore , ':set+= prepend a value if it is not exactly match to item' ) 1894 1895set wildignore & 1896endfunc 1897 1898" Test for setting string flags option value 1899func Test_set_string_flags_option () 1900" :set {option}= 1901set formatoptions = 1902call assert_equal ( '' , & fo ) 1903set formatoptions = abc 1904call assert_equal ( 'abc' , & fo ) 1905 1906" :set {option}: 1907set formatoptions : 1908call assert_equal ( '' , & fo ) 1909set formatoptions : abc 1910call assert_equal ( 'abc' , & fo ) 1911 1912" Let string 1913let & formatoptions = '' 1914call assert_equal ( '' , & fo ) 1915let & formatoptions = 'abc' 1916call assert_equal ( 'abc' , & fo ) 1917 1918" Let number converts to string 1919let & formatoptions = 12 1920call assert_equal ( '12' , & fo ) 1921 1922" Appending 1923set formatoptions = abc 1924set formatoptions += pqr 1925call assert_equal ( 'abcpqr' , & fo ) 1926set formatoptions += pqr 1927call assert_equal ( 'abcpqr' , & fo , ':set+= does not append a value if it already contained' ) 1928let & formatoptions .= 'r' 1929call assert_equal ( 'abcpqrr' , & fo , ':let-& .= appends a value even if it already contained' ) 1930let & formatoptions ..= 'r' 1931call assert_equal ( 'abcpqrrr' , & fo , ':let-& ..= appends a value even if it already contained' ) 1932 1933" Removing 1934set formatoptions = abcpqr 1935set formatoptions -= cp 1936call assert_equal ( 'abqr' , & fo ) 1937set formatoptions -= cp 1938call assert_equal ( 'abqr' , & fo , ':set-= does not remove a value if it is not contained' ) 1939set formatoptions -= ar 1940call assert_equal ( 'abqr' , & fo , ':set-= does not remove a value if it is not exactly match' ) 1941 1942" Prepending 1943set formatoptions = abc 1944set formatoptions ^=pqr 1945call assert_equal ( 'pqrabc' , & fo ) 1946set formatoptions ^=qr 1947call assert_equal ( 'pqrabc' , & fo , ':set+= does not prepend a value if it already contained' ) 1948 1949set formatoptions & 1950endfunc 1951 1952" Test for setting number option value 1953func Test_set_number_option () 1954" :set {option}= 1955set scrolljump = 5 1956call assert_equal ( 5 , & sj ) 1957set scrolljump = -3 1958call assert_equal ( -3 , & sj ) 1959 1960" :set {option}: 1961set scrolljump : 7 1962call assert_equal ( 7 , & sj ) 1963set scrolljump : -5 1964call assert_equal ( -5 , & sj ) 1965 1966" Set hex 1967set scrolljump = 0x10 1968call assert_equal ( 16 , & sj ) 1969set scrolljump = -0x10 1970call assert_equal ( -16 , & sj ) 1971set scrolljump = 0X12 1972call assert_equal ( 18 , & sj ) 1973set scrolljump = -0X12 1974call assert_equal ( -18 , & sj ) 1975 1976" Set octal 1977set scrolljump = 010 1978call assert_equal ( 8 , & sj ) 1979set scrolljump = -010 1980call assert_equal ( -8 , & sj ) 1981set scrolljump = 0o12 1982call assert_equal ( 10 , & sj ) 1983set scrolljump = -0o12 1984call assert_equal ( -10 , & sj ) 1985set scrolljump = 0O15 1986call assert_equal ( 13 , & sj ) 1987set scrolljump = -0O15 1988call assert_equal ( -13 , & sj ) 1989 1990" Let number 1991let & scrolljump = 4 1992call assert_equal ( 4 , & sj ) 1993let & scrolljump = -6 1994call assert_equal ( -6 , & sj ) 1995 1996" Let numeric string converts to number 1997let & scrolljump = '7' 1998call assert_equal ( 7 , & sj ) 1999let & scrolljump = '-9' 2000call assert_equal ( -9 , & sj ) 2001 2002" Incrementing 2003set shiftwidth = 4 2004set sw += 2 2005call assert_equal ( 6 , & sw ) 2006let & shiftwidth += 2 2007call assert_equal ( 8 , & sw ) 2008 2009" Decrementing 2010set shiftwidth = 6 2011set sw -= 2 2012call assert_equal ( 4 , & sw ) 2013let & shiftwidth -= 2 2014call assert_equal ( 2 , & sw ) 2015 2016" Multiplying 2017set shiftwidth = 4 2018set sw ^=2 2019call assert_equal ( 8 , & sw ) 2020let & shiftwidth *= 2 2021call assert_equal ( 16 , & sw ) 2022 2023set scrolljump & 2024set shiftwidth & 2025endfunc 2026 2027" Test for setting boolean option value 2028func Test_set_boolean_option () 2029set number & 2030 2031" :set {option} 2032set number 2033call assert_equal ( 1 , & nu ) 2034 2035" :set no{option} 2036set nonu 2037call assert_equal ( 0 , & nu ) 2038 2039" :set {option}! 2040set number ! 2041call assert_equal ( 1 , & nu ) 2042set number ! 2043call assert_equal ( 0 , & nu ) 2044 2045" :set inv{option} 2046set invnumber 2047call assert_equal ( 1 , & nu ) 2048set invnumber 2049call assert_equal ( 0 , & nu ) 2050 2051" Let number 2052let & number = 1 2053call assert_equal ( 1 , & nu ) 2054let & number = 0 2055call assert_equal ( 0 , & nu ) 2056 2057" Let numeric string converts to number 2058let & number = '1' 2059call assert_equal ( 1 , & nu ) 2060let & number = '0' 2061call assert_equal ( 0 , & nu ) 2062 2063" Let v:true and v:false 2064let & nu = v: true 2065call assert_equal ( 1 , & nu ) 2066let & nu = v: false 2067call assert_equal ( 0 , & nu ) 2068 2069set number & 2070endfunc 2071 2072" Test for setting string option errors 2073func Test_set_string_option_errors () 2074" :set no{option} 2075call assert_fails ( 'set nomakeprg' , 'E474:' ) 2076call assert_fails ( 'setlocal nomakeprg' , 'E474:' ) 2077call assert_fails ( 'setglobal nomakeprg' , 'E474:' ) 2078 2079" :set inv{option} 2080call assert_fails ( 'set invmakeprg' , 'E474:' ) 2081call assert_fails ( 'setlocal invmakeprg' , 'E474:' ) 2082call assert_fails ( 'setglobal invmakeprg' , 'E474:' ) 2083 2084" :set {option}! 2085call assert_fails ( 'set makeprg!' , 'E488:' ) 2086call assert_fails ( 'setlocal makeprg!' , 'E488:' ) 2087call assert_fails ( 'setglobal makeprg!' , 'E488:' ) 2088 2089" Invalid trailing chars 2090call assert_fails ( 'set makeprg??' , 'E488:' ) 2091call assert_fails ( 'setlocal makeprg??' , 'E488:' ) 2092call assert_fails ( 'setglobal makeprg??' , 'E488:' ) 2093call assert_fails ( 'set makeprg&&' , 'E488:' ) 2094call assert_fails ( 'setlocal makeprg&&' , 'E488:' ) 2095call assert_fails ( 'setglobal makeprg&&' , 'E488:' ) 2096call assert_fails ( 'set makeprg<<' , 'E488:' ) 2097call assert_fails ( 'setlocal makeprg<<' , 'E488:' ) 2098call assert_fails ( 'setglobal makeprg<<' , 'E488:' ) 2099call assert_fails ( 'set makeprg@' , 'E488:' ) 2100call assert_fails ( 'setlocal makeprg@' , 'E488:' ) 2101call assert_fails ( 'setglobal makeprg@' , 'E488:' ) 2102 2103" Invalid type 2104call assert_fails ( "let &makeprg = ['xxx']" , 'E730:' ) 2105endfunc 2106 2107" Test for setting number option errors 2108func Test_set_number_option_errors () 2109" :set no{option} 2110call assert_fails ( 'set notabstop' , 'E474:' ) 2111call assert_fails ( 'setlocal notabstop' , 'E474:' ) 2112call assert_fails ( 'setglobal notabstop' , 'E474:' ) 2113 2114" :set inv{option} 2115call assert_fails ( 'set invtabstop' , 'E474:' ) 2116call assert_fails ( 'setlocal invtabstop' , 'E474:' ) 2117call assert_fails ( 'setglobal invtabstop' , 'E474:' ) 2118 2119" :set {option}! 2120call assert_fails ( 'set tabstop!' , 'E488:' ) 2121call assert_fails ( 'setlocal tabstop!' , 'E488:' ) 2122call assert_fails ( 'setglobal tabstop!' , 'E488:' ) 2123 2124" Invalid trailing chars 2125call assert_fails ( 'set tabstop??' , 'E488:' ) 2126call assert_fails ( 'setlocal tabstop??' , 'E488:' ) 2127call assert_fails ( 'setglobal tabstop??' , 'E488:' ) 2128call assert_fails ( 'set tabstop&&' , 'E488:' ) 2129call assert_fails ( 'setlocal tabstop&&' , 'E488:' ) 2130call assert_fails ( 'setglobal tabstop&&' , 'E488:' ) 2131call assert_fails ( 'set tabstop<<' , 'E488:' ) 2132call assert_fails ( 'setlocal tabstop<<' , 'E488:' ) 2133call assert_fails ( 'setglobal tabstop<<' , 'E488:' ) 2134call assert_fails ( 'set tabstop@' , 'E488:' ) 2135call assert_fails ( 'setlocal tabstop@' , 'E488:' ) 2136call assert_fails ( 'setglobal tabstop@' , 'E488:' ) 2137 2138" Not a number 2139call assert_fails ( 'set tabstop=' , 'E521:' ) 2140call assert_fails ( 'setlocal tabstop=' , 'E521:' ) 2141call assert_fails ( 'setglobal tabstop=' , 'E521:' ) 2142call assert_fails ( 'set tabstop=x' , 'E521:' ) 2143call assert_fails ( 'setlocal tabstop=x' , 'E521:' ) 2144call assert_fails ( 'setglobal tabstop=x' , 'E521:' ) 2145call assert_fails ( 'set tabstop=1x' , 'E521:' ) 2146call assert_fails ( 'setlocal tabstop=1x' , 'E521:' ) 2147call assert_fails ( 'setglobal tabstop=1x' , 'E521:' ) 2148call assert_fails ( 'set tabstop=-x' , 'E521:' ) 2149call assert_fails ( 'setlocal tabstop=-x' , 'E521:' ) 2150call assert_fails ( 'setglobal tabstop=-x' , 'E521:' ) 2151call assert_fails ( 'set tabstop=0x' , 'E521:' ) 2152call assert_fails ( 'setlocal tabstop=0x' , 'E521:' ) 2153call assert_fails ( 'setglobal tabstop=0x' , 'E521:' ) 2154call assert_fails ( 'set tabstop=0o' , 'E521:' ) 2155call assert_fails ( 'setlocal tabstop=0o' , 'E521:' ) 2156call assert_fails ( 'setglobal tabstop=0o' , 'E521:' ) 2157call assert_fails ( "let &tabstop = 'x'" , 'E521:' ) 2158call assert_fails ( "let &g:tabstop = 'x'" , 'E521:' ) 2159call assert_fails ( "let &l:tabstop = 'x'" , 'E521:' ) 2160 2161" Invalid type 2162call assert_fails ( "let &tabstop = 'xxx'" , 'E521:' ) 2163endfunc 2164 2165" Test for setting boolean option errors 2166func Test_set_boolean_option_errors () 2167" :set {option}= 2168call assert_fails ( 'set number=' , 'E474:' ) 2169call assert_fails ( 'setlocal number=' , 'E474:' ) 2170call assert_fails ( 'setglobal number=' , 'E474:' ) 2171call assert_fails ( 'set number=1' , 'E474:' ) 2172call assert_fails ( 'setlocal number=1' , 'E474:' ) 2173call assert_fails ( 'setglobal number=1' , 'E474:' ) 2174 2175" :set {option}: 2176call assert_fails ( 'set number:' , 'E474:' ) 2177call assert_fails ( 'setlocal number:' , 'E474:' ) 2178call assert_fails ( 'setglobal number:' , 'E474:' ) 2179call assert_fails ( 'set number:1' , 'E474:' ) 2180call assert_fails ( 'setlocal number:1' , 'E474:' ) 2181call assert_fails ( 'setglobal number:1' , 'E474:' ) 2182 2183" :set {option}+= 2184call assert_fails ( 'set number+=1' , 'E474:' ) 2185call assert_fails ( 'setlocal number+=1' , 'E474:' ) 2186call assert_fails ( 'setglobal number+=1' , 'E474:' ) 2187 2188" :set {option}^= 2189call assert_fails ( 'set number^=1' , 'E474:' ) 2190call assert_fails ( 'setlocal number^=1' , 'E474:' ) 2191call assert_fails ( 'setglobal number^=1' , 'E474:' ) 2192 2193" :set {option}-= 2194call assert_fails ( 'set number-=1' , 'E474:' ) 2195call assert_fails ( 'setlocal number-=1' , 'E474:' ) 2196call assert_fails ( 'setglobal number-=1' , 'E474:' ) 2197 2198" Invalid trailing chars 2199call assert_fails ( 'set number!!' , 'E488:' ) 2200call assert_fails ( 'setlocal number!!' , 'E488:' ) 2201call assert_fails ( 'setglobal number!!' , 'E488:' ) 2202call assert_fails ( 'set number??' , 'E488:' ) 2203call assert_fails ( 'setlocal number??' , 'E488:' ) 2204call assert_fails ( 'setglobal number??' , 'E488:' ) 2205call assert_fails ( 'set number&&' , 'E488:' ) 2206call assert_fails ( 'setlocal number&&' , 'E488:' ) 2207call assert_fails ( 'setglobal number&&' , 'E488:' ) 2208call assert_fails ( 'set number<<' , 'E488:' ) 2209call assert_fails ( 'setlocal number<<' , 'E488:' ) 2210call assert_fails ( 'setglobal number<<' , 'E488:' ) 2211call assert_fails ( 'set number@' , 'E488:' ) 2212call assert_fails ( 'setlocal number@' , 'E488:' ) 2213call assert_fails ( 'setglobal number@' , 'E488:' ) 2214 2215" Invalid type 2216call assert_fails ( "let &number = 'xxx'" , 'E521:' ) 2217endfunc 2218 2219" Test for the 'window' option 2220func Test_window_opt () 2221" Needs only one open widow 2222 %bw ! 2223call setline ( 1 , range ( 1 , 8 )) 2224set window = 5 2225exe "normal \<C-F>" 2226call assert_equal ( 4 , line ( 'w0' )) 2227exe "normal \<C-F>" 2228call assert_equal ( 7 , line ( 'w0' )) 2229exe "normal \<C-F>" 2230call assert_equal ( 8 , line ( 'w0' )) 2231exe "normal \<C-B>" 2232call assert_equal ( 5 , line ( 'w0' )) 2233exe "normal \<C-B>" 2234call assert_equal ( 2 , line ( 'w0' )) 2235exe "normal \<C-B>" 2236call assert_equal ( 1 , line ( 'w0' )) 2237set window = 1 2238exe "normal gg\<C-F>" 2239call assert_equal ( 2 , line ( 'w0' )) 2240exe "normal \<C-F>" 2241call assert_equal ( 3 , line ( 'w0' )) 2242exe "normal \<C-B>" 2243call assert_equal ( 2 , line ( 'w0' )) 2244exe "normal \<C-B>" 2245call assert_equal ( 1 , line ( 'w0' )) 2246enew ! 2247set window & 2248endfunc 2249 2250" Test for the 'winminheight' option 2251func Test_opt_winminheight () 2252only ! 2253let & winheight = & lines + 4 2254call assert_fails ( 'let &winminheight = &lines + 2' , 'E36:' ) 2255call assert_true ( & winminheight <= & lines ) 2256set winminheight & 2257set winheight & 2258endfunc 2259 2260func Test_opt_winminheight_term () 2261" See test/functional/options/options_spec.lua 2262CheckRunVimInTerminal 2263 2264" The tabline should be taken into account. 2265let lines =<< trim END 2266set wmh=0 stal=2 2267below sp | wincmd _ 2268below sp | wincmd _ 2269below sp | wincmd _ 2270below sp 2271END 2272call writefile ( lines , 'Xwinminheight' ) 2273let buf = RunVimInTerminal ( '-S Xwinminheight' , #{ rows : 11 }) 2274call term_sendkeys ( buf , ":set wmh=1\n" ) 2275call WaitForAssert ({ ->assert_match ( 'E36: Not enough room' , term_getline ( buf , 11 ))}) 2276 2277call StopVimInTerminal ( buf ) 2278call delete ( 'Xwinminheight' ) 2279endfunc 2280 2281func Test_opt_winminheight_term_tabs () 2282" See test/functional/options/options_spec.lua 2283CheckRunVimInTerminal 2284 2285" The tabline should be taken into account. 2286let lines =<< trim END 2287set wmh=0 stal=2 2288split 2289split 2290split 2291split 2292tabnew 2293END 2294call writefile ( lines , 'Xwinminheight' ) 2295let buf = RunVimInTerminal ( '-S Xwinminheight' , #{ rows : 11 }) 2296call term_sendkeys ( buf , ":set wmh=1\n" ) 2297call WaitForAssert ({ ->assert_match ( 'E36: Not enough room' , term_getline ( buf , 11 ))}) 2298 2299call StopVimInTerminal ( buf ) 2300call delete ( 'Xwinminheight' ) 2301endfunc 2302 2303" Test for the 'winminwidth' option 2304func Test_opt_winminwidth () 2305only ! 2306let & winwidth = & columns + 4 2307call assert_fails ( 'let &winminwidth = &columns + 2' , 'E36:' ) 2308call assert_true ( & winminwidth <= & columns ) 2309set winminwidth & 2310set winwidth & 2311endfunc 2312 2313" Test for setting option value containing spaces with isfname+=32 2314func Test_isfname_with_options () 2315set isfname += 32 2316setlocal keywordprg = :term\ help.exe 2317call assert_equal ( ':term help.exe' , & keywordprg ) 2318set isfname & 2319setlocal keywordprg & 2320endfunc 2321 2322" Test that resetting laststatus does change scroll option 2323func Test_opt_reset_scroll () 2324" See test/functional/options/options_spec.lua 2325CheckRunVimInTerminal 2326let vimrc =<< trim [CODE] 2327set scroll=2 2328set laststatus=2 2329[CODE] 2330call writefile ( vimrc , 'Xscroll' ) 2331let buf = RunVimInTerminal ( '-S Xscroll' , { 'rows' : 16 , 'cols' : 45 }) 2332call term_sendkeys ( buf , ":verbose set scroll?\n" ) 2333call WaitForAssert ({ ->assert_match ( 'Last set.*window size' , term_getline ( buf , 15 ))}) 2334call assert_match ( '^\s*scroll=7$' , term_getline ( buf , 14 )) 2335call StopVimInTerminal ( buf ) 2336 2337" clean up 2338call delete ( 'Xscroll' ) 2339endfunc 2340 2341" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm' 2342func Test_VIM_POSIX () 2343throw 'Skipped: Nvim does not support $VIM_POSIX' 2344let saved_VIM_POSIX = getenv ( "VIM_POSIX" ) 2345 2346call setenv ( 'VIM_POSIX' , "1" ) 2347let after =<< trim [CODE] 2348call writefile([&cpo, &shm], 'X_VIM_POSIX') 2349qall 2350[CODE] 2351if RunVim ([], after , '' ) 2352call assert_equal ([ 'aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;~' , 2353 \'AS' ], readfile ( 'X_VIM_POSIX' )) 2354endif 2355 2356call setenv ( 'VIM_POSIX' , v: null ) 2357let after =<< trim [CODE] 2358call writefile([&cpo, &shm], 'X_VIM_POSIX') 2359qall 2360[CODE] 2361if RunVim ([], after , '' ) 2362call assert_equal ([ 'aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;' , 2363 \'S' ], readfile ( 'X_VIM_POSIX' )) 2364endif 2365 2366call delete ( 'X_VIM_POSIX' ) 2367call setenv ( 'VIM_POSIX' , saved_VIM_POSIX ) 2368endfunc 2369 2370" Test for setting an option to a Vi or Vim default 2371func Test_opt_default () 2372throw 'Skipped: Nvim has different defaults' 2373set formatoptions & vi 2374call assert_equal ( 'vt' , & formatoptions ) 2375set formatoptions & vim 2376call assert_equal ( 'tcq' , & formatoptions ) 2377 2378call assert_equal ( 'ucs-bom,utf-8,default,latin1' , & fencs ) 2379set fencs = latin1 2380set fencs & 2381call assert_equal ( 'ucs-bom,utf-8,default,latin1' , & fencs ) 2382set fencs = latin1 2383set all& 2384call assert_equal ( 'ucs-bom,utf-8,default,latin1' , & fencs ) 2385endfunc 2386 2387" Test for the 'cmdheight' option 2388func Test_opt_cmdheight () 2389 %bw ! 2390let ht = & lines 2391set cmdheight = 9999 2392call assert_equal ( 1 , winheight ( 0 )) 2393call assert_equal ( ht - 1 , & cmdheight ) 2394set cmdheight & 2395 2396" The status line should be taken into account. 2397set laststatus = 2 2398set cmdheight = 9999 2399call assert_equal ( ht - 2 , & cmdheight ) 2400set cmdheight & laststatus = 1 " Accommodate Nvim default 2401 2402" The tabline should be taken into account only non-GUI. 2403set showtabline = 2 2404set cmdheight = 9999 2405if has ( 'gui_running' ) 2406call assert_equal ( ht - 1 , & cmdheight ) 2407else 2408call assert_equal ( ht - 2 , & cmdheight ) 2409endif 2410set cmdheight & showtabline & 2411 2412" The 'winminheight' should be taken into account. 2413set winheight = 3 winminheight = 3 2414split 2415set cmdheight = 9999 2416call assert_equal ( ht - 8 , & cmdheight ) 2417 %bw ! 2418set cmdheight & winminheight & winheight & 2419 2420" Only the windows in the current tabpage are taken into account. 2421set winheight = 3 winminheight = 3 showtabline = 0 2422split 2423tabnew 2424set cmdheight = 9999 2425call assert_equal ( ht - 3 , & cmdheight ) 2426 %bw ! 2427set cmdheight & winminheight & winheight & showtabline & 2428endfunc 2429 2430" To specify a control character as an option value, '^' can be used 2431func Test_opt_control_char () 2432set wildchar = ^v 2433call assert_equal ( "\<C-V>" , nr2char ( & wildchar )) 2434set wildcharm = ^r 2435call assert_equal ( "\<C-R>" , nr2char ( & wildcharm )) 2436" Bug: This doesn't work for the 'cedit' and 'termwinkey' options 2437set wildchar & wildcharm & 2438endfunc 2439 2440" Test for the 'errorbells' option 2441func Test_opt_errorbells () 2442set errorbells 2443call assert_beeps ( 's/a1b2/x1y2/' ) 2444set noerrorbells 2445endfunc 2446 2447func Test_opt_scrolljump () 2448help 2449resize 10 2450 2451" Test with positive 'scrolljump'. 2452set scrolljump = 2 2453norm ! Lj 2454call assert_equal ({ 'lnum' : 11 , 'leftcol' : 0 , 'col' : 0 , 'topfill' : 0 , 2455 \'topline' : 3 , 'coladd' : 0 , 'skipcol' : 0 , 'curswant' : 0 }, 2456 \winsaveview ()) 2457 2458" Test with negative 'scrolljump' (percentage of window height). 2459set scrolljump = -40 2460norm ! ggLj 2461call assert_equal ({ 'lnum' : 11 , 'leftcol' : 0 , 'col' : 0 , 'topfill' : 0 , 2462 \'topline' : 5 , 'coladd' : 0 , 'skipcol' : 0 , 'curswant' : 0 }, 2463 \winsaveview ()) 2464 2465norm ! 100Gzt 2466set scrolljump = -100 2467norm ! 20k 2468call assert_equal ({ 'lnum' : 80 , 'leftcol' : 0 , 'col' : 0 , 'topfill' : 0 , 2469 \'topline' : 71 , 'coladd' : 0 , 'skipcol' : 0 , 'curswant' : 0 }, 2470 \winsaveview ()) 2471 2472set scrolljump & 2473bw 2474endfunc 2475 2476" Test for the 'cdhome' option 2477func Test_opt_cdhome () 2478if has ( 'unix' ) || has ( 'vms' ) 2479throw 'Skipped: only works on non-Unix' 2480endif 2481 2482set cdhome & 2483call assert_equal ( 0 , & cdhome ) 2484set cdhome 2485 2486" This paragraph is copied from Test_cd_no_arg(). 2487let path = getcwd () 2488cd 2489call assert_equal ( $ HOME , getcwd ()) 2490call assert_notequal ( path , getcwd ()) 2491exe 'cd ' .. fnameescape ( path ) 2492call assert_equal ( path , getcwd ()) 2493 2494set cdhome & 2495endfunc 2496 2497func Test_set_completion_fuzzy () 2498CheckOption termguicolors 2499 2500" Test default option completion 2501set wildoptions = 2502call feedkeys ( ":set termg\<C-A>\<C-B>\"\<CR>" , 'tx' ) 2503call assert_equal ( '"set termguicolors' , @:) 2504 2505call feedkeys ( ":set notermg\<C-A>\<C-B>\"\<CR>" , 'tx' ) 2506call assert_equal ( '"set notermguicolors' , @:) 2507 2508" Test fuzzy option completion 2509set wildoptions = fuzzy 2510call feedkeys ( ":set termg\<C-A>\<C-B>\"\<CR>" , 'tx' ) 2511" Nvim doesn't have 'termencoding' 2512" call assert_equal('"set termguicolors termencoding', @:) 2513call assert_equal ( '"set termguicolors' , @:) 2514 2515call feedkeys ( ":set notermg\<C-A>\<C-B>\"\<CR>" , 'tx' ) 2516call assert_equal ( '"set notermguicolors' , @:) 2517 2518set wildoptions = 2519endfunc 2520 2521func Test_switchbuf_reset () 2522set switchbuf = useopen 2523sblast 2524call assert_equal ( 1 , winnr ( '$' )) 2525set all& 2526" Nvim has a different default for 'switchbuf' 2527" call assert_equal('', &switchbuf) 2528call assert_equal ( 'uselast' , & switchbuf ) 2529sblast 2530call assert_equal ( 2 , winnr ( '$' )) 2531only ! 2532endfunc 2533 2534" :set empty string for global 'keywordprg' falls back to ":help" 2535func Test_keywordprg_empty () 2536let k = & keywordprg 2537set keywordprg = man 2538call assert_equal ( 'man' , & keywordprg ) 2539set keywordprg = 2540call assert_equal ( ':help' , & keywordprg ) 2541set keywordprg = man 2542call assert_equal ( 'man' , & keywordprg ) 2543call assert_equal ( "\n keywordprg=:help" , execute ( 'set kp= kp?' )) 2544let & keywordprg = k 2545endfunc 2546 2547" check that the very first buffer created does not have 'endoffile' set 2548func Test_endoffile_default () 2549let after =<< trim [CODE] 2550call writefile([execute('set eof?')], 'Xtestout') 2551qall! 2552[CODE] 2553if RunVim ([], after , '' ) 2554call assert_equal ([ "\nnoendoffile" ], readfile ( 'Xtestout' )) 2555endif 2556call delete ( 'Xtestout' ) 2557endfunc 2558 2559" Test for setting the 'lines' and 'columns' options to a minimum value 2560func Test_set_min_lines_columns () 2561let save_lines = & lines 2562let save_columns = & columns 2563 2564let after =<< trim END 2565set laststatus=1 2566set nomore 2567let msg = [] 2568let v:errmsg = '' 2569silent! let &columns=0 2570call add(msg, v:errmsg) 2571silent! set columns=0 2572call add(msg, v:errmsg) 2573silent! call setbufvar('', '&columns', 0) 2574call add(msg, v:errmsg) 2575"call writefile(msg, 'XResultsetminlines') 2576silent! let &lines=0 2577call add(msg, v:errmsg) 2578silent! set lines=0 2579call add(msg, v:errmsg) 2580silent! call setbufvar('', '&lines', 0) 2581call add(msg, v:errmsg) 2582call writefile(msg, 'XResultsetminlines') 2583qall! 2584END 2585if RunVim ([], after , '' ) 2586call assert_equal ([ 'E594: Need at least 12 columns' , 2587 \'E594: Need at least 12 columns: columns=0' , 2588 \'E594: Need at least 12 columns' , 2589 \'E593: Need at least 2 lines' , 2590 \'E593: Need at least 2 lines: lines=0' , 2591 \'E593: Need at least 2 lines' ,], readfile ( 'XResultsetminlines' )) 2592endif 2593 2594call delete ( 'XResultsetminlines' ) 2595let & lines = save_lines 2596let & columns = save_columns 2597endfunc 2598 2599" Test for reverting a string option value if the new value is invalid. 2600func Test_string_option_revert_on_failure () 2601new 2602let optlist = [ 2603 \[ 'ambiwidth' , 'double' , 'a123' ], 2604 \[ 'background' , 'dark' , 'a123' ], 2605 \[ 'backspace' , 'eol' , 'a123' ], 2606 \[ 'backupcopy' , 'no' , 'a123' ], 2607 \[ 'belloff' , 'showmatch' , 'a123' ], 2608 \[ 'breakindentopt' , 'min:10' , 'list' ], 2609 \[ 'bufhidden' , 'wipe' , 'a123' ], 2610 \[ 'buftype' , 'nowrite' , 'a123' ], 2611 \[ 'casemap' , 'keepascii' , 'a123' ], 2612 \[ 'cedit' , "\<C-Y>" , 'z' ], 2613 \[ 'colorcolumn' , '10' , 'z' ], 2614 \[ 'commentstring' , '#%s' , 'a123' ], 2615 \[ 'complete' , '.,t' , 'a' ], 2616 \[ 'completefunc' , 'MyCmplFunc' , '1a-' ], 2617"\ ['completeopt', 'popup', 'a123'], 2618 \[ 'completeopt' , 'preview' , 'a123' ], 2619"\ ['completepopup', 'width:20', 'border'], 2620 \[ 'concealcursor' , 'v' , 'xyz' ], 2621"\ ['cpoptions', 'HJ', 'Q'], 2622 \[ 'cpoptions' , 'J' , 'Q' ], 2623"\ ['cryptmethod', 'zip', 'a123'], 2624 \[ 'cursorlineopt' , 'screenline' , 'a123' ], 2625 \[ 'debug' , 'throw' , 'a123' ], 2626 \[ 'diffopt' , 'iwhite' , 'a123' ], 2627 \[ 'display' , 'uhex' , 'a123' ], 2628 \[ 'eadirection' , 'hor' , 'a123' ], 2629 \[ 'encoding' , 'utf-8' , 'a123' ], 2630 \[ 'eventignore' , 'TextYankPost' , 'a123' ], 2631 \[ 'eventignorewin' , 'WinScrolled' , 'a123' ], 2632 \[ 'fileencoding' , 'utf-8' , 'a123,' ], 2633 \[ 'fileformat' , 'mac' , 'a123' ], 2634 \[ 'fileformats' , 'mac' , 'a123' ], 2635 \[ 'filetype' , 'abc' , 'a^b' ], 2636 \[ 'fillchars' , 'diff:~' , 'a123' ], 2637 \[ 'foldclose' , 'all' , 'a123' ], 2638 \[ 'foldmarker' , '[[[,]]]' , '[[[' ], 2639 \[ 'foldmethod' , 'marker' , 'a123' ], 2640 \[ 'foldopen' , 'percent' , 'a123' ], 2641 \[ 'formatoptions' , 'an' , '*' ], 2642 \[ 'guicursor' , 'n-v-c:block-Cursor/lCursor' , 'n-v-c' ], 2643 \[ 'helplang' , 'en' , 'a' ], 2644"\ ['highlight', '!:CursorColumn', '8:'], 2645 \[ 'keymodel' , 'stopsel' , 'a123' ], 2646"\ ['keyprotocol', 'kitty:kitty', 'kitty:'], 2647 \[ 'lispoptions' , 'expr:1' , 'a123' ], 2648 \[ 'listchars' , 'tab:->' , 'tab:' ], 2649 \[ 'matchpairs' , '<:>' , '<:' ], 2650 \[ 'messagesopt' , 'hit-enter,history:100' , 'a123' ], 2651 \[ 'mkspellmem' , '100000,1000,100' , '100000' ], 2652 \[ 'mouse' , 'nvi' , 'z' ], 2653 \[ 'mousemodel' , 'extend' , 'a123' ], 2654 \[ 'nrformats' , 'alpha' , 'a123' ], 2655 \[ 'omnifunc' , 'MyOmniFunc' , '1a-' ], 2656 \[ 'operatorfunc' , 'MyOpFunc' , '1a-' ], 2657 \[ 'previewpopup' , 'width:20' , 'a123' ], 2658"\ ['printoptions', 'paper:A4', 'a123:'], 2659 \[ 'quickfixtextfunc' , 'MyQfFunc' , '1a-' ], 2660 \[ 'rulerformat' , '%l' , '%[' ], 2661 \[ 'scrollopt' , 'hor,jump' , 'a123' ], 2662 \[ 'selection' , 'exclusive' , 'a123' ], 2663 \[ 'selectmode' , 'cmd' , 'a123' ], 2664 \[ 'sessionoptions' , 'options' , 'a123' ], 2665 \[ 'shellpipe' , '>%s' , "%s%s%s" ], 2666 \[ 'shellredir' , '>%s' , "%s%s%s" ], 2667 \[ 'shortmess' , 'w' , '2' ], 2668 \[ 'showbreak' , '>>' , "\x01" ], 2669 \[ 'showcmdloc' , 'statusline' , 'a123' ], 2670 \[ 'signcolumn' , 'no' , 'a123' ], 2671 \[ 'spellcapcheck' , '[.?!]\+' , '%\{' ], 2672 \[ 'spellfile' , 'MySpell.en.add' , "\x01" ], 2673 \[ 'spelllang' , 'en' , "#" ], 2674 \[ 'spelloptions' , 'camel' , 'a123' ], 2675 \[ 'spellsuggest' , 'double' , 'a123' ], 2676 \[ 'splitkeep' , 'topline' , 'a123' ], 2677 \[ 'statusline' , '%f' , '%[' ], 2678"\ ['swapsync', 'sync', 'a123'], 2679 \[ 'switchbuf' , 'usetab' , 'a123' ], 2680 \[ 'syntax' , 'abc' , 'a^b' ], 2681 \[ 'tabline' , '%f' , '%[' ], 2682 \[ 'tagcase' , 'ignore' , 'a123' ], 2683 \[ 'tagfunc' , 'MyTagFunc' , '1a-' ], 2684 \[ 'thesaurusfunc' , 'MyThesaurusFunc' , '1a-' ], 2685 \[ 'viewoptions' , 'options' , 'a123' ], 2686 \[ 'virtualedit' , 'onemore' , 'a123' ], 2687 \[ 'whichwrap' , '<,>' , '{,}' ], 2688 \[ 'wildmode' , 'list' , 'a123' ], 2689 \[ 'wildoptions' , 'pum' , 'a123' ] 2690 \] 2691if has ( 'gui' ) 2692call add ( optlist , [ 'browsedir' , 'buffer' , 'a123' ]) 2693endif 2694if has ( 'clipboard_working' ) 2695call add ( optlist , [ 'clipboard' , 'unnamed' , 'a123' ]) 2696endif 2697if has ( 'win32' ) 2698call add ( optlist , [ 'completeslash' , 'slash' , 'a123' ]) 2699endif 2700if has ( 'cscope' ) 2701call add ( optlist , [ 'cscopequickfix' , 't-' , 'z-' ]) 2702endif 2703if ! has ( 'win32' ) && ! has ( 'nvim' ) 2704call add ( optlist , [ 'imactivatefunc' , 'MyActFunc' , '1a-' ]) 2705call add ( optlist , [ 'imstatusfunc' , 'MyStatusFunc' , '1a-' ]) 2706endif 2707if has ( 'keymap' ) 2708call add ( optlist , [ 'keymap' , 'greek' , '[]' ]) 2709endif 2710if has ( 'mouseshape' ) 2711call add ( optlist , [ 'mouseshape' , 'm:no' , 'a123:' ]) 2712endif 2713if has ( 'win32' ) && has ( 'gui' ) 2714call add ( optlist , [ 'renderoptions' , 'type:directx' , 'type:directx,a123' ]) 2715endif 2716if has ( 'rightleft' ) 2717call add ( optlist , [ 'rightleftcmd' , 'search' , 'a123' ]) 2718endif 2719if has ( 'terminal' ) 2720call add ( optlist , [ 'termwinkey' , '<C-L>' , '<C' ]) 2721call add ( optlist , [ 'termwinsize' , '24x80' , '100' ]) 2722endif 2723if has ( 'win32' ) && has ( 'terminal' ) 2724call add ( optlist , [ 'termwintype' , 'winpty' , 'a123' ]) 2725endif 2726if exists ( '+toolbar' ) 2727call add ( optlist , [ 'toolbar' , 'text' , 'a123' ]) 2728endif 2729if exists ( '+toolbariconsize' ) 2730call add ( optlist , [ 'toolbariconsize' , 'medium' , 'a123' ]) 2731endif 2732if exists ( '+ttymouse' ) && ! has ( 'gui' ) 2733call add ( optlist , [ 'ttymouse' , 'xterm' , 'a123' ]) 2734endif 2735if exists ( '+vartabs' ) 2736call add ( optlist , [ 'varsofttabstop' , '12' , 'a123' ]) 2737call add ( optlist , [ 'vartabstop' , '4,20' , '4,' ]) 2738endif 2739if exists ( '+winaltkeys' ) 2740call add ( optlist , [ 'winaltkeys' , 'no' , 'a123' ]) 2741endif 2742for opt in optlist 2743exe $ "let save_opt = &{opt[0]}" 2744try 2745exe $ "let &{opt[0]} = '{opt[1]}'" 2746catch 2747call assert_report ( $ "Caught {v: exception } with {opt->string()}") 2748endtry 2749call assert_fails ( $ "let &{opt[0]} = '{opt[2]}'", '', opt[0]) 2750call assert_equal ( opt [ 1 ], eval ( $ "&{opt[0]}"), opt[0]) 2751exe $ "let &{opt[0]} = save_opt" 2752endfor 2753bw ! 2754endfunc 2755 2756func Test_set_option_window_global_local () 2757new Xbuffer1 2758let [ _gso , _lso ] = [ & g: scrolloff , & l: scrolloff ] 2759setlocal scrolloff = 2 2760setglobal scrolloff=3 2761setl modified 2762" A new buffer has its own window-local options 2763hide enew 2764call assert_equal ( -1 , & l: scrolloff ) 2765call assert_equal ( 3 , & g: scrolloff ) 2766" A new window opened with its own buffer-local options 2767new 2768call assert_equal ( -1 , & l: scrolloff ) 2769call assert_equal ( 3 , & g: scrolloff ) 2770" Re-open Xbuffer1 and it should use 2771" the previous set window-local options 2772b Xbuffer1 2773call assert_equal ( 2 , & l: scrolloff ) 2774call assert_equal ( 3 , & g: scrolloff ) 2775bw ! 2776bw ! 2777let & g: scrolloff = _gso 2778endfunc 2779 2780func GetGlobalLocalWindowOptions () 2781new 2782sil ! r $VIMRUNTIME/doc/options.txt 2783" Filter for global or local to window 2784v /^'.*'.*\n.*global or local to window |global -local/d 2785" get option value and type 2786sil %s /^'\( [ ^' ] * \)'. * '\s\+\(\w\+\)\s\+(default \%(\(". * "\|\d\+\|empty\|is very long\)\). * /\1 \2 \3/g 2787" sil %s/empty/""/g 2788" split the result 2789" let result=getline(1,'$')->map({_, val -> split(val, ' ')}) 2790let result = getline ( 1 , '$' ) ->map ({ _ , val ->matchlist ( val , '\([^ ]\+\) \+\([^ ]\+\) \+\(.*\)' )[ 1 : 3 ]}) 2791bw ! 2792return result 2793endfunc 2794 2795func Test_set_option_window_global_local_all () 2796new Xbuffer2 2797 2798let optionlist = GetGlobalLocalWindowOptions () 2799for [ opt , type , default ] in optionlist 2800let _old = eval ( '&g:' .. opt ) 2801if opt == 'statusline' 2802" parsed default value is "is very long" as it is a doc string, not actual value 2803let default = "\"" . _old . "\"" 2804endif 2805if type == 'string' 2806if opt == 'fillchars' 2807exe 'setl ' .. opt .. '=vert:+' 2808exe 'setg ' .. opt .. '=vert:+,fold:+' 2809elseif opt == 'listchars' 2810exe 'setl ' .. opt .. '=tab:>>' 2811exe 'setg ' .. opt .. '=tab:++' 2812elseif opt == 'virtualedit' 2813exe 'setl ' .. opt .. '=all' 2814exe 'setg ' .. opt .. '=block' 2815else 2816exe 'setl ' .. opt .. '=Local' 2817exe 'setg ' .. opt .. '=Global' 2818endif 2819elseif type == 'number' 2820exe 'setl ' .. opt .. '=5' 2821exe 'setg ' .. opt .. '=10' 2822endif 2823setl modified 2824hide enew 2825if type == 'string' 2826call assert_equal ( '' , eval ( '&l:' .. opt )) 2827if opt == 'fillchars' 2828call assert_equal ( 'vert:+,fold:+' , eval ( '&g:' .. opt ), 'option:' .. opt ) 2829elseif opt == 'listchars' 2830call assert_equal ( 'tab:++' , eval ( '&g:' .. opt ), 'option:' .. opt ) 2831elseif opt == 'virtualedit' 2832call assert_equal ( 'block' , eval ( '&g:' .. opt ), 'option:' .. opt ) 2833else 2834call assert_equal ( 'Global' , eval ( '&g:' .. opt ), 'option:' .. opt ) 2835endif 2836elseif type == 'number' 2837call assert_equal ( -1 , eval ( '&l:' .. opt ), 'option:' .. opt ) 2838call assert_equal ( 10 , eval ( '&g:' .. opt ), 'option:' .. opt ) 2839endif 2840bw ! 2841exe 'let &g:' .. opt .. '=' .. default 2842endfor 2843bw ! 2844endfunc 2845 2846func Test_paste_depending_options () 2847" setting the paste option, resets all dependent options 2848" and will be reported correctly using :verbose set <option>? 2849let lines =<< trim [CODE] 2850" set paste test 2851set autoindent 2852set expandtab 2853" disabled, because depends on compiled feature set 2854" set hkmap 2855" set revins 2856" set varsofttabstop=8,32,8 2857set ruler 2858set showmatch 2859set smarttab 2860set softtabstop=4 2861set textwidth=80 2862set wrapmargin=10 2863 2864source Xvimrc_paste2 2865 2866redir > Xoutput_paste 2867verbose set expandtab? 2868verbose setg expandtab? 2869verbose setl expandtab? 2870redir END 2871 2872qall! 2873[CODE] 2874 2875call writefile ( lines , 'Xvimrc_paste' , 'D' ) 2876call writefile ([ 'set paste' ], 'Xvimrc_paste2' , 'D' ) 2877if ! RunVim ([], lines , '--clean' ) 2878return 2879endif 2880 2881let result = readfile ( 'Xoutput_paste' ) ->filter ( '!empty(v:val)' ) 2882call assert_equal ( 'noexpandtab' , result [ 0 ]) 2883call assert_match ( "^\tLast set from .*Xvimrc_paste2 line 1$" , result [ 1 ]) 2884call assert_equal ( 'noexpandtab' , result [ 2 ]) 2885call assert_match ( "^\tLast set from .*Xvimrc_paste2 line 1$" , result [ 3 ]) 2886call assert_equal ( 'noexpandtab' , result [ 4 ]) 2887call assert_match ( "^\tLast set from .*Xvimrc_paste2 line 1$" , result [ 5 ]) 2888 2889call delete ( 'Xoutput_paste' ) 2890endfunc 2891 2892func Test_binary_depending_options () 2893" setting the paste option, resets all dependent options 2894" and will be reported correctly using :verbose set <option>? 2895let lines =<< trim [CODE] 2896" set binary test 2897set expandtab 2898 2899source Xvimrc_bin2 2900 2901redir > Xoutput_bin 2902verbose set expandtab? 2903verbose setg expandtab? 2904verbose setl expandtab? 2905redir END 2906 2907qall! 2908[CODE] 2909 2910call writefile ( lines , 'Xvimrc_bin' , 'D' ) 2911call writefile ([ 'set binary' ], 'Xvimrc_bin2' , 'D' ) 2912if ! RunVim ([], lines , '--clean' ) 2913return 2914endif 2915 2916let result = readfile ( 'Xoutput_bin' ) ->filter ( '!empty(v:val)' ) 2917call assert_equal ( 'noexpandtab' , result [ 0 ]) 2918call assert_match ( "^\tLast set from .*Xvimrc_bin2 line 1$" , result [ 1 ]) 2919call assert_equal ( 'noexpandtab' , result [ 2 ]) 2920call assert_match ( "^\tLast set from .*Xvimrc_bin2 line 1$" , result [ 3 ]) 2921call assert_equal ( 'noexpandtab' , result [ 4 ]) 2922call assert_match ( "^\tLast set from .*Xvimrc_bin2 line 1$" , result [ 5 ]) 2923 2924call delete ( 'Xoutput_bin' ) 2925endfunc 2926 2927func Test_set_wrap () 2928" Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect 2929" cursor position. 2930set wrap smoothscroll scrolloff = 5 2931 2932call setline ( 1 , [ '' , 'aaaa' ->repeat ( 500 )]) 293320 split 293420 vsplit 2935norm 2G$ 2936redraw 2937set nowrap 2938call assert_equal ( 2 , winline ()) 2939 2940set wrap & smoothscroll & scrolloff & 2941endfunc 2942 2943func Test_delcombine () 2944new 2945set backspace = indent,eol,start 2946 2947set delcombine 2948call setline ( 1 , 'β̳̈:β̳̈' ) 2949normal ! 0x 2950call assert_equal ( 'β̈:β̳̈' , getline ( 1 )) 2951exe "normal! A\<BS>" 2952call assert_equal ( 'β̈:β̈' , getline ( 1 )) 2953normal ! 0x 2954call assert_equal ( 'β:β̈' , getline ( 1 )) 2955exe "normal! A\<BS>" 2956call assert_equal ( 'β:β' , getline ( 1 )) 2957normal ! 0x 2958call assert_equal ( ':β' , getline ( 1 )) 2959exe "normal! A\<BS>" 2960call assert_equal ( ':' , getline ( 1 )) 2961 2962set nodelcombine 2963call setline ( 1 , 'β̳̈:β̳̈' ) 2964normal ! 0x 2965call assert_equal ( ':β̳̈' , getline ( 1 )) 2966exe "normal! A\<BS>" 2967call assert_equal ( ':' , getline ( 1 )) 2968 2969set backspace & delcombine & 2970bwipe ! 2971endfunc 2972 2973" Should not raise errors when set missing-options. 2974func Test_set_missing_options () 2975throw 'Skipped: N/A' 2976set autoprint 2977set beautify 2978set flash 2979set graphic 2980set hardtabs = 8 2981set mesg 2982set novice 2983set open 2984set optimize 2985set redraw 2986set slowopen 2987set sourceany 2988set w 300=23 2989set w 1200=23 2990set w 9600=23 2991endfunc 2992 2993func Test_showcmd () 2994throw 'Skipped: Nvim does not support support Vi-compatible mode' 2995" in no-cp mode, 'showcmd' is enabled 2996let _cp =& cp 2997call assert_equal ( 1 , & showcmd ) 2998set cp 2999call assert_equal ( 0 , & showcmd ) 3000set nocp 3001call assert_equal ( 1 , & showcmd ) 3002let & cp = _cp 3003endfunc 3004 3005" Test that :set+= and :set-= handle "key:value" items in comma-separated 3006" options by matching on the key part. 3007func Test_comma_option_key_value () 3008" += replaces existing item with same key 3009set diffopt = internal,filler,algorithm:patience 3010set diffopt += algorithm:histogram 3011call assert_equal ( 'internal,filler,algorithm:histogram' , & diffopt ) 3012 3013" += with exact duplicate does nothing 3014set diffopt = internal,filler,algorithm:patience 3015set diffopt += algorithm:patience 3016call assert_equal ( 'internal,filler,algorithm:patience' , & diffopt ) 3017 3018" += with multiple items, each processed individually 3019set diffopt = algorithm:patience,filler 3020set diffopt += algorithm:histogram,filler 3021call assert_equal ( 'filler,algorithm:histogram' , & diffopt ) 3022 3023" += with non-colon item appends normally 3024set diffopt = internal,filler 3025set diffopt += iwhite 3026call assert_equal ( 'internal,filler,iwhite' , & diffopt ) 3027 3028" += repeated updates 3029set diffopt = internal,filler,algorithm:patience 3030set diffopt += algorithm:histogram 3031set diffopt += algorithm:minimal 3032set diffopt += algorithm:myers 3033call assert_equal ( 'internal,filler,algorithm:myers' , & diffopt ) 3034 3035" += all exact duplicates does nothing 3036set diffopt = internal,filler,algorithm:patience 3037set diffopt += algorithm:patience,filler 3038call assert_equal ( 'internal,filler,algorithm:patience' , & diffopt ) 3039 3040" -= with "key:" removes item regardless of value 3041set diffopt = internal,filler,algorithm:patience 3042set diffopt -= algorithm: 3043call assert_equal ( 'internal,filler' , & diffopt ) 3044 3045" -= with "key:value" also matches by key 3046set diffopt = internal,filler,algorithm:patience 3047set diffopt -= algorithm:histogram 3048call assert_equal ( 'internal,filler' , & diffopt ) 3049 3050" -= without colon does not match "key:value" items 3051set diffopt = internal,filler,algorithm:patience 3052set diffopt -= algorithm 3053call assert_equal ( 'internal,filler,algorithm:patience' , & diffopt ) 3054 3055" -= with multiple non-colon items (order independent) 3056set diffopt = internal,filler,closeoff 3057set diffopt -= filler,internal 3058call assert_equal ( 'closeoff' , & diffopt ) 3059 3060" -= with multiple non-colon items (same order as in option) 3061set diffopt = internal,filler,closeoff 3062set diffopt -= internal,filler 3063call assert_equal ( 'closeoff' , & diffopt ) 3064 3065" -= with multiple items: non-colon and colon mixed 3066set diffopt & diffopt = internal,filler,closeoff,indent-heuristic,inline:char 3067set diffopt -= indent-heuristic,inline:char 3068call assert_equal ( 'internal,filler,closeoff' , & diffopt ) 3069 3070" -= with multiple items: colon and non-colon mixed (reverse order) 3071set diffopt & diffopt = internal,filler,closeoff,indent-heuristic,inline:char 3072set diffopt -= inline:char,indent-heuristic 3073call assert_equal ( 'internal,filler,closeoff' , & diffopt ) 3074 3075" += with multiple non-colon items 3076set diffopt = internal,filler 3077set diffopt += closeoff,iwhite 3078call assert_equal ( 'internal,filler,closeoff,iwhite' , & diffopt ) 3079 3080" += with multiple non-colon items, some already exist 3081set diffopt = internal,filler,closeoff 3082set diffopt += filler,iwhite 3083call assert_equal ( 'internal,filler,closeoff,iwhite' , & diffopt ) 3084 3085" -= with multiple items including key match 3086set diffopt = internal,filler,algorithm:patience 3087set diffopt -= algorithm:,filler 3088call assert_equal ( 'internal' , & diffopt ) 3089 3090" -= key match when item is at the beginning 3091set diffopt = algorithm:patience,internal,filler 3092set diffopt -= algorithm: 3093call assert_equal ( 'internal,filler' , & diffopt ) 3094 3095" -= key match when item is at the end 3096set diffopt = internal,filler,algorithm:patience 3097set diffopt -= algorithm: 3098call assert_equal ( 'internal,filler' , & diffopt ) 3099 3100" -= key match when item is the only item 3101set diffopt = algorithm:patience 3102set diffopt -= algorithm: 3103call assert_equal ( '' , & diffopt ) 3104 3105" ^= prepends new item 3106set diffopt = internal,filler 3107set diffopt ^=algorithm:histogram 3108call assert_equal ( 'algorithm:histogram,internal,filler' , & diffopt ) 3109 3110" ^= replaces item and prepends 3111set diffopt = internal,filler,algorithm:patience 3112set diffopt ^=algorithm:histogram 3113call assert_equal ( 'algorithm:histogram,internal,filler' , & diffopt ) 3114 3115" ^= with exact duplicate does nothing 3116set diffopt = internal,filler,algorithm:patience 3117set diffopt ^=algorithm:patience 3118call assert_equal ( 'internal,filler,algorithm:patience' , & diffopt ) 3119 3120set diffopt & 3121 3122" Multiple items with the same key (set via :let) 3123" += with different value removes all items with the same key 3124let & lcs = 'eol:$,multispace:yY,space:x,multispace:XY' 3125set lcs += multispace:AB 3126call assert_equal ( 'eol:$,space:x,multispace:AB' , & lcs ) 3127 3128" += with exact duplicate keeps it and removes others with the same key 3129let & lcs = 'eol:$,multispace:XY,space:x,multispace:XY' 3130set lcs += multispace:XY 3131call assert_equal ( 'eol:$,multispace:XY,space:x' , & lcs ) 3132 3133" -= removes all items with the same key 3134let & lcs = 'eol:$,multispace:yY,space:x,multispace:XY' 3135set lcs -= multispace: 3136call assert_equal ( 'eol:$,space:x' , & lcs ) 3137 3138" ^= with different value removes all items and prepends 3139let & lcs = 'eol:$,multispace:yY,space:x,multispace:XY' 3140set lcs ^=multispace:AB 3141call assert_equal ( 'multispace:AB,eol:$,space:x' , & lcs ) 3142 3143set lcs & 3144endfunc 3145 3146func Test_insecure_flag_copied_to_new_buffer_indentexpr () 3147let modeline = & modeline 3148let modelineexpr = & modelineexpr 3149"let modelinestrict = &modelinestrict 3150 3151func ! Xindentexprpwn ( findstart , base ) 3152if a: findstart 3153sandbox setglobal indentexpr=writefile(['leak'],\'Xindentexpr_proof' ) 3154return 0 3155endif 3156return [] 3157endfunc 3158 3159try 3160set modeline modelineexpr "nomodelinestrict 3161 3162call writefile ([ 3163 \'vim: set complete=FXindentexprpwn :' , 3164 \'body' , 3165 \], 'Xindentexpr_attack' , 'D' ) 3166call delete ( 'Xindentexpr_proof' ) 3167edit Xindentexpr_attack 3168call cursor ( 2 , 1 ) 3169call feedkeys ( "i\<C-N>\<Esc>" , 'xt' ) 3170bwipe ! 3171 3172" A brand new buffer now inherits the poisoned 'indentexpr' via 3173" buf_copy_options(). It must still be evaluated in the sandbox. 3174enew ! 3175call setline ( 1 , [ '{' , 'x' , '}' ]) 3176normal ! 2G== 3177call assert_false ( filereadable ( 'Xindentexpr_proof' )) 3178bwipe ! 3179finally 3180let & modeline = modeline 3181let & modelineexpr = modelineexpr 3182"let &modelinestrict = modelinestrict 3183set indentexpr & 3184call delete ( 'Xindentexpr_proof' ) 3185delfunc Xindentexprpwn 3186endtry 3187endfunc 3188 3189func Test_insecure_flag_not_cleared_by_other_buffer_complete () 3190let modeline = & modeline 3191let modelineexpr = & modelineexpr 3192"let modelinestrict = &modelinestrict 3193 3194func ! Xcompletepwn ( findstart , base ) 3195if a: findstart 3196call writefile ([ 'leak' ], 'Xcomplete_cross_proof' ) 3197return 0 3198endif 3199return [ 'match' ] 3200endfunc 3201 3202try 3203set modeline modelineexpr "nomodelinestrict 3204 3205call writefile ([ 3206 \'vim: set complete=FXcompletepwn :' , 3207 \'body' , 3208 \], 'Xcomplete_cross_attack' , 'D' ) 3209call delete ( 'Xcomplete_cross_proof' ) 3210edit Xcomplete_cross_attack 3211let bufA = bufnr ( '%' ) 3212 3213" An unrelated buffer does a completely ordinary, trusted reset. 3214new 3215setlocal complete = .,w,b,u,t 3216bwipe ! 3217 3218" Back in the modeline-tainted buffer: must still be sandboxed. 3219exe 'buffer ' .. bufA 3220call cursor ( 2 , 1 ) 3221call assert_fails ( 'call feedkeys("i\<C-N>\<Esc>", "xt")' , 'E48:' ) 3222call assert_false ( filereadable ( 'Xcomplete_cross_proof' )) 3223bwipe ! 3224finally 3225let & modeline = modeline 3226let & modelineexpr = modelineexpr 3227"let &modelinestrict = modelinestrict 3228call delete ( 'Xcomplete_cross_proof' ) 3229delfunc Xcompletepwn 3230endtry 3231endfunc 3232 3233func Test_formatexpr_insecure_copied_to_new_buffer () 3234new 3235sandbox setglobal formatexpr=writefile(['leak'],\'Xleak_fex' ) 3236enew ! 3237call setline ( 1 , [ 'some text to format' ]) 3238set textwidth = 10 3239silent ! normal ! gqq 3240call assert_false ( filereadable ( 'Xleak_fex' )) 3241call delete ( 'Xleak_fex' ) 3242set formatexpr & textwidth & 3243bwipe ! 3244endfunc 3245 3246" includeexpr: triggered via gf / find_pattern_in_path (used by [i, gf, etc.) 3247func Test_includeexpr_insecure_copied_to_new_buffer () 3248func Xleakinclude ( fname ) 3249call writefile ([ 'leak' ], 'Xleak_inex' ) 3250return a: fname 3251endfunc 3252new 3253sandbox setglobal includeexpr=Xleakinclude(v:fname) 3254enew ! 3255call setline ( 1 , [ '#include "foo.h"' ]) 3256silent ! normal ! [i 3257call assert_false ( filereadable ( 'Xleak_inex' )) 3258call delete ( 'Xleak_inex' ) 3259set includeexpr & 3260delfunc Xleakinclude 3261bwipe ! 3262endfunc 3263 3264" vim: shiftwidth=2 sts=2 expandtab