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 273 set tags& 274endfunc 275 276func Test_set_errors() 277 call assert_fails('set scroll=-1', 'E49:') 278 call assert_fails('set backupcopy=', 'E474:') 279 call assert_fails('set regexpengine=3', 'E474:') 280 call assert_fails('set history=10001', 'E474:') 281 call assert_fails('set numberwidth=21', 'E474:') 282 call assert_fails('set colorcolumn=-a', 'E474:') 283 call assert_fails('set colorcolumn=a', 'E474:') 284 call assert_fails('set colorcolumn=1,', 'E474:') 285 call assert_fails('set colorcolumn=1;', 'E474:') 286 call assert_fails('set cmdheight=-1', 'E487:') 287 call assert_fails('set cmdwinheight=-1', 'E487:') 288 if has('conceal') 289 call assert_fails('set conceallevel=-1', 'E487:') 290 call assert_fails('set conceallevel=4', 'E474:') 291 endif 292 call assert_fails('set helpheight=-1', 'E487:') 293 call assert_fails('set history=-1', 'E487:') 294 call assert_fails('set report=-1', 'E487:') 295 call assert_fails('set shiftwidth=-1', 'E487:') 296 call assert_fails('set sidescroll=-1', 'E487:') 297 call assert_fails('set tabstop=-1', 'E487:') 298 call assert_fails('set textwidth=-1', 'E487:') 299 call assert_fails('set timeoutlen=-1', 'E487:') 300 call assert_fails('set updatecount=-1', 'E487:') 301 call assert_fails('set updatetime=-1', 'E487:') 302 call assert_fails('set winheight=-1', 'E487:') 303 call assert_fails('set tabstop!', 'E488:') 304 call assert_fails('set xxx', 'E518:') 305 call assert_fails('set beautify?', 'E519:') 306 call assert_fails('set undolevels=x', 'E521:') 307 call assert_fails('set tabstop=', 'E521:') 308 call assert_fails('set comments=-', 'E524:') 309 call assert_fails('set comments=a', 'E525:') 310 call assert_fails('set foldmarker=x', 'E536:') 311 call assert_fails('set commentstring=x', 'E537:') 312 call assert_fails('set complete=x', 'E539:') 313 call assert_fails('set statusline=%{', 'E540:') 314 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 315 call assert_fails('set statusline=%(', 'E542:') 316 if has('cursorshape') 317 " This invalid value for 'guicursor' used to cause Vim to crash. 318 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 319 call assert_fails('set guicursor=i-ci', 'E545:') 320 call assert_fails('set guicursor=x', 'E545:') 321 call assert_fails('set guicursor=x:', 'E546:') 322 call assert_fails('set guicursor=r-cr:horx', 'E548:') 323 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 324 endif 325 if has('mouseshape') 326 call assert_fails('se mouseshape=i-r:x', 'E547:') 327 endif 328 call assert_fails('set backupext=~ patchmode=~', 'E589:') 329 call assert_fails('set winminheight=10 winheight=9', 'E591:') 330 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 331 call assert_fails("set showbreak=\x01", 'E595:') 332 call assert_fails('set t_foo=', 'E846:') 333 call assert_fails('set tabstop??', 'E488:') 334 call assert_fails('set wrapscan!!', 'E488:') 335 call assert_fails('set tabstop&&', 'E488:') 336 call assert_fails('set wrapscan<<', 'E488:') 337 call assert_fails('set wrapscan=1', 'E474:') 338 call assert_fails('set autoindent@', 'E488:') 339 call assert_fails('set wildchar=<abc>', 'E474:') 340 call assert_fails('set cmdheight=1a', 'E521:') 341 if has('python') && has('python3') 342 call assert_fails('set pyxversion=6', 'E474:') 343 endif 344endfunc 345 346func CheckWasSet(name) 347 let verb_cm = execute('verbose set ' .. a:name .. '?') 348 call assert_match('Last set from.*test_options.vim', verb_cm) 349endfunc 350func CheckWasNotSet(name) 351 let verb_cm = execute('verbose set ' .. a:name .. '?') 352 call assert_notmatch('Last set from', verb_cm) 353endfunc 354 355" Must be executed before other tests that set 'term'. 356func Test_000_term_option_verbose() 357 CheckNotGui 358 359 call CheckWasNotSet('t_cm') 360 361 let term_save = &term 362 set term=ansi 363 call CheckWasSet('t_cm') 364 let &term = term_save 365endfunc 366 367func Test_copy_context() 368 setlocal list 369 call CheckWasSet('list') 370 split 371 call CheckWasSet('list') 372 quit 373 setlocal nolist 374 375 set ai 376 call CheckWasSet('ai') 377 set filetype=perl 378 call CheckWasSet('filetype') 379 set fo=tcroq 380 call CheckWasSet('fo') 381 382 split Xsomebuf 383 call CheckWasSet('ai') 384 call CheckWasNotSet('filetype') 385 call CheckWasSet('fo') 386endfunc 387 388func Test_set_ttytype() 389 CheckUnix 390 CheckNotGui 391 392 " Setting 'ttytype' used to cause a double-free when exiting vim and 393 " when vim is compiled with -DEXITFREE. 394 set ttytype=ansi 395 call assert_equal('ansi', &ttytype) 396 call assert_equal(&ttytype, &term) 397 set ttytype=xterm 398 call assert_equal('xterm', &ttytype) 399 call assert_equal(&ttytype, &term) 400 " "set ttytype=" gives E522 instead of E529 401 " in travis on some builds. Why? Catch both for now 402 try 403 set ttytype= 404 call assert_report('set ttytype= did not fail') 405 catch /E529\|E522/ 406 endtry 407 408 " Some systems accept any terminal name and return dumb settings, 409 " check for failure of finding the entry and for missing 'cm' entry. 410 try 411 set ttytype=xxx 412 call assert_report('set ttytype=xxx did not fail') 413 catch /E522\|E437/ 414 endtry 415 416 set ttytype& 417 call assert_equal(&ttytype, &term) 418 419 if has('gui') && !has('gui_running') 420 call assert_fails('set term=gui', 'E531:') 421 endif 422endfunc 423 424func Test_set_all() 425 set tw=75 426 set iskeyword=a-z,A-Z 427 set nosplitbelow 428 let out = execute('set all') 429 call assert_match('textwidth=75', out) 430 call assert_match('iskeyword=a-z,A-Z', out) 431 call assert_match('nosplitbelow', out) 432 set tw& iskeyword& splitbelow& 433endfunc 434 435func Test_set_one_column() 436 let out_mult = execute('set all')->split("\n") 437 let out_one = execute('set! all')->split("\n") 438 call assert_true(len(out_mult) < len(out_one)) 439endfunc 440 441func Test_set_values() 442 if filereadable('opt_test.vim') 443 source opt_test.vim 444 else 445 throw 'Skipped: opt_test.vim does not exist' 446 endif 447endfunc 448 449func Test_renderoptions() 450 " Only do this for Windows Vista and later, fails on Windows XP and earlier. 451 " Doesn't hurt to do this on a non-Windows system. 452 if windowsversion() !~ '^[345]\.' 453 set renderoptions=type:directx 454 set rop=type:directx 455 endif 456endfunc 457 458func ResetIndentexpr() 459 set indentexpr= 460endfunc 461 462func Test_set_indentexpr() 463 " this was causing usage of freed memory 464 set indentexpr=ResetIndentexpr() 465 new 466 call feedkeys("i\<c-f>", 'x') 467 call assert_equal('', &indentexpr) 468 bwipe! 469endfunc 470 471func Test_backupskip() 472 " Option 'backupskip' may contain several comma-separated path 473 " specifications if one or more of the environment variables TMPDIR, TMP, 474 " or TEMP is defined. To simplify testing, convert the string value into a 475 " list. 476 let bsklist = split(&bsk, ',') 477 478 if has("mac") 479 let found = (index(bsklist, '/private/tmp/*') >= 0) 480 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 481 elseif has("unix") 482 let found = (index(bsklist, '/tmp/*') >= 0) 483 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 484 endif 485 486 " If our test platform is Windows, the path(s) in option bsk will use 487 " backslash for the path separator and the components could be in short 488 " (8.3) format. As such, we need to replace the backslashes with forward 489 " slashes and convert the path components to long format. The expand() 490 " function will do this but it cannot handle comma-separated paths. This is 491 " why bsk was converted from a string into a list of strings above. 492 " 493 " One final complication is that the wildcard "/*" is at the end of each 494 " path and so expand() might return a list of matching files. To prevent 495 " this, we need to remove the wildcard before calling expand() and then 496 " append it afterwards. 497 if has('win32') 498 let item_nbr = 0 499 while item_nbr < len(bsklist) 500 let path_spec = bsklist[item_nbr] 501 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 502 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 503 let bsklist[item_nbr] = path_spec . '/*' 504 let item_nbr += 1 505 endwhile 506 endif 507 508 " Option bsk will also include these environment variables if defined. 509 " If they're defined, verify they appear in the option value. 510 for var in ['$TMPDIR', '$TMP', '$TEMP'] 511 if exists(var) 512 let varvalue = substitute(expand(var), '\\', '/', 'g') 513 let varvalue = substitute(varvalue, '/$', '', '') 514 let varvalue .= '/*' 515 let found = (index(bsklist, varvalue) >= 0) 516 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 517 endif 518 endfor 519 520 " Duplicates should be filtered out (option has P_NODUP) 521 let backupskip = &backupskip 522 set backupskip= 523 set backupskip+=/test/dir 524 set backupskip+=/other/dir 525 set backupskip+=/test/dir 526 call assert_equal('/test/dir,/other/dir', &backupskip) 527 let &backupskip = backupskip 528endfunc 529 530func Test_copy_winopt() 531 set hidden 532 533 " Test copy option from current buffer in window 534 split 535 enew 536 setlocal numberwidth=5 537 wincmd w 538 call assert_equal(4,&numberwidth) 539 bnext 540 call assert_equal(5,&numberwidth) 541 bw! 542 call assert_equal(4,&numberwidth) 543 544 " Test copy value from window that used to be display the buffer 545 split 546 enew 547 setlocal numberwidth=6 548 bnext 549 wincmd w 550 call assert_equal(4,&numberwidth) 551 bnext 552 call assert_equal(6,&numberwidth) 553 bw! 554 555 " Test that if buffer is current, don't use the stale cached value 556 " from the last time the buffer was displayed. 557 split 558 enew 559 setlocal numberwidth=7 560 bnext 561 bnext 562 setlocal numberwidth=8 563 wincmd w 564 call assert_equal(4,&numberwidth) 565 bnext 566 call assert_equal(8,&numberwidth) 567 bw! 568 569 " Test value is not copied if window already has seen the buffer 570 enew 571 split 572 setlocal numberwidth=9 573 bnext 574 setlocal numberwidth=10 575 wincmd w 576 call assert_equal(4,&numberwidth) 577 bnext 578 call assert_equal(4,&numberwidth) 579 bw! 580 581 set hidden& 582endfunc 583 584func Test_shortmess_F() 585 new 586 call assert_match('\[No Name\]', execute('file')) 587 set shortmess+=F 588 call assert_match('\[No Name\]', execute('file')) 589 call assert_match('^\s*$', execute('file foo')) 590 call assert_match('foo', execute('file')) 591 set shortmess-=F 592 call assert_match('bar', execute('file bar')) 593 call assert_match('bar', execute('file')) 594 set shortmess& 595 bwipe 596endfunc 597 598func Test_shortmess_F2() 599 e file1 600 e file2 601 call assert_match('file1', execute('bn', '')) 602 call assert_match('file2', execute('bn', '')) 603 set shortmess+=F 604 call assert_true(empty(execute('bn', ''))) 605 call assert_false(test_getvalue('need_fileinfo')) 606 call assert_true(empty(execute('bn', ''))) 607 call assert_false('need_fileinfo'->test_getvalue()) 608 set hidden 609 call assert_true(empty(execute('bn', ''))) 610 call assert_false(test_getvalue('need_fileinfo')) 611 call assert_true(empty(execute('bn', ''))) 612 call assert_false(test_getvalue('need_fileinfo')) 613 set nohidden 614 call assert_true(empty(execute('bn', ''))) 615 call assert_false(test_getvalue('need_fileinfo')) 616 call assert_true(empty(execute('bn', ''))) 617 call assert_false(test_getvalue('need_fileinfo')) 618 set shortmess& 619 call assert_match('file1', execute('bn', '')) 620 call assert_match('file2', execute('bn', '')) 621 bwipe 622 bwipe 623endfunc 624 625func Test_local_scrolloff() 626 set so=5 627 set siso=7 628 split 629 call assert_equal(5, &so) 630 setlocal so=3 631 call assert_equal(3, &so) 632 wincmd w 633 call assert_equal(5, &so) 634 wincmd w 635 setlocal so< 636 call assert_equal(5, &so) 637 setlocal so=0 638 call assert_equal(0, &so) 639 setlocal so=-1 640 call assert_equal(5, &so) 641 642 call assert_equal(7, &siso) 643 setlocal siso=3 644 call assert_equal(3, &siso) 645 wincmd w 646 call assert_equal(7, &siso) 647 wincmd w 648 setlocal siso< 649 call assert_equal(7, &siso) 650 setlocal siso=0 651 call assert_equal(0, &siso) 652 setlocal siso=-1 653 call assert_equal(7, &siso) 654 655 close 656 set so& 657 set siso& 658endfunc 659 660func Test_writedelay() 661 CheckFunction reltimefloat 662 663 new 664 call setline(1, 'empty') 665 redraw 666 set writedelay=10 667 let start = reltime() 668 call setline(1, repeat('x', 70)) 669 redraw 670 let elapsed = reltimefloat(reltime(start)) 671 set writedelay=0 672 " With 'writedelay' set should take at least 30 * 10 msec 673 call assert_inrange(30 * 0.01, 999.0, elapsed) 674 675 bwipe! 676endfunc 677 678func Test_visualbell() 679 set belloff= 680 set visualbell 681 call assert_beeps('normal 0h') 682 set novisualbell 683 set belloff=all 684endfunc 685 686" Test for the 'write' option 687func Test_write() 688 new 689 call setline(1, ['L1']) 690 set nowrite 691 call assert_fails('write Xfile', 'E142:') 692 set write 693 close! 694endfunc 695 696" Test for 'buftype' option 697func Test_buftype() 698 new 699 call setline(1, ['L1']) 700 set buftype=nowrite 701 call assert_fails('write', 'E382:') 702 703 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup'] 704 exe 'set buftype=' .. val 705 call writefile(['something'], 'XBuftype') 706 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val) 707 endfor 708 709 call delete('XBuftype') 710 bwipe! 711endfunc 712 713" Test for the 'shell' option 714func Test_shell() 715 CheckUnix 716 let save_shell = &shell 717 set shell= 718 call assert_fails('shell', 'E91:') 719 let &shell = save_shell 720endfunc 721 722" Test for the 'shellquote' option 723func Test_shellquote() 724 CheckUnix 725 set shellquote=# 726 set verbose=20 727 redir => v 728 silent! !echo Hello 729 redir END 730 set verbose& 731 set shellquote& 732 call assert_match(': "#echo Hello#"', v) 733endfunc 734 735" Test for the 'rightleftcmd' option 736func Test_rightleftcmd() 737 CheckFeature rightleft 738 set rightleft 739 set rightleftcmd 740 741 let g:l = [] 742 func AddPos() 743 call add(g:l, screencol()) 744 return '' 745 endfunc 746 cmap <expr> <F2> AddPos() 747 748 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" .. 749 \ "\<Left>\<F2>\<Esc>", 'xt') 750 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l) 751 752 cunmap <F2> 753 unlet g:l 754 set rightleftcmd& 755 set rightleft& 756endfunc 757 758" Test for the "debug" option 759func Test_debug_option() 760 set debug=beep 761 exe "normal \<C-c>" 762 call assert_equal('Beep!', Screenline(&lines)) 763 set debug& 764endfunc 765 766" Test for the default CDPATH option 767func Test_opt_default_cdpath() 768 CheckFeature file_in_path 769 let after =<< trim [CODE] 770 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath) 771 call writefile(v:errors, 'Xtestout') 772 qall 773 [CODE] 774 if has('unix') 775 let $CDPATH='/path/to/dir1:/path/to/dir2' 776 else 777 let $CDPATH='/path/to/dir1;/path/to/dir2' 778 endif 779 if RunVim([], after, '') 780 call assert_equal([], readfile('Xtestout')) 781 call delete('Xtestout') 782 endif 783endfunc 784 785" Test for setting keycodes using set 786func Test_opt_set_keycode() 787 call assert_fails('set <t_k1=l', 'E474:') 788 call assert_fails('set <Home=l', 'E474:') 789 set <t_k9>=abcd 790 call assert_equal('abcd', &t_k9) 791 set <t_k9>& 792 set <F9>=xyz 793 call assert_equal('xyz', &t_k9) 794 set <t_k9>& 795endfunc 796 797" Test for changing options in a sandbox 798func Test_opt_sandbox() 799 for opt in ['backupdir', 'cdpath', 'exrc'] 800 call assert_fails('sandbox set ' .. opt .. '?', 'E48:') 801 endfor 802endfunc 803 804" Test for setting an option with local value to global value 805func Test_opt_local_to_global() 806 setglobal equalprg=gprg 807 setlocal equalprg=lprg 808 call assert_equal('gprg', &g:equalprg) 809 call assert_equal('lprg', &l:equalprg) 810 call assert_equal('lprg', &equalprg) 811 set equalprg< 812 call assert_equal('', &l:equalprg) 813 call assert_equal('gprg', &equalprg) 814 setglobal equalprg=gnewprg 815 setlocal equalprg=lnewprg 816 setlocal equalprg< 817 call assert_equal('gnewprg', &l:equalprg) 818 call assert_equal('gnewprg', &equalprg) 819 set equalprg& 820endfunc 821 822" Test for incrementing, decrementing and multiplying a number option value 823func Test_opt_num_op() 824 set shiftwidth=4 825 set sw+=2 826 call assert_equal(6, &sw) 827 set sw-=2 828 call assert_equal(4, &sw) 829 set sw^=2 830 call assert_equal(8, &sw) 831 set shiftwidth& 832endfunc 833 834" vim: shiftwidth=2 sts=2 expandtab 835