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', @:) 240 set tags& 241endfunc 242 243func Test_set_errors() 244 call assert_fails('set scroll=-1', 'E49:') 245 call assert_fails('set backupcopy=', 'E474:') 246 call assert_fails('set regexpengine=3', 'E474:') 247 call assert_fails('set history=10001', 'E474:') 248 call assert_fails('set numberwidth=21', 'E474:') 249 call assert_fails('set colorcolumn=-a') 250 call assert_fails('set colorcolumn=a') 251 call assert_fails('set colorcolumn=1,') 252 call assert_fails('set cmdheight=-1', 'E487:') 253 call assert_fails('set cmdwinheight=-1', 'E487:') 254 if has('conceal') 255 call assert_fails('set conceallevel=-1', 'E487:') 256 call assert_fails('set conceallevel=4', 'E474:') 257 endif 258 call assert_fails('set helpheight=-1', 'E487:') 259 call assert_fails('set history=-1', 'E487:') 260 call assert_fails('set report=-1', 'E487:') 261 call assert_fails('set shiftwidth=-1', 'E487:') 262 call assert_fails('set sidescroll=-1', 'E487:') 263 call assert_fails('set tabstop=-1', 'E487:') 264 call assert_fails('set textwidth=-1', 'E487:') 265 call assert_fails('set timeoutlen=-1', 'E487:') 266 call assert_fails('set updatecount=-1', 'E487:') 267 call assert_fails('set updatetime=-1', 'E487:') 268 call assert_fails('set winheight=-1', 'E487:') 269 call assert_fails('set tabstop!', 'E488:') 270 call assert_fails('set xxx', 'E518:') 271 call assert_fails('set beautify?', 'E519:') 272 call assert_fails('set undolevels=x', 'E521:') 273 call assert_fails('set tabstop=', 'E521:') 274 call assert_fails('set comments=-', 'E524:') 275 call assert_fails('set comments=a', 'E525:') 276 call assert_fails('set foldmarker=x', 'E536:') 277 call assert_fails('set commentstring=x', 'E537:') 278 call assert_fails('set complete=x', 'E539:') 279 call assert_fails('set statusline=%{', 'E540:') 280 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 281 call assert_fails('set statusline=%(', 'E542:') 282 if has('cursorshape') 283 " This invalid value for 'guicursor' used to cause Vim to crash. 284 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') 285 call assert_fails('set guicursor=i-ci', 'E545:') 286 call assert_fails('set guicursor=x', 'E545:') 287 call assert_fails('set guicursor=r-cr:horx', 'E548:') 288 call assert_fails('set guicursor=r-cr:hor0', 'E549:') 289 endif 290 call assert_fails('set backupext=~ patchmode=~', 'E589:') 291 call assert_fails('set winminheight=10 winheight=9', 'E591:') 292 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 293 call assert_fails("set showbreak=\x01", 'E595:') 294 call assert_fails('set t_foo=', 'E846:') 295endfunc 296 297" Must be executed before other tests that set 'term'. 298func Test_000_term_option_verbose() 299 if has('gui_running') 300 return 301 endif 302 let verb_cm = execute('verbose set t_cm') 303 call assert_notmatch('Last set from', verb_cm) 304 305 let term_save = &term 306 set term=ansi 307 let verb_cm = execute('verbose set t_cm') 308 call assert_match('Last set from.*test_options.vim', verb_cm) 309 let &term = term_save 310endfunc 311 312func Test_set_ttytype() 313 if !has('gui_running') && has('unix') 314 " Setting 'ttytype' used to cause a double-free when exiting vim and 315 " when vim is compiled with -DEXITFREE. 316 set ttytype=ansi 317 call assert_equal('ansi', &ttytype) 318 call assert_equal(&ttytype, &term) 319 set ttytype=xterm 320 call assert_equal('xterm', &ttytype) 321 call assert_equal(&ttytype, &term) 322 " "set ttytype=" gives E522 instead of E529 323 " in travis on some builds. Why? Catch both for now 324 try 325 set ttytype= 326 call assert_report('set ttytype= did not fail') 327 catch /E529\|E522/ 328 endtry 329 330 " Some systems accept any terminal name and return dumb settings, 331 " check for failure of finding the entry and for missing 'cm' entry. 332 try 333 set ttytype=xxx 334 call assert_report('set ttytype=xxx did not fail') 335 catch /E522\|E437/ 336 endtry 337 338 set ttytype& 339 call assert_equal(&ttytype, &term) 340 endif 341endfunc 342 343func Test_set_all() 344 set tw=75 345 set iskeyword=a-z,A-Z 346 set nosplitbelow 347 let out = execute('set all') 348 call assert_match('textwidth=75', out) 349 call assert_match('iskeyword=a-z,A-Z', out) 350 call assert_match('nosplitbelow', out) 351 set tw& iskeyword& splitbelow& 352endfunc 353 354func Test_set_values() 355 if filereadable('opt_test.vim') 356 source opt_test.vim 357 else 358 throw 'Skipped: opt_test.vim does not exist' 359 endif 360endfunc 361 362func ResetIndentexpr() 363 set indentexpr= 364endfunc 365 366func Test_set_indentexpr() 367 " this was causing usage of freed memory 368 set indentexpr=ResetIndentexpr() 369 new 370 call feedkeys("i\<c-f>", 'x') 371 call assert_equal('', &indentexpr) 372 bwipe! 373endfunc 374 375func Test_backupskip() 376 " Option 'backupskip' may contain several comma-separated path 377 " specifications if one or more of the environment variables TMPDIR, TMP, 378 " or TEMP is defined. To simplify testing, convert the string value into a 379 " list. 380 let bsklist = split(&bsk, ',') 381 382 if has("mac") 383 let found = (index(bsklist, '/private/tmp/*') >= 0) 384 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) 385 elseif has("unix") 386 let found = (index(bsklist, '/tmp/*') >= 0) 387 call assert_true(found, '/tmp not in option bsk: ' . &bsk) 388 endif 389 390 " If our test platform is Windows, the path(s) in option bsk will use 391 " backslash for the path separator and the components could be in short 392 " (8.3) format. As such, we need to replace the backslashes with forward 393 " slashes and convert the path components to long format. The expand() 394 " function will do this but it cannot handle comma-separated paths. This is 395 " why bsk was converted from a string into a list of strings above. 396 " 397 " One final complication is that the wildcard "/*" is at the end of each 398 " path and so expand() might return a list of matching files. To prevent 399 " this, we need to remove the wildcard before calling expand() and then 400 " append it afterwards. 401 if has('win32') 402 let item_nbr = 0 403 while item_nbr < len(bsklist) 404 let path_spec = bsklist[item_nbr] 405 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) 406 let path_spec = substitute(expand(path_spec), '\\', '/', 'g') 407 let bsklist[item_nbr] = path_spec . '/*' 408 let item_nbr += 1 409 endwhile 410 endif 411 412 " Option bsk will also include these environment variables if defined. 413 " If they're defined, verify they appear in the option value. 414 for var in ['$TMPDIR', '$TMP', '$TEMP'] 415 if exists(var) 416 let varvalue = substitute(expand(var), '\\', '/', 'g') 417 let varvalue = substitute(varvalue, '/$', '', '') 418 let varvalue .= '/*' 419 let found = (index(bsklist, varvalue) >= 0) 420 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) 421 endif 422 endfor 423 424 " Duplicates should be filtered out (option has P_NODUP) 425 let backupskip = &backupskip 426 set backupskip= 427 set backupskip+=/test/dir 428 set backupskip+=/other/dir 429 set backupskip+=/test/dir 430 call assert_equal('/test/dir,/other/dir', &backupskip) 431 let &backupskip = backupskip 432endfunc 433 434func Test_copy_winopt() 435 set hidden 436 437 " Test copy option from current buffer in window 438 split 439 enew 440 setlocal numberwidth=5 441 wincmd w 442 call assert_equal(4,&numberwidth) 443 bnext 444 call assert_equal(5,&numberwidth) 445 bw! 446 call assert_equal(4,&numberwidth) 447 448 " Test copy value from window that used to be display the buffer 449 split 450 enew 451 setlocal numberwidth=6 452 bnext 453 wincmd w 454 call assert_equal(4,&numberwidth) 455 bnext 456 call assert_equal(6,&numberwidth) 457 bw! 458 459 " Test that if buffer is current, don't use the stale cached value 460 " from the last time the buffer was displayed. 461 split 462 enew 463 setlocal numberwidth=7 464 bnext 465 bnext 466 setlocal numberwidth=8 467 wincmd w 468 call assert_equal(4,&numberwidth) 469 bnext 470 call assert_equal(8,&numberwidth) 471 bw! 472 473 " Test value is not copied if window already has seen the buffer 474 enew 475 split 476 setlocal numberwidth=9 477 bnext 478 setlocal numberwidth=10 479 wincmd w 480 call assert_equal(4,&numberwidth) 481 bnext 482 call assert_equal(4,&numberwidth) 483 bw! 484 485 set hidden& 486endfunc 487 488func Test_shortmess_F() 489 new 490 call assert_match('\[No Name\]', execute('file')) 491 set shortmess+=F 492 call assert_match('\[No Name\]', execute('file')) 493 call assert_match('^\s*$', execute('file foo')) 494 call assert_match('foo', execute('file')) 495 set shortmess-=F 496 call assert_match('bar', execute('file bar')) 497 call assert_match('bar', execute('file')) 498 set shortmess& 499 bwipe 500endfunc 501 502func Test_shortmess_F2() 503 e file1 504 e file2 505 call assert_match('file1', execute('bn', '')) 506 call assert_match('file2', execute('bn', '')) 507 set shortmess+=F 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 hidden 513 call assert_true(empty(execute('bn', ''))) 514 call assert_false(test_getvalue('need_fileinfo')) 515 call assert_true(empty(execute('bn', ''))) 516 call assert_false(test_getvalue('need_fileinfo')) 517 set nohidden 518 call assert_true(empty(execute('bn', ''))) 519 call assert_false(test_getvalue('need_fileinfo')) 520 call assert_true(empty(execute('bn', ''))) 521 call assert_false(test_getvalue('need_fileinfo')) 522 set shortmess& 523 call assert_match('file1', execute('bn', '')) 524 call assert_match('file2', execute('bn', '')) 525 bwipe 526 bwipe 527endfunc 528 529func Test_local_scrolloff() 530 set so=5 531 set siso=7 532 split 533 call assert_equal(5, &so) 534 setlocal so=3 535 call assert_equal(3, &so) 536 wincmd w 537 call assert_equal(5, &so) 538 wincmd w 539 setlocal so< 540 call assert_equal(5, &so) 541 setlocal so=0 542 call assert_equal(0, &so) 543 setlocal so=-1 544 call assert_equal(5, &so) 545 546 call assert_equal(7, &siso) 547 setlocal siso=3 548 call assert_equal(3, &siso) 549 wincmd w 550 call assert_equal(7, &siso) 551 wincmd w 552 setlocal siso< 553 call assert_equal(7, &siso) 554 setlocal siso=0 555 call assert_equal(0, &siso) 556 setlocal siso=-1 557 call assert_equal(7, &siso) 558 559 close 560 set so& 561 set siso& 562endfunc 563 564func Test_writedelay() 565 if !has('reltime') 566 return 567 endif 568 new 569 call setline(1, 'empty') 570 redraw 571 set writedelay=10 572 let start = reltime() 573 call setline(1, repeat('x', 70)) 574 redraw 575 let elapsed = reltimefloat(reltime(start)) 576 set writedelay=0 577 " With 'writedelay' set should take at least 30 * 10 msec 578 call assert_inrange(30 * 0.01, 999.0, elapsed) 579 580 bwipe! 581endfunc 582 583func Test_visualbell() 584 set belloff= 585 set visualbell 586 call assert_beeps('normal 0h') 587 set novisualbell 588 set belloff=all 589endfunc 590