blob: f1118948dfe31454e9fff70fd1ad8fdf5162050b [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
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02004source view_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02005
Bram Moolenaar1e115362019-01-09 23:01:02 +01006func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02007 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
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010019 set whichwrap=h,h
20 call assert_equal('h', &whichwrap)
21
22 set whichwrap=h,h,h
23 call assert_equal('h', &whichwrap)
24
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020025 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010026endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020027
Bram Moolenaar1e115362019-01-09 23:01:02 +010028func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010029 " This used to cause Vim to access uninitialized memory.
30 set isfname=
31 call assert_equal("~X", expand("~X"))
32 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010033endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010034
Bram Moolenaar1e115362019-01-09 23:01:02 +010035func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010036 " Empty 'wildchar' used to access invalid memory.
37 call assert_fails('set wildchar=', 'E521:')
38 call assert_fails('set wildchar=abc', 'E521:')
39 set wildchar=<Esc>
40 let a=execute('set wildchar?')
41 call assert_equal("\n wildchar=<Esc>", a)
42 set wildchar=27
43 let a=execute('set wildchar?')
44 call assert_equal("\n wildchar=<Esc>", a)
45 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010046endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010047
Bram Moolenaar6b915c02020-01-18 15:53:19 +010048func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020049 let caught = 'ok'
50 try
51 options
52 catch
53 let caught = v:throwpoint . "\n" . v:exception
54 endtry
55 call assert_equal('ok', caught)
56
Bram Moolenaare0b59492019-05-21 20:54:45 +020057 " Check if the option-window is opened horizontally.
58 wincmd j
59 call assert_notequal('option-window', bufname(''))
60 wincmd k
61 call assert_equal('option-window', bufname(''))
62 " close option-window
63 close
64
65 " Open the option-window vertically.
66 vert options
67 " Check if the option-window is opened vertically.
68 wincmd l
69 call assert_notequal('option-window', bufname(''))
70 wincmd h
71 call assert_equal('option-window', bufname(''))
72 " close option-window
73 close
74
75 " Open the option-window in a new tab.
76 tab options
77 " Check if the option-window is opened in a tab.
78 normal gT
79 call assert_notequal('option-window', bufname(''))
80 normal gt
81 call assert_equal('option-window', bufname(''))
82
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020083 " close option-window
84 close
Bram Moolenaar1e115362019-01-09 23:01:02 +010085endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020086
Bram Moolenaar1e115362019-01-09 23:01:02 +010087func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020088 " Test that changing 'path' keeps two commas.
89 set path=foo,,bar
90 set path-=bar
91 set path+=bar
92 call assert_equal('foo,,bar', &path)
93
94 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +010095endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020096
97func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +020098 if has('signs')
99 call assert_equal("auto", &signcolumn)
100 set signcolumn=yes
101 set signcolumn=no
102 call assert_fails('set signcolumn=nope')
103 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200104endfunc
105
Bram Moolenaard0b51382016-11-04 15:23:45 +0100106func Test_filetype_valid()
107 set ft=valid_name
108 call assert_equal("valid_name", &filetype)
109 set ft=valid-name
110 call assert_equal("valid-name", &filetype)
111
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/name", "E474:")
116 call assert_fails(":set ft=wrong\\\nname", "E474:")
117 call assert_equal("valid-name", &filetype)
118
119 exe "set ft=trunc\x00name"
120 call assert_equal("trunc", &filetype)
121endfunc
122
123func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100124 if !has('syntax')
125 return
126 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100127 set syn=valid_name
128 call assert_equal("valid_name", &syntax)
129 set syn=valid-name
130 call assert_equal("valid-name", &syntax)
131
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/name", "E474:")
136 call assert_fails(":set syn=wrong\\\nname", "E474:")
137 call assert_equal("valid-name", &syntax)
138
139 exe "set syn=trunc\x00name"
140 call assert_equal("trunc", &syntax)
141endfunc
142
143func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100144 if !has('keymap')
145 return
146 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100147 call assert_fails(":set kmp=valid_name", "E544:")
148 call assert_fails(":set kmp=valid_name", "valid_name")
149 call assert_fails(":set kmp=valid-name", "E544:")
150 call assert_fails(":set kmp=valid-name", "valid-name")
151
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/name", "E474:")
156 call assert_fails(":set kmp=wrong\\\nname", "E474:")
157
158 call assert_fails(":set kmp=trunc\x00name", "E544:")
159 call assert_fails(":set kmp=trunc\x00name", "trunc")
160endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100161
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100162func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100163 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100164 exe 'set ' . a:name . '=/usr/share/dict/words'
165 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
166 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
167 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
168 exe 'set ' . a:name . '=/usr/share/dict\ words'
169 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100170
171 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100172 call assert_fails("set " . a:name . "=/not&there", "E474:")
173 call assert_fails("set " . a:name . "=/not>there", "E474:")
174 call assert_fails("set " . a:name . "=/not.*there", "E474:")
175endfunc
176
Bram Moolenaar60629d62017-02-23 18:08:56 +0100177func Test_cinkeys()
178 " This used to cause invalid memory access
179 set cindent cinkeys=0
180 norm a
181 set cindent& cinkeys&
182endfunc
183
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100184func Test_dictionary()
185 call Check_dir_option('dictionary')
186endfunc
187
188func Test_thesaurus()
189 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100190endfun
191
Bram Moolenaar226c5342017-02-17 14:53:15 +0100192func Test_complete()
193 " Trailing single backslash used to cause invalid memory access.
194 set complete=s\
195 new
196 call feedkeys("i\<C-N>\<Esc>", 'xt')
197 bwipe!
198 set complete&
199endfun
200
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100201func Test_set_completion()
202 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
203 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
204
Bram Moolenaar297610b2019-12-27 17:20:55 +0100205 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
206 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
207
208 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
209 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
210
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100211 " Expand boolan options. When doing :set no<Tab>
212 " vim displays the options names without "no" but completion uses "no...".
213 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
214 call assert_equal('"set nodiff digraph', @:)
215
216 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
217 call assert_equal('"set invdiff digraph', @:)
218
219 " Expand abbreviation of options.
220 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
221 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
222
223 " Expand current value
224 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
225 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
226
227 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
228 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
229
230 " Expand key codes.
231 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
232 call assert_equal('"set <Help> <Home>', @:)
233
234 " Expand terminal options.
235 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
236 call assert_equal('"set t_AB t_AF t_AL', @:)
237
238 " Expand directories.
239 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
240 call assert_match(' ./samples/ ', @:)
241 call assert_notmatch(' ./small.vim ', @:)
242
243 " Expand files and directories.
244 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
245 call assert_match(' ./samples/.* ./small.vim', @:)
246
247 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
248 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100249
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200250 set tags&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100251endfunc
252
253func Test_set_errors()
254 call assert_fails('set scroll=-1', 'E49:')
255 call assert_fails('set backupcopy=', 'E474:')
256 call assert_fails('set regexpengine=3', 'E474:')
257 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200258 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100259 call assert_fails('set colorcolumn=-a', 'E474:')
260 call assert_fails('set colorcolumn=a', 'E474:')
261 call assert_fails('set colorcolumn=1,', 'E474:')
262 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100263 call assert_fails('set cmdheight=-1', 'E487:')
264 call assert_fails('set cmdwinheight=-1', 'E487:')
265 if has('conceal')
266 call assert_fails('set conceallevel=-1', 'E487:')
267 call assert_fails('set conceallevel=4', 'E474:')
268 endif
269 call assert_fails('set helpheight=-1', 'E487:')
270 call assert_fails('set history=-1', 'E487:')
271 call assert_fails('set report=-1', 'E487:')
272 call assert_fails('set shiftwidth=-1', 'E487:')
273 call assert_fails('set sidescroll=-1', 'E487:')
274 call assert_fails('set tabstop=-1', 'E487:')
275 call assert_fails('set textwidth=-1', 'E487:')
276 call assert_fails('set timeoutlen=-1', 'E487:')
277 call assert_fails('set updatecount=-1', 'E487:')
278 call assert_fails('set updatetime=-1', 'E487:')
279 call assert_fails('set winheight=-1', 'E487:')
280 call assert_fails('set tabstop!', 'E488:')
281 call assert_fails('set xxx', 'E518:')
282 call assert_fails('set beautify?', 'E519:')
283 call assert_fails('set undolevels=x', 'E521:')
284 call assert_fails('set tabstop=', 'E521:')
285 call assert_fails('set comments=-', 'E524:')
286 call assert_fails('set comments=a', 'E525:')
287 call assert_fails('set foldmarker=x', 'E536:')
288 call assert_fails('set commentstring=x', 'E537:')
289 call assert_fails('set complete=x', 'E539:')
290 call assert_fails('set statusline=%{', 'E540:')
291 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
292 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100293 if has('cursorshape')
294 " This invalid value for 'guicursor' used to cause Vim to crash.
295 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
296 call assert_fails('set guicursor=i-ci', 'E545:')
297 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100298 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100299 call assert_fails('set guicursor=r-cr:horx', 'E548:')
300 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
301 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100302 if has('mouseshape')
303 call assert_fails('se mouseshape=i-r:x', 'E547:')
304 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100305 call assert_fails('set backupext=~ patchmode=~', 'E589:')
306 call assert_fails('set winminheight=10 winheight=9', 'E591:')
307 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
308 call assert_fails("set showbreak=\x01", 'E595:')
309 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100310endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100311
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200312func CheckWasSet(name)
313 let verb_cm = execute('verbose set ' .. a:name .. '?')
314 call assert_match('Last set from.*test_options.vim', verb_cm)
315endfunc
316func CheckWasNotSet(name)
317 let verb_cm = execute('verbose set ' .. a:name .. '?')
318 call assert_notmatch('Last set from', verb_cm)
319endfunc
320
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200321" Must be executed before other tests that set 'term'.
322func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200323 CheckNotGui
324
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200325 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200326
327 let term_save = &term
328 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200329 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200330 let &term = term_save
331endfunc
332
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200333func Test_copy_context()
334 setlocal list
335 call CheckWasSet('list')
336 split
337 call CheckWasSet('list')
338 quit
339 setlocal nolist
340
341 set ai
342 call CheckWasSet('ai')
343 set filetype=perl
344 call CheckWasSet('filetype')
345 set fo=tcroq
346 call CheckWasSet('fo')
347
348 split Xsomebuf
349 call CheckWasSet('ai')
350 call CheckWasNotSet('filetype')
351 call CheckWasSet('fo')
352endfunc
353
Bram Moolenaar67391142017-02-19 21:07:04 +0100354func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200355 CheckUnix
356 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200357
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200358 " Setting 'ttytype' used to cause a double-free when exiting vim and
359 " when vim is compiled with -DEXITFREE.
360 set ttytype=ansi
361 call assert_equal('ansi', &ttytype)
362 call assert_equal(&ttytype, &term)
363 set ttytype=xterm
364 call assert_equal('xterm', &ttytype)
365 call assert_equal(&ttytype, &term)
366 " "set ttytype=" gives E522 instead of E529
367 " in travis on some builds. Why? Catch both for now
368 try
369 set ttytype=
370 call assert_report('set ttytype= did not fail')
371 catch /E529\|E522/
372 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200373
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200374 " Some systems accept any terminal name and return dumb settings,
375 " check for failure of finding the entry and for missing 'cm' entry.
376 try
377 set ttytype=xxx
378 call assert_report('set ttytype=xxx did not fail')
379 catch /E522\|E437/
380 endtry
381
382 set ttytype&
383 call assert_equal(&ttytype, &term)
Bram Moolenaar67391142017-02-19 21:07:04 +0100384endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100385
386func Test_set_all()
387 set tw=75
388 set iskeyword=a-z,A-Z
389 set nosplitbelow
390 let out = execute('set all')
391 call assert_match('textwidth=75', out)
392 call assert_match('iskeyword=a-z,A-Z', out)
393 call assert_match('nosplitbelow', out)
394 set tw& iskeyword& splitbelow&
395endfunc
396
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100397func Test_set_one_column()
398 let out_mult = execute('set all')->split("\n")
399 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100400 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100401endfunc
402
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100403func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100404 if filereadable('opt_test.vim')
405 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100406 else
407 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100408 endif
409endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200410
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100411func Test_renderoptions()
412 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
413 " Doesn't hurt to do this on a non-Windows system.
414 if windowsversion() !~ '^[345]\.'
415 set renderoptions=type:directx
416 set rop=type:directx
417 endif
418endfunc
419
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200420func ResetIndentexpr()
421 set indentexpr=
422endfunc
423
424func Test_set_indentexpr()
425 " this was causing usage of freed memory
426 set indentexpr=ResetIndentexpr()
427 new
428 call feedkeys("i\<c-f>", 'x')
429 call assert_equal('', &indentexpr)
430 bwipe!
431endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200432
433func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100434 " Option 'backupskip' may contain several comma-separated path
435 " specifications if one or more of the environment variables TMPDIR, TMP,
436 " or TEMP is defined. To simplify testing, convert the string value into a
437 " list.
438 let bsklist = split(&bsk, ',')
439
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200440 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100441 let found = (index(bsklist, '/private/tmp/*') >= 0)
442 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200443 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100444 let found = (index(bsklist, '/tmp/*') >= 0)
445 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200446 endif
447
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100448 " If our test platform is Windows, the path(s) in option bsk will use
449 " backslash for the path separator and the components could be in short
450 " (8.3) format. As such, we need to replace the backslashes with forward
451 " slashes and convert the path components to long format. The expand()
452 " function will do this but it cannot handle comma-separated paths. This is
453 " why bsk was converted from a string into a list of strings above.
454 "
455 " One final complication is that the wildcard "/*" is at the end of each
456 " path and so expand() might return a list of matching files. To prevent
457 " this, we need to remove the wildcard before calling expand() and then
458 " append it afterwards.
459 if has('win32')
460 let item_nbr = 0
461 while item_nbr < len(bsklist)
462 let path_spec = bsklist[item_nbr]
463 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
464 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
465 let bsklist[item_nbr] = path_spec . '/*'
466 let item_nbr += 1
467 endwhile
468 endif
469
470 " Option bsk will also include these environment variables if defined.
471 " If they're defined, verify they appear in the option value.
472 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200473 if exists(var)
474 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100475 let varvalue = substitute(varvalue, '/$', '', '')
476 let varvalue .= '/*'
477 let found = (index(bsklist, varvalue) >= 0)
478 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200479 endif
480 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200481
482 " Duplicates should be filtered out (option has P_NODUP)
483 let backupskip = &backupskip
484 set backupskip=
485 set backupskip+=/test/dir
486 set backupskip+=/other/dir
487 set backupskip+=/test/dir
488 call assert_equal('/test/dir,/other/dir', &backupskip)
489 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200490endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200491
492func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200493 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200494
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200495 " Test copy option from current buffer in window
496 split
497 enew
498 setlocal numberwidth=5
499 wincmd w
500 call assert_equal(4,&numberwidth)
501 bnext
502 call assert_equal(5,&numberwidth)
503 bw!
504 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200505
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200506 " Test copy value from window that used to be display the buffer
507 split
508 enew
509 setlocal numberwidth=6
510 bnext
511 wincmd w
512 call assert_equal(4,&numberwidth)
513 bnext
514 call assert_equal(6,&numberwidth)
515 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200516
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200517 " Test that if buffer is current, don't use the stale cached value
518 " from the last time the buffer was displayed.
519 split
520 enew
521 setlocal numberwidth=7
522 bnext
523 bnext
524 setlocal numberwidth=8
525 wincmd w
526 call assert_equal(4,&numberwidth)
527 bnext
528 call assert_equal(8,&numberwidth)
529 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200530
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200531 " Test value is not copied if window already has seen the buffer
532 enew
533 split
534 setlocal numberwidth=9
535 bnext
536 setlocal numberwidth=10
537 wincmd w
538 call assert_equal(4,&numberwidth)
539 bnext
540 call assert_equal(4,&numberwidth)
541 bw!
542
543 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200544endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200545
546func Test_shortmess_F()
547 new
548 call assert_match('\[No Name\]', execute('file'))
549 set shortmess+=F
550 call assert_match('\[No Name\]', execute('file'))
551 call assert_match('^\s*$', execute('file foo'))
552 call assert_match('foo', execute('file'))
553 set shortmess-=F
554 call assert_match('bar', execute('file bar'))
555 call assert_match('bar', execute('file'))
556 set shortmess&
557 bwipe
558endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200559
560func Test_shortmess_F2()
561 e file1
562 e file2
563 call assert_match('file1', execute('bn', ''))
564 call assert_match('file2', execute('bn', ''))
565 set shortmess+=F
566 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200567 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200568 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200569 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200570 set hidden
571 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200572 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200573 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200574 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200575 set nohidden
576 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200577 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200578 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200579 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200580 set shortmess&
581 call assert_match('file1', execute('bn', ''))
582 call assert_match('file2', execute('bn', ''))
583 bwipe
584 bwipe
585endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100586
587func Test_local_scrolloff()
588 set so=5
589 set siso=7
590 split
591 call assert_equal(5, &so)
592 setlocal so=3
593 call assert_equal(3, &so)
594 wincmd w
595 call assert_equal(5, &so)
596 wincmd w
597 setlocal so<
598 call assert_equal(5, &so)
599 setlocal so=0
600 call assert_equal(0, &so)
601 setlocal so=-1
602 call assert_equal(5, &so)
603
604 call assert_equal(7, &siso)
605 setlocal siso=3
606 call assert_equal(3, &siso)
607 wincmd w
608 call assert_equal(7, &siso)
609 wincmd w
610 setlocal siso<
611 call assert_equal(7, &siso)
612 setlocal siso=0
613 call assert_equal(0, &siso)
614 setlocal siso=-1
615 call assert_equal(7, &siso)
616
617 close
618 set so&
619 set siso&
620endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200621
622func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100623 CheckFunction reltimefloat
624
Bram Moolenaar449ac472019-04-03 21:42:35 +0200625 new
626 call setline(1, 'empty')
627 redraw
628 set writedelay=10
629 let start = reltime()
630 call setline(1, repeat('x', 70))
631 redraw
632 let elapsed = reltimefloat(reltime(start))
633 set writedelay=0
634 " With 'writedelay' set should take at least 30 * 10 msec
635 call assert_inrange(30 * 0.01, 999.0, elapsed)
636
637 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200638endfunc
639
640func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200641 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200642 set visualbell
643 call assert_beeps('normal 0h')
644 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200645 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200646endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100647
648" Test for the 'write' option
649func Test_write()
650 new
651 call setline(1, ['L1'])
652 set nowrite
653 call assert_fails('write Xfile', 'E142:')
654 set write
655 close!
656endfunc
657
658" Test for 'buftype' option
659func Test_buftype()
660 new
661 call setline(1, ['L1'])
662 set buftype=nowrite
663 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100664
665 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
666 exe 'set buftype=' .. val
667 call writefile(['something'], 'XBuftype')
668 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
669 endfor
670
671 call delete('XBuftype')
672 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100673endfunc
674
Bram Moolenaarea3db912020-02-02 15:32:13 +0100675" Test for the 'shellquote' option
676func Test_shellquote()
677 CheckUnix
678 set shellquote=#
679 set verbose=20
680 redir => v
681 silent! !echo Hello
682 redir END
683 set verbose&
684 set shellquote&
685 call assert_match(': "#echo Hello#"', v)
686endfunc
687
Bram Moolenaar578fe942020-02-27 21:32:51 +0100688" Test for the 'rightleftcmd' option
689func Test_rightleftcmd()
690 CheckFeature rightleft
691 set rightleft
692 set rightleftcmd
693
694 let g:l = []
695 func AddPos()
696 call add(g:l, screencol())
697 return ''
698 endfunc
699 cmap <expr> <F2> AddPos()
700
701 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
702 \ "\<Left>\<F2>\<Esc>", 'xt')
703 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
704
705 cunmap <F2>
706 unlet g:l
707 set rightleftcmd&
708 set rightleft&
709endfunc
710
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200711" Test for the "debug" option
712func Test_debug_option()
713 set debug=beep
714 exe "normal \<C-c>"
715 call assert_equal('Beep!', Screenline(&lines))
716 set debug&
717endfunc
718
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100719" vim: shiftwidth=2 sts=2 expandtab