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