blob: af7b08359384c658244d8dbd6a1cb2ca1ae6db8e [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 Moolenaar004a6782020-04-11 17:09:31 +020025 " 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
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020040 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010041endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020042
Bram Moolenaar1e115362019-01-09 23:01:02 +010043func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010044 " This used to cause Vim to access uninitialized memory.
45 set isfname=
46 call assert_equal("~X", expand("~X"))
47 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010048endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010049
Bram Moolenaar1e115362019-01-09 23:01:02 +010050func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010051 " 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&
Bram Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010062
Bram Moolenaar6b915c02020-01-18 15:53:19 +010063func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020064 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
Bram Moolenaare0b59492019-05-21 20:54:45 +020072 " 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 in a new tab.
91 tab options
92 " Check if the option-window is opened in a tab.
93 normal gT
94 call assert_notequal('option-window', bufname(''))
95 normal gt
96 call assert_equal('option-window', bufname(''))
97
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020098 " close option-window
99 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200100
101 " Open the options window browse
102 if has('browse')
103 browse set
104 call assert_equal('option-window', bufname(''))
105 close
106 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100107endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200108
Bram Moolenaar1e115362019-01-09 23:01:02 +0100109func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200110 " Test that changing 'path' keeps two commas.
111 set path=foo,,bar
112 set path-=bar
113 set path+=bar
114 call assert_equal('foo,,bar', &path)
115
116 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100117endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200118
119func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +0200120 if has('signs')
121 call assert_equal("auto", &signcolumn)
122 set signcolumn=yes
123 set signcolumn=no
124 call assert_fails('set signcolumn=nope')
125 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200126endfunc
127
Bram Moolenaard0b51382016-11-04 15:23:45 +0100128func Test_filetype_valid()
129 set ft=valid_name
130 call assert_equal("valid_name", &filetype)
131 set ft=valid-name
132 call assert_equal("valid-name", &filetype)
133
134 call assert_fails(":set ft=wrong;name", "E474:")
135 call assert_fails(":set ft=wrong\\\\name", "E474:")
136 call assert_fails(":set ft=wrong\\|name", "E474:")
137 call assert_fails(":set ft=wrong/name", "E474:")
138 call assert_fails(":set ft=wrong\\\nname", "E474:")
139 call assert_equal("valid-name", &filetype)
140
141 exe "set ft=trunc\x00name"
142 call assert_equal("trunc", &filetype)
143endfunc
144
145func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100146 if !has('syntax')
147 return
148 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100149 set syn=valid_name
150 call assert_equal("valid_name", &syntax)
151 set syn=valid-name
152 call assert_equal("valid-name", &syntax)
153
154 call assert_fails(":set syn=wrong;name", "E474:")
155 call assert_fails(":set syn=wrong\\\\name", "E474:")
156 call assert_fails(":set syn=wrong\\|name", "E474:")
157 call assert_fails(":set syn=wrong/name", "E474:")
158 call assert_fails(":set syn=wrong\\\nname", "E474:")
159 call assert_equal("valid-name", &syntax)
160
161 exe "set syn=trunc\x00name"
162 call assert_equal("trunc", &syntax)
163endfunc
164
165func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100166 if !has('keymap')
167 return
168 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100169 call assert_fails(":set kmp=valid_name", "E544:")
170 call assert_fails(":set kmp=valid_name", "valid_name")
171 call assert_fails(":set kmp=valid-name", "E544:")
172 call assert_fails(":set kmp=valid-name", "valid-name")
173
174 call assert_fails(":set kmp=wrong;name", "E474:")
175 call assert_fails(":set kmp=wrong\\\\name", "E474:")
176 call assert_fails(":set kmp=wrong\\|name", "E474:")
177 call assert_fails(":set kmp=wrong/name", "E474:")
178 call assert_fails(":set kmp=wrong\\\nname", "E474:")
179
180 call assert_fails(":set kmp=trunc\x00name", "E544:")
181 call assert_fails(":set kmp=trunc\x00name", "trunc")
182endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100183
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100184func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100185 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100186 exe 'set ' . a:name . '=/usr/share/dict/words'
187 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
188 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
189 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
190 exe 'set ' . a:name . '=/usr/share/dict\ words'
191 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100192
193 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100194 call assert_fails("set " . a:name . "=/not&there", "E474:")
195 call assert_fails("set " . a:name . "=/not>there", "E474:")
196 call assert_fails("set " . a:name . "=/not.*there", "E474:")
197endfunc
198
Bram Moolenaar60629d62017-02-23 18:08:56 +0100199func Test_cinkeys()
200 " This used to cause invalid memory access
201 set cindent cinkeys=0
202 norm a
203 set cindent& cinkeys&
204endfunc
205
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100206func Test_dictionary()
207 call Check_dir_option('dictionary')
208endfunc
209
210func Test_thesaurus()
211 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100212endfun
213
Bram Moolenaar226c5342017-02-17 14:53:15 +0100214func Test_complete()
215 " Trailing single backslash used to cause invalid memory access.
216 set complete=s\
217 new
218 call feedkeys("i\<C-N>\<Esc>", 'xt')
219 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200220 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100221 set complete&
222endfun
223
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100224func Test_set_completion()
225 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
226 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
227
Bram Moolenaar297610b2019-12-27 17:20:55 +0100228 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
229 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
230
231 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
232 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
233
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100234 " Expand boolan options. When doing :set no<Tab>
235 " vim displays the options names without "no" but completion uses "no...".
236 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
237 call assert_equal('"set nodiff digraph', @:)
238
239 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
240 call assert_equal('"set invdiff digraph', @:)
241
242 " Expand abbreviation of options.
243 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
244 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
245
246 " Expand current value
247 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
248 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
249
250 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
251 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
252
253 " Expand key codes.
254 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
255 call assert_equal('"set <Help> <Home>', @:)
256
257 " Expand terminal options.
258 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
259 call assert_equal('"set t_AB t_AF t_AL', @:)
260
261 " Expand directories.
262 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
263 call assert_match(' ./samples/ ', @:)
264 call assert_notmatch(' ./small.vim ', @:)
265
266 " Expand files and directories.
267 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
268 call assert_match(' ./samples/.* ./small.vim', @:)
269
270 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
271 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100272
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200273 set tags&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100274endfunc
275
276func Test_set_errors()
277 call assert_fails('set scroll=-1', 'E49:')
278 call assert_fails('set backupcopy=', 'E474:')
279 call assert_fails('set regexpengine=3', 'E474:')
280 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200281 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100282 call assert_fails('set colorcolumn=-a', 'E474:')
283 call assert_fails('set colorcolumn=a', 'E474:')
284 call assert_fails('set colorcolumn=1,', 'E474:')
285 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100286 call assert_fails('set cmdheight=-1', 'E487:')
287 call assert_fails('set cmdwinheight=-1', 'E487:')
288 if has('conceal')
289 call assert_fails('set conceallevel=-1', 'E487:')
290 call assert_fails('set conceallevel=4', 'E474:')
291 endif
292 call assert_fails('set helpheight=-1', 'E487:')
293 call assert_fails('set history=-1', 'E487:')
294 call assert_fails('set report=-1', 'E487:')
295 call assert_fails('set shiftwidth=-1', 'E487:')
296 call assert_fails('set sidescroll=-1', 'E487:')
297 call assert_fails('set tabstop=-1', 'E487:')
298 call assert_fails('set textwidth=-1', 'E487:')
299 call assert_fails('set timeoutlen=-1', 'E487:')
300 call assert_fails('set updatecount=-1', 'E487:')
301 call assert_fails('set updatetime=-1', 'E487:')
302 call assert_fails('set winheight=-1', 'E487:')
303 call assert_fails('set tabstop!', 'E488:')
304 call assert_fails('set xxx', 'E518:')
305 call assert_fails('set beautify?', 'E519:')
306 call assert_fails('set undolevels=x', 'E521:')
307 call assert_fails('set tabstop=', 'E521:')
308 call assert_fails('set comments=-', 'E524:')
309 call assert_fails('set comments=a', 'E525:')
310 call assert_fails('set foldmarker=x', 'E536:')
311 call assert_fails('set commentstring=x', 'E537:')
312 call assert_fails('set complete=x', 'E539:')
313 call assert_fails('set statusline=%{', 'E540:')
314 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
315 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100316 if has('cursorshape')
317 " This invalid value for 'guicursor' used to cause Vim to crash.
318 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
319 call assert_fails('set guicursor=i-ci', 'E545:')
320 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100321 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100322 call assert_fails('set guicursor=r-cr:horx', 'E548:')
323 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
324 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100325 if has('mouseshape')
326 call assert_fails('se mouseshape=i-r:x', 'E547:')
327 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100328 call assert_fails('set backupext=~ patchmode=~', 'E589:')
329 call assert_fails('set winminheight=10 winheight=9', 'E591:')
330 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
331 call assert_fails("set showbreak=\x01", 'E595:')
332 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200333 call assert_fails('set tabstop??', 'E488:')
334 call assert_fails('set wrapscan!!', 'E488:')
335 call assert_fails('set tabstop&&', 'E488:')
336 call assert_fails('set wrapscan<<', 'E488:')
337 call assert_fails('set wrapscan=1', 'E474:')
338 call assert_fails('set autoindent@', 'E488:')
339 call assert_fails('set wildchar=<abc>', 'E474:')
340 call assert_fails('set cmdheight=1a', 'E521:')
341 if has('python') && has('python3')
342 call assert_fails('set pyxversion=6', 'E474:')
343 endif
Bram Moolenaar7554da42016-11-25 22:04:13 +0100344endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100345
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200346func CheckWasSet(name)
347 let verb_cm = execute('verbose set ' .. a:name .. '?')
348 call assert_match('Last set from.*test_options.vim', verb_cm)
349endfunc
350func CheckWasNotSet(name)
351 let verb_cm = execute('verbose set ' .. a:name .. '?')
352 call assert_notmatch('Last set from', verb_cm)
353endfunc
354
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200355" Must be executed before other tests that set 'term'.
356func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200357 CheckNotGui
358
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200359 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200360
361 let term_save = &term
362 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200363 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200364 let &term = term_save
365endfunc
366
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200367func Test_copy_context()
368 setlocal list
369 call CheckWasSet('list')
370 split
371 call CheckWasSet('list')
372 quit
373 setlocal nolist
374
375 set ai
376 call CheckWasSet('ai')
377 set filetype=perl
378 call CheckWasSet('filetype')
379 set fo=tcroq
380 call CheckWasSet('fo')
381
382 split Xsomebuf
383 call CheckWasSet('ai')
384 call CheckWasNotSet('filetype')
385 call CheckWasSet('fo')
386endfunc
387
Bram Moolenaar67391142017-02-19 21:07:04 +0100388func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200389 CheckUnix
390 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200391
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200392 " Setting 'ttytype' used to cause a double-free when exiting vim and
393 " when vim is compiled with -DEXITFREE.
394 set ttytype=ansi
395 call assert_equal('ansi', &ttytype)
396 call assert_equal(&ttytype, &term)
397 set ttytype=xterm
398 call assert_equal('xterm', &ttytype)
399 call assert_equal(&ttytype, &term)
400 " "set ttytype=" gives E522 instead of E529
401 " in travis on some builds. Why? Catch both for now
402 try
403 set ttytype=
404 call assert_report('set ttytype= did not fail')
405 catch /E529\|E522/
406 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200407
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200408 " Some systems accept any terminal name and return dumb settings,
409 " check for failure of finding the entry and for missing 'cm' entry.
410 try
411 set ttytype=xxx
412 call assert_report('set ttytype=xxx did not fail')
413 catch /E522\|E437/
414 endtry
415
416 set ttytype&
417 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200418
419 if has('gui') && !has('gui_running')
420 call assert_fails('set term=gui', 'E531:')
421 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100422endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100423
424func Test_set_all()
425 set tw=75
426 set iskeyword=a-z,A-Z
427 set nosplitbelow
428 let out = execute('set all')
429 call assert_match('textwidth=75', out)
430 call assert_match('iskeyword=a-z,A-Z', out)
431 call assert_match('nosplitbelow', out)
432 set tw& iskeyword& splitbelow&
433endfunc
434
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100435func Test_set_one_column()
436 let out_mult = execute('set all')->split("\n")
437 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100438 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100439endfunc
440
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100441func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100442 if filereadable('opt_test.vim')
443 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100444 else
445 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100446 endif
447endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200448
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100449func Test_renderoptions()
450 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
451 " Doesn't hurt to do this on a non-Windows system.
452 if windowsversion() !~ '^[345]\.'
453 set renderoptions=type:directx
454 set rop=type:directx
455 endif
456endfunc
457
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200458func ResetIndentexpr()
459 set indentexpr=
460endfunc
461
462func Test_set_indentexpr()
463 " this was causing usage of freed memory
464 set indentexpr=ResetIndentexpr()
465 new
466 call feedkeys("i\<c-f>", 'x')
467 call assert_equal('', &indentexpr)
468 bwipe!
469endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200470
471func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100472 " Option 'backupskip' may contain several comma-separated path
473 " specifications if one or more of the environment variables TMPDIR, TMP,
474 " or TEMP is defined. To simplify testing, convert the string value into a
475 " list.
476 let bsklist = split(&bsk, ',')
477
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200478 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100479 let found = (index(bsklist, '/private/tmp/*') >= 0)
480 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200481 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100482 let found = (index(bsklist, '/tmp/*') >= 0)
483 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200484 endif
485
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100486 " If our test platform is Windows, the path(s) in option bsk will use
487 " backslash for the path separator and the components could be in short
488 " (8.3) format. As such, we need to replace the backslashes with forward
489 " slashes and convert the path components to long format. The expand()
490 " function will do this but it cannot handle comma-separated paths. This is
491 " why bsk was converted from a string into a list of strings above.
492 "
493 " One final complication is that the wildcard "/*" is at the end of each
494 " path and so expand() might return a list of matching files. To prevent
495 " this, we need to remove the wildcard before calling expand() and then
496 " append it afterwards.
497 if has('win32')
498 let item_nbr = 0
499 while item_nbr < len(bsklist)
500 let path_spec = bsklist[item_nbr]
501 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
502 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
503 let bsklist[item_nbr] = path_spec . '/*'
504 let item_nbr += 1
505 endwhile
506 endif
507
508 " Option bsk will also include these environment variables if defined.
509 " If they're defined, verify they appear in the option value.
510 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200511 if exists(var)
512 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100513 let varvalue = substitute(varvalue, '/$', '', '')
514 let varvalue .= '/*'
515 let found = (index(bsklist, varvalue) >= 0)
516 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200517 endif
518 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200519
520 " Duplicates should be filtered out (option has P_NODUP)
521 let backupskip = &backupskip
522 set backupskip=
523 set backupskip+=/test/dir
524 set backupskip+=/other/dir
525 set backupskip+=/test/dir
526 call assert_equal('/test/dir,/other/dir', &backupskip)
527 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200528endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200529
530func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200531 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200532
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200533 " Test copy option from current buffer in window
534 split
535 enew
536 setlocal numberwidth=5
537 wincmd w
538 call assert_equal(4,&numberwidth)
539 bnext
540 call assert_equal(5,&numberwidth)
541 bw!
542 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200543
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200544 " Test copy value from window that used to be display the buffer
545 split
546 enew
547 setlocal numberwidth=6
548 bnext
549 wincmd w
550 call assert_equal(4,&numberwidth)
551 bnext
552 call assert_equal(6,&numberwidth)
553 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200554
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200555 " Test that if buffer is current, don't use the stale cached value
556 " from the last time the buffer was displayed.
557 split
558 enew
559 setlocal numberwidth=7
560 bnext
561 bnext
562 setlocal numberwidth=8
563 wincmd w
564 call assert_equal(4,&numberwidth)
565 bnext
566 call assert_equal(8,&numberwidth)
567 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200568
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200569 " Test value is not copied if window already has seen the buffer
570 enew
571 split
572 setlocal numberwidth=9
573 bnext
574 setlocal numberwidth=10
575 wincmd w
576 call assert_equal(4,&numberwidth)
577 bnext
578 call assert_equal(4,&numberwidth)
579 bw!
580
581 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200582endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200583
584func Test_shortmess_F()
585 new
586 call assert_match('\[No Name\]', execute('file'))
587 set shortmess+=F
588 call assert_match('\[No Name\]', execute('file'))
589 call assert_match('^\s*$', execute('file foo'))
590 call assert_match('foo', execute('file'))
591 set shortmess-=F
592 call assert_match('bar', execute('file bar'))
593 call assert_match('bar', execute('file'))
594 set shortmess&
595 bwipe
596endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200597
598func Test_shortmess_F2()
599 e file1
600 e file2
601 call assert_match('file1', execute('bn', ''))
602 call assert_match('file2', execute('bn', ''))
603 set shortmess+=F
604 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200605 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200606 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200607 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200608 set hidden
609 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200610 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200611 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200612 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200613 set nohidden
614 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200615 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200616 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200617 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200618 set shortmess&
619 call assert_match('file1', execute('bn', ''))
620 call assert_match('file2', execute('bn', ''))
621 bwipe
622 bwipe
623endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100624
625func Test_local_scrolloff()
626 set so=5
627 set siso=7
628 split
629 call assert_equal(5, &so)
630 setlocal so=3
631 call assert_equal(3, &so)
632 wincmd w
633 call assert_equal(5, &so)
634 wincmd w
635 setlocal so<
636 call assert_equal(5, &so)
637 setlocal so=0
638 call assert_equal(0, &so)
639 setlocal so=-1
640 call assert_equal(5, &so)
641
642 call assert_equal(7, &siso)
643 setlocal siso=3
644 call assert_equal(3, &siso)
645 wincmd w
646 call assert_equal(7, &siso)
647 wincmd w
648 setlocal siso<
649 call assert_equal(7, &siso)
650 setlocal siso=0
651 call assert_equal(0, &siso)
652 setlocal siso=-1
653 call assert_equal(7, &siso)
654
655 close
656 set so&
657 set siso&
658endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200659
660func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100661 CheckFunction reltimefloat
662
Bram Moolenaar449ac472019-04-03 21:42:35 +0200663 new
664 call setline(1, 'empty')
665 redraw
666 set writedelay=10
667 let start = reltime()
668 call setline(1, repeat('x', 70))
669 redraw
670 let elapsed = reltimefloat(reltime(start))
671 set writedelay=0
672 " With 'writedelay' set should take at least 30 * 10 msec
673 call assert_inrange(30 * 0.01, 999.0, elapsed)
674
675 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200676endfunc
677
678func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200679 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200680 set visualbell
681 call assert_beeps('normal 0h')
682 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200683 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200684endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100685
686" Test for the 'write' option
687func Test_write()
688 new
689 call setline(1, ['L1'])
690 set nowrite
691 call assert_fails('write Xfile', 'E142:')
692 set write
693 close!
694endfunc
695
696" Test for 'buftype' option
697func Test_buftype()
698 new
699 call setline(1, ['L1'])
700 set buftype=nowrite
701 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100702
703 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
704 exe 'set buftype=' .. val
705 call writefile(['something'], 'XBuftype')
706 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
707 endfor
708
709 call delete('XBuftype')
710 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100711endfunc
712
Bram Moolenaar4d23c522020-04-09 18:42:11 +0200713" Test for the 'shell' option
714func Test_shell()
715 CheckUnix
716 let save_shell = &shell
717 set shell=
718 call assert_fails('shell', 'E91:')
719 let &shell = save_shell
720endfunc
721
Bram Moolenaarea3db912020-02-02 15:32:13 +0100722" Test for the 'shellquote' option
723func Test_shellquote()
724 CheckUnix
725 set shellquote=#
726 set verbose=20
727 redir => v
728 silent! !echo Hello
729 redir END
730 set verbose&
731 set shellquote&
732 call assert_match(': "#echo Hello#"', v)
733endfunc
734
Bram Moolenaar578fe942020-02-27 21:32:51 +0100735" Test for the 'rightleftcmd' option
736func Test_rightleftcmd()
737 CheckFeature rightleft
738 set rightleft
739 set rightleftcmd
740
741 let g:l = []
742 func AddPos()
743 call add(g:l, screencol())
744 return ''
745 endfunc
746 cmap <expr> <F2> AddPos()
747
748 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
749 \ "\<Left>\<F2>\<Esc>", 'xt')
750 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
751
752 cunmap <F2>
753 unlet g:l
754 set rightleftcmd&
755 set rightleft&
756endfunc
757
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200758" Test for the "debug" option
759func Test_debug_option()
760 set debug=beep
761 exe "normal \<C-c>"
762 call assert_equal('Beep!', Screenline(&lines))
763 set debug&
764endfunc
765
Bram Moolenaar004a6782020-04-11 17:09:31 +0200766" Test for the default CDPATH option
767func Test_opt_default_cdpath()
768 CheckFeature file_in_path
769 let after =<< trim [CODE]
770 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
771 call writefile(v:errors, 'Xtestout')
772 qall
773 [CODE]
774 if has('unix')
775 let $CDPATH='/path/to/dir1:/path/to/dir2'
776 else
777 let $CDPATH='/path/to/dir1;/path/to/dir2'
778 endif
779 if RunVim([], after, '')
780 call assert_equal([], readfile('Xtestout'))
781 call delete('Xtestout')
782 endif
783endfunc
784
785" Test for setting keycodes using set
786func Test_opt_set_keycode()
787 call assert_fails('set <t_k1=l', 'E474:')
788 call assert_fails('set <Home=l', 'E474:')
789 set <t_k9>=abcd
790 call assert_equal('abcd', &t_k9)
791 set <t_k9>&
792 set <F9>=xyz
793 call assert_equal('xyz', &t_k9)
794 set <t_k9>&
795endfunc
796
797" Test for changing options in a sandbox
798func Test_opt_sandbox()
799 for opt in ['backupdir', 'cdpath', 'exrc']
800 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
801 endfor
802endfunc
803
804" Test for setting an option with local value to global value
805func Test_opt_local_to_global()
806 setglobal equalprg=gprg
807 setlocal equalprg=lprg
808 call assert_equal('gprg', &g:equalprg)
809 call assert_equal('lprg', &l:equalprg)
810 call assert_equal('lprg', &equalprg)
811 set equalprg<
812 call assert_equal('', &l:equalprg)
813 call assert_equal('gprg', &equalprg)
814 setglobal equalprg=gnewprg
815 setlocal equalprg=lnewprg
816 setlocal equalprg<
817 call assert_equal('gnewprg', &l:equalprg)
818 call assert_equal('gnewprg', &equalprg)
819 set equalprg&
820endfunc
821
822" Test for incrementing, decrementing and multiplying a number option value
823func Test_opt_num_op()
824 set shiftwidth=4
825 set sw+=2
826 call assert_equal(6, &sw)
827 set sw-=2
828 call assert_equal(4, &sw)
829 set sw^=2
830 call assert_equal(8, &sw)
831 set shiftwidth&
832endfunc
833
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100834" vim: shiftwidth=2 sts=2 expandtab