blob: 015ecc122ddc228ce229169892b08b83f20614bf [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
957 setlocal so<
958 call assert_equal(5, &so)
959 setlocal so=0
960 call assert_equal(0, &so)
961 setlocal so=-1
962 call assert_equal(5, &so)
963
964 call assert_equal(7, &siso)
965 setlocal siso=3
966 call assert_equal(3, &siso)
967 wincmd w
968 call assert_equal(7, &siso)
969 wincmd w
970 setlocal siso<
971 call assert_equal(7, &siso)
972 setlocal siso=0
973 call assert_equal(0, &siso)
974 setlocal siso=-1
975 call assert_equal(7, &siso)
976
977 close
978 set so&
979 set siso&
980endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200981
982func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100983 CheckFunction reltimefloat
984
Bram Moolenaar449ac472019-04-03 21:42:35 +0200985 new
986 call setline(1, 'empty')
987 redraw
988 set writedelay=10
989 let start = reltime()
990 call setline(1, repeat('x', 70))
991 redraw
992 let elapsed = reltimefloat(reltime(start))
993 set writedelay=0
994 " With 'writedelay' set should take at least 30 * 10 msec
995 call assert_inrange(30 * 0.01, 999.0, elapsed)
996
997 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200998endfunc
999
1000func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001001 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001002 set visualbell
1003 call assert_beeps('normal 0h')
1004 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001005 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001006endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001007
1008" Test for the 'write' option
1009func Test_write()
1010 new
1011 call setline(1, ['L1'])
1012 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001013 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001014 set write
1015 close!
1016endfunc
1017
1018" Test for 'buftype' option
1019func Test_buftype()
1020 new
1021 call setline(1, ['L1'])
1022 set buftype=nowrite
1023 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001024
1025 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1026 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001027 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001028 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1029 endfor
1030
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001031 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001032endfunc
1033
Bram Moolenaar578fe942020-02-27 21:32:51 +01001034" Test for the 'rightleftcmd' option
1035func Test_rightleftcmd()
1036 CheckFeature rightleft
1037 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001038
1039 let g:l = []
1040 func AddPos()
1041 call add(g:l, screencol())
1042 return ''
1043 endfunc
1044 cmap <expr> <F2> AddPos()
1045
zeertzjqbb404f52022-07-23 06:25:29 +01001046 set rightleftcmd=
1047 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1048 \ "\<Right>\<F2>\<Esc>", 'xt')
1049 call assert_equal([2, 5, 3, 4], g:l)
1050
1051 let g:l = []
1052 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001053 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1054 \ "\<Left>\<F2>\<Esc>", 'xt')
1055 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1056
1057 cunmap <F2>
1058 unlet g:l
1059 set rightleftcmd&
1060 set rightleft&
1061endfunc
1062
zeertzjq28c162f2022-08-14 14:49:50 +01001063" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001064func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001065 " redraw to avoid matching previous messages
1066 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001067 set debug=beep
1068 exe "normal \<C-c>"
1069 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001070 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001071 " also check a line above, with a certain window width the colon is there
1072 call assert_match('Test_debug_option:$',
1073 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001074 set debug&
1075endfunc
1076
Bram Moolenaar004a6782020-04-11 17:09:31 +02001077" Test for the default CDPATH option
1078func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001079 let after =<< trim [CODE]
1080 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1081 call writefile(v:errors, 'Xtestout')
1082 qall
1083 [CODE]
1084 if has('unix')
1085 let $CDPATH='/path/to/dir1:/path/to/dir2'
1086 else
1087 let $CDPATH='/path/to/dir1;/path/to/dir2'
1088 endif
1089 if RunVim([], after, '')
1090 call assert_equal([], readfile('Xtestout'))
1091 call delete('Xtestout')
1092 endif
1093endfunc
1094
1095" Test for setting keycodes using set
1096func Test_opt_set_keycode()
1097 call assert_fails('set <t_k1=l', 'E474:')
1098 call assert_fails('set <Home=l', 'E474:')
1099 set <t_k9>=abcd
1100 call assert_equal('abcd', &t_k9)
1101 set <t_k9>&
1102 set <F9>=xyz
1103 call assert_equal('xyz', &t_k9)
1104 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001105
1106 " should we test all of them?
1107 set t_Ce=testCe
1108 set t_Cs=testCs
1109 set t_Us=testUs
1110 set t_ds=testds
1111 set t_Ds=testDs
1112 call assert_equal('testCe', &t_Ce)
1113 call assert_equal('testCs', &t_Cs)
1114 call assert_equal('testUs', &t_Us)
1115 call assert_equal('testds', &t_ds)
1116 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001117endfunc
1118
1119" Test for changing options in a sandbox
1120func Test_opt_sandbox()
1121 for opt in ['backupdir', 'cdpath', 'exrc']
1122 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001123 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001124 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001125 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001126endfunc
1127
1128" Test for setting an option with local value to global value
1129func Test_opt_local_to_global()
1130 setglobal equalprg=gprg
1131 setlocal equalprg=lprg
1132 call assert_equal('gprg', &g:equalprg)
1133 call assert_equal('lprg', &l:equalprg)
1134 call assert_equal('lprg', &equalprg)
1135 set equalprg<
1136 call assert_equal('', &l:equalprg)
1137 call assert_equal('gprg', &equalprg)
1138 setglobal equalprg=gnewprg
1139 setlocal equalprg=lnewprg
1140 setlocal equalprg<
1141 call assert_equal('gnewprg', &l:equalprg)
1142 call assert_equal('gnewprg', &equalprg)
1143 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001144
1145 " Test for setting the global/local value of a boolean option
1146 setglobal autoread
1147 setlocal noautoread
1148 call assert_false(&autoread)
1149 set autoread<
1150 call assert_true(&autoread)
1151 setglobal noautoread
1152 setlocal autoread
1153 setlocal autoread<
1154 call assert_false(&autoread)
1155 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001156endfunc
1157
Dominique Pelle042414f2021-07-12 21:43:19 +02001158func Test_set_in_sandbox()
1159 " Some boolean options cannot be set in sandbox, some can.
1160 call assert_fails('sandbox set modelineexpr', 'E48:')
1161 sandbox set number
1162 call assert_true(&number)
1163 set number&
1164
1165 " Some boolean options cannot be set in sandbox, some can.
1166 if has('python') || has('python3')
1167 call assert_fails('sandbox set pyxversion=3', 'E48:')
1168 endif
1169 sandbox set tabstop=4
1170 call assert_equal(4, &tabstop)
1171 set tabstop&
1172
1173 " Some string options cannot be set in sandbox, some can.
1174 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1175 sandbox set filetype=perl
1176 call assert_equal('perl', &filetype)
1177 set filetype&
1178endfunc
1179
Bram Moolenaar004a6782020-04-11 17:09:31 +02001180" Test for incrementing, decrementing and multiplying a number option value
1181func Test_opt_num_op()
1182 set shiftwidth=4
1183 set sw+=2
1184 call assert_equal(6, &sw)
1185 set sw-=2
1186 call assert_equal(4, &sw)
1187 set sw^=2
1188 call assert_equal(8, &sw)
1189 set shiftwidth&
1190endfunc
1191
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001192" Test for setting option values using v:false and v:true
1193func Test_opt_boolean()
1194 set number&
1195 set number
1196 call assert_equal(1, &nu)
1197 set nonu
1198 call assert_equal(0, &nu)
1199 let &nu = v:true
1200 call assert_equal(1, &nu)
1201 let &nu = v:false
1202 call assert_equal(0, &nu)
1203 set number&
1204endfunc
1205
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001206" Test for the 'window' option
1207func Test_window_opt()
1208 " Needs only one open widow
1209 %bw!
1210 call setline(1, range(1, 8))
1211 set window=5
1212 exe "normal \<C-F>"
1213 call assert_equal(4, line('w0'))
1214 exe "normal \<C-F>"
1215 call assert_equal(7, line('w0'))
1216 exe "normal \<C-F>"
1217 call assert_equal(8, line('w0'))
1218 exe "normal \<C-B>"
1219 call assert_equal(5, line('w0'))
1220 exe "normal \<C-B>"
1221 call assert_equal(2, line('w0'))
1222 exe "normal \<C-B>"
1223 call assert_equal(1, line('w0'))
1224 set window=1
1225 exe "normal gg\<C-F>"
1226 call assert_equal(2, line('w0'))
1227 exe "normal \<C-F>"
1228 call assert_equal(3, line('w0'))
1229 exe "normal \<C-B>"
1230 call assert_equal(2, line('w0'))
1231 exe "normal \<C-B>"
1232 call assert_equal(1, line('w0'))
1233 enew!
1234 set window&
1235endfunc
1236
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001237" Test for the 'winminheight' option
1238func Test_opt_winminheight()
1239 only!
1240 let &winheight = &lines + 4
1241 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1242 call assert_true(&winminheight <= &lines)
1243 set winminheight&
1244 set winheight&
1245endfunc
1246
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001247func Test_opt_winminheight_term()
1248 CheckRunVimInTerminal
1249
1250 " The tabline should be taken into account.
1251 let lines =<< trim END
1252 set wmh=0 stal=2
1253 below sp | wincmd _
1254 below sp | wincmd _
1255 below sp | wincmd _
1256 below sp
1257 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001258 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001259 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1260 call term_sendkeys(buf, ":set wmh=1\n")
1261 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1262
1263 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001264endfunc
1265
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001266func Test_opt_winminheight_term_tabs()
1267 CheckRunVimInTerminal
1268
1269 " The tabline should be taken into account.
1270 let lines =<< trim END
1271 set wmh=0 stal=2
1272 split
1273 split
1274 split
1275 split
1276 tabnew
1277 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001278 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001279 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1280 call term_sendkeys(buf, ":set wmh=1\n")
1281 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1282
1283 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001284endfunc
1285
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001286" Test for the 'winminwidth' option
1287func Test_opt_winminwidth()
1288 only!
1289 let &winwidth = &columns + 4
1290 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1291 call assert_true(&winminwidth <= &columns)
1292 set winminwidth&
1293 set winwidth&
1294endfunc
1295
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001296" Test for setting option value containing spaces with isfname+=32
1297func Test_isfname_with_options()
1298 set isfname+=32
1299 setlocal keywordprg=:term\ help.exe
1300 call assert_equal(':term help.exe', &keywordprg)
1301 set isfname&
1302 setlocal keywordprg&
1303endfunc
1304
Bram Moolenaar74667062020-12-28 15:41:41 +01001305" Test that resetting laststatus does change scroll option
1306func Test_opt_reset_scroll()
1307 CheckRunVimInTerminal
1308 let vimrc =<< trim [CODE]
1309 set scroll=2
1310 set laststatus=2
1311 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001312 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001313 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1314 call term_sendkeys(buf, ":verbose set scroll?\n")
1315 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1316 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001317
1318 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001319 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001320endfunc
1321
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001322" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1323func Test_VIM_POSIX()
1324 let saved_VIM_POSIX = getenv("VIM_POSIX")
1325
1326 call setenv('VIM_POSIX', "1")
1327 let after =<< trim [CODE]
1328 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1329 qall
1330 [CODE]
1331 if RunVim([], after, '')
1332 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1333 \ 'AS'], readfile('X_VIM_POSIX'))
1334 endif
1335
1336 call setenv('VIM_POSIX', v:null)
1337 let after =<< trim [CODE]
1338 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1339 qall
1340 [CODE]
1341 if RunVim([], after, '')
1342 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1343 \ 'S'], readfile('X_VIM_POSIX'))
1344 endif
1345
1346 call delete('X_VIM_POSIX')
1347 call setenv('VIM_POSIX', saved_VIM_POSIX)
1348endfunc
1349
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001350" Test for setting an option to a Vi or Vim default
1351func Test_opt_default()
1352 set formatoptions&vi
1353 call assert_equal('vt', &formatoptions)
1354 set formatoptions&vim
1355 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001356
1357 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1358 set fencs=latin1
1359 set fencs&
1360 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1361 set fencs=latin1
1362 set all&
1363 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001364endfunc
1365
1366" Test for the 'cmdheight' option
1367func Test_cmdheight()
1368 %bw!
1369 let ht = &lines
1370 set cmdheight=9999
1371 call assert_equal(1, winheight(0))
1372 call assert_equal(ht - 1, &cmdheight)
1373 set cmdheight&
1374endfunc
1375
Dominique Pelle923dce22021-11-21 11:36:04 +00001376" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001377func Test_opt_control_char()
1378 set wildchar=^v
1379 call assert_equal("\<C-V>", nr2char(&wildchar))
1380 set wildcharm=^r
1381 call assert_equal("\<C-R>", nr2char(&wildcharm))
1382 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1383 set wildchar& wildcharm&
1384endfunc
1385
1386" Test for the 'errorbells' option
1387func Test_opt_errorbells()
1388 set errorbells
1389 call assert_beeps('s/a1b2/x1y2/')
1390 set noerrorbells
1391endfunc
1392
Dominique Pelle042414f2021-07-12 21:43:19 +02001393func Test_opt_scrolljump()
1394 help
1395 resize 10
1396
1397 " Test with positive 'scrolljump'.
1398 set scrolljump=2
1399 norm! Lj
1400 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1401 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1402 \ winsaveview())
1403
1404 " Test with negative 'scrolljump' (percentage of window height).
1405 set scrolljump=-40
1406 norm! ggLj
1407 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1408 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1409 \ winsaveview())
1410
1411 set scrolljump&
1412 bw
1413endfunc
1414
Bakudankun29f3a452021-12-11 12:28:08 +00001415" Test for the 'cdhome' option
1416func Test_opt_cdhome()
1417 if has('unix') || has('vms')
1418 throw 'Skipped: only works on non-Unix'
1419 endif
1420
1421 set cdhome&
1422 call assert_equal(0, &cdhome)
1423 set cdhome
1424
1425 " This paragraph is copied from Test_cd_no_arg().
1426 let path = getcwd()
1427 cd
1428 call assert_equal($HOME, getcwd())
1429 call assert_notequal(path, getcwd())
1430 exe 'cd ' .. fnameescape(path)
1431 call assert_equal(path, getcwd())
1432
1433 set cdhome&
1434endfunc
1435
Christian Brabandtcb747892022-05-08 21:10:56 +01001436func Test_set_completion_2()
1437 CheckOption termguicolors
1438
1439 " Test default option completion
1440 set wildoptions=
1441 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1442 call assert_equal('"set termguicolors', @:)
1443
1444 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1445 call assert_equal('"set notermguicolors', @:)
1446
1447 " Test fuzzy option completion
1448 set wildoptions=fuzzy
1449 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1450 call assert_equal('"set termguicolors termencoding', @:)
1451
1452 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1453 call assert_equal('"set notermguicolors', @:)
1454
1455 set wildoptions=
1456endfunc
1457
Sean Dewar39c46b42022-05-12 17:44:29 +01001458func Test_switchbuf_reset()
1459 set switchbuf=useopen
1460 sblast
1461 call assert_equal(1, winnr('$'))
1462 set all&
1463 call assert_equal('', &switchbuf)
1464 sblast
1465 call assert_equal(2, winnr('$'))
1466 only!
1467endfunc
1468
zeertzjqfcba86c2022-09-22 13:57:32 +01001469" :set empty string for global 'keywordprg' falls back to ":help"
1470func Test_keywordprg_empty()
1471 let k = &keywordprg
1472 set keywordprg=man
1473 call assert_equal('man', &keywordprg)
1474 set keywordprg=
1475 call assert_equal(':help', &keywordprg)
1476 set keywordprg=man
1477 call assert_equal('man', &keywordprg)
1478 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1479 let &keywordprg = k
1480endfunc
1481
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001482" check that the very first buffer created does not have 'endoffile' set
1483func Test_endoffile_default()
1484 let after =<< trim [CODE]
1485 call writefile([execute('set eof?')], 'Xtestout')
1486 qall!
1487 [CODE]
1488 if RunVim([], after, '')
1489 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1490 endif
1491 call delete('Xtestout')
1492endfunc
1493
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001494" Test for setting the 'lines' and 'columns' options to a minimum value
1495func Test_set_min_lines_columns()
1496 let save_lines = &lines
1497 let save_columns = &columns
1498
1499 let after =<< trim END
1500 set nomore
1501 let msg = []
1502 let v:errmsg = ''
1503 silent! let &columns=0
1504 call add(msg, v:errmsg)
1505 silent! set columns=0
1506 call add(msg, v:errmsg)
1507 silent! call setbufvar('', '&columns', 0)
1508 call add(msg, v:errmsg)
1509 "call writefile(msg, 'XResultsetminlines')
1510 silent! let &lines=0
1511 call add(msg, v:errmsg)
1512 silent! set lines=0
1513 call add(msg, v:errmsg)
1514 silent! call setbufvar('', '&lines', 0)
1515 call add(msg, v:errmsg)
1516 call writefile(msg, 'XResultsetminlines')
1517 qall!
1518 END
1519 if RunVim([], after, '')
1520 call assert_equal(['E594: Need at least 12 columns',
1521 \ 'E594: Need at least 12 columns: columns=0',
1522 \ 'E594: Need at least 12 columns',
1523 \ 'E593: Need at least 2 lines',
1524 \ 'E593: Need at least 2 lines: lines=0',
1525 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1526 endif
1527
1528 call delete('XResultsetminlines')
1529 let &lines = save_lines
1530 let &columns = save_columns
1531endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001532
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001533" Test for reverting a string option value if the new value is invalid.
1534func Test_string_option_revert_on_failure()
1535 new
1536 let optlist = [
1537 \ ['ambiwidth', 'double', 'a123'],
1538 \ ['background', 'dark', 'a123'],
1539 \ ['backspace', 'eol', 'a123'],
1540 \ ['backupcopy', 'no', 'a123'],
1541 \ ['belloff', 'showmatch', 'a123'],
1542 \ ['breakindentopt', 'min:10', 'list'],
1543 \ ['bufhidden', 'wipe', 'a123'],
1544 \ ['buftype', 'nowrite', 'a123'],
1545 \ ['casemap', 'keepascii', 'a123'],
1546 \ ['cedit', "\<C-Y>", 'z'],
1547 \ ['colorcolumn', '10', 'z'],
1548 \ ['commentstring', '#%s', 'a123'],
1549 \ ['complete', '.,t', 'a'],
1550 \ ['completefunc', 'MyCmplFunc', '1a-'],
1551 \ ['completeopt', 'popup', 'a123'],
1552 \ ['completepopup', 'width:20', 'border'],
1553 \ ['concealcursor', 'v', 'xyz'],
1554 \ ['cpoptions', 'HJ', '~'],
1555 \ ['cryptmethod', 'zip', 'a123'],
1556 \ ['cursorlineopt', 'screenline', 'a123'],
1557 \ ['debug', 'throw', 'a123'],
1558 \ ['diffopt', 'iwhite', 'a123'],
1559 \ ['display', 'uhex', 'a123'],
1560 \ ['eadirection', 'hor', 'a123'],
1561 \ ['encoding', 'utf-8', 'a123'],
1562 \ ['eventignore', 'TextYankPost', 'a123'],
1563 \ ['fileencoding', 'utf-8', 'a123,'],
1564 \ ['fileformat', 'mac', 'a123'],
1565 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001566 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001567 \ ['fillchars', 'diff:~', 'a123'],
1568 \ ['foldclose', 'all', 'a123'],
1569 \ ['foldmarker', '[[[,]]]', '[[['],
1570 \ ['foldmethod', 'marker', 'a123'],
1571 \ ['foldopen', 'percent', 'a123'],
1572 \ ['formatoptions', 'an', '*'],
1573 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1574 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001575 \ ['highlight', '!:CursorColumn', '8:'],
1576 \ ['keymodel', 'stopsel', 'a123'],
1577 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1578 \ ['lispoptions', 'expr:1', 'a123'],
1579 \ ['listchars', 'tab:->', 'tab:'],
1580 \ ['matchpairs', '<:>', '<:'],
1581 \ ['mkspellmem', '100000,1000,100', '100000'],
1582 \ ['mouse', 'nvi', 'z'],
1583 \ ['mousemodel', 'extend', 'a123'],
1584 \ ['nrformats', 'alpha', 'a123'],
1585 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1586 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1587 \ ['previewpopup', 'width:20', 'a123'],
1588 \ ['printoptions', 'paper:A4', 'a123:'],
1589 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1590 \ ['rulerformat', '%l', '%['],
1591 \ ['scrollopt', 'hor,jump', 'a123'],
1592 \ ['selection', 'exclusive', 'a123'],
1593 \ ['selectmode', 'cmd', 'a123'],
1594 \ ['sessionoptions', 'options', 'a123'],
1595 \ ['shortmess', 'w', '2'],
1596 \ ['showbreak', '>>', "\x01"],
1597 \ ['showcmdloc', 'statusline', 'a123'],
1598 \ ['signcolumn', 'no', 'a123'],
1599 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1600 \ ['spellfile', 'MySpell.en.add', "\x01"],
1601 \ ['spelllang', 'en', "#"],
1602 \ ['spelloptions', 'camel', 'a123'],
1603 \ ['spellsuggest', 'double', 'a123'],
1604 \ ['splitkeep', 'topline', 'a123'],
1605 \ ['statusline', '%f', '%['],
1606 \ ['swapsync', 'sync', 'a123'],
1607 \ ['switchbuf', 'usetab', 'a123'],
1608 \ ['syntax', 'abc', 'a^b'],
1609 \ ['tabline', '%f', '%['],
1610 \ ['tagcase', 'ignore', 'a123'],
1611 \ ['tagfunc', 'MyTagFunc', '1a-'],
1612 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1613 \ ['viewoptions', 'options', 'a123'],
1614 \ ['virtualedit', 'onemore', 'a123'],
1615 \ ['whichwrap', '<,>', '{,}'],
1616 \ ['wildmode', 'list', 'a123'],
1617 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001618 \ ]
1619 if has('gui')
1620 call add(optlist, ['browsedir', 'buffer', 'a123'])
1621 endif
1622 if has('clipboard_working')
1623 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1624 endif
1625 if has('win32')
1626 call add(optlist, ['completeslash', 'slash', 'a123'])
1627 endif
1628 if has('cscope')
1629 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1630 endif
1631 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001632 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1633 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1634 endif
1635 if has('keymap')
1636 call add(optlist, ['keymap', 'greek', '[]'])
1637 endif
1638 if has('mouseshape')
1639 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1640 endif
1641 if has('win32') && has('gui')
1642 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1643 endif
1644 if has('rightleft')
1645 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1646 endif
1647 if has('terminal')
1648 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1649 call add(optlist, ['termwinsize', '24x80', '100'])
1650 endif
1651 if has('win32') && has('terminal')
1652 call add(optlist, ['termwintype', 'winpty', 'a123'])
1653 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001654 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001655 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001656 endif
1657 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001658 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1659 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001660 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001661 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1662 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001663 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001664 call add(optlist, ['varsofttabstop', '12', 'a123'])
1665 call add(optlist, ['vartabstop', '4,20', '4,'])
1666 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001667 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001668 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001669 endif
1670 for opt in optlist
1671 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001672 try
1673 exe $"let &{opt[0]} = '{opt[1]}'"
1674 catch
1675 call assert_report($"Caught {v:exception} with {opt->string()}")
1676 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001677 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1678 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1679 exe $"let &{opt[0]} = save_opt"
1680 endfor
1681 bw!
1682endfunc
1683
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001684" vim: shiftwidth=2 sts=2 expandtab