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= 335endfunc 336 337func Test_set_errors() 338 call assert_fails('set scroll=-1', 'E49:') 339 call assert_fails('set backupcopy=', 'E474:') 340 call assert_fails('set regexpengine=3', 'E474:') 341 call assert_fails('set history=10001', 'E474:') 342 call assert_fails('set numberwidth=21', 'E474:') 343 call assert_fails('set colorcolumn=-a', 'E474:') 344 call assert_fails('set colorcolumn=a', 'E474:') 345 call assert_fails('set colorcolumn=1,', 'E474:') 346 call assert_fails('set colorcolumn=1;', 'E474:') 347 call assert_fails('set cmdheight=-1', 'E487:') 348 call assert_fails('set cmdwinheight=-1', 'E487:') 349 if has('conceal') 350 call assert_fails('set conceallevel=-1', 'E487:') 351 call assert_fails('set conceallevel=4', 'E474:') 352 endif 353 call assert_fails('set helpheight=-1', 'E487:') 354 call assert_fails('set history=-1', 'E487:') 355 call assert_fails('set report=-1', 'E487:') 356 call assert_fails('set shiftwidth=-1', 'E487:') 357 call assert_fails('set sidescroll=-1', 'E487:') 358 call assert_fails('set tabstop=-1', 'E487:') 359 call assert_fails('set textwidth=-1', 'E487:') 360 call assert_fails('set timeoutlen=-1', 'E487:') 361 call assert_fails('set updatecount=-1', 'E487:') 362 call assert_fails('set updatetime=-1', 'E487:') 363 call assert_fails('set winheight=-1', 'E487:') 364 call assert_fails('set tabstop!', 'E488:') 365 call assert_fails('set xxx', 'E518:') 366 call assert_fails('set beautify?', 'E519:') 367 call assert_fails('set undolevels=x', 'E521:') 368 call assert_fails('set tabstop=', 'E521:') 369 call assert_fails('set comments=-', 'E524:') 370 call assert_fails('set comments=a', 'E525:') 371 call assert_fails('set foldmarker=x', 'E536:') 372 call assert_fails('set commentstring=x', 'E537:') 373 call assert_fails('set complete=x', 'E539:') 374 call assert_fails('set statusline=%{', 'E540:') 375 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 376 call assert_fails('set statusline=%(', 'E542:') 377 if has('cursorshape') 378 " This invalid value for 'guicursor' used to cause Vim to crash. 379 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 380 call assert_fails('set guicursor=i-ci', 'E545:') 381 call assert_fails('set guicursor=x', 'E545:') 382 call assert_fails('set guicursor=x:', 'E546:') 383 call assert_fails('set guicursor=r-cr:horx', 'E548:') 384 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 385 endif 386 if has('mouseshape') 387 call assert_fails('se mouseshape=i-r:x', 'E547:') 388 endif 389 call assert_fails('set backupext=~ patchmode=~', 'E589:') 390 call assert_fails('set winminheight=10 winheight=9', 'E591:') 391 set winminheight& winheight& 392 set winheight=10 winminheight=10 393 call assert_fails('set winheight=9', 'E591:') 394 set winminheight& winheight& 395 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 396 set winminwidth& winwidth& 397 call assert_fails('set winwidth=9 winminwidth=10', 'E592:') 398 set winwidth& winminwidth& 399 call assert_fails("set showbreak=\x01", 'E595:') 400 call assert_fails('set t_foo=', 'E846:') 401 call assert_fails('set tabstop??', 'E488:') 402 call assert_fails('set wrapscan!!', 'E488:') 403 call assert_fails('set tabstop&&', 'E488:') 404 call assert_fails('set wrapscan<<', 'E488:') 405 call assert_fails('set wrapscan=1', 'E474:') 406 call assert_fails('set autoindent@', 'E488:') 407 call assert_fails('set wildchar=<abc>', 'E474:') 408 call assert_fails('set cmdheight=1a', 'E521:') 409 call assert_fails('set invcmdheight', 'E474:') 410 if has('python') && has('python3') 411 call assert_fails('set pyxversion=6', 'E474:') 412 endif 413 call assert_fails("let &tabstop='ab'", 'E521:') 414 call assert_fails('set spellcapcheck=%\\(', 'E54:') 415endfunc 416 417func CheckWasSet(name) 418 let verb_cm = execute('verbose set ' .. a:name .. '?') 419 call assert_match('Last set from.*test_options.vim', verb_cm) 420endfunc 421func CheckWasNotSet(name) 422 let verb_cm = execute('verbose set ' .. a:name .. '?') 423 call assert_notmatch('Last set from', verb_cm) 424endfunc 425 426" Must be executed before other tests that set 'term'. 427func Test_000_term_option_verbose() 428 CheckNotGui 429 430 call CheckWasNotSet('t_cm') 431 432 let term_save = &term 433 set term=ansi 434 call CheckWasSet('t_cm') 435 let &term = term_save 436endfunc 437 438func Test_copy_context() 439 setlocal list 440 call CheckWasSet('list') 441 split 442 call CheckWasSet('list') 443 quit 444 setlocal nolist 445 446 set ai 447 call CheckWasSet('ai') 448 set filetype=perl 449 call CheckWasSet('filetype') 450 set fo=tcroq 451 call CheckWasSet('fo') 452 453 split Xsomebuf 454 call CheckWasSet('ai') 455 call CheckWasNotSet('filetype') 456 call CheckWasSet('fo') 457endfunc 458 459func Test_set_ttytype() 460 CheckUnix 461 CheckNotGui 462 463 " Setting 'ttytype' used to cause a double-free when exiting vim and 464 " when vim is compiled with -DEXITFREE. 465 set ttytype=ansi 466 call assert_equal('ansi', &ttytype) 467 call assert_equal(&ttytype, &term) 468 set ttytype=xterm 469 call assert_equal('xterm', &ttytype) 470 call assert_equal(&ttytype, &term) 471 " "set ttytype=" gives E522 instead of E529 472 " in travis on some builds. Why? Catch both for now 473 try 474 set ttytype= 475 call assert_report('set ttytype= did not fail') 476 catch /E529\|E522/ 477 endtry 478 479 " Some systems accept any terminal name and return dumb settings, 480 " check for failure of finding the entry and for missing 'cm' entry. 481 try 482 set ttytype=xxx 483 call assert_report('set ttytype=xxx did not fail') 484 catch /E522\|E437/ 485 endtry 486 487 set ttytype& 488 call assert_equal(&ttytype, &term) 489 490 if has('gui') && !has('gui_running') 491 call assert_fails('set term=gui', 'E531:') 492 endif 493endfunc 494 495func Test_set_all() 496 set tw=75 497 set iskeyword=a-z,A-Z 498 set nosplitbelow 499 let out = execute('set all') 500 call assert_match('textwidth=75', out) 501 call assert_match('iskeyword=a-z,A-Z', out) 502 call assert_match('nosplitbelow', out) 503 set tw& iskeyword& splitbelow& 504endfunc 505 506func Test_set_one_column() 507 let out_mult = execute('set all')->split("\n") 508 let out_one = execute('set! all')->split("\n") 509 call assert_true(len(out_mult) < len(out_one)) 510endfunc 511 512func Test_set_values() 513 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim 514 if filereadable('opt_test.vim') 515 source opt_test.vim 516 else 517 throw 'Skipped: opt_test.vim does not exist' 518 endif 519endfunc 520 521func Test_renderoptions() 522 " Only do this for Windows Vista and later, fails on Windows XP and earlier. 523 " Doesn't hurt to do this on a non-Windows system. 524 if windowsversion() !~ '^[345]\.' 525 set renderoptions=type:directx 526 set rop=type:directx 527 endif 528endfunc 529 530func ResetIndentexpr() 531 set indentexpr= 532endfunc 533 534func Test_set_indentexpr() 535 " this was causing usage of freed memory 536 set indentexpr=ResetIndentexpr() 537 new 538 call feedkeys("i\<c-f>", 'x') 539 call assert_equal('', &indentexpr) 540 bwipe! 541endfunc 542 543func Test_backupskip() 544 " Option 'backupskip' may contain several comma-separated path 545 " specifications if one or more of the environment variables TMPDIR, TMP, 546 " or TEMP is defined. To simplify testing, convert the string value into a 547 " list. 548 let bsklist = split(&bsk, ',') 549 550 if has("mac") 551 let found = (index(bsklist, '/private/tmp/*') >= 0) 552 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 553 elseif has("unix") 554 let found = (index(bsklist, '/tmp/*') >= 0) 555 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 556 endif 557 558 " If our test platform is Windows, the path(s) in option bsk will use 559 " backslash for the path separator and the components could be in short 560 " (8.3) format. As such, we need to replace the backslashes with forward 561 " slashes and convert the path components to long format. The expand() 562 " function will do this but it cannot handle comma-separated paths. This is 563 " why bsk was converted from a string into a list of strings above. 564 " 565 " One final complication is that the wildcard "/*" is at the end of each 566 " path and so expand() might return a list of matching files. To prevent 567 " this, we need to remove the wildcard before calling expand() and then 568 " append it afterwards. 569 if has('win32') 570 let item_nbr = 0 571 while item_nbr < len(bsklist) 572 let path_spec = bsklist[item_nbr] 573 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 574 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 575 let bsklist[item_nbr] = path_spec . '/*' 576 let item_nbr += 1 577 endwhile 578 endif 579 580 " Option bsk will also include these environment variables if defined. 581 " If they're defined, verify they appear in the option value. 582 for var in ['$TMPDIR', '$TMP', '$TEMP'] 583 if exists(var) 584 let varvalue = substitute(expand(var), '\\', '/', 'g') 585 let varvalue = substitute(varvalue, '/$', '', '') 586 let varvalue .= '/*' 587 let found = (index(bsklist, varvalue) >= 0) 588 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 589 endif 590 endfor 591 592 " Duplicates from environment variables should be filtered out (option has 593 " P_NODUP). Run this in a separate instance and write v:errors in a file, 594 " so that we see what happens on startup. 595 let after =<< trim [CODE] 596 let bsklist = split(&backupskip, ',') 597 call assert_equal(uniq(copy(bsklist)), bsklist) 598 call writefile(['errors:'] + v:errors, 'Xtestout') 599 qall 600 [CODE] 601 call writefile(after, 'Xafter') 602 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"' 603 604 let saveenv = {} 605 for var in ['TMPDIR', 'TMP', 'TEMP'] 606 let saveenv[var] = getenv(var) 607 call setenv(var, '/duplicate/path') 608 endfor 609 610 exe 'silent !' . cmd 611 call assert_equal(['errors:'], readfile('Xtestout')) 612 613 " restore environment variables 614 for var in ['TMPDIR', 'TMP', 'TEMP'] 615 call setenv(var, saveenv[var]) 616 endfor 617 618 call delete('Xtestout') 619 call delete('Xafter') 620 621 " Duplicates should be filtered out (option has P_NODUP) 622 let backupskip = &backupskip 623 set backupskip= 624 set backupskip+=/test/dir 625 set backupskip+=/other/dir 626 set backupskip+=/test/dir 627 call assert_equal('/test/dir,/other/dir', &backupskip) 628 let &backupskip = backupskip 629endfunc 630 631func Test_copy_winopt() 632 set hidden 633 634 " Test copy option from current buffer in window 635 split 636 enew 637 setlocal numberwidth=5 638 wincmd w 639 call assert_equal(4,&numberwidth) 640 bnext 641 call assert_equal(5,&numberwidth) 642 bw! 643 call assert_equal(4,&numberwidth) 644 645 " Test copy value from window that used to be display the buffer 646 split 647 enew 648 setlocal numberwidth=6 649 bnext 650 wincmd w 651 call assert_equal(4,&numberwidth) 652 bnext 653 call assert_equal(6,&numberwidth) 654 bw! 655 656 " Test that if buffer is current, don't use the stale cached value 657 " from the last time the buffer was displayed. 658 split 659 enew 660 setlocal numberwidth=7 661 bnext 662 bnext 663 setlocal numberwidth=8 664 wincmd w 665 call assert_equal(4,&numberwidth) 666 bnext 667 call assert_equal(8,&numberwidth) 668 bw! 669 670 " Test value is not copied if window already has seen the buffer 671 enew 672 split 673 setlocal numberwidth=9 674 bnext 675 setlocal numberwidth=10 676 wincmd w 677 call assert_equal(4,&numberwidth) 678 bnext 679 call assert_equal(4,&numberwidth) 680 bw! 681 682 set hidden& 683endfunc 684 685func Test_shortmess_F() 686 new 687 call assert_match('\[No Name\]', execute('file')) 688 set shortmess+=F 689 call assert_match('\[No Name\]', execute('file')) 690 call assert_match('^\s*$', execute('file foo')) 691 call assert_match('foo', execute('file')) 692 set shortmess-=F 693 call assert_match('bar', execute('file bar')) 694 call assert_match('bar', execute('file')) 695 set shortmess& 696 bwipe 697endfunc 698 699func Test_shortmess_F2() 700 e file1 701 e file2 702 call assert_match('file1', execute('bn', '')) 703 call assert_match('file2', execute('bn', '')) 704 set shortmess+=F 705 call assert_true(empty(execute('bn', ''))) 706 call assert_false(test_getvalue('need_fileinfo')) 707 call assert_true(empty(execute('bn', ''))) 708 call assert_false('need_fileinfo'->test_getvalue()) 709 set hidden 710 call assert_true(empty(execute('bn', ''))) 711 call assert_false(test_getvalue('need_fileinfo')) 712 call assert_true(empty(execute('bn', ''))) 713 call assert_false(test_getvalue('need_fileinfo')) 714 set nohidden 715 call assert_true(empty(execute('bn', ''))) 716 call assert_false(test_getvalue('need_fileinfo')) 717 call assert_true(empty(execute('bn', ''))) 718 call assert_false(test_getvalue('need_fileinfo')) 719 set shortmess& 720 call assert_match('file1', execute('bn', '')) 721 call assert_match('file2', execute('bn', '')) 722 bwipe 723 bwipe 724endfunc 725 726func Test_local_scrolloff() 727 set so=5 728 set siso=7 729 split 730 call assert_equal(5, &so) 731 setlocal so=3 732 call assert_equal(3, &so) 733 wincmd w 734 call assert_equal(5, &so) 735 wincmd w 736 setlocal so< 737 call assert_equal(5, &so) 738 setlocal so=0 739 call assert_equal(0, &so) 740 setlocal so=-1 741 call assert_equal(5, &so) 742 743 call assert_equal(7, &siso) 744 setlocal siso=3 745 call assert_equal(3, &siso) 746 wincmd w 747 call assert_equal(7, &siso) 748 wincmd w 749 setlocal siso< 750 call assert_equal(7, &siso) 751 setlocal siso=0 752 call assert_equal(0, &siso) 753 setlocal siso=-1 754 call assert_equal(7, &siso) 755 756 close 757 set so& 758 set siso& 759endfunc 760 761func Test_writedelay() 762 CheckFunction reltimefloat 763 764 new 765 call setline(1, 'empty') 766 redraw 767 set writedelay=10 768 let start = reltime() 769 call setline(1, repeat('x', 70)) 770 redraw 771 let elapsed = reltimefloat(reltime(start)) 772 set writedelay=0 773 " With 'writedelay' set should take at least 30 * 10 msec 774 call assert_inrange(30 * 0.01, 999.0, elapsed) 775 776 bwipe! 777endfunc 778 779func Test_visualbell() 780 set belloff= 781 set visualbell 782 call assert_beeps('normal 0h') 783 set novisualbell 784 set belloff=all 785endfunc 786 787" Test for the 'write' option 788func Test_write() 789 new 790 call setline(1, ['L1']) 791 set nowrite 792 call assert_fails('write Xfile', 'E142:') 793 set write 794 close! 795endfunc 796 797" Test for 'buftype' option 798func Test_buftype() 799 new 800 call setline(1, ['L1']) 801 set buftype=nowrite 802 call assert_fails('write', 'E382:') 803 804 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] 805 exe 'set buftype=' .. val 806 call writefile(['something'], 'XBuftype') 807 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) 808 endfor 809 810 call delete('XBuftype') 811 bwipe! 812endfunc 813 814" Test for the 'shell' option 815func Test_shell() 816 CheckUnix 817 let save_shell = &shell 818 set shell= 819 call assert_fails('shell', 'E91:') 820 let &shell = save_shell 821endfunc 822 823" Test for the 'shellquote' option 824func Test_shellquote() 825 CheckUnix 826 set shellquote=# 827 set verbose=20 828 redir => v 829 silent! !echo Hello 830 redir END 831 set verbose& 832 set shellquote& 833 call assert_match(': "#echo Hello#"', v) 834endfunc 835 836" Test for the 'rightleftcmd' option 837func Test_rightleftcmd() 838 CheckFeature rightleft 839 set rightleft 840 set rightleftcmd 841 842 let g:l = [] 843 func AddPos() 844 call add(g:l, screencol()) 845 return '' 846 endfunc 847 cmap <expr> <F2> AddPos() 848 849 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. 850 \ "\<Left>\<F2>\<Esc>", 'xt') 851 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) 852 853 cunmap <F2> 854 unlet g:l 855 set rightleftcmd& 856 set rightleft& 857endfunc 858 859" Test for the "debug" option 860func Test_debug_option() 861 set debug=beep 862 exe "normal \<C-c>" 863 call assert_equal('Beep!', Screenline(&lines)) 864 set debug& 865endfunc 866 867" Test for the default CDPATH option 868func Test_opt_default_cdpath() 869 CheckFeature file_in_path 870 let after =<< trim [CODE] 871 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) 872 call writefile(v:errors, 'Xtestout') 873 qall 874 [CODE] 875 if has('unix') 876 let $CDPATH='/path/to/dir1:/path/to/dir2' 877 else 878 let $CDPATH='/path/to/dir1;/path/to/dir2' 879 endif 880 if RunVim([], after, '') 881 call assert_equal([], readfile('Xtestout')) 882 call delete('Xtestout') 883 endif 884endfunc 885 886" Test for setting keycodes using set 887func Test_opt_set_keycode() 888 call assert_fails('set <t_k1=l', 'E474:') 889 call assert_fails('set <Home=l', 'E474:') 890 set <t_k9>=abcd 891 call assert_equal('abcd', &t_k9) 892 set <t_k9>& 893 set <F9>=xyz 894 call assert_equal('xyz', &t_k9) 895 set <t_k9>& 896endfunc 897 898" Test for changing options in a sandbox 899func Test_opt_sandbox() 900 for opt in ['backupdir', 'cdpath', 'exrc'] 901 call assert_fails('sandbox set ' .. opt .. '?', 'E48:') 902 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:') 903 endfor 904 call assert_fails('sandbox let &modelineexpr = 1', 'E48:') 905endfunc 906 907" Test for setting an option with local value to global value 908func Test_opt_local_to_global() 909 setglobal equalprg=gprg 910 setlocal equalprg=lprg 911 call assert_equal('gprg', &g:equalprg) 912 call assert_equal('lprg', &l:equalprg) 913 call assert_equal('lprg', &equalprg) 914 set equalprg< 915 call assert_equal('', &l:equalprg) 916 call assert_equal('gprg', &equalprg) 917 setglobal equalprg=gnewprg 918 setlocal equalprg=lnewprg 919 setlocal equalprg< 920 call assert_equal('gnewprg', &l:equalprg) 921 call assert_equal('gnewprg', &equalprg) 922 set equalprg& 923endfunc 924 925" Test for incrementing, decrementing and multiplying a number option value 926func Test_opt_num_op() 927 set shiftwidth=4 928 set sw+=2 929 call assert_equal(6, &sw) 930 set sw-=2 931 call assert_equal(4, &sw) 932 set sw^=2 933 call assert_equal(8, &sw) 934 set shiftwidth& 935endfunc 936 937" Test for setting option values using v:false and v:true 938func Test_opt_boolean() 939 set number& 940 set number 941 call assert_equal(1, &nu) 942 set nonu 943 call assert_equal(0, &nu) 944 let &nu = v:true 945 call assert_equal(1, &nu) 946 let &nu = v:false 947 call assert_equal(0, &nu) 948 set number& 949endfunc 950 951" Test for the 'window' option 952func Test_window_opt() 953 " Needs only one open widow 954 %bw! 955 call setline(1, range(1, 8)) 956 set window=5 957 exe "normal \<C-F>" 958 call assert_equal(4, line('w0')) 959 exe "normal \<C-F>" 960 call assert_equal(7, line('w0')) 961 exe "normal \<C-F>" 962 call assert_equal(8, line('w0')) 963 exe "normal \<C-B>" 964 call assert_equal(5, line('w0')) 965 exe "normal \<C-B>" 966 call assert_equal(2, line('w0')) 967 exe "normal \<C-B>" 968 call assert_equal(1, line('w0')) 969 set window=1 970 exe "normal gg\<C-F>" 971 call assert_equal(2, line('w0')) 972 exe "normal \<C-F>" 973 call assert_equal(3, line('w0')) 974 exe "normal \<C-B>" 975 call assert_equal(2, line('w0')) 976 exe "normal \<C-B>" 977 call assert_equal(1, line('w0')) 978 enew! 979 set window& 980endfunc 981 982" Test for the 'winminheight' option 983func Test_opt_winminheight() 984 only! 985 let &winheight = &lines + 4 986 call assert_fails('let &winminheight = &lines + 2', 'E36:') 987 call assert_true(&winminheight <= &lines) 988 set winminheight& 989 set winheight& 990endfunc 991 992" Test for the 'winminwidth' option 993func Test_opt_winminwidth() 994 only! 995 let &winwidth = &columns + 4 996 call assert_fails('let &winminwidth = &columns + 2', 'E36:') 997 call assert_true(&winminwidth <= &columns) 998 set winminwidth& 999 set winwidth& 1000endfunc 1001 1002" Test for setting option value containing spaces with isfname+=32 1003func Test_isfname_with_options() 1004 set isfname+=32 1005 setlocal keywordprg=:term\ help.exe 1006 call assert_equal(':term help.exe', &keywordprg) 1007 set isfname& 1008 setlocal keywordprg& 1009endfunc 1010 1011" vim: shiftwidth=2 sts=2 expandtab 1012