xref: /vim-8.2.3635/src/testdir/test_options.vim (revision 5daa9116)
1" Test for options
2
3source shared.vim
4source check.vim
5source view_util.vim
6
7func Test_whichwrap()
8  set whichwrap=b,s
9  call assert_equal('b,s', &whichwrap)
10
11  set whichwrap+=h,l
12  call assert_equal('b,s,h,l', &whichwrap)
13
14  set whichwrap+=h,l
15  call assert_equal('b,s,h,l', &whichwrap)
16
17  set whichwrap+=h,l
18  call assert_equal('b,s,h,l', &whichwrap)
19
20  set whichwrap=h,h
21  call assert_equal('h', &whichwrap)
22
23  set whichwrap=h,h,h
24  call assert_equal('h', &whichwrap)
25
26  " For compatibility with Vim 3.0 and before, number values are also
27  " supported for 'whichwrap'
28  set whichwrap=1
29  call assert_equal('b', &whichwrap)
30  set whichwrap=2
31  call assert_equal('s', &whichwrap)
32  set whichwrap=4
33  call assert_equal('h,l', &whichwrap)
34  set whichwrap=8
35  call assert_equal('<,>', &whichwrap)
36  set whichwrap=16
37  call assert_equal('[,]', &whichwrap)
38  set whichwrap=31
39  call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
40
41  set whichwrap&
42endfunc
43
44func Test_isfname()
45  " This used to cause Vim to access uninitialized memory.
46  set isfname=
47  call assert_equal("~X", expand("~X"))
48  set isfname&
49endfunc
50
51func Test_wildchar()
52  " Empty 'wildchar' used to access invalid memory.
53  call assert_fails('set wildchar=', 'E521:')
54  call assert_fails('set wildchar=abc', 'E521:')
55  set wildchar=<Esc>
56  let a=execute('set wildchar?')
57  call assert_equal("\n  wildchar=<Esc>", a)
58  set wildchar=27
59  let a=execute('set wildchar?')
60  call assert_equal("\n  wildchar=<Esc>", a)
61  set wildchar&
62endfunc
63
64func Test_wildoptions()
65  set wildoptions=
66  set wildoptions+=tagfile
67  set wildoptions+=tagfile
68  call assert_equal('tagfile', &wildoptions)
69endfunc
70
71func Test_options_command()
72  let caught = 'ok'
73  try
74    options
75  catch
76    let caught = v:throwpoint . "\n" . v:exception
77  endtry
78  call assert_equal('ok', caught)
79
80  " Check if the option-window is opened horizontally.
81  wincmd j
82  call assert_notequal('option-window', bufname(''))
83  wincmd k
84  call assert_equal('option-window', bufname(''))
85  " close option-window
86  close
87
88  " Open the option-window vertically.
89  vert options
90  " Check if the option-window is opened vertically.
91  wincmd l
92  call assert_notequal('option-window', bufname(''))
93  wincmd h
94  call assert_equal('option-window', bufname(''))
95  " close option-window
96  close
97
98  " Open the option-window at the top.
99  set splitbelow
100  topleft options
101  call assert_equal(1, winnr())
102  close
103
104  " Open the option-window at the bottom.
105  set nosplitbelow
106  botright options
107  call assert_equal(winnr('$'), winnr())
108  close
109  set splitbelow&
110
111  " Open the option-window in a new tab.
112  tab options
113  " Check if the option-window is opened in a tab.
114  normal gT
115  call assert_notequal('option-window', bufname(''))
116  normal gt
117  call assert_equal('option-window', bufname(''))
118  " close option-window
119  close
120
121  " Open the options window browse
122  if has('browse')
123    browse set
124    call assert_equal('option-window', bufname(''))
125    close
126  endif
127endfunc
128
129func Test_path_keep_commas()
130  " Test that changing 'path' keeps two commas.
131  set path=foo,,bar
132  set path-=bar
133  set path+=bar
134  call assert_equal('foo,,bar', &path)
135
136  set path&
137endfunc
138
139func Test_signcolumn()
140  CheckFeature signs
141  call assert_equal("auto", &signcolumn)
142  set signcolumn=yes
143  set signcolumn=no
144  call assert_fails('set signcolumn=nope')
145endfunc
146
147func Test_filetype_valid()
148  set ft=valid_name
149  call assert_equal("valid_name", &filetype)
150  set ft=valid-name
151  call assert_equal("valid-name", &filetype)
152
153  call assert_fails(":set ft=wrong;name", "E474:")
154  call assert_fails(":set ft=wrong\\\\name", "E474:")
155  call assert_fails(":set ft=wrong\\|name", "E474:")
156  call assert_fails(":set ft=wrong/name", "E474:")
157  call assert_fails(":set ft=wrong\\\nname", "E474:")
158  call assert_equal("valid-name", &filetype)
159
160  exe "set ft=trunc\x00name"
161  call assert_equal("trunc", &filetype)
162endfunc
163
164func Test_syntax_valid()
165  CheckFeature syntax
166  set syn=valid_name
167  call assert_equal("valid_name", &syntax)
168  set syn=valid-name
169  call assert_equal("valid-name", &syntax)
170
171  call assert_fails(":set syn=wrong;name", "E474:")
172  call assert_fails(":set syn=wrong\\\\name", "E474:")
173  call assert_fails(":set syn=wrong\\|name", "E474:")
174  call assert_fails(":set syn=wrong/name", "E474:")
175  call assert_fails(":set syn=wrong\\\nname", "E474:")
176  call assert_equal("valid-name", &syntax)
177
178  exe "set syn=trunc\x00name"
179  call assert_equal("trunc", &syntax)
180endfunc
181
182func Test_keymap_valid()
183  CheckFeature keymap
184  call assert_fails(":set kmp=valid_name", "E544:")
185  call assert_fails(":set kmp=valid_name", "valid_name")
186  call assert_fails(":set kmp=valid-name", "E544:")
187  call assert_fails(":set kmp=valid-name", "valid-name")
188
189  call assert_fails(":set kmp=wrong;name", "E474:")
190  call assert_fails(":set kmp=wrong\\\\name", "E474:")
191  call assert_fails(":set kmp=wrong\\|name", "E474:")
192  call assert_fails(":set kmp=wrong/name", "E474:")
193  call assert_fails(":set kmp=wrong\\\nname", "E474:")
194
195  call assert_fails(":set kmp=trunc\x00name", "E544:")
196  call assert_fails(":set kmp=trunc\x00name", "trunc")
197endfunc
198
199func Check_dir_option(name)
200  " Check that it's possible to set the option.
201  exe 'set ' . a:name . '=/usr/share/dict/words'
202  call assert_equal('/usr/share/dict/words', eval('&' . a:name))
203  exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
204  call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
205  exe 'set ' . a:name . '=/usr/share/dict\ words'
206  call assert_equal('/usr/share/dict words', eval('&' . a:name))
207
208  " Check rejecting weird characters.
209  call assert_fails("set " . a:name . "=/not&there", "E474:")
210  call assert_fails("set " . a:name . "=/not>there", "E474:")
211  call assert_fails("set " . a:name . "=/not.*there", "E474:")
212endfunc
213
214func Test_cinkeys()
215  " This used to cause invalid memory access
216  set cindent cinkeys=0
217  norm a
218  set cindent& cinkeys&
219endfunc
220
221func Test_dictionary()
222  call Check_dir_option('dictionary')
223endfunc
224
225func Test_thesaurus()
226  call Check_dir_option('thesaurus')
227endfun
228
229func Test_complete()
230  " Trailing single backslash used to cause invalid memory access.
231  set complete=s\
232  new
233  call feedkeys("i\<C-N>\<Esc>", 'xt')
234  bwipe!
235  call assert_fails('set complete=ix', 'E535:')
236  set complete&
237endfun
238
239func Test_set_completion()
240  call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
241  call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
242
243  call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
244  call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
245
246  call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
247  call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
248
249  " Expand boolan options. When doing :set no<Tab>
250  " vim displays the options names without "no" but completion uses "no...".
251  call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
252  call assert_equal('"set nodiff digraph', @:)
253
254  call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
255  call assert_equal('"set invdiff digraph', @:)
256
257  " Expand abbreviation of options.
258  call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
259  call assert_equal('"set tabstop thesaurus ttyscroll', @:)
260
261  " Expand current value
262  call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
263  call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
264
265  call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
266  call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
267
268  " Expand key codes.
269  call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
270  call assert_equal('"set <Help> <Home>', @:)
271
272  " Expand terminal options.
273  call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
274  call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
275  call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
276
277  " Expand directories.
278  call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
279  call assert_match(' ./samples/ ', @:)
280  call assert_notmatch(' ./summarize.vim ', @:)
281
282  " Expand files and directories.
283  call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
284  call assert_match(' ./samples/.* ./summarize.vim', @:)
285
286  call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
287  call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
288  set tags&
289
290  " Expanding the option names
291  call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
292  call assert_equal('"set all', @:)
293
294  " Expanding a second set of option names
295  call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
296  call assert_equal('"set wrapscan all', @:)
297
298  " Expanding a special keycode
299  call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
300  call assert_equal('"set <Home>', @:)
301
302  " Expanding an invalid special keycode
303  call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
304  call assert_equal("\"set <abcd>\<Tab>", @:)
305
306  " Expanding a terminal keycode
307  call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
308  call assert_equal("\"set t_AB", @:)
309
310  " Expanding an invalid option name
311  call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
312  call assert_equal("\"set abcde=\<Tab>", @:)
313
314  " Expanding after a = for a boolean option
315  call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
316  call assert_equal("\"set wrapscan=\<Tab>", @:)
317
318  " Expanding a numeric option
319  call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
320  call assert_equal("\"set tabstop+=" .. &tabstop, @:)
321
322  " Expanding a non-boolean option
323  call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
324  call assert_equal("\"set invtabstop=", @:)
325
326  " Expand options for 'spellsuggest'
327  call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
328  call assert_equal("\"set spellsuggest=best,file:xyz", @:)
329
330  " Expand value for 'key'
331  set key=abcd
332  call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
333  call assert_equal('"set key=*****', @:)
334  set key=
335endfunc
336
337func Test_set_errors()
338  call assert_fails('set scroll=-1', 'E49:')
339  call assert_fails('set backupcopy=', 'E474:')
340  call assert_fails('set regexpengine=3', 'E474:')
341  call assert_fails('set history=10001', 'E474:')
342  call assert_fails('set numberwidth=21', 'E474:')
343  call assert_fails('set colorcolumn=-a', 'E474:')
344  call assert_fails('set colorcolumn=a', 'E474:')
345  call assert_fails('set colorcolumn=1,', 'E474:')
346  call assert_fails('set colorcolumn=1;', 'E474:')
347  call assert_fails('set cmdheight=-1', 'E487:')
348  call assert_fails('set cmdwinheight=-1', 'E487:')
349  if has('conceal')
350    call assert_fails('set conceallevel=-1', 'E487:')
351    call assert_fails('set conceallevel=4', 'E474:')
352  endif
353  call assert_fails('set helpheight=-1', 'E487:')
354  call assert_fails('set history=-1', 'E487:')
355  call assert_fails('set report=-1', 'E487:')
356  call assert_fails('set shiftwidth=-1', 'E487:')
357  call assert_fails('set sidescroll=-1', 'E487:')
358  call assert_fails('set tabstop=-1', 'E487:')
359  call assert_fails('set textwidth=-1', 'E487:')
360  call assert_fails('set timeoutlen=-1', 'E487:')
361  call assert_fails('set updatecount=-1', 'E487:')
362  call assert_fails('set updatetime=-1', 'E487:')
363  call assert_fails('set winheight=-1', 'E487:')
364  call assert_fails('set tabstop!', 'E488:')
365  call assert_fails('set xxx', 'E518:')
366  call assert_fails('set beautify?', 'E519:')
367  call assert_fails('set undolevels=x', 'E521:')
368  call assert_fails('set tabstop=', 'E521:')
369  call assert_fails('set comments=-', 'E524:')
370  call assert_fails('set comments=a', 'E525:')
371  call assert_fails('set foldmarker=x', 'E536:')
372  call assert_fails('set commentstring=x', 'E537:')
373  call assert_fails('set complete=x', 'E539:')
374  call assert_fails('set rulerformat=%-', 'E539:')
375  call assert_fails('set rulerformat=%(', 'E542:')
376  call assert_fails('set rulerformat=%15(%%', 'E542:')
377  call assert_fails('set statusline=%$', 'E539:')
378  call assert_fails('set statusline=%{', 'E540:')
379  call assert_fails('set statusline=%(', 'E542:')
380  call assert_fails('set statusline=%)', 'E542:')
381
382  if has('cursorshape')
383    " This invalid value for 'guicursor' used to cause Vim to crash.
384    call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
385    call assert_fails('set guicursor=i-ci', 'E545:')
386    call assert_fails('set guicursor=x', 'E545:')
387    call assert_fails('set guicursor=x:', 'E546:')
388    call assert_fails('set guicursor=r-cr:horx', 'E548:')
389    call assert_fails('set guicursor=r-cr:hor0', 'E549:')
390  endif
391  if has('mouseshape')
392    call assert_fails('se mouseshape=i-r:x', 'E547:')
393  endif
394  call assert_fails('set backupext=~ patchmode=~', 'E589:')
395  call assert_fails('set winminheight=10 winheight=9', 'E591:')
396  set winminheight& winheight&
397  set winheight=10 winminheight=10
398  call assert_fails('set winheight=9', 'E591:')
399  set winminheight& winheight&
400  call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
401  set winminwidth& winwidth&
402  call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
403  set winwidth& winminwidth&
404  call assert_fails("set showbreak=\x01", 'E595:')
405  call assert_fails('set t_foo=', 'E846:')
406  call assert_fails('set tabstop??', 'E488:')
407  call assert_fails('set wrapscan!!', 'E488:')
408  call assert_fails('set tabstop&&', 'E488:')
409  call assert_fails('set wrapscan<<', 'E488:')
410  call assert_fails('set wrapscan=1', 'E474:')
411  call assert_fails('set autoindent@', 'E488:')
412  call assert_fails('set wildchar=<abc>', 'E474:')
413  call assert_fails('set cmdheight=1a', 'E521:')
414  call assert_fails('set invcmdheight', 'E474:')
415  if has('python') || has('python3')
416    call assert_fails('set pyxversion=6', 'E474:')
417  endif
418  call assert_fails("let &tabstop='ab'", 'E521:')
419  call assert_fails('set spellcapcheck=%\\(', 'E54:')
420  call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
421  call assert_fails('set foldmarker={{{,', 'E474:')
422  call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
423  call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:')
424  set listchars&
425  call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:')
426  set fillchars&
427  call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
428  set nomodifiable
429  call assert_fails('set fileencoding=latin1', 'E21:')
430  set modifiable&
431endfunc
432
433func CheckWasSet(name)
434  let verb_cm = execute('verbose set ' .. a:name .. '?')
435  call assert_match('Last set from.*test_options.vim', verb_cm)
436endfunc
437func CheckWasNotSet(name)
438  let verb_cm = execute('verbose set ' .. a:name .. '?')
439  call assert_notmatch('Last set from', verb_cm)
440endfunc
441
442" Must be executed before other tests that set 'term'.
443func Test_000_term_option_verbose()
444  CheckNotGui
445
446  call CheckWasNotSet('t_cm')
447
448  let term_save = &term
449  set term=ansi
450  call CheckWasSet('t_cm')
451  let &term = term_save
452endfunc
453
454func Test_copy_context()
455  setlocal list
456  call CheckWasSet('list')
457  split
458  call CheckWasSet('list')
459  quit
460  setlocal nolist
461
462  set ai
463  call CheckWasSet('ai')
464  set filetype=perl
465  call CheckWasSet('filetype')
466  set fo=tcroq
467  call CheckWasSet('fo')
468
469  split Xsomebuf
470  call CheckWasSet('ai')
471  call CheckWasNotSet('filetype')
472  call CheckWasSet('fo')
473endfunc
474
475func Test_set_ttytype()
476  CheckUnix
477  CheckNotGui
478
479  " Setting 'ttytype' used to cause a double-free when exiting vim and
480  " when vim is compiled with -DEXITFREE.
481  set ttytype=ansi
482  call assert_equal('ansi', &ttytype)
483  call assert_equal(&ttytype, &term)
484  set ttytype=xterm
485  call assert_equal('xterm', &ttytype)
486  call assert_equal(&ttytype, &term)
487  try
488    set ttytype=
489    call assert_report('set ttytype= did not fail')
490  catch /E529/
491  endtry
492
493  " Some systems accept any terminal name and return dumb settings,
494  " check for failure of finding the entry and for missing 'cm' entry.
495  try
496    set ttytype=xxx
497    call assert_report('set ttytype=xxx did not fail')
498  catch /E522\|E437/
499  endtry
500
501  set ttytype&
502  call assert_equal(&ttytype, &term)
503
504  if has('gui') && !has('gui_running')
505    call assert_fails('set term=gui', 'E531:')
506  endif
507endfunc
508
509func Test_set_all()
510  set tw=75
511  set iskeyword=a-z,A-Z
512  set nosplitbelow
513  let out = execute('set all')
514  call assert_match('textwidth=75', out)
515  call assert_match('iskeyword=a-z,A-Z', out)
516  call assert_match('nosplitbelow', out)
517  set tw& iskeyword& splitbelow&
518endfunc
519
520func Test_set_one_column()
521  let out_mult = execute('set all')->split("\n")
522  let out_one = execute('set! all')->split("\n")
523  call assert_true(len(out_mult) < len(out_one))
524endfunc
525
526func Test_set_values()
527  " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
528  if filereadable('opt_test.vim')
529    source opt_test.vim
530  else
531    throw 'Skipped: opt_test.vim does not exist'
532  endif
533endfunc
534
535func Test_renderoptions()
536  " Only do this for Windows Vista and later, fails on Windows XP and earlier.
537  " Doesn't hurt to do this on a non-Windows system.
538  if windowsversion() !~ '^[345]\.'
539    set renderoptions=type:directx
540    set rop=type:directx
541  endif
542endfunc
543
544func ResetIndentexpr()
545  set indentexpr=
546endfunc
547
548func Test_set_indentexpr()
549  " this was causing usage of freed memory
550  set indentexpr=ResetIndentexpr()
551  new
552  call feedkeys("i\<c-f>", 'x')
553  call assert_equal('', &indentexpr)
554  bwipe!
555endfunc
556
557func Test_backupskip()
558  " Option 'backupskip' may contain several comma-separated path
559  " specifications if one or more of the environment variables TMPDIR, TMP,
560  " or TEMP is defined.  To simplify testing, convert the string value into a
561  " list.
562  let bsklist = split(&bsk, ',')
563
564  if has("mac")
565    let found = (index(bsklist, '/private/tmp/*') >= 0)
566    call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
567  elseif has("unix")
568    let found = (index(bsklist, '/tmp/*') >= 0)
569    call assert_true(found, '/tmp not in option bsk: ' . &bsk)
570  endif
571
572  " If our test platform is Windows, the path(s) in option bsk will use
573  " backslash for the path separator and the components could be in short
574  " (8.3) format.  As such, we need to replace the backslashes with forward
575  " slashes and convert the path components to long format.  The expand()
576  " function will do this but it cannot handle comma-separated paths.  This is
577  " why bsk was converted from a string into a list of strings above.
578  "
579  " One final complication is that the wildcard "/*" is at the end of each
580  " path and so expand() might return a list of matching files.  To prevent
581  " this, we need to remove the wildcard before calling expand() and then
582  " append it afterwards.
583  if has('win32')
584    let item_nbr = 0
585    while item_nbr < len(bsklist)
586      let path_spec = bsklist[item_nbr]
587      let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
588      let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
589      let bsklist[item_nbr] = path_spec . '/*'
590      let item_nbr += 1
591    endwhile
592  endif
593
594  " Option bsk will also include these environment variables if defined.
595  " If they're defined, verify they appear in the option value.
596  for var in  ['$TMPDIR', '$TMP', '$TEMP']
597    if exists(var)
598      let varvalue = substitute(expand(var), '\\', '/', 'g')
599      let varvalue = substitute(varvalue, '/$', '', '')
600      let varvalue .= '/*'
601      let found = (index(bsklist, varvalue) >= 0)
602      call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
603    endif
604  endfor
605
606  " Duplicates from environment variables should be filtered out (option has
607  " P_NODUP).  Run this in a separate instance and write v:errors in a file,
608  " so that we see what happens on startup.
609  let after =<< trim [CODE]
610      let bsklist = split(&backupskip, ',')
611      call assert_equal(uniq(copy(bsklist)), bsklist)
612      call writefile(['errors:'] + v:errors, 'Xtestout')
613      qall
614  [CODE]
615  call writefile(after, 'Xafter')
616  let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
617
618  let saveenv = {}
619  for var in ['TMPDIR', 'TMP', 'TEMP']
620    let saveenv[var] = getenv(var)
621    call setenv(var, '/duplicate/path')
622  endfor
623
624  exe 'silent !' . cmd
625  call assert_equal(['errors:'], readfile('Xtestout'))
626
627  " restore environment variables
628  for var in ['TMPDIR', 'TMP', 'TEMP']
629    call setenv(var, saveenv[var])
630  endfor
631
632  call delete('Xtestout')
633  call delete('Xafter')
634
635  " Duplicates should be filtered out (option has P_NODUP)
636  let backupskip = &backupskip
637  set backupskip=
638  set backupskip+=/test/dir
639  set backupskip+=/other/dir
640  set backupskip+=/test/dir
641  call assert_equal('/test/dir,/other/dir', &backupskip)
642  let &backupskip = backupskip
643endfunc
644
645func Test_copy_winopt()
646  set hidden
647
648  " Test copy option from current buffer in window
649  split
650  enew
651  setlocal numberwidth=5
652  wincmd w
653  call assert_equal(4,&numberwidth)
654  bnext
655  call assert_equal(5,&numberwidth)
656  bw!
657  call assert_equal(4,&numberwidth)
658
659  " Test copy value from window that used to be display the buffer
660  split
661  enew
662  setlocal numberwidth=6
663  bnext
664  wincmd w
665  call assert_equal(4,&numberwidth)
666  bnext
667  call assert_equal(6,&numberwidth)
668  bw!
669
670  " Test that if buffer is current, don't use the stale cached value
671  " from the last time the buffer was displayed.
672  split
673  enew
674  setlocal numberwidth=7
675  bnext
676  bnext
677  setlocal numberwidth=8
678  wincmd w
679  call assert_equal(4,&numberwidth)
680  bnext
681  call assert_equal(8,&numberwidth)
682  bw!
683
684  " Test value is not copied if window already has seen the buffer
685  enew
686  split
687  setlocal numberwidth=9
688  bnext
689  setlocal numberwidth=10
690  wincmd w
691  call assert_equal(4,&numberwidth)
692  bnext
693  call assert_equal(4,&numberwidth)
694  bw!
695
696  set hidden&
697endfunc
698
699func Test_shortmess_F()
700  new
701  call assert_match('\[No Name\]', execute('file'))
702  set shortmess+=F
703  call assert_match('\[No Name\]', execute('file'))
704  call assert_match('^\s*$', execute('file foo'))
705  call assert_match('foo', execute('file'))
706  set shortmess-=F
707  call assert_match('bar', execute('file bar'))
708  call assert_match('bar', execute('file'))
709  set shortmess&
710  bwipe
711endfunc
712
713func Test_shortmess_F2()
714  e file1
715  e file2
716  call assert_match('file1', execute('bn', ''))
717  call assert_match('file2', execute('bn', ''))
718  set shortmess+=F
719  call assert_true(empty(execute('bn', '')))
720  call assert_false(test_getvalue('need_fileinfo'))
721  call assert_true(empty(execute('bn', '')))
722  call assert_false('need_fileinfo'->test_getvalue())
723  set hidden
724  call assert_true(empty(execute('bn', '')))
725  call assert_false(test_getvalue('need_fileinfo'))
726  call assert_true(empty(execute('bn', '')))
727  call assert_false(test_getvalue('need_fileinfo'))
728  set nohidden
729  call assert_true(empty(execute('bn', '')))
730  call assert_false(test_getvalue('need_fileinfo'))
731  call assert_true(empty(execute('bn', '')))
732  call assert_false(test_getvalue('need_fileinfo'))
733  set shortmess&
734  call assert_match('file1', execute('bn', ''))
735  call assert_match('file2', execute('bn', ''))
736  bwipe
737  bwipe
738endfunc
739
740func Test_local_scrolloff()
741  set so=5
742  set siso=7
743  split
744  call assert_equal(5, &so)
745  setlocal so=3
746  call assert_equal(3, &so)
747  wincmd w
748  call assert_equal(5, &so)
749  wincmd w
750  setlocal so<
751  call assert_equal(5, &so)
752  setlocal so=0
753  call assert_equal(0, &so)
754  setlocal so=-1
755  call assert_equal(5, &so)
756
757  call assert_equal(7, &siso)
758  setlocal siso=3
759  call assert_equal(3, &siso)
760  wincmd w
761  call assert_equal(7, &siso)
762  wincmd w
763  setlocal siso<
764  call assert_equal(7, &siso)
765  setlocal siso=0
766  call assert_equal(0, &siso)
767  setlocal siso=-1
768  call assert_equal(7, &siso)
769
770  close
771  set so&
772  set siso&
773endfunc
774
775func Test_writedelay()
776  CheckFunction reltimefloat
777
778  new
779  call setline(1, 'empty')
780  redraw
781  set writedelay=10
782  let start = reltime()
783  call setline(1, repeat('x', 70))
784  redraw
785  let elapsed = reltimefloat(reltime(start))
786  set writedelay=0
787  " With 'writedelay' set should take at least 30 * 10 msec
788  call assert_inrange(30 * 0.01, 999.0, elapsed)
789
790  bwipe!
791endfunc
792
793func Test_visualbell()
794  set belloff=
795  set visualbell
796  call assert_beeps('normal 0h')
797  set novisualbell
798  set belloff=all
799endfunc
800
801" Test for the 'write' option
802func Test_write()
803  new
804  call setline(1, ['L1'])
805  set nowrite
806  call assert_fails('write Xfile', 'E142:')
807  set write
808  close!
809endfunc
810
811" Test for 'buftype' option
812func Test_buftype()
813  new
814  call setline(1, ['L1'])
815  set buftype=nowrite
816  call assert_fails('write', 'E382:')
817
818  for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
819    exe 'set buftype=' .. val
820    call writefile(['something'], 'XBuftype')
821    call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
822  endfor
823
824  call delete('XBuftype')
825  bwipe!
826endfunc
827
828" Test for the 'shell' option
829func Test_shell()
830  CheckUnix
831  let save_shell = &shell
832  set shell=
833  let caught_e91 = 0
834  try
835    shell
836  catch /E91:/
837    let caught_e91 = 1
838  endtry
839  call assert_equal(1, caught_e91)
840  let &shell = save_shell
841endfunc
842
843" Test for the 'shellquote' option
844func Test_shellquote()
845  CheckUnix
846  set shellquote=#
847  set verbose=20
848  redir => v
849  silent! !echo Hello
850  redir END
851  set verbose&
852  set shellquote&
853  call assert_match(': "#echo Hello#"', v)
854endfunc
855
856" Test for the 'rightleftcmd' option
857func Test_rightleftcmd()
858  CheckFeature rightleft
859  set rightleft
860  set rightleftcmd
861
862  let g:l = []
863  func AddPos()
864    call add(g:l, screencol())
865    return ''
866  endfunc
867  cmap <expr> <F2> AddPos()
868
869  call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
870        \ "\<Left>\<F2>\<Esc>", 'xt')
871  call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
872
873  cunmap <F2>
874  unlet g:l
875  set rightleftcmd&
876  set rightleft&
877endfunc
878
879" Test for the "debug" option
880func Test_debug_option()
881  set debug=beep
882  exe "normal \<C-c>"
883  call assert_equal('Beep!', Screenline(&lines))
884  set debug&
885endfunc
886
887" Test for the default CDPATH option
888func Test_opt_default_cdpath()
889  CheckFeature file_in_path
890  let after =<< trim [CODE]
891    call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
892    call writefile(v:errors, 'Xtestout')
893    qall
894  [CODE]
895  if has('unix')
896    let $CDPATH='/path/to/dir1:/path/to/dir2'
897  else
898    let $CDPATH='/path/to/dir1;/path/to/dir2'
899  endif
900  if RunVim([], after, '')
901    call assert_equal([], readfile('Xtestout'))
902    call delete('Xtestout')
903  endif
904endfunc
905
906" Test for setting keycodes using set
907func Test_opt_set_keycode()
908  call assert_fails('set <t_k1=l', 'E474:')
909  call assert_fails('set <Home=l', 'E474:')
910  set <t_k9>=abcd
911  call assert_equal('abcd', &t_k9)
912  set <t_k9>&
913  set <F9>=xyz
914  call assert_equal('xyz', &t_k9)
915  set <t_k9>&
916endfunc
917
918" Test for changing options in a sandbox
919func Test_opt_sandbox()
920  for opt in ['backupdir', 'cdpath', 'exrc']
921    call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
922    call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
923  endfor
924  call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
925endfunc
926
927" Test for setting an option with local value to global value
928func Test_opt_local_to_global()
929  setglobal equalprg=gprg
930  setlocal equalprg=lprg
931  call assert_equal('gprg', &g:equalprg)
932  call assert_equal('lprg', &l:equalprg)
933  call assert_equal('lprg', &equalprg)
934  set equalprg<
935  call assert_equal('', &l:equalprg)
936  call assert_equal('gprg', &equalprg)
937  setglobal equalprg=gnewprg
938  setlocal equalprg=lnewprg
939  setlocal equalprg<
940  call assert_equal('gnewprg', &l:equalprg)
941  call assert_equal('gnewprg', &equalprg)
942  set equalprg&
943endfunc
944
945" Test for incrementing, decrementing and multiplying a number option value
946func Test_opt_num_op()
947  set shiftwidth=4
948  set sw+=2
949  call assert_equal(6, &sw)
950  set sw-=2
951  call assert_equal(4, &sw)
952  set sw^=2
953  call assert_equal(8, &sw)
954  set shiftwidth&
955endfunc
956
957" Test for setting option values using v:false and v:true
958func Test_opt_boolean()
959  set number&
960  set number
961  call assert_equal(1, &nu)
962  set nonu
963  call assert_equal(0, &nu)
964  let &nu = v:true
965  call assert_equal(1, &nu)
966  let &nu = v:false
967  call assert_equal(0, &nu)
968  set number&
969endfunc
970
971" Test for the 'window' option
972func Test_window_opt()
973  " Needs only one open widow
974  %bw!
975  call setline(1, range(1, 8))
976  set window=5
977  exe "normal \<C-F>"
978  call assert_equal(4, line('w0'))
979  exe "normal \<C-F>"
980  call assert_equal(7, line('w0'))
981  exe "normal \<C-F>"
982  call assert_equal(8, line('w0'))
983  exe "normal \<C-B>"
984  call assert_equal(5, line('w0'))
985  exe "normal \<C-B>"
986  call assert_equal(2, line('w0'))
987  exe "normal \<C-B>"
988  call assert_equal(1, line('w0'))
989  set window=1
990  exe "normal gg\<C-F>"
991  call assert_equal(2, line('w0'))
992  exe "normal \<C-F>"
993  call assert_equal(3, line('w0'))
994  exe "normal \<C-B>"
995  call assert_equal(2, line('w0'))
996  exe "normal \<C-B>"
997  call assert_equal(1, line('w0'))
998  enew!
999  set window&
1000endfunc
1001
1002" Test for the 'winminheight' option
1003func Test_opt_winminheight()
1004  only!
1005  let &winheight = &lines + 4
1006  call assert_fails('let &winminheight = &lines + 2', 'E36:')
1007  call assert_true(&winminheight <= &lines)
1008  set winminheight&
1009  set winheight&
1010endfunc
1011
1012" Test for the 'winminwidth' option
1013func Test_opt_winminwidth()
1014  only!
1015  let &winwidth = &columns + 4
1016  call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1017  call assert_true(&winminwidth <= &columns)
1018  set winminwidth&
1019  set winwidth&
1020endfunc
1021
1022" Test for setting option value containing spaces with isfname+=32
1023func Test_isfname_with_options()
1024  set isfname+=32
1025  setlocal keywordprg=:term\ help.exe
1026  call assert_equal(':term help.exe', &keywordprg)
1027  set isfname&
1028  setlocal keywordprg&
1029endfunc
1030
1031" Test that resetting laststatus does change scroll option
1032func Test_opt_reset_scroll()
1033  CheckRunVimInTerminal
1034  let vimrc =<< trim [CODE]
1035    set scroll=2
1036    set laststatus=2
1037  [CODE]
1038  call writefile(vimrc, 'Xscroll')
1039  let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1040  call term_sendkeys(buf, ":verbose set scroll?\n")
1041  call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1042  call assert_match('^\s*scroll=7$', term_getline(buf, 14))
1043  call StopVimInTerminal(buf)
1044
1045  " clean up
1046  call delete('Xscroll')
1047endfunc
1048
1049" vim: shiftwidth=2 sts=2 expandtab
1050