1" Test for options 2 3source shared.vim 4source check.vim 5source view_util.vim 6 7func Test_whichwrap() 8 set whichwrap=b,s 9 call assert_equal('b,s', &whichwrap) 10 11 set whichwrap+=h,l 12 call assert_equal('b,s,h,l', &whichwrap) 13 14 set whichwrap+=h,l 15 call assert_equal('b,s,h,l', &whichwrap) 16 17 set whichwrap+=h,l 18 call assert_equal('b,s,h,l', &whichwrap) 19 20 set whichwrap=h,h 21 call assert_equal('h', &whichwrap) 22 23 set whichwrap=h,h,h 24 call assert_equal('h', &whichwrap) 25 26 " For compatibility with Vim 3.0 and before, number values are also 27 " supported for 'whichwrap' 28 set whichwrap=1 29 call assert_equal('b', &whichwrap) 30 set whichwrap=2 31 call assert_equal('s', &whichwrap) 32 set whichwrap=4 33 call assert_equal('h,l', &whichwrap) 34 set whichwrap=8 35 call assert_equal('<,>', &whichwrap) 36 set whichwrap=16 37 call assert_equal('[,]', &whichwrap) 38 set whichwrap=31 39 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) 40 41 set whichwrap& 42endfunc 43 44func Test_isfname() 45 " This used to cause Vim to access uninitialized memory. 46 set isfname= 47 call assert_equal("~X", expand("~X")) 48 set isfname& 49endfunc 50 51func Test_wildchar() 52 " Empty 'wildchar' used to access invalid memory. 53 call assert_fails('set wildchar=', 'E521:') 54 call assert_fails('set wildchar=abc', 'E521:') 55 set wildchar=<Esc> 56 let a=execute('set wildchar?') 57 call assert_equal("\n wildchar=<Esc>", a) 58 set wildchar=27 59 let a=execute('set wildchar?') 60 call assert_equal("\n wildchar=<Esc>", a) 61 set wildchar& 62endfunc 63 64func Test_wildoptions() 65 set wildoptions= 66 set wildoptions+=tagfile 67 set wildoptions+=tagfile 68 call assert_equal('tagfile', &wildoptions) 69endfunc 70 71func Test_options_command() 72 let caught = 'ok' 73 try 74 options 75 catch 76 let caught = v:throwpoint . "\n" . v:exception 77 endtry 78 call assert_equal('ok', caught) 79 80 " Check if the option-window is opened horizontally. 81 wincmd j 82 call assert_notequal('option-window', bufname('')) 83 wincmd k 84 call assert_equal('option-window', bufname('')) 85 " close option-window 86 close 87 88 " Open the option-window vertically. 89 vert options 90 " Check if the option-window is opened vertically. 91 wincmd l 92 call assert_notequal('option-window', bufname('')) 93 wincmd h 94 call assert_equal('option-window', bufname('')) 95 " close option-window 96 close 97 98 " Open the option-window at the top. 99 set splitbelow 100 topleft options 101 call assert_equal(1, winnr()) 102 close 103 104 " Open the option-window at the bottom. 105 set nosplitbelow 106 botright options 107 call assert_equal(winnr('$'), winnr()) 108 close 109 set splitbelow& 110 111 " Open the option-window in a new tab. 112 tab options 113 " Check if the option-window is opened in a tab. 114 normal gT 115 call assert_notequal('option-window', bufname('')) 116 normal gt 117 call assert_equal('option-window', bufname('')) 118 " close option-window 119 close 120 121 " Open the options window browse 122 if has('browse') 123 browse set 124 call assert_equal('option-window', bufname('')) 125 close 126 endif 127endfunc 128 129func Test_path_keep_commas() 130 " Test that changing 'path' keeps two commas. 131 set path=foo,,bar 132 set path-=bar 133 set path+=bar 134 call assert_equal('foo,,bar', &path) 135 136 set path& 137endfunc 138 139func Test_signcolumn() 140 CheckFeature signs 141 call assert_equal("auto", &signcolumn) 142 set signcolumn=yes 143 set signcolumn=no 144 call assert_fails('set signcolumn=nope') 145endfunc 146 147func Test_filetype_valid() 148 set ft=valid_name 149 call assert_equal("valid_name", &filetype) 150 set ft=valid-name 151 call assert_equal("valid-name", &filetype) 152 153 call assert_fails(":set ft=wrong;name", "E474:") 154 call assert_fails(":set ft=wrong\\\\name", "E474:") 155 call assert_fails(":set ft=wrong\\|name", "E474:") 156 call assert_fails(":set ft=wrong/name", "E474:") 157 call assert_fails(":set ft=wrong\\\nname", "E474:") 158 call assert_equal("valid-name", &filetype) 159 160 exe "set ft=trunc\x00name" 161 call assert_equal("trunc", &filetype) 162endfunc 163 164func Test_syntax_valid() 165 CheckFeature syntax 166 set syn=valid_name 167 call assert_equal("valid_name", &syntax) 168 set syn=valid-name 169 call assert_equal("valid-name", &syntax) 170 171 call assert_fails(":set syn=wrong;name", "E474:") 172 call assert_fails(":set syn=wrong\\\\name", "E474:") 173 call assert_fails(":set syn=wrong\\|name", "E474:") 174 call assert_fails(":set syn=wrong/name", "E474:") 175 call assert_fails(":set syn=wrong\\\nname", "E474:") 176 call assert_equal("valid-name", &syntax) 177 178 exe "set syn=trunc\x00name" 179 call assert_equal("trunc", &syntax) 180endfunc 181 182func Test_keymap_valid() 183 CheckFeature keymap 184 call assert_fails(":set kmp=valid_name", "E544:") 185 call assert_fails(":set kmp=valid_name", "valid_name") 186 call assert_fails(":set kmp=valid-name", "E544:") 187 call assert_fails(":set kmp=valid-name", "valid-name") 188 189 call assert_fails(":set kmp=wrong;name", "E474:") 190 call assert_fails(":set kmp=wrong\\\\name", "E474:") 191 call assert_fails(":set kmp=wrong\\|name", "E474:") 192 call assert_fails(":set kmp=wrong/name", "E474:") 193 call assert_fails(":set kmp=wrong\\\nname", "E474:") 194 195 call assert_fails(":set kmp=trunc\x00name", "E544:") 196 call assert_fails(":set kmp=trunc\x00name", "trunc") 197endfunc 198 199func Check_dir_option(name) 200 " Check that it's possible to set the option. 201 exe 'set ' . a:name . '=/usr/share/dict/words' 202 call assert_equal('/usr/share/dict/words', eval('&' . a:name)) 203 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' 204 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) 205 exe 'set ' . a:name . '=/usr/share/dict\ words' 206 call assert_equal('/usr/share/dict words', eval('&' . a:name)) 207 208 " Check rejecting weird characters. 209 call assert_fails("set " . a:name . "=/not&there", "E474:") 210 call assert_fails("set " . a:name . "=/not>there", "E474:") 211 call assert_fails("set " . a:name . "=/not.*there", "E474:") 212endfunc 213 214func Test_cinkeys() 215 " This used to cause invalid memory access 216 set cindent cinkeys=0 217 norm a 218 set cindent& cinkeys& 219endfunc 220 221func Test_dictionary() 222 call Check_dir_option('dictionary') 223endfunc 224 225func Test_thesaurus() 226 call Check_dir_option('thesaurus') 227endfun 228 229func Test_complete() 230 " Trailing single backslash used to cause invalid memory access. 231 set complete=s\ 232 new 233 call feedkeys("i\<C-N>\<Esc>", 'xt') 234 bwipe! 235 call assert_fails('set complete=ix', 'E535:') 236 set complete& 237endfun 238 239func Test_set_completion() 240 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') 241 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) 242 243 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx') 244 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:) 245 246 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') 247 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) 248 249 " Expand boolan options. When doing :set no<Tab> 250 " vim displays the options names without "no" but completion uses "no...". 251 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') 252 call assert_equal('"set nodiff digraph', @:) 253 254 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') 255 call assert_equal('"set invdiff digraph', @:) 256 257 " Expand abbreviation of options. 258 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') 259 call assert_equal('"set tabstop thesaurus ttyscroll', @:) 260 261 " Expand current value 262 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') 263 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) 264 265 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') 266 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) 267 268 " Expand key codes. 269 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') 270 call assert_equal('"set <Help> <Home>', @:) 271 272 " Expand terminal options. 273 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') 274 call assert_equal('"set t_AB t_AF t_AU t_AL', @:) 275 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:') 276 277 " Expand directories. 278 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') 279 call assert_match(' ./samples/ ', @:) 280 call assert_notmatch(' ./summarize.vim ', @:) 281 282 " Expand files and directories. 283 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') 284 call assert_match(' ./samples/.* ./summarize.vim', @:) 285 286 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') 287 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) 288 set tags& 289 290 " Expanding the option names 291 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') 292 call assert_equal('"set all', @:) 293 294 " Expanding a second set of option names 295 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt') 296 call assert_equal('"set wrapscan all', @:) 297 298 " Expanding a special keycode 299 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') 300 call assert_equal('"set <Home>', @:) 301 302 " Expanding an invalid special keycode 303 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt') 304 call assert_equal("\"set <abcd>\<Tab>", @:) 305 306 " Expanding a terminal keycode 307 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') 308 call assert_equal("\"set t_AB", @:) 309 310 " Expanding an invalid option name 311 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt') 312 call assert_equal("\"set abcde=\<Tab>", @:) 313 314 " Expanding after a = for a boolean option 315 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt') 316 call assert_equal("\"set wrapscan=\<Tab>", @:) 317 318 " Expanding a numeric option 319 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt') 320 call assert_equal("\"set tabstop+=" .. &tabstop, @:) 321 322 " Expanding a non-boolean option 323 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt') 324 call assert_equal("\"set invtabstop=", @:) 325 326 " Expand options for 'spellsuggest' 327 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt') 328 call assert_equal("\"set spellsuggest=best,file:xyz", @:) 329 330 " Expand value for 'key' 331 set key=abcd 332 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt') 333 call assert_equal('"set key=*****', @:) 334 set key= 335 336 " Expand values for 'filetype' 337 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt') 338 call assert_equal('"set filetype=sshdconfig', @:) 339 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt') 340 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:) 341endfunc 342 343func Test_set_errors() 344 call assert_fails('set scroll=-1', 'E49:') 345 call assert_fails('set backupcopy=', 'E474:') 346 call assert_fails('set regexpengine=3', 'E474:') 347 call assert_fails('set history=10001', 'E474:') 348 call assert_fails('set numberwidth=21', 'E474:') 349 call assert_fails('set colorcolumn=-a', 'E474:') 350 call assert_fails('set colorcolumn=a', 'E474:') 351 call assert_fails('set colorcolumn=1,', 'E474:') 352 call assert_fails('set colorcolumn=1;', 'E474:') 353 call assert_fails('set cmdheight=-1', 'E487:') 354 call assert_fails('set cmdwinheight=-1', 'E487:') 355 if has('conceal') 356 call assert_fails('set conceallevel=-1', 'E487:') 357 call assert_fails('set conceallevel=4', 'E474:') 358 endif 359 call assert_fails('set helpheight=-1', 'E487:') 360 call assert_fails('set history=-1', 'E487:') 361 call assert_fails('set report=-1', 'E487:') 362 call assert_fails('set shiftwidth=-1', 'E487:') 363 call assert_fails('set sidescroll=-1', 'E487:') 364 call assert_fails('set tabstop=-1', 'E487:') 365 call assert_fails('set textwidth=-1', 'E487:') 366 call assert_fails('set timeoutlen=-1', 'E487:') 367 call assert_fails('set updatecount=-1', 'E487:') 368 call assert_fails('set updatetime=-1', 'E487:') 369 call assert_fails('set winheight=-1', 'E487:') 370 call assert_fails('set tabstop!', 'E488:') 371 call assert_fails('set xxx', 'E518:') 372 call assert_fails('set beautify?', 'E519:') 373 call assert_fails('set undolevels=x', 'E521:') 374 call assert_fails('set tabstop=', 'E521:') 375 call assert_fails('set comments=-', 'E524:') 376 call assert_fails('set comments=a', 'E525:') 377 call assert_fails('set foldmarker=x', 'E536:') 378 call assert_fails('set commentstring=x', 'E537:') 379 call assert_fails('set complete=x', 'E539:') 380 call assert_fails('set rulerformat=%-', 'E539:') 381 call assert_fails('set rulerformat=%(', 'E542:') 382 call assert_fails('set rulerformat=%15(%%', 'E542:') 383 call assert_fails('set statusline=%$', 'E539:') 384 call assert_fails('set statusline=%{', 'E540:') 385 call assert_fails('set statusline=%(', 'E542:') 386 call assert_fails('set statusline=%)', 'E542:') 387 388 if has('cursorshape') 389 " This invalid value for 'guicursor' used to cause Vim to crash. 390 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 391 call assert_fails('set guicursor=i-ci', 'E545:') 392 call assert_fails('set guicursor=x', 'E545:') 393 call assert_fails('set guicursor=x:', 'E546:') 394 call assert_fails('set guicursor=r-cr:horx', 'E548:') 395 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 396 endif 397 if has('mouseshape') 398 call assert_fails('se mouseshape=i-r:x', 'E547:') 399 endif 400 call assert_fails('set backupext=~ patchmode=~', 'E589:') 401 call assert_fails('set winminheight=10 winheight=9', 'E591:') 402 set winminheight& winheight& 403 set winheight=10 winminheight=10 404 call assert_fails('set winheight=9', 'E591:') 405 set winminheight& winheight& 406 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 407 set winminwidth& winwidth& 408 call assert_fails('set winwidth=9 winminwidth=10', 'E592:') 409 set winwidth& winminwidth& 410 call assert_fails("set showbreak=\x01", 'E595:') 411 call assert_fails('set t_foo=', 'E846:') 412 call assert_fails('set tabstop??', 'E488:') 413 call assert_fails('set wrapscan!!', 'E488:') 414 call assert_fails('set tabstop&&', 'E488:') 415 call assert_fails('set wrapscan<<', 'E488:') 416 call assert_fails('set wrapscan=1', 'E474:') 417 call assert_fails('set autoindent@', 'E488:') 418 call assert_fails('set wildchar=<abc>', 'E474:') 419 call assert_fails('set cmdheight=1a', 'E521:') 420 call assert_fails('set invcmdheight', 'E474:') 421 if has('python') || has('python3') 422 call assert_fails('set pyxversion=6', 'E474:') 423 endif 424 call assert_fails("let &tabstop='ab'", 'E521:') 425 call assert_fails('set spellcapcheck=%\\(', 'E54:') 426 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:') 427 call assert_fails('set foldmarker={{{,', 'E474:') 428 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:') 429 call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:') 430 set listchars& 431 call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:') 432 set fillchars& 433 call assert_fails('set fileencoding=latin1,utf-8', 'E474:') 434 set nomodifiable 435 call assert_fails('set fileencoding=latin1', 'E21:') 436 set modifiable& 437 call assert_fails('set t_#-&', 'E522:') 438endfunc 439 440func CheckWasSet(name) 441 let verb_cm = execute('verbose set ' .. a:name .. '?') 442 call assert_match('Last set from.*test_options.vim', verb_cm) 443endfunc 444func CheckWasNotSet(name) 445 let verb_cm = execute('verbose set ' .. a:name .. '?') 446 call assert_notmatch('Last set from', verb_cm) 447endfunc 448 449" Must be executed before other tests that set 'term'. 450func Test_000_term_option_verbose() 451 CheckNotGui 452 453 call CheckWasNotSet('t_cm') 454 455 let term_save = &term 456 set term=ansi 457 call CheckWasSet('t_cm') 458 let &term = term_save 459endfunc 460 461func Test_copy_context() 462 setlocal list 463 call CheckWasSet('list') 464 split 465 call CheckWasSet('list') 466 quit 467 setlocal nolist 468 469 set ai 470 call CheckWasSet('ai') 471 set filetype=perl 472 call CheckWasSet('filetype') 473 set fo=tcroq 474 call CheckWasSet('fo') 475 476 split Xsomebuf 477 call CheckWasSet('ai') 478 call CheckWasNotSet('filetype') 479 call CheckWasSet('fo') 480endfunc 481 482func Test_set_ttytype() 483 CheckUnix 484 CheckNotGui 485 486 " Setting 'ttytype' used to cause a double-free when exiting vim and 487 " when vim is compiled with -DEXITFREE. 488 set ttytype=ansi 489 call assert_equal('ansi', &ttytype) 490 call assert_equal(&ttytype, &term) 491 set ttytype=xterm 492 call assert_equal('xterm', &ttytype) 493 call assert_equal(&ttytype, &term) 494 try 495 set ttytype= 496 call assert_report('set ttytype= did not fail') 497 catch /E529/ 498 endtry 499 500 " Some systems accept any terminal name and return dumb settings, 501 " check for failure of finding the entry and for missing 'cm' entry. 502 try 503 set ttytype=xxx 504 call assert_report('set ttytype=xxx did not fail') 505 catch /E522\|E437/ 506 endtry 507 508 set ttytype& 509 call assert_equal(&ttytype, &term) 510 511 if has('gui') && !has('gui_running') 512 call assert_fails('set term=gui', 'E531:') 513 endif 514endfunc 515 516func Test_set_all() 517 set tw=75 518 set iskeyword=a-z,A-Z 519 set nosplitbelow 520 let out = execute('set all') 521 call assert_match('textwidth=75', out) 522 call assert_match('iskeyword=a-z,A-Z', out) 523 call assert_match('nosplitbelow', out) 524 set tw& iskeyword& splitbelow& 525endfunc 526 527func Test_set_one_column() 528 let out_mult = execute('set all')->split("\n") 529 let out_one = execute('set! all')->split("\n") 530 call assert_true(len(out_mult) < len(out_one)) 531endfunc 532 533func Test_set_values() 534 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim 535 if filereadable('opt_test.vim') 536 source opt_test.vim 537 else 538 throw 'Skipped: opt_test.vim does not exist' 539 endif 540endfunc 541 542func Test_renderoptions() 543 " Only do this for Windows Vista and later, fails on Windows XP and earlier. 544 " Doesn't hurt to do this on a non-Windows system. 545 if windowsversion() !~ '^[345]\.' 546 set renderoptions=type:directx 547 set rop=type:directx 548 endif 549endfunc 550 551func ResetIndentexpr() 552 set indentexpr= 553endfunc 554 555func Test_set_indentexpr() 556 " this was causing usage of freed memory 557 set indentexpr=ResetIndentexpr() 558 new 559 call feedkeys("i\<c-f>", 'x') 560 call assert_equal('', &indentexpr) 561 bwipe! 562endfunc 563 564func Test_backupskip() 565 " Option 'backupskip' may contain several comma-separated path 566 " specifications if one or more of the environment variables TMPDIR, TMP, 567 " or TEMP is defined. To simplify testing, convert the string value into a 568 " list. 569 let bsklist = split(&bsk, ',') 570 571 if has("mac") 572 let found = (index(bsklist, '/private/tmp/*') >= 0) 573 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 574 elseif has("unix") 575 let found = (index(bsklist, '/tmp/*') >= 0) 576 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 577 endif 578 579 " If our test platform is Windows, the path(s) in option bsk will use 580 " backslash for the path separator and the components could be in short 581 " (8.3) format. As such, we need to replace the backslashes with forward 582 " slashes and convert the path components to long format. The expand() 583 " function will do this but it cannot handle comma-separated paths. This is 584 " why bsk was converted from a string into a list of strings above. 585 " 586 " One final complication is that the wildcard "/*" is at the end of each 587 " path and so expand() might return a list of matching files. To prevent 588 " this, we need to remove the wildcard before calling expand() and then 589 " append it afterwards. 590 if has('win32') 591 let item_nbr = 0 592 while item_nbr < len(bsklist) 593 let path_spec = bsklist[item_nbr] 594 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 595 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 596 let bsklist[item_nbr] = path_spec . '/*' 597 let item_nbr += 1 598 endwhile 599 endif 600 601 " Option bsk will also include these environment variables if defined. 602 " If they're defined, verify they appear in the option value. 603 for var in ['$TMPDIR', '$TMP', '$TEMP'] 604 if exists(var) 605 let varvalue = substitute(expand(var), '\\', '/', 'g') 606 let varvalue = substitute(varvalue, '/$', '', '') 607 let varvalue .= '/*' 608 let found = (index(bsklist, varvalue) >= 0) 609 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 610 endif 611 endfor 612 613 " Duplicates from environment variables should be filtered out (option has 614 " P_NODUP). Run this in a separate instance and write v:errors in a file, 615 " so that we see what happens on startup. 616 let after =<< trim [CODE] 617 let bsklist = split(&backupskip, ',') 618 call assert_equal(uniq(copy(bsklist)), bsklist) 619 call writefile(['errors:'] + v:errors, 'Xtestout') 620 qall 621 [CODE] 622 call writefile(after, 'Xafter') 623 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' 624 625 let saveenv = {} 626 for var in ['TMPDIR', 'TMP', 'TEMP'] 627 let saveenv[var] = getenv(var) 628 call setenv(var, '/duplicate/path') 629 endfor 630 631 exe 'silent !' . cmd 632 call assert_equal(['errors:'], readfile('Xtestout')) 633 634 " restore environment variables 635 for var in ['TMPDIR', 'TMP', 'TEMP'] 636 call setenv(var, saveenv[var]) 637 endfor 638 639 call delete('Xtestout') 640 call delete('Xafter') 641 642 " Duplicates should be filtered out (option has P_NODUP) 643 let backupskip = &backupskip 644 set backupskip= 645 set backupskip+=/test/dir 646 set backupskip+=/other/dir 647 set backupskip+=/test/dir 648 call assert_equal('/test/dir,/other/dir', &backupskip) 649 let &backupskip = backupskip 650endfunc 651 652func Test_copy_winopt() 653 set hidden 654 655 " Test copy option from current buffer in window 656 split 657 enew 658 setlocal numberwidth=5 659 wincmd w 660 call assert_equal(4,&numberwidth) 661 bnext 662 call assert_equal(5,&numberwidth) 663 bw! 664 call assert_equal(4,&numberwidth) 665 666 " Test copy value from window that used to be display the buffer 667 split 668 enew 669 setlocal numberwidth=6 670 bnext 671 wincmd w 672 call assert_equal(4,&numberwidth) 673 bnext 674 call assert_equal(6,&numberwidth) 675 bw! 676 677 " Test that if buffer is current, don't use the stale cached value 678 " from the last time the buffer was displayed. 679 split 680 enew 681 setlocal numberwidth=7 682 bnext 683 bnext 684 setlocal numberwidth=8 685 wincmd w 686 call assert_equal(4,&numberwidth) 687 bnext 688 call assert_equal(8,&numberwidth) 689 bw! 690 691 " Test value is not copied if window already has seen the buffer 692 enew 693 split 694 setlocal numberwidth=9 695 bnext 696 setlocal numberwidth=10 697 wincmd w 698 call assert_equal(4,&numberwidth) 699 bnext 700 call assert_equal(4,&numberwidth) 701 bw! 702 703 set hidden& 704endfunc 705 706func Test_shortmess_F() 707 new 708 call assert_match('\[No Name\]', execute('file')) 709 set shortmess+=F 710 call assert_match('\[No Name\]', execute('file')) 711 call assert_match('^\s*$', execute('file foo')) 712 call assert_match('foo', execute('file')) 713 set shortmess-=F 714 call assert_match('bar', execute('file bar')) 715 call assert_match('bar', execute('file')) 716 set shortmess& 717 bwipe 718endfunc 719 720func Test_shortmess_F2() 721 e file1 722 e file2 723 call assert_match('file1', execute('bn', '')) 724 call assert_match('file2', execute('bn', '')) 725 set shortmess+=F 726 call assert_true(empty(execute('bn', ''))) 727 call assert_false(test_getvalue('need_fileinfo')) 728 call assert_true(empty(execute('bn', ''))) 729 call assert_false('need_fileinfo'->test_getvalue()) 730 set hidden 731 call assert_true(empty(execute('bn', ''))) 732 call assert_false(test_getvalue('need_fileinfo')) 733 call assert_true(empty(execute('bn', ''))) 734 call assert_false(test_getvalue('need_fileinfo')) 735 set nohidden 736 call assert_true(empty(execute('bn', ''))) 737 call assert_false(test_getvalue('need_fileinfo')) 738 call assert_true(empty(execute('bn', ''))) 739 call assert_false(test_getvalue('need_fileinfo')) 740 set shortmess& 741 call assert_match('file1', execute('bn', '')) 742 call assert_match('file2', execute('bn', '')) 743 bwipe 744 bwipe 745endfunc 746 747func Test_local_scrolloff() 748 set so=5 749 set siso=7 750 split 751 call assert_equal(5, &so) 752 setlocal so=3 753 call assert_equal(3, &so) 754 wincmd w 755 call assert_equal(5, &so) 756 wincmd w 757 setlocal so< 758 call assert_equal(5, &so) 759 setlocal so=0 760 call assert_equal(0, &so) 761 setlocal so=-1 762 call assert_equal(5, &so) 763 764 call assert_equal(7, &siso) 765 setlocal siso=3 766 call assert_equal(3, &siso) 767 wincmd w 768 call assert_equal(7, &siso) 769 wincmd w 770 setlocal siso< 771 call assert_equal(7, &siso) 772 setlocal siso=0 773 call assert_equal(0, &siso) 774 setlocal siso=-1 775 call assert_equal(7, &siso) 776 777 close 778 set so& 779 set siso& 780endfunc 781 782func Test_writedelay() 783 CheckFunction reltimefloat 784 785 new 786 call setline(1, 'empty') 787 redraw 788 set writedelay=10 789 let start = reltime() 790 call setline(1, repeat('x', 70)) 791 redraw 792 let elapsed = reltimefloat(reltime(start)) 793 set writedelay=0 794 " With 'writedelay' set should take at least 30 * 10 msec 795 call assert_inrange(30 * 0.01, 999.0, elapsed) 796 797 bwipe! 798endfunc 799 800func Test_visualbell() 801 set belloff= 802 set visualbell 803 call assert_beeps('normal 0h') 804 set novisualbell 805 set belloff=all 806endfunc 807 808" Test for the 'write' option 809func Test_write() 810 new 811 call setline(1, ['L1']) 812 set nowrite 813 call assert_fails('write Xfile', 'E142:') 814 set write 815 close! 816endfunc 817 818" Test for 'buftype' option 819func Test_buftype() 820 new 821 call setline(1, ['L1']) 822 set buftype=nowrite 823 call assert_fails('write', 'E382:') 824 825 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] 826 exe 'set buftype=' .. val 827 call writefile(['something'], 'XBuftype') 828 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) 829 endfor 830 831 call delete('XBuftype') 832 bwipe! 833endfunc 834 835" Test for the 'rightleftcmd' option 836func Test_rightleftcmd() 837 CheckFeature rightleft 838 set rightleft 839 set rightleftcmd 840 841 let g:l = [] 842 func AddPos() 843 call add(g:l, screencol()) 844 return '' 845 endfunc 846 cmap <expr> <F2> AddPos() 847 848 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. 849 \ "\<Left>\<F2>\<Esc>", 'xt') 850 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) 851 852 cunmap <F2> 853 unlet g:l 854 set rightleftcmd& 855 set rightleft& 856endfunc 857 858" Test for the "debug" option 859func Test_debug_option() 860 set debug=beep 861 exe "normal \<C-c>" 862 call assert_equal('Beep!', Screenline(&lines)) 863 set debug& 864endfunc 865 866" Test for the default CDPATH option 867func Test_opt_default_cdpath() 868 CheckFeature file_in_path 869 let after =<< trim [CODE] 870 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) 871 call writefile(v:errors, 'Xtestout') 872 qall 873 [CODE] 874 if has('unix') 875 let $CDPATH='/path/to/dir1:/path/to/dir2' 876 else 877 let $CDPATH='/path/to/dir1;/path/to/dir2' 878 endif 879 if RunVim([], after, '') 880 call assert_equal([], readfile('Xtestout')) 881 call delete('Xtestout') 882 endif 883endfunc 884 885" Test for setting keycodes using set 886func Test_opt_set_keycode() 887 call assert_fails('set <t_k1=l', 'E474:') 888 call assert_fails('set <Home=l', 'E474:') 889 set <t_k9>=abcd 890 call assert_equal('abcd', &t_k9) 891 set <t_k9>& 892 set <F9>=xyz 893 call assert_equal('xyz', &t_k9) 894 set <t_k9>& 895endfunc 896 897" Test for changing options in a sandbox 898func Test_opt_sandbox() 899 for opt in ['backupdir', 'cdpath', 'exrc'] 900 call assert_fails('sandbox set ' .. opt .. '?', 'E48:') 901 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') 902 endfor 903 call assert_fails('sandbox let &modelineexpr = 1', 'E48:') 904endfunc 905 906" Test for setting an option with local value to global value 907func Test_opt_local_to_global() 908 setglobal equalprg=gprg 909 setlocal equalprg=lprg 910 call assert_equal('gprg', &g:equalprg) 911 call assert_equal('lprg', &l:equalprg) 912 call assert_equal('lprg', &equalprg) 913 set equalprg< 914 call assert_equal('', &l:equalprg) 915 call assert_equal('gprg', &equalprg) 916 setglobal equalprg=gnewprg 917 setlocal equalprg=lnewprg 918 setlocal equalprg< 919 call assert_equal('gnewprg', &l:equalprg) 920 call assert_equal('gnewprg', &equalprg) 921 set equalprg& 922 923 " Test for setting the global/local value of a boolean option 924 setglobal autoread 925 setlocal noautoread 926 call assert_false(&autoread) 927 set autoread< 928 call assert_true(&autoread) 929 setglobal noautoread 930 setlocal autoread 931 setlocal autoread< 932 call assert_false(&autoread) 933 set autoread& 934endfunc 935 936func Test_set_in_sandbox() 937 " Some boolean options cannot be set in sandbox, some can. 938 call assert_fails('sandbox set modelineexpr', 'E48:') 939 sandbox set number 940 call assert_true(&number) 941 set number& 942 943 " Some boolean options cannot be set in sandbox, some can. 944 if has('python') || has('python3') 945 call assert_fails('sandbox set pyxversion=3', 'E48:') 946 endif 947 sandbox set tabstop=4 948 call assert_equal(4, &tabstop) 949 set tabstop& 950 951 " Some string options cannot be set in sandbox, some can. 952 call assert_fails('sandbox set backupdir=/tmp', 'E48:') 953 sandbox set filetype=perl 954 call assert_equal('perl', &filetype) 955 set filetype& 956endfunc 957 958" Test for incrementing, decrementing and multiplying a number option value 959func Test_opt_num_op() 960 set shiftwidth=4 961 set sw+=2 962 call assert_equal(6, &sw) 963 set sw-=2 964 call assert_equal(4, &sw) 965 set sw^=2 966 call assert_equal(8, &sw) 967 set shiftwidth& 968endfunc 969 970" Test for setting option values using v:false and v:true 971func Test_opt_boolean() 972 set number& 973 set number 974 call assert_equal(1, &nu) 975 set nonu 976 call assert_equal(0, &nu) 977 let &nu = v:true 978 call assert_equal(1, &nu) 979 let &nu = v:false 980 call assert_equal(0, &nu) 981 set number& 982endfunc 983 984" Test for the 'window' option 985func Test_window_opt() 986 " Needs only one open widow 987 %bw! 988 call setline(1, range(1, 8)) 989 set window=5 990 exe "normal \<C-F>" 991 call assert_equal(4, line('w0')) 992 exe "normal \<C-F>" 993 call assert_equal(7, line('w0')) 994 exe "normal \<C-F>" 995 call assert_equal(8, line('w0')) 996 exe "normal \<C-B>" 997 call assert_equal(5, line('w0')) 998 exe "normal \<C-B>" 999 call assert_equal(2, line('w0')) 1000 exe "normal \<C-B>" 1001 call assert_equal(1, line('w0')) 1002 set window=1 1003 exe "normal gg\<C-F>" 1004 call assert_equal(2, line('w0')) 1005 exe "normal \<C-F>" 1006 call assert_equal(3, line('w0')) 1007 exe "normal \<C-B>" 1008 call assert_equal(2, line('w0')) 1009 exe "normal \<C-B>" 1010 call assert_equal(1, line('w0')) 1011 enew! 1012 set window& 1013endfunc 1014 1015" Test for the 'winminheight' option 1016func Test_opt_winminheight() 1017 only! 1018 let &winheight = &lines + 4 1019 call assert_fails('let &winminheight = &lines + 2', 'E36:') 1020 call assert_true(&winminheight <= &lines) 1021 set winminheight& 1022 set winheight& 1023endfunc 1024 1025func Test_opt_winminheight_term() 1026 CheckRunVimInTerminal 1027 1028 " The tabline should be taken into account. 1029 let lines =<< trim END 1030 set wmh=0 stal=2 1031 below sp | wincmd _ 1032 below sp | wincmd _ 1033 below sp | wincmd _ 1034 below sp 1035 END 1036 call writefile(lines, 'Xwinminheight') 1037 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) 1038 call term_sendkeys(buf, ":set wmh=1\n") 1039 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) 1040 1041 call StopVimInTerminal(buf) 1042 call delete('Xwinminheight') 1043endfunc 1044 1045func Test_opt_winminheight_term_tabs() 1046 CheckRunVimInTerminal 1047 1048 " The tabline should be taken into account. 1049 let lines =<< trim END 1050 set wmh=0 stal=2 1051 split 1052 split 1053 split 1054 split 1055 tabnew 1056 END 1057 call writefile(lines, 'Xwinminheight') 1058 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11}) 1059 call term_sendkeys(buf, ":set wmh=1\n") 1060 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))}) 1061 1062 call StopVimInTerminal(buf) 1063 call delete('Xwinminheight') 1064endfunc 1065 1066" Test for the 'winminwidth' option 1067func Test_opt_winminwidth() 1068 only! 1069 let &winwidth = &columns + 4 1070 call assert_fails('let &winminwidth = &columns + 2', 'E36:') 1071 call assert_true(&winminwidth <= &columns) 1072 set winminwidth& 1073 set winwidth& 1074endfunc 1075 1076" Test for setting option value containing spaces with isfname+=32 1077func Test_isfname_with_options() 1078 set isfname+=32 1079 setlocal keywordprg=:term\ help.exe 1080 call assert_equal(':term help.exe', &keywordprg) 1081 set isfname& 1082 setlocal keywordprg& 1083endfunc 1084 1085" Test that resetting laststatus does change scroll option 1086func Test_opt_reset_scroll() 1087 CheckRunVimInTerminal 1088 let vimrc =<< trim [CODE] 1089 set scroll=2 1090 set laststatus=2 1091 [CODE] 1092 call writefile(vimrc, 'Xscroll') 1093 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45}) 1094 call term_sendkeys(buf, ":verbose set scroll?\n") 1095 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))}) 1096 call assert_match('^\s*scroll=7$', term_getline(buf, 14)) 1097 call StopVimInTerminal(buf) 1098 1099 " clean up 1100 call delete('Xscroll') 1101endfunc 1102 1103" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm' 1104func Test_VIM_POSIX() 1105 let saved_VIM_POSIX = getenv("VIM_POSIX") 1106 1107 call setenv('VIM_POSIX', "1") 1108 let after =<< trim [CODE] 1109 call writefile([&cpo, &shm], 'X_VIM_POSIX') 1110 qall 1111 [CODE] 1112 if RunVim([], after, '') 1113 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;', 1114 \ 'AS'], readfile('X_VIM_POSIX')) 1115 endif 1116 1117 call setenv('VIM_POSIX', v:null) 1118 let after =<< trim [CODE] 1119 call writefile([&cpo, &shm], 'X_VIM_POSIX') 1120 qall 1121 [CODE] 1122 if RunVim([], after, '') 1123 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;', 1124 \ 'S'], readfile('X_VIM_POSIX')) 1125 endif 1126 1127 call delete('X_VIM_POSIX') 1128 call setenv('VIM_POSIX', saved_VIM_POSIX) 1129endfunc 1130 1131" Test for setting an option to a Vi or Vim default 1132func Test_opt_default() 1133 set formatoptions&vi 1134 call assert_equal('vt', &formatoptions) 1135 set formatoptions&vim 1136 call assert_equal('tcq', &formatoptions) 1137 1138 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) 1139 set fencs=latin1 1140 set fencs& 1141 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) 1142 set fencs=latin1 1143 set all& 1144 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) 1145endfunc 1146 1147" Test for the 'cmdheight' option 1148func Test_cmdheight() 1149 %bw! 1150 let ht = &lines 1151 set cmdheight=9999 1152 call assert_equal(1, winheight(0)) 1153 call assert_equal(ht - 1, &cmdheight) 1154 set cmdheight& 1155endfunc 1156 1157" To specify a control character as a option value, '^' can be used 1158func Test_opt_control_char() 1159 set wildchar=^v 1160 call assert_equal("\<C-V>", nr2char(&wildchar)) 1161 set wildcharm=^r 1162 call assert_equal("\<C-R>", nr2char(&wildcharm)) 1163 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options 1164 set wildchar& wildcharm& 1165endfunc 1166 1167" Test for the 'errorbells' option 1168func Test_opt_errorbells() 1169 set errorbells 1170 call assert_beeps('s/a1b2/x1y2/') 1171 set noerrorbells 1172endfunc 1173 1174func Test_opt_scrolljump() 1175 help 1176 resize 10 1177 1178 " Test with positive 'scrolljump'. 1179 set scrolljump=2 1180 norm! Lj 1181 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, 1182 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0}, 1183 \ winsaveview()) 1184 1185 " Test with negative 'scrolljump' (percentage of window height). 1186 set scrolljump=-40 1187 norm! ggLj 1188 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0, 1189 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0}, 1190 \ winsaveview()) 1191 1192 set scrolljump& 1193 bw 1194endfunc 1195 1196" vim: shiftwidth=2 sts=2 expandtab 1197