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