blob: fc81cec4eacfca506e08e4d4779341240ba15a94 [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(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200377
378 " Expand values for 'syntax'
379 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
380 call assert_equal('"set syntax=sshdconfig', @:)
381 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
382 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100383endfunc
384
zeertzjq4c7cb372023-06-14 16:39:54 +0100385func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100386 call assert_fails('set scroll=-1', 'E49:')
387 call assert_fails('set backupcopy=', 'E474:')
388 call assert_fails('set regexpengine=3', 'E474:')
389 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200390 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100391 call assert_fails('set colorcolumn=-a', 'E474:')
392 call assert_fails('set colorcolumn=a', 'E474:')
393 call assert_fails('set colorcolumn=1,', 'E474:')
394 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100395 call assert_fails('set cmdheight=-1', 'E487:')
396 call assert_fails('set cmdwinheight=-1', 'E487:')
397 if has('conceal')
398 call assert_fails('set conceallevel=-1', 'E487:')
399 call assert_fails('set conceallevel=4', 'E474:')
400 endif
401 call assert_fails('set helpheight=-1', 'E487:')
402 call assert_fails('set history=-1', 'E487:')
403 call assert_fails('set report=-1', 'E487:')
404 call assert_fails('set shiftwidth=-1', 'E487:')
405 call assert_fails('set sidescroll=-1', 'E487:')
406 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000407 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000408 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000409 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100410 call assert_fails('set textwidth=-1', 'E487:')
411 call assert_fails('set timeoutlen=-1', 'E487:')
412 call assert_fails('set updatecount=-1', 'E487:')
413 call assert_fails('set updatetime=-1', 'E487:')
414 call assert_fails('set winheight=-1', 'E487:')
415 call assert_fails('set tabstop!', 'E488:')
416 call assert_fails('set xxx', 'E518:')
417 call assert_fails('set beautify?', 'E519:')
418 call assert_fails('set undolevels=x', 'E521:')
419 call assert_fails('set tabstop=', 'E521:')
420 call assert_fails('set comments=-', 'E524:')
421 call assert_fails('set comments=a', 'E525:')
422 call assert_fails('set foldmarker=x', 'E536:')
423 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000424 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100425 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100426 call assert_fails('set rulerformat=%-', 'E539:')
427 call assert_fails('set rulerformat=%(', 'E542:')
428 call assert_fails('set rulerformat=%15(%%', 'E542:')
429 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100430 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100431 call assert_fails('set statusline=%{%', 'E540:')
432 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100433 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100434 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100435 call assert_fails('set tabline=%$', 'E539:')
436 call assert_fails('set tabline=%{', 'E540:')
437 call assert_fails('set tabline=%{%', 'E540:')
438 call assert_fails('set tabline=%{%}', 'E539:')
439 call assert_fails('set tabline=%(', 'E542:')
440 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100441
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100442 if has('cursorshape')
443 " This invalid value for 'guicursor' used to cause Vim to crash.
444 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
445 call assert_fails('set guicursor=i-ci', 'E545:')
446 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100447 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100448 call assert_fails('set guicursor=r-cr:horx', 'E548:')
449 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
450 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100451 if has('mouseshape')
452 call assert_fails('se mouseshape=i-r:x', 'E547:')
453 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000454
455 " Test for 'backupext' and 'patchmode' set to the same value
456 set backupext=.bak
457 set patchmode=.patch
458 call assert_fails('set patchmode=.bak', 'E589:')
459 call assert_equal('.patch', &patchmode)
460 call assert_fails('set backupext=.patch', 'E589:')
461 call assert_equal('.bak', &backupext)
462 set backupext& patchmode&
463
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100464 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200465 set winminheight& winheight&
466 set winheight=10 winminheight=10
467 call assert_fails('set winheight=9', 'E591:')
468 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100469 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200470 set winminwidth& winwidth&
471 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
472 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100473 call assert_fails("set showbreak=\x01", 'E595:')
474 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200475 call assert_fails('set tabstop??', 'E488:')
476 call assert_fails('set wrapscan!!', 'E488:')
477 call assert_fails('set tabstop&&', 'E488:')
478 call assert_fails('set wrapscan<<', 'E488:')
479 call assert_fails('set wrapscan=1', 'E474:')
480 call assert_fails('set autoindent@', 'E488:')
481 call assert_fails('set wildchar=<abc>', 'E474:')
482 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200483 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100484 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200485 call assert_fails('set pyxversion=6', 'E474:')
486 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100487 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200488 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100489 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
490 call assert_fails('set foldmarker={{{,', 'E474:')
491 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100492 setlocal listchars=trail:·
493 call assert_fails('set ambiwidth=double', 'E834:')
494 setlocal listchars=trail:-
495 setglobal listchars=trail:·
496 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100497 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100498 setlocal fillchars=stl:·
499 call assert_fails('set ambiwidth=double', 'E835:')
500 setlocal fillchars=stl:-
501 setglobal fillchars=stl:·
502 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100503 set fillchars&
504 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
505 set nomodifiable
506 call assert_fails('set fileencoding=latin1', 'E21:')
507 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200508 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000509 call assert_fails('let &formatoptions = "?"', 'E539:')
510 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100511 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
512 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
513 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
514 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
515 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
516 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100517endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100518
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000519func Test_set_encoding()
520 let save_encoding = &encoding
521
522 set enc=iso8859-1
523 call assert_equal('latin1', &enc)
524 set enc=iso8859_1
525 call assert_equal('latin1', &enc)
526 set enc=iso-8859-1
527 call assert_equal('latin1', &enc)
528 set enc=iso_8859_1
529 call assert_equal('latin1', &enc)
530 set enc=iso88591
531 call assert_equal('latin1', &enc)
532 set enc=iso8859
533 call assert_equal('latin1', &enc)
534 set enc=iso-8859
535 call assert_equal('latin1', &enc)
536 set enc=iso_8859
537 call assert_equal('latin1', &enc)
538 call assert_fails('set enc=iso8858', 'E474:')
539 call assert_equal('latin1', &enc)
540
541 let &encoding = save_encoding
542endfunc
543
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200544func CheckWasSet(name)
545 let verb_cm = execute('verbose set ' .. a:name .. '?')
546 call assert_match('Last set from.*test_options.vim', verb_cm)
547endfunc
548func CheckWasNotSet(name)
549 let verb_cm = execute('verbose set ' .. a:name .. '?')
550 call assert_notmatch('Last set from', verb_cm)
551endfunc
552
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200553" Must be executed before other tests that set 'term'.
554func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200555 CheckNotGui
556
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200557 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200558
559 let term_save = &term
560 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200561 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200562 let &term = term_save
563endfunc
564
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200565func Test_copy_context()
566 setlocal list
567 call CheckWasSet('list')
568 split
569 call CheckWasSet('list')
570 quit
571 setlocal nolist
572
573 set ai
574 call CheckWasSet('ai')
575 set filetype=perl
576 call CheckWasSet('filetype')
577 set fo=tcroq
578 call CheckWasSet('fo')
579
580 split Xsomebuf
581 call CheckWasSet('ai')
582 call CheckWasNotSet('filetype')
583 call CheckWasSet('fo')
584endfunc
585
Bram Moolenaar67391142017-02-19 21:07:04 +0100586func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200587 CheckUnix
588 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200589
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200590 " Setting 'ttytype' used to cause a double-free when exiting vim and
591 " when vim is compiled with -DEXITFREE.
592 set ttytype=ansi
593 call assert_equal('ansi', &ttytype)
594 call assert_equal(&ttytype, &term)
595 set ttytype=xterm
596 call assert_equal('xterm', &ttytype)
597 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200598 try
599 set ttytype=
600 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100601 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200602 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200603
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200604 " Some systems accept any terminal name and return dumb settings,
605 " check for failure of finding the entry and for missing 'cm' entry.
606 try
607 set ttytype=xxx
608 call assert_report('set ttytype=xxx did not fail')
609 catch /E522\|E437/
610 endtry
611
612 set ttytype&
613 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200614
615 if has('gui') && !has('gui_running')
616 call assert_fails('set term=gui', 'E531:')
617 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100618endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100619
620func Test_set_all()
621 set tw=75
622 set iskeyword=a-z,A-Z
623 set nosplitbelow
624 let out = execute('set all')
625 call assert_match('textwidth=75', out)
626 call assert_match('iskeyword=a-z,A-Z', out)
627 call assert_match('nosplitbelow', out)
628 set tw& iskeyword& splitbelow&
629endfunc
630
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100631func Test_set_one_column()
632 let out_mult = execute('set all')->split("\n")
633 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100634 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100635endfunc
636
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100637func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200638 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100639 if filereadable('opt_test.vim')
640 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100641 else
642 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100643 endif
644endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200645
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100646func Test_renderoptions()
647 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
648 " Doesn't hurt to do this on a non-Windows system.
649 if windowsversion() !~ '^[345]\.'
650 set renderoptions=type:directx
651 set rop=type:directx
652 endif
653endfunc
654
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200655func ResetIndentexpr()
656 set indentexpr=
657endfunc
658
659func Test_set_indentexpr()
660 " this was causing usage of freed memory
661 set indentexpr=ResetIndentexpr()
662 new
663 call feedkeys("i\<c-f>", 'x')
664 call assert_equal('', &indentexpr)
665 bwipe!
666endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200667
668func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100669 " Option 'backupskip' may contain several comma-separated path
670 " specifications if one or more of the environment variables TMPDIR, TMP,
671 " or TEMP is defined. To simplify testing, convert the string value into a
672 " list.
673 let bsklist = split(&bsk, ',')
674
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200675 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100676 let found = (index(bsklist, '/private/tmp/*') >= 0)
677 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200678 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100679 let found = (index(bsklist, '/tmp/*') >= 0)
680 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200681 endif
682
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100683 " If our test platform is Windows, the path(s) in option bsk will use
684 " backslash for the path separator and the components could be in short
685 " (8.3) format. As such, we need to replace the backslashes with forward
686 " slashes and convert the path components to long format. The expand()
687 " function will do this but it cannot handle comma-separated paths. This is
688 " why bsk was converted from a string into a list of strings above.
689 "
690 " One final complication is that the wildcard "/*" is at the end of each
691 " path and so expand() might return a list of matching files. To prevent
692 " this, we need to remove the wildcard before calling expand() and then
693 " append it afterwards.
694 if has('win32')
695 let item_nbr = 0
696 while item_nbr < len(bsklist)
697 let path_spec = bsklist[item_nbr]
698 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
699 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
700 let bsklist[item_nbr] = path_spec . '/*'
701 let item_nbr += 1
702 endwhile
703 endif
704
705 " Option bsk will also include these environment variables if defined.
706 " If they're defined, verify they appear in the option value.
707 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200708 if exists(var)
709 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100710 let varvalue = substitute(varvalue, '/$', '', '')
711 let varvalue .= '/*'
712 let found = (index(bsklist, varvalue) >= 0)
713 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200714 endif
715 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200716
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200717 " Duplicates from environment variables should be filtered out (option has
718 " P_NODUP). Run this in a separate instance and write v:errors in a file,
719 " so that we see what happens on startup.
720 let after =<< trim [CODE]
721 let bsklist = split(&backupskip, ',')
722 call assert_equal(uniq(copy(bsklist)), bsklist)
723 call writefile(['errors:'] + v:errors, 'Xtestout')
724 qall
725 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100726 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200727 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
728
729 let saveenv = {}
730 for var in ['TMPDIR', 'TMP', 'TEMP']
731 let saveenv[var] = getenv(var)
732 call setenv(var, '/duplicate/path')
733 endfor
734
735 exe 'silent !' . cmd
736 call assert_equal(['errors:'], readfile('Xtestout'))
737
738 " restore environment variables
739 for var in ['TMPDIR', 'TMP', 'TEMP']
740 call setenv(var, saveenv[var])
741 endfor
742
743 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200744
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200745 " Duplicates should be filtered out (option has P_NODUP)
746 let backupskip = &backupskip
747 set backupskip=
748 set backupskip+=/test/dir
749 set backupskip+=/other/dir
750 set backupskip+=/test/dir
751 call assert_equal('/test/dir,/other/dir', &backupskip)
752 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200753endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200754
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100755func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200756 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200757
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200758 " Test copy option from current buffer in window
759 split
760 enew
761 setlocal numberwidth=5
762 wincmd w
763 call assert_equal(4,&numberwidth)
764 bnext
765 call assert_equal(5,&numberwidth)
766 bw!
767 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200768
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200769 " Test copy value from window that used to be display the buffer
770 split
771 enew
772 setlocal numberwidth=6
773 bnext
774 wincmd w
775 call assert_equal(4,&numberwidth)
776 bnext
777 call assert_equal(6,&numberwidth)
778 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200779
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200780 " Test that if buffer is current, don't use the stale cached value
781 " from the last time the buffer was displayed.
782 split
783 enew
784 setlocal numberwidth=7
785 bnext
786 bnext
787 setlocal numberwidth=8
788 wincmd w
789 call assert_equal(4,&numberwidth)
790 bnext
791 call assert_equal(8,&numberwidth)
792 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200793
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200794 " Test value is not copied if window already has seen the buffer
795 enew
796 split
797 setlocal numberwidth=9
798 bnext
799 setlocal numberwidth=10
800 wincmd w
801 call assert_equal(4,&numberwidth)
802 bnext
803 call assert_equal(4,&numberwidth)
804 bw!
805
806 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200807endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200808
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +0100809def Test_split_copy_options()
810 var values = [
811 ['cursorbind', true, false],
812 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
813 ['list', true, 0],
814 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
815 ['number', true, 0],
816 ['relativenumber', true, false],
817 ['scrollbind', true, false],
818 ['smoothscroll', true, false],
819 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
820 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
821 ['wrap', false, true],
822 ]
823 if has('linebreak')
824 values += [
825 ['breakindent', true, false],
826 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
827 ['linebreak', true, false],
828 ['numberwidth', 7, 4],
829 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
830 ]
831 endif
832 if has('rightleft')
833 values += [
834 ['rightleft', true, false],
835 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
836 ]
837 endif
838 if has('statusline')
839 values += [
840 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
841 ]
842 endif
843 if has('spell')
844 values += [
845 ['spell', true, false],
846 ]
847 endif
848 if has('syntax')
849 values += [
850 ['cursorcolumn', true, false],
851 ['cursorline', true, false],
852 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
853 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
854 ]
855 endif
856 if has('diff')
857 values += [
858 ['diff', true, false],
859 ]
860 endif
861 if has('conceal')
862 values += [
863 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
864 ['conceallevel', '3', &conceallevel],
865 ]
866 endif
867 if has('terminal')
868 values += [
869 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
870 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
871 ]
872 endif
873 if has('folding')
874 values += [
875 ['foldcolumn', 5, &foldcolumn],
876 ['foldenable', false, true],
877 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
878 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
879 ['foldlevel', 4, &foldlevel],
880 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
881 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
882 ['foldminlines', 3, &foldminlines],
883 ['foldnestmax', 17, &foldnestmax],
884 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
885 ]
886 endif
887 if has('signs')
888 values += [
889 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
890 ]
891 endif
892
893 # set options to non-default value
894 for item in values
895 exe $'&l:{item[0]} = {item[1]}'
896 endfor
897
898 # check values are set in new window
899 split
900 for item in values
901 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
902 endfor
903
904 # restore
905 close
906 for item in values
907 exe $'&l:{item[0]} = {item[2]}'
908 endfor
909enddef
910
Bram Moolenaarfc089602018-06-24 16:53:35 +0200911func Test_shortmess_F()
912 new
913 call assert_match('\[No Name\]', execute('file'))
914 set shortmess+=F
915 call assert_match('\[No Name\]', execute('file'))
916 call assert_match('^\s*$', execute('file foo'))
917 call assert_match('foo', execute('file'))
918 set shortmess-=F
919 call assert_match('bar', execute('file bar'))
920 call assert_match('bar', execute('file'))
921 set shortmess&
922 bwipe
923endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200924
925func Test_shortmess_F2()
926 e file1
927 e file2
928 call assert_match('file1', execute('bn', ''))
929 call assert_match('file2', execute('bn', ''))
930 set shortmess+=F
931 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200932 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200933 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200934 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200935 set hidden
936 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200937 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200938 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200939 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200940 set nohidden
941 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200942 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200943 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200944 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200945 set shortmess&
946 call assert_match('file1', execute('bn', ''))
947 call assert_match('file2', execute('bn', ''))
948 bwipe
949 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +0100950 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200951endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100952
953func Test_local_scrolloff()
954 set so=5
955 set siso=7
956 split
957 call assert_equal(5, &so)
958 setlocal so=3
959 call assert_equal(3, &so)
960 wincmd w
961 call assert_equal(5, &so)
962 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100963 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100964 setlocal so<
965 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100966 setglob so=8
967 call assert_equal(8, &so)
968 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100969 setlocal so=0
970 call assert_equal(0, &so)
971 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100972 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100973
974 call assert_equal(7, &siso)
975 setlocal siso=3
976 call assert_equal(3, &siso)
977 wincmd w
978 call assert_equal(7, &siso)
979 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100980 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100981 setlocal siso<
982 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100983 setglob siso=4
984 call assert_equal(4, &siso)
985 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100986 setlocal siso=0
987 call assert_equal(0, &siso)
988 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +0100989 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100990
991 close
992 set so&
993 set siso&
994endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200995
996func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100997 CheckFunction reltimefloat
998
Bram Moolenaar449ac472019-04-03 21:42:35 +0200999 new
1000 call setline(1, 'empty')
1001 redraw
1002 set writedelay=10
1003 let start = reltime()
1004 call setline(1, repeat('x', 70))
1005 redraw
1006 let elapsed = reltimefloat(reltime(start))
1007 set writedelay=0
1008 " With 'writedelay' set should take at least 30 * 10 msec
1009 call assert_inrange(30 * 0.01, 999.0, elapsed)
1010
1011 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001012endfunc
1013
1014func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001015 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001016 set visualbell
1017 call assert_beeps('normal 0h')
1018 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001019 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001020endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001021
1022" Test for the 'write' option
1023func Test_write()
1024 new
1025 call setline(1, ['L1'])
1026 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001027 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001028 set write
1029 close!
1030endfunc
1031
1032" Test for 'buftype' option
1033func Test_buftype()
1034 new
1035 call setline(1, ['L1'])
1036 set buftype=nowrite
1037 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001038
1039 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1040 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001041 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001042 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1043 endfor
1044
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001045 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001046endfunc
1047
Bram Moolenaar578fe942020-02-27 21:32:51 +01001048" Test for the 'rightleftcmd' option
1049func Test_rightleftcmd()
1050 CheckFeature rightleft
1051 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001052
1053 let g:l = []
1054 func AddPos()
1055 call add(g:l, screencol())
1056 return ''
1057 endfunc
1058 cmap <expr> <F2> AddPos()
1059
zeertzjqbb404f52022-07-23 06:25:29 +01001060 set rightleftcmd=
1061 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1062 \ "\<Right>\<F2>\<Esc>", 'xt')
1063 call assert_equal([2, 5, 3, 4], g:l)
1064
1065 let g:l = []
1066 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001067 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1068 \ "\<Left>\<F2>\<Esc>", 'xt')
1069 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1070
1071 cunmap <F2>
1072 unlet g:l
1073 set rightleftcmd&
1074 set rightleft&
1075endfunc
1076
zeertzjq28c162f2022-08-14 14:49:50 +01001077" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001078func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001079 " redraw to avoid matching previous messages
1080 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001081 set debug=beep
1082 exe "normal \<C-c>"
1083 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001084 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001085 " also check a line above, with a certain window width the colon is there
1086 call assert_match('Test_debug_option:$',
1087 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001088 set debug&
1089endfunc
1090
Bram Moolenaar004a6782020-04-11 17:09:31 +02001091" Test for the default CDPATH option
1092func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001093 let after =<< trim [CODE]
1094 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1095 call writefile(v:errors, 'Xtestout')
1096 qall
1097 [CODE]
1098 if has('unix')
1099 let $CDPATH='/path/to/dir1:/path/to/dir2'
1100 else
1101 let $CDPATH='/path/to/dir1;/path/to/dir2'
1102 endif
1103 if RunVim([], after, '')
1104 call assert_equal([], readfile('Xtestout'))
1105 call delete('Xtestout')
1106 endif
1107endfunc
1108
1109" Test for setting keycodes using set
1110func Test_opt_set_keycode()
1111 call assert_fails('set <t_k1=l', 'E474:')
1112 call assert_fails('set <Home=l', 'E474:')
1113 set <t_k9>=abcd
1114 call assert_equal('abcd', &t_k9)
1115 set <t_k9>&
1116 set <F9>=xyz
1117 call assert_equal('xyz', &t_k9)
1118 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001119
1120 " should we test all of them?
1121 set t_Ce=testCe
1122 set t_Cs=testCs
1123 set t_Us=testUs
1124 set t_ds=testds
1125 set t_Ds=testDs
1126 call assert_equal('testCe', &t_Ce)
1127 call assert_equal('testCs', &t_Cs)
1128 call assert_equal('testUs', &t_Us)
1129 call assert_equal('testds', &t_ds)
1130 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001131endfunc
1132
1133" Test for changing options in a sandbox
1134func Test_opt_sandbox()
1135 for opt in ['backupdir', 'cdpath', 'exrc']
1136 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001137 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001138 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001139 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001140endfunc
1141
1142" Test for setting an option with local value to global value
1143func Test_opt_local_to_global()
1144 setglobal equalprg=gprg
1145 setlocal equalprg=lprg
1146 call assert_equal('gprg', &g:equalprg)
1147 call assert_equal('lprg', &l:equalprg)
1148 call assert_equal('lprg', &equalprg)
1149 set equalprg<
1150 call assert_equal('', &l:equalprg)
1151 call assert_equal('gprg', &equalprg)
1152 setglobal equalprg=gnewprg
1153 setlocal equalprg=lnewprg
1154 setlocal equalprg<
1155 call assert_equal('gnewprg', &l:equalprg)
1156 call assert_equal('gnewprg', &equalprg)
1157 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001158
1159 " Test for setting the global/local value of a boolean option
1160 setglobal autoread
1161 setlocal noautoread
1162 call assert_false(&autoread)
1163 set autoread<
1164 call assert_true(&autoread)
1165 setglobal noautoread
1166 setlocal autoread
1167 setlocal autoread<
1168 call assert_false(&autoread)
1169 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001170endfunc
1171
Dominique Pelle042414f2021-07-12 21:43:19 +02001172func Test_set_in_sandbox()
1173 " Some boolean options cannot be set in sandbox, some can.
1174 call assert_fails('sandbox set modelineexpr', 'E48:')
1175 sandbox set number
1176 call assert_true(&number)
1177 set number&
1178
1179 " Some boolean options cannot be set in sandbox, some can.
1180 if has('python') || has('python3')
1181 call assert_fails('sandbox set pyxversion=3', 'E48:')
1182 endif
1183 sandbox set tabstop=4
1184 call assert_equal(4, &tabstop)
1185 set tabstop&
1186
1187 " Some string options cannot be set in sandbox, some can.
1188 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1189 sandbox set filetype=perl
1190 call assert_equal('perl', &filetype)
1191 set filetype&
1192endfunc
1193
Bram Moolenaar004a6782020-04-11 17:09:31 +02001194" Test for incrementing, decrementing and multiplying a number option value
1195func Test_opt_num_op()
1196 set shiftwidth=4
1197 set sw+=2
1198 call assert_equal(6, &sw)
1199 set sw-=2
1200 call assert_equal(4, &sw)
1201 set sw^=2
1202 call assert_equal(8, &sw)
1203 set shiftwidth&
1204endfunc
1205
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001206" Test for setting option values using v:false and v:true
1207func Test_opt_boolean()
1208 set number&
1209 set number
1210 call assert_equal(1, &nu)
1211 set nonu
1212 call assert_equal(0, &nu)
1213 let &nu = v:true
1214 call assert_equal(1, &nu)
1215 let &nu = v:false
1216 call assert_equal(0, &nu)
1217 set number&
1218endfunc
1219
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001220" Test for the 'window' option
1221func Test_window_opt()
1222 " Needs only one open widow
1223 %bw!
1224 call setline(1, range(1, 8))
1225 set window=5
1226 exe "normal \<C-F>"
1227 call assert_equal(4, line('w0'))
1228 exe "normal \<C-F>"
1229 call assert_equal(7, line('w0'))
1230 exe "normal \<C-F>"
1231 call assert_equal(8, line('w0'))
1232 exe "normal \<C-B>"
1233 call assert_equal(5, line('w0'))
1234 exe "normal \<C-B>"
1235 call assert_equal(2, line('w0'))
1236 exe "normal \<C-B>"
1237 call assert_equal(1, line('w0'))
1238 set window=1
1239 exe "normal gg\<C-F>"
1240 call assert_equal(2, line('w0'))
1241 exe "normal \<C-F>"
1242 call assert_equal(3, line('w0'))
1243 exe "normal \<C-B>"
1244 call assert_equal(2, line('w0'))
1245 exe "normal \<C-B>"
1246 call assert_equal(1, line('w0'))
1247 enew!
1248 set window&
1249endfunc
1250
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001251" Test for the 'winminheight' option
1252func Test_opt_winminheight()
1253 only!
1254 let &winheight = &lines + 4
1255 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1256 call assert_true(&winminheight <= &lines)
1257 set winminheight&
1258 set winheight&
1259endfunc
1260
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001261func Test_opt_winminheight_term()
1262 CheckRunVimInTerminal
1263
1264 " The tabline should be taken into account.
1265 let lines =<< trim END
1266 set wmh=0 stal=2
1267 below sp | wincmd _
1268 below sp | wincmd _
1269 below sp | wincmd _
1270 below sp
1271 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001272 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001273 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1274 call term_sendkeys(buf, ":set wmh=1\n")
1275 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1276
1277 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001278endfunc
1279
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001280func Test_opt_winminheight_term_tabs()
1281 CheckRunVimInTerminal
1282
1283 " The tabline should be taken into account.
1284 let lines =<< trim END
1285 set wmh=0 stal=2
1286 split
1287 split
1288 split
1289 split
1290 tabnew
1291 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001292 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001293 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1294 call term_sendkeys(buf, ":set wmh=1\n")
1295 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1296
1297 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001298endfunc
1299
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001300" Test for the 'winminwidth' option
1301func Test_opt_winminwidth()
1302 only!
1303 let &winwidth = &columns + 4
1304 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1305 call assert_true(&winminwidth <= &columns)
1306 set winminwidth&
1307 set winwidth&
1308endfunc
1309
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001310" Test for setting option value containing spaces with isfname+=32
1311func Test_isfname_with_options()
1312 set isfname+=32
1313 setlocal keywordprg=:term\ help.exe
1314 call assert_equal(':term help.exe', &keywordprg)
1315 set isfname&
1316 setlocal keywordprg&
1317endfunc
1318
Bram Moolenaar74667062020-12-28 15:41:41 +01001319" Test that resetting laststatus does change scroll option
1320func Test_opt_reset_scroll()
1321 CheckRunVimInTerminal
1322 let vimrc =<< trim [CODE]
1323 set scroll=2
1324 set laststatus=2
1325 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001326 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001327 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1328 call term_sendkeys(buf, ":verbose set scroll?\n")
1329 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1330 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001331
1332 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001333 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001334endfunc
1335
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001336" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1337func Test_VIM_POSIX()
1338 let saved_VIM_POSIX = getenv("VIM_POSIX")
1339
1340 call setenv('VIM_POSIX', "1")
1341 let after =<< trim [CODE]
1342 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1343 qall
1344 [CODE]
1345 if RunVim([], after, '')
1346 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1347 \ 'AS'], readfile('X_VIM_POSIX'))
1348 endif
1349
1350 call setenv('VIM_POSIX', v:null)
1351 let after =<< trim [CODE]
1352 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1353 qall
1354 [CODE]
1355 if RunVim([], after, '')
1356 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1357 \ 'S'], readfile('X_VIM_POSIX'))
1358 endif
1359
1360 call delete('X_VIM_POSIX')
1361 call setenv('VIM_POSIX', saved_VIM_POSIX)
1362endfunc
1363
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001364" Test for setting an option to a Vi or Vim default
1365func Test_opt_default()
1366 set formatoptions&vi
1367 call assert_equal('vt', &formatoptions)
1368 set formatoptions&vim
1369 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001370
1371 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1372 set fencs=latin1
1373 set fencs&
1374 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1375 set fencs=latin1
1376 set all&
1377 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001378endfunc
1379
1380" Test for the 'cmdheight' option
1381func Test_cmdheight()
1382 %bw!
1383 let ht = &lines
1384 set cmdheight=9999
1385 call assert_equal(1, winheight(0))
1386 call assert_equal(ht - 1, &cmdheight)
1387 set cmdheight&
1388endfunc
1389
Dominique Pelle923dce22021-11-21 11:36:04 +00001390" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001391func Test_opt_control_char()
1392 set wildchar=^v
1393 call assert_equal("\<C-V>", nr2char(&wildchar))
1394 set wildcharm=^r
1395 call assert_equal("\<C-R>", nr2char(&wildcharm))
1396 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1397 set wildchar& wildcharm&
1398endfunc
1399
1400" Test for the 'errorbells' option
1401func Test_opt_errorbells()
1402 set errorbells
1403 call assert_beeps('s/a1b2/x1y2/')
1404 set noerrorbells
1405endfunc
1406
Dominique Pelle042414f2021-07-12 21:43:19 +02001407func Test_opt_scrolljump()
1408 help
1409 resize 10
1410
1411 " Test with positive 'scrolljump'.
1412 set scrolljump=2
1413 norm! Lj
1414 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1415 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1416 \ winsaveview())
1417
1418 " Test with negative 'scrolljump' (percentage of window height).
1419 set scrolljump=-40
1420 norm! ggLj
1421 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1422 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1423 \ winsaveview())
1424
1425 set scrolljump&
1426 bw
1427endfunc
1428
Bakudankun29f3a452021-12-11 12:28:08 +00001429" Test for the 'cdhome' option
1430func Test_opt_cdhome()
1431 if has('unix') || has('vms')
1432 throw 'Skipped: only works on non-Unix'
1433 endif
1434
1435 set cdhome&
1436 call assert_equal(0, &cdhome)
1437 set cdhome
1438
1439 " This paragraph is copied from Test_cd_no_arg().
1440 let path = getcwd()
1441 cd
1442 call assert_equal($HOME, getcwd())
1443 call assert_notequal(path, getcwd())
1444 exe 'cd ' .. fnameescape(path)
1445 call assert_equal(path, getcwd())
1446
1447 set cdhome&
1448endfunc
1449
Christian Brabandtcb747892022-05-08 21:10:56 +01001450func Test_set_completion_2()
1451 CheckOption termguicolors
1452
1453 " Test default option completion
1454 set wildoptions=
1455 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1456 call assert_equal('"set termguicolors', @:)
1457
1458 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1459 call assert_equal('"set notermguicolors', @:)
1460
1461 " Test fuzzy option completion
1462 set wildoptions=fuzzy
1463 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1464 call assert_equal('"set termguicolors termencoding', @:)
1465
1466 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1467 call assert_equal('"set notermguicolors', @:)
1468
1469 set wildoptions=
1470endfunc
1471
Sean Dewar39c46b42022-05-12 17:44:29 +01001472func Test_switchbuf_reset()
1473 set switchbuf=useopen
1474 sblast
1475 call assert_equal(1, winnr('$'))
1476 set all&
1477 call assert_equal('', &switchbuf)
1478 sblast
1479 call assert_equal(2, winnr('$'))
1480 only!
1481endfunc
1482
zeertzjqfcba86c2022-09-22 13:57:32 +01001483" :set empty string for global 'keywordprg' falls back to ":help"
1484func Test_keywordprg_empty()
1485 let k = &keywordprg
1486 set keywordprg=man
1487 call assert_equal('man', &keywordprg)
1488 set keywordprg=
1489 call assert_equal(':help', &keywordprg)
1490 set keywordprg=man
1491 call assert_equal('man', &keywordprg)
1492 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1493 let &keywordprg = k
1494endfunc
1495
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001496" check that the very first buffer created does not have 'endoffile' set
1497func Test_endoffile_default()
1498 let after =<< trim [CODE]
1499 call writefile([execute('set eof?')], 'Xtestout')
1500 qall!
1501 [CODE]
1502 if RunVim([], after, '')
1503 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1504 endif
1505 call delete('Xtestout')
1506endfunc
1507
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001508" Test for setting the 'lines' and 'columns' options to a minimum value
1509func Test_set_min_lines_columns()
1510 let save_lines = &lines
1511 let save_columns = &columns
1512
1513 let after =<< trim END
1514 set nomore
1515 let msg = []
1516 let v:errmsg = ''
1517 silent! let &columns=0
1518 call add(msg, v:errmsg)
1519 silent! set columns=0
1520 call add(msg, v:errmsg)
1521 silent! call setbufvar('', '&columns', 0)
1522 call add(msg, v:errmsg)
1523 "call writefile(msg, 'XResultsetminlines')
1524 silent! let &lines=0
1525 call add(msg, v:errmsg)
1526 silent! set lines=0
1527 call add(msg, v:errmsg)
1528 silent! call setbufvar('', '&lines', 0)
1529 call add(msg, v:errmsg)
1530 call writefile(msg, 'XResultsetminlines')
1531 qall!
1532 END
1533 if RunVim([], after, '')
1534 call assert_equal(['E594: Need at least 12 columns',
1535 \ 'E594: Need at least 12 columns: columns=0',
1536 \ 'E594: Need at least 12 columns',
1537 \ 'E593: Need at least 2 lines',
1538 \ 'E593: Need at least 2 lines: lines=0',
1539 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1540 endif
1541
1542 call delete('XResultsetminlines')
1543 let &lines = save_lines
1544 let &columns = save_columns
1545endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001546
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001547" Test for reverting a string option value if the new value is invalid.
1548func Test_string_option_revert_on_failure()
1549 new
1550 let optlist = [
1551 \ ['ambiwidth', 'double', 'a123'],
1552 \ ['background', 'dark', 'a123'],
1553 \ ['backspace', 'eol', 'a123'],
1554 \ ['backupcopy', 'no', 'a123'],
1555 \ ['belloff', 'showmatch', 'a123'],
1556 \ ['breakindentopt', 'min:10', 'list'],
1557 \ ['bufhidden', 'wipe', 'a123'],
1558 \ ['buftype', 'nowrite', 'a123'],
1559 \ ['casemap', 'keepascii', 'a123'],
1560 \ ['cedit', "\<C-Y>", 'z'],
1561 \ ['colorcolumn', '10', 'z'],
1562 \ ['commentstring', '#%s', 'a123'],
1563 \ ['complete', '.,t', 'a'],
1564 \ ['completefunc', 'MyCmplFunc', '1a-'],
1565 \ ['completeopt', 'popup', 'a123'],
1566 \ ['completepopup', 'width:20', 'border'],
1567 \ ['concealcursor', 'v', 'xyz'],
1568 \ ['cpoptions', 'HJ', '~'],
1569 \ ['cryptmethod', 'zip', 'a123'],
1570 \ ['cursorlineopt', 'screenline', 'a123'],
1571 \ ['debug', 'throw', 'a123'],
1572 \ ['diffopt', 'iwhite', 'a123'],
1573 \ ['display', 'uhex', 'a123'],
1574 \ ['eadirection', 'hor', 'a123'],
1575 \ ['encoding', 'utf-8', 'a123'],
1576 \ ['eventignore', 'TextYankPost', 'a123'],
1577 \ ['fileencoding', 'utf-8', 'a123,'],
1578 \ ['fileformat', 'mac', 'a123'],
1579 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001580 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001581 \ ['fillchars', 'diff:~', 'a123'],
1582 \ ['foldclose', 'all', 'a123'],
1583 \ ['foldmarker', '[[[,]]]', '[[['],
1584 \ ['foldmethod', 'marker', 'a123'],
1585 \ ['foldopen', 'percent', 'a123'],
1586 \ ['formatoptions', 'an', '*'],
1587 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1588 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001589 \ ['highlight', '!:CursorColumn', '8:'],
1590 \ ['keymodel', 'stopsel', 'a123'],
1591 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1592 \ ['lispoptions', 'expr:1', 'a123'],
1593 \ ['listchars', 'tab:->', 'tab:'],
1594 \ ['matchpairs', '<:>', '<:'],
1595 \ ['mkspellmem', '100000,1000,100', '100000'],
1596 \ ['mouse', 'nvi', 'z'],
1597 \ ['mousemodel', 'extend', 'a123'],
1598 \ ['nrformats', 'alpha', 'a123'],
1599 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1600 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1601 \ ['previewpopup', 'width:20', 'a123'],
1602 \ ['printoptions', 'paper:A4', 'a123:'],
1603 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1604 \ ['rulerformat', '%l', '%['],
1605 \ ['scrollopt', 'hor,jump', 'a123'],
1606 \ ['selection', 'exclusive', 'a123'],
1607 \ ['selectmode', 'cmd', 'a123'],
1608 \ ['sessionoptions', 'options', 'a123'],
1609 \ ['shortmess', 'w', '2'],
1610 \ ['showbreak', '>>', "\x01"],
1611 \ ['showcmdloc', 'statusline', 'a123'],
1612 \ ['signcolumn', 'no', 'a123'],
1613 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1614 \ ['spellfile', 'MySpell.en.add', "\x01"],
1615 \ ['spelllang', 'en', "#"],
1616 \ ['spelloptions', 'camel', 'a123'],
1617 \ ['spellsuggest', 'double', 'a123'],
1618 \ ['splitkeep', 'topline', 'a123'],
1619 \ ['statusline', '%f', '%['],
1620 \ ['swapsync', 'sync', 'a123'],
1621 \ ['switchbuf', 'usetab', 'a123'],
1622 \ ['syntax', 'abc', 'a^b'],
1623 \ ['tabline', '%f', '%['],
1624 \ ['tagcase', 'ignore', 'a123'],
1625 \ ['tagfunc', 'MyTagFunc', '1a-'],
1626 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1627 \ ['viewoptions', 'options', 'a123'],
1628 \ ['virtualedit', 'onemore', 'a123'],
1629 \ ['whichwrap', '<,>', '{,}'],
1630 \ ['wildmode', 'list', 'a123'],
1631 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001632 \ ]
1633 if has('gui')
1634 call add(optlist, ['browsedir', 'buffer', 'a123'])
1635 endif
1636 if has('clipboard_working')
1637 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1638 endif
1639 if has('win32')
1640 call add(optlist, ['completeslash', 'slash', 'a123'])
1641 endif
1642 if has('cscope')
1643 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1644 endif
1645 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001646 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1647 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1648 endif
1649 if has('keymap')
1650 call add(optlist, ['keymap', 'greek', '[]'])
1651 endif
1652 if has('mouseshape')
1653 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1654 endif
1655 if has('win32') && has('gui')
1656 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1657 endif
1658 if has('rightleft')
1659 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1660 endif
1661 if has('terminal')
1662 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1663 call add(optlist, ['termwinsize', '24x80', '100'])
1664 endif
1665 if has('win32') && has('terminal')
1666 call add(optlist, ['termwintype', 'winpty', 'a123'])
1667 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001668 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001669 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001670 endif
1671 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001672 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1673 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001674 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001675 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1676 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001677 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001678 call add(optlist, ['varsofttabstop', '12', 'a123'])
1679 call add(optlist, ['vartabstop', '4,20', '4,'])
1680 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001681 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001682 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001683 endif
1684 for opt in optlist
1685 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001686 try
1687 exe $"let &{opt[0]} = '{opt[1]}'"
1688 catch
1689 call assert_report($"Caught {v:exception} with {opt->string()}")
1690 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001691 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1692 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1693 exe $"let &{opt[0]} = save_opt"
1694 endfor
1695 bw!
1696endfunc
1697
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02001698func Test_set_option_window_global_local()
1699 new Xbuffer1
1700 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
1701 setlocal scrolloff=2
1702 setglobal scrolloff=3
1703 setl modified
1704 " A new buffer has its own window-local options
1705 hide enew
1706 call assert_equal(-1, &l:scrolloff)
1707 call assert_equal(3, &g:scrolloff)
1708 " A new window opened with its own buffer-local options
1709 new
1710 call assert_equal(-1, &l:scrolloff)
1711 call assert_equal(3, &g:scrolloff)
1712 " Re-open Xbuffer1 and it should use
1713 " the previous set window-local options
1714 b Xbuffer1
1715 call assert_equal(2, &l:scrolloff)
1716 call assert_equal(3, &g:scrolloff)
1717 bw!
1718 bw!
1719 let &g:scrolloff = _gso
1720endfunc
1721
1722func GetGlobalLocalWindowOptions()
1723 new
1724 sil! r $VIMRUNTIME/doc/options.txt
1725 " Filter for global or local to window
1726 v/^'.*'.*\n.*global or local to window |global-local/d
1727 " get option value and type
1728 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
1729 sil %s/empty/""/g
1730 " split the result
1731 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
1732 bw!
1733 return result
1734endfunc
1735
1736func Test_set_option_window_global_local_all()
1737 new Xbuffer2
1738
1739 let optionlist = GetGlobalLocalWindowOptions()
1740 for [opt, type, default] in optionlist
1741 let _old = eval('&g:' .. opt)
1742 if type == 'string'
1743 if opt == 'fillchars'
1744 exe 'setl ' .. opt .. '=vert:+'
1745 exe 'setg ' .. opt .. '=vert:+,fold:+'
1746 elseif opt == 'listchars'
1747 exe 'setl ' .. opt .. '=tab:>>'
1748 exe 'setg ' .. opt .. '=tab:++'
1749 elseif opt == 'virtualedit'
1750 exe 'setl ' .. opt .. '=all'
1751 exe 'setg ' .. opt .. '=block'
1752 else
1753 exe 'setl ' .. opt .. '=Local'
1754 exe 'setg ' .. opt .. '=Global'
1755 endif
1756 elseif type == 'number'
1757 exe 'setl ' .. opt .. '=5'
1758 exe 'setg ' .. opt .. '=10'
1759 endif
1760 setl modified
1761 hide enew
1762 if type == 'string'
1763 call assert_equal('', eval('&l:' .. opt))
1764 if opt == 'fillchars'
1765 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
1766 elseif opt == 'listchars'
1767 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
1768 elseif opt == 'virtualedit'
1769 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
1770 else
1771 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
1772 endif
1773 elseif type == 'number'
1774 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
1775 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
1776 endif
1777 bw!
1778 exe 'let &g:' .. opt .. '=' .. default
1779 endfor
1780 bw!
1781endfunc
1782
Christian Brabandt757593c2023-08-22 21:44:10 +02001783func Test_paste_depending_options()
1784 " setting the paste option, resets all dependent options
1785 " and will be reported correctly using :verbose set <option>?
1786 let lines =<< trim [CODE]
1787 " set paste test
1788 set autoindent
1789 set expandtab
1790 " disabled, because depends on compiled feature set
1791 " set hkmap
1792 " set revins
1793 " set varsofttabstop=8,32,8
1794 set ruler
1795 set showmatch
1796 set smarttab
1797 set softtabstop=4
1798 set textwidth=80
1799 set wrapmargin=10
1800
1801 source Xvimrc_paste2
1802
1803 redir > Xoutput_paste
1804 verbose set expandtab?
1805 verbose setg expandtab?
1806 verbose setl expandtab?
1807 redir END
1808
1809 qall!
1810 [CODE]
1811
1812 call writefile(lines, 'Xvimrc_paste', 'D')
1813 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
1814 if !RunVim([], lines, '--clean')
1815 return
1816 endif
1817
1818 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
1819 call assert_equal('noexpandtab', result[0])
1820 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
1821 call assert_equal('noexpandtab', result[2])
1822 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
1823 call assert_equal('noexpandtab', result[4])
1824 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
1825
1826 call delete('Xoutput_paste')
1827endfunc
1828
1829func Test_binary_depending_options()
1830 " setting the paste option, resets all dependent options
1831 " and will be reported correctly using :verbose set <option>?
1832 let lines =<< trim [CODE]
1833 " set binary test
1834 set expandtab
1835
1836 source Xvimrc_bin2
1837
1838 redir > Xoutput_bin
1839 verbose set expandtab?
1840 verbose setg expandtab?
1841 verbose setl expandtab?
1842 redir END
1843
1844 qall!
1845 [CODE]
1846
1847 call writefile(lines, 'Xvimrc_bin', 'D')
1848 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
1849 if !RunVim([], lines, '--clean')
1850 return
1851 endif
1852
1853 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
1854 call assert_equal('noexpandtab', result[0])
1855 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
1856 call assert_equal('noexpandtab', result[2])
1857 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
1858 call assert_equal('noexpandtab', result[4])
1859 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
1860
1861 call delete('Xoutput_bin')
1862endfunc
1863
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001864" vim: shiftwidth=2 sts=2 expandtab