blob: b3b90d142901ca55fd715ae6073933e0dcbd7edd [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&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000049 " Test for setting 'isfname' to an unsupported character
50 let save_isfname = &isfname
51 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
52 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010053endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010054
zeertzjq0519ce02022-05-09 12:16:19 +010055" Test for getting the value of 'pastetoggle'
56func Test_pastetoggle()
57 " character with K_SPECIAL byte
58 let &pastetoggle = '…'
59 call assert_equal('…', &pastetoggle)
60 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
61
62 " modified character with K_SPECIAL byte
63 let &pastetoggle = '<M-…>'
64 call assert_equal('<M-…>', &pastetoggle)
65 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
66
67 " illegal bytes
68 let str = ":\x7f:\x80:\x90:\xd0:"
69 let &pastetoggle = str
70 call assert_equal(str, &pastetoggle)
71 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010072
zeertzjq0519ce02022-05-09 12:16:19 +010073 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010074 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010075endfunc
76
Bram Moolenaar1e115362019-01-09 23:01:02 +010077func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010078 " Empty 'wildchar' used to access invalid memory.
79 call assert_fails('set wildchar=', 'E521:')
80 call assert_fails('set wildchar=abc', 'E521:')
81 set wildchar=<Esc>
82 let a=execute('set wildchar?')
83 call assert_equal("\n wildchar=<Esc>", a)
84 set wildchar=27
85 let a=execute('set wildchar?')
86 call assert_equal("\n wildchar=<Esc>", a)
87 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010088endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010089
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020090func Test_wildoptions()
91 set wildoptions=
92 set wildoptions+=tagfile
93 set wildoptions+=tagfile
94 call assert_equal('tagfile', &wildoptions)
95endfunc
96
Bram Moolenaar6b915c02020-01-18 15:53:19 +010097func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020098 let caught = 'ok'
99 try
100 options
101 catch
102 let caught = v:throwpoint . "\n" . v:exception
103 endtry
104 call assert_equal('ok', caught)
105
Bram Moolenaare0b59492019-05-21 20:54:45 +0200106 " Check if the option-window is opened horizontally.
107 wincmd j
108 call assert_notequal('option-window', bufname(''))
109 wincmd k
110 call assert_equal('option-window', bufname(''))
111 " close option-window
112 close
113
114 " Open the option-window vertically.
115 vert options
116 " Check if the option-window is opened vertically.
117 wincmd l
118 call assert_notequal('option-window', bufname(''))
119 wincmd h
120 call assert_equal('option-window', bufname(''))
121 " close option-window
122 close
123
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200124 " Open the option-window at the top.
125 set splitbelow
126 topleft options
127 call assert_equal(1, winnr())
128 close
129
130 " Open the option-window at the bottom.
131 set nosplitbelow
132 botright options
133 call assert_equal(winnr('$'), winnr())
134 close
135 set splitbelow&
136
Bram Moolenaare0b59492019-05-21 20:54:45 +0200137 " Open the option-window in a new tab.
138 tab options
139 " Check if the option-window is opened in a tab.
140 normal gT
141 call assert_notequal('option-window', bufname(''))
142 normal gt
143 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200144 " close option-window
145 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200146
147 " Open the options window browse
148 if has('browse')
149 browse set
150 call assert_equal('option-window', bufname(''))
151 close
152 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100153endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200154
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200156 " Test that changing 'path' keeps two commas.
157 set path=foo,,bar
158 set path-=bar
159 set path+=bar
160 call assert_equal('foo,,bar', &path)
161
162 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100163endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200164
Dominique Pellef645ee42021-12-05 13:21:18 +0000165func Test_path_too_long()
166 exe 'set path=' .. repeat('x', 10000)
167 call assert_fails('find x', 'E854:')
168 set path&
169endfunc
170
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200171func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200172 CheckFeature signs
173 call assert_equal("auto", &signcolumn)
174 set signcolumn=yes
175 set signcolumn=no
176 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200177endfunc
178
Bram Moolenaard0b51382016-11-04 15:23:45 +0100179func Test_filetype_valid()
180 set ft=valid_name
181 call assert_equal("valid_name", &filetype)
182 set ft=valid-name
183 call assert_equal("valid-name", &filetype)
184
185 call assert_fails(":set ft=wrong;name", "E474:")
186 call assert_fails(":set ft=wrong\\\\name", "E474:")
187 call assert_fails(":set ft=wrong\\|name", "E474:")
188 call assert_fails(":set ft=wrong/name", "E474:")
189 call assert_fails(":set ft=wrong\\\nname", "E474:")
190 call assert_equal("valid-name", &filetype)
191
192 exe "set ft=trunc\x00name"
193 call assert_equal("trunc", &filetype)
194endfunc
195
196func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200197 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100198 set syn=valid_name
199 call assert_equal("valid_name", &syntax)
200 set syn=valid-name
201 call assert_equal("valid-name", &syntax)
202
203 call assert_fails(":set syn=wrong;name", "E474:")
204 call assert_fails(":set syn=wrong\\\\name", "E474:")
205 call assert_fails(":set syn=wrong\\|name", "E474:")
206 call assert_fails(":set syn=wrong/name", "E474:")
207 call assert_fails(":set syn=wrong\\\nname", "E474:")
208 call assert_equal("valid-name", &syntax)
209
210 exe "set syn=trunc\x00name"
211 call assert_equal("trunc", &syntax)
212endfunc
213
214func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200215 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100216 call assert_fails(":set kmp=valid_name", "E544:")
217 call assert_fails(":set kmp=valid_name", "valid_name")
218 call assert_fails(":set kmp=valid-name", "E544:")
219 call assert_fails(":set kmp=valid-name", "valid-name")
220
221 call assert_fails(":set kmp=wrong;name", "E474:")
222 call assert_fails(":set kmp=wrong\\\\name", "E474:")
223 call assert_fails(":set kmp=wrong\\|name", "E474:")
224 call assert_fails(":set kmp=wrong/name", "E474:")
225 call assert_fails(":set kmp=wrong\\\nname", "E474:")
226
227 call assert_fails(":set kmp=trunc\x00name", "E544:")
228 call assert_fails(":set kmp=trunc\x00name", "trunc")
229endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100230
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100231func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100232 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100233 exe 'set ' . a:name . '=/usr/share/dict/words'
234 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
235 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
236 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
237 exe 'set ' . a:name . '=/usr/share/dict\ words'
238 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100239
240 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100241 call assert_fails("set " . a:name . "=/not&there", "E474:")
242 call assert_fails("set " . a:name . "=/not>there", "E474:")
243 call assert_fails("set " . a:name . "=/not.*there", "E474:")
244endfunc
245
Bram Moolenaar60629d62017-02-23 18:08:56 +0100246func Test_cinkeys()
247 " This used to cause invalid memory access
248 set cindent cinkeys=0
249 norm a
250 set cindent& cinkeys&
251endfunc
252
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100253func Test_dictionary()
254 call Check_dir_option('dictionary')
255endfunc
256
257func Test_thesaurus()
258 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100259endfun
260
Bram Moolenaar226c5342017-02-17 14:53:15 +0100261func Test_complete()
262 " Trailing single backslash used to cause invalid memory access.
263 set complete=s\
264 new
265 call feedkeys("i\<C-N>\<Esc>", 'xt')
266 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200267 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100268 set complete&
269endfun
270
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100271func Test_set_completion()
272 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
273 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
274
Bram Moolenaar297610b2019-12-27 17:20:55 +0100275 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
276 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
277
278 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
279 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
280
dundargocc57b5bc2022-11-02 13:30:51 +0000281 " Expand boolean options. When doing :set no<Tab>
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100282 " vim displays the options names without "no" but completion uses "no...".
283 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
284 call assert_equal('"set nodiff digraph', @:)
285
286 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
287 call assert_equal('"set invdiff digraph', @:)
288
289 " Expand abbreviation of options.
290 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100291 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100292
293 " Expand current value
294 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
295 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
296
297 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
298 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
299
300 " Expand key codes.
301 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
302 call assert_equal('"set <Help> <Home>', @:)
303
304 " Expand terminal options.
305 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200306 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200307 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100308
309 " Expand directories.
310 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
311 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200312 call assert_notmatch(' ./summarize.vim ', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100313
314 " Expand files and directories.
315 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200316 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100317
318 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
319 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200320 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200321
322 " Expanding the option names
323 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
324 call assert_equal('"set all', @:)
325
326 " Expanding a second set of option names
327 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
328 call assert_equal('"set wrapscan all', @:)
329
330 " Expanding a special keycode
331 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal('"set <Home>', @:)
333
334 " Expanding an invalid special keycode
335 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
336 call assert_equal("\"set <abcd>\<Tab>", @:)
337
338 " Expanding a terminal keycode
339 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
340 call assert_equal("\"set t_AB", @:)
341
342 " Expanding an invalid option name
343 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
344 call assert_equal("\"set abcde=\<Tab>", @:)
345
346 " Expanding after a = for a boolean option
347 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
348 call assert_equal("\"set wrapscan=\<Tab>", @:)
349
350 " Expanding a numeric option
351 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
352 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
353
354 " Expanding a non-boolean option
355 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
356 call assert_equal("\"set invtabstop=", @:)
357
358 " Expand options for 'spellsuggest'
359 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
360 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
361
362 " Expand value for 'key'
363 set key=abcd
364 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
365 call assert_equal('"set key=*****', @:)
366 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100367
368 " Expand values for 'filetype'
369 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
370 call assert_equal('"set filetype=sshdconfig', @:)
371 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
372 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100373endfunc
374
375func Test_set_errors()
376 call assert_fails('set scroll=-1', 'E49:')
377 call assert_fails('set backupcopy=', 'E474:')
378 call assert_fails('set regexpengine=3', 'E474:')
379 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200380 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100381 call assert_fails('set colorcolumn=-a', 'E474:')
382 call assert_fails('set colorcolumn=a', 'E474:')
383 call assert_fails('set colorcolumn=1,', 'E474:')
384 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100385 call assert_fails('set cmdheight=-1', 'E487:')
386 call assert_fails('set cmdwinheight=-1', 'E487:')
387 if has('conceal')
388 call assert_fails('set conceallevel=-1', 'E487:')
389 call assert_fails('set conceallevel=4', 'E474:')
390 endif
391 call assert_fails('set helpheight=-1', 'E487:')
392 call assert_fails('set history=-1', 'E487:')
393 call assert_fails('set report=-1', 'E487:')
394 call assert_fails('set shiftwidth=-1', 'E487:')
395 call assert_fails('set sidescroll=-1', 'E487:')
396 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000397 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000398 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000399 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100400 call assert_fails('set textwidth=-1', 'E487:')
401 call assert_fails('set timeoutlen=-1', 'E487:')
402 call assert_fails('set updatecount=-1', 'E487:')
403 call assert_fails('set updatetime=-1', 'E487:')
404 call assert_fails('set winheight=-1', 'E487:')
405 call assert_fails('set tabstop!', 'E488:')
406 call assert_fails('set xxx', 'E518:')
407 call assert_fails('set beautify?', 'E519:')
408 call assert_fails('set undolevels=x', 'E521:')
409 call assert_fails('set tabstop=', 'E521:')
410 call assert_fails('set comments=-', 'E524:')
411 call assert_fails('set comments=a', 'E525:')
412 call assert_fails('set foldmarker=x', 'E536:')
413 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000414 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100415 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100416 call assert_fails('set rulerformat=%-', 'E539:')
417 call assert_fails('set rulerformat=%(', 'E542:')
418 call assert_fails('set rulerformat=%15(%%', 'E542:')
419 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100420 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100421 call assert_fails('set statusline=%{%', 'E540:')
422 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100423 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100424 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100425 call assert_fails('set tabline=%$', 'E539:')
426 call assert_fails('set tabline=%{', 'E540:')
427 call assert_fails('set tabline=%{%', 'E540:')
428 call assert_fails('set tabline=%{%}', 'E539:')
429 call assert_fails('set tabline=%(', 'E542:')
430 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100431
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100432 if has('cursorshape')
433 " This invalid value for 'guicursor' used to cause Vim to crash.
434 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
435 call assert_fails('set guicursor=i-ci', 'E545:')
436 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100437 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100438 call assert_fails('set guicursor=r-cr:horx', 'E548:')
439 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
440 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100441 if has('mouseshape')
442 call assert_fails('se mouseshape=i-r:x', 'E547:')
443 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000444
445 " Test for 'backupext' and 'patchmode' set to the same value
446 set backupext=.bak
447 set patchmode=.patch
448 call assert_fails('set patchmode=.bak', 'E589:')
449 call assert_equal('.patch', &patchmode)
450 call assert_fails('set backupext=.patch', 'E589:')
451 call assert_equal('.bak', &backupext)
452 set backupext& patchmode&
453
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100454 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200455 set winminheight& winheight&
456 set winheight=10 winminheight=10
457 call assert_fails('set winheight=9', 'E591:')
458 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100459 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200460 set winminwidth& winwidth&
461 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
462 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100463 call assert_fails("set showbreak=\x01", 'E595:')
464 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200465 call assert_fails('set tabstop??', 'E488:')
466 call assert_fails('set wrapscan!!', 'E488:')
467 call assert_fails('set tabstop&&', 'E488:')
468 call assert_fails('set wrapscan<<', 'E488:')
469 call assert_fails('set wrapscan=1', 'E474:')
470 call assert_fails('set autoindent@', 'E488:')
471 call assert_fails('set wildchar=<abc>', 'E474:')
472 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200473 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100474 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200475 call assert_fails('set pyxversion=6', 'E474:')
476 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200477 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200478 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100479 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
480 call assert_fails('set foldmarker={{{,', 'E474:')
481 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100482 setlocal listchars=trail:·
483 call assert_fails('set ambiwidth=double', 'E834:')
484 setlocal listchars=trail:-
485 setglobal listchars=trail:·
486 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100487 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100488 setlocal fillchars=stl:·
489 call assert_fails('set ambiwidth=double', 'E835:')
490 setlocal fillchars=stl:-
491 setglobal fillchars=stl:·
492 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100493 set fillchars&
494 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
495 set nomodifiable
496 call assert_fails('set fileencoding=latin1', 'E21:')
497 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200498 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000499 call assert_fails('let &formatoptions = "?"', 'E539:')
500 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100501endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100502
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000503func Test_set_encoding()
504 let save_encoding = &encoding
505
506 set enc=iso8859-1
507 call assert_equal('latin1', &enc)
508 set enc=iso8859_1
509 call assert_equal('latin1', &enc)
510 set enc=iso-8859-1
511 call assert_equal('latin1', &enc)
512 set enc=iso_8859_1
513 call assert_equal('latin1', &enc)
514 set enc=iso88591
515 call assert_equal('latin1', &enc)
516 set enc=iso8859
517 call assert_equal('latin1', &enc)
518 set enc=iso-8859
519 call assert_equal('latin1', &enc)
520 set enc=iso_8859
521 call assert_equal('latin1', &enc)
522 call assert_fails('set enc=iso8858', 'E474:')
523 call assert_equal('latin1', &enc)
524
525 let &encoding = save_encoding
526endfunc
527
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200528func CheckWasSet(name)
529 let verb_cm = execute('verbose set ' .. a:name .. '?')
530 call assert_match('Last set from.*test_options.vim', verb_cm)
531endfunc
532func CheckWasNotSet(name)
533 let verb_cm = execute('verbose set ' .. a:name .. '?')
534 call assert_notmatch('Last set from', verb_cm)
535endfunc
536
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200537" Must be executed before other tests that set 'term'.
538func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200539 CheckNotGui
540
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200541 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200542
543 let term_save = &term
544 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200545 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200546 let &term = term_save
547endfunc
548
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200549func Test_copy_context()
550 setlocal list
551 call CheckWasSet('list')
552 split
553 call CheckWasSet('list')
554 quit
555 setlocal nolist
556
557 set ai
558 call CheckWasSet('ai')
559 set filetype=perl
560 call CheckWasSet('filetype')
561 set fo=tcroq
562 call CheckWasSet('fo')
563
564 split Xsomebuf
565 call CheckWasSet('ai')
566 call CheckWasNotSet('filetype')
567 call CheckWasSet('fo')
568endfunc
569
Bram Moolenaar67391142017-02-19 21:07:04 +0100570func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200571 CheckUnix
572 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200573
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200574 " Setting 'ttytype' used to cause a double-free when exiting vim and
575 " when vim is compiled with -DEXITFREE.
576 set ttytype=ansi
577 call assert_equal('ansi', &ttytype)
578 call assert_equal(&ttytype, &term)
579 set ttytype=xterm
580 call assert_equal('xterm', &ttytype)
581 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200582 try
583 set ttytype=
584 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100585 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200586 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200587
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200588 " Some systems accept any terminal name and return dumb settings,
589 " check for failure of finding the entry and for missing 'cm' entry.
590 try
591 set ttytype=xxx
592 call assert_report('set ttytype=xxx did not fail')
593 catch /E522\|E437/
594 endtry
595
596 set ttytype&
597 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200598
599 if has('gui') && !has('gui_running')
600 call assert_fails('set term=gui', 'E531:')
601 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100602endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100603
604func Test_set_all()
605 set tw=75
606 set iskeyword=a-z,A-Z
607 set nosplitbelow
608 let out = execute('set all')
609 call assert_match('textwidth=75', out)
610 call assert_match('iskeyword=a-z,A-Z', out)
611 call assert_match('nosplitbelow', out)
612 set tw& iskeyword& splitbelow&
613endfunc
614
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100615func Test_set_one_column()
616 let out_mult = execute('set all')->split("\n")
617 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100618 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100619endfunc
620
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100621func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200622 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100623 if filereadable('opt_test.vim')
624 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100625 else
626 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100627 endif
628endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200629
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100630func Test_renderoptions()
631 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
632 " Doesn't hurt to do this on a non-Windows system.
633 if windowsversion() !~ '^[345]\.'
634 set renderoptions=type:directx
635 set rop=type:directx
636 endif
637endfunc
638
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200639func ResetIndentexpr()
640 set indentexpr=
641endfunc
642
643func Test_set_indentexpr()
644 " this was causing usage of freed memory
645 set indentexpr=ResetIndentexpr()
646 new
647 call feedkeys("i\<c-f>", 'x')
648 call assert_equal('', &indentexpr)
649 bwipe!
650endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200651
652func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100653 " Option 'backupskip' may contain several comma-separated path
654 " specifications if one or more of the environment variables TMPDIR, TMP,
655 " or TEMP is defined. To simplify testing, convert the string value into a
656 " list.
657 let bsklist = split(&bsk, ',')
658
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200659 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100660 let found = (index(bsklist, '/private/tmp/*') >= 0)
661 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200662 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100663 let found = (index(bsklist, '/tmp/*') >= 0)
664 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200665 endif
666
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100667 " If our test platform is Windows, the path(s) in option bsk will use
668 " backslash for the path separator and the components could be in short
669 " (8.3) format. As such, we need to replace the backslashes with forward
670 " slashes and convert the path components to long format. The expand()
671 " function will do this but it cannot handle comma-separated paths. This is
672 " why bsk was converted from a string into a list of strings above.
673 "
674 " One final complication is that the wildcard "/*" is at the end of each
675 " path and so expand() might return a list of matching files. To prevent
676 " this, we need to remove the wildcard before calling expand() and then
677 " append it afterwards.
678 if has('win32')
679 let item_nbr = 0
680 while item_nbr < len(bsklist)
681 let path_spec = bsklist[item_nbr]
682 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
683 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
684 let bsklist[item_nbr] = path_spec . '/*'
685 let item_nbr += 1
686 endwhile
687 endif
688
689 " Option bsk will also include these environment variables if defined.
690 " If they're defined, verify they appear in the option value.
691 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200692 if exists(var)
693 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100694 let varvalue = substitute(varvalue, '/$', '', '')
695 let varvalue .= '/*'
696 let found = (index(bsklist, varvalue) >= 0)
697 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200698 endif
699 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200700
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200701 " Duplicates from environment variables should be filtered out (option has
702 " P_NODUP). Run this in a separate instance and write v:errors in a file,
703 " so that we see what happens on startup.
704 let after =<< trim [CODE]
705 let bsklist = split(&backupskip, ',')
706 call assert_equal(uniq(copy(bsklist)), bsklist)
707 call writefile(['errors:'] + v:errors, 'Xtestout')
708 qall
709 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100710 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200711 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
712
713 let saveenv = {}
714 for var in ['TMPDIR', 'TMP', 'TEMP']
715 let saveenv[var] = getenv(var)
716 call setenv(var, '/duplicate/path')
717 endfor
718
719 exe 'silent !' . cmd
720 call assert_equal(['errors:'], readfile('Xtestout'))
721
722 " restore environment variables
723 for var in ['TMPDIR', 'TMP', 'TEMP']
724 call setenv(var, saveenv[var])
725 endfor
726
727 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200728
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200729 " Duplicates should be filtered out (option has P_NODUP)
730 let backupskip = &backupskip
731 set backupskip=
732 set backupskip+=/test/dir
733 set backupskip+=/other/dir
734 set backupskip+=/test/dir
735 call assert_equal('/test/dir,/other/dir', &backupskip)
736 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200737endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200738
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100739func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200740 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200741
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200742 " Test copy option from current buffer in window
743 split
744 enew
745 setlocal numberwidth=5
746 wincmd w
747 call assert_equal(4,&numberwidth)
748 bnext
749 call assert_equal(5,&numberwidth)
750 bw!
751 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200752
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200753 " Test copy value from window that used to be display the buffer
754 split
755 enew
756 setlocal numberwidth=6
757 bnext
758 wincmd w
759 call assert_equal(4,&numberwidth)
760 bnext
761 call assert_equal(6,&numberwidth)
762 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200763
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200764 " Test that if buffer is current, don't use the stale cached value
765 " from the last time the buffer was displayed.
766 split
767 enew
768 setlocal numberwidth=7
769 bnext
770 bnext
771 setlocal numberwidth=8
772 wincmd w
773 call assert_equal(4,&numberwidth)
774 bnext
775 call assert_equal(8,&numberwidth)
776 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200777
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200778 " Test value is not copied if window already has seen the buffer
779 enew
780 split
781 setlocal numberwidth=9
782 bnext
783 setlocal numberwidth=10
784 wincmd w
785 call assert_equal(4,&numberwidth)
786 bnext
787 call assert_equal(4,&numberwidth)
788 bw!
789
790 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200791endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200792
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100793def Test_split_copy_options()
794 var values = [
795 ['cursorbind', true, false],
796 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
797 ['list', true, 0],
798 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
799 ['number', true, 0],
800 ['relativenumber', true, false],
801 ['scrollbind', true, false],
802 ['smoothscroll', true, false],
803 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
804 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
805 ['wrap', false, true],
806 ]
807 if has('linebreak')
808 values += [
809 ['breakindent', true, false],
810 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
811 ['linebreak', true, false],
812 ['numberwidth', 7, 4],
813 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
814 ]
815 endif
816 if has('rightleft')
817 values += [
818 ['rightleft', true, false],
819 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
820 ]
821 endif
822 if has('statusline')
823 values += [
824 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
825 ]
826 endif
827 if has('spell')
828 values += [
829 ['spell', true, false],
830 ]
831 endif
832 if has('syntax')
833 values += [
834 ['cursorcolumn', true, false],
835 ['cursorline', true, false],
836 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
837 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
838 ]
839 endif
840 if has('diff')
841 values += [
842 ['diff', true, false],
843 ]
844 endif
845 if has('conceal')
846 values += [
847 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
848 ['conceallevel', '3', &conceallevel],
849 ]
850 endif
851 if has('terminal')
852 values += [
853 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
854 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
855 ]
856 endif
857 if has('folding')
858 values += [
859 ['foldcolumn', 5, &foldcolumn],
860 ['foldenable', false, true],
861 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
862 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
863 ['foldlevel', 4, &foldlevel],
864 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
865 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
866 ['foldminlines', 3, &foldminlines],
867 ['foldnestmax', 17, &foldnestmax],
868 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
869 ]
870 endif
871 if has('signs')
872 values += [
873 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
874 ]
875 endif
876
877 # set options to non-default value
878 for item in values
879 exe $'&l:{item[0]} = {item[1]}'
880 endfor
881
882 # check values are set in new window
883 split
884 for item in values
885 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
886 endfor
887
888 # restore
889 close
890 for item in values
891 exe $'&l:{item[0]} = {item[2]}'
892 endfor
893enddef
894
Bram Moolenaarfc089602018-06-24 16:53:35 +0200895func Test_shortmess_F()
896 new
897 call assert_match('\[No Name\]', execute('file'))
898 set shortmess+=F
899 call assert_match('\[No Name\]', execute('file'))
900 call assert_match('^\s*$', execute('file foo'))
901 call assert_match('foo', execute('file'))
902 set shortmess-=F
903 call assert_match('bar', execute('file bar'))
904 call assert_match('bar', execute('file'))
905 set shortmess&
906 bwipe
907endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200908
909func Test_shortmess_F2()
910 e file1
911 e file2
912 call assert_match('file1', execute('bn', ''))
913 call assert_match('file2', execute('bn', ''))
914 set shortmess+=F
915 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200916 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200917 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200918 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200919 set hidden
920 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200921 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200922 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200923 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200924 set nohidden
925 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200926 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200927 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200928 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200929 set shortmess&
930 call assert_match('file1', execute('bn', ''))
931 call assert_match('file2', execute('bn', ''))
932 bwipe
933 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +0100934 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200935endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100936
937func Test_local_scrolloff()
938 set so=5
939 set siso=7
940 split
941 call assert_equal(5, &so)
942 setlocal so=3
943 call assert_equal(3, &so)
944 wincmd w
945 call assert_equal(5, &so)
946 wincmd w
947 setlocal so<
948 call assert_equal(5, &so)
949 setlocal so=0
950 call assert_equal(0, &so)
951 setlocal so=-1
952 call assert_equal(5, &so)
953
954 call assert_equal(7, &siso)
955 setlocal siso=3
956 call assert_equal(3, &siso)
957 wincmd w
958 call assert_equal(7, &siso)
959 wincmd w
960 setlocal siso<
961 call assert_equal(7, &siso)
962 setlocal siso=0
963 call assert_equal(0, &siso)
964 setlocal siso=-1
965 call assert_equal(7, &siso)
966
967 close
968 set so&
969 set siso&
970endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200971
972func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100973 CheckFunction reltimefloat
974
Bram Moolenaar449ac472019-04-03 21:42:35 +0200975 new
976 call setline(1, 'empty')
977 redraw
978 set writedelay=10
979 let start = reltime()
980 call setline(1, repeat('x', 70))
981 redraw
982 let elapsed = reltimefloat(reltime(start))
983 set writedelay=0
984 " With 'writedelay' set should take at least 30 * 10 msec
985 call assert_inrange(30 * 0.01, 999.0, elapsed)
986
987 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200988endfunc
989
990func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200991 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200992 set visualbell
993 call assert_beeps('normal 0h')
994 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200995 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200996endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100997
998" Test for the 'write' option
999func Test_write()
1000 new
1001 call setline(1, ['L1'])
1002 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001003 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001004 set write
1005 close!
1006endfunc
1007
1008" Test for 'buftype' option
1009func Test_buftype()
1010 new
1011 call setline(1, ['L1'])
1012 set buftype=nowrite
1013 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001014
1015 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1016 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001017 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001018 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1019 endfor
1020
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001021 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001022endfunc
1023
Bram Moolenaar578fe942020-02-27 21:32:51 +01001024" Test for the 'rightleftcmd' option
1025func Test_rightleftcmd()
1026 CheckFeature rightleft
1027 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001028
1029 let g:l = []
1030 func AddPos()
1031 call add(g:l, screencol())
1032 return ''
1033 endfunc
1034 cmap <expr> <F2> AddPos()
1035
zeertzjqbb404f52022-07-23 06:25:29 +01001036 set rightleftcmd=
1037 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1038 \ "\<Right>\<F2>\<Esc>", 'xt')
1039 call assert_equal([2, 5, 3, 4], g:l)
1040
1041 let g:l = []
1042 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001043 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1044 \ "\<Left>\<F2>\<Esc>", 'xt')
1045 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1046
1047 cunmap <F2>
1048 unlet g:l
1049 set rightleftcmd&
1050 set rightleft&
1051endfunc
1052
zeertzjq28c162f2022-08-14 14:49:50 +01001053" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001054func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001055 " redraw to avoid matching previous messages
1056 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001057 set debug=beep
1058 exe "normal \<C-c>"
1059 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001060 call assert_equal('line 4:', Screenline(&lines - 1))
1061 " only match the final colon in the line that shows the source
1062 call assert_match(':$', Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001063 set debug&
1064endfunc
1065
Bram Moolenaar004a6782020-04-11 17:09:31 +02001066" Test for the default CDPATH option
1067func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001068 let after =<< trim [CODE]
1069 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1070 call writefile(v:errors, 'Xtestout')
1071 qall
1072 [CODE]
1073 if has('unix')
1074 let $CDPATH='/path/to/dir1:/path/to/dir2'
1075 else
1076 let $CDPATH='/path/to/dir1;/path/to/dir2'
1077 endif
1078 if RunVim([], after, '')
1079 call assert_equal([], readfile('Xtestout'))
1080 call delete('Xtestout')
1081 endif
1082endfunc
1083
1084" Test for setting keycodes using set
1085func Test_opt_set_keycode()
1086 call assert_fails('set <t_k1=l', 'E474:')
1087 call assert_fails('set <Home=l', 'E474:')
1088 set <t_k9>=abcd
1089 call assert_equal('abcd', &t_k9)
1090 set <t_k9>&
1091 set <F9>=xyz
1092 call assert_equal('xyz', &t_k9)
1093 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001094
1095 " should we test all of them?
1096 set t_Ce=testCe
1097 set t_Cs=testCs
1098 set t_Us=testUs
1099 set t_ds=testds
1100 set t_Ds=testDs
1101 call assert_equal('testCe', &t_Ce)
1102 call assert_equal('testCs', &t_Cs)
1103 call assert_equal('testUs', &t_Us)
1104 call assert_equal('testds', &t_ds)
1105 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001106endfunc
1107
1108" Test for changing options in a sandbox
1109func Test_opt_sandbox()
1110 for opt in ['backupdir', 'cdpath', 'exrc']
1111 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001112 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001113 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001114 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001115endfunc
1116
1117" Test for setting an option with local value to global value
1118func Test_opt_local_to_global()
1119 setglobal equalprg=gprg
1120 setlocal equalprg=lprg
1121 call assert_equal('gprg', &g:equalprg)
1122 call assert_equal('lprg', &l:equalprg)
1123 call assert_equal('lprg', &equalprg)
1124 set equalprg<
1125 call assert_equal('', &l:equalprg)
1126 call assert_equal('gprg', &equalprg)
1127 setglobal equalprg=gnewprg
1128 setlocal equalprg=lnewprg
1129 setlocal equalprg<
1130 call assert_equal('gnewprg', &l:equalprg)
1131 call assert_equal('gnewprg', &equalprg)
1132 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001133
1134 " Test for setting the global/local value of a boolean option
1135 setglobal autoread
1136 setlocal noautoread
1137 call assert_false(&autoread)
1138 set autoread<
1139 call assert_true(&autoread)
1140 setglobal noautoread
1141 setlocal autoread
1142 setlocal autoread<
1143 call assert_false(&autoread)
1144 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001145endfunc
1146
Dominique Pelle042414f2021-07-12 21:43:19 +02001147func Test_set_in_sandbox()
1148 " Some boolean options cannot be set in sandbox, some can.
1149 call assert_fails('sandbox set modelineexpr', 'E48:')
1150 sandbox set number
1151 call assert_true(&number)
1152 set number&
1153
1154 " Some boolean options cannot be set in sandbox, some can.
1155 if has('python') || has('python3')
1156 call assert_fails('sandbox set pyxversion=3', 'E48:')
1157 endif
1158 sandbox set tabstop=4
1159 call assert_equal(4, &tabstop)
1160 set tabstop&
1161
1162 " Some string options cannot be set in sandbox, some can.
1163 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1164 sandbox set filetype=perl
1165 call assert_equal('perl', &filetype)
1166 set filetype&
1167endfunc
1168
Bram Moolenaar004a6782020-04-11 17:09:31 +02001169" Test for incrementing, decrementing and multiplying a number option value
1170func Test_opt_num_op()
1171 set shiftwidth=4
1172 set sw+=2
1173 call assert_equal(6, &sw)
1174 set sw-=2
1175 call assert_equal(4, &sw)
1176 set sw^=2
1177 call assert_equal(8, &sw)
1178 set shiftwidth&
1179endfunc
1180
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001181" Test for setting option values using v:false and v:true
1182func Test_opt_boolean()
1183 set number&
1184 set number
1185 call assert_equal(1, &nu)
1186 set nonu
1187 call assert_equal(0, &nu)
1188 let &nu = v:true
1189 call assert_equal(1, &nu)
1190 let &nu = v:false
1191 call assert_equal(0, &nu)
1192 set number&
1193endfunc
1194
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001195" Test for the 'window' option
1196func Test_window_opt()
1197 " Needs only one open widow
1198 %bw!
1199 call setline(1, range(1, 8))
1200 set window=5
1201 exe "normal \<C-F>"
1202 call assert_equal(4, line('w0'))
1203 exe "normal \<C-F>"
1204 call assert_equal(7, line('w0'))
1205 exe "normal \<C-F>"
1206 call assert_equal(8, line('w0'))
1207 exe "normal \<C-B>"
1208 call assert_equal(5, line('w0'))
1209 exe "normal \<C-B>"
1210 call assert_equal(2, line('w0'))
1211 exe "normal \<C-B>"
1212 call assert_equal(1, line('w0'))
1213 set window=1
1214 exe "normal gg\<C-F>"
1215 call assert_equal(2, line('w0'))
1216 exe "normal \<C-F>"
1217 call assert_equal(3, line('w0'))
1218 exe "normal \<C-B>"
1219 call assert_equal(2, line('w0'))
1220 exe "normal \<C-B>"
1221 call assert_equal(1, line('w0'))
1222 enew!
1223 set window&
1224endfunc
1225
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001226" Test for the 'winminheight' option
1227func Test_opt_winminheight()
1228 only!
1229 let &winheight = &lines + 4
1230 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1231 call assert_true(&winminheight <= &lines)
1232 set winminheight&
1233 set winheight&
1234endfunc
1235
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001236func Test_opt_winminheight_term()
1237 CheckRunVimInTerminal
1238
1239 " The tabline should be taken into account.
1240 let lines =<< trim END
1241 set wmh=0 stal=2
1242 below sp | wincmd _
1243 below sp | wincmd _
1244 below sp | wincmd _
1245 below sp
1246 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001247 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001248 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1249 call term_sendkeys(buf, ":set wmh=1\n")
1250 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1251
1252 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001253endfunc
1254
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001255func Test_opt_winminheight_term_tabs()
1256 CheckRunVimInTerminal
1257
1258 " The tabline should be taken into account.
1259 let lines =<< trim END
1260 set wmh=0 stal=2
1261 split
1262 split
1263 split
1264 split
1265 tabnew
1266 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001267 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001268 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1269 call term_sendkeys(buf, ":set wmh=1\n")
1270 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1271
1272 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001273endfunc
1274
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001275" Test for the 'winminwidth' option
1276func Test_opt_winminwidth()
1277 only!
1278 let &winwidth = &columns + 4
1279 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1280 call assert_true(&winminwidth <= &columns)
1281 set winminwidth&
1282 set winwidth&
1283endfunc
1284
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001285" Test for setting option value containing spaces with isfname+=32
1286func Test_isfname_with_options()
1287 set isfname+=32
1288 setlocal keywordprg=:term\ help.exe
1289 call assert_equal(':term help.exe', &keywordprg)
1290 set isfname&
1291 setlocal keywordprg&
1292endfunc
1293
Bram Moolenaar74667062020-12-28 15:41:41 +01001294" Test that resetting laststatus does change scroll option
1295func Test_opt_reset_scroll()
1296 CheckRunVimInTerminal
1297 let vimrc =<< trim [CODE]
1298 set scroll=2
1299 set laststatus=2
1300 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001301 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001302 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1303 call term_sendkeys(buf, ":verbose set scroll?\n")
1304 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1305 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001306
1307 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001308 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001309endfunc
1310
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001311" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1312func Test_VIM_POSIX()
1313 let saved_VIM_POSIX = getenv("VIM_POSIX")
1314
1315 call setenv('VIM_POSIX', "1")
1316 let after =<< trim [CODE]
1317 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1318 qall
1319 [CODE]
1320 if RunVim([], after, '')
1321 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1322 \ 'AS'], readfile('X_VIM_POSIX'))
1323 endif
1324
1325 call setenv('VIM_POSIX', v:null)
1326 let after =<< trim [CODE]
1327 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1328 qall
1329 [CODE]
1330 if RunVim([], after, '')
1331 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1332 \ 'S'], readfile('X_VIM_POSIX'))
1333 endif
1334
1335 call delete('X_VIM_POSIX')
1336 call setenv('VIM_POSIX', saved_VIM_POSIX)
1337endfunc
1338
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001339" Test for setting an option to a Vi or Vim default
1340func Test_opt_default()
1341 set formatoptions&vi
1342 call assert_equal('vt', &formatoptions)
1343 set formatoptions&vim
1344 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001345
1346 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1347 set fencs=latin1
1348 set fencs&
1349 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1350 set fencs=latin1
1351 set all&
1352 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001353endfunc
1354
1355" Test for the 'cmdheight' option
1356func Test_cmdheight()
1357 %bw!
1358 let ht = &lines
1359 set cmdheight=9999
1360 call assert_equal(1, winheight(0))
1361 call assert_equal(ht - 1, &cmdheight)
1362 set cmdheight&
1363endfunc
1364
Dominique Pelle923dce22021-11-21 11:36:04 +00001365" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001366func Test_opt_control_char()
1367 set wildchar=^v
1368 call assert_equal("\<C-V>", nr2char(&wildchar))
1369 set wildcharm=^r
1370 call assert_equal("\<C-R>", nr2char(&wildcharm))
1371 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1372 set wildchar& wildcharm&
1373endfunc
1374
1375" Test for the 'errorbells' option
1376func Test_opt_errorbells()
1377 set errorbells
1378 call assert_beeps('s/a1b2/x1y2/')
1379 set noerrorbells
1380endfunc
1381
Dominique Pelle042414f2021-07-12 21:43:19 +02001382func Test_opt_scrolljump()
1383 help
1384 resize 10
1385
1386 " Test with positive 'scrolljump'.
1387 set scrolljump=2
1388 norm! Lj
1389 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1390 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1391 \ winsaveview())
1392
1393 " Test with negative 'scrolljump' (percentage of window height).
1394 set scrolljump=-40
1395 norm! ggLj
1396 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1397 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1398 \ winsaveview())
1399
1400 set scrolljump&
1401 bw
1402endfunc
1403
Bakudankun29f3a452021-12-11 12:28:08 +00001404" Test for the 'cdhome' option
1405func Test_opt_cdhome()
1406 if has('unix') || has('vms')
1407 throw 'Skipped: only works on non-Unix'
1408 endif
1409
1410 set cdhome&
1411 call assert_equal(0, &cdhome)
1412 set cdhome
1413
1414 " This paragraph is copied from Test_cd_no_arg().
1415 let path = getcwd()
1416 cd
1417 call assert_equal($HOME, getcwd())
1418 call assert_notequal(path, getcwd())
1419 exe 'cd ' .. fnameescape(path)
1420 call assert_equal(path, getcwd())
1421
1422 set cdhome&
1423endfunc
1424
Christian Brabandtcb747892022-05-08 21:10:56 +01001425func Test_set_completion_2()
1426 CheckOption termguicolors
1427
1428 " Test default option completion
1429 set wildoptions=
1430 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1431 call assert_equal('"set termguicolors', @:)
1432
1433 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1434 call assert_equal('"set notermguicolors', @:)
1435
1436 " Test fuzzy option completion
1437 set wildoptions=fuzzy
1438 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1439 call assert_equal('"set termguicolors termencoding', @:)
1440
1441 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1442 call assert_equal('"set notermguicolors', @:)
1443
1444 set wildoptions=
1445endfunc
1446
Sean Dewar39c46b42022-05-12 17:44:29 +01001447func Test_switchbuf_reset()
1448 set switchbuf=useopen
1449 sblast
1450 call assert_equal(1, winnr('$'))
1451 set all&
1452 call assert_equal('', &switchbuf)
1453 sblast
1454 call assert_equal(2, winnr('$'))
1455 only!
1456endfunc
1457
zeertzjqfcba86c2022-09-22 13:57:32 +01001458" :set empty string for global 'keywordprg' falls back to ":help"
1459func Test_keywordprg_empty()
1460 let k = &keywordprg
1461 set keywordprg=man
1462 call assert_equal('man', &keywordprg)
1463 set keywordprg=
1464 call assert_equal(':help', &keywordprg)
1465 set keywordprg=man
1466 call assert_equal('man', &keywordprg)
1467 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1468 let &keywordprg = k
1469endfunc
1470
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001471" check that the very first buffer created does not have 'endoffile' set
1472func Test_endoffile_default()
1473 let after =<< trim [CODE]
1474 call writefile([execute('set eof?')], 'Xtestout')
1475 qall!
1476 [CODE]
1477 if RunVim([], after, '')
1478 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1479 endif
1480 call delete('Xtestout')
1481endfunc
1482
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001483" Test for setting the 'lines' and 'columns' options to a minimum value
1484func Test_set_min_lines_columns()
1485 let save_lines = &lines
1486 let save_columns = &columns
1487
1488 let after =<< trim END
1489 set nomore
1490 let msg = []
1491 let v:errmsg = ''
1492 silent! let &columns=0
1493 call add(msg, v:errmsg)
1494 silent! set columns=0
1495 call add(msg, v:errmsg)
1496 silent! call setbufvar('', '&columns', 0)
1497 call add(msg, v:errmsg)
1498 "call writefile(msg, 'XResultsetminlines')
1499 silent! let &lines=0
1500 call add(msg, v:errmsg)
1501 silent! set lines=0
1502 call add(msg, v:errmsg)
1503 silent! call setbufvar('', '&lines', 0)
1504 call add(msg, v:errmsg)
1505 call writefile(msg, 'XResultsetminlines')
1506 qall!
1507 END
1508 if RunVim([], after, '')
1509 call assert_equal(['E594: Need at least 12 columns',
1510 \ 'E594: Need at least 12 columns: columns=0',
1511 \ 'E594: Need at least 12 columns',
1512 \ 'E593: Need at least 2 lines',
1513 \ 'E593: Need at least 2 lines: lines=0',
1514 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1515 endif
1516
1517 call delete('XResultsetminlines')
1518 let &lines = save_lines
1519 let &columns = save_columns
1520endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001521
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001522" Test for reverting a string option value if the new value is invalid.
1523func Test_string_option_revert_on_failure()
1524 new
1525 let optlist = [
1526 \ ['ambiwidth', 'double', 'a123'],
1527 \ ['background', 'dark', 'a123'],
1528 \ ['backspace', 'eol', 'a123'],
1529 \ ['backupcopy', 'no', 'a123'],
1530 \ ['belloff', 'showmatch', 'a123'],
1531 \ ['breakindentopt', 'min:10', 'list'],
1532 \ ['bufhidden', 'wipe', 'a123'],
1533 \ ['buftype', 'nowrite', 'a123'],
1534 \ ['casemap', 'keepascii', 'a123'],
1535 \ ['cedit', "\<C-Y>", 'z'],
1536 \ ['colorcolumn', '10', 'z'],
1537 \ ['commentstring', '#%s', 'a123'],
1538 \ ['complete', '.,t', 'a'],
1539 \ ['completefunc', 'MyCmplFunc', '1a-'],
1540 \ ['completeopt', 'popup', 'a123'],
1541 \ ['completepopup', 'width:20', 'border'],
1542 \ ['concealcursor', 'v', 'xyz'],
1543 \ ['cpoptions', 'HJ', '~'],
1544 \ ['cryptmethod', 'zip', 'a123'],
1545 \ ['cursorlineopt', 'screenline', 'a123'],
1546 \ ['debug', 'throw', 'a123'],
1547 \ ['diffopt', 'iwhite', 'a123'],
1548 \ ['display', 'uhex', 'a123'],
1549 \ ['eadirection', 'hor', 'a123'],
1550 \ ['encoding', 'utf-8', 'a123'],
1551 \ ['eventignore', 'TextYankPost', 'a123'],
1552 \ ['fileencoding', 'utf-8', 'a123,'],
1553 \ ['fileformat', 'mac', 'a123'],
1554 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001555 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001556 \ ['fillchars', 'diff:~', 'a123'],
1557 \ ['foldclose', 'all', 'a123'],
1558 \ ['foldmarker', '[[[,]]]', '[[['],
1559 \ ['foldmethod', 'marker', 'a123'],
1560 \ ['foldopen', 'percent', 'a123'],
1561 \ ['formatoptions', 'an', '*'],
1562 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1563 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001564 \ ['highlight', '!:CursorColumn', '8:'],
1565 \ ['keymodel', 'stopsel', 'a123'],
1566 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1567 \ ['lispoptions', 'expr:1', 'a123'],
1568 \ ['listchars', 'tab:->', 'tab:'],
1569 \ ['matchpairs', '<:>', '<:'],
1570 \ ['mkspellmem', '100000,1000,100', '100000'],
1571 \ ['mouse', 'nvi', 'z'],
1572 \ ['mousemodel', 'extend', 'a123'],
1573 \ ['nrformats', 'alpha', 'a123'],
1574 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1575 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1576 \ ['previewpopup', 'width:20', 'a123'],
1577 \ ['printoptions', 'paper:A4', 'a123:'],
1578 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1579 \ ['rulerformat', '%l', '%['],
1580 \ ['scrollopt', 'hor,jump', 'a123'],
1581 \ ['selection', 'exclusive', 'a123'],
1582 \ ['selectmode', 'cmd', 'a123'],
1583 \ ['sessionoptions', 'options', 'a123'],
1584 \ ['shortmess', 'w', '2'],
1585 \ ['showbreak', '>>', "\x01"],
1586 \ ['showcmdloc', 'statusline', 'a123'],
1587 \ ['signcolumn', 'no', 'a123'],
1588 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1589 \ ['spellfile', 'MySpell.en.add', "\x01"],
1590 \ ['spelllang', 'en', "#"],
1591 \ ['spelloptions', 'camel', 'a123'],
1592 \ ['spellsuggest', 'double', 'a123'],
1593 \ ['splitkeep', 'topline', 'a123'],
1594 \ ['statusline', '%f', '%['],
1595 \ ['swapsync', 'sync', 'a123'],
1596 \ ['switchbuf', 'usetab', 'a123'],
1597 \ ['syntax', 'abc', 'a^b'],
1598 \ ['tabline', '%f', '%['],
1599 \ ['tagcase', 'ignore', 'a123'],
1600 \ ['tagfunc', 'MyTagFunc', '1a-'],
1601 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1602 \ ['viewoptions', 'options', 'a123'],
1603 \ ['virtualedit', 'onemore', 'a123'],
1604 \ ['whichwrap', '<,>', '{,}'],
1605 \ ['wildmode', 'list', 'a123'],
1606 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001607 \ ]
1608 if has('gui')
1609 call add(optlist, ['browsedir', 'buffer', 'a123'])
1610 endif
1611 if has('clipboard_working')
1612 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1613 endif
1614 if has('win32')
1615 call add(optlist, ['completeslash', 'slash', 'a123'])
1616 endif
1617 if has('cscope')
1618 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1619 endif
1620 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001621 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1622 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1623 endif
1624 if has('keymap')
1625 call add(optlist, ['keymap', 'greek', '[]'])
1626 endif
1627 if has('mouseshape')
1628 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1629 endif
1630 if has('win32') && has('gui')
1631 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1632 endif
1633 if has('rightleft')
1634 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1635 endif
1636 if has('terminal')
1637 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1638 call add(optlist, ['termwinsize', '24x80', '100'])
1639 endif
1640 if has('win32') && has('terminal')
1641 call add(optlist, ['termwintype', 'winpty', 'a123'])
1642 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001643 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001644 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001645 endif
1646 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001647 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1648 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001649 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001650 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1651 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001652 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001653 call add(optlist, ['varsofttabstop', '12', 'a123'])
1654 call add(optlist, ['vartabstop', '4,20', '4,'])
1655 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001656 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001657 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001658 endif
1659 for opt in optlist
1660 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001661 try
1662 exe $"let &{opt[0]} = '{opt[1]}'"
1663 catch
1664 call assert_report($"Caught {v:exception} with {opt->string()}")
1665 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001666 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1667 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1668 exe $"let &{opt[0]} = save_opt"
1669 endfor
1670 bw!
1671endfunc
1672
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001673" vim: shiftwidth=2 sts=2 expandtab