blob: 01418bd6d69574669072957a3daa288178a71491 [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?'))
zeertzjqbb404f52022-07-23 06:25:29 +010068
zeertzjq0519ce02022-05-09 12:16:19 +010069 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010070 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010071endfunc
72
Bram Moolenaar1e115362019-01-09 23:01:02 +010073func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010074 " Empty 'wildchar' used to access invalid memory.
75 call assert_fails('set wildchar=', 'E521:')
76 call assert_fails('set wildchar=abc', 'E521:')
77 set wildchar=<Esc>
78 let a=execute('set wildchar?')
79 call assert_equal("\n wildchar=<Esc>", a)
80 set wildchar=27
81 let a=execute('set wildchar?')
82 call assert_equal("\n wildchar=<Esc>", a)
83 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010084endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010085
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020086func Test_wildoptions()
87 set wildoptions=
88 set wildoptions+=tagfile
89 set wildoptions+=tagfile
90 call assert_equal('tagfile', &wildoptions)
91endfunc
92
Bram Moolenaar6b915c02020-01-18 15:53:19 +010093func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020094 let caught = 'ok'
95 try
96 options
97 catch
98 let caught = v:throwpoint . "\n" . v:exception
99 endtry
100 call assert_equal('ok', caught)
101
Bram Moolenaare0b59492019-05-21 20:54:45 +0200102 " Check if the option-window is opened horizontally.
103 wincmd j
104 call assert_notequal('option-window', bufname(''))
105 wincmd k
106 call assert_equal('option-window', bufname(''))
107 " close option-window
108 close
109
110 " Open the option-window vertically.
111 vert options
112 " Check if the option-window is opened vertically.
113 wincmd l
114 call assert_notequal('option-window', bufname(''))
115 wincmd h
116 call assert_equal('option-window', bufname(''))
117 " close option-window
118 close
119
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200120 " Open the option-window at the top.
121 set splitbelow
122 topleft options
123 call assert_equal(1, winnr())
124 close
125
126 " Open the option-window at the bottom.
127 set nosplitbelow
128 botright options
129 call assert_equal(winnr('$'), winnr())
130 close
131 set splitbelow&
132
Bram Moolenaare0b59492019-05-21 20:54:45 +0200133 " Open the option-window in a new tab.
134 tab options
135 " Check if the option-window is opened in a tab.
136 normal gT
137 call assert_notequal('option-window', bufname(''))
138 normal gt
139 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200140 " close option-window
141 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200142
143 " Open the options window browse
144 if has('browse')
145 browse set
146 call assert_equal('option-window', bufname(''))
147 close
148 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100149endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200150
Bram Moolenaar1e115362019-01-09 23:01:02 +0100151func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200152 " Test that changing 'path' keeps two commas.
153 set path=foo,,bar
154 set path-=bar
155 set path+=bar
156 call assert_equal('foo,,bar', &path)
157
158 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100159endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200160
Dominique Pellef645ee42021-12-05 13:21:18 +0000161func Test_path_too_long()
162 exe 'set path=' .. repeat('x', 10000)
163 call assert_fails('find x', 'E854:')
164 set path&
165endfunc
166
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200167func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200168 CheckFeature signs
169 call assert_equal("auto", &signcolumn)
170 set signcolumn=yes
171 set signcolumn=no
172 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200173endfunc
174
Bram Moolenaard0b51382016-11-04 15:23:45 +0100175func Test_filetype_valid()
176 set ft=valid_name
177 call assert_equal("valid_name", &filetype)
178 set ft=valid-name
179 call assert_equal("valid-name", &filetype)
180
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\\|name", "E474:")
184 call assert_fails(":set ft=wrong/name", "E474:")
185 call assert_fails(":set ft=wrong\\\nname", "E474:")
186 call assert_equal("valid-name", &filetype)
187
188 exe "set ft=trunc\x00name"
189 call assert_equal("trunc", &filetype)
190endfunc
191
192func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200193 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100194 set syn=valid_name
195 call assert_equal("valid_name", &syntax)
196 set syn=valid-name
197 call assert_equal("valid-name", &syntax)
198
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\\|name", "E474:")
202 call assert_fails(":set syn=wrong/name", "E474:")
203 call assert_fails(":set syn=wrong\\\nname", "E474:")
204 call assert_equal("valid-name", &syntax)
205
206 exe "set syn=trunc\x00name"
207 call assert_equal("trunc", &syntax)
208endfunc
209
210func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200211 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100212 call assert_fails(":set kmp=valid_name", "E544:")
213 call assert_fails(":set kmp=valid_name", "valid_name")
214 call assert_fails(":set kmp=valid-name", "E544:")
215 call assert_fails(":set kmp=valid-name", "valid-name")
216
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\\|name", "E474:")
220 call assert_fails(":set kmp=wrong/name", "E474:")
221 call assert_fails(":set kmp=wrong\\\nname", "E474:")
222
223 call assert_fails(":set kmp=trunc\x00name", "E544:")
224 call assert_fails(":set kmp=trunc\x00name", "trunc")
225endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100226
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100227func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100228 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100229 exe 'set ' . a:name . '=/usr/share/dict/words'
230 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
231 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
232 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
233 exe 'set ' . a:name . '=/usr/share/dict\ words'
234 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100235
236 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100237 call assert_fails("set " . a:name . "=/not&there", "E474:")
238 call assert_fails("set " . a:name . "=/not>there", "E474:")
239 call assert_fails("set " . a:name . "=/not.*there", "E474:")
240endfunc
241
Bram Moolenaar60629d62017-02-23 18:08:56 +0100242func Test_cinkeys()
243 " This used to cause invalid memory access
244 set cindent cinkeys=0
245 norm a
246 set cindent& cinkeys&
247endfunc
248
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100249func Test_dictionary()
250 call Check_dir_option('dictionary')
251endfunc
252
253func Test_thesaurus()
254 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100255endfun
256
Bram Moolenaar226c5342017-02-17 14:53:15 +0100257func Test_complete()
258 " Trailing single backslash used to cause invalid memory access.
259 set complete=s\
260 new
261 call feedkeys("i\<C-N>\<Esc>", 'xt')
262 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200263 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100264 set complete&
265endfun
266
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100267func Test_set_completion()
268 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
269 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
270
Bram Moolenaar297610b2019-12-27 17:20:55 +0100271 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
272 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
273
274 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
275 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
276
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100277 " Expand boolan options. When doing :set no<Tab>
278 " vim displays the options names without "no" but completion uses "no...".
279 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
280 call assert_equal('"set nodiff digraph', @:)
281
282 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_equal('"set invdiff digraph', @:)
284
285 " Expand abbreviation of options.
286 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100287 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100288
289 " Expand current value
290 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
291 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
292
293 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
294 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
295
296 " Expand key codes.
297 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
298 call assert_equal('"set <Help> <Home>', @:)
299
300 " Expand terminal options.
301 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200302 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200303 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100304
305 " Expand directories.
306 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
307 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200308 call assert_notmatch(' ./summarize.vim ', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100309
310 " Expand files and directories.
311 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200312 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100313
314 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
315 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200316 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200317
318 " Expanding the option names
319 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
320 call assert_equal('"set all', @:)
321
322 " Expanding a second set of option names
323 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
324 call assert_equal('"set wrapscan all', @:)
325
326 " Expanding a special keycode
327 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
328 call assert_equal('"set <Home>', @:)
329
330 " Expanding an invalid special keycode
331 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal("\"set <abcd>\<Tab>", @:)
333
334 " Expanding a terminal keycode
335 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
336 call assert_equal("\"set t_AB", @:)
337
338 " Expanding an invalid option name
339 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
340 call assert_equal("\"set abcde=\<Tab>", @:)
341
342 " Expanding after a = for a boolean option
343 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
344 call assert_equal("\"set wrapscan=\<Tab>", @:)
345
346 " Expanding a numeric option
347 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
348 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
349
350 " Expanding a non-boolean option
351 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
352 call assert_equal("\"set invtabstop=", @:)
353
354 " Expand options for 'spellsuggest'
355 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
356 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
357
358 " Expand value for 'key'
359 set key=abcd
360 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
361 call assert_equal('"set key=*****', @:)
362 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100363
364 " Expand values for 'filetype'
365 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
366 call assert_equal('"set filetype=sshdconfig', @:)
367 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
368 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100369endfunc
370
371func Test_set_errors()
372 call assert_fails('set scroll=-1', 'E49:')
373 call assert_fails('set backupcopy=', 'E474:')
374 call assert_fails('set regexpengine=3', 'E474:')
375 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200376 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100377 call assert_fails('set colorcolumn=-a', 'E474:')
378 call assert_fails('set colorcolumn=a', 'E474:')
379 call assert_fails('set colorcolumn=1,', 'E474:')
380 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100381 call assert_fails('set cmdheight=-1', 'E487:')
382 call assert_fails('set cmdwinheight=-1', 'E487:')
383 if has('conceal')
384 call assert_fails('set conceallevel=-1', 'E487:')
385 call assert_fails('set conceallevel=4', 'E474:')
386 endif
387 call assert_fails('set helpheight=-1', 'E487:')
388 call assert_fails('set history=-1', 'E487:')
389 call assert_fails('set report=-1', 'E487:')
390 call assert_fails('set shiftwidth=-1', 'E487:')
391 call assert_fails('set sidescroll=-1', 'E487:')
392 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000393 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000394 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000395 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100396 call assert_fails('set textwidth=-1', 'E487:')
397 call assert_fails('set timeoutlen=-1', 'E487:')
398 call assert_fails('set updatecount=-1', 'E487:')
399 call assert_fails('set updatetime=-1', 'E487:')
400 call assert_fails('set winheight=-1', 'E487:')
401 call assert_fails('set tabstop!', 'E488:')
402 call assert_fails('set xxx', 'E518:')
403 call assert_fails('set beautify?', 'E519:')
404 call assert_fails('set undolevels=x', 'E521:')
405 call assert_fails('set tabstop=', 'E521:')
406 call assert_fails('set comments=-', 'E524:')
407 call assert_fails('set comments=a', 'E525:')
408 call assert_fails('set foldmarker=x', 'E536:')
409 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000410 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100411 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100412 call assert_fails('set rulerformat=%-', 'E539:')
413 call assert_fails('set rulerformat=%(', 'E542:')
414 call assert_fails('set rulerformat=%15(%%', 'E542:')
415 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100416 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100417 call assert_fails('set statusline=%{%', 'E540:')
418 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100419 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100420 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100421 call assert_fails('set tabline=%$', 'E539:')
422 call assert_fails('set tabline=%{', 'E540:')
423 call assert_fails('set tabline=%{%', 'E540:')
424 call assert_fails('set tabline=%{%}', 'E539:')
425 call assert_fails('set tabline=%(', 'E542:')
426 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100427
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100428 if has('cursorshape')
429 " This invalid value for 'guicursor' used to cause Vim to crash.
430 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
431 call assert_fails('set guicursor=i-ci', 'E545:')
432 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100433 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100434 call assert_fails('set guicursor=r-cr:horx', 'E548:')
435 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
436 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100437 if has('mouseshape')
438 call assert_fails('se mouseshape=i-r:x', 'E547:')
439 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100440 call assert_fails('set backupext=~ patchmode=~', 'E589:')
441 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200442 set winminheight& winheight&
443 set winheight=10 winminheight=10
444 call assert_fails('set winheight=9', 'E591:')
445 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100446 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200447 set winminwidth& winwidth&
448 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
449 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100450 call assert_fails("set showbreak=\x01", 'E595:')
451 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200452 call assert_fails('set tabstop??', 'E488:')
453 call assert_fails('set wrapscan!!', 'E488:')
454 call assert_fails('set tabstop&&', 'E488:')
455 call assert_fails('set wrapscan<<', 'E488:')
456 call assert_fails('set wrapscan=1', 'E474:')
457 call assert_fails('set autoindent@', 'E488:')
458 call assert_fails('set wildchar=<abc>', 'E474:')
459 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200460 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100461 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200462 call assert_fails('set pyxversion=6', 'E474:')
463 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200464 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200465 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100466 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
467 call assert_fails('set foldmarker={{{,', 'E474:')
468 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
469 call assert_fails('set listchars=trail ambiwidth=double', 'E834:')
470 set listchars&
471 call assert_fails('set fillchars=stl ambiwidth=double', 'E835:')
472 set fillchars&
473 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
474 set nomodifiable
475 call assert_fails('set fileencoding=latin1', 'E21:')
476 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200477 call assert_fails('set t_#-&', 'E522:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100478endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100479
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000480func Test_set_encoding()
481 let save_encoding = &encoding
482
483 set enc=iso8859-1
484 call assert_equal('latin1', &enc)
485 set enc=iso8859_1
486 call assert_equal('latin1', &enc)
487 set enc=iso-8859-1
488 call assert_equal('latin1', &enc)
489 set enc=iso_8859_1
490 call assert_equal('latin1', &enc)
491 set enc=iso88591
492 call assert_equal('latin1', &enc)
493 set enc=iso8859
494 call assert_equal('latin1', &enc)
495 set enc=iso-8859
496 call assert_equal('latin1', &enc)
497 set enc=iso_8859
498 call assert_equal('latin1', &enc)
499 call assert_fails('set enc=iso8858', 'E474:')
500 call assert_equal('latin1', &enc)
501
502 let &encoding = save_encoding
503endfunc
504
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200505func CheckWasSet(name)
506 let verb_cm = execute('verbose set ' .. a:name .. '?')
507 call assert_match('Last set from.*test_options.vim', verb_cm)
508endfunc
509func CheckWasNotSet(name)
510 let verb_cm = execute('verbose set ' .. a:name .. '?')
511 call assert_notmatch('Last set from', verb_cm)
512endfunc
513
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200514" Must be executed before other tests that set 'term'.
515func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200516 CheckNotGui
517
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200518 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200519
520 let term_save = &term
521 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200522 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200523 let &term = term_save
524endfunc
525
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200526func Test_copy_context()
527 setlocal list
528 call CheckWasSet('list')
529 split
530 call CheckWasSet('list')
531 quit
532 setlocal nolist
533
534 set ai
535 call CheckWasSet('ai')
536 set filetype=perl
537 call CheckWasSet('filetype')
538 set fo=tcroq
539 call CheckWasSet('fo')
540
541 split Xsomebuf
542 call CheckWasSet('ai')
543 call CheckWasNotSet('filetype')
544 call CheckWasSet('fo')
545endfunc
546
Bram Moolenaar67391142017-02-19 21:07:04 +0100547func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200548 CheckUnix
549 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200550
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200551 " Setting 'ttytype' used to cause a double-free when exiting vim and
552 " when vim is compiled with -DEXITFREE.
553 set ttytype=ansi
554 call assert_equal('ansi', &ttytype)
555 call assert_equal(&ttytype, &term)
556 set ttytype=xterm
557 call assert_equal('xterm', &ttytype)
558 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200559 try
560 set ttytype=
561 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100562 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200563 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200564
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200565 " Some systems accept any terminal name and return dumb settings,
566 " check for failure of finding the entry and for missing 'cm' entry.
567 try
568 set ttytype=xxx
569 call assert_report('set ttytype=xxx did not fail')
570 catch /E522\|E437/
571 endtry
572
573 set ttytype&
574 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200575
576 if has('gui') && !has('gui_running')
577 call assert_fails('set term=gui', 'E531:')
578 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100579endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100580
581func Test_set_all()
582 set tw=75
583 set iskeyword=a-z,A-Z
584 set nosplitbelow
585 let out = execute('set all')
586 call assert_match('textwidth=75', out)
587 call assert_match('iskeyword=a-z,A-Z', out)
588 call assert_match('nosplitbelow', out)
589 set tw& iskeyword& splitbelow&
590endfunc
591
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100592func Test_set_one_column()
593 let out_mult = execute('set all')->split("\n")
594 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100595 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100596endfunc
597
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100598func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200599 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100600 if filereadable('opt_test.vim')
601 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100602 else
603 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100604 endif
605endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200606
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100607func Test_renderoptions()
608 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
609 " Doesn't hurt to do this on a non-Windows system.
610 if windowsversion() !~ '^[345]\.'
611 set renderoptions=type:directx
612 set rop=type:directx
613 endif
614endfunc
615
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200616func ResetIndentexpr()
617 set indentexpr=
618endfunc
619
620func Test_set_indentexpr()
621 " this was causing usage of freed memory
622 set indentexpr=ResetIndentexpr()
623 new
624 call feedkeys("i\<c-f>", 'x')
625 call assert_equal('', &indentexpr)
626 bwipe!
627endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200628
629func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100630 " Option 'backupskip' may contain several comma-separated path
631 " specifications if one or more of the environment variables TMPDIR, TMP,
632 " or TEMP is defined. To simplify testing, convert the string value into a
633 " list.
634 let bsklist = split(&bsk, ',')
635
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200636 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100637 let found = (index(bsklist, '/private/tmp/*') >= 0)
638 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200639 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100640 let found = (index(bsklist, '/tmp/*') >= 0)
641 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200642 endif
643
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100644 " If our test platform is Windows, the path(s) in option bsk will use
645 " backslash for the path separator and the components could be in short
646 " (8.3) format. As such, we need to replace the backslashes with forward
647 " slashes and convert the path components to long format. The expand()
648 " function will do this but it cannot handle comma-separated paths. This is
649 " why bsk was converted from a string into a list of strings above.
650 "
651 " One final complication is that the wildcard "/*" is at the end of each
652 " path and so expand() might return a list of matching files. To prevent
653 " this, we need to remove the wildcard before calling expand() and then
654 " append it afterwards.
655 if has('win32')
656 let item_nbr = 0
657 while item_nbr < len(bsklist)
658 let path_spec = bsklist[item_nbr]
659 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
660 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
661 let bsklist[item_nbr] = path_spec . '/*'
662 let item_nbr += 1
663 endwhile
664 endif
665
666 " Option bsk will also include these environment variables if defined.
667 " If they're defined, verify they appear in the option value.
668 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200669 if exists(var)
670 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100671 let varvalue = substitute(varvalue, '/$', '', '')
672 let varvalue .= '/*'
673 let found = (index(bsklist, varvalue) >= 0)
674 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200675 endif
676 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200677
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200678 " Duplicates from environment variables should be filtered out (option has
679 " P_NODUP). Run this in a separate instance and write v:errors in a file,
680 " so that we see what happens on startup.
681 let after =<< trim [CODE]
682 let bsklist = split(&backupskip, ',')
683 call assert_equal(uniq(copy(bsklist)), bsklist)
684 call writefile(['errors:'] + v:errors, 'Xtestout')
685 qall
686 [CODE]
687 call writefile(after, 'Xafter')
688 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
689
690 let saveenv = {}
691 for var in ['TMPDIR', 'TMP', 'TEMP']
692 let saveenv[var] = getenv(var)
693 call setenv(var, '/duplicate/path')
694 endfor
695
696 exe 'silent !' . cmd
697 call assert_equal(['errors:'], readfile('Xtestout'))
698
699 " restore environment variables
700 for var in ['TMPDIR', 'TMP', 'TEMP']
701 call setenv(var, saveenv[var])
702 endfor
703
704 call delete('Xtestout')
705 call delete('Xafter')
706
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200707 " Duplicates should be filtered out (option has P_NODUP)
708 let backupskip = &backupskip
709 set backupskip=
710 set backupskip+=/test/dir
711 set backupskip+=/other/dir
712 set backupskip+=/test/dir
713 call assert_equal('/test/dir,/other/dir', &backupskip)
714 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200715endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200716
717func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200718 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200719
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200720 " Test copy option from current buffer in window
721 split
722 enew
723 setlocal numberwidth=5
724 wincmd w
725 call assert_equal(4,&numberwidth)
726 bnext
727 call assert_equal(5,&numberwidth)
728 bw!
729 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200730
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200731 " Test copy value from window that used to be display the buffer
732 split
733 enew
734 setlocal numberwidth=6
735 bnext
736 wincmd w
737 call assert_equal(4,&numberwidth)
738 bnext
739 call assert_equal(6,&numberwidth)
740 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200741
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200742 " Test that if buffer is current, don't use the stale cached value
743 " from the last time the buffer was displayed.
744 split
745 enew
746 setlocal numberwidth=7
747 bnext
748 bnext
749 setlocal numberwidth=8
750 wincmd w
751 call assert_equal(4,&numberwidth)
752 bnext
753 call assert_equal(8,&numberwidth)
754 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200755
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200756 " Test value is not copied if window already has seen the buffer
757 enew
758 split
759 setlocal numberwidth=9
760 bnext
761 setlocal numberwidth=10
762 wincmd w
763 call assert_equal(4,&numberwidth)
764 bnext
765 call assert_equal(4,&numberwidth)
766 bw!
767
768 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200769endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200770
771func Test_shortmess_F()
772 new
773 call assert_match('\[No Name\]', execute('file'))
774 set shortmess+=F
775 call assert_match('\[No Name\]', execute('file'))
776 call assert_match('^\s*$', execute('file foo'))
777 call assert_match('foo', execute('file'))
778 set shortmess-=F
779 call assert_match('bar', execute('file bar'))
780 call assert_match('bar', execute('file'))
781 set shortmess&
782 bwipe
783endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200784
785func Test_shortmess_F2()
786 e file1
787 e file2
788 call assert_match('file1', execute('bn', ''))
789 call assert_match('file2', execute('bn', ''))
790 set shortmess+=F
791 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200792 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200793 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200794 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200795 set hidden
796 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 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200799 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200800 set nohidden
801 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 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200804 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200805 set shortmess&
806 call assert_match('file1', execute('bn', ''))
807 call assert_match('file2', execute('bn', ''))
808 bwipe
809 bwipe
810endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100811
812func Test_local_scrolloff()
813 set so=5
814 set siso=7
815 split
816 call assert_equal(5, &so)
817 setlocal so=3
818 call assert_equal(3, &so)
819 wincmd w
820 call assert_equal(5, &so)
821 wincmd w
822 setlocal so<
823 call assert_equal(5, &so)
824 setlocal so=0
825 call assert_equal(0, &so)
826 setlocal so=-1
827 call assert_equal(5, &so)
828
829 call assert_equal(7, &siso)
830 setlocal siso=3
831 call assert_equal(3, &siso)
832 wincmd w
833 call assert_equal(7, &siso)
834 wincmd w
835 setlocal siso<
836 call assert_equal(7, &siso)
837 setlocal siso=0
838 call assert_equal(0, &siso)
839 setlocal siso=-1
840 call assert_equal(7, &siso)
841
842 close
843 set so&
844 set siso&
845endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200846
847func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100848 CheckFunction reltimefloat
849
Bram Moolenaar449ac472019-04-03 21:42:35 +0200850 new
851 call setline(1, 'empty')
852 redraw
853 set writedelay=10
854 let start = reltime()
855 call setline(1, repeat('x', 70))
856 redraw
857 let elapsed = reltimefloat(reltime(start))
858 set writedelay=0
859 " With 'writedelay' set should take at least 30 * 10 msec
860 call assert_inrange(30 * 0.01, 999.0, elapsed)
861
862 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200863endfunc
864
865func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200866 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200867 set visualbell
868 call assert_beeps('normal 0h')
869 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200870 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200871endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100872
873" Test for the 'write' option
874func Test_write()
875 new
876 call setline(1, ['L1'])
877 set nowrite
878 call assert_fails('write Xfile', 'E142:')
879 set write
880 close!
881endfunc
882
883" Test for 'buftype' option
884func Test_buftype()
885 new
886 call setline(1, ['L1'])
887 set buftype=nowrite
888 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100889
890 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
891 exe 'set buftype=' .. val
892 call writefile(['something'], 'XBuftype')
893 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
894 endfor
895
896 call delete('XBuftype')
897 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100898endfunc
899
Bram Moolenaar578fe942020-02-27 21:32:51 +0100900" Test for the 'rightleftcmd' option
901func Test_rightleftcmd()
902 CheckFeature rightleft
903 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +0100904
905 let g:l = []
906 func AddPos()
907 call add(g:l, screencol())
908 return ''
909 endfunc
910 cmap <expr> <F2> AddPos()
911
zeertzjqbb404f52022-07-23 06:25:29 +0100912 set rightleftcmd=
913 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
914 \ "\<Right>\<F2>\<Esc>", 'xt')
915 call assert_equal([2, 5, 3, 4], g:l)
916
917 let g:l = []
918 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +0100919 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
920 \ "\<Left>\<F2>\<Esc>", 'xt')
921 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
922
923 cunmap <F2>
924 unlet g:l
925 set rightleftcmd&
926 set rightleft&
927endfunc
928
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200929" Test for the "debug" option
930func Test_debug_option()
931 set debug=beep
932 exe "normal \<C-c>"
933 call assert_equal('Beep!', Screenline(&lines))
934 set debug&
935endfunc
936
Bram Moolenaar004a6782020-04-11 17:09:31 +0200937" Test for the default CDPATH option
938func Test_opt_default_cdpath()
939 CheckFeature file_in_path
940 let after =<< trim [CODE]
941 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
942 call writefile(v:errors, 'Xtestout')
943 qall
944 [CODE]
945 if has('unix')
946 let $CDPATH='/path/to/dir1:/path/to/dir2'
947 else
948 let $CDPATH='/path/to/dir1;/path/to/dir2'
949 endif
950 if RunVim([], after, '')
951 call assert_equal([], readfile('Xtestout'))
952 call delete('Xtestout')
953 endif
954endfunc
955
956" Test for setting keycodes using set
957func Test_opt_set_keycode()
958 call assert_fails('set <t_k1=l', 'E474:')
959 call assert_fails('set <Home=l', 'E474:')
960 set <t_k9>=abcd
961 call assert_equal('abcd', &t_k9)
962 set <t_k9>&
963 set <F9>=xyz
964 call assert_equal('xyz', &t_k9)
965 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +0100966
967 " should we test all of them?
968 set t_Ce=testCe
969 set t_Cs=testCs
970 set t_Us=testUs
971 set t_ds=testds
972 set t_Ds=testDs
973 call assert_equal('testCe', &t_Ce)
974 call assert_equal('testCs', &t_Cs)
975 call assert_equal('testUs', &t_Us)
976 call assert_equal('testds', &t_ds)
977 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +0200978endfunc
979
980" Test for changing options in a sandbox
981func Test_opt_sandbox()
982 for opt in ['backupdir', 'cdpath', 'exrc']
983 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200984 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200985 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200986 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200987endfunc
988
989" Test for setting an option with local value to global value
990func Test_opt_local_to_global()
991 setglobal equalprg=gprg
992 setlocal equalprg=lprg
993 call assert_equal('gprg', &g:equalprg)
994 call assert_equal('lprg', &l:equalprg)
995 call assert_equal('lprg', &equalprg)
996 set equalprg<
997 call assert_equal('', &l:equalprg)
998 call assert_equal('gprg', &equalprg)
999 setglobal equalprg=gnewprg
1000 setlocal equalprg=lnewprg
1001 setlocal equalprg<
1002 call assert_equal('gnewprg', &l:equalprg)
1003 call assert_equal('gnewprg', &equalprg)
1004 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001005
1006 " Test for setting the global/local value of a boolean option
1007 setglobal autoread
1008 setlocal noautoread
1009 call assert_false(&autoread)
1010 set autoread<
1011 call assert_true(&autoread)
1012 setglobal noautoread
1013 setlocal autoread
1014 setlocal autoread<
1015 call assert_false(&autoread)
1016 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001017endfunc
1018
Dominique Pelle042414f2021-07-12 21:43:19 +02001019func Test_set_in_sandbox()
1020 " Some boolean options cannot be set in sandbox, some can.
1021 call assert_fails('sandbox set modelineexpr', 'E48:')
1022 sandbox set number
1023 call assert_true(&number)
1024 set number&
1025
1026 " Some boolean options cannot be set in sandbox, some can.
1027 if has('python') || has('python3')
1028 call assert_fails('sandbox set pyxversion=3', 'E48:')
1029 endif
1030 sandbox set tabstop=4
1031 call assert_equal(4, &tabstop)
1032 set tabstop&
1033
1034 " Some string options cannot be set in sandbox, some can.
1035 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1036 sandbox set filetype=perl
1037 call assert_equal('perl', &filetype)
1038 set filetype&
1039endfunc
1040
Bram Moolenaar004a6782020-04-11 17:09:31 +02001041" Test for incrementing, decrementing and multiplying a number option value
1042func Test_opt_num_op()
1043 set shiftwidth=4
1044 set sw+=2
1045 call assert_equal(6, &sw)
1046 set sw-=2
1047 call assert_equal(4, &sw)
1048 set sw^=2
1049 call assert_equal(8, &sw)
1050 set shiftwidth&
1051endfunc
1052
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001053" Test for setting option values using v:false and v:true
1054func Test_opt_boolean()
1055 set number&
1056 set number
1057 call assert_equal(1, &nu)
1058 set nonu
1059 call assert_equal(0, &nu)
1060 let &nu = v:true
1061 call assert_equal(1, &nu)
1062 let &nu = v:false
1063 call assert_equal(0, &nu)
1064 set number&
1065endfunc
1066
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001067" Test for the 'window' option
1068func Test_window_opt()
1069 " Needs only one open widow
1070 %bw!
1071 call setline(1, range(1, 8))
1072 set window=5
1073 exe "normal \<C-F>"
1074 call assert_equal(4, line('w0'))
1075 exe "normal \<C-F>"
1076 call assert_equal(7, line('w0'))
1077 exe "normal \<C-F>"
1078 call assert_equal(8, line('w0'))
1079 exe "normal \<C-B>"
1080 call assert_equal(5, line('w0'))
1081 exe "normal \<C-B>"
1082 call assert_equal(2, line('w0'))
1083 exe "normal \<C-B>"
1084 call assert_equal(1, line('w0'))
1085 set window=1
1086 exe "normal gg\<C-F>"
1087 call assert_equal(2, line('w0'))
1088 exe "normal \<C-F>"
1089 call assert_equal(3, line('w0'))
1090 exe "normal \<C-B>"
1091 call assert_equal(2, line('w0'))
1092 exe "normal \<C-B>"
1093 call assert_equal(1, line('w0'))
1094 enew!
1095 set window&
1096endfunc
1097
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001098" Test for the 'winminheight' option
1099func Test_opt_winminheight()
1100 only!
1101 let &winheight = &lines + 4
1102 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1103 call assert_true(&winminheight <= &lines)
1104 set winminheight&
1105 set winheight&
1106endfunc
1107
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001108func Test_opt_winminheight_term()
1109 CheckRunVimInTerminal
1110
1111 " The tabline should be taken into account.
1112 let lines =<< trim END
1113 set wmh=0 stal=2
1114 below sp | wincmd _
1115 below sp | wincmd _
1116 below sp | wincmd _
1117 below sp
1118 END
1119 call writefile(lines, 'Xwinminheight')
1120 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1121 call term_sendkeys(buf, ":set wmh=1\n")
1122 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1123
1124 call StopVimInTerminal(buf)
1125 call delete('Xwinminheight')
1126endfunc
1127
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001128func Test_opt_winminheight_term_tabs()
1129 CheckRunVimInTerminal
1130
1131 " The tabline should be taken into account.
1132 let lines =<< trim END
1133 set wmh=0 stal=2
1134 split
1135 split
1136 split
1137 split
1138 tabnew
1139 END
1140 call writefile(lines, 'Xwinminheight')
1141 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1142 call term_sendkeys(buf, ":set wmh=1\n")
1143 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1144
1145 call StopVimInTerminal(buf)
1146 call delete('Xwinminheight')
1147endfunc
1148
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001149" Test for the 'winminwidth' option
1150func Test_opt_winminwidth()
1151 only!
1152 let &winwidth = &columns + 4
1153 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1154 call assert_true(&winminwidth <= &columns)
1155 set winminwidth&
1156 set winwidth&
1157endfunc
1158
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001159" Test for setting option value containing spaces with isfname+=32
1160func Test_isfname_with_options()
1161 set isfname+=32
1162 setlocal keywordprg=:term\ help.exe
1163 call assert_equal(':term help.exe', &keywordprg)
1164 set isfname&
1165 setlocal keywordprg&
1166endfunc
1167
Bram Moolenaar74667062020-12-28 15:41:41 +01001168" Test that resetting laststatus does change scroll option
1169func Test_opt_reset_scroll()
1170 CheckRunVimInTerminal
1171 let vimrc =<< trim [CODE]
1172 set scroll=2
1173 set laststatus=2
1174 [CODE]
1175 call writefile(vimrc, 'Xscroll')
1176 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1177 call term_sendkeys(buf, ":verbose set scroll?\n")
1178 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1179 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
1180 call StopVimInTerminal(buf)
1181
1182 " clean up
1183 call delete('Xscroll')
1184endfunc
1185
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001186" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1187func Test_VIM_POSIX()
1188 let saved_VIM_POSIX = getenv("VIM_POSIX")
1189
1190 call setenv('VIM_POSIX', "1")
1191 let after =<< trim [CODE]
1192 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1193 qall
1194 [CODE]
1195 if RunVim([], after, '')
1196 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1197 \ 'AS'], readfile('X_VIM_POSIX'))
1198 endif
1199
1200 call setenv('VIM_POSIX', v:null)
1201 let after =<< trim [CODE]
1202 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1203 qall
1204 [CODE]
1205 if RunVim([], after, '')
1206 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1207 \ 'S'], readfile('X_VIM_POSIX'))
1208 endif
1209
1210 call delete('X_VIM_POSIX')
1211 call setenv('VIM_POSIX', saved_VIM_POSIX)
1212endfunc
1213
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001214" Test for setting an option to a Vi or Vim default
1215func Test_opt_default()
1216 set formatoptions&vi
1217 call assert_equal('vt', &formatoptions)
1218 set formatoptions&vim
1219 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001220
1221 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1222 set fencs=latin1
1223 set fencs&
1224 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1225 set fencs=latin1
1226 set all&
1227 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001228endfunc
1229
1230" Test for the 'cmdheight' option
1231func Test_cmdheight()
1232 %bw!
1233 let ht = &lines
1234 set cmdheight=9999
1235 call assert_equal(1, winheight(0))
1236 call assert_equal(ht - 1, &cmdheight)
1237 set cmdheight&
1238endfunc
1239
Dominique Pelle923dce22021-11-21 11:36:04 +00001240" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001241func Test_opt_control_char()
1242 set wildchar=^v
1243 call assert_equal("\<C-V>", nr2char(&wildchar))
1244 set wildcharm=^r
1245 call assert_equal("\<C-R>", nr2char(&wildcharm))
1246 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1247 set wildchar& wildcharm&
1248endfunc
1249
1250" Test for the 'errorbells' option
1251func Test_opt_errorbells()
1252 set errorbells
1253 call assert_beeps('s/a1b2/x1y2/')
1254 set noerrorbells
1255endfunc
1256
Dominique Pelle042414f2021-07-12 21:43:19 +02001257func Test_opt_scrolljump()
1258 help
1259 resize 10
1260
1261 " Test with positive 'scrolljump'.
1262 set scrolljump=2
1263 norm! Lj
1264 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1265 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1266 \ winsaveview())
1267
1268 " Test with negative 'scrolljump' (percentage of window height).
1269 set scrolljump=-40
1270 norm! ggLj
1271 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1272 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1273 \ winsaveview())
1274
1275 set scrolljump&
1276 bw
1277endfunc
1278
Bakudankun29f3a452021-12-11 12:28:08 +00001279" Test for the 'cdhome' option
1280func Test_opt_cdhome()
1281 if has('unix') || has('vms')
1282 throw 'Skipped: only works on non-Unix'
1283 endif
1284
1285 set cdhome&
1286 call assert_equal(0, &cdhome)
1287 set cdhome
1288
1289 " This paragraph is copied from Test_cd_no_arg().
1290 let path = getcwd()
1291 cd
1292 call assert_equal($HOME, getcwd())
1293 call assert_notequal(path, getcwd())
1294 exe 'cd ' .. fnameescape(path)
1295 call assert_equal(path, getcwd())
1296
1297 set cdhome&
1298endfunc
1299
Christian Brabandtcb747892022-05-08 21:10:56 +01001300func Test_set_completion_2()
1301 CheckOption termguicolors
1302
1303 " Test default option completion
1304 set wildoptions=
1305 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1306 call assert_equal('"set termguicolors', @:)
1307
1308 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1309 call assert_equal('"set notermguicolors', @:)
1310
1311 " Test fuzzy option completion
1312 set wildoptions=fuzzy
1313 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1314 call assert_equal('"set termguicolors termencoding', @:)
1315
1316 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1317 call assert_equal('"set notermguicolors', @:)
1318
1319 set wildoptions=
1320endfunc
1321
Sean Dewar39c46b42022-05-12 17:44:29 +01001322func Test_switchbuf_reset()
1323 set switchbuf=useopen
1324 sblast
1325 call assert_equal(1, winnr('$'))
1326 set all&
1327 call assert_equal('', &switchbuf)
1328 sblast
1329 call assert_equal(2, winnr('$'))
1330 only!
1331endfunc
1332
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001333" vim: shiftwidth=2 sts=2 expandtab