blob: f5e0e9b143e6cc2301adad570845c169386ffa62 [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
4
Bram Moolenaar1e115362019-01-09 23:01:02 +01005func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02006 set whichwrap=b,s
7 call assert_equal('b,s', &whichwrap)
8
9 set whichwrap+=h,l
10 call assert_equal('b,s,h,l', &whichwrap)
11
12 set whichwrap+=h,l
13 call assert_equal('b,s,h,l', &whichwrap)
14
15 set whichwrap+=h,l
16 call assert_equal('b,s,h,l', &whichwrap)
17
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010018 set whichwrap=h,h
19 call assert_equal('h', &whichwrap)
20
21 set whichwrap=h,h,h
22 call assert_equal('h', &whichwrap)
23
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020024 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010025endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020026
Bram Moolenaar1e115362019-01-09 23:01:02 +010027func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010028 " This used to cause Vim to access uninitialized memory.
29 set isfname=
30 call assert_equal("~X", expand("~X"))
31 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010032endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010033
Bram Moolenaar1e115362019-01-09 23:01:02 +010034func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010035 " Empty 'wildchar' used to access invalid memory.
36 call assert_fails('set wildchar=', 'E521:')
37 call assert_fails('set wildchar=abc', 'E521:')
38 set wildchar=<Esc>
39 let a=execute('set wildchar?')
40 call assert_equal("\n wildchar=<Esc>", a)
41 set wildchar=27
42 let a=execute('set wildchar?')
43 call assert_equal("\n wildchar=<Esc>", a)
44 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010045endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010046
Bram Moolenaar6b915c02020-01-18 15:53:19 +010047func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020048 let caught = 'ok'
49 try
50 options
51 catch
52 let caught = v:throwpoint . "\n" . v:exception
53 endtry
54 call assert_equal('ok', caught)
55
Bram Moolenaare0b59492019-05-21 20:54:45 +020056 " Check if the option-window is opened horizontally.
57 wincmd j
58 call assert_notequal('option-window', bufname(''))
59 wincmd k
60 call assert_equal('option-window', bufname(''))
61 " close option-window
62 close
63
64 " Open the option-window vertically.
65 vert options
66 " Check if the option-window is opened vertically.
67 wincmd l
68 call assert_notequal('option-window', bufname(''))
69 wincmd h
70 call assert_equal('option-window', bufname(''))
71 " close option-window
72 close
73
74 " Open the option-window in a new tab.
75 tab options
76 " Check if the option-window is opened in a tab.
77 normal gT
78 call assert_notequal('option-window', bufname(''))
79 normal gt
80 call assert_equal('option-window', bufname(''))
81
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020082 " close option-window
83 close
Bram Moolenaar1e115362019-01-09 23:01:02 +010084endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020085
Bram Moolenaar1e115362019-01-09 23:01:02 +010086func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020087 " Test that changing 'path' keeps two commas.
88 set path=foo,,bar
89 set path-=bar
90 set path+=bar
91 call assert_equal('foo,,bar', &path)
92
93 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +010094endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020095
96func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +020097 if has('signs')
98 call assert_equal("auto", &signcolumn)
99 set signcolumn=yes
100 set signcolumn=no
101 call assert_fails('set signcolumn=nope')
102 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200103endfunc
104
Bram Moolenaard0b51382016-11-04 15:23:45 +0100105func Test_filetype_valid()
106 set ft=valid_name
107 call assert_equal("valid_name", &filetype)
108 set ft=valid-name
109 call assert_equal("valid-name", &filetype)
110
111 call assert_fails(":set ft=wrong;name", "E474:")
112 call assert_fails(":set ft=wrong\\\\name", "E474:")
113 call assert_fails(":set ft=wrong\\|name", "E474:")
114 call assert_fails(":set ft=wrong/name", "E474:")
115 call assert_fails(":set ft=wrong\\\nname", "E474:")
116 call assert_equal("valid-name", &filetype)
117
118 exe "set ft=trunc\x00name"
119 call assert_equal("trunc", &filetype)
120endfunc
121
122func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100123 if !has('syntax')
124 return
125 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100126 set syn=valid_name
127 call assert_equal("valid_name", &syntax)
128 set syn=valid-name
129 call assert_equal("valid-name", &syntax)
130
131 call assert_fails(":set syn=wrong;name", "E474:")
132 call assert_fails(":set syn=wrong\\\\name", "E474:")
133 call assert_fails(":set syn=wrong\\|name", "E474:")
134 call assert_fails(":set syn=wrong/name", "E474:")
135 call assert_fails(":set syn=wrong\\\nname", "E474:")
136 call assert_equal("valid-name", &syntax)
137
138 exe "set syn=trunc\x00name"
139 call assert_equal("trunc", &syntax)
140endfunc
141
142func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100143 if !has('keymap')
144 return
145 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100146 call assert_fails(":set kmp=valid_name", "E544:")
147 call assert_fails(":set kmp=valid_name", "valid_name")
148 call assert_fails(":set kmp=valid-name", "E544:")
149 call assert_fails(":set kmp=valid-name", "valid-name")
150
151 call assert_fails(":set kmp=wrong;name", "E474:")
152 call assert_fails(":set kmp=wrong\\\\name", "E474:")
153 call assert_fails(":set kmp=wrong\\|name", "E474:")
154 call assert_fails(":set kmp=wrong/name", "E474:")
155 call assert_fails(":set kmp=wrong\\\nname", "E474:")
156
157 call assert_fails(":set kmp=trunc\x00name", "E544:")
158 call assert_fails(":set kmp=trunc\x00name", "trunc")
159endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100160
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100161func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100162 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100163 exe 'set ' . a:name . '=/usr/share/dict/words'
164 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
165 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
166 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
167 exe 'set ' . a:name . '=/usr/share/dict\ words'
168 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100169
170 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100171 call assert_fails("set " . a:name . "=/not&there", "E474:")
172 call assert_fails("set " . a:name . "=/not>there", "E474:")
173 call assert_fails("set " . a:name . "=/not.*there", "E474:")
174endfunc
175
Bram Moolenaar60629d62017-02-23 18:08:56 +0100176func Test_cinkeys()
177 " This used to cause invalid memory access
178 set cindent cinkeys=0
179 norm a
180 set cindent& cinkeys&
181endfunc
182
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100183func Test_dictionary()
184 call Check_dir_option('dictionary')
185endfunc
186
187func Test_thesaurus()
188 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100189endfun
190
Bram Moolenaar226c5342017-02-17 14:53:15 +0100191func Test_complete()
192 " Trailing single backslash used to cause invalid memory access.
193 set complete=s\
194 new
195 call feedkeys("i\<C-N>\<Esc>", 'xt')
196 bwipe!
197 set complete&
198endfun
199
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100200func Test_set_completion()
201 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
202 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
203
Bram Moolenaar297610b2019-12-27 17:20:55 +0100204 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
205 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
206
207 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
208 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
209
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100210 " Expand boolan options. When doing :set no<Tab>
211 " vim displays the options names without "no" but completion uses "no...".
212 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
213 call assert_equal('"set nodiff digraph', @:)
214
215 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
216 call assert_equal('"set invdiff digraph', @:)
217
218 " Expand abbreviation of options.
219 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
220 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
221
222 " Expand current value
223 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
224 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
225
226 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
227 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
228
229 " Expand key codes.
230 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
231 call assert_equal('"set <Help> <Home>', @:)
232
233 " Expand terminal options.
234 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
235 call assert_equal('"set t_AB t_AF t_AL', @:)
236
237 " Expand directories.
238 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
239 call assert_match(' ./samples/ ', @:)
240 call assert_notmatch(' ./small.vim ', @:)
241
242 " Expand files and directories.
243 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
244 call assert_match(' ./samples/.* ./small.vim', @:)
245
246 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
247 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100248
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200249 set tags&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100250endfunc
251
252func Test_set_errors()
253 call assert_fails('set scroll=-1', 'E49:')
254 call assert_fails('set backupcopy=', 'E474:')
255 call assert_fails('set regexpengine=3', 'E474:')
256 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200257 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100258 call assert_fails('set colorcolumn=-a', 'E474:')
259 call assert_fails('set colorcolumn=a', 'E474:')
260 call assert_fails('set colorcolumn=1,', 'E474:')
261 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100262 call assert_fails('set cmdheight=-1', 'E487:')
263 call assert_fails('set cmdwinheight=-1', 'E487:')
264 if has('conceal')
265 call assert_fails('set conceallevel=-1', 'E487:')
266 call assert_fails('set conceallevel=4', 'E474:')
267 endif
268 call assert_fails('set helpheight=-1', 'E487:')
269 call assert_fails('set history=-1', 'E487:')
270 call assert_fails('set report=-1', 'E487:')
271 call assert_fails('set shiftwidth=-1', 'E487:')
272 call assert_fails('set sidescroll=-1', 'E487:')
273 call assert_fails('set tabstop=-1', 'E487:')
274 call assert_fails('set textwidth=-1', 'E487:')
275 call assert_fails('set timeoutlen=-1', 'E487:')
276 call assert_fails('set updatecount=-1', 'E487:')
277 call assert_fails('set updatetime=-1', 'E487:')
278 call assert_fails('set winheight=-1', 'E487:')
279 call assert_fails('set tabstop!', 'E488:')
280 call assert_fails('set xxx', 'E518:')
281 call assert_fails('set beautify?', 'E519:')
282 call assert_fails('set undolevels=x', 'E521:')
283 call assert_fails('set tabstop=', 'E521:')
284 call assert_fails('set comments=-', 'E524:')
285 call assert_fails('set comments=a', 'E525:')
286 call assert_fails('set foldmarker=x', 'E536:')
287 call assert_fails('set commentstring=x', 'E537:')
288 call assert_fails('set complete=x', 'E539:')
289 call assert_fails('set statusline=%{', 'E540:')
290 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
291 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100292 if has('cursorshape')
293 " This invalid value for 'guicursor' used to cause Vim to crash.
294 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
295 call assert_fails('set guicursor=i-ci', 'E545:')
296 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100297 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100298 call assert_fails('set guicursor=r-cr:horx', 'E548:')
299 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
300 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100301 if has('mouseshape')
302 call assert_fails('se mouseshape=i-r:x', 'E547:')
303 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100304 call assert_fails('set backupext=~ patchmode=~', 'E589:')
305 call assert_fails('set winminheight=10 winheight=9', 'E591:')
306 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
307 call assert_fails("set showbreak=\x01", 'E595:')
308 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100309endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100310
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200311func CheckWasSet(name)
312 let verb_cm = execute('verbose set ' .. a:name .. '?')
313 call assert_match('Last set from.*test_options.vim', verb_cm)
314endfunc
315func CheckWasNotSet(name)
316 let verb_cm = execute('verbose set ' .. a:name .. '?')
317 call assert_notmatch('Last set from', verb_cm)
318endfunc
319
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200320" Must be executed before other tests that set 'term'.
321func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200322 CheckNotGui
323
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200324 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200325
326 let term_save = &term
327 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200328 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200329 let &term = term_save
330endfunc
331
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200332func Test_copy_context()
333 setlocal list
334 call CheckWasSet('list')
335 split
336 call CheckWasSet('list')
337 quit
338 setlocal nolist
339
340 set ai
341 call CheckWasSet('ai')
342 set filetype=perl
343 call CheckWasSet('filetype')
344 set fo=tcroq
345 call CheckWasSet('fo')
346
347 split Xsomebuf
348 call CheckWasSet('ai')
349 call CheckWasNotSet('filetype')
350 call CheckWasSet('fo')
351endfunc
352
Bram Moolenaar67391142017-02-19 21:07:04 +0100353func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200354 CheckUnix
355 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200356
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200357 " Setting 'ttytype' used to cause a double-free when exiting vim and
358 " when vim is compiled with -DEXITFREE.
359 set ttytype=ansi
360 call assert_equal('ansi', &ttytype)
361 call assert_equal(&ttytype, &term)
362 set ttytype=xterm
363 call assert_equal('xterm', &ttytype)
364 call assert_equal(&ttytype, &term)
365 " "set ttytype=" gives E522 instead of E529
366 " in travis on some builds. Why? Catch both for now
367 try
368 set ttytype=
369 call assert_report('set ttytype= did not fail')
370 catch /E529\|E522/
371 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200372
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200373 " Some systems accept any terminal name and return dumb settings,
374 " check for failure of finding the entry and for missing 'cm' entry.
375 try
376 set ttytype=xxx
377 call assert_report('set ttytype=xxx did not fail')
378 catch /E522\|E437/
379 endtry
380
381 set ttytype&
382 call assert_equal(&ttytype, &term)
Bram Moolenaar67391142017-02-19 21:07:04 +0100383endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100384
385func Test_set_all()
386 set tw=75
387 set iskeyword=a-z,A-Z
388 set nosplitbelow
389 let out = execute('set all')
390 call assert_match('textwidth=75', out)
391 call assert_match('iskeyword=a-z,A-Z', out)
392 call assert_match('nosplitbelow', out)
393 set tw& iskeyword& splitbelow&
394endfunc
395
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100396func Test_set_one_column()
397 let out_mult = execute('set all')->split("\n")
398 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100399 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100400endfunc
401
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100402func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100403 if filereadable('opt_test.vim')
404 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100405 else
406 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100407 endif
408endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200409
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100410func Test_renderoptions()
411 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
412 " Doesn't hurt to do this on a non-Windows system.
413 if windowsversion() !~ '^[345]\.'
414 set renderoptions=type:directx
415 set rop=type:directx
416 endif
417endfunc
418
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200419func ResetIndentexpr()
420 set indentexpr=
421endfunc
422
423func Test_set_indentexpr()
424 " this was causing usage of freed memory
425 set indentexpr=ResetIndentexpr()
426 new
427 call feedkeys("i\<c-f>", 'x')
428 call assert_equal('', &indentexpr)
429 bwipe!
430endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200431
432func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100433 " Option 'backupskip' may contain several comma-separated path
434 " specifications if one or more of the environment variables TMPDIR, TMP,
435 " or TEMP is defined. To simplify testing, convert the string value into a
436 " list.
437 let bsklist = split(&bsk, ',')
438
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200439 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100440 let found = (index(bsklist, '/private/tmp/*') >= 0)
441 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200442 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100443 let found = (index(bsklist, '/tmp/*') >= 0)
444 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200445 endif
446
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100447 " If our test platform is Windows, the path(s) in option bsk will use
448 " backslash for the path separator and the components could be in short
449 " (8.3) format. As such, we need to replace the backslashes with forward
450 " slashes and convert the path components to long format. The expand()
451 " function will do this but it cannot handle comma-separated paths. This is
452 " why bsk was converted from a string into a list of strings above.
453 "
454 " One final complication is that the wildcard "/*" is at the end of each
455 " path and so expand() might return a list of matching files. To prevent
456 " this, we need to remove the wildcard before calling expand() and then
457 " append it afterwards.
458 if has('win32')
459 let item_nbr = 0
460 while item_nbr < len(bsklist)
461 let path_spec = bsklist[item_nbr]
462 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
463 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
464 let bsklist[item_nbr] = path_spec . '/*'
465 let item_nbr += 1
466 endwhile
467 endif
468
469 " Option bsk will also include these environment variables if defined.
470 " If they're defined, verify they appear in the option value.
471 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200472 if exists(var)
473 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100474 let varvalue = substitute(varvalue, '/$', '', '')
475 let varvalue .= '/*'
476 let found = (index(bsklist, varvalue) >= 0)
477 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200478 endif
479 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200480
481 " Duplicates should be filtered out (option has P_NODUP)
482 let backupskip = &backupskip
483 set backupskip=
484 set backupskip+=/test/dir
485 set backupskip+=/other/dir
486 set backupskip+=/test/dir
487 call assert_equal('/test/dir,/other/dir', &backupskip)
488 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200489endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200490
491func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200492 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200493
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200494 " Test copy option from current buffer in window
495 split
496 enew
497 setlocal numberwidth=5
498 wincmd w
499 call assert_equal(4,&numberwidth)
500 bnext
501 call assert_equal(5,&numberwidth)
502 bw!
503 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200504
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200505 " Test copy value from window that used to be display the buffer
506 split
507 enew
508 setlocal numberwidth=6
509 bnext
510 wincmd w
511 call assert_equal(4,&numberwidth)
512 bnext
513 call assert_equal(6,&numberwidth)
514 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200515
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200516 " Test that if buffer is current, don't use the stale cached value
517 " from the last time the buffer was displayed.
518 split
519 enew
520 setlocal numberwidth=7
521 bnext
522 bnext
523 setlocal numberwidth=8
524 wincmd w
525 call assert_equal(4,&numberwidth)
526 bnext
527 call assert_equal(8,&numberwidth)
528 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200529
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200530 " Test value is not copied if window already has seen the buffer
531 enew
532 split
533 setlocal numberwidth=9
534 bnext
535 setlocal numberwidth=10
536 wincmd w
537 call assert_equal(4,&numberwidth)
538 bnext
539 call assert_equal(4,&numberwidth)
540 bw!
541
542 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200543endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200544
545func Test_shortmess_F()
546 new
547 call assert_match('\[No Name\]', execute('file'))
548 set shortmess+=F
549 call assert_match('\[No Name\]', execute('file'))
550 call assert_match('^\s*$', execute('file foo'))
551 call assert_match('foo', execute('file'))
552 set shortmess-=F
553 call assert_match('bar', execute('file bar'))
554 call assert_match('bar', execute('file'))
555 set shortmess&
556 bwipe
557endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200558
559func Test_shortmess_F2()
560 e file1
561 e file2
562 call assert_match('file1', execute('bn', ''))
563 call assert_match('file2', execute('bn', ''))
564 set shortmess+=F
565 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200566 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200567 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200568 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200569 set hidden
570 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200571 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200572 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200573 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200574 set nohidden
575 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200576 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200577 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200578 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200579 set shortmess&
580 call assert_match('file1', execute('bn', ''))
581 call assert_match('file2', execute('bn', ''))
582 bwipe
583 bwipe
584endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100585
586func Test_local_scrolloff()
587 set so=5
588 set siso=7
589 split
590 call assert_equal(5, &so)
591 setlocal so=3
592 call assert_equal(3, &so)
593 wincmd w
594 call assert_equal(5, &so)
595 wincmd w
596 setlocal so<
597 call assert_equal(5, &so)
598 setlocal so=0
599 call assert_equal(0, &so)
600 setlocal so=-1
601 call assert_equal(5, &so)
602
603 call assert_equal(7, &siso)
604 setlocal siso=3
605 call assert_equal(3, &siso)
606 wincmd w
607 call assert_equal(7, &siso)
608 wincmd w
609 setlocal siso<
610 call assert_equal(7, &siso)
611 setlocal siso=0
612 call assert_equal(0, &siso)
613 setlocal siso=-1
614 call assert_equal(7, &siso)
615
616 close
617 set so&
618 set siso&
619endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200620
621func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100622 CheckFunction reltimefloat
623
Bram Moolenaar449ac472019-04-03 21:42:35 +0200624 new
625 call setline(1, 'empty')
626 redraw
627 set writedelay=10
628 let start = reltime()
629 call setline(1, repeat('x', 70))
630 redraw
631 let elapsed = reltimefloat(reltime(start))
632 set writedelay=0
633 " With 'writedelay' set should take at least 30 * 10 msec
634 call assert_inrange(30 * 0.01, 999.0, elapsed)
635
636 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200637endfunc
638
639func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200640 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200641 set visualbell
642 call assert_beeps('normal 0h')
643 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200644 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200645endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100646
647" Test for the 'write' option
648func Test_write()
649 new
650 call setline(1, ['L1'])
651 set nowrite
652 call assert_fails('write Xfile', 'E142:')
653 set write
654 close!
655endfunc
656
657" Test for 'buftype' option
658func Test_buftype()
659 new
660 call setline(1, ['L1'])
661 set buftype=nowrite
662 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100663
664 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
665 exe 'set buftype=' .. val
666 call writefile(['something'], 'XBuftype')
667 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
668 endfor
669
670 call delete('XBuftype')
671 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100672endfunc
673
Bram Moolenaarea3db912020-02-02 15:32:13 +0100674" Test for the 'shellquote' option
675func Test_shellquote()
676 CheckUnix
677 set shellquote=#
678 set verbose=20
679 redir => v
680 silent! !echo Hello
681 redir END
682 set verbose&
683 set shellquote&
684 call assert_match(': "#echo Hello#"', v)
685endfunc
686
Bram Moolenaar578fe942020-02-27 21:32:51 +0100687" Test for the 'rightleftcmd' option
688func Test_rightleftcmd()
689 CheckFeature rightleft
690 set rightleft
691 set rightleftcmd
692
693 let g:l = []
694 func AddPos()
695 call add(g:l, screencol())
696 return ''
697 endfunc
698 cmap <expr> <F2> AddPos()
699
700 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
701 \ "\<Left>\<F2>\<Esc>", 'xt')
702 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
703
704 cunmap <F2>
705 unlet g:l
706 set rightleftcmd&
707 set rightleft&
708endfunc
709
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100710" vim: shiftwidth=2 sts=2 expandtab