blob: 5bacebc35e7f87ba6ad34c183912b6d08af058d1 [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
zeertzjq4c7cb372023-06-14 16:39:54 +0100379func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100380 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
zeertzjq4c7cb372023-06-14 16:39:54 +0100481 call assert_fails("let &tabstop='ab'", ['E521:', '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:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100505 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
506 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
507 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
508 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
509 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
510 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100511endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100512
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000513func Test_set_encoding()
514 let save_encoding = &encoding
515
516 set enc=iso8859-1
517 call assert_equal('latin1', &enc)
518 set enc=iso8859_1
519 call assert_equal('latin1', &enc)
520 set enc=iso-8859-1
521 call assert_equal('latin1', &enc)
522 set enc=iso_8859_1
523 call assert_equal('latin1', &enc)
524 set enc=iso88591
525 call assert_equal('latin1', &enc)
526 set enc=iso8859
527 call assert_equal('latin1', &enc)
528 set enc=iso-8859
529 call assert_equal('latin1', &enc)
530 set enc=iso_8859
531 call assert_equal('latin1', &enc)
532 call assert_fails('set enc=iso8858', 'E474:')
533 call assert_equal('latin1', &enc)
534
535 let &encoding = save_encoding
536endfunc
537
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200538func CheckWasSet(name)
539 let verb_cm = execute('verbose set ' .. a:name .. '?')
540 call assert_match('Last set from.*test_options.vim', verb_cm)
541endfunc
542func CheckWasNotSet(name)
543 let verb_cm = execute('verbose set ' .. a:name .. '?')
544 call assert_notmatch('Last set from', verb_cm)
545endfunc
546
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200547" Must be executed before other tests that set 'term'.
548func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200549 CheckNotGui
550
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200551 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200552
553 let term_save = &term
554 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200555 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200556 let &term = term_save
557endfunc
558
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200559func Test_copy_context()
560 setlocal list
561 call CheckWasSet('list')
562 split
563 call CheckWasSet('list')
564 quit
565 setlocal nolist
566
567 set ai
568 call CheckWasSet('ai')
569 set filetype=perl
570 call CheckWasSet('filetype')
571 set fo=tcroq
572 call CheckWasSet('fo')
573
574 split Xsomebuf
575 call CheckWasSet('ai')
576 call CheckWasNotSet('filetype')
577 call CheckWasSet('fo')
578endfunc
579
Bram Moolenaar67391142017-02-19 21:07:04 +0100580func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200581 CheckUnix
582 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200583
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200584 " Setting 'ttytype' used to cause a double-free when exiting vim and
585 " when vim is compiled with -DEXITFREE.
586 set ttytype=ansi
587 call assert_equal('ansi', &ttytype)
588 call assert_equal(&ttytype, &term)
589 set ttytype=xterm
590 call assert_equal('xterm', &ttytype)
591 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200592 try
593 set ttytype=
594 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100595 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200596 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200597
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200598 " Some systems accept any terminal name and return dumb settings,
599 " check for failure of finding the entry and for missing 'cm' entry.
600 try
601 set ttytype=xxx
602 call assert_report('set ttytype=xxx did not fail')
603 catch /E522\|E437/
604 endtry
605
606 set ttytype&
607 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200608
609 if has('gui') && !has('gui_running')
610 call assert_fails('set term=gui', 'E531:')
611 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100612endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100613
614func Test_set_all()
615 set tw=75
616 set iskeyword=a-z,A-Z
617 set nosplitbelow
618 let out = execute('set all')
619 call assert_match('textwidth=75', out)
620 call assert_match('iskeyword=a-z,A-Z', out)
621 call assert_match('nosplitbelow', out)
622 set tw& iskeyword& splitbelow&
623endfunc
624
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100625func Test_set_one_column()
626 let out_mult = execute('set all')->split("\n")
627 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100628 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100629endfunc
630
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100631func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200632 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100633 if filereadable('opt_test.vim')
634 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100635 else
636 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100637 endif
638endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200639
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100640func Test_renderoptions()
641 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
642 " Doesn't hurt to do this on a non-Windows system.
643 if windowsversion() !~ '^[345]\.'
644 set renderoptions=type:directx
645 set rop=type:directx
646 endif
647endfunc
648
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200649func ResetIndentexpr()
650 set indentexpr=
651endfunc
652
653func Test_set_indentexpr()
654 " this was causing usage of freed memory
655 set indentexpr=ResetIndentexpr()
656 new
657 call feedkeys("i\<c-f>", 'x')
658 call assert_equal('', &indentexpr)
659 bwipe!
660endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200661
662func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100663 " Option 'backupskip' may contain several comma-separated path
664 " specifications if one or more of the environment variables TMPDIR, TMP,
665 " or TEMP is defined. To simplify testing, convert the string value into a
666 " list.
667 let bsklist = split(&bsk, ',')
668
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200669 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100670 let found = (index(bsklist, '/private/tmp/*') >= 0)
671 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200672 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100673 let found = (index(bsklist, '/tmp/*') >= 0)
674 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200675 endif
676
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100677 " If our test platform is Windows, the path(s) in option bsk will use
678 " backslash for the path separator and the components could be in short
679 " (8.3) format. As such, we need to replace the backslashes with forward
680 " slashes and convert the path components to long format. The expand()
681 " function will do this but it cannot handle comma-separated paths. This is
682 " why bsk was converted from a string into a list of strings above.
683 "
684 " One final complication is that the wildcard "/*" is at the end of each
685 " path and so expand() might return a list of matching files. To prevent
686 " this, we need to remove the wildcard before calling expand() and then
687 " append it afterwards.
688 if has('win32')
689 let item_nbr = 0
690 while item_nbr < len(bsklist)
691 let path_spec = bsklist[item_nbr]
692 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
693 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
694 let bsklist[item_nbr] = path_spec . '/*'
695 let item_nbr += 1
696 endwhile
697 endif
698
699 " Option bsk will also include these environment variables if defined.
700 " If they're defined, verify they appear in the option value.
701 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200702 if exists(var)
703 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100704 let varvalue = substitute(varvalue, '/$', '', '')
705 let varvalue .= '/*'
706 let found = (index(bsklist, varvalue) >= 0)
707 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200708 endif
709 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200710
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200711 " Duplicates from environment variables should be filtered out (option has
712 " P_NODUP). Run this in a separate instance and write v:errors in a file,
713 " so that we see what happens on startup.
714 let after =<< trim [CODE]
715 let bsklist = split(&backupskip, ',')
716 call assert_equal(uniq(copy(bsklist)), bsklist)
717 call writefile(['errors:'] + v:errors, 'Xtestout')
718 qall
719 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100720 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200721 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
722
723 let saveenv = {}
724 for var in ['TMPDIR', 'TMP', 'TEMP']
725 let saveenv[var] = getenv(var)
726 call setenv(var, '/duplicate/path')
727 endfor
728
729 exe 'silent !' . cmd
730 call assert_equal(['errors:'], readfile('Xtestout'))
731
732 " restore environment variables
733 for var in ['TMPDIR', 'TMP', 'TEMP']
734 call setenv(var, saveenv[var])
735 endfor
736
737 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200738
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200739 " Duplicates should be filtered out (option has P_NODUP)
740 let backupskip = &backupskip
741 set backupskip=
742 set backupskip+=/test/dir
743 set backupskip+=/other/dir
744 set backupskip+=/test/dir
745 call assert_equal('/test/dir,/other/dir', &backupskip)
746 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200747endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200748
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100749func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200750 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200751
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200752 " Test copy option from current buffer in window
753 split
754 enew
755 setlocal numberwidth=5
756 wincmd w
757 call assert_equal(4,&numberwidth)
758 bnext
759 call assert_equal(5,&numberwidth)
760 bw!
761 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200762
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200763 " Test copy value from window that used to be display the buffer
764 split
765 enew
766 setlocal numberwidth=6
767 bnext
768 wincmd w
769 call assert_equal(4,&numberwidth)
770 bnext
771 call assert_equal(6,&numberwidth)
772 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200773
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200774 " Test that if buffer is current, don't use the stale cached value
775 " from the last time the buffer was displayed.
776 split
777 enew
778 setlocal numberwidth=7
779 bnext
780 bnext
781 setlocal numberwidth=8
782 wincmd w
783 call assert_equal(4,&numberwidth)
784 bnext
785 call assert_equal(8,&numberwidth)
786 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200787
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200788 " Test value is not copied if window already has seen the buffer
789 enew
790 split
791 setlocal numberwidth=9
792 bnext
793 setlocal numberwidth=10
794 wincmd w
795 call assert_equal(4,&numberwidth)
796 bnext
797 call assert_equal(4,&numberwidth)
798 bw!
799
800 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200801endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200802
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100803def Test_split_copy_options()
804 var values = [
805 ['cursorbind', true, false],
806 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
807 ['list', true, 0],
808 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
809 ['number', true, 0],
810 ['relativenumber', true, false],
811 ['scrollbind', true, false],
812 ['smoothscroll', true, false],
813 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
814 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
815 ['wrap', false, true],
816 ]
817 if has('linebreak')
818 values += [
819 ['breakindent', true, false],
820 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
821 ['linebreak', true, false],
822 ['numberwidth', 7, 4],
823 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
824 ]
825 endif
826 if has('rightleft')
827 values += [
828 ['rightleft', true, false],
829 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
830 ]
831 endif
832 if has('statusline')
833 values += [
834 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
835 ]
836 endif
837 if has('spell')
838 values += [
839 ['spell', true, false],
840 ]
841 endif
842 if has('syntax')
843 values += [
844 ['cursorcolumn', true, false],
845 ['cursorline', true, false],
846 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
847 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
848 ]
849 endif
850 if has('diff')
851 values += [
852 ['diff', true, false],
853 ]
854 endif
855 if has('conceal')
856 values += [
857 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
858 ['conceallevel', '3', &conceallevel],
859 ]
860 endif
861 if has('terminal')
862 values += [
863 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
864 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
865 ]
866 endif
867 if has('folding')
868 values += [
869 ['foldcolumn', 5, &foldcolumn],
870 ['foldenable', false, true],
871 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
872 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
873 ['foldlevel', 4, &foldlevel],
874 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
875 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
876 ['foldminlines', 3, &foldminlines],
877 ['foldnestmax', 17, &foldnestmax],
878 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
879 ]
880 endif
881 if has('signs')
882 values += [
883 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
884 ]
885 endif
886
887 # set options to non-default value
888 for item in values
889 exe $'&l:{item[0]} = {item[1]}'
890 endfor
891
892 # check values are set in new window
893 split
894 for item in values
895 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
896 endfor
897
898 # restore
899 close
900 for item in values
901 exe $'&l:{item[0]} = {item[2]}'
902 endfor
903enddef
904
Bram Moolenaarfc089602018-06-24 16:53:35 +0200905func Test_shortmess_F()
906 new
907 call assert_match('\[No Name\]', execute('file'))
908 set shortmess+=F
909 call assert_match('\[No Name\]', execute('file'))
910 call assert_match('^\s*$', execute('file foo'))
911 call assert_match('foo', execute('file'))
912 set shortmess-=F
913 call assert_match('bar', execute('file bar'))
914 call assert_match('bar', execute('file'))
915 set shortmess&
916 bwipe
917endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200918
919func Test_shortmess_F2()
920 e file1
921 e file2
922 call assert_match('file1', execute('bn', ''))
923 call assert_match('file2', execute('bn', ''))
924 set shortmess+=F
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 Moolenaarce90e362019-09-08 18:58:44 +0200928 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200929 set hidden
930 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200931 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200932 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200933 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200934 set nohidden
935 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200936 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200937 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200938 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200939 set shortmess&
940 call assert_match('file1', execute('bn', ''))
941 call assert_match('file2', execute('bn', ''))
942 bwipe
943 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +0100944 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200945endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100946
947func Test_local_scrolloff()
948 set so=5
949 set siso=7
950 split
951 call assert_equal(5, &so)
952 setlocal so=3
953 call assert_equal(3, &so)
954 wincmd w
955 call assert_equal(5, &so)
956 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100957 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100958 setlocal so<
959 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100960 setglob so=8
961 call assert_equal(8, &so)
962 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100963 setlocal so=0
964 call assert_equal(0, &so)
965 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100966 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100967
968 call assert_equal(7, &siso)
969 setlocal siso=3
970 call assert_equal(3, &siso)
971 wincmd w
972 call assert_equal(7, &siso)
973 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100974 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100975 setlocal siso<
976 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100977 setglob siso=4
978 call assert_equal(4, &siso)
979 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100980 setlocal siso=0
981 call assert_equal(0, &siso)
982 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100983 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100984
985 close
986 set so&
987 set siso&
988endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200989
990func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100991 CheckFunction reltimefloat
992
Bram Moolenaar449ac472019-04-03 21:42:35 +0200993 new
994 call setline(1, 'empty')
995 redraw
996 set writedelay=10
997 let start = reltime()
998 call setline(1, repeat('x', 70))
999 redraw
1000 let elapsed = reltimefloat(reltime(start))
1001 set writedelay=0
1002 " With 'writedelay' set should take at least 30 * 10 msec
1003 call assert_inrange(30 * 0.01, 999.0, elapsed)
1004
1005 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001006endfunc
1007
1008func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001009 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001010 set visualbell
1011 call assert_beeps('normal 0h')
1012 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001013 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001014endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001015
1016" Test for the 'write' option
1017func Test_write()
1018 new
1019 call setline(1, ['L1'])
1020 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001021 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001022 set write
1023 close!
1024endfunc
1025
1026" Test for 'buftype' option
1027func Test_buftype()
1028 new
1029 call setline(1, ['L1'])
1030 set buftype=nowrite
1031 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001032
1033 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1034 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001035 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001036 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1037 endfor
1038
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001039 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001040endfunc
1041
Bram Moolenaar578fe942020-02-27 21:32:51 +01001042" Test for the 'rightleftcmd' option
1043func Test_rightleftcmd()
1044 CheckFeature rightleft
1045 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001046
1047 let g:l = []
1048 func AddPos()
1049 call add(g:l, screencol())
1050 return ''
1051 endfunc
1052 cmap <expr> <F2> AddPos()
1053
zeertzjqbb404f52022-07-23 06:25:29 +01001054 set rightleftcmd=
1055 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1056 \ "\<Right>\<F2>\<Esc>", 'xt')
1057 call assert_equal([2, 5, 3, 4], g:l)
1058
1059 let g:l = []
1060 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001061 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1062 \ "\<Left>\<F2>\<Esc>", 'xt')
1063 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1064
1065 cunmap <F2>
1066 unlet g:l
1067 set rightleftcmd&
1068 set rightleft&
1069endfunc
1070
zeertzjq28c162f2022-08-14 14:49:50 +01001071" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001072func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001073 " redraw to avoid matching previous messages
1074 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001075 set debug=beep
1076 exe "normal \<C-c>"
1077 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001078 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001079 " also check a line above, with a certain window width the colon is there
1080 call assert_match('Test_debug_option:$',
1081 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001082 set debug&
1083endfunc
1084
Bram Moolenaar004a6782020-04-11 17:09:31 +02001085" Test for the default CDPATH option
1086func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001087 let after =<< trim [CODE]
1088 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1089 call writefile(v:errors, 'Xtestout')
1090 qall
1091 [CODE]
1092 if has('unix')
1093 let $CDPATH='/path/to/dir1:/path/to/dir2'
1094 else
1095 let $CDPATH='/path/to/dir1;/path/to/dir2'
1096 endif
1097 if RunVim([], after, '')
1098 call assert_equal([], readfile('Xtestout'))
1099 call delete('Xtestout')
1100 endif
1101endfunc
1102
1103" Test for setting keycodes using set
1104func Test_opt_set_keycode()
1105 call assert_fails('set <t_k1=l', 'E474:')
1106 call assert_fails('set <Home=l', 'E474:')
1107 set <t_k9>=abcd
1108 call assert_equal('abcd', &t_k9)
1109 set <t_k9>&
1110 set <F9>=xyz
1111 call assert_equal('xyz', &t_k9)
1112 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001113
1114 " should we test all of them?
1115 set t_Ce=testCe
1116 set t_Cs=testCs
1117 set t_Us=testUs
1118 set t_ds=testds
1119 set t_Ds=testDs
1120 call assert_equal('testCe', &t_Ce)
1121 call assert_equal('testCs', &t_Cs)
1122 call assert_equal('testUs', &t_Us)
1123 call assert_equal('testds', &t_ds)
1124 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001125endfunc
1126
1127" Test for changing options in a sandbox
1128func Test_opt_sandbox()
1129 for opt in ['backupdir', 'cdpath', 'exrc']
1130 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001131 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001132 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001133 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001134endfunc
1135
1136" Test for setting an option with local value to global value
1137func Test_opt_local_to_global()
1138 setglobal equalprg=gprg
1139 setlocal equalprg=lprg
1140 call assert_equal('gprg', &g:equalprg)
1141 call assert_equal('lprg', &l:equalprg)
1142 call assert_equal('lprg', &equalprg)
1143 set equalprg<
1144 call assert_equal('', &l:equalprg)
1145 call assert_equal('gprg', &equalprg)
1146 setglobal equalprg=gnewprg
1147 setlocal equalprg=lnewprg
1148 setlocal equalprg<
1149 call assert_equal('gnewprg', &l:equalprg)
1150 call assert_equal('gnewprg', &equalprg)
1151 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001152
1153 " Test for setting the global/local value of a boolean option
1154 setglobal autoread
1155 setlocal noautoread
1156 call assert_false(&autoread)
1157 set autoread<
1158 call assert_true(&autoread)
1159 setglobal noautoread
1160 setlocal autoread
1161 setlocal autoread<
1162 call assert_false(&autoread)
1163 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001164endfunc
1165
Dominique Pelle042414f2021-07-12 21:43:19 +02001166func Test_set_in_sandbox()
1167 " Some boolean options cannot be set in sandbox, some can.
1168 call assert_fails('sandbox set modelineexpr', 'E48:')
1169 sandbox set number
1170 call assert_true(&number)
1171 set number&
1172
1173 " Some boolean options cannot be set in sandbox, some can.
1174 if has('python') || has('python3')
1175 call assert_fails('sandbox set pyxversion=3', 'E48:')
1176 endif
1177 sandbox set tabstop=4
1178 call assert_equal(4, &tabstop)
1179 set tabstop&
1180
1181 " Some string options cannot be set in sandbox, some can.
1182 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1183 sandbox set filetype=perl
1184 call assert_equal('perl', &filetype)
1185 set filetype&
1186endfunc
1187
Bram Moolenaar004a6782020-04-11 17:09:31 +02001188" Test for incrementing, decrementing and multiplying a number option value
1189func Test_opt_num_op()
1190 set shiftwidth=4
1191 set sw+=2
1192 call assert_equal(6, &sw)
1193 set sw-=2
1194 call assert_equal(4, &sw)
1195 set sw^=2
1196 call assert_equal(8, &sw)
1197 set shiftwidth&
1198endfunc
1199
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001200" Test for setting option values using v:false and v:true
1201func Test_opt_boolean()
1202 set number&
1203 set number
1204 call assert_equal(1, &nu)
1205 set nonu
1206 call assert_equal(0, &nu)
1207 let &nu = v:true
1208 call assert_equal(1, &nu)
1209 let &nu = v:false
1210 call assert_equal(0, &nu)
1211 set number&
1212endfunc
1213
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001214" Test for the 'window' option
1215func Test_window_opt()
1216 " Needs only one open widow
1217 %bw!
1218 call setline(1, range(1, 8))
1219 set window=5
1220 exe "normal \<C-F>"
1221 call assert_equal(4, line('w0'))
1222 exe "normal \<C-F>"
1223 call assert_equal(7, line('w0'))
1224 exe "normal \<C-F>"
1225 call assert_equal(8, line('w0'))
1226 exe "normal \<C-B>"
1227 call assert_equal(5, line('w0'))
1228 exe "normal \<C-B>"
1229 call assert_equal(2, line('w0'))
1230 exe "normal \<C-B>"
1231 call assert_equal(1, line('w0'))
1232 set window=1
1233 exe "normal gg\<C-F>"
1234 call assert_equal(2, line('w0'))
1235 exe "normal \<C-F>"
1236 call assert_equal(3, line('w0'))
1237 exe "normal \<C-B>"
1238 call assert_equal(2, line('w0'))
1239 exe "normal \<C-B>"
1240 call assert_equal(1, line('w0'))
1241 enew!
1242 set window&
1243endfunc
1244
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001245" Test for the 'winminheight' option
1246func Test_opt_winminheight()
1247 only!
1248 let &winheight = &lines + 4
1249 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1250 call assert_true(&winminheight <= &lines)
1251 set winminheight&
1252 set winheight&
1253endfunc
1254
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001255func Test_opt_winminheight_term()
1256 CheckRunVimInTerminal
1257
1258 " The tabline should be taken into account.
1259 let lines =<< trim END
1260 set wmh=0 stal=2
1261 below sp | wincmd _
1262 below sp | wincmd _
1263 below sp | wincmd _
1264 below sp
1265 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001266 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001267 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1268 call term_sendkeys(buf, ":set wmh=1\n")
1269 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1270
1271 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001272endfunc
1273
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001274func Test_opt_winminheight_term_tabs()
1275 CheckRunVimInTerminal
1276
1277 " The tabline should be taken into account.
1278 let lines =<< trim END
1279 set wmh=0 stal=2
1280 split
1281 split
1282 split
1283 split
1284 tabnew
1285 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001286 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001287 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1288 call term_sendkeys(buf, ":set wmh=1\n")
1289 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1290
1291 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001292endfunc
1293
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001294" Test for the 'winminwidth' option
1295func Test_opt_winminwidth()
1296 only!
1297 let &winwidth = &columns + 4
1298 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1299 call assert_true(&winminwidth <= &columns)
1300 set winminwidth&
1301 set winwidth&
1302endfunc
1303
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001304" Test for setting option value containing spaces with isfname+=32
1305func Test_isfname_with_options()
1306 set isfname+=32
1307 setlocal keywordprg=:term\ help.exe
1308 call assert_equal(':term help.exe', &keywordprg)
1309 set isfname&
1310 setlocal keywordprg&
1311endfunc
1312
Bram Moolenaar74667062020-12-28 15:41:41 +01001313" Test that resetting laststatus does change scroll option
1314func Test_opt_reset_scroll()
1315 CheckRunVimInTerminal
1316 let vimrc =<< trim [CODE]
1317 set scroll=2
1318 set laststatus=2
1319 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001320 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001321 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1322 call term_sendkeys(buf, ":verbose set scroll?\n")
1323 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1324 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001325
1326 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001327 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001328endfunc
1329
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001330" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1331func Test_VIM_POSIX()
1332 let saved_VIM_POSIX = getenv("VIM_POSIX")
1333
1334 call setenv('VIM_POSIX', "1")
1335 let after =<< trim [CODE]
1336 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1337 qall
1338 [CODE]
1339 if RunVim([], after, '')
1340 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1341 \ 'AS'], readfile('X_VIM_POSIX'))
1342 endif
1343
1344 call setenv('VIM_POSIX', v:null)
1345 let after =<< trim [CODE]
1346 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1347 qall
1348 [CODE]
1349 if RunVim([], after, '')
1350 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1351 \ 'S'], readfile('X_VIM_POSIX'))
1352 endif
1353
1354 call delete('X_VIM_POSIX')
1355 call setenv('VIM_POSIX', saved_VIM_POSIX)
1356endfunc
1357
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001358" Test for setting an option to a Vi or Vim default
1359func Test_opt_default()
1360 set formatoptions&vi
1361 call assert_equal('vt', &formatoptions)
1362 set formatoptions&vim
1363 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001364
1365 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1366 set fencs=latin1
1367 set fencs&
1368 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1369 set fencs=latin1
1370 set all&
1371 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001372endfunc
1373
1374" Test for the 'cmdheight' option
1375func Test_cmdheight()
1376 %bw!
1377 let ht = &lines
1378 set cmdheight=9999
1379 call assert_equal(1, winheight(0))
1380 call assert_equal(ht - 1, &cmdheight)
1381 set cmdheight&
1382endfunc
1383
Dominique Pelle923dce22021-11-21 11:36:04 +00001384" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001385func Test_opt_control_char()
1386 set wildchar=^v
1387 call assert_equal("\<C-V>", nr2char(&wildchar))
1388 set wildcharm=^r
1389 call assert_equal("\<C-R>", nr2char(&wildcharm))
1390 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1391 set wildchar& wildcharm&
1392endfunc
1393
1394" Test for the 'errorbells' option
1395func Test_opt_errorbells()
1396 set errorbells
1397 call assert_beeps('s/a1b2/x1y2/')
1398 set noerrorbells
1399endfunc
1400
Dominique Pelle042414f2021-07-12 21:43:19 +02001401func Test_opt_scrolljump()
1402 help
1403 resize 10
1404
1405 " Test with positive 'scrolljump'.
1406 set scrolljump=2
1407 norm! Lj
1408 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1409 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1410 \ winsaveview())
1411
1412 " Test with negative 'scrolljump' (percentage of window height).
1413 set scrolljump=-40
1414 norm! ggLj
1415 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1416 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1417 \ winsaveview())
1418
1419 set scrolljump&
1420 bw
1421endfunc
1422
Bakudankun29f3a452021-12-11 12:28:08 +00001423" Test for the 'cdhome' option
1424func Test_opt_cdhome()
1425 if has('unix') || has('vms')
1426 throw 'Skipped: only works on non-Unix'
1427 endif
1428
1429 set cdhome&
1430 call assert_equal(0, &cdhome)
1431 set cdhome
1432
1433 " This paragraph is copied from Test_cd_no_arg().
1434 let path = getcwd()
1435 cd
1436 call assert_equal($HOME, getcwd())
1437 call assert_notequal(path, getcwd())
1438 exe 'cd ' .. fnameescape(path)
1439 call assert_equal(path, getcwd())
1440
1441 set cdhome&
1442endfunc
1443
Christian Brabandtcb747892022-05-08 21:10:56 +01001444func Test_set_completion_2()
1445 CheckOption termguicolors
1446
1447 " Test default option completion
1448 set wildoptions=
1449 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1450 call assert_equal('"set termguicolors', @:)
1451
1452 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1453 call assert_equal('"set notermguicolors', @:)
1454
1455 " Test fuzzy option completion
1456 set wildoptions=fuzzy
1457 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1458 call assert_equal('"set termguicolors termencoding', @:)
1459
1460 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1461 call assert_equal('"set notermguicolors', @:)
1462
1463 set wildoptions=
1464endfunc
1465
Sean Dewar39c46b42022-05-12 17:44:29 +01001466func Test_switchbuf_reset()
1467 set switchbuf=useopen
1468 sblast
1469 call assert_equal(1, winnr('$'))
1470 set all&
1471 call assert_equal('', &switchbuf)
1472 sblast
1473 call assert_equal(2, winnr('$'))
1474 only!
1475endfunc
1476
zeertzjqfcba86c2022-09-22 13:57:32 +01001477" :set empty string for global 'keywordprg' falls back to ":help"
1478func Test_keywordprg_empty()
1479 let k = &keywordprg
1480 set keywordprg=man
1481 call assert_equal('man', &keywordprg)
1482 set keywordprg=
1483 call assert_equal(':help', &keywordprg)
1484 set keywordprg=man
1485 call assert_equal('man', &keywordprg)
1486 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1487 let &keywordprg = k
1488endfunc
1489
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001490" check that the very first buffer created does not have 'endoffile' set
1491func Test_endoffile_default()
1492 let after =<< trim [CODE]
1493 call writefile([execute('set eof?')], 'Xtestout')
1494 qall!
1495 [CODE]
1496 if RunVim([], after, '')
1497 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1498 endif
1499 call delete('Xtestout')
1500endfunc
1501
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001502" Test for setting the 'lines' and 'columns' options to a minimum value
1503func Test_set_min_lines_columns()
1504 let save_lines = &lines
1505 let save_columns = &columns
1506
1507 let after =<< trim END
1508 set nomore
1509 let msg = []
1510 let v:errmsg = ''
1511 silent! let &columns=0
1512 call add(msg, v:errmsg)
1513 silent! set columns=0
1514 call add(msg, v:errmsg)
1515 silent! call setbufvar('', '&columns', 0)
1516 call add(msg, v:errmsg)
1517 "call writefile(msg, 'XResultsetminlines')
1518 silent! let &lines=0
1519 call add(msg, v:errmsg)
1520 silent! set lines=0
1521 call add(msg, v:errmsg)
1522 silent! call setbufvar('', '&lines', 0)
1523 call add(msg, v:errmsg)
1524 call writefile(msg, 'XResultsetminlines')
1525 qall!
1526 END
1527 if RunVim([], after, '')
1528 call assert_equal(['E594: Need at least 12 columns',
1529 \ 'E594: Need at least 12 columns: columns=0',
1530 \ 'E594: Need at least 12 columns',
1531 \ 'E593: Need at least 2 lines',
1532 \ 'E593: Need at least 2 lines: lines=0',
1533 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1534 endif
1535
1536 call delete('XResultsetminlines')
1537 let &lines = save_lines
1538 let &columns = save_columns
1539endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001540
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001541" Test for reverting a string option value if the new value is invalid.
1542func Test_string_option_revert_on_failure()
1543 new
1544 let optlist = [
1545 \ ['ambiwidth', 'double', 'a123'],
1546 \ ['background', 'dark', 'a123'],
1547 \ ['backspace', 'eol', 'a123'],
1548 \ ['backupcopy', 'no', 'a123'],
1549 \ ['belloff', 'showmatch', 'a123'],
1550 \ ['breakindentopt', 'min:10', 'list'],
1551 \ ['bufhidden', 'wipe', 'a123'],
1552 \ ['buftype', 'nowrite', 'a123'],
1553 \ ['casemap', 'keepascii', 'a123'],
1554 \ ['cedit', "\<C-Y>", 'z'],
1555 \ ['colorcolumn', '10', 'z'],
1556 \ ['commentstring', '#%s', 'a123'],
1557 \ ['complete', '.,t', 'a'],
1558 \ ['completefunc', 'MyCmplFunc', '1a-'],
1559 \ ['completeopt', 'popup', 'a123'],
1560 \ ['completepopup', 'width:20', 'border'],
1561 \ ['concealcursor', 'v', 'xyz'],
1562 \ ['cpoptions', 'HJ', '~'],
1563 \ ['cryptmethod', 'zip', 'a123'],
1564 \ ['cursorlineopt', 'screenline', 'a123'],
1565 \ ['debug', 'throw', 'a123'],
1566 \ ['diffopt', 'iwhite', 'a123'],
1567 \ ['display', 'uhex', 'a123'],
1568 \ ['eadirection', 'hor', 'a123'],
1569 \ ['encoding', 'utf-8', 'a123'],
1570 \ ['eventignore', 'TextYankPost', 'a123'],
1571 \ ['fileencoding', 'utf-8', 'a123,'],
1572 \ ['fileformat', 'mac', 'a123'],
1573 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001574 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001575 \ ['fillchars', 'diff:~', 'a123'],
1576 \ ['foldclose', 'all', 'a123'],
1577 \ ['foldmarker', '[[[,]]]', '[[['],
1578 \ ['foldmethod', 'marker', 'a123'],
1579 \ ['foldopen', 'percent', 'a123'],
1580 \ ['formatoptions', 'an', '*'],
1581 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1582 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001583 \ ['highlight', '!:CursorColumn', '8:'],
1584 \ ['keymodel', 'stopsel', 'a123'],
1585 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1586 \ ['lispoptions', 'expr:1', 'a123'],
1587 \ ['listchars', 'tab:->', 'tab:'],
1588 \ ['matchpairs', '<:>', '<:'],
1589 \ ['mkspellmem', '100000,1000,100', '100000'],
1590 \ ['mouse', 'nvi', 'z'],
1591 \ ['mousemodel', 'extend', 'a123'],
1592 \ ['nrformats', 'alpha', 'a123'],
1593 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1594 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1595 \ ['previewpopup', 'width:20', 'a123'],
1596 \ ['printoptions', 'paper:A4', 'a123:'],
1597 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1598 \ ['rulerformat', '%l', '%['],
1599 \ ['scrollopt', 'hor,jump', 'a123'],
1600 \ ['selection', 'exclusive', 'a123'],
1601 \ ['selectmode', 'cmd', 'a123'],
1602 \ ['sessionoptions', 'options', 'a123'],
1603 \ ['shortmess', 'w', '2'],
1604 \ ['showbreak', '>>', "\x01"],
1605 \ ['showcmdloc', 'statusline', 'a123'],
1606 \ ['signcolumn', 'no', 'a123'],
1607 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1608 \ ['spellfile', 'MySpell.en.add', "\x01"],
1609 \ ['spelllang', 'en', "#"],
1610 \ ['spelloptions', 'camel', 'a123'],
1611 \ ['spellsuggest', 'double', 'a123'],
1612 \ ['splitkeep', 'topline', 'a123'],
1613 \ ['statusline', '%f', '%['],
1614 \ ['swapsync', 'sync', 'a123'],
1615 \ ['switchbuf', 'usetab', 'a123'],
1616 \ ['syntax', 'abc', 'a^b'],
1617 \ ['tabline', '%f', '%['],
1618 \ ['tagcase', 'ignore', 'a123'],
1619 \ ['tagfunc', 'MyTagFunc', '1a-'],
1620 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1621 \ ['viewoptions', 'options', 'a123'],
1622 \ ['virtualedit', 'onemore', 'a123'],
1623 \ ['whichwrap', '<,>', '{,}'],
1624 \ ['wildmode', 'list', 'a123'],
1625 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001626 \ ]
1627 if has('gui')
1628 call add(optlist, ['browsedir', 'buffer', 'a123'])
1629 endif
1630 if has('clipboard_working')
1631 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1632 endif
1633 if has('win32')
1634 call add(optlist, ['completeslash', 'slash', 'a123'])
1635 endif
1636 if has('cscope')
1637 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1638 endif
1639 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001640 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1641 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1642 endif
1643 if has('keymap')
1644 call add(optlist, ['keymap', 'greek', '[]'])
1645 endif
1646 if has('mouseshape')
1647 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1648 endif
1649 if has('win32') && has('gui')
1650 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1651 endif
1652 if has('rightleft')
1653 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1654 endif
1655 if has('terminal')
1656 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1657 call add(optlist, ['termwinsize', '24x80', '100'])
1658 endif
1659 if has('win32') && has('terminal')
1660 call add(optlist, ['termwintype', 'winpty', 'a123'])
1661 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001662 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001663 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001664 endif
1665 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001666 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1667 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001668 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001669 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1670 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001671 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001672 call add(optlist, ['varsofttabstop', '12', 'a123'])
1673 call add(optlist, ['vartabstop', '4,20', '4,'])
1674 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001675 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001676 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001677 endif
1678 for opt in optlist
1679 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001680 try
1681 exe $"let &{opt[0]} = '{opt[1]}'"
1682 catch
1683 call assert_report($"Caught {v:exception} with {opt->string()}")
1684 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001685 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1686 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1687 exe $"let &{opt[0]} = save_opt"
1688 endfor
1689 bw!
1690endfunc
1691
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02001692func Test_set_option_window_global_local()
1693 new Xbuffer1
1694 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
1695 setlocal scrolloff=2
1696 setglobal scrolloff=3
1697 setl modified
1698 " A new buffer has its own window-local options
1699 hide enew
1700 call assert_equal(-1, &l:scrolloff)
1701 call assert_equal(3, &g:scrolloff)
1702 " A new window opened with its own buffer-local options
1703 new
1704 call assert_equal(-1, &l:scrolloff)
1705 call assert_equal(3, &g:scrolloff)
1706 " Re-open Xbuffer1 and it should use
1707 " the previous set window-local options
1708 b Xbuffer1
1709 call assert_equal(2, &l:scrolloff)
1710 call assert_equal(3, &g:scrolloff)
1711 bw!
1712 bw!
1713 let &g:scrolloff = _gso
1714endfunc
1715
1716func GetGlobalLocalWindowOptions()
1717 new
1718 sil! r $VIMRUNTIME/doc/options.txt
1719 " Filter for global or local to window
1720 v/^'.*'.*\n.*global or local to window |global-local/d
1721 " get option value and type
1722 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
1723 sil %s/empty/""/g
1724 " split the result
1725 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
1726 bw!
1727 return result
1728endfunc
1729
1730func Test_set_option_window_global_local_all()
1731 new Xbuffer2
1732
1733 let optionlist = GetGlobalLocalWindowOptions()
1734 for [opt, type, default] in optionlist
1735 let _old = eval('&g:' .. opt)
1736 if type == 'string'
1737 if opt == 'fillchars'
1738 exe 'setl ' .. opt .. '=vert:+'
1739 exe 'setg ' .. opt .. '=vert:+,fold:+'
1740 elseif opt == 'listchars'
1741 exe 'setl ' .. opt .. '=tab:>>'
1742 exe 'setg ' .. opt .. '=tab:++'
1743 elseif opt == 'virtualedit'
1744 exe 'setl ' .. opt .. '=all'
1745 exe 'setg ' .. opt .. '=block'
1746 else
1747 exe 'setl ' .. opt .. '=Local'
1748 exe 'setg ' .. opt .. '=Global'
1749 endif
1750 elseif type == 'number'
1751 exe 'setl ' .. opt .. '=5'
1752 exe 'setg ' .. opt .. '=10'
1753 endif
1754 setl modified
1755 hide enew
1756 if type == 'string'
1757 call assert_equal('', eval('&l:' .. opt))
1758 if opt == 'fillchars'
1759 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
1760 elseif opt == 'listchars'
1761 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
1762 elseif opt == 'virtualedit'
1763 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
1764 else
1765 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
1766 endif
1767 elseif type == 'number'
1768 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
1769 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
1770 endif
1771 bw!
1772 exe 'let &g:' .. opt .. '=' .. default
1773 endfor
1774 bw!
1775endfunc
1776
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001777" vim: shiftwidth=2 sts=2 expandtab