xref: /vim-8.2.3635/src/testdir/test_options.vim (revision 2d2970ea)
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  call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
273
274  " Expand directories.
275  call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
276  call assert_match(' ./samples/ ', @:)
277  call assert_notmatch(' ./small.vim ', @:)
278
279  " Expand files and directories.
280  call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
281  call assert_match(' ./samples/.* ./small.vim', @:)
282
283  call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
284  call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
285  set tags&
286
287  " Expanding the option names
288  call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
289  call assert_equal('"set all', @:)
290
291  " Expanding a second set of option names
292  call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
293  call assert_equal('"set wrapscan all', @:)
294
295  " Expanding a special keycode
296  call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
297  call assert_equal('"set <Home>', @:)
298
299  " Expanding an invalid special keycode
300  call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
301  call assert_equal("\"set <abcd>\<Tab>", @:)
302
303  " Expanding a terminal keycode
304  call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
305  call assert_equal("\"set t_AB", @:)
306
307  " Expanding an invalid option name
308  call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
309  call assert_equal("\"set abcde=\<Tab>", @:)
310
311  " Expanding after a = for a boolean option
312  call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
313  call assert_equal("\"set wrapscan=\<Tab>", @:)
314
315  " Expanding a numeric option
316  call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
317  call assert_equal("\"set tabstop+=" .. &tabstop, @:)
318
319  " Expanding a non-boolean option
320  call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
321  call assert_equal("\"set invtabstop=", @:)
322
323  " Expand options for 'spellsuggest'
324  call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
325  call assert_equal("\"set spellsuggest=best,file:xyz", @:)
326
327  " Expand value for 'key'
328  set key=abcd
329  call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
330  call assert_equal('"set key=*****', @:)
331  set key=
332endfunc
333
334func Test_set_errors()
335  call assert_fails('set scroll=-1', 'E49:')
336  call assert_fails('set backupcopy=', 'E474:')
337  call assert_fails('set regexpengine=3', 'E474:')
338  call assert_fails('set history=10001', 'E474:')
339  call assert_fails('set numberwidth=21', 'E474:')
340  call assert_fails('set colorcolumn=-a', 'E474:')
341  call assert_fails('set colorcolumn=a', 'E474:')
342  call assert_fails('set colorcolumn=1,', 'E474:')
343  call assert_fails('set colorcolumn=1;', 'E474:')
344  call assert_fails('set cmdheight=-1', 'E487:')
345  call assert_fails('set cmdwinheight=-1', 'E487:')
346  if has('conceal')
347    call assert_fails('set conceallevel=-1', 'E487:')
348    call assert_fails('set conceallevel=4', 'E474:')
349  endif
350  call assert_fails('set helpheight=-1', 'E487:')
351  call assert_fails('set history=-1', 'E487:')
352  call assert_fails('set report=-1', 'E487:')
353  call assert_fails('set shiftwidth=-1', 'E487:')
354  call assert_fails('set sidescroll=-1', 'E487:')
355  call assert_fails('set tabstop=-1', 'E487:')
356  call assert_fails('set textwidth=-1', 'E487:')
357  call assert_fails('set timeoutlen=-1', 'E487:')
358  call assert_fails('set updatecount=-1', 'E487:')
359  call assert_fails('set updatetime=-1', 'E487:')
360  call assert_fails('set winheight=-1', 'E487:')
361  call assert_fails('set tabstop!', 'E488:')
362  call assert_fails('set xxx', 'E518:')
363  call assert_fails('set beautify?', 'E519:')
364  call assert_fails('set undolevels=x', 'E521:')
365  call assert_fails('set tabstop=', 'E521:')
366  call assert_fails('set comments=-', 'E524:')
367  call assert_fails('set comments=a', 'E525:')
368  call assert_fails('set foldmarker=x', 'E536:')
369  call assert_fails('set commentstring=x', 'E537:')
370  call assert_fails('set complete=x', 'E539:')
371  call assert_fails('set statusline=%{', 'E540:')
372  call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
373  call assert_fails('set statusline=%(', 'E542:')
374  if has('cursorshape')
375    " This invalid value for 'guicursor' used to cause Vim to crash.
376    call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
377    call assert_fails('set guicursor=i-ci', 'E545:')
378    call assert_fails('set guicursor=x', 'E545:')
379    call assert_fails('set guicursor=x:', 'E546:')
380    call assert_fails('set guicursor=r-cr:horx', 'E548:')
381    call assert_fails('set guicursor=r-cr:hor0', 'E549:')
382  endif
383  if has('mouseshape')
384    call assert_fails('se mouseshape=i-r:x', 'E547:')
385  endif
386  call assert_fails('set backupext=~ patchmode=~', 'E589:')
387  call assert_fails('set winminheight=10 winheight=9', 'E591:')
388  set winminheight& winheight&
389  set winheight=10 winminheight=10
390  call assert_fails('set winheight=9', 'E591:')
391  set winminheight& winheight&
392  call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
393  set winminwidth& winwidth&
394  call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
395  set winwidth& winminwidth&
396  call assert_fails("set showbreak=\x01", 'E595:')
397  call assert_fails('set t_foo=', 'E846:')
398  call assert_fails('set tabstop??', 'E488:')
399  call assert_fails('set wrapscan!!', 'E488:')
400  call assert_fails('set tabstop&&', 'E488:')
401  call assert_fails('set wrapscan<<', 'E488:')
402  call assert_fails('set wrapscan=1', 'E474:')
403  call assert_fails('set autoindent@', 'E488:')
404  call assert_fails('set wildchar=<abc>', 'E474:')
405  call assert_fails('set cmdheight=1a', 'E521:')
406  call assert_fails('set invcmdheight', 'E474:')
407  if has('python') && has('python3')
408    call assert_fails('set pyxversion=6', 'E474:')
409  endif
410  call assert_fails("let &tabstop='ab'", 'E521:')
411endfunc
412
413func CheckWasSet(name)
414  let verb_cm = execute('verbose set ' .. a:name .. '?')
415  call assert_match('Last set from.*test_options.vim', verb_cm)
416endfunc
417func CheckWasNotSet(name)
418  let verb_cm = execute('verbose set ' .. a:name .. '?')
419  call assert_notmatch('Last set from', verb_cm)
420endfunc
421
422" Must be executed before other tests that set 'term'.
423func Test_000_term_option_verbose()
424  CheckNotGui
425
426  call CheckWasNotSet('t_cm')
427
428  let term_save = &term
429  set term=ansi
430  call CheckWasSet('t_cm')
431  let &term = term_save
432endfunc
433
434func Test_copy_context()
435  setlocal list
436  call CheckWasSet('list')
437  split
438  call CheckWasSet('list')
439  quit
440  setlocal nolist
441
442  set ai
443  call CheckWasSet('ai')
444  set filetype=perl
445  call CheckWasSet('filetype')
446  set fo=tcroq
447  call CheckWasSet('fo')
448
449  split Xsomebuf
450  call CheckWasSet('ai')
451  call CheckWasNotSet('filetype')
452  call CheckWasSet('fo')
453endfunc
454
455func Test_set_ttytype()
456  CheckUnix
457  CheckNotGui
458
459  " Setting 'ttytype' used to cause a double-free when exiting vim and
460  " when vim is compiled with -DEXITFREE.
461  set ttytype=ansi
462  call assert_equal('ansi', &ttytype)
463  call assert_equal(&ttytype, &term)
464  set ttytype=xterm
465  call assert_equal('xterm', &ttytype)
466  call assert_equal(&ttytype, &term)
467  " "set ttytype=" gives E522 instead of E529
468  " in travis on some builds. Why?  Catch both for now
469  try
470    set ttytype=
471    call assert_report('set ttytype= did not fail')
472  catch /E529\|E522/
473  endtry
474
475  " Some systems accept any terminal name and return dumb settings,
476  " check for failure of finding the entry and for missing 'cm' entry.
477  try
478    set ttytype=xxx
479    call assert_report('set ttytype=xxx did not fail')
480  catch /E522\|E437/
481  endtry
482
483  set ttytype&
484  call assert_equal(&ttytype, &term)
485
486  if has('gui') && !has('gui_running')
487    call assert_fails('set term=gui', 'E531:')
488  endif
489endfunc
490
491func Test_set_all()
492  set tw=75
493  set iskeyword=a-z,A-Z
494  set nosplitbelow
495  let out = execute('set all')
496  call assert_match('textwidth=75', out)
497  call assert_match('iskeyword=a-z,A-Z', out)
498  call assert_match('nosplitbelow', out)
499  set tw& iskeyword& splitbelow&
500endfunc
501
502func Test_set_one_column()
503  let out_mult = execute('set all')->split("\n")
504  let out_one = execute('set! all')->split("\n")
505  call assert_true(len(out_mult) < len(out_one))
506endfunc
507
508func Test_set_values()
509  if filereadable('opt_test.vim')
510    source opt_test.vim
511  else
512    throw 'Skipped: opt_test.vim does not exist'
513  endif
514endfunc
515
516func Test_renderoptions()
517  " Only do this for Windows Vista and later, fails on Windows XP and earlier.
518  " Doesn't hurt to do this on a non-Windows system.
519  if windowsversion() !~ '^[345]\.'
520    set renderoptions=type:directx
521    set rop=type:directx
522  endif
523endfunc
524
525func ResetIndentexpr()
526  set indentexpr=
527endfunc
528
529func Test_set_indentexpr()
530  " this was causing usage of freed memory
531  set indentexpr=ResetIndentexpr()
532  new
533  call feedkeys("i\<c-f>", 'x')
534  call assert_equal('', &indentexpr)
535  bwipe!
536endfunc
537
538func Test_backupskip()
539  " Option 'backupskip' may contain several comma-separated path
540  " specifications if one or more of the environment variables TMPDIR, TMP,
541  " or TEMP is defined.  To simplify testing, convert the string value into a
542  " list.
543  let bsklist = split(&bsk, ',')
544
545  if has("mac")
546    let found = (index(bsklist, '/private/tmp/*') >= 0)
547    call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
548  elseif has("unix")
549    let found = (index(bsklist, '/tmp/*') >= 0)
550    call assert_true(found, '/tmp not in option bsk: ' . &bsk)
551  endif
552
553  " If our test platform is Windows, the path(s) in option bsk will use
554  " backslash for the path separator and the components could be in short
555  " (8.3) format.  As such, we need to replace the backslashes with forward
556  " slashes and convert the path components to long format.  The expand()
557  " function will do this but it cannot handle comma-separated paths.  This is
558  " why bsk was converted from a string into a list of strings above.
559  "
560  " One final complication is that the wildcard "/*" is at the end of each
561  " path and so expand() might return a list of matching files.  To prevent
562  " this, we need to remove the wildcard before calling expand() and then
563  " append it afterwards.
564  if has('win32')
565    let item_nbr = 0
566    while item_nbr < len(bsklist)
567      let path_spec = bsklist[item_nbr]
568      let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
569      let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
570      let bsklist[item_nbr] = path_spec . '/*'
571      let item_nbr += 1
572    endwhile
573  endif
574
575  " Option bsk will also include these environment variables if defined.
576  " If they're defined, verify they appear in the option value.
577  for var in  ['$TMPDIR', '$TMP', '$TEMP']
578    if exists(var)
579      let varvalue = substitute(expand(var), '\\', '/', 'g')
580      let varvalue = substitute(varvalue, '/$', '', '')
581      let varvalue .= '/*'
582      let found = (index(bsklist, varvalue) >= 0)
583      call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
584    endif
585  endfor
586
587  " Duplicates should be filtered out (option has P_NODUP)
588  let backupskip = &backupskip
589  set backupskip=
590  set backupskip+=/test/dir
591  set backupskip+=/other/dir
592  set backupskip+=/test/dir
593  call assert_equal('/test/dir,/other/dir', &backupskip)
594  let &backupskip = backupskip
595endfunc
596
597func Test_copy_winopt()
598  set hidden
599
600  " Test copy option from current buffer in window
601  split
602  enew
603  setlocal numberwidth=5
604  wincmd w
605  call assert_equal(4,&numberwidth)
606  bnext
607  call assert_equal(5,&numberwidth)
608  bw!
609  call assert_equal(4,&numberwidth)
610
611  " Test copy value from window that used to be display the buffer
612  split
613  enew
614  setlocal numberwidth=6
615  bnext
616  wincmd w
617  call assert_equal(4,&numberwidth)
618  bnext
619  call assert_equal(6,&numberwidth)
620  bw!
621
622  " Test that if buffer is current, don't use the stale cached value
623  " from the last time the buffer was displayed.
624  split
625  enew
626  setlocal numberwidth=7
627  bnext
628  bnext
629  setlocal numberwidth=8
630  wincmd w
631  call assert_equal(4,&numberwidth)
632  bnext
633  call assert_equal(8,&numberwidth)
634  bw!
635
636  " Test value is not copied if window already has seen the buffer
637  enew
638  split
639  setlocal numberwidth=9
640  bnext
641  setlocal numberwidth=10
642  wincmd w
643  call assert_equal(4,&numberwidth)
644  bnext
645  call assert_equal(4,&numberwidth)
646  bw!
647
648  set hidden&
649endfunc
650
651func Test_shortmess_F()
652  new
653  call assert_match('\[No Name\]', execute('file'))
654  set shortmess+=F
655  call assert_match('\[No Name\]', execute('file'))
656  call assert_match('^\s*$', execute('file foo'))
657  call assert_match('foo', execute('file'))
658  set shortmess-=F
659  call assert_match('bar', execute('file bar'))
660  call assert_match('bar', execute('file'))
661  set shortmess&
662  bwipe
663endfunc
664
665func Test_shortmess_F2()
666  e file1
667  e file2
668  call assert_match('file1', execute('bn', ''))
669  call assert_match('file2', execute('bn', ''))
670  set shortmess+=F
671  call assert_true(empty(execute('bn', '')))
672  call assert_false(test_getvalue('need_fileinfo'))
673  call assert_true(empty(execute('bn', '')))
674  call assert_false('need_fileinfo'->test_getvalue())
675  set hidden
676  call assert_true(empty(execute('bn', '')))
677  call assert_false(test_getvalue('need_fileinfo'))
678  call assert_true(empty(execute('bn', '')))
679  call assert_false(test_getvalue('need_fileinfo'))
680  set nohidden
681  call assert_true(empty(execute('bn', '')))
682  call assert_false(test_getvalue('need_fileinfo'))
683  call assert_true(empty(execute('bn', '')))
684  call assert_false(test_getvalue('need_fileinfo'))
685  set shortmess&
686  call assert_match('file1', execute('bn', ''))
687  call assert_match('file2', execute('bn', ''))
688  bwipe
689  bwipe
690endfunc
691
692func Test_local_scrolloff()
693  set so=5
694  set siso=7
695  split
696  call assert_equal(5, &so)
697  setlocal so=3
698  call assert_equal(3, &so)
699  wincmd w
700  call assert_equal(5, &so)
701  wincmd w
702  setlocal so<
703  call assert_equal(5, &so)
704  setlocal so=0
705  call assert_equal(0, &so)
706  setlocal so=-1
707  call assert_equal(5, &so)
708
709  call assert_equal(7, &siso)
710  setlocal siso=3
711  call assert_equal(3, &siso)
712  wincmd w
713  call assert_equal(7, &siso)
714  wincmd w
715  setlocal siso<
716  call assert_equal(7, &siso)
717  setlocal siso=0
718  call assert_equal(0, &siso)
719  setlocal siso=-1
720  call assert_equal(7, &siso)
721
722  close
723  set so&
724  set siso&
725endfunc
726
727func Test_writedelay()
728  CheckFunction reltimefloat
729
730  new
731  call setline(1, 'empty')
732  redraw
733  set writedelay=10
734  let start = reltime()
735  call setline(1, repeat('x', 70))
736  redraw
737  let elapsed = reltimefloat(reltime(start))
738  set writedelay=0
739  " With 'writedelay' set should take at least 30 * 10 msec
740  call assert_inrange(30 * 0.01, 999.0, elapsed)
741
742  bwipe!
743endfunc
744
745func Test_visualbell()
746  set belloff=
747  set visualbell
748  call assert_beeps('normal 0h')
749  set novisualbell
750  set belloff=all
751endfunc
752
753" Test for the 'write' option
754func Test_write()
755  new
756  call setline(1, ['L1'])
757  set nowrite
758  call assert_fails('write Xfile', 'E142:')
759  set write
760  close!
761endfunc
762
763" Test for 'buftype' option
764func Test_buftype()
765  new
766  call setline(1, ['L1'])
767  set buftype=nowrite
768  call assert_fails('write', 'E382:')
769
770  for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
771    exe 'set buftype=' .. val
772    call writefile(['something'], 'XBuftype')
773    call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
774  endfor
775
776  call delete('XBuftype')
777  bwipe!
778endfunc
779
780" Test for the 'shell' option
781func Test_shell()
782  CheckUnix
783  let save_shell = &shell
784  set shell=
785  call assert_fails('shell', 'E91:')
786  let &shell = save_shell
787endfunc
788
789" Test for the 'shellquote' option
790func Test_shellquote()
791  CheckUnix
792  set shellquote=#
793  set verbose=20
794  redir => v
795  silent! !echo Hello
796  redir END
797  set verbose&
798  set shellquote&
799  call assert_match(': "#echo Hello#"', v)
800endfunc
801
802" Test for the 'rightleftcmd' option
803func Test_rightleftcmd()
804  CheckFeature rightleft
805  set rightleft
806  set rightleftcmd
807
808  let g:l = []
809  func AddPos()
810    call add(g:l, screencol())
811    return ''
812  endfunc
813  cmap <expr> <F2> AddPos()
814
815  call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
816        \ "\<Left>\<F2>\<Esc>", 'xt')
817  call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
818
819  cunmap <F2>
820  unlet g:l
821  set rightleftcmd&
822  set rightleft&
823endfunc
824
825" Test for the "debug" option
826func Test_debug_option()
827  set debug=beep
828  exe "normal \<C-c>"
829  call assert_equal('Beep!', Screenline(&lines))
830  set debug&
831endfunc
832
833" Test for the default CDPATH option
834func Test_opt_default_cdpath()
835  CheckFeature file_in_path
836  let after =<< trim [CODE]
837    call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
838    call writefile(v:errors, 'Xtestout')
839    qall
840  [CODE]
841  if has('unix')
842    let $CDPATH='/path/to/dir1:/path/to/dir2'
843  else
844    let $CDPATH='/path/to/dir1;/path/to/dir2'
845  endif
846  if RunVim([], after, '')
847    call assert_equal([], readfile('Xtestout'))
848    call delete('Xtestout')
849  endif
850endfunc
851
852" Test for setting keycodes using set
853func Test_opt_set_keycode()
854  call assert_fails('set <t_k1=l', 'E474:')
855  call assert_fails('set <Home=l', 'E474:')
856  set <t_k9>=abcd
857  call assert_equal('abcd', &t_k9)
858  set <t_k9>&
859  set <F9>=xyz
860  call assert_equal('xyz', &t_k9)
861  set <t_k9>&
862endfunc
863
864" Test for changing options in a sandbox
865func Test_opt_sandbox()
866  for opt in ['backupdir', 'cdpath', 'exrc']
867    call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
868    call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
869  endfor
870  call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
871endfunc
872
873" Test for setting an option with local value to global value
874func Test_opt_local_to_global()
875  setglobal equalprg=gprg
876  setlocal equalprg=lprg
877  call assert_equal('gprg', &g:equalprg)
878  call assert_equal('lprg', &l:equalprg)
879  call assert_equal('lprg', &equalprg)
880  set equalprg<
881  call assert_equal('', &l:equalprg)
882  call assert_equal('gprg', &equalprg)
883  setglobal equalprg=gnewprg
884  setlocal equalprg=lnewprg
885  setlocal equalprg<
886  call assert_equal('gnewprg', &l:equalprg)
887  call assert_equal('gnewprg', &equalprg)
888  set equalprg&
889endfunc
890
891" Test for incrementing, decrementing and multiplying a number option value
892func Test_opt_num_op()
893  set shiftwidth=4
894  set sw+=2
895  call assert_equal(6, &sw)
896  set sw-=2
897  call assert_equal(4, &sw)
898  set sw^=2
899  call assert_equal(8, &sw)
900  set shiftwidth&
901endfunc
902
903" Test for setting option values using v:false and v:true
904func Test_opt_boolean()
905  set number&
906  set number
907  call assert_equal(1, &nu)
908  set nonu
909  call assert_equal(0, &nu)
910  let &nu = v:true
911  call assert_equal(1, &nu)
912  let &nu = v:false
913  call assert_equal(0, &nu)
914  set number&
915endfunc
916
917" vim: shiftwidth=2 sts=2 expandtab
918