1" Test for options 2 3func Test_whichwrap() 4 set whichwrap=b,s 5 call assert_equal('b,s', &whichwrap) 6 7 set whichwrap+=h,l 8 call assert_equal('b,s,h,l', &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,h 17 call assert_equal('h', &whichwrap) 18 19 set whichwrap=h,h,h 20 call assert_equal('h', &whichwrap) 21 22 set whichwrap& 23endfunc 24 25func Test_isfname() 26 " This used to cause Vim to access uninitialized memory. 27 set isfname= 28 call assert_equal("~X", expand("~X")) 29 set isfname& 30endfunc 31 32func Test_wildchar() 33 " Empty 'wildchar' used to access invalid memory. 34 call assert_fails('set wildchar=', 'E521:') 35 call assert_fails('set wildchar=abc', 'E521:') 36 set wildchar=<Esc> 37 let a=execute('set wildchar?') 38 call assert_equal("\n wildchar=<Esc>", a) 39 set wildchar=27 40 let a=execute('set wildchar?') 41 call assert_equal("\n wildchar=<Esc>", a) 42 set wildchar& 43endfunc 44 45func Test_options() 46 let caught = 'ok' 47 try 48 options 49 catch 50 let caught = v:throwpoint . "\n" . v:exception 51 endtry 52 call assert_equal('ok', caught) 53 54 " Check if the option-window is opened horizontally. 55 wincmd j 56 call assert_notequal('option-window', bufname('')) 57 wincmd k 58 call assert_equal('option-window', bufname('')) 59 " close option-window 60 close 61 62 " Open the option-window vertically. 63 vert options 64 " Check if the option-window is opened vertically. 65 wincmd l 66 call assert_notequal('option-window', bufname('')) 67 wincmd h 68 call assert_equal('option-window', bufname('')) 69 " close option-window 70 close 71 72 " Open the option-window in a new tab. 73 tab options 74 " Check if the option-window is opened in a tab. 75 normal gT 76 call assert_notequal('option-window', bufname('')) 77 normal gt 78 call assert_equal('option-window', bufname('')) 79 80 " close option-window 81 close 82endfunc 83 84func Test_path_keep_commas() 85 " Test that changing 'path' keeps two commas. 86 set path=foo,,bar 87 set path-=bar 88 set path+=bar 89 call assert_equal('foo,,bar', &path) 90 91 set path& 92endfunc 93 94func Test_signcolumn() 95 if has('signs') 96 call assert_equal("auto", &signcolumn) 97 set signcolumn=yes 98 set signcolumn=no 99 call assert_fails('set signcolumn=nope') 100 endif 101endfunc 102 103func Test_filetype_valid() 104 set ft=valid_name 105 call assert_equal("valid_name", &filetype) 106 set ft=valid-name 107 call assert_equal("valid-name", &filetype) 108 109 call assert_fails(":set ft=wrong;name", "E474:") 110 call assert_fails(":set ft=wrong\\\\name", "E474:") 111 call assert_fails(":set ft=wrong\\|name", "E474:") 112 call assert_fails(":set ft=wrong/name", "E474:") 113 call assert_fails(":set ft=wrong\\\nname", "E474:") 114 call assert_equal("valid-name", &filetype) 115 116 exe "set ft=trunc\x00name" 117 call assert_equal("trunc", &filetype) 118endfunc 119 120func Test_syntax_valid() 121 if !has('syntax') 122 return 123 endif 124 set syn=valid_name 125 call assert_equal("valid_name", &syntax) 126 set syn=valid-name 127 call assert_equal("valid-name", &syntax) 128 129 call assert_fails(":set syn=wrong;name", "E474:") 130 call assert_fails(":set syn=wrong\\\\name", "E474:") 131 call assert_fails(":set syn=wrong\\|name", "E474:") 132 call assert_fails(":set syn=wrong/name", "E474:") 133 call assert_fails(":set syn=wrong\\\nname", "E474:") 134 call assert_equal("valid-name", &syntax) 135 136 exe "set syn=trunc\x00name" 137 call assert_equal("trunc", &syntax) 138endfunc 139 140func Test_keymap_valid() 141 if !has('keymap') 142 return 143 endif 144 call assert_fails(":set kmp=valid_name", "E544:") 145 call assert_fails(":set kmp=valid_name", "valid_name") 146 call assert_fails(":set kmp=valid-name", "E544:") 147 call assert_fails(":set kmp=valid-name", "valid-name") 148 149 call assert_fails(":set kmp=wrong;name", "E474:") 150 call assert_fails(":set kmp=wrong\\\\name", "E474:") 151 call assert_fails(":set kmp=wrong\\|name", "E474:") 152 call assert_fails(":set kmp=wrong/name", "E474:") 153 call assert_fails(":set kmp=wrong\\\nname", "E474:") 154 155 call assert_fails(":set kmp=trunc\x00name", "E544:") 156 call assert_fails(":set kmp=trunc\x00name", "trunc") 157endfunc 158 159func Check_dir_option(name) 160 " Check that it's possible to set the option. 161 exe 'set ' . a:name . '=/usr/share/dict/words' 162 call assert_equal('/usr/share/dict/words', eval('&' . a:name)) 163 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' 164 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) 165 exe 'set ' . a:name . '=/usr/share/dict\ words' 166 call assert_equal('/usr/share/dict words', eval('&' . a:name)) 167 168 " Check rejecting weird characters. 169 call assert_fails("set " . a:name . "=/not&there", "E474:") 170 call assert_fails("set " . a:name . "=/not>there", "E474:") 171 call assert_fails("set " . a:name . "=/not.*there", "E474:") 172endfunc 173 174func Test_cinkeys() 175 " This used to cause invalid memory access 176 set cindent cinkeys=0 177 norm a 178 set cindent& cinkeys& 179endfunc 180 181func Test_dictionary() 182 call Check_dir_option('dictionary') 183endfunc 184 185func Test_thesaurus() 186 call Check_dir_option('thesaurus') 187endfun 188 189func Test_complete() 190 " Trailing single backslash used to cause invalid memory access. 191 set complete=s\ 192 new 193 call feedkeys("i\<C-N>\<Esc>", 'xt') 194 bwipe! 195 set complete& 196endfun 197 198func Test_set_completion() 199 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') 200 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) 201 202 " Expand boolan options. When doing :set no<Tab> 203 " vim displays the options names without "no" but completion uses "no...". 204 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') 205 call assert_equal('"set nodiff digraph', @:) 206 207 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') 208 call assert_equal('"set invdiff digraph', @:) 209 210 " Expand abbreviation of options. 211 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') 212 call assert_equal('"set tabstop thesaurus ttyscroll', @:) 213 214 " Expand current value 215 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') 216 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) 217 218 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') 219 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) 220 221 " Expand key codes. 222 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') 223 call assert_equal('"set <Help> <Home>', @:) 224 225 " Expand terminal options. 226 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') 227 call assert_equal('"set t_AB t_AF t_AL', @:) 228 229 " Expand directories. 230 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') 231 call assert_match(' ./samples/ ', @:) 232 call assert_notmatch(' ./small.vim ', @:) 233 234 " Expand files and directories. 235 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') 236 call assert_match(' ./samples/.* ./small.vim', @:) 237 238 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') 239 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) 240endfunc 241 242func Test_set_errors() 243 call assert_fails('set scroll=-1', 'E49:') 244 call assert_fails('set backupcopy=', 'E474:') 245 call assert_fails('set regexpengine=3', 'E474:') 246 call assert_fails('set history=10001', 'E474:') 247 call assert_fails('set numberwidth=11', 'E474:') 248 call assert_fails('set colorcolumn=-a') 249 call assert_fails('set colorcolumn=a') 250 call assert_fails('set colorcolumn=1,') 251 call assert_fails('set cmdheight=-1', 'E487:') 252 call assert_fails('set cmdwinheight=-1', 'E487:') 253 if has('conceal') 254 call assert_fails('set conceallevel=-1', 'E487:') 255 call assert_fails('set conceallevel=4', 'E474:') 256 endif 257 call assert_fails('set helpheight=-1', 'E487:') 258 call assert_fails('set history=-1', 'E487:') 259 call assert_fails('set report=-1', 'E487:') 260 call assert_fails('set shiftwidth=-1', 'E487:') 261 call assert_fails('set sidescroll=-1', 'E487:') 262 call assert_fails('set tabstop=-1', 'E487:') 263 call assert_fails('set textwidth=-1', 'E487:') 264 call assert_fails('set timeoutlen=-1', 'E487:') 265 call assert_fails('set updatecount=-1', 'E487:') 266 call assert_fails('set updatetime=-1', 'E487:') 267 call assert_fails('set winheight=-1', 'E487:') 268 call assert_fails('set tabstop!', 'E488:') 269 call assert_fails('set xxx', 'E518:') 270 call assert_fails('set beautify?', 'E519:') 271 call assert_fails('set undolevels=x', 'E521:') 272 call assert_fails('set tabstop=', 'E521:') 273 call assert_fails('set comments=-', 'E524:') 274 call assert_fails('set comments=a', 'E525:') 275 call assert_fails('set foldmarker=x', 'E536:') 276 call assert_fails('set commentstring=x', 'E537:') 277 call assert_fails('set complete=x', 'E539:') 278 call assert_fails('set statusline=%{', 'E540:') 279 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 280 call assert_fails('set statusline=%(', 'E542:') 281 if has('cursorshape') 282 " This invalid value for 'guicursor' used to cause Vim to crash. 283 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 284 call assert_fails('set guicursor=i-ci', 'E545:') 285 call assert_fails('set guicursor=x', 'E545:') 286 call assert_fails('set guicursor=r-cr:horx', 'E548:') 287 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 288 endif 289 call assert_fails('set backupext=~ patchmode=~', 'E589:') 290 call assert_fails('set winminheight=10 winheight=9', 'E591:') 291 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 292 call assert_fails("set showbreak=\x01", 'E595:') 293 call assert_fails('set t_foo=', 'E846:') 294endfunc 295 296" Must be executed before other tests that set 'term'. 297func Test_000_term_option_verbose() 298 if has('gui_running') 299 return 300 endif 301 let verb_cm = execute('verbose set t_cm') 302 call assert_notmatch('Last set from', verb_cm) 303 304 let term_save = &term 305 set term=ansi 306 let verb_cm = execute('verbose set t_cm') 307 call assert_match('Last set from.*test_options.vim', verb_cm) 308 let &term = term_save 309endfunc 310 311func Test_set_ttytype() 312 if !has('gui_running') && has('unix') 313 " Setting 'ttytype' used to cause a double-free when exiting vim and 314 " when vim is compiled with -DEXITFREE. 315 set ttytype=ansi 316 call assert_equal('ansi', &ttytype) 317 call assert_equal(&ttytype, &term) 318 set ttytype=xterm 319 call assert_equal('xterm', &ttytype) 320 call assert_equal(&ttytype, &term) 321 " "set ttytype=" gives E522 instead of E529 322 " in travis on some builds. Why? Catch both for now 323 try 324 set ttytype= 325 call assert_report('set ttytype= did not fail') 326 catch /E529\|E522/ 327 endtry 328 329 " Some systems accept any terminal name and return dumb settings, 330 " check for failure of finding the entry and for missing 'cm' entry. 331 try 332 set ttytype=xxx 333 call assert_report('set ttytype=xxx did not fail') 334 catch /E522\|E437/ 335 endtry 336 337 set ttytype& 338 call assert_equal(&ttytype, &term) 339 endif 340endfunc 341 342func Test_set_all() 343 set tw=75 344 set iskeyword=a-z,A-Z 345 set nosplitbelow 346 let out = execute('set all') 347 call assert_match('textwidth=75', out) 348 call assert_match('iskeyword=a-z,A-Z', out) 349 call assert_match('nosplitbelow', out) 350 set tw& iskeyword& splitbelow& 351endfunc 352 353func Test_set_values() 354 if filereadable('opt_test.vim') 355 source opt_test.vim 356 else 357 throw 'Skipped: opt_test.vim does not exist' 358 endif 359endfunc 360 361func ResetIndentexpr() 362 set indentexpr= 363endfunc 364 365func Test_set_indentexpr() 366 " this was causing usage of freed memory 367 set indentexpr=ResetIndentexpr() 368 new 369 call feedkeys("i\<c-f>", 'x') 370 call assert_equal('', &indentexpr) 371 bwipe! 372endfunc 373 374func Test_backupskip() 375 " Option 'backupskip' may contain several comma-separated path 376 " specifications if one or more of the environment variables TMPDIR, TMP, 377 " or TEMP is defined. To simplify testing, convert the string value into a 378 " list. 379 let bsklist = split(&bsk, ',') 380 381 if has("mac") 382 let found = (index(bsklist, '/private/tmp/*') >= 0) 383 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 384 elseif has("unix") 385 let found = (index(bsklist, '/tmp/*') >= 0) 386 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 387 endif 388 389 " If our test platform is Windows, the path(s) in option bsk will use 390 " backslash for the path separator and the components could be in short 391 " (8.3) format. As such, we need to replace the backslashes with forward 392 " slashes and convert the path components to long format. The expand() 393 " function will do this but it cannot handle comma-separated paths. This is 394 " why bsk was converted from a string into a list of strings above. 395 " 396 " One final complication is that the wildcard "/*" is at the end of each 397 " path and so expand() might return a list of matching files. To prevent 398 " this, we need to remove the wildcard before calling expand() and then 399 " append it afterwards. 400 if has('win32') 401 let item_nbr = 0 402 while item_nbr < len(bsklist) 403 let path_spec = bsklist[item_nbr] 404 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 405 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 406 let bsklist[item_nbr] = path_spec . '/*' 407 let item_nbr += 1 408 endwhile 409 endif 410 411 " Option bsk will also include these environment variables if defined. 412 " If they're defined, verify they appear in the option value. 413 for var in ['$TMPDIR', '$TMP', '$TEMP'] 414 if exists(var) 415 let varvalue = substitute(expand(var), '\\', '/', 'g') 416 let varvalue = substitute(varvalue, '/$', '', '') 417 let varvalue .= '/*' 418 let found = (index(bsklist, varvalue) >= 0) 419 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 420 endif 421 endfor 422endfunc 423 424func Test_copy_winopt() 425 set hidden 426 427 " Test copy option from current buffer in window 428 split 429 enew 430 setlocal numberwidth=5 431 wincmd w 432 call assert_equal(4,&numberwidth) 433 bnext 434 call assert_equal(5,&numberwidth) 435 bw! 436 call assert_equal(4,&numberwidth) 437 438 " Test copy value from window that used to be display the buffer 439 split 440 enew 441 setlocal numberwidth=6 442 bnext 443 wincmd w 444 call assert_equal(4,&numberwidth) 445 bnext 446 call assert_equal(6,&numberwidth) 447 bw! 448 449 " Test that if buffer is current, don't use the stale cached value 450 " from the last time the buffer was displayed. 451 split 452 enew 453 setlocal numberwidth=7 454 bnext 455 bnext 456 setlocal numberwidth=8 457 wincmd w 458 call assert_equal(4,&numberwidth) 459 bnext 460 call assert_equal(8,&numberwidth) 461 bw! 462 463 " Test value is not copied if window already has seen the buffer 464 enew 465 split 466 setlocal numberwidth=9 467 bnext 468 setlocal numberwidth=10 469 wincmd w 470 call assert_equal(4,&numberwidth) 471 bnext 472 call assert_equal(4,&numberwidth) 473 bw! 474 475 set hidden& 476endfunc 477 478func Test_shortmess_F() 479 new 480 call assert_match('\[No Name\]', execute('file')) 481 set shortmess+=F 482 call assert_match('\[No Name\]', execute('file')) 483 call assert_match('^\s*$', execute('file foo')) 484 call assert_match('foo', execute('file')) 485 set shortmess-=F 486 call assert_match('bar', execute('file bar')) 487 call assert_match('bar', execute('file')) 488 set shortmess& 489 bwipe 490endfunc 491 492func Test_shortmess_F2() 493 e file1 494 e file2 495 call assert_match('file1', execute('bn', '')) 496 call assert_match('file2', execute('bn', '')) 497 set shortmess+=F 498 call assert_true(empty(execute('bn', ''))) 499 call assert_false(test_getvalue('need_fileinfo')) 500 call assert_true(empty(execute('bn', ''))) 501 call assert_false(test_getvalue('need_fileinfo')) 502 set hidden 503 call assert_true(empty(execute('bn', ''))) 504 call assert_false(test_getvalue('need_fileinfo')) 505 call assert_true(empty(execute('bn', ''))) 506 call assert_false(test_getvalue('need_fileinfo')) 507 set nohidden 508 call assert_true(empty(execute('bn', ''))) 509 call assert_false(test_getvalue('need_fileinfo')) 510 call assert_true(empty(execute('bn', ''))) 511 call assert_false(test_getvalue('need_fileinfo')) 512 set shortmess& 513 call assert_match('file1', execute('bn', '')) 514 call assert_match('file2', execute('bn', '')) 515 bwipe 516 bwipe 517endfunc 518 519func Test_local_scrolloff() 520 set so=5 521 set siso=7 522 split 523 call assert_equal(5, &so) 524 setlocal so=3 525 call assert_equal(3, &so) 526 wincmd w 527 call assert_equal(5, &so) 528 wincmd w 529 setlocal so< 530 call assert_equal(5, &so) 531 setlocal so=0 532 call assert_equal(0, &so) 533 setlocal so=-1 534 call assert_equal(5, &so) 535 536 call assert_equal(7, &siso) 537 setlocal siso=3 538 call assert_equal(3, &siso) 539 wincmd w 540 call assert_equal(7, &siso) 541 wincmd w 542 setlocal siso< 543 call assert_equal(7, &siso) 544 setlocal siso=0 545 call assert_equal(0, &siso) 546 setlocal siso=-1 547 call assert_equal(7, &siso) 548 549 close 550 set so& 551 set siso& 552endfunc 553 554func Test_writedelay() 555 if !has('reltime') 556 return 557 endif 558 new 559 call setline(1, 'empty') 560 redraw 561 set writedelay=10 562 let start = reltime() 563 call setline(1, repeat('x', 70)) 564 redraw 565 let elapsed = reltimefloat(reltime(start)) 566 set writedelay=0 567 " With 'writedelay' set should take at least 30 * 10 msec 568 call assert_inrange(30 * 0.01, 999.0, elapsed) 569 570 bwipe! 571endfunc 572 573func Test_visualbell() 574 set belloff= 575 set visualbell 576 call assert_beeps('normal 0h') 577 set novisualbell 578 set belloff=all 579endfunc 580