1" Test for options 2 3source check.vim 4source view_util.vim 5 6func Test_whichwrap() 7 set whichwrap=b,s 8 call assert_equal('b,s', &whichwrap) 9 10 set whichwrap+=h,l 11 call assert_equal('b,s,h,l', &whichwrap) 12 13 set whichwrap+=h,l 14 call assert_equal('b,s,h,l', &whichwrap) 15 16 set whichwrap+=h,l 17 call assert_equal('b,s,h,l', &whichwrap) 18 19 set whichwrap=h,h 20 call assert_equal('h', &whichwrap) 21 22 set whichwrap=h,h,h 23 call assert_equal('h', &whichwrap) 24 25 " For compatibility with Vim 3.0 and before, number values are also 26 " supported for 'whichwrap' 27 set whichwrap=1 28 call assert_equal('b', &whichwrap) 29 set whichwrap=2 30 call assert_equal('s', &whichwrap) 31 set whichwrap=4 32 call assert_equal('h,l', &whichwrap) 33 set whichwrap=8 34 call assert_equal('<,>', &whichwrap) 35 set whichwrap=16 36 call assert_equal('[,]', &whichwrap) 37 set whichwrap=31 38 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap) 39 40 set whichwrap& 41endfunc 42 43func Test_isfname() 44 " This used to cause Vim to access uninitialized memory. 45 set isfname= 46 call assert_equal("~X", expand("~X")) 47 set isfname& 48endfunc 49 50func Test_wildchar() 51 " Empty 'wildchar' used to access invalid memory. 52 call assert_fails('set wildchar=', 'E521:') 53 call assert_fails('set wildchar=abc', 'E521:') 54 set wildchar=<Esc> 55 let a=execute('set wildchar?') 56 call assert_equal("\n wildchar=<Esc>", a) 57 set wildchar=27 58 let a=execute('set wildchar?') 59 call assert_equal("\n wildchar=<Esc>", a) 60 set wildchar& 61endfunc 62 63func Test_options_command() 64 let caught = 'ok' 65 try 66 options 67 catch 68 let caught = v:throwpoint . "\n" . v:exception 69 endtry 70 call assert_equal('ok', caught) 71 72 " Check if the option-window is opened horizontally. 73 wincmd j 74 call assert_notequal('option-window', bufname('')) 75 wincmd k 76 call assert_equal('option-window', bufname('')) 77 " close option-window 78 close 79 80 " Open the option-window vertically. 81 vert options 82 " Check if the option-window is opened vertically. 83 wincmd l 84 call assert_notequal('option-window', bufname('')) 85 wincmd h 86 call assert_equal('option-window', bufname('')) 87 " close option-window 88 close 89 90 " Open the option-window in a new tab. 91 tab options 92 " Check if the option-window is opened in a tab. 93 normal gT 94 call assert_notequal('option-window', bufname('')) 95 normal gt 96 call assert_equal('option-window', bufname('')) 97 98 " close option-window 99 close 100 101 " Open the options window browse 102 if has('browse') 103 browse set 104 call assert_equal('option-window', bufname('')) 105 close 106 endif 107endfunc 108 109func Test_path_keep_commas() 110 " Test that changing 'path' keeps two commas. 111 set path=foo,,bar 112 set path-=bar 113 set path+=bar 114 call assert_equal('foo,,bar', &path) 115 116 set path& 117endfunc 118 119func Test_signcolumn() 120 if has('signs') 121 call assert_equal("auto", &signcolumn) 122 set signcolumn=yes 123 set signcolumn=no 124 call assert_fails('set signcolumn=nope') 125 endif 126endfunc 127 128func Test_filetype_valid() 129 set ft=valid_name 130 call assert_equal("valid_name", &filetype) 131 set ft=valid-name 132 call assert_equal("valid-name", &filetype) 133 134 call assert_fails(":set ft=wrong;name", "E474:") 135 call assert_fails(":set ft=wrong\\\\name", "E474:") 136 call assert_fails(":set ft=wrong\\|name", "E474:") 137 call assert_fails(":set ft=wrong/name", "E474:") 138 call assert_fails(":set ft=wrong\\\nname", "E474:") 139 call assert_equal("valid-name", &filetype) 140 141 exe "set ft=trunc\x00name" 142 call assert_equal("trunc", &filetype) 143endfunc 144 145func Test_syntax_valid() 146 if !has('syntax') 147 return 148 endif 149 set syn=valid_name 150 call assert_equal("valid_name", &syntax) 151 set syn=valid-name 152 call assert_equal("valid-name", &syntax) 153 154 call assert_fails(":set syn=wrong;name", "E474:") 155 call assert_fails(":set syn=wrong\\\\name", "E474:") 156 call assert_fails(":set syn=wrong\\|name", "E474:") 157 call assert_fails(":set syn=wrong/name", "E474:") 158 call assert_fails(":set syn=wrong\\\nname", "E474:") 159 call assert_equal("valid-name", &syntax) 160 161 exe "set syn=trunc\x00name" 162 call assert_equal("trunc", &syntax) 163endfunc 164 165func Test_keymap_valid() 166 if !has('keymap') 167 return 168 endif 169 call assert_fails(":set kmp=valid_name", "E544:") 170 call assert_fails(":set kmp=valid_name", "valid_name") 171 call assert_fails(":set kmp=valid-name", "E544:") 172 call assert_fails(":set kmp=valid-name", "valid-name") 173 174 call assert_fails(":set kmp=wrong;name", "E474:") 175 call assert_fails(":set kmp=wrong\\\\name", "E474:") 176 call assert_fails(":set kmp=wrong\\|name", "E474:") 177 call assert_fails(":set kmp=wrong/name", "E474:") 178 call assert_fails(":set kmp=wrong\\\nname", "E474:") 179 180 call assert_fails(":set kmp=trunc\x00name", "E544:") 181 call assert_fails(":set kmp=trunc\x00name", "trunc") 182endfunc 183 184func Check_dir_option(name) 185 " Check that it's possible to set the option. 186 exe 'set ' . a:name . '=/usr/share/dict/words' 187 call assert_equal('/usr/share/dict/words', eval('&' . a:name)) 188 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' 189 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) 190 exe 'set ' . a:name . '=/usr/share/dict\ words' 191 call assert_equal('/usr/share/dict words', eval('&' . a:name)) 192 193 " Check rejecting weird characters. 194 call assert_fails("set " . a:name . "=/not&there", "E474:") 195 call assert_fails("set " . a:name . "=/not>there", "E474:") 196 call assert_fails("set " . a:name . "=/not.*there", "E474:") 197endfunc 198 199func Test_cinkeys() 200 " This used to cause invalid memory access 201 set cindent cinkeys=0 202 norm a 203 set cindent& cinkeys& 204endfunc 205 206func Test_dictionary() 207 call Check_dir_option('dictionary') 208endfunc 209 210func Test_thesaurus() 211 call Check_dir_option('thesaurus') 212endfun 213 214func Test_complete() 215 " Trailing single backslash used to cause invalid memory access. 216 set complete=s\ 217 new 218 call feedkeys("i\<C-N>\<Esc>", 'xt') 219 bwipe! 220 call assert_fails('set complete=ix', 'E535:') 221 set complete& 222endfun 223 224func Test_set_completion() 225 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') 226 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) 227 228 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx') 229 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:) 230 231 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') 232 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) 233 234 " Expand boolan options. When doing :set no<Tab> 235 " vim displays the options names without "no" but completion uses "no...". 236 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') 237 call assert_equal('"set nodiff digraph', @:) 238 239 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') 240 call assert_equal('"set invdiff digraph', @:) 241 242 " Expand abbreviation of options. 243 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') 244 call assert_equal('"set tabstop thesaurus ttyscroll', @:) 245 246 " Expand current value 247 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') 248 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) 249 250 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') 251 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) 252 253 " Expand key codes. 254 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') 255 call assert_equal('"set <Help> <Home>', @:) 256 257 " Expand terminal options. 258 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') 259 call assert_equal('"set t_AB t_AF t_AL', @:) 260 261 " Expand directories. 262 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') 263 call assert_match(' ./samples/ ', @:) 264 call assert_notmatch(' ./small.vim ', @:) 265 266 " Expand files and directories. 267 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') 268 call assert_match(' ./samples/.* ./small.vim', @:) 269 270 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') 271 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) 272 set tags& 273 274 " Expanding the option names 275 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') 276 call assert_equal('"set all', @:) 277 278 " Expanding a second set of option names 279 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt') 280 call assert_equal('"set wrapscan all', @:) 281 282 " Expanding a special keycode 283 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt') 284 call assert_equal('"set <Home>', @:) 285 286 " Expanding an invalid special keycode 287 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt') 288 call assert_equal("\"set <abcd>\<Tab>", @:) 289 290 " Expanding a terminal keycode 291 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt') 292 call assert_equal("\"set t_AB", @:) 293 294 " Expanding an invalid option name 295 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt') 296 call assert_equal("\"set abcde=\<Tab>", @:) 297 298 " Expanding after a = for a boolean option 299 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt') 300 call assert_equal("\"set wrapscan=\<Tab>", @:) 301 302 " Expanding a numeric option 303 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt') 304 call assert_equal("\"set tabstop+=" .. &tabstop, @:) 305 306 " Expanding a non-boolean option 307 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt') 308 call assert_equal("\"set invtabstop=", @:) 309 310 " Expand options for 'spellsuggest' 311 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt') 312 call assert_equal("\"set spellsuggest=best,file:xyz", @:) 313 314 " Expand value for 'key' 315 set key=abcd 316 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt') 317 call assert_equal('"set key=*****', @:) 318 set key= 319endfunc 320 321func Test_set_errors() 322 call assert_fails('set scroll=-1', 'E49:') 323 call assert_fails('set backupcopy=', 'E474:') 324 call assert_fails('set regexpengine=3', 'E474:') 325 call assert_fails('set history=10001', 'E474:') 326 call assert_fails('set numberwidth=21', 'E474:') 327 call assert_fails('set colorcolumn=-a', 'E474:') 328 call assert_fails('set colorcolumn=a', 'E474:') 329 call assert_fails('set colorcolumn=1,', 'E474:') 330 call assert_fails('set colorcolumn=1;', 'E474:') 331 call assert_fails('set cmdheight=-1', 'E487:') 332 call assert_fails('set cmdwinheight=-1', 'E487:') 333 if has('conceal') 334 call assert_fails('set conceallevel=-1', 'E487:') 335 call assert_fails('set conceallevel=4', 'E474:') 336 endif 337 call assert_fails('set helpheight=-1', 'E487:') 338 call assert_fails('set history=-1', 'E487:') 339 call assert_fails('set report=-1', 'E487:') 340 call assert_fails('set shiftwidth=-1', 'E487:') 341 call assert_fails('set sidescroll=-1', 'E487:') 342 call assert_fails('set tabstop=-1', 'E487:') 343 call assert_fails('set textwidth=-1', 'E487:') 344 call assert_fails('set timeoutlen=-1', 'E487:') 345 call assert_fails('set updatecount=-1', 'E487:') 346 call assert_fails('set updatetime=-1', 'E487:') 347 call assert_fails('set winheight=-1', 'E487:') 348 call assert_fails('set tabstop!', 'E488:') 349 call assert_fails('set xxx', 'E518:') 350 call assert_fails('set beautify?', 'E519:') 351 call assert_fails('set undolevels=x', 'E521:') 352 call assert_fails('set tabstop=', 'E521:') 353 call assert_fails('set comments=-', 'E524:') 354 call assert_fails('set comments=a', 'E525:') 355 call assert_fails('set foldmarker=x', 'E536:') 356 call assert_fails('set commentstring=x', 'E537:') 357 call assert_fails('set complete=x', 'E539:') 358 call assert_fails('set statusline=%{', 'E540:') 359 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 360 call assert_fails('set statusline=%(', 'E542:') 361 if has('cursorshape') 362 " This invalid value for 'guicursor' used to cause Vim to crash. 363 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 364 call assert_fails('set guicursor=i-ci', 'E545:') 365 call assert_fails('set guicursor=x', 'E545:') 366 call assert_fails('set guicursor=x:', 'E546:') 367 call assert_fails('set guicursor=r-cr:horx', 'E548:') 368 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 369 endif 370 if has('mouseshape') 371 call assert_fails('se mouseshape=i-r:x', 'E547:') 372 endif 373 call assert_fails('set backupext=~ patchmode=~', 'E589:') 374 call assert_fails('set winminheight=10 winheight=9', 'E591:') 375 set winminheight& winheight& 376 set winheight=10 winminheight=10 377 call assert_fails('set winheight=9', 'E591:') 378 set winminheight& winheight& 379 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 380 set winminwidth& winwidth& 381 call assert_fails('set winwidth=9 winminwidth=10', 'E592:') 382 set winwidth& winminwidth& 383 call assert_fails("set showbreak=\x01", 'E595:') 384 call assert_fails('set t_foo=', 'E846:') 385 call assert_fails('set tabstop??', 'E488:') 386 call assert_fails('set wrapscan!!', 'E488:') 387 call assert_fails('set tabstop&&', 'E488:') 388 call assert_fails('set wrapscan<<', 'E488:') 389 call assert_fails('set wrapscan=1', 'E474:') 390 call assert_fails('set autoindent@', 'E488:') 391 call assert_fails('set wildchar=<abc>', 'E474:') 392 call assert_fails('set cmdheight=1a', 'E521:') 393 call assert_fails('set invcmdheight', 'E474:') 394 if has('python') && has('python3') 395 call assert_fails('set pyxversion=6', 'E474:') 396 endif 397 call assert_fails("let &tabstop='ab'", 'E521:') 398endfunc 399 400func CheckWasSet(name) 401 let verb_cm = execute('verbose set ' .. a:name .. '?') 402 call assert_match('Last set from.*test_options.vim', verb_cm) 403endfunc 404func CheckWasNotSet(name) 405 let verb_cm = execute('verbose set ' .. a:name .. '?') 406 call assert_notmatch('Last set from', verb_cm) 407endfunc 408 409" Must be executed before other tests that set 'term'. 410func Test_000_term_option_verbose() 411 CheckNotGui 412 413 call CheckWasNotSet('t_cm') 414 415 let term_save = &term 416 set term=ansi 417 call CheckWasSet('t_cm') 418 let &term = term_save 419endfunc 420 421func Test_copy_context() 422 setlocal list 423 call CheckWasSet('list') 424 split 425 call CheckWasSet('list') 426 quit 427 setlocal nolist 428 429 set ai 430 call CheckWasSet('ai') 431 set filetype=perl 432 call CheckWasSet('filetype') 433 set fo=tcroq 434 call CheckWasSet('fo') 435 436 split Xsomebuf 437 call CheckWasSet('ai') 438 call CheckWasNotSet('filetype') 439 call CheckWasSet('fo') 440endfunc 441 442func Test_set_ttytype() 443 CheckUnix 444 CheckNotGui 445 446 " Setting 'ttytype' used to cause a double-free when exiting vim and 447 " when vim is compiled with -DEXITFREE. 448 set ttytype=ansi 449 call assert_equal('ansi', &ttytype) 450 call assert_equal(&ttytype, &term) 451 set ttytype=xterm 452 call assert_equal('xterm', &ttytype) 453 call assert_equal(&ttytype, &term) 454 " "set ttytype=" gives E522 instead of E529 455 " in travis on some builds. Why? Catch both for now 456 try 457 set ttytype= 458 call assert_report('set ttytype= did not fail') 459 catch /E529\|E522/ 460 endtry 461 462 " Some systems accept any terminal name and return dumb settings, 463 " check for failure of finding the entry and for missing 'cm' entry. 464 try 465 set ttytype=xxx 466 call assert_report('set ttytype=xxx did not fail') 467 catch /E522\|E437/ 468 endtry 469 470 set ttytype& 471 call assert_equal(&ttytype, &term) 472 473 if has('gui') && !has('gui_running') 474 call assert_fails('set term=gui', 'E531:') 475 endif 476endfunc 477 478func Test_set_all() 479 set tw=75 480 set iskeyword=a-z,A-Z 481 set nosplitbelow 482 let out = execute('set all') 483 call assert_match('textwidth=75', out) 484 call assert_match('iskeyword=a-z,A-Z', out) 485 call assert_match('nosplitbelow', out) 486 set tw& iskeyword& splitbelow& 487endfunc 488 489func Test_set_one_column() 490 let out_mult = execute('set all')->split("\n") 491 let out_one = execute('set! all')->split("\n") 492 call assert_true(len(out_mult) < len(out_one)) 493endfunc 494 495func Test_set_values() 496 if filereadable('opt_test.vim') 497 source opt_test.vim 498 else 499 throw 'Skipped: opt_test.vim does not exist' 500 endif 501endfunc 502 503func Test_renderoptions() 504 " Only do this for Windows Vista and later, fails on Windows XP and earlier. 505 " Doesn't hurt to do this on a non-Windows system. 506 if windowsversion() !~ '^[345]\.' 507 set renderoptions=type:directx 508 set rop=type:directx 509 endif 510endfunc 511 512func ResetIndentexpr() 513 set indentexpr= 514endfunc 515 516func Test_set_indentexpr() 517 " this was causing usage of freed memory 518 set indentexpr=ResetIndentexpr() 519 new 520 call feedkeys("i\<c-f>", 'x') 521 call assert_equal('', &indentexpr) 522 bwipe! 523endfunc 524 525func Test_backupskip() 526 " Option 'backupskip' may contain several comma-separated path 527 " specifications if one or more of the environment variables TMPDIR, TMP, 528 " or TEMP is defined. To simplify testing, convert the string value into a 529 " list. 530 let bsklist = split(&bsk, ',') 531 532 if has("mac") 533 let found = (index(bsklist, '/private/tmp/*') >= 0) 534 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 535 elseif has("unix") 536 let found = (index(bsklist, '/tmp/*') >= 0) 537 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 538 endif 539 540 " If our test platform is Windows, the path(s) in option bsk will use 541 " backslash for the path separator and the components could be in short 542 " (8.3) format. As such, we need to replace the backslashes with forward 543 " slashes and convert the path components to long format. The expand() 544 " function will do this but it cannot handle comma-separated paths. This is 545 " why bsk was converted from a string into a list of strings above. 546 " 547 " One final complication is that the wildcard "/*" is at the end of each 548 " path and so expand() might return a list of matching files. To prevent 549 " this, we need to remove the wildcard before calling expand() and then 550 " append it afterwards. 551 if has('win32') 552 let item_nbr = 0 553 while item_nbr < len(bsklist) 554 let path_spec = bsklist[item_nbr] 555 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 556 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 557 let bsklist[item_nbr] = path_spec . '/*' 558 let item_nbr += 1 559 endwhile 560 endif 561 562 " Option bsk will also include these environment variables if defined. 563 " If they're defined, verify they appear in the option value. 564 for var in ['$TMPDIR', '$TMP', '$TEMP'] 565 if exists(var) 566 let varvalue = substitute(expand(var), '\\', '/', 'g') 567 let varvalue = substitute(varvalue, '/$', '', '') 568 let varvalue .= '/*' 569 let found = (index(bsklist, varvalue) >= 0) 570 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 571 endif 572 endfor 573 574 " Duplicates should be filtered out (option has P_NODUP) 575 let backupskip = &backupskip 576 set backupskip= 577 set backupskip+=/test/dir 578 set backupskip+=/other/dir 579 set backupskip+=/test/dir 580 call assert_equal('/test/dir,/other/dir', &backupskip) 581 let &backupskip = backupskip 582endfunc 583 584func Test_copy_winopt() 585 set hidden 586 587 " Test copy option from current buffer in window 588 split 589 enew 590 setlocal numberwidth=5 591 wincmd w 592 call assert_equal(4,&numberwidth) 593 bnext 594 call assert_equal(5,&numberwidth) 595 bw! 596 call assert_equal(4,&numberwidth) 597 598 " Test copy value from window that used to be display the buffer 599 split 600 enew 601 setlocal numberwidth=6 602 bnext 603 wincmd w 604 call assert_equal(4,&numberwidth) 605 bnext 606 call assert_equal(6,&numberwidth) 607 bw! 608 609 " Test that if buffer is current, don't use the stale cached value 610 " from the last time the buffer was displayed. 611 split 612 enew 613 setlocal numberwidth=7 614 bnext 615 bnext 616 setlocal numberwidth=8 617 wincmd w 618 call assert_equal(4,&numberwidth) 619 bnext 620 call assert_equal(8,&numberwidth) 621 bw! 622 623 " Test value is not copied if window already has seen the buffer 624 enew 625 split 626 setlocal numberwidth=9 627 bnext 628 setlocal numberwidth=10 629 wincmd w 630 call assert_equal(4,&numberwidth) 631 bnext 632 call assert_equal(4,&numberwidth) 633 bw! 634 635 set hidden& 636endfunc 637 638func Test_shortmess_F() 639 new 640 call assert_match('\[No Name\]', execute('file')) 641 set shortmess+=F 642 call assert_match('\[No Name\]', execute('file')) 643 call assert_match('^\s*$', execute('file foo')) 644 call assert_match('foo', execute('file')) 645 set shortmess-=F 646 call assert_match('bar', execute('file bar')) 647 call assert_match('bar', execute('file')) 648 set shortmess& 649 bwipe 650endfunc 651 652func Test_shortmess_F2() 653 e file1 654 e file2 655 call assert_match('file1', execute('bn', '')) 656 call assert_match('file2', execute('bn', '')) 657 set shortmess+=F 658 call assert_true(empty(execute('bn', ''))) 659 call assert_false(test_getvalue('need_fileinfo')) 660 call assert_true(empty(execute('bn', ''))) 661 call assert_false('need_fileinfo'->test_getvalue()) 662 set hidden 663 call assert_true(empty(execute('bn', ''))) 664 call assert_false(test_getvalue('need_fileinfo')) 665 call assert_true(empty(execute('bn', ''))) 666 call assert_false(test_getvalue('need_fileinfo')) 667 set nohidden 668 call assert_true(empty(execute('bn', ''))) 669 call assert_false(test_getvalue('need_fileinfo')) 670 call assert_true(empty(execute('bn', ''))) 671 call assert_false(test_getvalue('need_fileinfo')) 672 set shortmess& 673 call assert_match('file1', execute('bn', '')) 674 call assert_match('file2', execute('bn', '')) 675 bwipe 676 bwipe 677endfunc 678 679func Test_local_scrolloff() 680 set so=5 681 set siso=7 682 split 683 call assert_equal(5, &so) 684 setlocal so=3 685 call assert_equal(3, &so) 686 wincmd w 687 call assert_equal(5, &so) 688 wincmd w 689 setlocal so< 690 call assert_equal(5, &so) 691 setlocal so=0 692 call assert_equal(0, &so) 693 setlocal so=-1 694 call assert_equal(5, &so) 695 696 call assert_equal(7, &siso) 697 setlocal siso=3 698 call assert_equal(3, &siso) 699 wincmd w 700 call assert_equal(7, &siso) 701 wincmd w 702 setlocal siso< 703 call assert_equal(7, &siso) 704 setlocal siso=0 705 call assert_equal(0, &siso) 706 setlocal siso=-1 707 call assert_equal(7, &siso) 708 709 close 710 set so& 711 set siso& 712endfunc 713 714func Test_writedelay() 715 CheckFunction reltimefloat 716 717 new 718 call setline(1, 'empty') 719 redraw 720 set writedelay=10 721 let start = reltime() 722 call setline(1, repeat('x', 70)) 723 redraw 724 let elapsed = reltimefloat(reltime(start)) 725 set writedelay=0 726 " With 'writedelay' set should take at least 30 * 10 msec 727 call assert_inrange(30 * 0.01, 999.0, elapsed) 728 729 bwipe! 730endfunc 731 732func Test_visualbell() 733 set belloff= 734 set visualbell 735 call assert_beeps('normal 0h') 736 set novisualbell 737 set belloff=all 738endfunc 739 740" Test for the 'write' option 741func Test_write() 742 new 743 call setline(1, ['L1']) 744 set nowrite 745 call assert_fails('write Xfile', 'E142:') 746 set write 747 close! 748endfunc 749 750" Test for 'buftype' option 751func Test_buftype() 752 new 753 call setline(1, ['L1']) 754 set buftype=nowrite 755 call assert_fails('write', 'E382:') 756 757 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] 758 exe 'set buftype=' .. val 759 call writefile(['something'], 'XBuftype') 760 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) 761 endfor 762 763 call delete('XBuftype') 764 bwipe! 765endfunc 766 767" Test for the 'shell' option 768func Test_shell() 769 CheckUnix 770 let save_shell = &shell 771 set shell= 772 call assert_fails('shell', 'E91:') 773 let &shell = save_shell 774endfunc 775 776" Test for the 'shellquote' option 777func Test_shellquote() 778 CheckUnix 779 set shellquote=# 780 set verbose=20 781 redir => v 782 silent! !echo Hello 783 redir END 784 set verbose& 785 set shellquote& 786 call assert_match(': "#echo Hello#"', v) 787endfunc 788 789" Test for the 'rightleftcmd' option 790func Test_rightleftcmd() 791 CheckFeature rightleft 792 set rightleft 793 set rightleftcmd 794 795 let g:l = [] 796 func AddPos() 797 call add(g:l, screencol()) 798 return '' 799 endfunc 800 cmap <expr> <F2> AddPos() 801 802 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. 803 \ "\<Left>\<F2>\<Esc>", 'xt') 804 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) 805 806 cunmap <F2> 807 unlet g:l 808 set rightleftcmd& 809 set rightleft& 810endfunc 811 812" Test for the "debug" option 813func Test_debug_option() 814 set debug=beep 815 exe "normal \<C-c>" 816 call assert_equal('Beep!', Screenline(&lines)) 817 set debug& 818endfunc 819 820" Test for the default CDPATH option 821func Test_opt_default_cdpath() 822 CheckFeature file_in_path 823 let after =<< trim [CODE] 824 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) 825 call writefile(v:errors, 'Xtestout') 826 qall 827 [CODE] 828 if has('unix') 829 let $CDPATH='/path/to/dir1:/path/to/dir2' 830 else 831 let $CDPATH='/path/to/dir1;/path/to/dir2' 832 endif 833 if RunVim([], after, '') 834 call assert_equal([], readfile('Xtestout')) 835 call delete('Xtestout') 836 endif 837endfunc 838 839" Test for setting keycodes using set 840func Test_opt_set_keycode() 841 call assert_fails('set <t_k1=l', 'E474:') 842 call assert_fails('set <Home=l', 'E474:') 843 set <t_k9>=abcd 844 call assert_equal('abcd', &t_k9) 845 set <t_k9>& 846 set <F9>=xyz 847 call assert_equal('xyz', &t_k9) 848 set <t_k9>& 849endfunc 850 851" Test for changing options in a sandbox 852func Test_opt_sandbox() 853 for opt in ['backupdir', 'cdpath', 'exrc'] 854 call assert_fails('sandbox set ' .. opt .. '?', 'E48:') 855 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') 856 endfor 857 call assert_fails('sandbox let &modelineexpr = 1', 'E48:') 858endfunc 859 860" Test for setting an option with local value to global value 861func Test_opt_local_to_global() 862 setglobal equalprg=gprg 863 setlocal equalprg=lprg 864 call assert_equal('gprg', &g:equalprg) 865 call assert_equal('lprg', &l:equalprg) 866 call assert_equal('lprg', &equalprg) 867 set equalprg< 868 call assert_equal('', &l:equalprg) 869 call assert_equal('gprg', &equalprg) 870 setglobal equalprg=gnewprg 871 setlocal equalprg=lnewprg 872 setlocal equalprg< 873 call assert_equal('gnewprg', &l:equalprg) 874 call assert_equal('gnewprg', &equalprg) 875 set equalprg& 876endfunc 877 878" Test for incrementing, decrementing and multiplying a number option value 879func Test_opt_num_op() 880 set shiftwidth=4 881 set sw+=2 882 call assert_equal(6, &sw) 883 set sw-=2 884 call assert_equal(4, &sw) 885 set sw^=2 886 call assert_equal(8, &sw) 887 set shiftwidth& 888endfunc 889 890" vim: shiftwidth=2 sts=2 expandtab 891