blob: fbe592d16519f52c7373553611bff161d2ad10c3 [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
zeertzjq0519ce02022-05-09 12:16:19 +010051" Test for getting the value of 'pastetoggle'
52func Test_pastetoggle()
53 " character with K_SPECIAL byte
54 let &pastetoggle = '…'
55 call assert_equal('…', &pastetoggle)
56 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
57
58 " modified character with K_SPECIAL byte
59 let &pastetoggle = '<M-…>'
60 call assert_equal('<M-…>', &pastetoggle)
61 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
62
63 " illegal bytes
64 let str = ":\x7f:\x80:\x90:\xd0:"
65 let &pastetoggle = str
66 call assert_equal(str, &pastetoggle)
67 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
68 unlet str
69endfunc
70
Bram Moolenaar1e115362019-01-09 23:01:02 +010071func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010072 " Empty 'wildchar' used to access invalid memory.
73 call assert_fails('set wildchar=', 'E521:')
74 call assert_fails('set wildchar=abc', 'E521:')
75 set wildchar=<Esc>
76 let a=execute('set wildchar?')
77 call assert_equal("\n wildchar=<Esc>", a)
78 set wildchar=27
79 let a=execute('set wildchar?')
80 call assert_equal("\n wildchar=<Esc>", a)
81 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010082endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010083
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020084func Test_wildoptions()
85 set wildoptions=
86 set wildoptions+=tagfile
87 set wildoptions+=tagfile
88 call assert_equal('tagfile', &wildoptions)
89endfunc
90
Bram Moolenaar6b915c02020-01-18 15:53:19 +010091func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020092 let caught = 'ok'
93 try
94 options
95 catch
96 let caught = v:throwpoint . "\n" . v:exception
97 endtry
98 call assert_equal('ok', caught)
99
Bram Moolenaare0b59492019-05-21 20:54:45 +0200100 " Check if the option-window is opened horizontally.
101 wincmd j
102 call assert_notequal('option-window', bufname(''))
103 wincmd k
104 call assert_equal('option-window', bufname(''))
105 " close option-window
106 close
107
108 " Open the option-window vertically.
109 vert options
110 " Check if the option-window is opened vertically.
111 wincmd l
112 call assert_notequal('option-window', bufname(''))
113 wincmd h
114 call assert_equal('option-window', bufname(''))
115 " close option-window
116 close
117
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200118 " Open the option-window at the top.
119 set splitbelow
120 topleft options
121 call assert_equal(1, winnr())
122 close
123
124 " Open the option-window at the bottom.
125 set nosplitbelow
126 botright options
127 call assert_equal(winnr('$'), winnr())
128 close
129 set splitbelow&
130
Bram Moolenaare0b59492019-05-21 20:54:45 +0200131 " Open the option-window in a new tab.
132 tab options
133 " Check if the option-window is opened in a tab.
134 normal gT
135 call assert_notequal('option-window', bufname(''))
136 normal gt
137 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200138 " close option-window
139 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200140
141 " Open the options window browse
142 if has('browse')
143 browse set
144 call assert_equal('option-window', bufname(''))
145 close
146 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100147endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200148
Bram Moolenaar1e115362019-01-09 23:01:02 +0100149func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200150 " Test that changing 'path' keeps two commas.
151 set path=foo,,bar
152 set path-=bar
153 set path+=bar
154 call assert_equal('foo,,bar', &path)
155
156 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100157endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200158
Dominique Pellef645ee42021-12-05 13:21:18 +0000159func Test_path_too_long()
160 exe 'set path=' .. repeat('x', 10000)
161 call assert_fails('find x', 'E854:')
162 set path&
163endfunc
164
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200165func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200166 CheckFeature signs
167 call assert_equal("auto", &signcolumn)
168 set signcolumn=yes
169 set signcolumn=no
170 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200171endfunc
172
Bram Moolenaard0b51382016-11-04 15:23:45 +0100173func Test_filetype_valid()
174 set ft=valid_name
175 call assert_equal("valid_name", &filetype)
176 set ft=valid-name
177 call assert_equal("valid-name", &filetype)
178
179 call assert_fails(":set ft=wrong;name", "E474:")
180 call assert_fails(":set ft=wrong\\\\name", "E474:")
181 call assert_fails(":set ft=wrong\\|name", "E474:")
182 call assert_fails(":set ft=wrong/name", "E474:")
183 call assert_fails(":set ft=wrong\\\nname", "E474:")
184 call assert_equal("valid-name", &filetype)
185
186 exe "set ft=trunc\x00name"
187 call assert_equal("trunc", &filetype)
188endfunc
189
190func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200191 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100192 set syn=valid_name
193 call assert_equal("valid_name", &syntax)
194 set syn=valid-name
195 call assert_equal("valid-name", &syntax)
196
197 call assert_fails(":set syn=wrong;name", "E474:")
198 call assert_fails(":set syn=wrong\\\\name", "E474:")
199 call assert_fails(":set syn=wrong\\|name", "E474:")
200 call assert_fails(":set syn=wrong/name", "E474:")
201 call assert_fails(":set syn=wrong\\\nname", "E474:")
202 call assert_equal("valid-name", &syntax)
203
204 exe "set syn=trunc\x00name"
205 call assert_equal("trunc", &syntax)
206endfunc
207
208func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200209 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100210 call assert_fails(":set kmp=valid_name", "E544:")
211 call assert_fails(":set kmp=valid_name", "valid_name")
212 call assert_fails(":set kmp=valid-name", "E544:")
213 call assert_fails(":set kmp=valid-name", "valid-name")
214
215 call assert_fails(":set kmp=wrong;name", "E474:")
216 call assert_fails(":set kmp=wrong\\\\name", "E474:")
217 call assert_fails(":set kmp=wrong\\|name", "E474:")
218 call assert_fails(":set kmp=wrong/name", "E474:")
219 call assert_fails(":set kmp=wrong\\\nname", "E474:")
220
221 call assert_fails(":set kmp=trunc\x00name", "E544:")
222 call assert_fails(":set kmp=trunc\x00name", "trunc")
223endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100224
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100225func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100226 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100227 exe 'set ' . a:name . '=/usr/share/dict/words'
228 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
229 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
230 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
231 exe 'set ' . a:name . '=/usr/share/dict\ words'
232 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100233
234 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100235 call assert_fails("set " . a:name . "=/not&there", "E474:")
236 call assert_fails("set " . a:name . "=/not>there", "E474:")
237 call assert_fails("set " . a:name . "=/not.*there", "E474:")
238endfunc
239
Bram Moolenaar60629d62017-02-23 18:08:56 +0100240func Test_cinkeys()
241 " This used to cause invalid memory access
242 set cindent cinkeys=0
243 norm a
244 set cindent& cinkeys&
245endfunc
246
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100247func Test_dictionary()
248 call Check_dir_option('dictionary')
249endfunc
250
251func Test_thesaurus()
252 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100253endfun
254
Bram Moolenaar226c5342017-02-17 14:53:15 +0100255func Test_complete()
256 " Trailing single backslash used to cause invalid memory access.
257 set complete=s\
258 new
259 call feedkeys("i\<C-N>\<Esc>", 'xt')
260 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200261 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100262 set complete&
263endfun
264
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100265func Test_set_completion()
266 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
267 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
268
Bram Moolenaar297610b2019-12-27 17:20:55 +0100269 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
270 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
271
272 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
273 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
274
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100275 " Expand boolan options. When doing :set no<Tab>
276 " vim displays the options names without "no" but completion uses "no...".
277 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
278 call assert_equal('"set nodiff digraph', @:)
279
280 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
281 call assert_equal('"set invdiff digraph', @:)
282
283 " Expand abbreviation of options.
284 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100285 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100286
287 " Expand current value
288 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
289 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
290
291 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
292 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
293
294 " Expand key codes.
295 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
296 call assert_equal('"set <Help> <Home>', @:)
297
298 " Expand terminal options.
299 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200300 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200301 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100302
303 " Expand directories.
304 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
305 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200306 call assert_notmatch(' ./summarize.vim ', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100307
308 " Expand files and directories.
309 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200310 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100311
312 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
313 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200314 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200315
316 " Expanding the option names
317 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
318 call assert_equal('"set all', @:)
319
320 " Expanding a second set of option names
321 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
322 call assert_equal('"set wrapscan all', @:)
323
324 " Expanding a special keycode
325 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
326 call assert_equal('"set <Home>', @:)
327
328 " Expanding an invalid special keycode
329 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
330 call assert_equal("\"set <abcd>\<Tab>", @:)
331
332 " Expanding a terminal keycode
333 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
334 call assert_equal("\"set t_AB", @:)
335
336 " Expanding an invalid option name
337 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
338 call assert_equal("\"set abcde=\<Tab>", @:)
339
340 " Expanding after a = for a boolean option
341 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
342 call assert_equal("\"set wrapscan=\<Tab>", @:)
343
344 " Expanding a numeric option
345 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
346 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
347
348 " Expanding a non-boolean option
349 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
350 call assert_equal("\"set invtabstop=", @:)
351
352 " Expand options for 'spellsuggest'
353 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
354 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
355
356 " Expand value for 'key'
357 set key=abcd
358 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
359 call assert_equal('"set key=*****', @:)
360 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100361
362 " Expand values for 'filetype'
363 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
364 call assert_equal('"set filetype=sshdconfig', @:)
365 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
366 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100367endfunc
368
369func Test_set_errors()
370 call assert_fails('set scroll=-1', 'E49:')
371 call assert_fails('set backupcopy=', 'E474:')
372 call assert_fails('set regexpengine=3', 'E474:')
373 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200374 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100375 call assert_fails('set colorcolumn=-a', 'E474:')
376 call assert_fails('set colorcolumn=a', 'E474:')
377 call assert_fails('set colorcolumn=1,', 'E474:')
378 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100379 call assert_fails('set cmdheight=-1', 'E487:')
380 call assert_fails('set cmdwinheight=-1', 'E487:')
381 if has('conceal')
382 call assert_fails('set conceallevel=-1', 'E487:')
383 call assert_fails('set conceallevel=4', 'E474:')
384 endif
385 call assert_fails('set helpheight=-1', 'E487:')
386 call assert_fails('set history=-1', 'E487:')
387 call assert_fails('set report=-1', 'E487:')
388 call assert_fails('set shiftwidth=-1', 'E487:')
389 call assert_fails('set sidescroll=-1', 'E487:')
390 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000391 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000392 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000393 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100394 call assert_fails('set textwidth=-1', 'E487:')
395 call assert_fails('set timeoutlen=-1', 'E487:')
396 call assert_fails('set updatecount=-1', 'E487:')
397 call assert_fails('set updatetime=-1', 'E487:')
398 call assert_fails('set winheight=-1', 'E487:')
399 call assert_fails('set tabstop!', 'E488:')
400 call assert_fails('set xxx', 'E518:')
401 call assert_fails('set beautify?', 'E519:')
402 call assert_fails('set undolevels=x', 'E521:')
403 call assert_fails('set tabstop=', 'E521:')
404 call assert_fails('set comments=-', 'E524:')
405 call assert_fails('set comments=a', 'E525:')
406 call assert_fails('set foldmarker=x', 'E536:')
407 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000408 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100409 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100410 call assert_fails('set rulerformat=%-', 'E539:')
411 call assert_fails('set rulerformat=%(', 'E542:')
412 call assert_fails('set rulerformat=%15(%%', 'E542:')
413 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100414 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100415 call assert_fails('set statusline=%{%', 'E540:')
416 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100417 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100418 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100419 call assert_fails('set tabline=%$', 'E539:')
420 call assert_fails('set tabline=%{', 'E540:')
421 call assert_fails('set tabline=%{%', 'E540:')
422 call assert_fails('set tabline=%{%}', 'E539:')
423 call assert_fails('set tabline=%(', 'E542:')
424 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100425
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100426 if has('cursorshape')
427 " This invalid value for 'guicursor' used to cause Vim to crash.
428 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
429 call assert_fails('set guicursor=i-ci', 'E545:')
430 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100431 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100432 call assert_fails('set guicursor=r-cr:horx', 'E548:')
433 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
434 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100435 if has('mouseshape')
436 call assert_fails('se mouseshape=i-r:x', 'E547:')
437 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100438 call assert_fails('set backupext=~ patchmode=~', 'E589:')
439 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200440 set winminheight& winheight&
441 set winheight=10 winminheight=10
442 call assert_fails('set winheight=9', 'E591:')
443 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100444 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200445 set winminwidth& winwidth&
446 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
447 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100448 call assert_fails("set showbreak=\x01", 'E595:')
449 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200450 call assert_fails('set tabstop??', 'E488:')
451 call assert_fails('set wrapscan!!', 'E488:')
452 call assert_fails('set tabstop&&', 'E488:')
453 call assert_fails('set wrapscan<<', 'E488:')
454 call assert_fails('set wrapscan=1', 'E474:')
455 call assert_fails('set autoindent@', 'E488:')
456 call assert_fails('set wildchar=<abc>', 'E474:')
457 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200458 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100459 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200460 call assert_fails('set pyxversion=6', 'E474:')
461 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200462 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200463 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100464 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
465 call assert_fails('set foldmarker={{{,', 'E474:')
466 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
467 call assert_fails('set listchars=trail ambiwidth=double', 'E834:')
468 set listchars&
469 call assert_fails('set fillchars=stl ambiwidth=double', 'E835:')
470 set fillchars&
471 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
472 set nomodifiable
473 call assert_fails('set fileencoding=latin1', 'E21:')
474 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200475 call assert_fails('set t_#-&', 'E522:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100476endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100477
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000478func Test_set_encoding()
479 let save_encoding = &encoding
480
481 set enc=iso8859-1
482 call assert_equal('latin1', &enc)
483 set enc=iso8859_1
484 call assert_equal('latin1', &enc)
485 set enc=iso-8859-1
486 call assert_equal('latin1', &enc)
487 set enc=iso_8859_1
488 call assert_equal('latin1', &enc)
489 set enc=iso88591
490 call assert_equal('latin1', &enc)
491 set enc=iso8859
492 call assert_equal('latin1', &enc)
493 set enc=iso-8859
494 call assert_equal('latin1', &enc)
495 set enc=iso_8859
496 call assert_equal('latin1', &enc)
497 call assert_fails('set enc=iso8858', 'E474:')
498 call assert_equal('latin1', &enc)
499
500 let &encoding = save_encoding
501endfunc
502
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200503func CheckWasSet(name)
504 let verb_cm = execute('verbose set ' .. a:name .. '?')
505 call assert_match('Last set from.*test_options.vim', verb_cm)
506endfunc
507func CheckWasNotSet(name)
508 let verb_cm = execute('verbose set ' .. a:name .. '?')
509 call assert_notmatch('Last set from', verb_cm)
510endfunc
511
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200512" Must be executed before other tests that set 'term'.
513func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200514 CheckNotGui
515
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200516 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200517
518 let term_save = &term
519 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200520 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200521 let &term = term_save
522endfunc
523
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200524func Test_copy_context()
525 setlocal list
526 call CheckWasSet('list')
527 split
528 call CheckWasSet('list')
529 quit
530 setlocal nolist
531
532 set ai
533 call CheckWasSet('ai')
534 set filetype=perl
535 call CheckWasSet('filetype')
536 set fo=tcroq
537 call CheckWasSet('fo')
538
539 split Xsomebuf
540 call CheckWasSet('ai')
541 call CheckWasNotSet('filetype')
542 call CheckWasSet('fo')
543endfunc
544
Bram Moolenaar67391142017-02-19 21:07:04 +0100545func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200546 CheckUnix
547 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200548
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200549 " Setting 'ttytype' used to cause a double-free when exiting vim and
550 " when vim is compiled with -DEXITFREE.
551 set ttytype=ansi
552 call assert_equal('ansi', &ttytype)
553 call assert_equal(&ttytype, &term)
554 set ttytype=xterm
555 call assert_equal('xterm', &ttytype)
556 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200557 try
558 set ttytype=
559 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100560 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200561 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200562
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200563 " Some systems accept any terminal name and return dumb settings,
564 " check for failure of finding the entry and for missing 'cm' entry.
565 try
566 set ttytype=xxx
567 call assert_report('set ttytype=xxx did not fail')
568 catch /E522\|E437/
569 endtry
570
571 set ttytype&
572 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200573
574 if has('gui') && !has('gui_running')
575 call assert_fails('set term=gui', 'E531:')
576 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100577endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100578
579func Test_set_all()
580 set tw=75
581 set iskeyword=a-z,A-Z
582 set nosplitbelow
583 let out = execute('set all')
584 call assert_match('textwidth=75', out)
585 call assert_match('iskeyword=a-z,A-Z', out)
586 call assert_match('nosplitbelow', out)
587 set tw& iskeyword& splitbelow&
588endfunc
589
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100590func Test_set_one_column()
591 let out_mult = execute('set all')->split("\n")
592 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100593 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100594endfunc
595
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100596func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200597 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100598 if filereadable('opt_test.vim')
599 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100600 else
601 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100602 endif
603endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200604
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100605func Test_renderoptions()
606 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
607 " Doesn't hurt to do this on a non-Windows system.
608 if windowsversion() !~ '^[345]\.'
609 set renderoptions=type:directx
610 set rop=type:directx
611 endif
612endfunc
613
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200614func ResetIndentexpr()
615 set indentexpr=
616endfunc
617
618func Test_set_indentexpr()
619 " this was causing usage of freed memory
620 set indentexpr=ResetIndentexpr()
621 new
622 call feedkeys("i\<c-f>", 'x')
623 call assert_equal('', &indentexpr)
624 bwipe!
625endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200626
627func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100628 " Option 'backupskip' may contain several comma-separated path
629 " specifications if one or more of the environment variables TMPDIR, TMP,
630 " or TEMP is defined. To simplify testing, convert the string value into a
631 " list.
632 let bsklist = split(&bsk, ',')
633
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200634 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100635 let found = (index(bsklist, '/private/tmp/*') >= 0)
636 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200637 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100638 let found = (index(bsklist, '/tmp/*') >= 0)
639 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200640 endif
641
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100642 " If our test platform is Windows, the path(s) in option bsk will use
643 " backslash for the path separator and the components could be in short
644 " (8.3) format. As such, we need to replace the backslashes with forward
645 " slashes and convert the path components to long format. The expand()
646 " function will do this but it cannot handle comma-separated paths. This is
647 " why bsk was converted from a string into a list of strings above.
648 "
649 " One final complication is that the wildcard "/*" is at the end of each
650 " path and so expand() might return a list of matching files. To prevent
651 " this, we need to remove the wildcard before calling expand() and then
652 " append it afterwards.
653 if has('win32')
654 let item_nbr = 0
655 while item_nbr < len(bsklist)
656 let path_spec = bsklist[item_nbr]
657 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
658 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
659 let bsklist[item_nbr] = path_spec . '/*'
660 let item_nbr += 1
661 endwhile
662 endif
663
664 " Option bsk will also include these environment variables if defined.
665 " If they're defined, verify they appear in the option value.
666 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200667 if exists(var)
668 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100669 let varvalue = substitute(varvalue, '/$', '', '')
670 let varvalue .= '/*'
671 let found = (index(bsklist, varvalue) >= 0)
672 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200673 endif
674 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200675
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200676 " Duplicates from environment variables should be filtered out (option has
677 " P_NODUP). Run this in a separate instance and write v:errors in a file,
678 " so that we see what happens on startup.
679 let after =<< trim [CODE]
680 let bsklist = split(&backupskip, ',')
681 call assert_equal(uniq(copy(bsklist)), bsklist)
682 call writefile(['errors:'] + v:errors, 'Xtestout')
683 qall
684 [CODE]
685 call writefile(after, 'Xafter')
686 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
687
688 let saveenv = {}
689 for var in ['TMPDIR', 'TMP', 'TEMP']
690 let saveenv[var] = getenv(var)
691 call setenv(var, '/duplicate/path')
692 endfor
693
694 exe 'silent !' . cmd
695 call assert_equal(['errors:'], readfile('Xtestout'))
696
697 " restore environment variables
698 for var in ['TMPDIR', 'TMP', 'TEMP']
699 call setenv(var, saveenv[var])
700 endfor
701
702 call delete('Xtestout')
703 call delete('Xafter')
704
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200705 " Duplicates should be filtered out (option has P_NODUP)
706 let backupskip = &backupskip
707 set backupskip=
708 set backupskip+=/test/dir
709 set backupskip+=/other/dir
710 set backupskip+=/test/dir
711 call assert_equal('/test/dir,/other/dir', &backupskip)
712 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200713endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200714
715func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200716 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200717
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200718 " Test copy option from current buffer in window
719 split
720 enew
721 setlocal numberwidth=5
722 wincmd w
723 call assert_equal(4,&numberwidth)
724 bnext
725 call assert_equal(5,&numberwidth)
726 bw!
727 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200728
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200729 " Test copy value from window that used to be display the buffer
730 split
731 enew
732 setlocal numberwidth=6
733 bnext
734 wincmd w
735 call assert_equal(4,&numberwidth)
736 bnext
737 call assert_equal(6,&numberwidth)
738 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200739
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200740 " Test that if buffer is current, don't use the stale cached value
741 " from the last time the buffer was displayed.
742 split
743 enew
744 setlocal numberwidth=7
745 bnext
746 bnext
747 setlocal numberwidth=8
748 wincmd w
749 call assert_equal(4,&numberwidth)
750 bnext
751 call assert_equal(8,&numberwidth)
752 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200753
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200754 " Test value is not copied if window already has seen the buffer
755 enew
756 split
757 setlocal numberwidth=9
758 bnext
759 setlocal numberwidth=10
760 wincmd w
761 call assert_equal(4,&numberwidth)
762 bnext
763 call assert_equal(4,&numberwidth)
764 bw!
765
766 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200767endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200768
769func Test_shortmess_F()
770 new
771 call assert_match('\[No Name\]', execute('file'))
772 set shortmess+=F
773 call assert_match('\[No Name\]', execute('file'))
774 call assert_match('^\s*$', execute('file foo'))
775 call assert_match('foo', execute('file'))
776 set shortmess-=F
777 call assert_match('bar', execute('file bar'))
778 call assert_match('bar', execute('file'))
779 set shortmess&
780 bwipe
781endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200782
783func Test_shortmess_F2()
784 e file1
785 e file2
786 call assert_match('file1', execute('bn', ''))
787 call assert_match('file2', execute('bn', ''))
788 set shortmess+=F
789 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200790 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200791 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200792 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200793 set hidden
794 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200795 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200796 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200797 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200798 set nohidden
799 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200800 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200801 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200802 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200803 set shortmess&
804 call assert_match('file1', execute('bn', ''))
805 call assert_match('file2', execute('bn', ''))
806 bwipe
807 bwipe
808endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100809
810func Test_local_scrolloff()
811 set so=5
812 set siso=7
813 split
814 call assert_equal(5, &so)
815 setlocal so=3
816 call assert_equal(3, &so)
817 wincmd w
818 call assert_equal(5, &so)
819 wincmd w
820 setlocal so<
821 call assert_equal(5, &so)
822 setlocal so=0
823 call assert_equal(0, &so)
824 setlocal so=-1
825 call assert_equal(5, &so)
826
827 call assert_equal(7, &siso)
828 setlocal siso=3
829 call assert_equal(3, &siso)
830 wincmd w
831 call assert_equal(7, &siso)
832 wincmd w
833 setlocal siso<
834 call assert_equal(7, &siso)
835 setlocal siso=0
836 call assert_equal(0, &siso)
837 setlocal siso=-1
838 call assert_equal(7, &siso)
839
840 close
841 set so&
842 set siso&
843endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200844
845func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100846 CheckFunction reltimefloat
847
Bram Moolenaar449ac472019-04-03 21:42:35 +0200848 new
849 call setline(1, 'empty')
850 redraw
851 set writedelay=10
852 let start = reltime()
853 call setline(1, repeat('x', 70))
854 redraw
855 let elapsed = reltimefloat(reltime(start))
856 set writedelay=0
857 " With 'writedelay' set should take at least 30 * 10 msec
858 call assert_inrange(30 * 0.01, 999.0, elapsed)
859
860 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200861endfunc
862
863func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200864 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200865 set visualbell
866 call assert_beeps('normal 0h')
867 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200868 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200869endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100870
871" Test for the 'write' option
872func Test_write()
873 new
874 call setline(1, ['L1'])
875 set nowrite
876 call assert_fails('write Xfile', 'E142:')
877 set write
878 close!
879endfunc
880
881" Test for 'buftype' option
882func Test_buftype()
883 new
884 call setline(1, ['L1'])
885 set buftype=nowrite
886 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100887
888 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
889 exe 'set buftype=' .. val
890 call writefile(['something'], 'XBuftype')
891 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
892 endfor
893
894 call delete('XBuftype')
895 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100896endfunc
897
Bram Moolenaar578fe942020-02-27 21:32:51 +0100898" Test for the 'rightleftcmd' option
899func Test_rightleftcmd()
900 CheckFeature rightleft
901 set rightleft
902 set rightleftcmd
903
904 let g:l = []
905 func AddPos()
906 call add(g:l, screencol())
907 return ''
908 endfunc
909 cmap <expr> <F2> AddPos()
910
911 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
912 \ "\<Left>\<F2>\<Esc>", 'xt')
913 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
914
915 cunmap <F2>
916 unlet g:l
917 set rightleftcmd&
918 set rightleft&
919endfunc
920
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200921" Test for the "debug" option
922func Test_debug_option()
923 set debug=beep
924 exe "normal \<C-c>"
925 call assert_equal('Beep!', Screenline(&lines))
926 set debug&
927endfunc
928
Bram Moolenaar004a6782020-04-11 17:09:31 +0200929" Test for the default CDPATH option
930func Test_opt_default_cdpath()
931 CheckFeature file_in_path
932 let after =<< trim [CODE]
933 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
934 call writefile(v:errors, 'Xtestout')
935 qall
936 [CODE]
937 if has('unix')
938 let $CDPATH='/path/to/dir1:/path/to/dir2'
939 else
940 let $CDPATH='/path/to/dir1;/path/to/dir2'
941 endif
942 if RunVim([], after, '')
943 call assert_equal([], readfile('Xtestout'))
944 call delete('Xtestout')
945 endif
946endfunc
947
948" Test for setting keycodes using set
949func Test_opt_set_keycode()
950 call assert_fails('set <t_k1=l', 'E474:')
951 call assert_fails('set <Home=l', 'E474:')
952 set <t_k9>=abcd
953 call assert_equal('abcd', &t_k9)
954 set <t_k9>&
955 set <F9>=xyz
956 call assert_equal('xyz', &t_k9)
957 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +0100958
959 " should we test all of them?
960 set t_Ce=testCe
961 set t_Cs=testCs
962 set t_Us=testUs
963 set t_ds=testds
964 set t_Ds=testDs
965 call assert_equal('testCe', &t_Ce)
966 call assert_equal('testCs', &t_Cs)
967 call assert_equal('testUs', &t_Us)
968 call assert_equal('testds', &t_ds)
969 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +0200970endfunc
971
972" Test for changing options in a sandbox
973func Test_opt_sandbox()
974 for opt in ['backupdir', 'cdpath', 'exrc']
975 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200976 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200977 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200978 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200979endfunc
980
981" Test for setting an option with local value to global value
982func Test_opt_local_to_global()
983 setglobal equalprg=gprg
984 setlocal equalprg=lprg
985 call assert_equal('gprg', &g:equalprg)
986 call assert_equal('lprg', &l:equalprg)
987 call assert_equal('lprg', &equalprg)
988 set equalprg<
989 call assert_equal('', &l:equalprg)
990 call assert_equal('gprg', &equalprg)
991 setglobal equalprg=gnewprg
992 setlocal equalprg=lnewprg
993 setlocal equalprg<
994 call assert_equal('gnewprg', &l:equalprg)
995 call assert_equal('gnewprg', &equalprg)
996 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200997
998 " Test for setting the global/local value of a boolean option
999 setglobal autoread
1000 setlocal noautoread
1001 call assert_false(&autoread)
1002 set autoread<
1003 call assert_true(&autoread)
1004 setglobal noautoread
1005 setlocal autoread
1006 setlocal autoread<
1007 call assert_false(&autoread)
1008 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001009endfunc
1010
Dominique Pelle042414f2021-07-12 21:43:19 +02001011func Test_set_in_sandbox()
1012 " Some boolean options cannot be set in sandbox, some can.
1013 call assert_fails('sandbox set modelineexpr', 'E48:')
1014 sandbox set number
1015 call assert_true(&number)
1016 set number&
1017
1018 " Some boolean options cannot be set in sandbox, some can.
1019 if has('python') || has('python3')
1020 call assert_fails('sandbox set pyxversion=3', 'E48:')
1021 endif
1022 sandbox set tabstop=4
1023 call assert_equal(4, &tabstop)
1024 set tabstop&
1025
1026 " Some string options cannot be set in sandbox, some can.
1027 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1028 sandbox set filetype=perl
1029 call assert_equal('perl', &filetype)
1030 set filetype&
1031endfunc
1032
Bram Moolenaar004a6782020-04-11 17:09:31 +02001033" Test for incrementing, decrementing and multiplying a number option value
1034func Test_opt_num_op()
1035 set shiftwidth=4
1036 set sw+=2
1037 call assert_equal(6, &sw)
1038 set sw-=2
1039 call assert_equal(4, &sw)
1040 set sw^=2
1041 call assert_equal(8, &sw)
1042 set shiftwidth&
1043endfunc
1044
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001045" Test for setting option values using v:false and v:true
1046func Test_opt_boolean()
1047 set number&
1048 set number
1049 call assert_equal(1, &nu)
1050 set nonu
1051 call assert_equal(0, &nu)
1052 let &nu = v:true
1053 call assert_equal(1, &nu)
1054 let &nu = v:false
1055 call assert_equal(0, &nu)
1056 set number&
1057endfunc
1058
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001059" Test for the 'window' option
1060func Test_window_opt()
1061 " Needs only one open widow
1062 %bw!
1063 call setline(1, range(1, 8))
1064 set window=5
1065 exe "normal \<C-F>"
1066 call assert_equal(4, line('w0'))
1067 exe "normal \<C-F>"
1068 call assert_equal(7, line('w0'))
1069 exe "normal \<C-F>"
1070 call assert_equal(8, line('w0'))
1071 exe "normal \<C-B>"
1072 call assert_equal(5, line('w0'))
1073 exe "normal \<C-B>"
1074 call assert_equal(2, line('w0'))
1075 exe "normal \<C-B>"
1076 call assert_equal(1, line('w0'))
1077 set window=1
1078 exe "normal gg\<C-F>"
1079 call assert_equal(2, line('w0'))
1080 exe "normal \<C-F>"
1081 call assert_equal(3, line('w0'))
1082 exe "normal \<C-B>"
1083 call assert_equal(2, line('w0'))
1084 exe "normal \<C-B>"
1085 call assert_equal(1, line('w0'))
1086 enew!
1087 set window&
1088endfunc
1089
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001090" Test for the 'winminheight' option
1091func Test_opt_winminheight()
1092 only!
1093 let &winheight = &lines + 4
1094 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1095 call assert_true(&winminheight <= &lines)
1096 set winminheight&
1097 set winheight&
1098endfunc
1099
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001100func Test_opt_winminheight_term()
1101 CheckRunVimInTerminal
1102
1103 " The tabline should be taken into account.
1104 let lines =<< trim END
1105 set wmh=0 stal=2
1106 below sp | wincmd _
1107 below sp | wincmd _
1108 below sp | wincmd _
1109 below sp
1110 END
1111 call writefile(lines, 'Xwinminheight')
1112 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1113 call term_sendkeys(buf, ":set wmh=1\n")
1114 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1115
1116 call StopVimInTerminal(buf)
1117 call delete('Xwinminheight')
1118endfunc
1119
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001120func Test_opt_winminheight_term_tabs()
1121 CheckRunVimInTerminal
1122
1123 " The tabline should be taken into account.
1124 let lines =<< trim END
1125 set wmh=0 stal=2
1126 split
1127 split
1128 split
1129 split
1130 tabnew
1131 END
1132 call writefile(lines, 'Xwinminheight')
1133 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1134 call term_sendkeys(buf, ":set wmh=1\n")
1135 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1136
1137 call StopVimInTerminal(buf)
1138 call delete('Xwinminheight')
1139endfunc
1140
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001141" Test for the 'winminwidth' option
1142func Test_opt_winminwidth()
1143 only!
1144 let &winwidth = &columns + 4
1145 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1146 call assert_true(&winminwidth <= &columns)
1147 set winminwidth&
1148 set winwidth&
1149endfunc
1150
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001151" Test for setting option value containing spaces with isfname+=32
1152func Test_isfname_with_options()
1153 set isfname+=32
1154 setlocal keywordprg=:term\ help.exe
1155 call assert_equal(':term help.exe', &keywordprg)
1156 set isfname&
1157 setlocal keywordprg&
1158endfunc
1159
Bram Moolenaar74667062020-12-28 15:41:41 +01001160" Test that resetting laststatus does change scroll option
1161func Test_opt_reset_scroll()
1162 CheckRunVimInTerminal
1163 let vimrc =<< trim [CODE]
1164 set scroll=2
1165 set laststatus=2
1166 [CODE]
1167 call writefile(vimrc, 'Xscroll')
1168 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1169 call term_sendkeys(buf, ":verbose set scroll?\n")
1170 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1171 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
1172 call StopVimInTerminal(buf)
1173
1174 " clean up
1175 call delete('Xscroll')
1176endfunc
1177
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001178" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1179func Test_VIM_POSIX()
1180 let saved_VIM_POSIX = getenv("VIM_POSIX")
1181
1182 call setenv('VIM_POSIX', "1")
1183 let after =<< trim [CODE]
1184 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1185 qall
1186 [CODE]
1187 if RunVim([], after, '')
1188 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1189 \ 'AS'], readfile('X_VIM_POSIX'))
1190 endif
1191
1192 call setenv('VIM_POSIX', v:null)
1193 let after =<< trim [CODE]
1194 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1195 qall
1196 [CODE]
1197 if RunVim([], after, '')
1198 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1199 \ 'S'], readfile('X_VIM_POSIX'))
1200 endif
1201
1202 call delete('X_VIM_POSIX')
1203 call setenv('VIM_POSIX', saved_VIM_POSIX)
1204endfunc
1205
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001206" Test for setting an option to a Vi or Vim default
1207func Test_opt_default()
1208 set formatoptions&vi
1209 call assert_equal('vt', &formatoptions)
1210 set formatoptions&vim
1211 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001212
1213 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1214 set fencs=latin1
1215 set fencs&
1216 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1217 set fencs=latin1
1218 set all&
1219 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001220endfunc
1221
1222" Test for the 'cmdheight' option
1223func Test_cmdheight()
1224 %bw!
1225 let ht = &lines
1226 set cmdheight=9999
1227 call assert_equal(1, winheight(0))
1228 call assert_equal(ht - 1, &cmdheight)
1229 set cmdheight&
1230endfunc
1231
Dominique Pelle923dce22021-11-21 11:36:04 +00001232" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001233func Test_opt_control_char()
1234 set wildchar=^v
1235 call assert_equal("\<C-V>", nr2char(&wildchar))
1236 set wildcharm=^r
1237 call assert_equal("\<C-R>", nr2char(&wildcharm))
1238 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1239 set wildchar& wildcharm&
1240endfunc
1241
1242" Test for the 'errorbells' option
1243func Test_opt_errorbells()
1244 set errorbells
1245 call assert_beeps('s/a1b2/x1y2/')
1246 set noerrorbells
1247endfunc
1248
Dominique Pelle042414f2021-07-12 21:43:19 +02001249func Test_opt_scrolljump()
1250 help
1251 resize 10
1252
1253 " Test with positive 'scrolljump'.
1254 set scrolljump=2
1255 norm! Lj
1256 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1257 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1258 \ winsaveview())
1259
1260 " Test with negative 'scrolljump' (percentage of window height).
1261 set scrolljump=-40
1262 norm! ggLj
1263 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1264 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1265 \ winsaveview())
1266
1267 set scrolljump&
1268 bw
1269endfunc
1270
Bakudankun29f3a452021-12-11 12:28:08 +00001271" Test for the 'cdhome' option
1272func Test_opt_cdhome()
1273 if has('unix') || has('vms')
1274 throw 'Skipped: only works on non-Unix'
1275 endif
1276
1277 set cdhome&
1278 call assert_equal(0, &cdhome)
1279 set cdhome
1280
1281 " This paragraph is copied from Test_cd_no_arg().
1282 let path = getcwd()
1283 cd
1284 call assert_equal($HOME, getcwd())
1285 call assert_notequal(path, getcwd())
1286 exe 'cd ' .. fnameescape(path)
1287 call assert_equal(path, getcwd())
1288
1289 set cdhome&
1290endfunc
1291
Christian Brabandtcb747892022-05-08 21:10:56 +01001292func Test_set_completion_2()
1293 CheckOption termguicolors
1294
1295 " Test default option completion
1296 set wildoptions=
1297 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1298 call assert_equal('"set termguicolors', @:)
1299
1300 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1301 call assert_equal('"set notermguicolors', @:)
1302
1303 " Test fuzzy option completion
1304 set wildoptions=fuzzy
1305 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1306 call assert_equal('"set termguicolors termencoding', @:)
1307
1308 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1309 call assert_equal('"set notermguicolors', @:)
1310
1311 set wildoptions=
1312endfunc
1313
Sean Dewar39c46b42022-05-12 17:44:29 +01001314func Test_switchbuf_reset()
1315 set switchbuf=useopen
1316 sblast
1317 call assert_equal(1, winnr('$'))
1318 set all&
1319 call assert_equal('', &switchbuf)
1320 sblast
1321 call assert_equal(2, winnr('$'))
1322 only!
1323endfunc
1324
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001325" vim: shiftwidth=2 sts=2 expandtab