9 call assert_equal('b,s', &whichwrap)
12 call assert_equal('b,s,h,l', &whichwrap)
15 call assert_equal('b,s,h,l', &whichwrap)
18 call assert_equal('b,s,h,l', &whichwrap)
21 call assert_equal('h', &whichwrap)
24 call assert_equal('h', &whichwrap)
26 " For compatibility with Vim 3.0 and before, number values are also
27 " supported for 'whichwrap'
29 call assert_equal('b', &whichwrap)
31 call assert_equal('s', &whichwrap)
33 call assert_equal('h,l', &whichwrap)
35 call assert_equal('<,>', &whichwrap)
37 call assert_equal('[,]', &whichwrap)
39 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
45 " This used to cause Vim to access uninitialized memory.
47 call assert_equal("~X", expand("~X"))
51 " Test for getting the value of 'pastetoggle'
52 func Test_pastetoggle()
53 " character with K_SPECIAL byte
54 let &pastetoggle = '…'
55 call assert_equal('…', &pastetoggle)
56 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
58 " modified character with K_SPECIAL byte
59 let &pastetoggle = '<M-…>'
60 call assert_equal('<M-…>', &pastetoggle)
61 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
64 let str = ":\x7f:\x80:\x90:\xd0:"
65 let &pastetoggle = str
66 call assert_equal(str, &pastetoggle)
67 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
74 " Empty 'wildchar' used to access invalid memory.
75 call assert_fails('set wildchar=', 'E521:')
76 call assert_fails('set wildchar=abc', 'E521:')
78 let a=execute('set wildchar?')
79 call assert_equal("\n wildchar=<Esc>", a)
81 let a=execute('set wildchar?')
82 call assert_equal("\n wildchar=<Esc>", a)
86 func Test_wildoptions()
88 set wildoptions+=tagfile
89 set wildoptions+=tagfile
90 call assert_equal('tagfile', &wildoptions)
93 func Test_options_command()
98 let caught = v:throwpoint . "\n" . v:exception
100 call assert_equal('ok', caught)
102 " Check if the option-window is opened horizontally.
104 call assert_notequal('option-window', bufname(''))
106 call assert_equal('option-window', bufname(''))
107 " close option-window
110 " Open the option-window vertically.
112 " Check if the option-window is opened vertically.
114 call assert_notequal('option-window', bufname(''))
116 call assert_equal('option-window', bufname(''))
117 " close option-window
120 " Open the option-window at the top.
123 call assert_equal(1, winnr())
126 " Open the option-window at the bottom.
129 call assert_equal(winnr('$'), winnr())
133 " Open the option-window in a new tab.
135 " Check if the option-window is opened in a tab.
137 call assert_notequal('option-window', bufname(''))
139 call assert_equal('option-window', bufname(''))
140 " close option-window
143 " Open the options window browse
146 call assert_equal('option-window', bufname(''))
151 func Test_path_keep_commas()
152 " Test that changing 'path' keeps two commas.
156 call assert_equal('foo,,bar', &path)
161 func Test_path_too_long()
162 exe 'set path=' .. repeat('x', 10000)
163 call assert_fails('find x', 'E854:')
167 func Test_signcolumn()
169 call assert_equal("auto", &signcolumn)
172 call assert_fails('set signcolumn=nope')
175 func Test_filetype_valid()
177 call assert_equal("valid_name", &filetype)
179 call assert_equal("valid-name", &filetype)
181 call assert_fails(":set ft=wrong;name", "E474:")
182 call assert_fails(":set ft=wrong\\\\name", "E474:")
183 call assert_fails(":set ft=wrong\\|name", "E474:")
184 call assert_fails(":set ft=wrong/name", "E474:")
185 call assert_fails(":set ft=wrong\\\nname", "E474:")
186 call assert_equal("valid-name", &filetype)
188 exe "set ft=trunc\x00name"
189 call assert_equal("trunc", &filetype)
192 func Test_syntax_valid()
195 call assert_equal("valid_name", &syntax)
197 call assert_equal("valid-name", &syntax)
199 call assert_fails(":set syn=wrong;name", "E474:")
200 call assert_fails(":set syn=wrong\\\\name", "E474:")
201 call assert_fails(":set syn=wrong\\|name", "E474:")
202 call assert_fails(":set syn=wrong/name", "E474:")
203 call assert_fails(":set syn=wrong\\\nname", "E474:")
204 call assert_equal("valid-name", &syntax)
206 exe "set syn=trunc\x00name"
207 call assert_equal("trunc", &syntax)
210 func Test_keymap_valid()
212 call assert_fails(":set kmp=valid_name", "E544:")
213 call assert_fails(":set kmp=valid_name", "valid_name")
214 call assert_fails(":set kmp=valid-name", "E544:")
215 call assert_fails(":set kmp=valid-name", "valid-name")
217 call assert_fails(":set kmp=wrong;name", "E474:")
218 call assert_fails(":set kmp=wrong\\\\name", "E474:")
219 call assert_fails(":set kmp=wrong\\|name", "E474:")
220 call assert_fails(":set kmp=wrong/name", "E474:")
221 call assert_fails(":set kmp=wrong\\\nname", "E474:")
223 call assert_fails(":set kmp=trunc\x00name", "E544:")
224 call assert_fails(":set kmp=trunc\x00name", "trunc")
227 func Check_dir_option(name)
228 " Check that it's possible to set the option.
229 exe 'set ' . a:name . '=/usr/share/dict/words'
230 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
231 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
232 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
233 exe 'set ' . a:name . '=/usr/share/dict\ words'
234 call assert_equal('/usr/share/dict words', eval('&' . a:name))
236 " Check rejecting weird characters.
237 call assert_fails("set " . a:name . "=/not&there", "E474:")
238 call assert_fails("set " . a:name . "=/not>there", "E474:")
239 call assert_fails("set " . a:name . "=/not.*there", "E474:")
243 " This used to cause invalid memory access
244 set cindent cinkeys=0
246 set cindent& cinkeys&
249 func Test_dictionary()
250 call Check_dir_option('dictionary')
253 func Test_thesaurus()
254 call Check_dir_option('thesaurus')
258 " Trailing single backslash used to cause invalid memory access.
261 call feedkeys("i\<C-N>\<Esc>", 'xt')
263 call assert_fails('set complete=ix', 'E535:')
267 func Test_set_completion()
268 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
269 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
271 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
272 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
274 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
275 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
277 " Expand boolean options. When doing :set no<Tab>
278 " vim displays the options names without "no" but completion uses "no...".
279 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
280 call assert_equal('"set nodiff digraph', @:)
282 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_equal('"set invdiff digraph', @:)
285 " Expand abbreviation of options.
286 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
287 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
289 " Expand current value
290 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
291 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
293 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
294 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
297 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
298 call assert_equal('"set <Help> <Home>', @:)
300 " Expand terminal options.
301 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
302 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
303 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
305 " Expand directories.
306 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
307 call assert_match(' ./samples/ ', @:)
308 call assert_notmatch(' ./summarize.vim ', @:)
310 " Expand files and directories.
311 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
312 call assert_match(' ./samples/.* ./summarize.vim', @:)
314 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
315 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
318 " Expanding the option names
319 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
320 call assert_equal('"set all', @:)
322 " Expanding a second set of option names
323 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
324 call assert_equal('"set wrapscan all', @:)
326 " Expanding a special keycode
327 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
328 call assert_equal('"set <Home>', @:)
330 " Expanding an invalid special keycode
331 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal("\"set <abcd>\<Tab>", @:)
334 " Expanding a terminal keycode
335 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
336 call assert_equal("\"set t_AB", @:)
338 " Expanding an invalid option name
339 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
340 call assert_equal("\"set abcde=\<Tab>", @:)
342 " Expanding after a = for a boolean option
343 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
344 call assert_equal("\"set wrapscan=\<Tab>", @:)
346 " Expanding a numeric option
347 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
348 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
350 " Expanding a non-boolean option
351 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
352 call assert_equal("\"set invtabstop=", @:)
354 " Expand options for 'spellsuggest'
355 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
356 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
358 " Expand value for 'key'
360 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
361 call assert_equal('"set key=*****', @:)
364 " Expand values for 'filetype'
365 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
366 call assert_equal('"set filetype=sshdconfig', @:)
367 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
368 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
371 func Test_set_errors()
372 call assert_fails('set scroll=-1', 'E49:')
373 call assert_fails('set backupcopy=', 'E474:')
374 call assert_fails('set regexpengine=3', 'E474:')
375 call assert_fails('set history=10001', 'E474:')
376 call assert_fails('set numberwidth=21', 'E474:')
377 call assert_fails('set colorcolumn=-a', 'E474:')
378 call assert_fails('set colorcolumn=a', 'E474:')
379 call assert_fails('set colorcolumn=1,', 'E474:')
380 call assert_fails('set colorcolumn=1;', 'E474:')
381 call assert_fails('set cmdheight=-1', 'E487:')
382 call assert_fails('set cmdwinheight=-1', 'E487:')
384 call assert_fails('set conceallevel=-1', 'E487:')
385 call assert_fails('set conceallevel=4', 'E474:')
387 call assert_fails('set helpheight=-1', 'E487:')
388 call assert_fails('set history=-1', 'E487:')
389 call assert_fails('set report=-1', 'E487:')
390 call assert_fails('set shiftwidth=-1', 'E487:')
391 call assert_fails('set sidescroll=-1', 'E487:')
392 call assert_fails('set tabstop=-1', 'E487:')
393 call assert_fails('set tabstop=10000', 'E474:')
394 call assert_fails('let &tabstop = 10000', 'E474:')
395 call assert_fails('set tabstop=5500000000', 'E474:')
396 call assert_fails('set textwidth=-1', 'E487:')
397 call assert_fails('set timeoutlen=-1', 'E487:')
398 call assert_fails('set updatecount=-1', 'E487:')
399 call assert_fails('set updatetime=-1', 'E487:')
400 call assert_fails('set winheight=-1', 'E487:')
401 call assert_fails('set tabstop!', 'E488:')
402 call assert_fails('set xxx', 'E518:')
403 call assert_fails('set beautify?', 'E519:')
404 call assert_fails('set undolevels=x', 'E521:')
405 call assert_fails('set tabstop=', 'E521:')
406 call assert_fails('set comments=-', 'E524:')
407 call assert_fails('set comments=a', 'E525:')
408 call assert_fails('set foldmarker=x', 'E536:')
409 call assert_fails('set commentstring=x', 'E537:')
410 call assert_fails('let &commentstring = "x"', 'E537:')
411 call assert_fails('set complete=x', 'E539:')
412 call assert_fails('set rulerformat=%-', 'E539:')
413 call assert_fails('set rulerformat=%(', 'E542:')
414 call assert_fails('set rulerformat=%15(%%', 'E542:')
415 call assert_fails('set statusline=%$', 'E539:')
416 call assert_fails('set statusline=%{', 'E540:')
417 call assert_fails('set statusline=%{%', 'E540:')
418 call assert_fails('set statusline=%{%}', 'E539:')
419 call assert_fails('set statusline=%(', 'E542:')
420 call assert_fails('set statusline=%)', 'E542:')
421 call assert_fails('set tabline=%$', 'E539:')
422 call assert_fails('set tabline=%{', 'E540:')
423 call assert_fails('set tabline=%{%', 'E540:')
424 call assert_fails('set tabline=%{%}', 'E539:')
425 call assert_fails('set tabline=%(', 'E542:')
426 call assert_fails('set tabline=%)', 'E542:')
428 if has('cursorshape')
429 " This invalid value for 'guicursor' used to cause Vim to crash.
430 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
431 call assert_fails('set guicursor=i-ci', 'E545:')
432 call assert_fails('set guicursor=x', 'E545:')
433 call assert_fails('set guicursor=x:', 'E546:')
434 call assert_fails('set guicursor=r-cr:horx', 'E548:')
435 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
438 call assert_fails('se mouseshape=i-r:x', 'E547:')
441 " Test for 'backupext' and 'patchmode' set to the same value
444 call assert_fails('set patchmode=.bak', 'E589:')
445 call assert_equal('.patch', &patchmode)
446 call assert_fails('set backupext=.patch', 'E589:')
447 call assert_equal('.bak', &backupext)
448 set backupext& patchmode&
450 call assert_fails('set winminheight=10 winheight=9', 'E591:')
451 set winminheight& winheight&
452 set winheight=10 winminheight=10
453 call assert_fails('set winheight=9', 'E591:')
454 set winminheight& winheight&
455 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
456 set winminwidth& winwidth&
457 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
458 set winwidth& winminwidth&
459 call assert_fails("set showbreak=\x01", 'E595:')
460 call assert_fails('set t_foo=', 'E846:')
461 call assert_fails('set tabstop??', 'E488:')
462 call assert_fails('set wrapscan!!', 'E488:')
463 call assert_fails('set tabstop&&', 'E488:')
464 call assert_fails('set wrapscan<<', 'E488:')
465 call assert_fails('set wrapscan=1', 'E474:')
466 call assert_fails('set autoindent@', 'E488:')
467 call assert_fails('set wildchar=<abc>', 'E474:')
468 call assert_fails('set cmdheight=1a', 'E521:')
469 call assert_fails('set invcmdheight', 'E474:')
470 if has('python') || has('python3')
471 call assert_fails('set pyxversion=6', 'E474:')
473 call assert_fails("let &tabstop='ab'", 'E521:')
474 call assert_fails('set spellcapcheck=%\\(', 'E54:')
475 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
476 call assert_fails('set foldmarker={{{,', 'E474:')
477 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
478 setlocal listchars=trail:·
479 call assert_fails('set ambiwidth=double', 'E834:')
480 setlocal listchars=trail:-
481 setglobal listchars=trail:·
482 call assert_fails('set ambiwidth=double', 'E834:')
484 setlocal fillchars=stl:·
485 call assert_fails('set ambiwidth=double', 'E835:')
486 setlocal fillchars=stl:-
487 setglobal fillchars=stl:·
488 call assert_fails('set ambiwidth=double', 'E835:')
490 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
492 call assert_fails('set fileencoding=latin1', 'E21:')
494 call assert_fails('set t_#-&', 'E522:')
495 call assert_fails('let &formatoptions = "?"', 'E539:')
496 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
499 func Test_set_encoding()
500 let save_encoding = &encoding
503 call assert_equal('latin1', &enc)
505 call assert_equal('latin1', &enc)
507 call assert_equal('latin1', &enc)
509 call assert_equal('latin1', &enc)
511 call assert_equal('latin1', &enc)
513 call assert_equal('latin1', &enc)
515 call assert_equal('latin1', &enc)
517 call assert_equal('latin1', &enc)
518 call assert_fails('set enc=iso8858', 'E474:')
519 call assert_equal('latin1', &enc)
521 let &encoding = save_encoding
524 func CheckWasSet(name)
525 let verb_cm = execute('verbose set ' .. a:name .. '?')
526 call assert_match('Last set from.*test_options.vim', verb_cm)
528 func CheckWasNotSet(name)
529 let verb_cm = execute('verbose set ' .. a:name .. '?')
530 call assert_notmatch('Last set from', verb_cm)
533 " Must be executed before other tests that set 'term'.
534 func Test_000_term_option_verbose()
537 call CheckWasNotSet('t_cm')
539 let term_save = &term
541 call CheckWasSet('t_cm')
542 let &term = term_save
545 func Test_copy_context()
547 call CheckWasSet('list')
549 call CheckWasSet('list')
554 call CheckWasSet('ai')
556 call CheckWasSet('filetype')
558 call CheckWasSet('fo')
561 call CheckWasSet('ai')
562 call CheckWasNotSet('filetype')
563 call CheckWasSet('fo')
566 func Test_set_ttytype()
570 " Setting 'ttytype' used to cause a double-free when exiting vim and
571 " when vim is compiled with -DEXITFREE.
573 call assert_equal('ansi', &ttytype)
574 call assert_equal(&ttytype, &term)
576 call assert_equal('xterm', &ttytype)
577 call assert_equal(&ttytype, &term)
580 call assert_report('set ttytype= did not fail')
584 " Some systems accept any terminal name and return dumb settings,
585 " check for failure of finding the entry and for missing 'cm' entry.
588 call assert_report('set ttytype=xxx did not fail')
593 call assert_equal(&ttytype, &term)
595 if has('gui') && !has('gui_running')
596 call assert_fails('set term=gui', 'E531:')
602 set iskeyword=a-z,A-Z
604 let out = execute('set all')
605 call assert_match('textwidth=75', out)
606 call assert_match('iskeyword=a-z,A-Z', out)
607 call assert_match('nosplitbelow', out)
608 set tw& iskeyword& splitbelow&
611 func Test_set_one_column()
612 let out_mult = execute('set all')->split("\n")
613 let out_one = execute('set! all')->split("\n")
614 call assert_true(len(out_mult) < len(out_one))
617 func Test_set_values()
618 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
619 if filereadable('opt_test.vim')
622 throw 'Skipped: opt_test.vim does not exist'
626 func Test_renderoptions()
627 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
628 " Doesn't hurt to do this on a non-Windows system.
629 if windowsversion() !~ '^[345]\.'
630 set renderoptions=type:directx
635 func ResetIndentexpr()
639 func Test_set_indentexpr()
640 " this was causing usage of freed memory
641 set indentexpr=ResetIndentexpr()
643 call feedkeys("i\<c-f>", 'x')
644 call assert_equal('', &indentexpr)
648 func Test_backupskip()
649 " Option 'backupskip' may contain several comma-separated path
650 " specifications if one or more of the environment variables TMPDIR, TMP,
651 " or TEMP is defined. To simplify testing, convert the string value into a
653 let bsklist = split(&bsk, ',')
656 let found = (index(bsklist, '/private/tmp/*') >= 0)
657 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
659 let found = (index(bsklist, '/tmp/*') >= 0)
660 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
663 " If our test platform is Windows, the path(s) in option bsk will use
664 " backslash for the path separator and the components could be in short
665 " (8.3) format. As such, we need to replace the backslashes with forward
666 " slashes and convert the path components to long format. The expand()
667 " function will do this but it cannot handle comma-separated paths. This is
668 " why bsk was converted from a string into a list of strings above.
670 " One final complication is that the wildcard "/*" is at the end of each
671 " path and so expand() might return a list of matching files. To prevent
672 " this, we need to remove the wildcard before calling expand() and then
673 " append it afterwards.
676 while item_nbr < len(bsklist)
677 let path_spec = bsklist[item_nbr]
678 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
679 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
680 let bsklist[item_nbr] = path_spec . '/*'
685 " Option bsk will also include these environment variables if defined.
686 " If they're defined, verify they appear in the option value.
687 for var in ['$TMPDIR', '$TMP', '$TEMP']
689 let varvalue = substitute(expand(var), '\\', '/', 'g')
690 let varvalue = substitute(varvalue, '/$', '', '')
692 let found = (index(bsklist, varvalue) >= 0)
693 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
697 " Duplicates from environment variables should be filtered out (option has
698 " P_NODUP). Run this in a separate instance and write v:errors in a file,
699 " so that we see what happens on startup.
700 let after =<< trim [CODE]
701 let bsklist = split(&backupskip, ',')
702 call assert_equal(uniq(copy(bsklist)), bsklist)
703 call writefile(['errors:'] + v:errors, 'Xtestout')
706 call writefile(after, 'Xafter', 'D')
707 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
710 for var in ['TMPDIR', 'TMP', 'TEMP']
711 let saveenv[var] = getenv(var)
712 call setenv(var, '/duplicate/path')
716 call assert_equal(['errors:'], readfile('Xtestout'))
718 " restore environment variables
719 for var in ['TMPDIR', 'TMP', 'TEMP']
720 call setenv(var, saveenv[var])
723 call delete('Xtestout')
725 " Duplicates should be filtered out (option has P_NODUP)
726 let backupskip = &backupskip
728 set backupskip+=/test/dir
729 set backupskip+=/other/dir
730 set backupskip+=/test/dir
731 call assert_equal('/test/dir,/other/dir', &backupskip)
732 let &backupskip = backupskip
735 func Test_buf_copy_winopt()
738 " Test copy option from current buffer in window
741 setlocal numberwidth=5
743 call assert_equal(4,&numberwidth)
745 call assert_equal(5,&numberwidth)
747 call assert_equal(4,&numberwidth)
749 " Test copy value from window that used to be display the buffer
752 setlocal numberwidth=6
755 call assert_equal(4,&numberwidth)
757 call assert_equal(6,&numberwidth)
760 " Test that if buffer is current, don't use the stale cached value
761 " from the last time the buffer was displayed.
764 setlocal numberwidth=7
767 setlocal numberwidth=8
769 call assert_equal(4,&numberwidth)
771 call assert_equal(8,&numberwidth)
774 " Test value is not copied if window already has seen the buffer
777 setlocal numberwidth=9
779 setlocal numberwidth=10
781 call assert_equal(4,&numberwidth)
783 call assert_equal(4,&numberwidth)
789 def Test_split_copy_options()
791 ['cursorbind', true, false],
792 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
794 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
796 ['relativenumber', true, false],
797 ['scrollbind', true, false],
798 ['smoothscroll', true, false],
799 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
800 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
801 ['wrap', false, true],
805 ['breakindent', true, false],
806 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
807 ['linebreak', true, false],
808 ['numberwidth', 7, 4],
809 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
814 ['rightleft', true, false],
815 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
820 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
825 ['spell', true, false],
830 ['cursorcolumn', true, false],
831 ['cursorline', true, false],
832 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
833 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
838 ['diff', true, false],
843 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
844 ['conceallevel', '3', &conceallevel],
849 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
850 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
855 ['foldcolumn', 5, &foldcolumn],
856 ['foldenable', false, true],
857 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
858 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
859 ['foldlevel', 4, &foldlevel],
860 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
861 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
862 ['foldminlines', 3, &foldminlines],
863 ['foldnestmax', 17, &foldnestmax],
864 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
869 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
873 # set options to non-default value
875 exe $'&l:{item[0]} = {item[1]}'
878 # check values are set in new window
881 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
887 exe $'&l:{item[0]} = {item[2]}'
891 func Test_shortmess_F()
893 call assert_match('\[No Name\]', execute('file'))
895 call assert_match('\[No Name\]', execute('file'))
896 call assert_match('^\s*$', execute('file foo'))
897 call assert_match('foo', execute('file'))
899 call assert_match('bar', execute('file bar'))
900 call assert_match('bar', execute('file'))
905 func Test_shortmess_F2()
908 call assert_match('file1', execute('bn', ''))
909 call assert_match('file2', execute('bn', ''))
911 call assert_true(empty(execute('bn', '')))
912 call assert_false(test_getvalue('need_fileinfo'))
913 call assert_true(empty(execute('bn', '')))
914 call assert_false('need_fileinfo'->test_getvalue())
916 call assert_true(empty(execute('bn', '')))
917 call assert_false(test_getvalue('need_fileinfo'))
918 call assert_true(empty(execute('bn', '')))
919 call assert_false(test_getvalue('need_fileinfo'))
921 call assert_true(empty(execute('bn', '')))
922 call assert_false(test_getvalue('need_fileinfo'))
923 call assert_true(empty(execute('bn', '')))
924 call assert_false(test_getvalue('need_fileinfo'))
926 call assert_match('file1', execute('bn', ''))
927 call assert_match('file2', execute('bn', ''))
930 call assert_fails('call test_getvalue("abc")', 'E475:')
933 func Test_local_scrolloff()
937 call assert_equal(5, &so)
939 call assert_equal(3, &so)
941 call assert_equal(5, &so)
944 call assert_equal(5, &so)
946 call assert_equal(0, &so)
948 call assert_equal(5, &so)
950 call assert_equal(7, &siso)
952 call assert_equal(3, &siso)
954 call assert_equal(7, &siso)
957 call assert_equal(7, &siso)
959 call assert_equal(0, &siso)
961 call assert_equal(7, &siso)
968 func Test_writedelay()
969 CheckFunction reltimefloat
972 call setline(1, 'empty')
975 let start = reltime()
976 call setline(1, repeat('x', 70))
978 let elapsed = reltimefloat(reltime(start))
980 " With 'writedelay' set should take at least 30 * 10 msec
981 call assert_inrange(30 * 0.01, 999.0, elapsed)
986 func Test_visualbell()
989 call assert_beeps('normal 0h')
994 " Test for the 'write' option
997 call setline(1, ['L1'])
999 call assert_fails('write Xwrfile', 'E142:')
1004 " Test for 'buftype' option
1007 call setline(1, ['L1'])
1009 call assert_fails('write', 'E382:')
1011 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1012 exe 'set buftype=' .. val
1013 call writefile(['something'], 'XBuftype', 'D')
1014 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1020 " Test for the 'rightleftcmd' option
1021 func Test_rightleftcmd()
1022 CheckFeature rightleft
1027 call add(g:l, screencol())
1030 cmap <expr> <F2> AddPos()
1033 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1034 \ "\<Right>\<F2>\<Esc>", 'xt')
1035 call assert_equal([2, 5, 3, 4], g:l)
1038 set rightleftcmd=search
1039 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1040 \ "\<Left>\<F2>\<Esc>", 'xt')
1041 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1049 " Test for the 'debug' option
1050 func Test_debug_option()
1051 " redraw to avoid matching previous messages
1055 call assert_equal('Beep!', Screenline(&lines))
1056 call assert_equal('line 4:', Screenline(&lines - 1))
1057 " only match the final colon in the line that shows the source
1058 call assert_match(':$', Screenline(&lines - 2))
1062 " Test for the default CDPATH option
1063 func Test_opt_default_cdpath()
1064 let after =<< trim [CODE]
1065 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1066 call writefile(v:errors, 'Xtestout')
1070 let $CDPATH='/path/to/dir1:/path/to/dir2'
1072 let $CDPATH='/path/to/dir1;/path/to/dir2'
1074 if RunVim([], after, '')
1075 call assert_equal([], readfile('Xtestout'))
1076 call delete('Xtestout')
1080 " Test for setting keycodes using set
1081 func Test_opt_set_keycode()
1082 call assert_fails('set <t_k1=l', 'E474:')
1083 call assert_fails('set <Home=l', 'E474:')
1085 call assert_equal('abcd', &t_k9)
1088 call assert_equal('xyz', &t_k9)
1091 " should we test all of them?
1097 call assert_equal('testCe', &t_Ce)
1098 call assert_equal('testCs', &t_Cs)
1099 call assert_equal('testUs', &t_Us)
1100 call assert_equal('testds', &t_ds)
1101 call assert_equal('testDs', &t_Ds)
1104 " Test for changing options in a sandbox
1105 func Test_opt_sandbox()
1106 for opt in ['backupdir', 'cdpath', 'exrc']
1107 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
1108 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
1110 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
1113 " Test for setting an option with local value to global value
1114 func Test_opt_local_to_global()
1115 setglobal equalprg=gprg
1116 setlocal equalprg=lprg
1117 call assert_equal('gprg', &g:equalprg)
1118 call assert_equal('lprg', &l:equalprg)
1119 call assert_equal('lprg', &equalprg)
1121 call assert_equal('', &l:equalprg)
1122 call assert_equal('gprg', &equalprg)
1123 setglobal equalprg=gnewprg
1124 setlocal equalprg=lnewprg
1126 call assert_equal('gnewprg', &l:equalprg)
1127 call assert_equal('gnewprg', &equalprg)
1130 " Test for setting the global/local value of a boolean option
1133 call assert_false(&autoread)
1135 call assert_true(&autoread)
1136 setglobal noautoread
1139 call assert_false(&autoread)
1143 func Test_set_in_sandbox()
1144 " Some boolean options cannot be set in sandbox, some can.
1145 call assert_fails('sandbox set modelineexpr', 'E48:')
1147 call assert_true(&number)
1150 " Some boolean options cannot be set in sandbox, some can.
1151 if has('python') || has('python3')
1152 call assert_fails('sandbox set pyxversion=3', 'E48:')
1154 sandbox set tabstop=4
1155 call assert_equal(4, &tabstop)
1158 " Some string options cannot be set in sandbox, some can.
1159 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1160 sandbox set filetype=perl
1161 call assert_equal('perl', &filetype)
1165 " Test for incrementing, decrementing and multiplying a number option value
1166 func Test_opt_num_op()
1169 call assert_equal(6, &sw)
1171 call assert_equal(4, &sw)
1173 call assert_equal(8, &sw)
1177 " Test for setting option values using v:false and v:true
1178 func Test_opt_boolean()
1181 call assert_equal(1, &nu)
1183 call assert_equal(0, &nu)
1185 call assert_equal(1, &nu)
1187 call assert_equal(0, &nu)
1191 " Test for the 'window' option
1192 func Test_window_opt()
1193 " Needs only one open widow
1195 call setline(1, range(1, 8))
1198 call assert_equal(4, line('w0'))
1200 call assert_equal(7, line('w0'))
1202 call assert_equal(8, line('w0'))
1204 call assert_equal(5, line('w0'))
1206 call assert_equal(2, line('w0'))
1208 call assert_equal(1, line('w0'))
1210 exe "normal gg\<C-F>"
1211 call assert_equal(2, line('w0'))
1213 call assert_equal(3, line('w0'))
1215 call assert_equal(2, line('w0'))
1217 call assert_equal(1, line('w0'))
1222 " Test for the 'winminheight' option
1223 func Test_opt_winminheight()
1225 let &winheight = &lines + 4
1226 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1227 call assert_true(&winminheight <= &lines)
1232 func Test_opt_winminheight_term()
1233 CheckRunVimInTerminal
1235 " The tabline should be taken into account.
1236 let lines =<< trim END
1243 call writefile(lines, 'Xwinminheight', 'D')
1244 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1245 call term_sendkeys(buf, ":set wmh=1\n")
1246 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1248 call StopVimInTerminal(buf)
1251 func Test_opt_winminheight_term_tabs()
1252 CheckRunVimInTerminal
1254 " The tabline should be taken into account.
1255 let lines =<< trim END
1263 call writefile(lines, 'Xwinminheight', 'D')
1264 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1265 call term_sendkeys(buf, ":set wmh=1\n")
1266 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1268 call StopVimInTerminal(buf)
1271 " Test for the 'winminwidth' option
1272 func Test_opt_winminwidth()
1274 let &winwidth = &columns + 4
1275 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1276 call assert_true(&winminwidth <= &columns)
1281 " Test for setting option value containing spaces with isfname+=32
1282 func Test_isfname_with_options()
1284 setlocal keywordprg=:term\ help.exe
1285 call assert_equal(':term help.exe', &keywordprg)
1287 setlocal keywordprg&
1290 " Test that resetting laststatus does change scroll option
1291 func Test_opt_reset_scroll()
1292 CheckRunVimInTerminal
1293 let vimrc =<< trim [CODE]
1297 call writefile(vimrc, 'Xscroll', 'D')
1298 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1299 call term_sendkeys(buf, ":verbose set scroll?\n")
1300 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1301 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
1304 call StopVimInTerminal(buf)
1307 " Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1308 func Test_VIM_POSIX()
1309 let saved_VIM_POSIX = getenv("VIM_POSIX")
1311 call setenv('VIM_POSIX', "1")
1312 let after =<< trim [CODE]
1313 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1316 if RunVim([], after, '')
1317 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1318 \ 'AS'], readfile('X_VIM_POSIX'))
1321 call setenv('VIM_POSIX', v:null)
1322 let after =<< trim [CODE]
1323 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1326 if RunVim([], after, '')
1327 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1328 \ 'S'], readfile('X_VIM_POSIX'))
1331 call delete('X_VIM_POSIX')
1332 call setenv('VIM_POSIX', saved_VIM_POSIX)
1335 " Test for setting an option to a Vi or Vim default
1336 func Test_opt_default()
1337 set formatoptions&vi
1338 call assert_equal('vt', &formatoptions)
1339 set formatoptions&vim
1340 call assert_equal('tcq', &formatoptions)
1342 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1345 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1348 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1351 " Test for the 'cmdheight' option
1352 func Test_cmdheight()
1356 call assert_equal(1, winheight(0))
1357 call assert_equal(ht - 1, &cmdheight)
1361 " To specify a control character as an option value, '^' can be used
1362 func Test_opt_control_char()
1364 call assert_equal("\<C-V>", nr2char(&wildchar))
1366 call assert_equal("\<C-R>", nr2char(&wildcharm))
1367 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1368 set wildchar& wildcharm&
1371 " Test for the 'errorbells' option
1372 func Test_opt_errorbells()
1374 call assert_beeps('s/a1b2/x1y2/')
1378 func Test_opt_scrolljump()
1382 " Test with positive 'scrolljump'.
1385 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1386 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1389 " Test with negative 'scrolljump' (percentage of window height).
1392 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1393 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1400 " Test for the 'cdhome' option
1401 func Test_opt_cdhome()
1402 if has('unix') || has('vms')
1403 throw 'Skipped: only works on non-Unix'
1407 call assert_equal(0, &cdhome)
1410 " This paragraph is copied from Test_cd_no_arg().
1413 call assert_equal($HOME, getcwd())
1414 call assert_notequal(path, getcwd())
1415 exe 'cd ' .. fnameescape(path)
1416 call assert_equal(path, getcwd())
1421 func Test_set_completion_2()
1422 CheckOption termguicolors
1424 " Test default option completion
1426 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1427 call assert_equal('"set termguicolors', @:)
1429 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1430 call assert_equal('"set notermguicolors', @:)
1432 " Test fuzzy option completion
1433 set wildoptions=fuzzy
1434 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1435 call assert_equal('"set termguicolors termencoding', @:)
1437 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1438 call assert_equal('"set notermguicolors', @:)
1443 func Test_switchbuf_reset()
1444 set switchbuf=useopen
1446 call assert_equal(1, winnr('$'))
1448 call assert_equal('', &switchbuf)
1450 call assert_equal(2, winnr('$'))
1454 " :set empty string for global 'keywordprg' falls back to ":help"
1455 func Test_keywordprg_empty()
1458 call assert_equal('man', &keywordprg)
1460 call assert_equal(':help', &keywordprg)
1462 call assert_equal('man', &keywordprg)
1463 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1467 " check that the very first buffer created does not have 'endoffile' set
1468 func Test_endoffile_default()
1469 let after =<< trim [CODE]
1470 call writefile([execute('set eof?')], 'Xtestout')
1473 if RunVim([], after, '')
1474 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1476 call delete('Xtestout')
1479 " Test for setting the 'lines' and 'columns' options to a minimum value
1480 func Test_set_min_lines_columns()
1481 let save_lines = &lines
1482 let save_columns = &columns
1484 let after =<< trim END
1488 silent! let &columns=0
1489 call add(msg, v:errmsg)
1490 silent! set columns=0
1491 call add(msg, v:errmsg)
1492 silent! call setbufvar('', '&columns', 0)
1493 call add(msg, v:errmsg)
1494 "call writefile(msg, 'XResultsetminlines')
1495 silent! let &lines=0
1496 call add(msg, v:errmsg)
1498 call add(msg, v:errmsg)
1499 silent! call setbufvar('', '&lines', 0)
1500 call add(msg, v:errmsg)
1501 call writefile(msg, 'XResultsetminlines')
1504 if RunVim([], after, '')
1505 call assert_equal(['E594: Need at least 12 columns',
1506 \ 'E594: Need at least 12 columns: columns=0',
1507 \ 'E594: Need at least 12 columns',
1508 \ 'E593: Need at least 2 lines',
1509 \ 'E593: Need at least 2 lines: lines=0',
1510 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1513 call delete('XResultsetminlines')
1514 let &lines = save_lines
1515 let &columns = save_columns
1518 " Test for reverting a string option value if the new value is invalid.
1519 func Test_string_option_revert_on_failure()
1522 \ ['ambiwidth', 'double', 'a123'],
1523 \ ['background', 'dark', 'a123'],
1524 \ ['backspace', 'eol', 'a123'],
1525 \ ['backupcopy', 'no', 'a123'],
1526 \ ['belloff', 'showmatch', 'a123'],
1527 \ ['breakindentopt', 'min:10', 'list'],
1528 \ ['bufhidden', 'wipe', 'a123'],
1529 \ ['buftype', 'nowrite', 'a123'],
1530 \ ['casemap', 'keepascii', 'a123'],
1531 \ ['cedit', "\<C-Y>", 'z'],
1532 \ ['colorcolumn', '10', 'z'],
1533 \ ['commentstring', '#%s', 'a123'],
1534 \ ['complete', '.,t', 'a'],
1535 \ ['completefunc', 'MyCmplFunc', '1a-'],
1536 \ ['completeopt', 'popup', 'a123'],
1537 \ ['completepopup', 'width:20', 'border'],
1538 \ ['concealcursor', 'v', 'xyz'],
1539 \ ['cpoptions', 'HJ', '~'],
1540 \ ['cryptmethod', 'zip', 'a123'],
1541 \ ['cursorlineopt', 'screenline', 'a123'],
1542 \ ['debug', 'throw', 'a123'],
1543 \ ['diffopt', 'iwhite', 'a123'],
1544 \ ['display', 'uhex', 'a123'],
1545 \ ['eadirection', 'hor', 'a123'],
1546 \ ['encoding', 'utf-8', 'a123'],
1547 \ ['eventignore', 'TextYankPost', 'a123'],
1548 \ ['fileencoding', 'utf-8', 'a123,'],
1549 \ ['fileformat', 'mac', 'a123'],
1550 \ ['fileformats', 'mac', 'a123'],
1551 \ ['fillchars', 'diff:~', 'a123'],
1552 \ ['foldclose', 'all', 'a123'],
1553 \ ['foldmarker', '[[[,]]]', '[[['],
1554 \ ['foldmethod', 'marker', 'a123'],
1555 \ ['foldopen', 'percent', 'a123'],
1556 \ ['formatoptions', 'an', '*'],
1557 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1558 \ ['helplang', 'en', 'a'],
1559 \ ['highlight', '!:CursorColumn', '8:']
1562 call add(optlist, ['browsedir', 'buffer', 'a123'])
1564 if has('clipboard_working')
1565 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1568 call add(optlist, ['completeslash', 'slash', 'a123'])
1571 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1574 call add(optlist, ['imactivatefunc', 'MyCmplFunc', '1a-'])
1577 exe $"let save_opt = &{opt[0]}"
1578 exe $"let &{opt[0]} = '{opt[1]}'"
1579 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1580 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1581 exe $"let &{opt[0]} = save_opt"
1586 " vim: shiftwidth=2 sts=2 expandtab