blob: 5d7714e7ae7cbd8ef60f510157e680f0c897b172 [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 Moolenaar2e61e2d2020-05-22 14:10:36 +020063func Test_wildoptions()
64 set wildoptions=
65 set wildoptions+=tagfile
66 set wildoptions+=tagfile
67 call assert_equal('tagfile', &wildoptions)
68endfunc
69
Bram Moolenaar6b915c02020-01-18 15:53:19 +010070func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020071 let caught = 'ok'
72 try
73 options
74 catch
75 let caught = v:throwpoint . "\n" . v:exception
76 endtry
77 call assert_equal('ok', caught)
78
Bram Moolenaare0b59492019-05-21 20:54:45 +020079 " Check if the option-window is opened horizontally.
80 wincmd j
81 call assert_notequal('option-window', bufname(''))
82 wincmd k
83 call assert_equal('option-window', bufname(''))
84 " close option-window
85 close
86
87 " Open the option-window vertically.
88 vert options
89 " Check if the option-window is opened vertically.
90 wincmd l
91 call assert_notequal('option-window', bufname(''))
92 wincmd h
93 call assert_equal('option-window', bufname(''))
94 " close option-window
95 close
96
Bram Moolenaar7a1637f2020-04-13 21:16:21 +020097 " Open the option-window at the top.
98 set splitbelow
99 topleft options
100 call assert_equal(1, winnr())
101 close
102
103 " Open the option-window at the bottom.
104 set nosplitbelow
105 botright options
106 call assert_equal(winnr('$'), winnr())
107 close
108 set splitbelow&
109
Bram Moolenaare0b59492019-05-21 20:54:45 +0200110 " Open the option-window in a new tab.
111 tab options
112 " Check if the option-window is opened in a tab.
113 normal gT
114 call assert_notequal('option-window', bufname(''))
115 normal gt
116 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200117 " close option-window
118 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200119
120 " Open the options window browse
121 if has('browse')
122 browse set
123 call assert_equal('option-window', bufname(''))
124 close
125 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100126endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200127
Bram Moolenaar1e115362019-01-09 23:01:02 +0100128func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200129 " Test that changing 'path' keeps two commas.
130 set path=foo,,bar
131 set path-=bar
132 set path+=bar
133 call assert_equal('foo,,bar', &path)
134
135 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100136endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200137
138func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200139 CheckFeature signs
140 call assert_equal("auto", &signcolumn)
141 set signcolumn=yes
142 set signcolumn=no
143 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200144endfunc
145
Bram Moolenaard0b51382016-11-04 15:23:45 +0100146func Test_filetype_valid()
147 set ft=valid_name
148 call assert_equal("valid_name", &filetype)
149 set ft=valid-name
150 call assert_equal("valid-name", &filetype)
151
152 call assert_fails(":set ft=wrong;name", "E474:")
153 call assert_fails(":set ft=wrong\\\\name", "E474:")
154 call assert_fails(":set ft=wrong\\|name", "E474:")
155 call assert_fails(":set ft=wrong/name", "E474:")
156 call assert_fails(":set ft=wrong\\\nname", "E474:")
157 call assert_equal("valid-name", &filetype)
158
159 exe "set ft=trunc\x00name"
160 call assert_equal("trunc", &filetype)
161endfunc
162
163func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200164 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100165 set syn=valid_name
166 call assert_equal("valid_name", &syntax)
167 set syn=valid-name
168 call assert_equal("valid-name", &syntax)
169
170 call assert_fails(":set syn=wrong;name", "E474:")
171 call assert_fails(":set syn=wrong\\\\name", "E474:")
172 call assert_fails(":set syn=wrong\\|name", "E474:")
173 call assert_fails(":set syn=wrong/name", "E474:")
174 call assert_fails(":set syn=wrong\\\nname", "E474:")
175 call assert_equal("valid-name", &syntax)
176
177 exe "set syn=trunc\x00name"
178 call assert_equal("trunc", &syntax)
179endfunc
180
181func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200182 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100183 call assert_fails(":set kmp=valid_name", "E544:")
184 call assert_fails(":set kmp=valid_name", "valid_name")
185 call assert_fails(":set kmp=valid-name", "E544:")
186 call assert_fails(":set kmp=valid-name", "valid-name")
187
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\\|name", "E474:")
191 call assert_fails(":set kmp=wrong/name", "E474:")
192 call assert_fails(":set kmp=wrong\\\nname", "E474:")
193
194 call assert_fails(":set kmp=trunc\x00name", "E544:")
195 call assert_fails(":set kmp=trunc\x00name", "trunc")
196endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100197
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100198func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100199 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100200 exe 'set ' . a:name . '=/usr/share/dict/words'
201 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
202 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
203 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
204 exe 'set ' . a:name . '=/usr/share/dict\ words'
205 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100206
207 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100208 call assert_fails("set " . a:name . "=/not&there", "E474:")
209 call assert_fails("set " . a:name . "=/not>there", "E474:")
210 call assert_fails("set " . a:name . "=/not.*there", "E474:")
211endfunc
212
Bram Moolenaar60629d62017-02-23 18:08:56 +0100213func Test_cinkeys()
214 " This used to cause invalid memory access
215 set cindent cinkeys=0
216 norm a
217 set cindent& cinkeys&
218endfunc
219
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100220func Test_dictionary()
221 call Check_dir_option('dictionary')
222endfunc
223
224func Test_thesaurus()
225 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100226endfun
227
Bram Moolenaar226c5342017-02-17 14:53:15 +0100228func Test_complete()
229 " Trailing single backslash used to cause invalid memory access.
230 set complete=s\
231 new
232 call feedkeys("i\<C-N>\<Esc>", 'xt')
233 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200234 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100235 set complete&
236endfun
237
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100238func Test_set_completion()
239 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
240 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
241
Bram Moolenaar297610b2019-12-27 17:20:55 +0100242 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
243 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
244
245 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
246 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
247
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100248 " Expand boolan options. When doing :set no<Tab>
249 " vim displays the options names without "no" but completion uses "no...".
250 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
251 call assert_equal('"set nodiff digraph', @:)
252
253 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
254 call assert_equal('"set invdiff digraph', @:)
255
256 " Expand abbreviation of options.
257 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
258 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
259
260 " Expand current value
261 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
262 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
263
264 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
265 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
266
267 " Expand key codes.
268 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
269 call assert_equal('"set <Help> <Home>', @:)
270
271 " Expand terminal options.
272 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200273 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200274 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100275
276 " Expand directories.
277 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
278 call assert_match(' ./samples/ ', @:)
279 call assert_notmatch(' ./small.vim ', @:)
280
281 " Expand files and directories.
282 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_match(' ./samples/.* ./small.vim', @:)
284
285 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
286 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200287 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200288
289 " Expanding the option names
290 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
291 call assert_equal('"set all', @:)
292
293 " Expanding a second set of option names
294 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
295 call assert_equal('"set wrapscan all', @:)
296
297 " Expanding a special keycode
298 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
299 call assert_equal('"set <Home>', @:)
300
301 " Expanding an invalid special keycode
302 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
303 call assert_equal("\"set <abcd>\<Tab>", @:)
304
305 " Expanding a terminal keycode
306 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
307 call assert_equal("\"set t_AB", @:)
308
309 " Expanding an invalid option name
310 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
311 call assert_equal("\"set abcde=\<Tab>", @:)
312
313 " Expanding after a = for a boolean option
314 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
315 call assert_equal("\"set wrapscan=\<Tab>", @:)
316
317 " Expanding a numeric option
318 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
319 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
320
321 " Expanding a non-boolean option
322 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
323 call assert_equal("\"set invtabstop=", @:)
324
325 " Expand options for 'spellsuggest'
326 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
327 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
328
329 " Expand value for 'key'
330 set key=abcd
331 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal('"set key=*****', @:)
333 set key=
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100334endfunc
335
336func Test_set_errors()
337 call assert_fails('set scroll=-1', 'E49:')
338 call assert_fails('set backupcopy=', 'E474:')
339 call assert_fails('set regexpengine=3', 'E474:')
340 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200341 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100342 call assert_fails('set colorcolumn=-a', 'E474:')
343 call assert_fails('set colorcolumn=a', 'E474:')
344 call assert_fails('set colorcolumn=1,', 'E474:')
345 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100346 call assert_fails('set cmdheight=-1', 'E487:')
347 call assert_fails('set cmdwinheight=-1', 'E487:')
348 if has('conceal')
349 call assert_fails('set conceallevel=-1', 'E487:')
350 call assert_fails('set conceallevel=4', 'E474:')
351 endif
352 call assert_fails('set helpheight=-1', 'E487:')
353 call assert_fails('set history=-1', 'E487:')
354 call assert_fails('set report=-1', 'E487:')
355 call assert_fails('set shiftwidth=-1', 'E487:')
356 call assert_fails('set sidescroll=-1', 'E487:')
357 call assert_fails('set tabstop=-1', 'E487:')
358 call assert_fails('set textwidth=-1', 'E487:')
359 call assert_fails('set timeoutlen=-1', 'E487:')
360 call assert_fails('set updatecount=-1', 'E487:')
361 call assert_fails('set updatetime=-1', 'E487:')
362 call assert_fails('set winheight=-1', 'E487:')
363 call assert_fails('set tabstop!', 'E488:')
364 call assert_fails('set xxx', 'E518:')
365 call assert_fails('set beautify?', 'E519:')
366 call assert_fails('set undolevels=x', 'E521:')
367 call assert_fails('set tabstop=', 'E521:')
368 call assert_fails('set comments=-', 'E524:')
369 call assert_fails('set comments=a', 'E525:')
370 call assert_fails('set foldmarker=x', 'E536:')
371 call assert_fails('set commentstring=x', 'E537:')
372 call assert_fails('set complete=x', 'E539:')
373 call assert_fails('set statusline=%{', 'E540:')
374 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
375 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100376 if has('cursorshape')
377 " This invalid value for 'guicursor' used to cause Vim to crash.
378 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
379 call assert_fails('set guicursor=i-ci', 'E545:')
380 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100381 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100382 call assert_fails('set guicursor=r-cr:horx', 'E548:')
383 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
384 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100385 if has('mouseshape')
386 call assert_fails('se mouseshape=i-r:x', 'E547:')
387 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100388 call assert_fails('set backupext=~ patchmode=~', 'E589:')
389 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200390 set winminheight& winheight&
391 set winheight=10 winminheight=10
392 call assert_fails('set winheight=9', 'E591:')
393 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100394 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200395 set winminwidth& winwidth&
396 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
397 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100398 call assert_fails("set showbreak=\x01", 'E595:')
399 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200400 call assert_fails('set tabstop??', 'E488:')
401 call assert_fails('set wrapscan!!', 'E488:')
402 call assert_fails('set tabstop&&', 'E488:')
403 call assert_fails('set wrapscan<<', 'E488:')
404 call assert_fails('set wrapscan=1', 'E474:')
405 call assert_fails('set autoindent@', 'E488:')
406 call assert_fails('set wildchar=<abc>', 'E474:')
407 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200408 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200409 if has('python') && has('python3')
410 call assert_fails('set pyxversion=6', 'E474:')
411 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200412 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100413endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100414
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200415func CheckWasSet(name)
416 let verb_cm = execute('verbose set ' .. a:name .. '?')
417 call assert_match('Last set from.*test_options.vim', verb_cm)
418endfunc
419func CheckWasNotSet(name)
420 let verb_cm = execute('verbose set ' .. a:name .. '?')
421 call assert_notmatch('Last set from', verb_cm)
422endfunc
423
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200424" Must be executed before other tests that set 'term'.
425func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200426 CheckNotGui
427
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200428 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200429
430 let term_save = &term
431 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200432 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200433 let &term = term_save
434endfunc
435
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200436func Test_copy_context()
437 setlocal list
438 call CheckWasSet('list')
439 split
440 call CheckWasSet('list')
441 quit
442 setlocal nolist
443
444 set ai
445 call CheckWasSet('ai')
446 set filetype=perl
447 call CheckWasSet('filetype')
448 set fo=tcroq
449 call CheckWasSet('fo')
450
451 split Xsomebuf
452 call CheckWasSet('ai')
453 call CheckWasNotSet('filetype')
454 call CheckWasSet('fo')
455endfunc
456
Bram Moolenaar67391142017-02-19 21:07:04 +0100457func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200458 CheckUnix
459 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200460
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200461 " Setting 'ttytype' used to cause a double-free when exiting vim and
462 " when vim is compiled with -DEXITFREE.
463 set ttytype=ansi
464 call assert_equal('ansi', &ttytype)
465 call assert_equal(&ttytype, &term)
466 set ttytype=xterm
467 call assert_equal('xterm', &ttytype)
468 call assert_equal(&ttytype, &term)
469 " "set ttytype=" gives E522 instead of E529
470 " in travis on some builds. Why? Catch both for now
471 try
472 set ttytype=
473 call assert_report('set ttytype= did not fail')
474 catch /E529\|E522/
475 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200476
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200477 " Some systems accept any terminal name and return dumb settings,
478 " check for failure of finding the entry and for missing 'cm' entry.
479 try
480 set ttytype=xxx
481 call assert_report('set ttytype=xxx did not fail')
482 catch /E522\|E437/
483 endtry
484
485 set ttytype&
486 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200487
488 if has('gui') && !has('gui_running')
489 call assert_fails('set term=gui', 'E531:')
490 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100491endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100492
493func Test_set_all()
494 set tw=75
495 set iskeyword=a-z,A-Z
496 set nosplitbelow
497 let out = execute('set all')
498 call assert_match('textwidth=75', out)
499 call assert_match('iskeyword=a-z,A-Z', out)
500 call assert_match('nosplitbelow', out)
501 set tw& iskeyword& splitbelow&
502endfunc
503
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100504func Test_set_one_column()
505 let out_mult = execute('set all')->split("\n")
506 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100507 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100508endfunc
509
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100510func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200511 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100512 if filereadable('opt_test.vim')
513 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100514 else
515 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100516 endif
517endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200518
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100519func Test_renderoptions()
520 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
521 " Doesn't hurt to do this on a non-Windows system.
522 if windowsversion() !~ '^[345]\.'
523 set renderoptions=type:directx
524 set rop=type:directx
525 endif
526endfunc
527
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200528func ResetIndentexpr()
529 set indentexpr=
530endfunc
531
532func Test_set_indentexpr()
533 " this was causing usage of freed memory
534 set indentexpr=ResetIndentexpr()
535 new
536 call feedkeys("i\<c-f>", 'x')
537 call assert_equal('', &indentexpr)
538 bwipe!
539endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200540
541func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100542 " Option 'backupskip' may contain several comma-separated path
543 " specifications if one or more of the environment variables TMPDIR, TMP,
544 " or TEMP is defined. To simplify testing, convert the string value into a
545 " list.
546 let bsklist = split(&bsk, ',')
547
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200548 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100549 let found = (index(bsklist, '/private/tmp/*') >= 0)
550 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200551 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100552 let found = (index(bsklist, '/tmp/*') >= 0)
553 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200554 endif
555
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100556 " If our test platform is Windows, the path(s) in option bsk will use
557 " backslash for the path separator and the components could be in short
558 " (8.3) format. As such, we need to replace the backslashes with forward
559 " slashes and convert the path components to long format. The expand()
560 " function will do this but it cannot handle comma-separated paths. This is
561 " why bsk was converted from a string into a list of strings above.
562 "
563 " One final complication is that the wildcard "/*" is at the end of each
564 " path and so expand() might return a list of matching files. To prevent
565 " this, we need to remove the wildcard before calling expand() and then
566 " append it afterwards.
567 if has('win32')
568 let item_nbr = 0
569 while item_nbr < len(bsklist)
570 let path_spec = bsklist[item_nbr]
571 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
572 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
573 let bsklist[item_nbr] = path_spec . '/*'
574 let item_nbr += 1
575 endwhile
576 endif
577
578 " Option bsk will also include these environment variables if defined.
579 " If they're defined, verify they appear in the option value.
580 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200581 if exists(var)
582 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100583 let varvalue = substitute(varvalue, '/$', '', '')
584 let varvalue .= '/*'
585 let found = (index(bsklist, varvalue) >= 0)
586 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200587 endif
588 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200589
590 " Duplicates should be filtered out (option has P_NODUP)
591 let backupskip = &backupskip
592 set backupskip=
593 set backupskip+=/test/dir
594 set backupskip+=/other/dir
595 set backupskip+=/test/dir
596 call assert_equal('/test/dir,/other/dir', &backupskip)
597 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200598endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200599
600func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200601 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200602
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200603 " Test copy option from current buffer in window
604 split
605 enew
606 setlocal numberwidth=5
607 wincmd w
608 call assert_equal(4,&numberwidth)
609 bnext
610 call assert_equal(5,&numberwidth)
611 bw!
612 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200613
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200614 " Test copy value from window that used to be display the buffer
615 split
616 enew
617 setlocal numberwidth=6
618 bnext
619 wincmd w
620 call assert_equal(4,&numberwidth)
621 bnext
622 call assert_equal(6,&numberwidth)
623 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200624
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200625 " Test that if buffer is current, don't use the stale cached value
626 " from the last time the buffer was displayed.
627 split
628 enew
629 setlocal numberwidth=7
630 bnext
631 bnext
632 setlocal numberwidth=8
633 wincmd w
634 call assert_equal(4,&numberwidth)
635 bnext
636 call assert_equal(8,&numberwidth)
637 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200638
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200639 " Test value is not copied if window already has seen the buffer
640 enew
641 split
642 setlocal numberwidth=9
643 bnext
644 setlocal numberwidth=10
645 wincmd w
646 call assert_equal(4,&numberwidth)
647 bnext
648 call assert_equal(4,&numberwidth)
649 bw!
650
651 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200652endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200653
654func Test_shortmess_F()
655 new
656 call assert_match('\[No Name\]', execute('file'))
657 set shortmess+=F
658 call assert_match('\[No Name\]', execute('file'))
659 call assert_match('^\s*$', execute('file foo'))
660 call assert_match('foo', execute('file'))
661 set shortmess-=F
662 call assert_match('bar', execute('file bar'))
663 call assert_match('bar', execute('file'))
664 set shortmess&
665 bwipe
666endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200667
668func Test_shortmess_F2()
669 e file1
670 e file2
671 call assert_match('file1', execute('bn', ''))
672 call assert_match('file2', execute('bn', ''))
673 set shortmess+=F
674 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200675 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200676 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200677 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200678 set hidden
679 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200680 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200681 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200682 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200683 set nohidden
684 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200685 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200686 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200687 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200688 set shortmess&
689 call assert_match('file1', execute('bn', ''))
690 call assert_match('file2', execute('bn', ''))
691 bwipe
692 bwipe
693endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100694
695func Test_local_scrolloff()
696 set so=5
697 set siso=7
698 split
699 call assert_equal(5, &so)
700 setlocal so=3
701 call assert_equal(3, &so)
702 wincmd w
703 call assert_equal(5, &so)
704 wincmd w
705 setlocal so<
706 call assert_equal(5, &so)
707 setlocal so=0
708 call assert_equal(0, &so)
709 setlocal so=-1
710 call assert_equal(5, &so)
711
712 call assert_equal(7, &siso)
713 setlocal siso=3
714 call assert_equal(3, &siso)
715 wincmd w
716 call assert_equal(7, &siso)
717 wincmd w
718 setlocal siso<
719 call assert_equal(7, &siso)
720 setlocal siso=0
721 call assert_equal(0, &siso)
722 setlocal siso=-1
723 call assert_equal(7, &siso)
724
725 close
726 set so&
727 set siso&
728endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200729
730func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100731 CheckFunction reltimefloat
732
Bram Moolenaar449ac472019-04-03 21:42:35 +0200733 new
734 call setline(1, 'empty')
735 redraw
736 set writedelay=10
737 let start = reltime()
738 call setline(1, repeat('x', 70))
739 redraw
740 let elapsed = reltimefloat(reltime(start))
741 set writedelay=0
742 " With 'writedelay' set should take at least 30 * 10 msec
743 call assert_inrange(30 * 0.01, 999.0, elapsed)
744
745 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200746endfunc
747
748func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200749 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200750 set visualbell
751 call assert_beeps('normal 0h')
752 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200753 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200754endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100755
756" Test for the 'write' option
757func Test_write()
758 new
759 call setline(1, ['L1'])
760 set nowrite
761 call assert_fails('write Xfile', 'E142:')
762 set write
763 close!
764endfunc
765
766" Test for 'buftype' option
767func Test_buftype()
768 new
769 call setline(1, ['L1'])
770 set buftype=nowrite
771 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100772
773 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
774 exe 'set buftype=' .. val
775 call writefile(['something'], 'XBuftype')
776 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
777 endfor
778
779 call delete('XBuftype')
780 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100781endfunc
782
Bram Moolenaar4d23c522020-04-09 18:42:11 +0200783" Test for the 'shell' option
784func Test_shell()
785 CheckUnix
786 let save_shell = &shell
787 set shell=
788 call assert_fails('shell', 'E91:')
789 let &shell = save_shell
790endfunc
791
Bram Moolenaarea3db912020-02-02 15:32:13 +0100792" Test for the 'shellquote' option
793func Test_shellquote()
794 CheckUnix
795 set shellquote=#
796 set verbose=20
797 redir => v
798 silent! !echo Hello
799 redir END
800 set verbose&
801 set shellquote&
802 call assert_match(': "#echo Hello#"', v)
803endfunc
804
Bram Moolenaar578fe942020-02-27 21:32:51 +0100805" Test for the 'rightleftcmd' option
806func Test_rightleftcmd()
807 CheckFeature rightleft
808 set rightleft
809 set rightleftcmd
810
811 let g:l = []
812 func AddPos()
813 call add(g:l, screencol())
814 return ''
815 endfunc
816 cmap <expr> <F2> AddPos()
817
818 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
819 \ "\<Left>\<F2>\<Esc>", 'xt')
820 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
821
822 cunmap <F2>
823 unlet g:l
824 set rightleftcmd&
825 set rightleft&
826endfunc
827
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200828" Test for the "debug" option
829func Test_debug_option()
830 set debug=beep
831 exe "normal \<C-c>"
832 call assert_equal('Beep!', Screenline(&lines))
833 set debug&
834endfunc
835
Bram Moolenaar004a6782020-04-11 17:09:31 +0200836" Test for the default CDPATH option
837func Test_opt_default_cdpath()
838 CheckFeature file_in_path
839 let after =<< trim [CODE]
840 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
841 call writefile(v:errors, 'Xtestout')
842 qall
843 [CODE]
844 if has('unix')
845 let $CDPATH='/path/to/dir1:/path/to/dir2'
846 else
847 let $CDPATH='/path/to/dir1;/path/to/dir2'
848 endif
849 if RunVim([], after, '')
850 call assert_equal([], readfile('Xtestout'))
851 call delete('Xtestout')
852 endif
853endfunc
854
855" Test for setting keycodes using set
856func Test_opt_set_keycode()
857 call assert_fails('set <t_k1=l', 'E474:')
858 call assert_fails('set <Home=l', 'E474:')
859 set <t_k9>=abcd
860 call assert_equal('abcd', &t_k9)
861 set <t_k9>&
862 set <F9>=xyz
863 call assert_equal('xyz', &t_k9)
864 set <t_k9>&
865endfunc
866
867" Test for changing options in a sandbox
868func Test_opt_sandbox()
869 for opt in ['backupdir', 'cdpath', 'exrc']
870 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200871 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200872 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200873 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200874endfunc
875
876" Test for setting an option with local value to global value
877func Test_opt_local_to_global()
878 setglobal equalprg=gprg
879 setlocal equalprg=lprg
880 call assert_equal('gprg', &g:equalprg)
881 call assert_equal('lprg', &l:equalprg)
882 call assert_equal('lprg', &equalprg)
883 set equalprg<
884 call assert_equal('', &l:equalprg)
885 call assert_equal('gprg', &equalprg)
886 setglobal equalprg=gnewprg
887 setlocal equalprg=lnewprg
888 setlocal equalprg<
889 call assert_equal('gnewprg', &l:equalprg)
890 call assert_equal('gnewprg', &equalprg)
891 set equalprg&
892endfunc
893
894" Test for incrementing, decrementing and multiplying a number option value
895func Test_opt_num_op()
896 set shiftwidth=4
897 set sw+=2
898 call assert_equal(6, &sw)
899 set sw-=2
900 call assert_equal(4, &sw)
901 set sw^=2
902 call assert_equal(8, &sw)
903 set shiftwidth&
904endfunc
905
Bram Moolenaar65d032c2020-04-24 20:57:01 +0200906" Test for setting option values using v:false and v:true
907func Test_opt_boolean()
908 set number&
909 set number
910 call assert_equal(1, &nu)
911 set nonu
912 call assert_equal(0, &nu)
913 let &nu = v:true
914 call assert_equal(1, &nu)
915 let &nu = v:false
916 call assert_equal(0, &nu)
917 set number&
918endfunc
919
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200920" Test for the 'window' option
921func Test_window_opt()
922 " Needs only one open widow
923 %bw!
924 call setline(1, range(1, 8))
925 set window=5
926 exe "normal \<C-F>"
927 call assert_equal(4, line('w0'))
928 exe "normal \<C-F>"
929 call assert_equal(7, line('w0'))
930 exe "normal \<C-F>"
931 call assert_equal(8, line('w0'))
932 exe "normal \<C-B>"
933 call assert_equal(5, line('w0'))
934 exe "normal \<C-B>"
935 call assert_equal(2, line('w0'))
936 exe "normal \<C-B>"
937 call assert_equal(1, line('w0'))
938 set window=1
939 exe "normal gg\<C-F>"
940 call assert_equal(2, line('w0'))
941 exe "normal \<C-F>"
942 call assert_equal(3, line('w0'))
943 exe "normal \<C-B>"
944 call assert_equal(2, line('w0'))
945 exe "normal \<C-B>"
946 call assert_equal(1, line('w0'))
947 enew!
948 set window&
949endfunc
950
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +0200951" Test for the 'winminheight' option
952func Test_opt_winminheight()
953 only!
954 let &winheight = &lines + 4
955 call assert_fails('let &winminheight = &lines + 2', 'E36:')
956 call assert_true(&winminheight <= &lines)
957 set winminheight&
958 set winheight&
959endfunc
960
961" Test for the 'winminwidth' option
962func Test_opt_winminwidth()
963 only!
964 let &winwidth = &columns + 4
965 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
966 call assert_true(&winminwidth <= &columns)
967 set winminwidth&
968 set winwidth&
969endfunc
970
Bram Moolenaar994b89d2020-08-07 19:12:41 +0200971" Test for setting option value containing spaces with isfname+=32
972func Test_isfname_with_options()
973 set isfname+=32
974 setlocal keywordprg=:term\ help.exe
975 call assert_equal(':term help.exe', &keywordprg)
976 set isfname&
977 setlocal keywordprg&
978endfunc
979
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100980" vim: shiftwidth=2 sts=2 expandtab