blob: d33389ac8db365909da2482381c822bbe873cfa3 [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
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100281 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
282 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100283 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100284 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100285
286 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100287 call assert_equal('"set invdiff invdigraph', @:)
288
289 " Expanding "set noinv" does nothing.
290 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
291 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100292
293 " Expand abbreviation of options.
294 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100295 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100296
297 " Expand current value
298 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
299 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
300
301 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
302 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
303
304 " Expand key codes.
305 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
306 call assert_equal('"set <Help> <Home>', @:)
307
308 " Expand terminal options.
309 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200310 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200311 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100312
313 " Expand directories.
314 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
315 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200316 call assert_notmatch(' ./summarize.vim ', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100317
318 " Expand files and directories.
319 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200320 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100321
322 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
323 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200324 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200325
326 " Expanding the option names
327 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
328 call assert_equal('"set all', @:)
329
330 " Expanding a second set of option names
331 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal('"set wrapscan all', @:)
333
334 " Expanding a special keycode
335 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
336 call assert_equal('"set <Home>', @:)
337
338 " Expanding an invalid special keycode
339 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
340 call assert_equal("\"set <abcd>\<Tab>", @:)
341
342 " Expanding a terminal keycode
343 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
344 call assert_equal("\"set t_AB", @:)
345
346 " Expanding an invalid option name
347 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
348 call assert_equal("\"set abcde=\<Tab>", @:)
349
350 " Expanding after a = for a boolean option
351 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
352 call assert_equal("\"set wrapscan=\<Tab>", @:)
353
354 " Expanding a numeric option
355 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
356 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
357
358 " Expanding a non-boolean option
359 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
360 call assert_equal("\"set invtabstop=", @:)
361
362 " Expand options for 'spellsuggest'
363 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
364 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
365
366 " Expand value for 'key'
367 set key=abcd
368 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
369 call assert_equal('"set key=*****', @:)
370 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100371
372 " Expand values for 'filetype'
373 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
374 call assert_equal('"set filetype=sshdconfig', @:)
375 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
376 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100377endfunc
378
379func Test_set_errors()
380 call assert_fails('set scroll=-1', 'E49:')
381 call assert_fails('set backupcopy=', 'E474:')
382 call assert_fails('set regexpengine=3', 'E474:')
383 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200384 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100385 call assert_fails('set colorcolumn=-a', 'E474:')
386 call assert_fails('set colorcolumn=a', 'E474:')
387 call assert_fails('set colorcolumn=1,', 'E474:')
388 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100389 call assert_fails('set cmdheight=-1', 'E487:')
390 call assert_fails('set cmdwinheight=-1', 'E487:')
391 if has('conceal')
392 call assert_fails('set conceallevel=-1', 'E487:')
393 call assert_fails('set conceallevel=4', 'E474:')
394 endif
395 call assert_fails('set helpheight=-1', 'E487:')
396 call assert_fails('set history=-1', 'E487:')
397 call assert_fails('set report=-1', 'E487:')
398 call assert_fails('set shiftwidth=-1', 'E487:')
399 call assert_fails('set sidescroll=-1', 'E487:')
400 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000401 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000402 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000403 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100404 call assert_fails('set textwidth=-1', 'E487:')
405 call assert_fails('set timeoutlen=-1', 'E487:')
406 call assert_fails('set updatecount=-1', 'E487:')
407 call assert_fails('set updatetime=-1', 'E487:')
408 call assert_fails('set winheight=-1', 'E487:')
409 call assert_fails('set tabstop!', 'E488:')
410 call assert_fails('set xxx', 'E518:')
411 call assert_fails('set beautify?', 'E519:')
412 call assert_fails('set undolevels=x', 'E521:')
413 call assert_fails('set tabstop=', 'E521:')
414 call assert_fails('set comments=-', 'E524:')
415 call assert_fails('set comments=a', 'E525:')
416 call assert_fails('set foldmarker=x', 'E536:')
417 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000418 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100419 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100420 call assert_fails('set rulerformat=%-', 'E539:')
421 call assert_fails('set rulerformat=%(', 'E542:')
422 call assert_fails('set rulerformat=%15(%%', 'E542:')
423 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100424 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100425 call assert_fails('set statusline=%{%', 'E540:')
426 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100427 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100428 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100429 call assert_fails('set tabline=%$', 'E539:')
430 call assert_fails('set tabline=%{', 'E540:')
431 call assert_fails('set tabline=%{%', 'E540:')
432 call assert_fails('set tabline=%{%}', 'E539:')
433 call assert_fails('set tabline=%(', 'E542:')
434 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100435
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100436 if has('cursorshape')
437 " This invalid value for 'guicursor' used to cause Vim to crash.
438 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
439 call assert_fails('set guicursor=i-ci', 'E545:')
440 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100441 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100442 call assert_fails('set guicursor=r-cr:horx', 'E548:')
443 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
444 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100445 if has('mouseshape')
446 call assert_fails('se mouseshape=i-r:x', 'E547:')
447 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000448
449 " Test for 'backupext' and 'patchmode' set to the same value
450 set backupext=.bak
451 set patchmode=.patch
452 call assert_fails('set patchmode=.bak', 'E589:')
453 call assert_equal('.patch', &patchmode)
454 call assert_fails('set backupext=.patch', 'E589:')
455 call assert_equal('.bak', &backupext)
456 set backupext& patchmode&
457
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100458 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200459 set winminheight& winheight&
460 set winheight=10 winminheight=10
461 call assert_fails('set winheight=9', 'E591:')
462 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100463 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200464 set winminwidth& winwidth&
465 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
466 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100467 call assert_fails("set showbreak=\x01", 'E595:')
468 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200469 call assert_fails('set tabstop??', 'E488:')
470 call assert_fails('set wrapscan!!', 'E488:')
471 call assert_fails('set tabstop&&', 'E488:')
472 call assert_fails('set wrapscan<<', 'E488:')
473 call assert_fails('set wrapscan=1', 'E474:')
474 call assert_fails('set autoindent@', 'E488:')
475 call assert_fails('set wildchar=<abc>', 'E474:')
476 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200477 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100478 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200479 call assert_fails('set pyxversion=6', 'E474:')
480 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200481 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar531be472020-09-23 22:38:05 +0200482 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100483 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
484 call assert_fails('set foldmarker={{{,', 'E474:')
485 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100486 setlocal listchars=trail
487 call assert_fails('set ambiwidth=double', 'E834:')
488 setlocal listchars=trail:-
489 setglobal listchars=trail
490 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100491 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100492 setlocal fillchars=stl
493 call assert_fails('set ambiwidth=double', 'E835:')
494 setlocal fillchars=stl:-
495 setglobal fillchars=stl
496 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100497 set fillchars&
498 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
499 set nomodifiable
500 call assert_fails('set fileencoding=latin1', 'E21:')
501 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200502 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000503 call assert_fails('let &formatoptions = "?"', 'E539:')
504 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100505endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100506
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000507func Test_set_encoding()
508 let save_encoding = &encoding
509
510 set enc=iso8859-1
511 call assert_equal('latin1', &enc)
512 set enc=iso8859_1
513 call assert_equal('latin1', &enc)
514 set enc=iso-8859-1
515 call assert_equal('latin1', &enc)
516 set enc=iso_8859_1
517 call assert_equal('latin1', &enc)
518 set enc=iso88591
519 call assert_equal('latin1', &enc)
520 set enc=iso8859
521 call assert_equal('latin1', &enc)
522 set enc=iso-8859
523 call assert_equal('latin1', &enc)
524 set enc=iso_8859
525 call assert_equal('latin1', &enc)
526 call assert_fails('set enc=iso8858', 'E474:')
527 call assert_equal('latin1', &enc)
528
529 let &encoding = save_encoding
530endfunc
531
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200532func CheckWasSet(name)
533 let verb_cm = execute('verbose set ' .. a:name .. '?')
534 call assert_match('Last set from.*test_options.vim', verb_cm)
535endfunc
536func CheckWasNotSet(name)
537 let verb_cm = execute('verbose set ' .. a:name .. '?')
538 call assert_notmatch('Last set from', verb_cm)
539endfunc
540
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200541" Must be executed before other tests that set 'term'.
542func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200543 CheckNotGui
544
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200545 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200546
547 let term_save = &term
548 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200549 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200550 let &term = term_save
551endfunc
552
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200553func Test_copy_context()
554 setlocal list
555 call CheckWasSet('list')
556 split
557 call CheckWasSet('list')
558 quit
559 setlocal nolist
560
561 set ai
562 call CheckWasSet('ai')
563 set filetype=perl
564 call CheckWasSet('filetype')
565 set fo=tcroq
566 call CheckWasSet('fo')
567
568 split Xsomebuf
569 call CheckWasSet('ai')
570 call CheckWasNotSet('filetype')
571 call CheckWasSet('fo')
572endfunc
573
Bram Moolenaar67391142017-02-19 21:07:04 +0100574func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200575 CheckUnix
576 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200577
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200578 " Setting 'ttytype' used to cause a double-free when exiting vim and
579 " when vim is compiled with -DEXITFREE.
580 set ttytype=ansi
581 call assert_equal('ansi', &ttytype)
582 call assert_equal(&ttytype, &term)
583 set ttytype=xterm
584 call assert_equal('xterm', &ttytype)
585 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200586 try
587 set ttytype=
588 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100589 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200590 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200591
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200592 " Some systems accept any terminal name and return dumb settings,
593 " check for failure of finding the entry and for missing 'cm' entry.
594 try
595 set ttytype=xxx
596 call assert_report('set ttytype=xxx did not fail')
597 catch /E522\|E437/
598 endtry
599
600 set ttytype&
601 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200602
603 if has('gui') && !has('gui_running')
604 call assert_fails('set term=gui', 'E531:')
605 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100606endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100607
608func Test_set_all()
609 set tw=75
610 set iskeyword=a-z,A-Z
611 set nosplitbelow
612 let out = execute('set all')
613 call assert_match('textwidth=75', out)
614 call assert_match('iskeyword=a-z,A-Z', out)
615 call assert_match('nosplitbelow', out)
616 set tw& iskeyword& splitbelow&
617endfunc
618
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100619func Test_set_one_column()
620 let out_mult = execute('set all')->split("\n")
621 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100622 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100623endfunc
624
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100625func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200626 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100627 if filereadable('opt_test.vim')
628 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100629 else
630 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100631 endif
632endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200633
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100634func Test_renderoptions()
635 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
636 " Doesn't hurt to do this on a non-Windows system.
637 if windowsversion() !~ '^[345]\.'
638 set renderoptions=type:directx
639 set rop=type:directx
640 endif
641endfunc
642
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200643func ResetIndentexpr()
644 set indentexpr=
645endfunc
646
647func Test_set_indentexpr()
648 " this was causing usage of freed memory
649 set indentexpr=ResetIndentexpr()
650 new
651 call feedkeys("i\<c-f>", 'x')
652 call assert_equal('', &indentexpr)
653 bwipe!
654endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200655
656func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100657 " Option 'backupskip' may contain several comma-separated path
658 " specifications if one or more of the environment variables TMPDIR, TMP,
659 " or TEMP is defined. To simplify testing, convert the string value into a
660 " list.
661 let bsklist = split(&bsk, ',')
662
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200663 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100664 let found = (index(bsklist, '/private/tmp/*') >= 0)
665 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200666 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100667 let found = (index(bsklist, '/tmp/*') >= 0)
668 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200669 endif
670
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100671 " If our test platform is Windows, the path(s) in option bsk will use
672 " backslash for the path separator and the components could be in short
673 " (8.3) format. As such, we need to replace the backslashes with forward
674 " slashes and convert the path components to long format. The expand()
675 " function will do this but it cannot handle comma-separated paths. This is
676 " why bsk was converted from a string into a list of strings above.
677 "
678 " One final complication is that the wildcard "/*" is at the end of each
679 " path and so expand() might return a list of matching files. To prevent
680 " this, we need to remove the wildcard before calling expand() and then
681 " append it afterwards.
682 if has('win32')
683 let item_nbr = 0
684 while item_nbr < len(bsklist)
685 let path_spec = bsklist[item_nbr]
686 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
687 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
688 let bsklist[item_nbr] = path_spec . '/*'
689 let item_nbr += 1
690 endwhile
691 endif
692
693 " Option bsk will also include these environment variables if defined.
694 " If they're defined, verify they appear in the option value.
695 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200696 if exists(var)
697 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100698 let varvalue = substitute(varvalue, '/$', '', '')
699 let varvalue .= '/*'
700 let found = (index(bsklist, varvalue) >= 0)
701 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200702 endif
703 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200704
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200705 " Duplicates from environment variables should be filtered out (option has
706 " P_NODUP). Run this in a separate instance and write v:errors in a file,
707 " so that we see what happens on startup.
708 let after =<< trim [CODE]
709 let bsklist = split(&backupskip, ',')
710 call assert_equal(uniq(copy(bsklist)), bsklist)
711 call writefile(['errors:'] + v:errors, 'Xtestout')
712 qall
713 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100714 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200715 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
716
717 let saveenv = {}
718 for var in ['TMPDIR', 'TMP', 'TEMP']
719 let saveenv[var] = getenv(var)
720 call setenv(var, '/duplicate/path')
721 endfor
722
723 exe 'silent !' . cmd
724 call assert_equal(['errors:'], readfile('Xtestout'))
725
726 " restore environment variables
727 for var in ['TMPDIR', 'TMP', 'TEMP']
728 call setenv(var, saveenv[var])
729 endfor
730
731 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200732
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200733 " Duplicates should be filtered out (option has P_NODUP)
734 let backupskip = &backupskip
735 set backupskip=
736 set backupskip+=/test/dir
737 set backupskip+=/other/dir
738 set backupskip+=/test/dir
739 call assert_equal('/test/dir,/other/dir', &backupskip)
740 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200741endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200742
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100743func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200744 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200745
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200746 " Test copy option from current buffer in window
747 split
748 enew
749 setlocal numberwidth=5
750 wincmd w
751 call assert_equal(4,&numberwidth)
752 bnext
753 call assert_equal(5,&numberwidth)
754 bw!
755 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200756
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200757 " Test copy value from window that used to be display the buffer
758 split
759 enew
760 setlocal numberwidth=6
761 bnext
762 wincmd w
763 call assert_equal(4,&numberwidth)
764 bnext
765 call assert_equal(6,&numberwidth)
766 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200767
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200768 " Test that if buffer is current, don't use the stale cached value
769 " from the last time the buffer was displayed.
770 split
771 enew
772 setlocal numberwidth=7
773 bnext
774 bnext
775 setlocal numberwidth=8
776 wincmd w
777 call assert_equal(4,&numberwidth)
778 bnext
779 call assert_equal(8,&numberwidth)
780 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200781
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200782 " Test value is not copied if window already has seen the buffer
783 enew
784 split
785 setlocal numberwidth=9
786 bnext
787 setlocal numberwidth=10
788 wincmd w
789 call assert_equal(4,&numberwidth)
790 bnext
791 call assert_equal(4,&numberwidth)
792 bw!
793
794 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200795endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200796
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100797def Test_split_copy_options()
798 var values = [
799 ['cursorbind', true, false],
800 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
801 ['list', true, 0],
802 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
803 ['number', true, 0],
804 ['relativenumber', true, false],
805 ['scrollbind', true, false],
806 ['smoothscroll', true, false],
807 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
808 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
809 ['wrap', false, true],
810 ]
811 if has('linebreak')
812 values += [
813 ['breakindent', true, false],
814 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
815 ['linebreak', true, false],
816 ['numberwidth', 7, 4],
817 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
818 ]
819 endif
820 if has('rightleft')
821 values += [
822 ['rightleft', true, false],
823 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
824 ]
825 endif
826 if has('statusline')
827 values += [
828 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
829 ]
830 endif
831 if has('spell')
832 values += [
833 ['spell', true, false],
834 ]
835 endif
836 if has('syntax')
837 values += [
838 ['cursorcolumn', true, false],
839 ['cursorline', true, false],
840 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
841 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
842 ]
843 endif
844 if has('diff')
845 values += [
846 ['diff', true, false],
847 ]
848 endif
849 if has('conceal')
850 values += [
851 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
852 ['conceallevel', '3', &conceallevel],
853 ]
854 endif
855 if has('terminal')
856 values += [
857 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
858 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
859 ]
860 endif
861 if has('folding')
862 values += [
863 ['foldcolumn', 5, &foldcolumn],
864 ['foldenable', false, true],
865 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
866 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
867 ['foldlevel', 4, &foldlevel],
868 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
869 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
870 ['foldminlines', 3, &foldminlines],
871 ['foldnestmax', 17, &foldnestmax],
872 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
873 ]
874 endif
875 if has('signs')
876 values += [
877 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
878 ]
879 endif
880
881 # set options to non-default value
882 for item in values
883 exe $'&l:{item[0]} = {item[1]}'
884 endfor
885
886 # check values are set in new window
887 split
888 for item in values
889 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
890 endfor
891
892 # restore
893 close
894 for item in values
895 exe $'&l:{item[0]} = {item[2]}'
896 endfor
897enddef
898
Bram Moolenaarfc089602018-06-24 16:53:35 +0200899func Test_shortmess_F()
900 new
901 call assert_match('\[No Name\]', execute('file'))
902 set shortmess+=F
903 call assert_match('\[No Name\]', execute('file'))
904 call assert_match('^\s*$', execute('file foo'))
905 call assert_match('foo', execute('file'))
906 set shortmess-=F
907 call assert_match('bar', execute('file bar'))
908 call assert_match('bar', execute('file'))
909 set shortmess&
910 bwipe
911endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200912
913func Test_shortmess_F2()
914 e file1
915 e file2
916 call assert_match('file1', execute('bn', ''))
917 call assert_match('file2', execute('bn', ''))
918 set shortmess+=F
919 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200920 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200921 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200922 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200923 set hidden
924 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200925 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200926 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200927 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200928 set nohidden
929 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200930 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200931 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200932 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200933 set shortmess&
934 call assert_match('file1', execute('bn', ''))
935 call assert_match('file2', execute('bn', ''))
936 bwipe
937 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +0100938 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200939endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100940
941func Test_local_scrolloff()
942 set so=5
943 set siso=7
944 split
945 call assert_equal(5, &so)
946 setlocal so=3
947 call assert_equal(3, &so)
948 wincmd w
949 call assert_equal(5, &so)
950 wincmd w
951 setlocal so<
952 call assert_equal(5, &so)
953 setlocal so=0
954 call assert_equal(0, &so)
955 setlocal so=-1
956 call assert_equal(5, &so)
957
958 call assert_equal(7, &siso)
959 setlocal siso=3
960 call assert_equal(3, &siso)
961 wincmd w
962 call assert_equal(7, &siso)
963 wincmd w
964 setlocal siso<
965 call assert_equal(7, &siso)
966 setlocal siso=0
967 call assert_equal(0, &siso)
968 setlocal siso=-1
969 call assert_equal(7, &siso)
970
971 close
972 set so&
973 set siso&
974endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200975
976func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100977 CheckFunction reltimefloat
978
Bram Moolenaar449ac472019-04-03 21:42:35 +0200979 new
980 call setline(1, 'empty')
981 redraw
982 set writedelay=10
983 let start = reltime()
984 call setline(1, repeat('x', 70))
985 redraw
986 let elapsed = reltimefloat(reltime(start))
987 set writedelay=0
988 " With 'writedelay' set should take at least 30 * 10 msec
989 call assert_inrange(30 * 0.01, 999.0, elapsed)
990
991 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200992endfunc
993
994func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200995 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200996 set visualbell
997 call assert_beeps('normal 0h')
998 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200999 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001000endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001001
1002" Test for the 'write' option
1003func Test_write()
1004 new
1005 call setline(1, ['L1'])
1006 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001007 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001008 set write
1009 close!
1010endfunc
1011
1012" Test for 'buftype' option
1013func Test_buftype()
1014 new
1015 call setline(1, ['L1'])
1016 set buftype=nowrite
1017 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001018
1019 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1020 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001021 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001022 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1023 endfor
1024
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001025 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001026endfunc
1027
Bram Moolenaar578fe942020-02-27 21:32:51 +01001028" Test for the 'rightleftcmd' option
1029func Test_rightleftcmd()
1030 CheckFeature rightleft
1031 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001032
1033 let g:l = []
1034 func AddPos()
1035 call add(g:l, screencol())
1036 return ''
1037 endfunc
1038 cmap <expr> <F2> AddPos()
1039
zeertzjqbb404f52022-07-23 06:25:29 +01001040 set rightleftcmd=
1041 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1042 \ "\<Right>\<F2>\<Esc>", 'xt')
1043 call assert_equal([2, 5, 3, 4], g:l)
1044
1045 let g:l = []
1046 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001047 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1048 \ "\<Left>\<F2>\<Esc>", 'xt')
1049 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1050
1051 cunmap <F2>
1052 unlet g:l
1053 set rightleftcmd&
1054 set rightleft&
1055endfunc
1056
zeertzjq28c162f2022-08-14 14:49:50 +01001057" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001058func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001059 " redraw to avoid matching previous messages
1060 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001061 set debug=beep
1062 exe "normal \<C-c>"
1063 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001064 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001065 " also check a line above, with a certain window width the colon is there
1066 call assert_match('Test_debug_option:$',
1067 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001068 set debug&
1069endfunc
1070
Bram Moolenaar004a6782020-04-11 17:09:31 +02001071" Test for the default CDPATH option
1072func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001073 let after =<< trim [CODE]
1074 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1075 call writefile(v:errors, 'Xtestout')
1076 qall
1077 [CODE]
1078 if has('unix')
1079 let $CDPATH='/path/to/dir1:/path/to/dir2'
1080 else
1081 let $CDPATH='/path/to/dir1;/path/to/dir2'
1082 endif
1083 if RunVim([], after, '')
1084 call assert_equal([], readfile('Xtestout'))
1085 call delete('Xtestout')
1086 endif
1087endfunc
1088
1089" Test for setting keycodes using set
1090func Test_opt_set_keycode()
1091 call assert_fails('set <t_k1=l', 'E474:')
1092 call assert_fails('set <Home=l', 'E474:')
1093 set <t_k9>=abcd
1094 call assert_equal('abcd', &t_k9)
1095 set <t_k9>&
1096 set <F9>=xyz
1097 call assert_equal('xyz', &t_k9)
1098 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001099
1100 " should we test all of them?
1101 set t_Ce=testCe
1102 set t_Cs=testCs
1103 set t_Us=testUs
1104 set t_ds=testds
1105 set t_Ds=testDs
1106 call assert_equal('testCe', &t_Ce)
1107 call assert_equal('testCs', &t_Cs)
1108 call assert_equal('testUs', &t_Us)
1109 call assert_equal('testds', &t_ds)
1110 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001111endfunc
1112
1113" Test for changing options in a sandbox
1114func Test_opt_sandbox()
1115 for opt in ['backupdir', 'cdpath', 'exrc']
1116 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001117 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001118 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001119 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001120endfunc
1121
1122" Test for setting an option with local value to global value
1123func Test_opt_local_to_global()
1124 setglobal equalprg=gprg
1125 setlocal equalprg=lprg
1126 call assert_equal('gprg', &g:equalprg)
1127 call assert_equal('lprg', &l:equalprg)
1128 call assert_equal('lprg', &equalprg)
1129 set equalprg<
1130 call assert_equal('', &l:equalprg)
1131 call assert_equal('gprg', &equalprg)
1132 setglobal equalprg=gnewprg
1133 setlocal equalprg=lnewprg
1134 setlocal equalprg<
1135 call assert_equal('gnewprg', &l:equalprg)
1136 call assert_equal('gnewprg', &equalprg)
1137 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001138
1139 " Test for setting the global/local value of a boolean option
1140 setglobal autoread
1141 setlocal noautoread
1142 call assert_false(&autoread)
1143 set autoread<
1144 call assert_true(&autoread)
1145 setglobal noautoread
1146 setlocal autoread
1147 setlocal autoread<
1148 call assert_false(&autoread)
1149 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001150endfunc
1151
Dominique Pelle042414f2021-07-12 21:43:19 +02001152func Test_set_in_sandbox()
1153 " Some boolean options cannot be set in sandbox, some can.
1154 call assert_fails('sandbox set modelineexpr', 'E48:')
1155 sandbox set number
1156 call assert_true(&number)
1157 set number&
1158
1159 " Some boolean options cannot be set in sandbox, some can.
1160 if has('python') || has('python3')
1161 call assert_fails('sandbox set pyxversion=3', 'E48:')
1162 endif
1163 sandbox set tabstop=4
1164 call assert_equal(4, &tabstop)
1165 set tabstop&
1166
1167 " Some string options cannot be set in sandbox, some can.
1168 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1169 sandbox set filetype=perl
1170 call assert_equal('perl', &filetype)
1171 set filetype&
1172endfunc
1173
Bram Moolenaar004a6782020-04-11 17:09:31 +02001174" Test for incrementing, decrementing and multiplying a number option value
1175func Test_opt_num_op()
1176 set shiftwidth=4
1177 set sw+=2
1178 call assert_equal(6, &sw)
1179 set sw-=2
1180 call assert_equal(4, &sw)
1181 set sw^=2
1182 call assert_equal(8, &sw)
1183 set shiftwidth&
1184endfunc
1185
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001186" Test for setting option values using v:false and v:true
1187func Test_opt_boolean()
1188 set number&
1189 set number
1190 call assert_equal(1, &nu)
1191 set nonu
1192 call assert_equal(0, &nu)
1193 let &nu = v:true
1194 call assert_equal(1, &nu)
1195 let &nu = v:false
1196 call assert_equal(0, &nu)
1197 set number&
1198endfunc
1199
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001200" Test for the 'window' option
1201func Test_window_opt()
1202 " Needs only one open widow
1203 %bw!
1204 call setline(1, range(1, 8))
1205 set window=5
1206 exe "normal \<C-F>"
1207 call assert_equal(4, line('w0'))
1208 exe "normal \<C-F>"
1209 call assert_equal(7, line('w0'))
1210 exe "normal \<C-F>"
1211 call assert_equal(8, line('w0'))
1212 exe "normal \<C-B>"
1213 call assert_equal(5, line('w0'))
1214 exe "normal \<C-B>"
1215 call assert_equal(2, line('w0'))
1216 exe "normal \<C-B>"
1217 call assert_equal(1, line('w0'))
1218 set window=1
1219 exe "normal gg\<C-F>"
1220 call assert_equal(2, line('w0'))
1221 exe "normal \<C-F>"
1222 call assert_equal(3, line('w0'))
1223 exe "normal \<C-B>"
1224 call assert_equal(2, line('w0'))
1225 exe "normal \<C-B>"
1226 call assert_equal(1, line('w0'))
1227 enew!
1228 set window&
1229endfunc
1230
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001231" Test for the 'winminheight' option
1232func Test_opt_winminheight()
1233 only!
1234 let &winheight = &lines + 4
1235 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1236 call assert_true(&winminheight <= &lines)
1237 set winminheight&
1238 set winheight&
1239endfunc
1240
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001241func Test_opt_winminheight_term()
1242 CheckRunVimInTerminal
1243
1244 " The tabline should be taken into account.
1245 let lines =<< trim END
1246 set wmh=0 stal=2
1247 below sp | wincmd _
1248 below sp | wincmd _
1249 below sp | wincmd _
1250 below sp
1251 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001252 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001253 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1254 call term_sendkeys(buf, ":set wmh=1\n")
1255 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1256
1257 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001258endfunc
1259
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001260func Test_opt_winminheight_term_tabs()
1261 CheckRunVimInTerminal
1262
1263 " The tabline should be taken into account.
1264 let lines =<< trim END
1265 set wmh=0 stal=2
1266 split
1267 split
1268 split
1269 split
1270 tabnew
1271 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001272 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001273 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1274 call term_sendkeys(buf, ":set wmh=1\n")
1275 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1276
1277 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001278endfunc
1279
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001280" Test for the 'winminwidth' option
1281func Test_opt_winminwidth()
1282 only!
1283 let &winwidth = &columns + 4
1284 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1285 call assert_true(&winminwidth <= &columns)
1286 set winminwidth&
1287 set winwidth&
1288endfunc
1289
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001290" Test for setting option value containing spaces with isfname+=32
1291func Test_isfname_with_options()
1292 set isfname+=32
1293 setlocal keywordprg=:term\ help.exe
1294 call assert_equal(':term help.exe', &keywordprg)
1295 set isfname&
1296 setlocal keywordprg&
1297endfunc
1298
Bram Moolenaar74667062020-12-28 15:41:41 +01001299" Test that resetting laststatus does change scroll option
1300func Test_opt_reset_scroll()
1301 CheckRunVimInTerminal
1302 let vimrc =<< trim [CODE]
1303 set scroll=2
1304 set laststatus=2
1305 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001306 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001307 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1308 call term_sendkeys(buf, ":verbose set scroll?\n")
1309 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1310 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001311
1312 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001313 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001314endfunc
1315
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001316" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1317func Test_VIM_POSIX()
1318 let saved_VIM_POSIX = getenv("VIM_POSIX")
1319
1320 call setenv('VIM_POSIX', "1")
1321 let after =<< trim [CODE]
1322 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1323 qall
1324 [CODE]
1325 if RunVim([], after, '')
1326 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1327 \ 'AS'], readfile('X_VIM_POSIX'))
1328 endif
1329
1330 call setenv('VIM_POSIX', v:null)
1331 let after =<< trim [CODE]
1332 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1333 qall
1334 [CODE]
1335 if RunVim([], after, '')
1336 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1337 \ 'S'], readfile('X_VIM_POSIX'))
1338 endif
1339
1340 call delete('X_VIM_POSIX')
1341 call setenv('VIM_POSIX', saved_VIM_POSIX)
1342endfunc
1343
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001344" Test for setting an option to a Vi or Vim default
1345func Test_opt_default()
1346 set formatoptions&vi
1347 call assert_equal('vt', &formatoptions)
1348 set formatoptions&vim
1349 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001350
1351 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1352 set fencs=latin1
1353 set fencs&
1354 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1355 set fencs=latin1
1356 set all&
1357 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001358endfunc
1359
1360" Test for the 'cmdheight' option
1361func Test_cmdheight()
1362 %bw!
1363 let ht = &lines
1364 set cmdheight=9999
1365 call assert_equal(1, winheight(0))
1366 call assert_equal(ht - 1, &cmdheight)
1367 set cmdheight&
1368endfunc
1369
Dominique Pelle923dce22021-11-21 11:36:04 +00001370" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001371func Test_opt_control_char()
1372 set wildchar=^v
1373 call assert_equal("\<C-V>", nr2char(&wildchar))
1374 set wildcharm=^r
1375 call assert_equal("\<C-R>", nr2char(&wildcharm))
1376 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1377 set wildchar& wildcharm&
1378endfunc
1379
1380" Test for the 'errorbells' option
1381func Test_opt_errorbells()
1382 set errorbells
1383 call assert_beeps('s/a1b2/x1y2/')
1384 set noerrorbells
1385endfunc
1386
Dominique Pelle042414f2021-07-12 21:43:19 +02001387func Test_opt_scrolljump()
1388 help
1389 resize 10
1390
1391 " Test with positive 'scrolljump'.
1392 set scrolljump=2
1393 norm! Lj
1394 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1395 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1396 \ winsaveview())
1397
1398 " Test with negative 'scrolljump' (percentage of window height).
1399 set scrolljump=-40
1400 norm! ggLj
1401 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1402 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1403 \ winsaveview())
1404
1405 set scrolljump&
1406 bw
1407endfunc
1408
Bakudankun29f3a452021-12-11 12:28:08 +00001409" Test for the 'cdhome' option
1410func Test_opt_cdhome()
1411 if has('unix') || has('vms')
1412 throw 'Skipped: only works on non-Unix'
1413 endif
1414
1415 set cdhome&
1416 call assert_equal(0, &cdhome)
1417 set cdhome
1418
1419 " This paragraph is copied from Test_cd_no_arg().
1420 let path = getcwd()
1421 cd
1422 call assert_equal($HOME, getcwd())
1423 call assert_notequal(path, getcwd())
1424 exe 'cd ' .. fnameescape(path)
1425 call assert_equal(path, getcwd())
1426
1427 set cdhome&
1428endfunc
1429
Christian Brabandtcb747892022-05-08 21:10:56 +01001430func Test_set_completion_2()
1431 CheckOption termguicolors
1432
1433 " Test default option completion
1434 set wildoptions=
1435 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1436 call assert_equal('"set termguicolors', @:)
1437
1438 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1439 call assert_equal('"set notermguicolors', @:)
1440
1441 " Test fuzzy option completion
1442 set wildoptions=fuzzy
1443 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1444 call assert_equal('"set termguicolors termencoding', @:)
1445
1446 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1447 call assert_equal('"set notermguicolors', @:)
1448
1449 set wildoptions=
1450endfunc
1451
Sean Dewar39c46b42022-05-12 17:44:29 +01001452func Test_switchbuf_reset()
1453 set switchbuf=useopen
1454 sblast
1455 call assert_equal(1, winnr('$'))
1456 set all&
1457 call assert_equal('', &switchbuf)
1458 sblast
1459 call assert_equal(2, winnr('$'))
1460 only!
1461endfunc
1462
zeertzjqfcba86c2022-09-22 13:57:32 +01001463" :set empty string for global 'keywordprg' falls back to ":help"
1464func Test_keywordprg_empty()
1465 let k = &keywordprg
1466 set keywordprg=man
1467 call assert_equal('man', &keywordprg)
1468 set keywordprg=
1469 call assert_equal(':help', &keywordprg)
1470 set keywordprg=man
1471 call assert_equal('man', &keywordprg)
1472 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1473 let &keywordprg = k
1474endfunc
1475
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001476" check that the very first buffer created does not have 'endoffile' set
1477func Test_endoffile_default()
1478 let after =<< trim [CODE]
1479 call writefile([execute('set eof?')], 'Xtestout')
1480 qall!
1481 [CODE]
1482 if RunVim([], after, '')
1483 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1484 endif
1485 call delete('Xtestout')
1486endfunc
1487
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001488" Test for setting the 'lines' and 'columns' options to a minimum value
1489func Test_set_min_lines_columns()
1490 let save_lines = &lines
1491 let save_columns = &columns
1492
1493 let after =<< trim END
1494 set nomore
1495 let msg = []
1496 let v:errmsg = ''
1497 silent! let &columns=0
1498 call add(msg, v:errmsg)
1499 silent! set columns=0
1500 call add(msg, v:errmsg)
1501 silent! call setbufvar('', '&columns', 0)
1502 call add(msg, v:errmsg)
1503 "call writefile(msg, 'XResultsetminlines')
1504 silent! let &lines=0
1505 call add(msg, v:errmsg)
1506 silent! set lines=0
1507 call add(msg, v:errmsg)
1508 silent! call setbufvar('', '&lines', 0)
1509 call add(msg, v:errmsg)
1510 call writefile(msg, 'XResultsetminlines')
1511 qall!
1512 END
1513 if RunVim([], after, '')
1514 call assert_equal(['E594: Need at least 12 columns',
1515 \ 'E594: Need at least 12 columns: columns=0',
1516 \ 'E594: Need at least 12 columns',
1517 \ 'E593: Need at least 2 lines',
1518 \ 'E593: Need at least 2 lines: lines=0',
1519 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1520 endif
1521
1522 call delete('XResultsetminlines')
1523 let &lines = save_lines
1524 let &columns = save_columns
1525endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001526
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001527" Test for reverting a string option value if the new value is invalid.
1528func Test_string_option_revert_on_failure()
1529 new
1530 let optlist = [
1531 \ ['ambiwidth', 'double', 'a123'],
1532 \ ['background', 'dark', 'a123'],
1533 \ ['backspace', 'eol', 'a123'],
1534 \ ['backupcopy', 'no', 'a123'],
1535 \ ['belloff', 'showmatch', 'a123'],
1536 \ ['breakindentopt', 'min:10', 'list'],
1537 \ ['bufhidden', 'wipe', 'a123'],
1538 \ ['buftype', 'nowrite', 'a123'],
1539 \ ['casemap', 'keepascii', 'a123'],
1540 \ ['cedit', "\<C-Y>", 'z'],
1541 \ ['colorcolumn', '10', 'z'],
1542 \ ['commentstring', '#%s', 'a123'],
1543 \ ['complete', '.,t', 'a'],
1544 \ ['completefunc', 'MyCmplFunc', '1a-'],
1545 \ ['completeopt', 'popup', 'a123'],
1546 \ ['completepopup', 'width:20', 'border'],
1547 \ ['concealcursor', 'v', 'xyz'],
1548 \ ['cpoptions', 'HJ', '~'],
1549 \ ['cryptmethod', 'zip', 'a123'],
1550 \ ['cursorlineopt', 'screenline', 'a123'],
1551 \ ['debug', 'throw', 'a123'],
1552 \ ['diffopt', 'iwhite', 'a123'],
1553 \ ['display', 'uhex', 'a123'],
1554 \ ['eadirection', 'hor', 'a123'],
1555 \ ['encoding', 'utf-8', 'a123'],
1556 \ ['eventignore', 'TextYankPost', 'a123'],
1557 \ ['fileencoding', 'utf-8', 'a123,'],
1558 \ ['fileformat', 'mac', 'a123'],
1559 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001560 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001561 \ ['fillchars', 'diff:~', 'a123'],
1562 \ ['foldclose', 'all', 'a123'],
1563 \ ['foldmarker', '[[[,]]]', '[[['],
1564 \ ['foldmethod', 'marker', 'a123'],
1565 \ ['foldopen', 'percent', 'a123'],
1566 \ ['formatoptions', 'an', '*'],
1567 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1568 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001569 \ ['highlight', '!:CursorColumn', '8:'],
1570 \ ['keymodel', 'stopsel', 'a123'],
1571 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1572 \ ['lispoptions', 'expr:1', 'a123'],
1573 \ ['listchars', 'tab:->', 'tab:'],
1574 \ ['matchpairs', '<:>', '<:'],
1575 \ ['mkspellmem', '100000,1000,100', '100000'],
1576 \ ['mouse', 'nvi', 'z'],
1577 \ ['mousemodel', 'extend', 'a123'],
1578 \ ['nrformats', 'alpha', 'a123'],
1579 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1580 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1581 \ ['previewpopup', 'width:20', 'a123'],
1582 \ ['printoptions', 'paper:A4', 'a123:'],
1583 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1584 \ ['rulerformat', '%l', '%['],
1585 \ ['scrollopt', 'hor,jump', 'a123'],
1586 \ ['selection', 'exclusive', 'a123'],
1587 \ ['selectmode', 'cmd', 'a123'],
1588 \ ['sessionoptions', 'options', 'a123'],
1589 \ ['shortmess', 'w', '2'],
1590 \ ['showbreak', '>>', "\x01"],
1591 \ ['showcmdloc', 'statusline', 'a123'],
1592 \ ['signcolumn', 'no', 'a123'],
1593 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1594 \ ['spellfile', 'MySpell.en.add', "\x01"],
1595 \ ['spelllang', 'en', "#"],
1596 \ ['spelloptions', 'camel', 'a123'],
1597 \ ['spellsuggest', 'double', 'a123'],
1598 \ ['splitkeep', 'topline', 'a123'],
1599 \ ['statusline', '%f', '%['],
1600 \ ['swapsync', 'sync', 'a123'],
1601 \ ['switchbuf', 'usetab', 'a123'],
1602 \ ['syntax', 'abc', 'a^b'],
1603 \ ['tabline', '%f', '%['],
1604 \ ['tagcase', 'ignore', 'a123'],
1605 \ ['tagfunc', 'MyTagFunc', '1a-'],
1606 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1607 \ ['viewoptions', 'options', 'a123'],
1608 \ ['virtualedit', 'onemore', 'a123'],
1609 \ ['whichwrap', '<,>', '{,}'],
1610 \ ['wildmode', 'list', 'a123'],
1611 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001612 \ ]
1613 if has('gui')
1614 call add(optlist, ['browsedir', 'buffer', 'a123'])
1615 endif
1616 if has('clipboard_working')
1617 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1618 endif
1619 if has('win32')
1620 call add(optlist, ['completeslash', 'slash', 'a123'])
1621 endif
1622 if has('cscope')
1623 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1624 endif
1625 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001626 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1627 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1628 endif
1629 if has('keymap')
1630 call add(optlist, ['keymap', 'greek', '[]'])
1631 endif
1632 if has('mouseshape')
1633 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1634 endif
1635 if has('win32') && has('gui')
1636 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1637 endif
1638 if has('rightleft')
1639 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1640 endif
1641 if has('terminal')
1642 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1643 call add(optlist, ['termwinsize', '24x80', '100'])
1644 endif
1645 if has('win32') && has('terminal')
1646 call add(optlist, ['termwintype', 'winpty', 'a123'])
1647 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001648 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001649 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001650 endif
1651 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001652 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1653 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001654 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001655 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1656 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001657 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001658 call add(optlist, ['varsofttabstop', '12', 'a123'])
1659 call add(optlist, ['vartabstop', '4,20', '4,'])
1660 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001661 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001662 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001663 endif
1664 for opt in optlist
1665 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001666 try
1667 exe $"let &{opt[0]} = '{opt[1]}'"
1668 catch
1669 call assert_report($"Caught {v:exception} with {opt->string()}")
1670 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001671 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1672 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1673 exe $"let &{opt[0]} = save_opt"
1674 endfor
1675 bw!
1676endfunc
1677
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001678" vim: shiftwidth=2 sts=2 expandtab