blob: e03d7e99cc95df67f098b4f63962441ef84c0083 [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
Bram Moolenaar7a1637f2020-04-13 21:16:21 +020090 " 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
Bram Moolenaare0b59492019-05-21 20:54:45 +0200103 " 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(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200110 " close option-window
111 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200112
113 " Open the options window browse
114 if has('browse')
115 browse set
116 call assert_equal('option-window', bufname(''))
117 close
118 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100119endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200120
Bram Moolenaar1e115362019-01-09 23:01:02 +0100121func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200122 " 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&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100129endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200130
131func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +0200132 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
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200138endfunc
139
Bram Moolenaard0b51382016-11-04 15:23:45 +0100140func 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()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100158 if !has('syntax')
159 return
160 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100161 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()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100178 if !has('keymap')
179 return
180 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100181 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
Bram Moolenaar7554da42016-11-25 22:04:13 +0100195
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100196func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100197 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100198 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))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100204
205 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100206 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
Bram Moolenaar60629d62017-02-23 18:08:56 +0100211func Test_cinkeys()
212 " This used to cause invalid memory access
213 set cindent cinkeys=0
214 norm a
215 set cindent& cinkeys&
216endfunc
217
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100218func Test_dictionary()
219 call Check_dir_option('dictionary')
220endfunc
221
222func Test_thesaurus()
223 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100224endfun
225
Bram Moolenaar226c5342017-02-17 14:53:15 +0100226func 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!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200232 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100233 set complete&
234endfun
235
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100236func 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
Bram Moolenaar297610b2019-12-27 17:20:55 +0100240 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
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100246 " Expand boolan options. When doing :set no<Tab>
247 " vim displays the options names without "no" but completion uses "no...".
248 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
249 call assert_equal('"set nodiff digraph', @:)
250
251 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
252 call assert_equal('"set invdiff digraph', @:)
253
254 " Expand abbreviation of options.
255 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
256 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
257
258 " Expand current value
259 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
260 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
261
262 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
263 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
264
265 " Expand key codes.
266 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
267 call assert_equal('"set <Help> <Home>', @:)
268
269 " Expand terminal options.
270 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
271 call assert_equal('"set t_AB t_AF t_AL', @:)
272
273 " Expand directories.
274 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
275 call assert_match(' ./samples/ ', @:)
276 call assert_notmatch(' ./small.vim ', @:)
277
278 " Expand files and directories.
279 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
280 call assert_match(' ./samples/.* ./small.vim', @:)
281
282 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200284 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200285
286 " Expanding the option names
287 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
288 call assert_equal('"set all', @:)
289
290 " Expanding a second set of option names
291 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
292 call assert_equal('"set wrapscan all', @:)
293
294 " Expanding a special keycode
295 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
296 call assert_equal('"set <Home>', @:)
297
298 " Expanding an invalid special keycode
299 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
300 call assert_equal("\"set <abcd>\<Tab>", @:)
301
302 " Expanding a terminal keycode
303 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
304 call assert_equal("\"set t_AB", @:)
305
306 " Expanding an invalid option name
307 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
308 call assert_equal("\"set abcde=\<Tab>", @:)
309
310 " Expanding after a = for a boolean option
311 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
312 call assert_equal("\"set wrapscan=\<Tab>", @:)
313
314 " Expanding a numeric option
315 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
316 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
317
318 " Expanding a non-boolean option
319 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
320 call assert_equal("\"set invtabstop=", @:)
321
322 " Expand options for 'spellsuggest'
323 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
324 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
325
326 " Expand value for 'key'
327 set key=abcd
328 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
329 call assert_equal('"set key=*****', @:)
330 set key=
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100331endfunc
332
333func Test_set_errors()
334 call assert_fails('set scroll=-1', 'E49:')
335 call assert_fails('set backupcopy=', 'E474:')
336 call assert_fails('set regexpengine=3', 'E474:')
337 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200338 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100339 call assert_fails('set colorcolumn=-a', 'E474:')
340 call assert_fails('set colorcolumn=a', 'E474:')
341 call assert_fails('set colorcolumn=1,', 'E474:')
342 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100343 call assert_fails('set cmdheight=-1', 'E487:')
344 call assert_fails('set cmdwinheight=-1', 'E487:')
345 if has('conceal')
346 call assert_fails('set conceallevel=-1', 'E487:')
347 call assert_fails('set conceallevel=4', 'E474:')
348 endif
349 call assert_fails('set helpheight=-1', 'E487:')
350 call assert_fails('set history=-1', 'E487:')
351 call assert_fails('set report=-1', 'E487:')
352 call assert_fails('set shiftwidth=-1', 'E487:')
353 call assert_fails('set sidescroll=-1', 'E487:')
354 call assert_fails('set tabstop=-1', 'E487:')
355 call assert_fails('set textwidth=-1', 'E487:')
356 call assert_fails('set timeoutlen=-1', 'E487:')
357 call assert_fails('set updatecount=-1', 'E487:')
358 call assert_fails('set updatetime=-1', 'E487:')
359 call assert_fails('set winheight=-1', 'E487:')
360 call assert_fails('set tabstop!', 'E488:')
361 call assert_fails('set xxx', 'E518:')
362 call assert_fails('set beautify?', 'E519:')
363 call assert_fails('set undolevels=x', 'E521:')
364 call assert_fails('set tabstop=', 'E521:')
365 call assert_fails('set comments=-', 'E524:')
366 call assert_fails('set comments=a', 'E525:')
367 call assert_fails('set foldmarker=x', 'E536:')
368 call assert_fails('set commentstring=x', 'E537:')
369 call assert_fails('set complete=x', 'E539:')
370 call assert_fails('set statusline=%{', 'E540:')
371 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
372 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100373 if has('cursorshape')
374 " This invalid value for 'guicursor' used to cause Vim to crash.
375 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
376 call assert_fails('set guicursor=i-ci', 'E545:')
377 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100378 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100379 call assert_fails('set guicursor=r-cr:horx', 'E548:')
380 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
381 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100382 if has('mouseshape')
383 call assert_fails('se mouseshape=i-r:x', 'E547:')
384 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100385 call assert_fails('set backupext=~ patchmode=~', 'E589:')
386 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200387 set winminheight& winheight&
388 set winheight=10 winminheight=10
389 call assert_fails('set winheight=9', 'E591:')
390 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100391 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200392 set winminwidth& winwidth&
393 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
394 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100395 call assert_fails("set showbreak=\x01", 'E595:')
396 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200397 call assert_fails('set tabstop??', 'E488:')
398 call assert_fails('set wrapscan!!', 'E488:')
399 call assert_fails('set tabstop&&', 'E488:')
400 call assert_fails('set wrapscan<<', 'E488:')
401 call assert_fails('set wrapscan=1', 'E474:')
402 call assert_fails('set autoindent@', 'E488:')
403 call assert_fails('set wildchar=<abc>', 'E474:')
404 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200405 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200406 if has('python') && has('python3')
407 call assert_fails('set pyxversion=6', 'E474:')
408 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200409 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100410endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100411
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200412func CheckWasSet(name)
413 let verb_cm = execute('verbose set ' .. a:name .. '?')
414 call assert_match('Last set from.*test_options.vim', verb_cm)
415endfunc
416func CheckWasNotSet(name)
417 let verb_cm = execute('verbose set ' .. a:name .. '?')
418 call assert_notmatch('Last set from', verb_cm)
419endfunc
420
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200421" Must be executed before other tests that set 'term'.
422func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200423 CheckNotGui
424
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200425 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200426
427 let term_save = &term
428 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200429 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200430 let &term = term_save
431endfunc
432
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200433func Test_copy_context()
434 setlocal list
435 call CheckWasSet('list')
436 split
437 call CheckWasSet('list')
438 quit
439 setlocal nolist
440
441 set ai
442 call CheckWasSet('ai')
443 set filetype=perl
444 call CheckWasSet('filetype')
445 set fo=tcroq
446 call CheckWasSet('fo')
447
448 split Xsomebuf
449 call CheckWasSet('ai')
450 call CheckWasNotSet('filetype')
451 call CheckWasSet('fo')
452endfunc
453
Bram Moolenaar67391142017-02-19 21:07:04 +0100454func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200455 CheckUnix
456 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200457
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200458 " Setting 'ttytype' used to cause a double-free when exiting vim and
459 " when vim is compiled with -DEXITFREE.
460 set ttytype=ansi
461 call assert_equal('ansi', &ttytype)
462 call assert_equal(&ttytype, &term)
463 set ttytype=xterm
464 call assert_equal('xterm', &ttytype)
465 call assert_equal(&ttytype, &term)
466 " "set ttytype=" gives E522 instead of E529
467 " in travis on some builds. Why? Catch both for now
468 try
469 set ttytype=
470 call assert_report('set ttytype= did not fail')
471 catch /E529\|E522/
472 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200473
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200474 " Some systems accept any terminal name and return dumb settings,
475 " check for failure of finding the entry and for missing 'cm' entry.
476 try
477 set ttytype=xxx
478 call assert_report('set ttytype=xxx did not fail')
479 catch /E522\|E437/
480 endtry
481
482 set ttytype&
483 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200484
485 if has('gui') && !has('gui_running')
486 call assert_fails('set term=gui', 'E531:')
487 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100488endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100489
490func Test_set_all()
491 set tw=75
492 set iskeyword=a-z,A-Z
493 set nosplitbelow
494 let out = execute('set all')
495 call assert_match('textwidth=75', out)
496 call assert_match('iskeyword=a-z,A-Z', out)
497 call assert_match('nosplitbelow', out)
498 set tw& iskeyword& splitbelow&
499endfunc
500
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100501func Test_set_one_column()
502 let out_mult = execute('set all')->split("\n")
503 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100504 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100505endfunc
506
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100507func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100508 if filereadable('opt_test.vim')
509 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100510 else
511 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100512 endif
513endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200514
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100515func Test_renderoptions()
516 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
517 " Doesn't hurt to do this on a non-Windows system.
518 if windowsversion() !~ '^[345]\.'
519 set renderoptions=type:directx
520 set rop=type:directx
521 endif
522endfunc
523
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200524func ResetIndentexpr()
525 set indentexpr=
526endfunc
527
528func Test_set_indentexpr()
529 " this was causing usage of freed memory
530 set indentexpr=ResetIndentexpr()
531 new
532 call feedkeys("i\<c-f>", 'x')
533 call assert_equal('', &indentexpr)
534 bwipe!
535endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200536
537func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100538 " Option 'backupskip' may contain several comma-separated path
539 " specifications if one or more of the environment variables TMPDIR, TMP,
540 " or TEMP is defined. To simplify testing, convert the string value into a
541 " list.
542 let bsklist = split(&bsk, ',')
543
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200544 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100545 let found = (index(bsklist, '/private/tmp/*') >= 0)
546 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200547 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100548 let found = (index(bsklist, '/tmp/*') >= 0)
549 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200550 endif
551
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100552 " If our test platform is Windows, the path(s) in option bsk will use
553 " backslash for the path separator and the components could be in short
554 " (8.3) format. As such, we need to replace the backslashes with forward
555 " slashes and convert the path components to long format. The expand()
556 " function will do this but it cannot handle comma-separated paths. This is
557 " why bsk was converted from a string into a list of strings above.
558 "
559 " One final complication is that the wildcard "/*" is at the end of each
560 " path and so expand() might return a list of matching files. To prevent
561 " this, we need to remove the wildcard before calling expand() and then
562 " append it afterwards.
563 if has('win32')
564 let item_nbr = 0
565 while item_nbr < len(bsklist)
566 let path_spec = bsklist[item_nbr]
567 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
568 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
569 let bsklist[item_nbr] = path_spec . '/*'
570 let item_nbr += 1
571 endwhile
572 endif
573
574 " Option bsk will also include these environment variables if defined.
575 " If they're defined, verify they appear in the option value.
576 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200577 if exists(var)
578 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100579 let varvalue = substitute(varvalue, '/$', '', '')
580 let varvalue .= '/*'
581 let found = (index(bsklist, varvalue) >= 0)
582 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200583 endif
584 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200585
586 " Duplicates should be filtered out (option has P_NODUP)
587 let backupskip = &backupskip
588 set backupskip=
589 set backupskip+=/test/dir
590 set backupskip+=/other/dir
591 set backupskip+=/test/dir
592 call assert_equal('/test/dir,/other/dir', &backupskip)
593 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200594endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200595
596func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200597 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200598
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200599 " Test copy option from current buffer in window
600 split
601 enew
602 setlocal numberwidth=5
603 wincmd w
604 call assert_equal(4,&numberwidth)
605 bnext
606 call assert_equal(5,&numberwidth)
607 bw!
608 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200609
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200610 " Test copy value from window that used to be display the buffer
611 split
612 enew
613 setlocal numberwidth=6
614 bnext
615 wincmd w
616 call assert_equal(4,&numberwidth)
617 bnext
618 call assert_equal(6,&numberwidth)
619 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200620
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200621 " Test that if buffer is current, don't use the stale cached value
622 " from the last time the buffer was displayed.
623 split
624 enew
625 setlocal numberwidth=7
626 bnext
627 bnext
628 setlocal numberwidth=8
629 wincmd w
630 call assert_equal(4,&numberwidth)
631 bnext
632 call assert_equal(8,&numberwidth)
633 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200634
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200635 " Test value is not copied if window already has seen the buffer
636 enew
637 split
638 setlocal numberwidth=9
639 bnext
640 setlocal numberwidth=10
641 wincmd w
642 call assert_equal(4,&numberwidth)
643 bnext
644 call assert_equal(4,&numberwidth)
645 bw!
646
647 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200648endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200649
650func Test_shortmess_F()
651 new
652 call assert_match('\[No Name\]', execute('file'))
653 set shortmess+=F
654 call assert_match('\[No Name\]', execute('file'))
655 call assert_match('^\s*$', execute('file foo'))
656 call assert_match('foo', execute('file'))
657 set shortmess-=F
658 call assert_match('bar', execute('file bar'))
659 call assert_match('bar', execute('file'))
660 set shortmess&
661 bwipe
662endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200663
664func Test_shortmess_F2()
665 e file1
666 e file2
667 call assert_match('file1', execute('bn', ''))
668 call assert_match('file2', execute('bn', ''))
669 set shortmess+=F
670 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200671 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200672 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200673 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200674 set hidden
675 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200676 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200677 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200678 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200679 set nohidden
680 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200681 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200682 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200683 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200684 set shortmess&
685 call assert_match('file1', execute('bn', ''))
686 call assert_match('file2', execute('bn', ''))
687 bwipe
688 bwipe
689endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100690
691func Test_local_scrolloff()
692 set so=5
693 set siso=7
694 split
695 call assert_equal(5, &so)
696 setlocal so=3
697 call assert_equal(3, &so)
698 wincmd w
699 call assert_equal(5, &so)
700 wincmd w
701 setlocal so<
702 call assert_equal(5, &so)
703 setlocal so=0
704 call assert_equal(0, &so)
705 setlocal so=-1
706 call assert_equal(5, &so)
707
708 call assert_equal(7, &siso)
709 setlocal siso=3
710 call assert_equal(3, &siso)
711 wincmd w
712 call assert_equal(7, &siso)
713 wincmd w
714 setlocal siso<
715 call assert_equal(7, &siso)
716 setlocal siso=0
717 call assert_equal(0, &siso)
718 setlocal siso=-1
719 call assert_equal(7, &siso)
720
721 close
722 set so&
723 set siso&
724endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200725
726func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100727 CheckFunction reltimefloat
728
Bram Moolenaar449ac472019-04-03 21:42:35 +0200729 new
730 call setline(1, 'empty')
731 redraw
732 set writedelay=10
733 let start = reltime()
734 call setline(1, repeat('x', 70))
735 redraw
736 let elapsed = reltimefloat(reltime(start))
737 set writedelay=0
738 " With 'writedelay' set should take at least 30 * 10 msec
739 call assert_inrange(30 * 0.01, 999.0, elapsed)
740
741 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200742endfunc
743
744func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200745 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200746 set visualbell
747 call assert_beeps('normal 0h')
748 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200749 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200750endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100751
752" Test for the 'write' option
753func Test_write()
754 new
755 call setline(1, ['L1'])
756 set nowrite
757 call assert_fails('write Xfile', 'E142:')
758 set write
759 close!
760endfunc
761
762" Test for 'buftype' option
763func Test_buftype()
764 new
765 call setline(1, ['L1'])
766 set buftype=nowrite
767 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100768
769 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
770 exe 'set buftype=' .. val
771 call writefile(['something'], 'XBuftype')
772 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
773 endfor
774
775 call delete('XBuftype')
776 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100777endfunc
778
Bram Moolenaar4d23c522020-04-09 18:42:11 +0200779" Test for the 'shell' option
780func Test_shell()
781 CheckUnix
782 let save_shell = &shell
783 set shell=
784 call assert_fails('shell', 'E91:')
785 let &shell = save_shell
786endfunc
787
Bram Moolenaarea3db912020-02-02 15:32:13 +0100788" Test for the 'shellquote' option
789func Test_shellquote()
790 CheckUnix
791 set shellquote=#
792 set verbose=20
793 redir => v
794 silent! !echo Hello
795 redir END
796 set verbose&
797 set shellquote&
798 call assert_match(': "#echo Hello#"', v)
799endfunc
800
Bram Moolenaar578fe942020-02-27 21:32:51 +0100801" Test for the 'rightleftcmd' option
802func Test_rightleftcmd()
803 CheckFeature rightleft
804 set rightleft
805 set rightleftcmd
806
807 let g:l = []
808 func AddPos()
809 call add(g:l, screencol())
810 return ''
811 endfunc
812 cmap <expr> <F2> AddPos()
813
814 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
815 \ "\<Left>\<F2>\<Esc>", 'xt')
816 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
817
818 cunmap <F2>
819 unlet g:l
820 set rightleftcmd&
821 set rightleft&
822endfunc
823
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200824" Test for the "debug" option
825func Test_debug_option()
826 set debug=beep
827 exe "normal \<C-c>"
828 call assert_equal('Beep!', Screenline(&lines))
829 set debug&
830endfunc
831
Bram Moolenaar004a6782020-04-11 17:09:31 +0200832" Test for the default CDPATH option
833func Test_opt_default_cdpath()
834 CheckFeature file_in_path
835 let after =<< trim [CODE]
836 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
837 call writefile(v:errors, 'Xtestout')
838 qall
839 [CODE]
840 if has('unix')
841 let $CDPATH='/path/to/dir1:/path/to/dir2'
842 else
843 let $CDPATH='/path/to/dir1;/path/to/dir2'
844 endif
845 if RunVim([], after, '')
846 call assert_equal([], readfile('Xtestout'))
847 call delete('Xtestout')
848 endif
849endfunc
850
851" Test for setting keycodes using set
852func Test_opt_set_keycode()
853 call assert_fails('set <t_k1=l', 'E474:')
854 call assert_fails('set <Home=l', 'E474:')
855 set <t_k9>=abcd
856 call assert_equal('abcd', &t_k9)
857 set <t_k9>&
858 set <F9>=xyz
859 call assert_equal('xyz', &t_k9)
860 set <t_k9>&
861endfunc
862
863" Test for changing options in a sandbox
864func Test_opt_sandbox()
865 for opt in ['backupdir', 'cdpath', 'exrc']
866 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200867 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200868 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200869 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200870endfunc
871
872" Test for setting an option with local value to global value
873func Test_opt_local_to_global()
874 setglobal equalprg=gprg
875 setlocal equalprg=lprg
876 call assert_equal('gprg', &g:equalprg)
877 call assert_equal('lprg', &l:equalprg)
878 call assert_equal('lprg', &equalprg)
879 set equalprg<
880 call assert_equal('', &l:equalprg)
881 call assert_equal('gprg', &equalprg)
882 setglobal equalprg=gnewprg
883 setlocal equalprg=lnewprg
884 setlocal equalprg<
885 call assert_equal('gnewprg', &l:equalprg)
886 call assert_equal('gnewprg', &equalprg)
887 set equalprg&
888endfunc
889
890" Test for incrementing, decrementing and multiplying a number option value
891func Test_opt_num_op()
892 set shiftwidth=4
893 set sw+=2
894 call assert_equal(6, &sw)
895 set sw-=2
896 call assert_equal(4, &sw)
897 set sw^=2
898 call assert_equal(8, &sw)
899 set shiftwidth&
900endfunc
901
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100902" vim: shiftwidth=2 sts=2 expandtab