blob: 32d4910ccb423d315c9d024d5baf33ee19549a41 [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
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200298 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
299 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100300
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200301 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
302 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100303
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'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200363 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
364 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
365 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
366 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200367
368 " Expand value for 'key'
369 set key=abcd
370 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
371 call assert_equal('"set key=*****', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200372 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
373 call assert_equal('"set key-=*****', @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200374 set key=
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100375
376 " Expand values for 'filetype'
377 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
378 call assert_equal('"set filetype=sshdconfig', @:)
379 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
380 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200381
382 " Expand values for 'syntax'
383 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
384 call assert_equal('"set syntax=sshdconfig', @:)
385 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
386 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100387endfunc
388
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200389" Test handling of expanding individual string option values
390func Test_set_completion_string_values()
391 "
392 " Test basic enum string options that have well-defined enum names
393 "
394
395 call assert_equal(getcompletion('set display=', 'cmdline'), ['lastline', 'truncate', 'uhex'])
396 call assert_equal(getcompletion('set display=t', 'cmdline'), ['truncate'])
397 call assert_equal(getcompletion('set display=*ex*', 'cmdline'), ['uhex'])
398
399 " Test that if a value is set, it will populate the results, but only if
400 " typed value is empty.
401 set display=uhex,lastline
402 call assert_equal(getcompletion('set display=', 'cmdline'), ['uhex,lastline', 'lastline', 'truncate', 'uhex'])
403 call assert_equal(getcompletion('set display=u', 'cmdline'), ['uhex'])
404 " If the set value is part of the enum list, it will show as the first
405 " result with no duplicate.
406 set display=uhex
407 call assert_equal(getcompletion('set display=', 'cmdline'), ['uhex', 'lastline', 'truncate'])
408 " If empty value, will just show the normal list without an empty item
409 set display=
410 call assert_equal(getcompletion('set display=', 'cmdline'), ['lastline', 'truncate', 'uhex'])
411 " Test escaping of the values
412 call assert_equal(getcompletion('set fillchars=', 'cmdline')[0], 'vert:\|,fold:-,eob:~,lastline:@')
413
414 " Test comma-separated lists will expand after a comma.
415 call assert_equal(getcompletion('set display=truncate,*ex*', 'cmdline'), ['uhex'])
416 " Also test the positioning of the expansion is correct
417 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
418 call assert_equal('"set display=truncate,lastline', @:)
419 set display&
420
421 " Test single-value options will not expand after a comma
422 call assert_equal(getcompletion('set ambw=single,', 'cmdline'), [])
423
424 " Test the other simple options to make sure they have basic auto-complete,
425 " but don't exhaustively validate their results.
426 call assert_equal(getcompletion('set ambw=', 'cmdline')[0], 'single')
427 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
428 call assert_equal(getcompletion('set backspace=', 'cmdline')[0], 'indent')
429 call assert_equal(getcompletion('set backupcopy=', 'cmdline')[1], 'yes')
430 call assert_equal(getcompletion('set belloff=', 'cmdline')[1], 'backspace')
431 call assert_equal(getcompletion('set briopt=', 'cmdline')[1], 'min:')
432 if exists('+browsedir')
433 call assert_equal(getcompletion('set browsedir=', 'cmdline')[1], 'current')
434 endif
435 call assert_equal(getcompletion('set bufhidden=', 'cmdline')[1], 'unload')
436 call assert_equal(getcompletion('set buftype=', 'cmdline')[1], 'nowrite')
437 call assert_equal(getcompletion('set casemap=', 'cmdline')[1], 'internal')
438 if exists('+clipboard')
439 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
440 endif
441 call assert_equal(getcompletion('set complete=', 'cmdline')[1], '.')
442 call assert_equal(getcompletion('set completeopt=', 'cmdline')[1], 'menu')
443 if exists('+completeslash')
444 call assert_equal(getcompletion('set completeslash=', 'cmdline')[1], 'backslash')
445 endif
446 if exists('+cryptmethod')
447 call assert_equal(getcompletion('set cryptmethod=', 'cmdline')[1], 'zip')
448 endif
449 if exists('+cursorlineopt')
450 call assert_equal(getcompletion('set cursorlineopt=', 'cmdline')[1], 'line')
451 endif
452 call assert_equal(getcompletion('set debug=', 'cmdline')[1], 'throw')
453 call assert_equal(getcompletion('set eadirection=', 'cmdline')[1], 'ver')
454 call assert_equal(getcompletion('set fileformat=', 'cmdline')[2], 'mac')
455 if exists('+foldclose')
456 call assert_equal(getcompletion('set foldclose=', 'cmdline')[0], 'all')
457 endif
458 if exists('+foldmethod')
459 call assert_equal(getcompletion('set foldmethod=', 'cmdline')[1], 'expr')
460 endif
461 if exists('+foldopen')
462 call assert_equal(getcompletion('set foldopen=', 'cmdline')[1], 'all')
463 endif
464 call assert_equal(getcompletion('set jumpoptions=', 'cmdline')[0], 'stack')
465 call assert_equal(getcompletion('set keymodel=', 'cmdline')[1], 'stopsel')
466 call assert_equal(getcompletion('set lispoptions=', 'cmdline')[1], 'expr:1')
467 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
468 call assert_equal(getcompletion('set nrformats=', 'cmdline')[1], 'bin')
469 if exists('+rightleftcmd')
470 call assert_equal(getcompletion('set rightleftcmd=', 'cmdline')[0], 'search')
471 endif
472 call assert_equal(getcompletion('set scrollopt=', 'cmdline')[1], 'ver')
473 call assert_equal(getcompletion('set selection=', 'cmdline')[1], 'exclusive')
474 call assert_equal(getcompletion('set selectmode=', 'cmdline')[1], 'key')
475 if exists('+ssop')
476 call assert_equal(getcompletion('set ssop=', 'cmdline')[1], 'buffers')
477 endif
478 call assert_equal(getcompletion('set showcmdloc=', 'cmdline')[1], 'statusline')
479 if exists('+signcolumn')
480 call assert_equal(getcompletion('set signcolumn=', 'cmdline')[1], 'yes')
481 endif
482 if exists('+spelloptions')
483 call assert_equal(getcompletion('set spelloptions=', 'cmdline')[0], 'camel')
484 endif
485 if exists('+spellsuggest')
486 call assert_equal(getcompletion('set spellsuggest+=', 'cmdline')[0], 'best')
487 endif
488 call assert_equal(getcompletion('set splitkeep=', 'cmdline')[1], 'screen')
489 call assert_equal(getcompletion('set swapsync=', 'cmdline')[1], 'sync')
490 call assert_equal(getcompletion('set switchbuf=', 'cmdline')[1], 'usetab')
491 call assert_equal(getcompletion('set tagcase=', 'cmdline')[1], 'ignore')
492 if exists('+termwintype')
493 call assert_equal(getcompletion('set termwintype=', 'cmdline')[1], 'conpty')
494 endif
495 if exists('+toolbar')
496 call assert_equal(getcompletion('set toolbar=', 'cmdline')[1], 'text')
497 endif
498 if exists('+tbis')
499 call assert_equal(getcompletion('set tbis=', 'cmdline')[2], 'medium')
500 endif
501 if exists('+ttymouse')
502 set ttymouse=
503 call assert_equal(getcompletion('set ttymouse=', 'cmdline')[1], 'xterm2')
504 set ttymouse&
505 endif
506 call assert_equal(getcompletion('set virtualedit=', 'cmdline')[1], 'insert')
507 call assert_equal(getcompletion('set wildmode=', 'cmdline')[1], 'longest')
508 call assert_equal(getcompletion('set wildmode=list,longest:', 'cmdline')[0], 'full')
509 call assert_equal(getcompletion('set wildoptions=', 'cmdline')[1], 'tagfile')
510 if exists('+winaltkeys')
511 call assert_equal(getcompletion('set winaltkeys=', 'cmdline')[1], 'yes')
512 endif
513
514 " Other string options that queries the system rather than fixed enum names
515 call assert_equal(getcompletion('set eventignore=', 'cmdline')[0:1], ['all', 'BufAdd'])
516 call assert_equal(getcompletion('set fileencodings=', 'cmdline')[1], 'latin1')
517 call assert_equal(getcompletion('set printoptions=', 'cmdline')[0], 'top')
518 call assert_equal(getcompletion('set wincolor=', 'cmdline')[0], 'SpecialKey')
519
zeertzjq1f025b02023-09-30 12:43:07 +0200520 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
521 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
522 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
523 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
524 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
525 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200526
527 "
528 " Unique string options below
529 "
530
531 " keyprotocol: only auto-complete when after ':' with known protocol types
532 call assert_equal(getcompletion('set keyprotocol=', 'cmdline'), [&keyprotocol])
533 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
534 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
535 set keyprotocol&
536
537 " previewpopup / completepopup
538 call assert_equal(getcompletion('set previewpopup=', 'cmdline')[0], 'height:')
539 call assert_equal(getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0], 'EndOfBuffer')
540 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
541 call assert_equal('"set previewpopup+=border:on', @:)
542 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
543 call assert_equal('"set completepopup=height:10,align:item', @:)
544 call assert_equal(getcompletion('set completepopup=bogusname:', 'cmdline'), [])
545 set previewpopup& completepopup&
546
547 " diffopt: special handling of algorithm:<alg_list>
548 call assert_equal(getcompletion('set diffopt+=', 'cmdline')[0], 'filler')
549 call assert_equal(getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'), [])
550 call assert_equal(getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0], 'patience')
551
552 " highlight: special parsing, including auto-completing highlight groups
553 " after ':'
554 call assert_equal(getcompletion('set hl=', 'cmdline')[0:1], [&hl, '8'])
555 call assert_equal(getcompletion('set hl+=', 'cmdline')[0], '8')
556 call assert_equal(getcompletion('set hl+=8', 'cmdline')[0:2], ['8:', '8b', '8i'])
557 call assert_equal(getcompletion('set hl+=8b', 'cmdline')[0], '8bi')
558 call assert_equal(getcompletion('set hl+=8:No*ext', 'cmdline')[0], 'NonText')
559 " If all the display modes are used up we should be suggesting nothing. Make
560 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
561 " and make sure nothing is suggested from that.
562 let hl_display_modes = join(
563 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
564 \ {idx, val -> val[1]}),
565 \ {idx, val -> val != ':'}),
566 \ '')
567 call assert_equal(getcompletion('set hl+=8'..hl_display_modes, 'cmdline'), [])
568
569 "
570 " Test flag lists
571 "
572
573 " Test set=. Show the original value if nothing is typed after '='.
574 " Otherwise, the list should avoid showing what's already typed.
575 set mouse=v
576 call assert_equal(getcompletion('set mouse=', 'cmdline'), ['v','a','n','i','c','h','r'])
577 set mouse=nvi
578 call assert_equal(getcompletion('set mouse=', 'cmdline'), ['nvi','a','n','v','i','c','h','r'])
579 call assert_equal(getcompletion('set mouse=hn', 'cmdline'), ['a','v','i','c','r'])
580
581 " Test set+=. Never show original value, and it also tries to avoid listing
582 " flags that's already in the option value.
583 call assert_equal(getcompletion('set mouse+=', 'cmdline'), ['a','c','h','r'])
584 call assert_equal(getcompletion('set mouse+=hn', 'cmdline'), ['a','c','r'])
585 call assert_equal(getcompletion('set mouse+=acrhn', 'cmdline'), [])
586
587 " Test that the position of the expansion is correct (even if there are
588 " additional values after the current cursor)
589 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
590 call assert_equal('"set mouse=han', @:)
591 set mouse&
592
593 " Test that other flag list options have auto-complete, but don't
594 " exhaustively validate their results.
595 if exists('+concealcursor')
596 call assert_equal(getcompletion('set cocu=', 'cmdline')[0], 'n')
597 endif
598 call assert_equal(getcompletion('set cpo=', 'cmdline')[1], 'a')
599 call assert_equal(getcompletion('set fo=', 'cmdline')[1], 't')
600 if exists('+guioptions')
601 call assert_equal(getcompletion('set go=', 'cmdline')[1], '!')
602 endif
603 call assert_equal(getcompletion('set shortmess=', 'cmdline')[1], 'r')
604 call assert_equal(getcompletion('set whichwrap=', 'cmdline')[1], 'b')
605
606 "
607 "Test set-=
608 "
609
610 " Normal single-value option just shows the existing value
611 set ambiwidth=double
612 call assert_equal(getcompletion('set ambw-=', 'cmdline'), ['double'])
613 set ambiwidth&
614
615 " Works on numbers and term options as well
616 call assert_equal(getcompletion('set laststatus-=', 'cmdline'), [string(&laststatus)])
617 set t_Ce=testCe
618 call assert_equal(getcompletion('set t_Ce-=', 'cmdline'), ['testCe'])
619 set t_Ce&
620
621 " Comma-separated lists should present each option
622 set diffopt=context:123,,,,,iblank,iwhiteall
623 call assert_equal(getcompletion('set diffopt-=', 'cmdline'), ['context:123', 'iblank', 'iwhiteall'])
624 call assert_equal(getcompletion('set diffopt-=*n*', 'cmdline'), ['context:123', 'iblank'])
625 call assert_equal(getcompletion('set diffopt-=i', 'cmdline'), ['iblank', 'iwhiteall'])
626 " Don't present more than one option as it doesn't make sense in set-=
627 call assert_equal(getcompletion('set diffopt-=iblank,', 'cmdline'), [])
628 " Test empty option
629 set diffopt=
630 call assert_equal(getcompletion('set diffopt-=', 'cmdline'), [])
631 set diffopt&
632
633 " Test escaping output
634 call assert_equal(getcompletion('set fillchars-=', 'cmdline')[0], 'vert:\|')
635
636 " Test files with commas in name are being parsed and escaped properly
637 set path=has\\\ space,file\\,with\\,comma,normal_file
638 if exists('+completeslash')
639 call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\,with\,comma', 'normal_file'])
640 else
641 call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\\,with\\,comma', 'normal_file'])
642 endif
643 set path&
644
645 " Flag list should present orig value, then individual flags
646 set mouse=v
647 call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['v'])
648 set mouse=avn
649 call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['avn','a','v','n'])
650 " Don't auto-complete when we have at least one flags already
651 call assert_equal(getcompletion('set mouse-=n', 'cmdline'), [])
652 " Test empty option
653 set mouse=
654 call assert_equal(getcompletion('set mouse-=', 'cmdline'), [])
655 set mouse&
656
657 " 'whichwrap' is an odd case where it's both flag list and comma-separated
658 set ww=b,h
659 call assert_equal(getcompletion('set ww-=', 'cmdline'), ['b','h'])
660 set ww&
661endfunc
662
zeertzjq4c7cb372023-06-14 16:39:54 +0100663func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100664 call assert_fails('set scroll=-1', 'E49:')
665 call assert_fails('set backupcopy=', 'E474:')
666 call assert_fails('set regexpengine=3', 'E474:')
667 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200668 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100669 call assert_fails('set colorcolumn=-a', 'E474:')
670 call assert_fails('set colorcolumn=a', 'E474:')
671 call assert_fails('set colorcolumn=1,', 'E474:')
672 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100673 call assert_fails('set cmdheight=-1', 'E487:')
674 call assert_fails('set cmdwinheight=-1', 'E487:')
675 if has('conceal')
676 call assert_fails('set conceallevel=-1', 'E487:')
677 call assert_fails('set conceallevel=4', 'E474:')
678 endif
679 call assert_fails('set helpheight=-1', 'E487:')
680 call assert_fails('set history=-1', 'E487:')
681 call assert_fails('set report=-1', 'E487:')
682 call assert_fails('set shiftwidth=-1', 'E487:')
683 call assert_fails('set sidescroll=-1', 'E487:')
684 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000685 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000686 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000687 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100688 call assert_fails('set textwidth=-1', 'E487:')
689 call assert_fails('set timeoutlen=-1', 'E487:')
690 call assert_fails('set updatecount=-1', 'E487:')
691 call assert_fails('set updatetime=-1', 'E487:')
692 call assert_fails('set winheight=-1', 'E487:')
693 call assert_fails('set tabstop!', 'E488:')
694 call assert_fails('set xxx', 'E518:')
695 call assert_fails('set beautify?', 'E519:')
696 call assert_fails('set undolevels=x', 'E521:')
697 call assert_fails('set tabstop=', 'E521:')
698 call assert_fails('set comments=-', 'E524:')
699 call assert_fails('set comments=a', 'E525:')
700 call assert_fails('set foldmarker=x', 'E536:')
701 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000702 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100703 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100704 call assert_fails('set rulerformat=%-', 'E539:')
705 call assert_fails('set rulerformat=%(', 'E542:')
706 call assert_fails('set rulerformat=%15(%%', 'E542:')
707 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100708 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100709 call assert_fails('set statusline=%{%', 'E540:')
710 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100711 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100712 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100713 call assert_fails('set tabline=%$', 'E539:')
714 call assert_fails('set tabline=%{', 'E540:')
715 call assert_fails('set tabline=%{%', 'E540:')
716 call assert_fails('set tabline=%{%}', 'E539:')
717 call assert_fails('set tabline=%(', 'E542:')
718 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100719
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100720 if has('cursorshape')
721 " This invalid value for 'guicursor' used to cause Vim to crash.
722 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
723 call assert_fails('set guicursor=i-ci', 'E545:')
724 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100725 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100726 call assert_fails('set guicursor=r-cr:horx', 'E548:')
727 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
728 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100729 if has('mouseshape')
730 call assert_fails('se mouseshape=i-r:x', 'E547:')
731 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000732
733 " Test for 'backupext' and 'patchmode' set to the same value
734 set backupext=.bak
735 set patchmode=.patch
736 call assert_fails('set patchmode=.bak', 'E589:')
737 call assert_equal('.patch', &patchmode)
738 call assert_fails('set backupext=.patch', 'E589:')
739 call assert_equal('.bak', &backupext)
740 set backupext& patchmode&
741
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100742 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200743 set winminheight& winheight&
744 set winheight=10 winminheight=10
745 call assert_fails('set winheight=9', 'E591:')
746 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100747 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200748 set winminwidth& winwidth&
749 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
750 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100751 call assert_fails("set showbreak=\x01", 'E595:')
752 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200753 call assert_fails('set tabstop??', 'E488:')
754 call assert_fails('set wrapscan!!', 'E488:')
755 call assert_fails('set tabstop&&', 'E488:')
756 call assert_fails('set wrapscan<<', 'E488:')
757 call assert_fails('set wrapscan=1', 'E474:')
758 call assert_fails('set autoindent@', 'E488:')
759 call assert_fails('set wildchar=<abc>', 'E474:')
760 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200761 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100762 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200763 call assert_fails('set pyxversion=6', 'E474:')
764 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100765 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200766 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100767 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
768 call assert_fails('set foldmarker={{{,', 'E474:')
769 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100770 setlocal listchars=trail:·
771 call assert_fails('set ambiwidth=double', 'E834:')
772 setlocal listchars=trail:-
773 setglobal listchars=trail:·
774 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100775 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100776 setlocal fillchars=stl:·
777 call assert_fails('set ambiwidth=double', 'E835:')
778 setlocal fillchars=stl:-
779 setglobal fillchars=stl:·
780 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100781 set fillchars&
782 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
783 set nomodifiable
784 call assert_fails('set fileencoding=latin1', 'E21:')
785 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200786 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000787 call assert_fails('let &formatoptions = "?"', 'E539:')
788 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100789 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
790 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
791 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
792 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
793 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
794 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100795endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100796
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000797func Test_set_encoding()
798 let save_encoding = &encoding
799
800 set enc=iso8859-1
801 call assert_equal('latin1', &enc)
802 set enc=iso8859_1
803 call assert_equal('latin1', &enc)
804 set enc=iso-8859-1
805 call assert_equal('latin1', &enc)
806 set enc=iso_8859_1
807 call assert_equal('latin1', &enc)
808 set enc=iso88591
809 call assert_equal('latin1', &enc)
810 set enc=iso8859
811 call assert_equal('latin1', &enc)
812 set enc=iso-8859
813 call assert_equal('latin1', &enc)
814 set enc=iso_8859
815 call assert_equal('latin1', &enc)
816 call assert_fails('set enc=iso8858', 'E474:')
817 call assert_equal('latin1', &enc)
818
819 let &encoding = save_encoding
820endfunc
821
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200822func CheckWasSet(name)
823 let verb_cm = execute('verbose set ' .. a:name .. '?')
824 call assert_match('Last set from.*test_options.vim', verb_cm)
825endfunc
826func CheckWasNotSet(name)
827 let verb_cm = execute('verbose set ' .. a:name .. '?')
828 call assert_notmatch('Last set from', verb_cm)
829endfunc
830
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200831" Must be executed before other tests that set 'term'.
832func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200833 CheckNotGui
834
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200835 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200836
837 let term_save = &term
838 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200839 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200840 let &term = term_save
841endfunc
842
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200843func Test_copy_context()
844 setlocal list
845 call CheckWasSet('list')
846 split
847 call CheckWasSet('list')
848 quit
849 setlocal nolist
850
851 set ai
852 call CheckWasSet('ai')
853 set filetype=perl
854 call CheckWasSet('filetype')
855 set fo=tcroq
856 call CheckWasSet('fo')
857
858 split Xsomebuf
859 call CheckWasSet('ai')
860 call CheckWasNotSet('filetype')
861 call CheckWasSet('fo')
862endfunc
863
Bram Moolenaar67391142017-02-19 21:07:04 +0100864func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200865 CheckUnix
866 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200867
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200868 " Setting 'ttytype' used to cause a double-free when exiting vim and
869 " when vim is compiled with -DEXITFREE.
870 set ttytype=ansi
871 call assert_equal('ansi', &ttytype)
872 call assert_equal(&ttytype, &term)
873 set ttytype=xterm
874 call assert_equal('xterm', &ttytype)
875 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200876 try
877 set ttytype=
878 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100879 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200880 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200881
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200882 " Some systems accept any terminal name and return dumb settings,
883 " check for failure of finding the entry and for missing 'cm' entry.
884 try
885 set ttytype=xxx
886 call assert_report('set ttytype=xxx did not fail')
887 catch /E522\|E437/
888 endtry
889
890 set ttytype&
891 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200892
893 if has('gui') && !has('gui_running')
894 call assert_fails('set term=gui', 'E531:')
895 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100896endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100897
898func Test_set_all()
899 set tw=75
900 set iskeyword=a-z,A-Z
901 set nosplitbelow
902 let out = execute('set all')
903 call assert_match('textwidth=75', out)
904 call assert_match('iskeyword=a-z,A-Z', out)
905 call assert_match('nosplitbelow', out)
906 set tw& iskeyword& splitbelow&
907endfunc
908
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100909func Test_set_one_column()
910 let out_mult = execute('set all')->split("\n")
911 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100912 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100913endfunc
914
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100915func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200916 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100917 if filereadable('opt_test.vim')
918 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100919 else
920 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100921 endif
922endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200923
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100924func Test_renderoptions()
925 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
926 " Doesn't hurt to do this on a non-Windows system.
927 if windowsversion() !~ '^[345]\.'
928 set renderoptions=type:directx
929 set rop=type:directx
930 endif
931endfunc
932
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200933func ResetIndentexpr()
934 set indentexpr=
935endfunc
936
937func Test_set_indentexpr()
938 " this was causing usage of freed memory
939 set indentexpr=ResetIndentexpr()
940 new
941 call feedkeys("i\<c-f>", 'x')
942 call assert_equal('', &indentexpr)
943 bwipe!
944endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200945
946func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100947 " Option 'backupskip' may contain several comma-separated path
948 " specifications if one or more of the environment variables TMPDIR, TMP,
949 " or TEMP is defined. To simplify testing, convert the string value into a
950 " list.
951 let bsklist = split(&bsk, ',')
952
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200953 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100954 let found = (index(bsklist, '/private/tmp/*') >= 0)
955 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200956 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100957 let found = (index(bsklist, '/tmp/*') >= 0)
958 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200959 endif
960
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100961 " If our test platform is Windows, the path(s) in option bsk will use
962 " backslash for the path separator and the components could be in short
963 " (8.3) format. As such, we need to replace the backslashes with forward
964 " slashes and convert the path components to long format. The expand()
965 " function will do this but it cannot handle comma-separated paths. This is
966 " why bsk was converted from a string into a list of strings above.
967 "
968 " One final complication is that the wildcard "/*" is at the end of each
969 " path and so expand() might return a list of matching files. To prevent
970 " this, we need to remove the wildcard before calling expand() and then
971 " append it afterwards.
972 if has('win32')
973 let item_nbr = 0
974 while item_nbr < len(bsklist)
975 let path_spec = bsklist[item_nbr]
976 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
977 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
978 let bsklist[item_nbr] = path_spec . '/*'
979 let item_nbr += 1
980 endwhile
981 endif
982
983 " Option bsk will also include these environment variables if defined.
984 " If they're defined, verify they appear in the option value.
985 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200986 if exists(var)
987 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100988 let varvalue = substitute(varvalue, '/$', '', '')
989 let varvalue .= '/*'
990 let found = (index(bsklist, varvalue) >= 0)
991 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200992 endif
993 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200994
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200995 " Duplicates from environment variables should be filtered out (option has
996 " P_NODUP). Run this in a separate instance and write v:errors in a file,
997 " so that we see what happens on startup.
998 let after =<< trim [CODE]
999 let bsklist = split(&backupskip, ',')
1000 call assert_equal(uniq(copy(bsklist)), bsklist)
1001 call writefile(['errors:'] + v:errors, 'Xtestout')
1002 qall
1003 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001004 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001005 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1006
1007 let saveenv = {}
1008 for var in ['TMPDIR', 'TMP', 'TEMP']
1009 let saveenv[var] = getenv(var)
1010 call setenv(var, '/duplicate/path')
1011 endfor
1012
1013 exe 'silent !' . cmd
1014 call assert_equal(['errors:'], readfile('Xtestout'))
1015
1016 " restore environment variables
1017 for var in ['TMPDIR', 'TMP', 'TEMP']
1018 call setenv(var, saveenv[var])
1019 endfor
1020
1021 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001022
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001023 " Duplicates should be filtered out (option has P_NODUP)
1024 let backupskip = &backupskip
1025 set backupskip=
1026 set backupskip+=/test/dir
1027 set backupskip+=/other/dir
1028 set backupskip+=/test/dir
1029 call assert_equal('/test/dir,/other/dir', &backupskip)
1030 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001031endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001032
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001033func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001034 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001035
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001036 " Test copy option from current buffer in window
1037 split
1038 enew
1039 setlocal numberwidth=5
1040 wincmd w
1041 call assert_equal(4,&numberwidth)
1042 bnext
1043 call assert_equal(5,&numberwidth)
1044 bw!
1045 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001046
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001047 " Test copy value from window that used to be display the buffer
1048 split
1049 enew
1050 setlocal numberwidth=6
1051 bnext
1052 wincmd w
1053 call assert_equal(4,&numberwidth)
1054 bnext
1055 call assert_equal(6,&numberwidth)
1056 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001057
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001058 " Test that if buffer is current, don't use the stale cached value
1059 " from the last time the buffer was displayed.
1060 split
1061 enew
1062 setlocal numberwidth=7
1063 bnext
1064 bnext
1065 setlocal numberwidth=8
1066 wincmd w
1067 call assert_equal(4,&numberwidth)
1068 bnext
1069 call assert_equal(8,&numberwidth)
1070 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001071
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001072 " Test value is not copied if window already has seen the buffer
1073 enew
1074 split
1075 setlocal numberwidth=9
1076 bnext
1077 setlocal numberwidth=10
1078 wincmd w
1079 call assert_equal(4,&numberwidth)
1080 bnext
1081 call assert_equal(4,&numberwidth)
1082 bw!
1083
1084 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001085endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001086
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001087def Test_split_copy_options()
1088 var values = [
1089 ['cursorbind', true, false],
1090 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1091 ['list', true, 0],
1092 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1093 ['number', true, 0],
1094 ['relativenumber', true, false],
1095 ['scrollbind', true, false],
1096 ['smoothscroll', true, false],
1097 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1098 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1099 ['wrap', false, true],
1100 ]
1101 if has('linebreak')
1102 values += [
1103 ['breakindent', true, false],
1104 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1105 ['linebreak', true, false],
1106 ['numberwidth', 7, 4],
1107 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1108 ]
1109 endif
1110 if has('rightleft')
1111 values += [
1112 ['rightleft', true, false],
1113 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1114 ]
1115 endif
1116 if has('statusline')
1117 values += [
1118 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1119 ]
1120 endif
1121 if has('spell')
1122 values += [
1123 ['spell', true, false],
1124 ]
1125 endif
1126 if has('syntax')
1127 values += [
1128 ['cursorcolumn', true, false],
1129 ['cursorline', true, false],
1130 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1131 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1132 ]
1133 endif
1134 if has('diff')
1135 values += [
1136 ['diff', true, false],
1137 ]
1138 endif
1139 if has('conceal')
1140 values += [
1141 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1142 ['conceallevel', '3', &conceallevel],
1143 ]
1144 endif
1145 if has('terminal')
1146 values += [
1147 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1148 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1149 ]
1150 endif
1151 if has('folding')
1152 values += [
1153 ['foldcolumn', 5, &foldcolumn],
1154 ['foldenable', false, true],
1155 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1156 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1157 ['foldlevel', 4, &foldlevel],
1158 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1159 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1160 ['foldminlines', 3, &foldminlines],
1161 ['foldnestmax', 17, &foldnestmax],
1162 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1163 ]
1164 endif
1165 if has('signs')
1166 values += [
1167 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1168 ]
1169 endif
1170
1171 # set options to non-default value
1172 for item in values
1173 exe $'&l:{item[0]} = {item[1]}'
1174 endfor
1175
1176 # check values are set in new window
1177 split
1178 for item in values
1179 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1180 endfor
1181
1182 # restore
1183 close
1184 for item in values
1185 exe $'&l:{item[0]} = {item[2]}'
1186 endfor
1187enddef
1188
Bram Moolenaarfc089602018-06-24 16:53:35 +02001189func Test_shortmess_F()
1190 new
1191 call assert_match('\[No Name\]', execute('file'))
1192 set shortmess+=F
1193 call assert_match('\[No Name\]', execute('file'))
1194 call assert_match('^\s*$', execute('file foo'))
1195 call assert_match('foo', execute('file'))
1196 set shortmess-=F
1197 call assert_match('bar', execute('file bar'))
1198 call assert_match('bar', execute('file'))
1199 set shortmess&
1200 bwipe
1201endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001202
1203func Test_shortmess_F2()
1204 e file1
1205 e file2
1206 call assert_match('file1', execute('bn', ''))
1207 call assert_match('file2', execute('bn', ''))
1208 set shortmess+=F
1209 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001210 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001211 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001212 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001213 set hidden
1214 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001215 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001216 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001217 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001218 set nohidden
1219 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001220 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001221 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001222 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001223 set shortmess&
1224 call assert_match('file1', execute('bn', ''))
1225 call assert_match('file2', execute('bn', ''))
1226 bwipe
1227 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001228 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001229endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001230
1231func Test_local_scrolloff()
1232 set so=5
1233 set siso=7
1234 split
1235 call assert_equal(5, &so)
1236 setlocal so=3
1237 call assert_equal(3, &so)
1238 wincmd w
1239 call assert_equal(5, &so)
1240 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001241 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001242 setlocal so<
1243 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001244 setglob so=8
1245 call assert_equal(8, &so)
1246 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001247 setlocal so=0
1248 call assert_equal(0, &so)
1249 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001250 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001251
1252 call assert_equal(7, &siso)
1253 setlocal siso=3
1254 call assert_equal(3, &siso)
1255 wincmd w
1256 call assert_equal(7, &siso)
1257 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001258 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001259 setlocal siso<
1260 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001261 setglob siso=4
1262 call assert_equal(4, &siso)
1263 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001264 setlocal siso=0
1265 call assert_equal(0, &siso)
1266 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001267 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001268
1269 close
1270 set so&
1271 set siso&
1272endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001273
1274func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001275 CheckFunction reltimefloat
1276
Bram Moolenaar449ac472019-04-03 21:42:35 +02001277 new
1278 call setline(1, 'empty')
1279 redraw
1280 set writedelay=10
1281 let start = reltime()
1282 call setline(1, repeat('x', 70))
1283 redraw
1284 let elapsed = reltimefloat(reltime(start))
1285 set writedelay=0
1286 " With 'writedelay' set should take at least 30 * 10 msec
1287 call assert_inrange(30 * 0.01, 999.0, elapsed)
1288
1289 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001290endfunc
1291
1292func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001293 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001294 set visualbell
1295 call assert_beeps('normal 0h')
1296 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001297 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001298endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001299
1300" Test for the 'write' option
1301func Test_write()
1302 new
1303 call setline(1, ['L1'])
1304 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001305 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001306 set write
1307 close!
1308endfunc
1309
1310" Test for 'buftype' option
1311func Test_buftype()
1312 new
1313 call setline(1, ['L1'])
1314 set buftype=nowrite
1315 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001316
1317 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1318 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001319 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001320 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1321 endfor
1322
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001323 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001324endfunc
1325
Bram Moolenaar578fe942020-02-27 21:32:51 +01001326" Test for the 'rightleftcmd' option
1327func Test_rightleftcmd()
1328 CheckFeature rightleft
1329 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001330
1331 let g:l = []
1332 func AddPos()
1333 call add(g:l, screencol())
1334 return ''
1335 endfunc
1336 cmap <expr> <F2> AddPos()
1337
zeertzjqbb404f52022-07-23 06:25:29 +01001338 set rightleftcmd=
1339 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1340 \ "\<Right>\<F2>\<Esc>", 'xt')
1341 call assert_equal([2, 5, 3, 4], g:l)
1342
1343 let g:l = []
1344 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001345 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1346 \ "\<Left>\<F2>\<Esc>", 'xt')
1347 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1348
1349 cunmap <F2>
1350 unlet g:l
1351 set rightleftcmd&
1352 set rightleft&
1353endfunc
1354
zeertzjq28c162f2022-08-14 14:49:50 +01001355" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001356func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001357 " redraw to avoid matching previous messages
1358 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001359 set debug=beep
1360 exe "normal \<C-c>"
1361 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001362 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001363 " also check a line above, with a certain window width the colon is there
1364 call assert_match('Test_debug_option:$',
1365 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001366 set debug&
1367endfunc
1368
Bram Moolenaar004a6782020-04-11 17:09:31 +02001369" Test for the default CDPATH option
1370func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001371 let after =<< trim [CODE]
1372 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1373 call writefile(v:errors, 'Xtestout')
1374 qall
1375 [CODE]
1376 if has('unix')
1377 let $CDPATH='/path/to/dir1:/path/to/dir2'
1378 else
1379 let $CDPATH='/path/to/dir1;/path/to/dir2'
1380 endif
1381 if RunVim([], after, '')
1382 call assert_equal([], readfile('Xtestout'))
1383 call delete('Xtestout')
1384 endif
1385endfunc
1386
1387" Test for setting keycodes using set
1388func Test_opt_set_keycode()
1389 call assert_fails('set <t_k1=l', 'E474:')
1390 call assert_fails('set <Home=l', 'E474:')
1391 set <t_k9>=abcd
1392 call assert_equal('abcd', &t_k9)
1393 set <t_k9>&
1394 set <F9>=xyz
1395 call assert_equal('xyz', &t_k9)
1396 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001397
1398 " should we test all of them?
1399 set t_Ce=testCe
1400 set t_Cs=testCs
1401 set t_Us=testUs
1402 set t_ds=testds
1403 set t_Ds=testDs
1404 call assert_equal('testCe', &t_Ce)
1405 call assert_equal('testCs', &t_Cs)
1406 call assert_equal('testUs', &t_Us)
1407 call assert_equal('testds', &t_ds)
1408 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001409endfunc
1410
1411" Test for changing options in a sandbox
1412func Test_opt_sandbox()
1413 for opt in ['backupdir', 'cdpath', 'exrc']
1414 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001415 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001416 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001417 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001418endfunc
1419
1420" Test for setting an option with local value to global value
1421func Test_opt_local_to_global()
1422 setglobal equalprg=gprg
1423 setlocal equalprg=lprg
1424 call assert_equal('gprg', &g:equalprg)
1425 call assert_equal('lprg', &l:equalprg)
1426 call assert_equal('lprg', &equalprg)
1427 set equalprg<
1428 call assert_equal('', &l:equalprg)
1429 call assert_equal('gprg', &equalprg)
1430 setglobal equalprg=gnewprg
1431 setlocal equalprg=lnewprg
1432 setlocal equalprg<
1433 call assert_equal('gnewprg', &l:equalprg)
1434 call assert_equal('gnewprg', &equalprg)
1435 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001436
1437 " Test for setting the global/local value of a boolean option
1438 setglobal autoread
1439 setlocal noautoread
1440 call assert_false(&autoread)
1441 set autoread<
1442 call assert_true(&autoread)
1443 setglobal noautoread
1444 setlocal autoread
1445 setlocal autoread<
1446 call assert_false(&autoread)
1447 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001448endfunc
1449
Dominique Pelle042414f2021-07-12 21:43:19 +02001450func Test_set_in_sandbox()
1451 " Some boolean options cannot be set in sandbox, some can.
1452 call assert_fails('sandbox set modelineexpr', 'E48:')
1453 sandbox set number
1454 call assert_true(&number)
1455 set number&
1456
1457 " Some boolean options cannot be set in sandbox, some can.
1458 if has('python') || has('python3')
1459 call assert_fails('sandbox set pyxversion=3', 'E48:')
1460 endif
1461 sandbox set tabstop=4
1462 call assert_equal(4, &tabstop)
1463 set tabstop&
1464
1465 " Some string options cannot be set in sandbox, some can.
1466 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1467 sandbox set filetype=perl
1468 call assert_equal('perl', &filetype)
1469 set filetype&
1470endfunc
1471
Bram Moolenaar004a6782020-04-11 17:09:31 +02001472" Test for incrementing, decrementing and multiplying a number option value
1473func Test_opt_num_op()
1474 set shiftwidth=4
1475 set sw+=2
1476 call assert_equal(6, &sw)
1477 set sw-=2
1478 call assert_equal(4, &sw)
1479 set sw^=2
1480 call assert_equal(8, &sw)
1481 set shiftwidth&
1482endfunc
1483
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001484" Test for setting option values using v:false and v:true
1485func Test_opt_boolean()
1486 set number&
1487 set number
1488 call assert_equal(1, &nu)
1489 set nonu
1490 call assert_equal(0, &nu)
1491 let &nu = v:true
1492 call assert_equal(1, &nu)
1493 let &nu = v:false
1494 call assert_equal(0, &nu)
1495 set number&
1496endfunc
1497
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001498" Test for the 'window' option
1499func Test_window_opt()
1500 " Needs only one open widow
1501 %bw!
1502 call setline(1, range(1, 8))
1503 set window=5
1504 exe "normal \<C-F>"
1505 call assert_equal(4, line('w0'))
1506 exe "normal \<C-F>"
1507 call assert_equal(7, line('w0'))
1508 exe "normal \<C-F>"
1509 call assert_equal(8, line('w0'))
1510 exe "normal \<C-B>"
1511 call assert_equal(5, line('w0'))
1512 exe "normal \<C-B>"
1513 call assert_equal(2, line('w0'))
1514 exe "normal \<C-B>"
1515 call assert_equal(1, line('w0'))
1516 set window=1
1517 exe "normal gg\<C-F>"
1518 call assert_equal(2, line('w0'))
1519 exe "normal \<C-F>"
1520 call assert_equal(3, line('w0'))
1521 exe "normal \<C-B>"
1522 call assert_equal(2, line('w0'))
1523 exe "normal \<C-B>"
1524 call assert_equal(1, line('w0'))
1525 enew!
1526 set window&
1527endfunc
1528
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001529" Test for the 'winminheight' option
1530func Test_opt_winminheight()
1531 only!
1532 let &winheight = &lines + 4
1533 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1534 call assert_true(&winminheight <= &lines)
1535 set winminheight&
1536 set winheight&
1537endfunc
1538
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001539func Test_opt_winminheight_term()
1540 CheckRunVimInTerminal
1541
1542 " The tabline should be taken into account.
1543 let lines =<< trim END
1544 set wmh=0 stal=2
1545 below sp | wincmd _
1546 below sp | wincmd _
1547 below sp | wincmd _
1548 below sp
1549 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001550 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001551 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1552 call term_sendkeys(buf, ":set wmh=1\n")
1553 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1554
1555 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001556endfunc
1557
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001558func Test_opt_winminheight_term_tabs()
1559 CheckRunVimInTerminal
1560
1561 " The tabline should be taken into account.
1562 let lines =<< trim END
1563 set wmh=0 stal=2
1564 split
1565 split
1566 split
1567 split
1568 tabnew
1569 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001570 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001571 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1572 call term_sendkeys(buf, ":set wmh=1\n")
1573 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1574
1575 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001576endfunc
1577
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001578" Test for the 'winminwidth' option
1579func Test_opt_winminwidth()
1580 only!
1581 let &winwidth = &columns + 4
1582 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1583 call assert_true(&winminwidth <= &columns)
1584 set winminwidth&
1585 set winwidth&
1586endfunc
1587
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001588" Test for setting option value containing spaces with isfname+=32
1589func Test_isfname_with_options()
1590 set isfname+=32
1591 setlocal keywordprg=:term\ help.exe
1592 call assert_equal(':term help.exe', &keywordprg)
1593 set isfname&
1594 setlocal keywordprg&
1595endfunc
1596
Bram Moolenaar74667062020-12-28 15:41:41 +01001597" Test that resetting laststatus does change scroll option
1598func Test_opt_reset_scroll()
1599 CheckRunVimInTerminal
1600 let vimrc =<< trim [CODE]
1601 set scroll=2
1602 set laststatus=2
1603 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001604 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001605 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1606 call term_sendkeys(buf, ":verbose set scroll?\n")
1607 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1608 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001609
1610 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001611 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001612endfunc
1613
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001614" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1615func Test_VIM_POSIX()
1616 let saved_VIM_POSIX = getenv("VIM_POSIX")
1617
1618 call setenv('VIM_POSIX', "1")
1619 let after =<< trim [CODE]
1620 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1621 qall
1622 [CODE]
1623 if RunVim([], after, '')
1624 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1625 \ 'AS'], readfile('X_VIM_POSIX'))
1626 endif
1627
1628 call setenv('VIM_POSIX', v:null)
1629 let after =<< trim [CODE]
1630 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1631 qall
1632 [CODE]
1633 if RunVim([], after, '')
1634 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1635 \ 'S'], readfile('X_VIM_POSIX'))
1636 endif
1637
1638 call delete('X_VIM_POSIX')
1639 call setenv('VIM_POSIX', saved_VIM_POSIX)
1640endfunc
1641
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001642" Test for setting an option to a Vi or Vim default
1643func Test_opt_default()
1644 set formatoptions&vi
1645 call assert_equal('vt', &formatoptions)
1646 set formatoptions&vim
1647 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001648
1649 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1650 set fencs=latin1
1651 set fencs&
1652 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1653 set fencs=latin1
1654 set all&
1655 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001656endfunc
1657
1658" Test for the 'cmdheight' option
1659func Test_cmdheight()
1660 %bw!
1661 let ht = &lines
1662 set cmdheight=9999
1663 call assert_equal(1, winheight(0))
1664 call assert_equal(ht - 1, &cmdheight)
1665 set cmdheight&
1666endfunc
1667
Dominique Pelle923dce22021-11-21 11:36:04 +00001668" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001669func Test_opt_control_char()
1670 set wildchar=^v
1671 call assert_equal("\<C-V>", nr2char(&wildchar))
1672 set wildcharm=^r
1673 call assert_equal("\<C-R>", nr2char(&wildcharm))
1674 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1675 set wildchar& wildcharm&
1676endfunc
1677
1678" Test for the 'errorbells' option
1679func Test_opt_errorbells()
1680 set errorbells
1681 call assert_beeps('s/a1b2/x1y2/')
1682 set noerrorbells
1683endfunc
1684
Dominique Pelle042414f2021-07-12 21:43:19 +02001685func Test_opt_scrolljump()
1686 help
1687 resize 10
1688
1689 " Test with positive 'scrolljump'.
1690 set scrolljump=2
1691 norm! Lj
1692 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1693 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1694 \ winsaveview())
1695
1696 " Test with negative 'scrolljump' (percentage of window height).
1697 set scrolljump=-40
1698 norm! ggLj
1699 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1700 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1701 \ winsaveview())
1702
1703 set scrolljump&
1704 bw
1705endfunc
1706
Bakudankun29f3a452021-12-11 12:28:08 +00001707" Test for the 'cdhome' option
1708func Test_opt_cdhome()
1709 if has('unix') || has('vms')
1710 throw 'Skipped: only works on non-Unix'
1711 endif
1712
1713 set cdhome&
1714 call assert_equal(0, &cdhome)
1715 set cdhome
1716
1717 " This paragraph is copied from Test_cd_no_arg().
1718 let path = getcwd()
1719 cd
1720 call assert_equal($HOME, getcwd())
1721 call assert_notequal(path, getcwd())
1722 exe 'cd ' .. fnameescape(path)
1723 call assert_equal(path, getcwd())
1724
1725 set cdhome&
1726endfunc
1727
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001728func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001729 CheckOption termguicolors
1730
1731 " Test default option completion
1732 set wildoptions=
1733 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1734 call assert_equal('"set termguicolors', @:)
1735
1736 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1737 call assert_equal('"set notermguicolors', @:)
1738
1739 " Test fuzzy option completion
1740 set wildoptions=fuzzy
1741 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1742 call assert_equal('"set termguicolors termencoding', @:)
1743
1744 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1745 call assert_equal('"set notermguicolors', @:)
1746
1747 set wildoptions=
1748endfunc
1749
Sean Dewar39c46b42022-05-12 17:44:29 +01001750func Test_switchbuf_reset()
1751 set switchbuf=useopen
1752 sblast
1753 call assert_equal(1, winnr('$'))
1754 set all&
1755 call assert_equal('', &switchbuf)
1756 sblast
1757 call assert_equal(2, winnr('$'))
1758 only!
1759endfunc
1760
zeertzjqfcba86c2022-09-22 13:57:32 +01001761" :set empty string for global 'keywordprg' falls back to ":help"
1762func Test_keywordprg_empty()
1763 let k = &keywordprg
1764 set keywordprg=man
1765 call assert_equal('man', &keywordprg)
1766 set keywordprg=
1767 call assert_equal(':help', &keywordprg)
1768 set keywordprg=man
1769 call assert_equal('man', &keywordprg)
1770 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1771 let &keywordprg = k
1772endfunc
1773
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001774" check that the very first buffer created does not have 'endoffile' set
1775func Test_endoffile_default()
1776 let after =<< trim [CODE]
1777 call writefile([execute('set eof?')], 'Xtestout')
1778 qall!
1779 [CODE]
1780 if RunVim([], after, '')
1781 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1782 endif
1783 call delete('Xtestout')
1784endfunc
1785
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001786" Test for setting the 'lines' and 'columns' options to a minimum value
1787func Test_set_min_lines_columns()
1788 let save_lines = &lines
1789 let save_columns = &columns
1790
1791 let after =<< trim END
1792 set nomore
1793 let msg = []
1794 let v:errmsg = ''
1795 silent! let &columns=0
1796 call add(msg, v:errmsg)
1797 silent! set columns=0
1798 call add(msg, v:errmsg)
1799 silent! call setbufvar('', '&columns', 0)
1800 call add(msg, v:errmsg)
1801 "call writefile(msg, 'XResultsetminlines')
1802 silent! let &lines=0
1803 call add(msg, v:errmsg)
1804 silent! set lines=0
1805 call add(msg, v:errmsg)
1806 silent! call setbufvar('', '&lines', 0)
1807 call add(msg, v:errmsg)
1808 call writefile(msg, 'XResultsetminlines')
1809 qall!
1810 END
1811 if RunVim([], after, '')
1812 call assert_equal(['E594: Need at least 12 columns',
1813 \ 'E594: Need at least 12 columns: columns=0',
1814 \ 'E594: Need at least 12 columns',
1815 \ 'E593: Need at least 2 lines',
1816 \ 'E593: Need at least 2 lines: lines=0',
1817 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1818 endif
1819
1820 call delete('XResultsetminlines')
1821 let &lines = save_lines
1822 let &columns = save_columns
1823endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001824
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001825" Test for reverting a string option value if the new value is invalid.
1826func Test_string_option_revert_on_failure()
1827 new
1828 let optlist = [
1829 \ ['ambiwidth', 'double', 'a123'],
1830 \ ['background', 'dark', 'a123'],
1831 \ ['backspace', 'eol', 'a123'],
1832 \ ['backupcopy', 'no', 'a123'],
1833 \ ['belloff', 'showmatch', 'a123'],
1834 \ ['breakindentopt', 'min:10', 'list'],
1835 \ ['bufhidden', 'wipe', 'a123'],
1836 \ ['buftype', 'nowrite', 'a123'],
1837 \ ['casemap', 'keepascii', 'a123'],
1838 \ ['cedit', "\<C-Y>", 'z'],
1839 \ ['colorcolumn', '10', 'z'],
1840 \ ['commentstring', '#%s', 'a123'],
1841 \ ['complete', '.,t', 'a'],
1842 \ ['completefunc', 'MyCmplFunc', '1a-'],
1843 \ ['completeopt', 'popup', 'a123'],
1844 \ ['completepopup', 'width:20', 'border'],
1845 \ ['concealcursor', 'v', 'xyz'],
1846 \ ['cpoptions', 'HJ', '~'],
1847 \ ['cryptmethod', 'zip', 'a123'],
1848 \ ['cursorlineopt', 'screenline', 'a123'],
1849 \ ['debug', 'throw', 'a123'],
1850 \ ['diffopt', 'iwhite', 'a123'],
1851 \ ['display', 'uhex', 'a123'],
1852 \ ['eadirection', 'hor', 'a123'],
1853 \ ['encoding', 'utf-8', 'a123'],
1854 \ ['eventignore', 'TextYankPost', 'a123'],
1855 \ ['fileencoding', 'utf-8', 'a123,'],
1856 \ ['fileformat', 'mac', 'a123'],
1857 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001858 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001859 \ ['fillchars', 'diff:~', 'a123'],
1860 \ ['foldclose', 'all', 'a123'],
1861 \ ['foldmarker', '[[[,]]]', '[[['],
1862 \ ['foldmethod', 'marker', 'a123'],
1863 \ ['foldopen', 'percent', 'a123'],
1864 \ ['formatoptions', 'an', '*'],
1865 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1866 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001867 \ ['highlight', '!:CursorColumn', '8:'],
1868 \ ['keymodel', 'stopsel', 'a123'],
1869 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1870 \ ['lispoptions', 'expr:1', 'a123'],
1871 \ ['listchars', 'tab:->', 'tab:'],
1872 \ ['matchpairs', '<:>', '<:'],
1873 \ ['mkspellmem', '100000,1000,100', '100000'],
1874 \ ['mouse', 'nvi', 'z'],
1875 \ ['mousemodel', 'extend', 'a123'],
1876 \ ['nrformats', 'alpha', 'a123'],
1877 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1878 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1879 \ ['previewpopup', 'width:20', 'a123'],
1880 \ ['printoptions', 'paper:A4', 'a123:'],
1881 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1882 \ ['rulerformat', '%l', '%['],
1883 \ ['scrollopt', 'hor,jump', 'a123'],
1884 \ ['selection', 'exclusive', 'a123'],
1885 \ ['selectmode', 'cmd', 'a123'],
1886 \ ['sessionoptions', 'options', 'a123'],
1887 \ ['shortmess', 'w', '2'],
1888 \ ['showbreak', '>>', "\x01"],
1889 \ ['showcmdloc', 'statusline', 'a123'],
1890 \ ['signcolumn', 'no', 'a123'],
1891 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1892 \ ['spellfile', 'MySpell.en.add', "\x01"],
1893 \ ['spelllang', 'en', "#"],
1894 \ ['spelloptions', 'camel', 'a123'],
1895 \ ['spellsuggest', 'double', 'a123'],
1896 \ ['splitkeep', 'topline', 'a123'],
1897 \ ['statusline', '%f', '%['],
1898 \ ['swapsync', 'sync', 'a123'],
1899 \ ['switchbuf', 'usetab', 'a123'],
1900 \ ['syntax', 'abc', 'a^b'],
1901 \ ['tabline', '%f', '%['],
1902 \ ['tagcase', 'ignore', 'a123'],
1903 \ ['tagfunc', 'MyTagFunc', '1a-'],
1904 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1905 \ ['viewoptions', 'options', 'a123'],
1906 \ ['virtualedit', 'onemore', 'a123'],
1907 \ ['whichwrap', '<,>', '{,}'],
1908 \ ['wildmode', 'list', 'a123'],
1909 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001910 \ ]
1911 if has('gui')
1912 call add(optlist, ['browsedir', 'buffer', 'a123'])
1913 endif
1914 if has('clipboard_working')
1915 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1916 endif
1917 if has('win32')
1918 call add(optlist, ['completeslash', 'slash', 'a123'])
1919 endif
1920 if has('cscope')
1921 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1922 endif
1923 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001924 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1925 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1926 endif
1927 if has('keymap')
1928 call add(optlist, ['keymap', 'greek', '[]'])
1929 endif
1930 if has('mouseshape')
1931 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1932 endif
1933 if has('win32') && has('gui')
1934 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1935 endif
1936 if has('rightleft')
1937 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1938 endif
1939 if has('terminal')
1940 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1941 call add(optlist, ['termwinsize', '24x80', '100'])
1942 endif
1943 if has('win32') && has('terminal')
1944 call add(optlist, ['termwintype', 'winpty', 'a123'])
1945 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001946 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001947 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001948 endif
1949 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001950 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1951 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001952 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001953 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1954 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001955 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001956 call add(optlist, ['varsofttabstop', '12', 'a123'])
1957 call add(optlist, ['vartabstop', '4,20', '4,'])
1958 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001959 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001960 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001961 endif
1962 for opt in optlist
1963 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001964 try
1965 exe $"let &{opt[0]} = '{opt[1]}'"
1966 catch
1967 call assert_report($"Caught {v:exception} with {opt->string()}")
1968 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001969 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1970 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1971 exe $"let &{opt[0]} = save_opt"
1972 endfor
1973 bw!
1974endfunc
1975
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02001976func Test_set_option_window_global_local()
1977 new Xbuffer1
1978 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
1979 setlocal scrolloff=2
1980 setglobal scrolloff=3
1981 setl modified
1982 " A new buffer has its own window-local options
1983 hide enew
1984 call assert_equal(-1, &l:scrolloff)
1985 call assert_equal(3, &g:scrolloff)
1986 " A new window opened with its own buffer-local options
1987 new
1988 call assert_equal(-1, &l:scrolloff)
1989 call assert_equal(3, &g:scrolloff)
1990 " Re-open Xbuffer1 and it should use
1991 " the previous set window-local options
1992 b Xbuffer1
1993 call assert_equal(2, &l:scrolloff)
1994 call assert_equal(3, &g:scrolloff)
1995 bw!
1996 bw!
1997 let &g:scrolloff = _gso
1998endfunc
1999
2000func GetGlobalLocalWindowOptions()
2001 new
2002 sil! r $VIMRUNTIME/doc/options.txt
2003 " Filter for global or local to window
2004 v/^'.*'.*\n.*global or local to window |global-local/d
2005 " get option value and type
2006 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2007 sil %s/empty/""/g
2008 " split the result
2009 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2010 bw!
2011 return result
2012endfunc
2013
2014func Test_set_option_window_global_local_all()
2015 new Xbuffer2
2016
2017 let optionlist = GetGlobalLocalWindowOptions()
2018 for [opt, type, default] in optionlist
2019 let _old = eval('&g:' .. opt)
2020 if type == 'string'
2021 if opt == 'fillchars'
2022 exe 'setl ' .. opt .. '=vert:+'
2023 exe 'setg ' .. opt .. '=vert:+,fold:+'
2024 elseif opt == 'listchars'
2025 exe 'setl ' .. opt .. '=tab:>>'
2026 exe 'setg ' .. opt .. '=tab:++'
2027 elseif opt == 'virtualedit'
2028 exe 'setl ' .. opt .. '=all'
2029 exe 'setg ' .. opt .. '=block'
2030 else
2031 exe 'setl ' .. opt .. '=Local'
2032 exe 'setg ' .. opt .. '=Global'
2033 endif
2034 elseif type == 'number'
2035 exe 'setl ' .. opt .. '=5'
2036 exe 'setg ' .. opt .. '=10'
2037 endif
2038 setl modified
2039 hide enew
2040 if type == 'string'
2041 call assert_equal('', eval('&l:' .. opt))
2042 if opt == 'fillchars'
2043 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2044 elseif opt == 'listchars'
2045 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2046 elseif opt == 'virtualedit'
2047 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2048 else
2049 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2050 endif
2051 elseif type == 'number'
2052 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2053 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2054 endif
2055 bw!
2056 exe 'let &g:' .. opt .. '=' .. default
2057 endfor
2058 bw!
2059endfunc
2060
Christian Brabandt757593c2023-08-22 21:44:10 +02002061func Test_paste_depending_options()
2062 " setting the paste option, resets all dependent options
2063 " and will be reported correctly using :verbose set <option>?
2064 let lines =<< trim [CODE]
2065 " set paste test
2066 set autoindent
2067 set expandtab
2068 " disabled, because depends on compiled feature set
2069 " set hkmap
2070 " set revins
2071 " set varsofttabstop=8,32,8
2072 set ruler
2073 set showmatch
2074 set smarttab
2075 set softtabstop=4
2076 set textwidth=80
2077 set wrapmargin=10
2078
2079 source Xvimrc_paste2
2080
2081 redir > Xoutput_paste
2082 verbose set expandtab?
2083 verbose setg expandtab?
2084 verbose setl expandtab?
2085 redir END
2086
2087 qall!
2088 [CODE]
2089
2090 call writefile(lines, 'Xvimrc_paste', 'D')
2091 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2092 if !RunVim([], lines, '--clean')
2093 return
2094 endif
2095
2096 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2097 call assert_equal('noexpandtab', result[0])
2098 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2099 call assert_equal('noexpandtab', result[2])
2100 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2101 call assert_equal('noexpandtab', result[4])
2102 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2103
2104 call delete('Xoutput_paste')
2105endfunc
2106
2107func Test_binary_depending_options()
2108 " setting the paste option, resets all dependent options
2109 " and will be reported correctly using :verbose set <option>?
2110 let lines =<< trim [CODE]
2111 " set binary test
2112 set expandtab
2113
2114 source Xvimrc_bin2
2115
2116 redir > Xoutput_bin
2117 verbose set expandtab?
2118 verbose setg expandtab?
2119 verbose setl expandtab?
2120 redir END
2121
2122 qall!
2123 [CODE]
2124
2125 call writefile(lines, 'Xvimrc_bin', 'D')
2126 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2127 if !RunVim([], lines, '--clean')
2128 return
2129 endif
2130
2131 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2132 call assert_equal('noexpandtab', result[0])
2133 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2134 call assert_equal('noexpandtab', result[2])
2135 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2136 call assert_equal('noexpandtab', result[4])
2137 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2138
2139 call delete('Xoutput_bin')
2140endfunc
2141
Gregory Anders3695d0e2023-09-29 20:17:20 +02002142func Test_set_keyprotocol()
2143 CheckNotGui
2144
2145 let term = &term
2146 set term=ansi
2147 call assert_equal('', &t_TI)
2148
2149 " Setting 'keyprotocol' should affect terminal codes without needing to
2150 " reset 'term'
2151 set keyprotocol+=ansi:kitty
2152 call assert_equal("\<Esc>[=1;1u", &t_TI)
2153 let &term = term
2154endfunc
2155
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002156" vim: shiftwidth=2 sts=2 expandtab