blob: e49afae1742aeb0d7ed8cf6557cade2dfae97fb5 [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Bram Moolenaarb00ef052020-09-12 14:53:53 +02003source shared.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02005source view_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02006
Bram Moolenaar1e115362019-01-09 23:01:02 +01007func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02008 set whichwrap=b,s
9 call assert_equal('b,s', &whichwrap)
10
11 set whichwrap+=h,l
12 call assert_equal('b,s,h,l', &whichwrap)
13
14 set whichwrap+=h,l
15 call assert_equal('b,s,h,l', &whichwrap)
16
17 set whichwrap+=h,l
18 call assert_equal('b,s,h,l', &whichwrap)
19
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010020 set whichwrap=h,h
21 call assert_equal('h', &whichwrap)
22
23 set whichwrap=h,h,h
24 call assert_equal('h', &whichwrap)
25
Bram Moolenaar004a6782020-04-11 17:09:31 +020026 " For compatibility with Vim 3.0 and before, number values are also
27 " supported for 'whichwrap'
28 set whichwrap=1
29 call assert_equal('b', &whichwrap)
30 set whichwrap=2
31 call assert_equal('s', &whichwrap)
32 set whichwrap=4
33 call assert_equal('h,l', &whichwrap)
34 set whichwrap=8
35 call assert_equal('<,>', &whichwrap)
36 set whichwrap=16
37 call assert_equal('[,]', &whichwrap)
38 set whichwrap=31
39 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
40
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020041 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010042endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020043
Bram Moolenaar1e115362019-01-09 23:01:02 +010044func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010045 " This used to cause Vim to access uninitialized memory.
46 set isfname=
47 call assert_equal("~X", expand("~X"))
48 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010049endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010050
Bram Moolenaar1e115362019-01-09 23:01:02 +010051func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010052 " Empty 'wildchar' used to access invalid memory.
53 call assert_fails('set wildchar=', 'E521:')
54 call assert_fails('set wildchar=abc', 'E521:')
55 set wildchar=<Esc>
56 let a=execute('set wildchar?')
57 call assert_equal("\n wildchar=<Esc>", a)
58 set wildchar=27
59 let a=execute('set wildchar?')
60 call assert_equal("\n wildchar=<Esc>", a)
61 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010062endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010063
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020064func Test_wildoptions()
65 set wildoptions=
66 set wildoptions+=tagfile
67 set wildoptions+=tagfile
68 call assert_equal('tagfile', &wildoptions)
69endfunc
70
Bram Moolenaar6b915c02020-01-18 15:53:19 +010071func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020072 let caught = 'ok'
73 try
74 options
75 catch
76 let caught = v:throwpoint . "\n" . v:exception
77 endtry
78 call assert_equal('ok', caught)
79
Bram Moolenaare0b59492019-05-21 20:54:45 +020080 " Check if the option-window is opened horizontally.
81 wincmd j
82 call assert_notequal('option-window', bufname(''))
83 wincmd k
84 call assert_equal('option-window', bufname(''))
85 " close option-window
86 close
87
88 " Open the option-window vertically.
89 vert options
90 " Check if the option-window is opened vertically.
91 wincmd l
92 call assert_notequal('option-window', bufname(''))
93 wincmd h
94 call assert_equal('option-window', bufname(''))
95 " close option-window
96 close
97
Bram Moolenaar7a1637f2020-04-13 21:16:21 +020098 " Open the option-window at the top.
99 set splitbelow
100 topleft options
101 call assert_equal(1, winnr())
102 close
103
104 " Open the option-window at the bottom.
105 set nosplitbelow
106 botright options
107 call assert_equal(winnr('$'), winnr())
108 close
109 set splitbelow&
110
Bram Moolenaare0b59492019-05-21 20:54:45 +0200111 " Open the option-window in a new tab.
112 tab options
113 " Check if the option-window is opened in a tab.
114 normal gT
115 call assert_notequal('option-window', bufname(''))
116 normal gt
117 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200118 " close option-window
119 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200120
121 " Open the options window browse
122 if has('browse')
123 browse set
124 call assert_equal('option-window', bufname(''))
125 close
126 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100127endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200128
Bram Moolenaar1e115362019-01-09 23:01:02 +0100129func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200130 " Test that changing 'path' keeps two commas.
131 set path=foo,,bar
132 set path-=bar
133 set path+=bar
134 call assert_equal('foo,,bar', &path)
135
136 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100137endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200138
Dominique Pellef645ee42021-12-05 13:21:18 +0000139func Test_path_too_long()
140 exe 'set path=' .. repeat('x', 10000)
141 call assert_fails('find x', 'E854:')
142 set path&
143endfunc
144
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200145func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200146 CheckFeature signs
147 call assert_equal("auto", &signcolumn)
148 set signcolumn=yes
149 set signcolumn=no
150 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200151endfunc
152
Bram Moolenaard0b51382016-11-04 15:23:45 +0100153func Test_filetype_valid()
154 set ft=valid_name
155 call assert_equal("valid_name", &filetype)
156 set ft=valid-name
157 call assert_equal("valid-name", &filetype)
158
159 call assert_fails(":set ft=wrong;name", "E474:")
160 call assert_fails(":set ft=wrong\\\\name", "E474:")
161 call assert_fails(":set ft=wrong\\|name", "E474:")
162 call assert_fails(":set ft=wrong/name", "E474:")
163 call assert_fails(":set ft=wrong\\\nname", "E474:")
164 call assert_equal("valid-name", &filetype)
165
166 exe "set ft=trunc\x00name"
167 call assert_equal("trunc", &filetype)
168endfunc
169
170func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200171 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100172 set syn=valid_name
173 call assert_equal("valid_name", &syntax)
174 set syn=valid-name
175 call assert_equal("valid-name", &syntax)
176
177 call assert_fails(":set syn=wrong;name", "E474:")
178 call assert_fails(":set syn=wrong\\\\name", "E474:")
179 call assert_fails(":set syn=wrong\\|name", "E474:")
180 call assert_fails(":set syn=wrong/name", "E474:")
181 call assert_fails(":set syn=wrong\\\nname", "E474:")
182 call assert_equal("valid-name", &syntax)
183
184 exe "set syn=trunc\x00name"
185 call assert_equal("trunc", &syntax)
186endfunc
187
188func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200189 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100190 call assert_fails(":set kmp=valid_name", "E544:")
191 call assert_fails(":set kmp=valid_name", "valid_name")
192 call assert_fails(":set kmp=valid-name", "E544:")
193 call assert_fails(":set kmp=valid-name", "valid-name")
194
195 call assert_fails(":set kmp=wrong;name", "E474:")
196 call assert_fails(":set kmp=wrong\\\\name", "E474:")
197 call assert_fails(":set kmp=wrong\\|name", "E474:")
198 call assert_fails(":set kmp=wrong/name", "E474:")
199 call assert_fails(":set kmp=wrong\\\nname", "E474:")
200
201 call assert_fails(":set kmp=trunc\x00name", "E544:")
202 call assert_fails(":set kmp=trunc\x00name", "trunc")
203endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100204
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100205func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100206 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100207 exe 'set ' . a:name . '=/usr/share/dict/words'
208 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
209 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
210 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
211 exe 'set ' . a:name . '=/usr/share/dict\ words'
212 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100213
214 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100215 call assert_fails("set " . a:name . "=/not&there", "E474:")
216 call assert_fails("set " . a:name . "=/not>there", "E474:")
217 call assert_fails("set " . a:name . "=/not.*there", "E474:")
218endfunc
219
Bram Moolenaar60629d62017-02-23 18:08:56 +0100220func Test_cinkeys()
221 " This used to cause invalid memory access
222 set cindent cinkeys=0
223 norm a
224 set cindent& cinkeys&
225endfunc
226
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100227func Test_dictionary()
228 call Check_dir_option('dictionary')
229endfunc
230
231func Test_thesaurus()
232 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100233endfun
234
Bram Moolenaar226c5342017-02-17 14:53:15 +0100235func Test_complete()
236 " Trailing single backslash used to cause invalid memory access.
237 set complete=s\
238 new
239 call feedkeys("i\<C-N>\<Esc>", 'xt')
240 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200241 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100242 set complete&
243endfun
244
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100245func Test_set_completion()
246 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
247 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
248
Bram Moolenaar297610b2019-12-27 17:20:55 +0100249 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
250 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
251
252 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
253 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
254
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100255 " Expand boolan options. When doing :set no<Tab>
256 " vim displays the options names without "no" but completion uses "no...".
257 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
258 call assert_equal('"set nodiff digraph', @:)
259
260 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
261 call assert_equal('"set invdiff digraph', @:)
262
263 " Expand abbreviation of options.
264 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100265 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100266
267 " Expand current value
268 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
269 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
270
271 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
272 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
273
274 " Expand key codes.
275 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
276 call assert_equal('"set <Help> <Home>', @:)
277
278 " Expand terminal options.
279 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200280 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200281 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100282
283 " Expand directories.
284 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
285 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200286 call assert_notmatch(' ./summarize.vim ', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100287
288 " Expand files and directories.
289 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200290 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100291
292 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
293 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200294 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200295
296 " Expanding the option names
297 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
298 call assert_equal('"set all', @:)
299
300 " Expanding a second set of option names
301 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
302 call assert_equal('"set wrapscan all', @:)
303
304 " Expanding a special keycode
305 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
306 call assert_equal('"set <Home>', @:)
307
308 " Expanding an invalid special keycode
309 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
310 call assert_equal("\"set <abcd>\<Tab>", @:)
311
312 " Expanding a terminal keycode
313 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
314 call assert_equal("\"set t_AB", @:)
315
316 " Expanding an invalid option name
317 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
318 call assert_equal("\"set abcde=\<Tab>", @:)
319
320 " Expanding after a = for a boolean option
321 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
322 call assert_equal("\"set wrapscan=\<Tab>", @:)
323
324 " Expanding a numeric option
325 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
326 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
327
328 " Expanding a non-boolean option
329 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
330 call assert_equal("\"set invtabstop=", @:)
331
332 " Expand options for 'spellsuggest'
333 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
334 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
335
336 " Expand value for 'key'
337 set key=abcd
338 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
339 call assert_equal('"set key=*****', @:)
340 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100341
342 " Expand values for 'filetype'
343 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
344 call assert_equal('"set filetype=sshdconfig', @:)
345 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
346 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100347endfunc
348
349func Test_set_errors()
350 call assert_fails('set scroll=-1', 'E49:')
351 call assert_fails('set backupcopy=', 'E474:')
352 call assert_fails('set regexpengine=3', 'E474:')
353 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200354 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100355 call assert_fails('set colorcolumn=-a', 'E474:')
356 call assert_fails('set colorcolumn=a', 'E474:')
357 call assert_fails('set colorcolumn=1,', 'E474:')
358 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100359 call assert_fails('set cmdheight=-1', 'E487:')
360 call assert_fails('set cmdwinheight=-1', 'E487:')
361 if has('conceal')
362 call assert_fails('set conceallevel=-1', 'E487:')
363 call assert_fails('set conceallevel=4', 'E474:')
364 endif
365 call assert_fails('set helpheight=-1', 'E487:')
366 call assert_fails('set history=-1', 'E487:')
367 call assert_fails('set report=-1', 'E487:')
368 call assert_fails('set shiftwidth=-1', 'E487:')
369 call assert_fails('set sidescroll=-1', 'E487:')
370 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000371 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000372 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000373 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100374 call assert_fails('set textwidth=-1', 'E487:')
375 call assert_fails('set timeoutlen=-1', 'E487:')
376 call assert_fails('set updatecount=-1', 'E487:')
377 call assert_fails('set updatetime=-1', 'E487:')
378 call assert_fails('set winheight=-1', 'E487:')
379 call assert_fails('set tabstop!', 'E488:')
380 call assert_fails('set xxx', 'E518:')
381 call assert_fails('set beautify?', 'E519:')
382 call assert_fails('set undolevels=x', 'E521:')
383 call assert_fails('set tabstop=', 'E521:')
384 call assert_fails('set comments=-', 'E524:')
385 call assert_fails('set comments=a', 'E525:')
386 call assert_fails('set foldmarker=x', 'E536:')
387 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000388 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100389 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100390 call assert_fails('set rulerformat=%-', 'E539:')
391 call assert_fails('set rulerformat=%(', 'E542:')
392 call assert_fails('set rulerformat=%15(%%', 'E542:')
393 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100394 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100395 call assert_fails('set statusline=%{%', 'E540:')
396 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100397 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100398 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100399 call assert_fails('set tabline=%$', 'E539:')
400 call assert_fails('set tabline=%{', 'E540:')
401 call assert_fails('set tabline=%{%', 'E540:')
402 call assert_fails('set tabline=%{%}', 'E539:')
403 call assert_fails('set tabline=%(', 'E542:')
404 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100405
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100406 if has('cursorshape')
407 " This invalid value for 'guicursor' used to cause Vim to crash.
408 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
409 call assert_fails('set guicursor=i-ci', 'E545:')
410 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100411 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100412 call assert_fails('set guicursor=r-cr:horx', 'E548:')
413 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
414 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100415 if has('mouseshape')
416 call assert_fails('se mouseshape=i-r:x', 'E547:')
417 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100418 call assert_fails('set backupext=~ patchmode=~', 'E589:')
419 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200420 set winminheight& winheight&
421 set winheight=10 winminheight=10
422 call assert_fails('set winheight=9', 'E591:')
423 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100424 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200425 set winminwidth& winwidth&
426 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
427 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100428 call assert_fails("set showbreak=\x01", 'E595:')
429 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200430 call assert_fails('set tabstop??', 'E488:')
431 call assert_fails('set wrapscan!!', 'E488:')
432 call assert_fails('set tabstop&&', 'E488:')
433 call assert_fails('set wrapscan<<', 'E488:')
434 call assert_fails('set wrapscan=1', 'E474:')
435 call assert_fails('set autoindent@', 'E488:')
436 call assert_fails('set wildchar=<abc>', 'E474:')
437 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200438 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100439 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200440 call assert_fails('set pyxversion=6', 'E474:')
441 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200442 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200443 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100444 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
445 call assert_fails('set foldmarker={{{,', 'E474:')
446 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
447 call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:')
448 set listchars&
449 call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:')
450 set fillchars&
451 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
452 set nomodifiable
453 call assert_fails('set fileencoding=latin1', 'E21:')
454 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200455 call assert_fails('set t_#-&', 'E522:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100456endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100457
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000458func Test_set_encoding()
459 let save_encoding = &encoding
460
461 set enc=iso8859-1
462 call assert_equal('latin1', &enc)
463 set enc=iso8859_1
464 call assert_equal('latin1', &enc)
465 set enc=iso-8859-1
466 call assert_equal('latin1', &enc)
467 set enc=iso_8859_1
468 call assert_equal('latin1', &enc)
469 set enc=iso88591
470 call assert_equal('latin1', &enc)
471 set enc=iso8859
472 call assert_equal('latin1', &enc)
473 set enc=iso-8859
474 call assert_equal('latin1', &enc)
475 set enc=iso_8859
476 call assert_equal('latin1', &enc)
477 call assert_fails('set enc=iso8858', 'E474:')
478 call assert_equal('latin1', &enc)
479
480 let &encoding = save_encoding
481endfunc
482
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200483func CheckWasSet(name)
484 let verb_cm = execute('verbose set ' .. a:name .. '?')
485 call assert_match('Last set from.*test_options.vim', verb_cm)
486endfunc
487func CheckWasNotSet(name)
488 let verb_cm = execute('verbose set ' .. a:name .. '?')
489 call assert_notmatch('Last set from', verb_cm)
490endfunc
491
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200492" Must be executed before other tests that set 'term'.
493func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200494 CheckNotGui
495
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200496 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200497
498 let term_save = &term
499 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200500 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200501 let &term = term_save
502endfunc
503
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200504func Test_copy_context()
505 setlocal list
506 call CheckWasSet('list')
507 split
508 call CheckWasSet('list')
509 quit
510 setlocal nolist
511
512 set ai
513 call CheckWasSet('ai')
514 set filetype=perl
515 call CheckWasSet('filetype')
516 set fo=tcroq
517 call CheckWasSet('fo')
518
519 split Xsomebuf
520 call CheckWasSet('ai')
521 call CheckWasNotSet('filetype')
522 call CheckWasSet('fo')
523endfunc
524
Bram Moolenaar67391142017-02-19 21:07:04 +0100525func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200526 CheckUnix
527 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200528
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200529 " Setting 'ttytype' used to cause a double-free when exiting vim and
530 " when vim is compiled with -DEXITFREE.
531 set ttytype=ansi
532 call assert_equal('ansi', &ttytype)
533 call assert_equal(&ttytype, &term)
534 set ttytype=xterm
535 call assert_equal('xterm', &ttytype)
536 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200537 try
538 set ttytype=
539 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100540 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200541 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200542
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200543 " Some systems accept any terminal name and return dumb settings,
544 " check for failure of finding the entry and for missing 'cm' entry.
545 try
546 set ttytype=xxx
547 call assert_report('set ttytype=xxx did not fail')
548 catch /E522\|E437/
549 endtry
550
551 set ttytype&
552 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200553
554 if has('gui') && !has('gui_running')
555 call assert_fails('set term=gui', 'E531:')
556 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100557endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100558
559func Test_set_all()
560 set tw=75
561 set iskeyword=a-z,A-Z
562 set nosplitbelow
563 let out = execute('set all')
564 call assert_match('textwidth=75', out)
565 call assert_match('iskeyword=a-z,A-Z', out)
566 call assert_match('nosplitbelow', out)
567 set tw& iskeyword& splitbelow&
568endfunc
569
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100570func Test_set_one_column()
571 let out_mult = execute('set all')->split("\n")
572 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100573 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100574endfunc
575
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100576func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200577 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100578 if filereadable('opt_test.vim')
579 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100580 else
581 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100582 endif
583endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200584
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100585func Test_renderoptions()
586 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
587 " Doesn't hurt to do this on a non-Windows system.
588 if windowsversion() !~ '^[345]\.'
589 set renderoptions=type:directx
590 set rop=type:directx
591 endif
592endfunc
593
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200594func ResetIndentexpr()
595 set indentexpr=
596endfunc
597
598func Test_set_indentexpr()
599 " this was causing usage of freed memory
600 set indentexpr=ResetIndentexpr()
601 new
602 call feedkeys("i\<c-f>", 'x')
603 call assert_equal('', &indentexpr)
604 bwipe!
605endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200606
607func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100608 " Option 'backupskip' may contain several comma-separated path
609 " specifications if one or more of the environment variables TMPDIR, TMP,
610 " or TEMP is defined. To simplify testing, convert the string value into a
611 " list.
612 let bsklist = split(&bsk, ',')
613
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200614 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100615 let found = (index(bsklist, '/private/tmp/*') >= 0)
616 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200617 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100618 let found = (index(bsklist, '/tmp/*') >= 0)
619 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200620 endif
621
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100622 " If our test platform is Windows, the path(s) in option bsk will use
623 " backslash for the path separator and the components could be in short
624 " (8.3) format. As such, we need to replace the backslashes with forward
625 " slashes and convert the path components to long format. The expand()
626 " function will do this but it cannot handle comma-separated paths. This is
627 " why bsk was converted from a string into a list of strings above.
628 "
629 " One final complication is that the wildcard "/*" is at the end of each
630 " path and so expand() might return a list of matching files. To prevent
631 " this, we need to remove the wildcard before calling expand() and then
632 " append it afterwards.
633 if has('win32')
634 let item_nbr = 0
635 while item_nbr < len(bsklist)
636 let path_spec = bsklist[item_nbr]
637 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
638 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
639 let bsklist[item_nbr] = path_spec . '/*'
640 let item_nbr += 1
641 endwhile
642 endif
643
644 " Option bsk will also include these environment variables if defined.
645 " If they're defined, verify they appear in the option value.
646 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200647 if exists(var)
648 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100649 let varvalue = substitute(varvalue, '/$', '', '')
650 let varvalue .= '/*'
651 let found = (index(bsklist, varvalue) >= 0)
652 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200653 endif
654 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200655
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200656 " Duplicates from environment variables should be filtered out (option has
657 " P_NODUP). Run this in a separate instance and write v:errors in a file,
658 " so that we see what happens on startup.
659 let after =<< trim [CODE]
660 let bsklist = split(&backupskip, ',')
661 call assert_equal(uniq(copy(bsklist)), bsklist)
662 call writefile(['errors:'] + v:errors, 'Xtestout')
663 qall
664 [CODE]
665 call writefile(after, 'Xafter')
666 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
667
668 let saveenv = {}
669 for var in ['TMPDIR', 'TMP', 'TEMP']
670 let saveenv[var] = getenv(var)
671 call setenv(var, '/duplicate/path')
672 endfor
673
674 exe 'silent !' . cmd
675 call assert_equal(['errors:'], readfile('Xtestout'))
676
677 " restore environment variables
678 for var in ['TMPDIR', 'TMP', 'TEMP']
679 call setenv(var, saveenv[var])
680 endfor
681
682 call delete('Xtestout')
683 call delete('Xafter')
684
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200685 " Duplicates should be filtered out (option has P_NODUP)
686 let backupskip = &backupskip
687 set backupskip=
688 set backupskip+=/test/dir
689 set backupskip+=/other/dir
690 set backupskip+=/test/dir
691 call assert_equal('/test/dir,/other/dir', &backupskip)
692 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200693endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200694
695func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200696 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200697
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200698 " Test copy option from current buffer in window
699 split
700 enew
701 setlocal numberwidth=5
702 wincmd w
703 call assert_equal(4,&numberwidth)
704 bnext
705 call assert_equal(5,&numberwidth)
706 bw!
707 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200708
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200709 " Test copy value from window that used to be display the buffer
710 split
711 enew
712 setlocal numberwidth=6
713 bnext
714 wincmd w
715 call assert_equal(4,&numberwidth)
716 bnext
717 call assert_equal(6,&numberwidth)
718 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200719
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200720 " Test that if buffer is current, don't use the stale cached value
721 " from the last time the buffer was displayed.
722 split
723 enew
724 setlocal numberwidth=7
725 bnext
726 bnext
727 setlocal numberwidth=8
728 wincmd w
729 call assert_equal(4,&numberwidth)
730 bnext
731 call assert_equal(8,&numberwidth)
732 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200733
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200734 " Test value is not copied if window already has seen the buffer
735 enew
736 split
737 setlocal numberwidth=9
738 bnext
739 setlocal numberwidth=10
740 wincmd w
741 call assert_equal(4,&numberwidth)
742 bnext
743 call assert_equal(4,&numberwidth)
744 bw!
745
746 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200747endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200748
749func Test_shortmess_F()
750 new
751 call assert_match('\[No Name\]', execute('file'))
752 set shortmess+=F
753 call assert_match('\[No Name\]', execute('file'))
754 call assert_match('^\s*$', execute('file foo'))
755 call assert_match('foo', execute('file'))
756 set shortmess-=F
757 call assert_match('bar', execute('file bar'))
758 call assert_match('bar', execute('file'))
759 set shortmess&
760 bwipe
761endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200762
763func Test_shortmess_F2()
764 e file1
765 e file2
766 call assert_match('file1', execute('bn', ''))
767 call assert_match('file2', execute('bn', ''))
768 set shortmess+=F
769 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200770 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200771 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200772 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200773 set hidden
774 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200775 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200776 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200777 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200778 set nohidden
779 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200780 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200781 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200782 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200783 set shortmess&
784 call assert_match('file1', execute('bn', ''))
785 call assert_match('file2', execute('bn', ''))
786 bwipe
787 bwipe
788endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100789
790func Test_local_scrolloff()
791 set so=5
792 set siso=7
793 split
794 call assert_equal(5, &so)
795 setlocal so=3
796 call assert_equal(3, &so)
797 wincmd w
798 call assert_equal(5, &so)
799 wincmd w
800 setlocal so<
801 call assert_equal(5, &so)
802 setlocal so=0
803 call assert_equal(0, &so)
804 setlocal so=-1
805 call assert_equal(5, &so)
806
807 call assert_equal(7, &siso)
808 setlocal siso=3
809 call assert_equal(3, &siso)
810 wincmd w
811 call assert_equal(7, &siso)
812 wincmd w
813 setlocal siso<
814 call assert_equal(7, &siso)
815 setlocal siso=0
816 call assert_equal(0, &siso)
817 setlocal siso=-1
818 call assert_equal(7, &siso)
819
820 close
821 set so&
822 set siso&
823endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200824
825func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100826 CheckFunction reltimefloat
827
Bram Moolenaar449ac472019-04-03 21:42:35 +0200828 new
829 call setline(1, 'empty')
830 redraw
831 set writedelay=10
832 let start = reltime()
833 call setline(1, repeat('x', 70))
834 redraw
835 let elapsed = reltimefloat(reltime(start))
836 set writedelay=0
837 " With 'writedelay' set should take at least 30 * 10 msec
838 call assert_inrange(30 * 0.01, 999.0, elapsed)
839
840 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200841endfunc
842
843func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200844 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200845 set visualbell
846 call assert_beeps('normal 0h')
847 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200848 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200849endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100850
851" Test for the 'write' option
852func Test_write()
853 new
854 call setline(1, ['L1'])
855 set nowrite
856 call assert_fails('write Xfile', 'E142:')
857 set write
858 close!
859endfunc
860
861" Test for 'buftype' option
862func Test_buftype()
863 new
864 call setline(1, ['L1'])
865 set buftype=nowrite
866 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100867
868 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
869 exe 'set buftype=' .. val
870 call writefile(['something'], 'XBuftype')
871 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
872 endfor
873
874 call delete('XBuftype')
875 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100876endfunc
877
Bram Moolenaar578fe942020-02-27 21:32:51 +0100878" Test for the 'rightleftcmd' option
879func Test_rightleftcmd()
880 CheckFeature rightleft
881 set rightleft
882 set rightleftcmd
883
884 let g:l = []
885 func AddPos()
886 call add(g:l, screencol())
887 return ''
888 endfunc
889 cmap <expr> <F2> AddPos()
890
891 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
892 \ "\<Left>\<F2>\<Esc>", 'xt')
893 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
894
895 cunmap <F2>
896 unlet g:l
897 set rightleftcmd&
898 set rightleft&
899endfunc
900
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200901" Test for the "debug" option
902func Test_debug_option()
903 set debug=beep
904 exe "normal \<C-c>"
905 call assert_equal('Beep!', Screenline(&lines))
906 set debug&
907endfunc
908
Bram Moolenaar004a6782020-04-11 17:09:31 +0200909" Test for the default CDPATH option
910func Test_opt_default_cdpath()
911 CheckFeature file_in_path
912 let after =<< trim [CODE]
913 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
914 call writefile(v:errors, 'Xtestout')
915 qall
916 [CODE]
917 if has('unix')
918 let $CDPATH='/path/to/dir1:/path/to/dir2'
919 else
920 let $CDPATH='/path/to/dir1;/path/to/dir2'
921 endif
922 if RunVim([], after, '')
923 call assert_equal([], readfile('Xtestout'))
924 call delete('Xtestout')
925 endif
926endfunc
927
928" Test for setting keycodes using set
929func Test_opt_set_keycode()
930 call assert_fails('set <t_k1=l', 'E474:')
931 call assert_fails('set <Home=l', 'E474:')
932 set <t_k9>=abcd
933 call assert_equal('abcd', &t_k9)
934 set <t_k9>&
935 set <F9>=xyz
936 call assert_equal('xyz', &t_k9)
937 set <t_k9>&
938endfunc
939
940" Test for changing options in a sandbox
941func Test_opt_sandbox()
942 for opt in ['backupdir', 'cdpath', 'exrc']
943 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200944 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200945 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200946 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200947endfunc
948
949" Test for setting an option with local value to global value
950func Test_opt_local_to_global()
951 setglobal equalprg=gprg
952 setlocal equalprg=lprg
953 call assert_equal('gprg', &g:equalprg)
954 call assert_equal('lprg', &l:equalprg)
955 call assert_equal('lprg', &equalprg)
956 set equalprg<
957 call assert_equal('', &l:equalprg)
958 call assert_equal('gprg', &equalprg)
959 setglobal equalprg=gnewprg
960 setlocal equalprg=lnewprg
961 setlocal equalprg<
962 call assert_equal('gnewprg', &l:equalprg)
963 call assert_equal('gnewprg', &equalprg)
964 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200965
966 " Test for setting the global/local value of a boolean option
967 setglobal autoread
968 setlocal noautoread
969 call assert_false(&autoread)
970 set autoread<
971 call assert_true(&autoread)
972 setglobal noautoread
973 setlocal autoread
974 setlocal autoread<
975 call assert_false(&autoread)
976 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +0200977endfunc
978
Dominique Pelle042414f2021-07-12 21:43:19 +0200979func Test_set_in_sandbox()
980 " Some boolean options cannot be set in sandbox, some can.
981 call assert_fails('sandbox set modelineexpr', 'E48:')
982 sandbox set number
983 call assert_true(&number)
984 set number&
985
986 " Some boolean options cannot be set in sandbox, some can.
987 if has('python') || has('python3')
988 call assert_fails('sandbox set pyxversion=3', 'E48:')
989 endif
990 sandbox set tabstop=4
991 call assert_equal(4, &tabstop)
992 set tabstop&
993
994 " Some string options cannot be set in sandbox, some can.
995 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
996 sandbox set filetype=perl
997 call assert_equal('perl', &filetype)
998 set filetype&
999endfunc
1000
Bram Moolenaar004a6782020-04-11 17:09:31 +02001001" Test for incrementing, decrementing and multiplying a number option value
1002func Test_opt_num_op()
1003 set shiftwidth=4
1004 set sw+=2
1005 call assert_equal(6, &sw)
1006 set sw-=2
1007 call assert_equal(4, &sw)
1008 set sw^=2
1009 call assert_equal(8, &sw)
1010 set shiftwidth&
1011endfunc
1012
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001013" Test for setting option values using v:false and v:true
1014func Test_opt_boolean()
1015 set number&
1016 set number
1017 call assert_equal(1, &nu)
1018 set nonu
1019 call assert_equal(0, &nu)
1020 let &nu = v:true
1021 call assert_equal(1, &nu)
1022 let &nu = v:false
1023 call assert_equal(0, &nu)
1024 set number&
1025endfunc
1026
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001027" Test for the 'window' option
1028func Test_window_opt()
1029 " Needs only one open widow
1030 %bw!
1031 call setline(1, range(1, 8))
1032 set window=5
1033 exe "normal \<C-F>"
1034 call assert_equal(4, line('w0'))
1035 exe "normal \<C-F>"
1036 call assert_equal(7, line('w0'))
1037 exe "normal \<C-F>"
1038 call assert_equal(8, line('w0'))
1039 exe "normal \<C-B>"
1040 call assert_equal(5, line('w0'))
1041 exe "normal \<C-B>"
1042 call assert_equal(2, line('w0'))
1043 exe "normal \<C-B>"
1044 call assert_equal(1, line('w0'))
1045 set window=1
1046 exe "normal gg\<C-F>"
1047 call assert_equal(2, line('w0'))
1048 exe "normal \<C-F>"
1049 call assert_equal(3, line('w0'))
1050 exe "normal \<C-B>"
1051 call assert_equal(2, line('w0'))
1052 exe "normal \<C-B>"
1053 call assert_equal(1, line('w0'))
1054 enew!
1055 set window&
1056endfunc
1057
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001058" Test for the 'winminheight' option
1059func Test_opt_winminheight()
1060 only!
1061 let &winheight = &lines + 4
1062 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1063 call assert_true(&winminheight <= &lines)
1064 set winminheight&
1065 set winheight&
1066endfunc
1067
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001068func Test_opt_winminheight_term()
1069 CheckRunVimInTerminal
1070
1071 " The tabline should be taken into account.
1072 let lines =<< trim END
1073 set wmh=0 stal=2
1074 below sp | wincmd _
1075 below sp | wincmd _
1076 below sp | wincmd _
1077 below sp
1078 END
1079 call writefile(lines, 'Xwinminheight')
1080 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1081 call term_sendkeys(buf, ":set wmh=1\n")
1082 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1083
1084 call StopVimInTerminal(buf)
1085 call delete('Xwinminheight')
1086endfunc
1087
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001088func Test_opt_winminheight_term_tabs()
1089 CheckRunVimInTerminal
1090
1091 " The tabline should be taken into account.
1092 let lines =<< trim END
1093 set wmh=0 stal=2
1094 split
1095 split
1096 split
1097 split
1098 tabnew
1099 END
1100 call writefile(lines, 'Xwinminheight')
1101 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1102 call term_sendkeys(buf, ":set wmh=1\n")
1103 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1104
1105 call StopVimInTerminal(buf)
1106 call delete('Xwinminheight')
1107endfunc
1108
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001109" Test for the 'winminwidth' option
1110func Test_opt_winminwidth()
1111 only!
1112 let &winwidth = &columns + 4
1113 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1114 call assert_true(&winminwidth <= &columns)
1115 set winminwidth&
1116 set winwidth&
1117endfunc
1118
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001119" Test for setting option value containing spaces with isfname+=32
1120func Test_isfname_with_options()
1121 set isfname+=32
1122 setlocal keywordprg=:term\ help.exe
1123 call assert_equal(':term help.exe', &keywordprg)
1124 set isfname&
1125 setlocal keywordprg&
1126endfunc
1127
Bram Moolenaar74667062020-12-28 15:41:41 +01001128" Test that resetting laststatus does change scroll option
1129func Test_opt_reset_scroll()
1130 CheckRunVimInTerminal
1131 let vimrc =<< trim [CODE]
1132 set scroll=2
1133 set laststatus=2
1134 [CODE]
1135 call writefile(vimrc, 'Xscroll')
1136 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1137 call term_sendkeys(buf, ":verbose set scroll?\n")
1138 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1139 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
1140 call StopVimInTerminal(buf)
1141
1142 " clean up
1143 call delete('Xscroll')
1144endfunc
1145
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001146" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1147func Test_VIM_POSIX()
1148 let saved_VIM_POSIX = getenv("VIM_POSIX")
1149
1150 call setenv('VIM_POSIX', "1")
1151 let after =<< trim [CODE]
1152 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1153 qall
1154 [CODE]
1155 if RunVim([], after, '')
1156 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1157 \ 'AS'], readfile('X_VIM_POSIX'))
1158 endif
1159
1160 call setenv('VIM_POSIX', v:null)
1161 let after =<< trim [CODE]
1162 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1163 qall
1164 [CODE]
1165 if RunVim([], after, '')
1166 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1167 \ 'S'], readfile('X_VIM_POSIX'))
1168 endif
1169
1170 call delete('X_VIM_POSIX')
1171 call setenv('VIM_POSIX', saved_VIM_POSIX)
1172endfunc
1173
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001174" Test for setting an option to a Vi or Vim default
1175func Test_opt_default()
1176 set formatoptions&vi
1177 call assert_equal('vt', &formatoptions)
1178 set formatoptions&vim
1179 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001180
1181 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1182 set fencs=latin1
1183 set fencs&
1184 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1185 set fencs=latin1
1186 set all&
1187 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001188endfunc
1189
1190" Test for the 'cmdheight' option
1191func Test_cmdheight()
1192 %bw!
1193 let ht = &lines
1194 set cmdheight=9999
1195 call assert_equal(1, winheight(0))
1196 call assert_equal(ht - 1, &cmdheight)
1197 set cmdheight&
1198endfunc
1199
Dominique Pelle923dce22021-11-21 11:36:04 +00001200" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001201func Test_opt_control_char()
1202 set wildchar=^v
1203 call assert_equal("\<C-V>", nr2char(&wildchar))
1204 set wildcharm=^r
1205 call assert_equal("\<C-R>", nr2char(&wildcharm))
1206 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1207 set wildchar& wildcharm&
1208endfunc
1209
1210" Test for the 'errorbells' option
1211func Test_opt_errorbells()
1212 set errorbells
1213 call assert_beeps('s/a1b2/x1y2/')
1214 set noerrorbells
1215endfunc
1216
Dominique Pelle042414f2021-07-12 21:43:19 +02001217func Test_opt_scrolljump()
1218 help
1219 resize 10
1220
1221 " Test with positive 'scrolljump'.
1222 set scrolljump=2
1223 norm! Lj
1224 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1225 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1226 \ winsaveview())
1227
1228 " Test with negative 'scrolljump' (percentage of window height).
1229 set scrolljump=-40
1230 norm! ggLj
1231 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1232 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1233 \ winsaveview())
1234
1235 set scrolljump&
1236 bw
1237endfunc
1238
Bakudankun29f3a452021-12-11 12:28:08 +00001239" Test for the 'cdhome' option
1240func Test_opt_cdhome()
1241 if has('unix') || has('vms')
1242 throw 'Skipped: only works on non-Unix'
1243 endif
1244
1245 set cdhome&
1246 call assert_equal(0, &cdhome)
1247 set cdhome
1248
1249 " This paragraph is copied from Test_cd_no_arg().
1250 let path = getcwd()
1251 cd
1252 call assert_equal($HOME, getcwd())
1253 call assert_notequal(path, getcwd())
1254 exe 'cd ' .. fnameescape(path)
1255 call assert_equal(path, getcwd())
1256
1257 set cdhome&
1258endfunc
1259
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001260" vim: shiftwidth=2 sts=2 expandtab