blob: 3d53efdd6b192480fd209764c9576bfabaac8b70 [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
520 call assert_equal(getcompletion('set listchars+=', 'cmdline')[0], 'eol')
521 call assert_equal(getcompletion('setl listchars+=', 'cmdline')[0], 'eol')
522 call assert_equal(getcompletion('set fillchars+=', 'cmdline')[0], 'stl')
523 call assert_equal(getcompletion('setl fillchars+=', 'cmdline')[0], 'stl')
524
525 "
526 " Unique string options below
527 "
528
529 " keyprotocol: only auto-complete when after ':' with known protocol types
530 call assert_equal(getcompletion('set keyprotocol=', 'cmdline'), [&keyprotocol])
531 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
532 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
533 set keyprotocol&
534
535 " previewpopup / completepopup
536 call assert_equal(getcompletion('set previewpopup=', 'cmdline')[0], 'height:')
537 call assert_equal(getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0], 'EndOfBuffer')
538 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
539 call assert_equal('"set previewpopup+=border:on', @:)
540 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
541 call assert_equal('"set completepopup=height:10,align:item', @:)
542 call assert_equal(getcompletion('set completepopup=bogusname:', 'cmdline'), [])
543 set previewpopup& completepopup&
544
545 " diffopt: special handling of algorithm:<alg_list>
546 call assert_equal(getcompletion('set diffopt+=', 'cmdline')[0], 'filler')
547 call assert_equal(getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'), [])
548 call assert_equal(getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0], 'patience')
549
550 " highlight: special parsing, including auto-completing highlight groups
551 " after ':'
552 call assert_equal(getcompletion('set hl=', 'cmdline')[0:1], [&hl, '8'])
553 call assert_equal(getcompletion('set hl+=', 'cmdline')[0], '8')
554 call assert_equal(getcompletion('set hl+=8', 'cmdline')[0:2], ['8:', '8b', '8i'])
555 call assert_equal(getcompletion('set hl+=8b', 'cmdline')[0], '8bi')
556 call assert_equal(getcompletion('set hl+=8:No*ext', 'cmdline')[0], 'NonText')
557 " If all the display modes are used up we should be suggesting nothing. Make
558 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
559 " and make sure nothing is suggested from that.
560 let hl_display_modes = join(
561 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
562 \ {idx, val -> val[1]}),
563 \ {idx, val -> val != ':'}),
564 \ '')
565 call assert_equal(getcompletion('set hl+=8'..hl_display_modes, 'cmdline'), [])
566
567 "
568 " Test flag lists
569 "
570
571 " Test set=. Show the original value if nothing is typed after '='.
572 " Otherwise, the list should avoid showing what's already typed.
573 set mouse=v
574 call assert_equal(getcompletion('set mouse=', 'cmdline'), ['v','a','n','i','c','h','r'])
575 set mouse=nvi
576 call assert_equal(getcompletion('set mouse=', 'cmdline'), ['nvi','a','n','v','i','c','h','r'])
577 call assert_equal(getcompletion('set mouse=hn', 'cmdline'), ['a','v','i','c','r'])
578
579 " Test set+=. Never show original value, and it also tries to avoid listing
580 " flags that's already in the option value.
581 call assert_equal(getcompletion('set mouse+=', 'cmdline'), ['a','c','h','r'])
582 call assert_equal(getcompletion('set mouse+=hn', 'cmdline'), ['a','c','r'])
583 call assert_equal(getcompletion('set mouse+=acrhn', 'cmdline'), [])
584
585 " Test that the position of the expansion is correct (even if there are
586 " additional values after the current cursor)
587 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
588 call assert_equal('"set mouse=han', @:)
589 set mouse&
590
591 " Test that other flag list options have auto-complete, but don't
592 " exhaustively validate their results.
593 if exists('+concealcursor')
594 call assert_equal(getcompletion('set cocu=', 'cmdline')[0], 'n')
595 endif
596 call assert_equal(getcompletion('set cpo=', 'cmdline')[1], 'a')
597 call assert_equal(getcompletion('set fo=', 'cmdline')[1], 't')
598 if exists('+guioptions')
599 call assert_equal(getcompletion('set go=', 'cmdline')[1], '!')
600 endif
601 call assert_equal(getcompletion('set shortmess=', 'cmdline')[1], 'r')
602 call assert_equal(getcompletion('set whichwrap=', 'cmdline')[1], 'b')
603
604 "
605 "Test set-=
606 "
607
608 " Normal single-value option just shows the existing value
609 set ambiwidth=double
610 call assert_equal(getcompletion('set ambw-=', 'cmdline'), ['double'])
611 set ambiwidth&
612
613 " Works on numbers and term options as well
614 call assert_equal(getcompletion('set laststatus-=', 'cmdline'), [string(&laststatus)])
615 set t_Ce=testCe
616 call assert_equal(getcompletion('set t_Ce-=', 'cmdline'), ['testCe'])
617 set t_Ce&
618
619 " Comma-separated lists should present each option
620 set diffopt=context:123,,,,,iblank,iwhiteall
621 call assert_equal(getcompletion('set diffopt-=', 'cmdline'), ['context:123', 'iblank', 'iwhiteall'])
622 call assert_equal(getcompletion('set diffopt-=*n*', 'cmdline'), ['context:123', 'iblank'])
623 call assert_equal(getcompletion('set diffopt-=i', 'cmdline'), ['iblank', 'iwhiteall'])
624 " Don't present more than one option as it doesn't make sense in set-=
625 call assert_equal(getcompletion('set diffopt-=iblank,', 'cmdline'), [])
626 " Test empty option
627 set diffopt=
628 call assert_equal(getcompletion('set diffopt-=', 'cmdline'), [])
629 set diffopt&
630
631 " Test escaping output
632 call assert_equal(getcompletion('set fillchars-=', 'cmdline')[0], 'vert:\|')
633
634 " Test files with commas in name are being parsed and escaped properly
635 set path=has\\\ space,file\\,with\\,comma,normal_file
636 if exists('+completeslash')
637 call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\,with\,comma', 'normal_file'])
638 else
639 call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\\,with\\,comma', 'normal_file'])
640 endif
641 set path&
642
643 " Flag list should present orig value, then individual flags
644 set mouse=v
645 call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['v'])
646 set mouse=avn
647 call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['avn','a','v','n'])
648 " Don't auto-complete when we have at least one flags already
649 call assert_equal(getcompletion('set mouse-=n', 'cmdline'), [])
650 " Test empty option
651 set mouse=
652 call assert_equal(getcompletion('set mouse-=', 'cmdline'), [])
653 set mouse&
654
655 " 'whichwrap' is an odd case where it's both flag list and comma-separated
656 set ww=b,h
657 call assert_equal(getcompletion('set ww-=', 'cmdline'), ['b','h'])
658 set ww&
659endfunc
660
zeertzjq4c7cb372023-06-14 16:39:54 +0100661func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100662 call assert_fails('set scroll=-1', 'E49:')
663 call assert_fails('set backupcopy=', 'E474:')
664 call assert_fails('set regexpengine=3', 'E474:')
665 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200666 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100667 call assert_fails('set colorcolumn=-a', 'E474:')
668 call assert_fails('set colorcolumn=a', 'E474:')
669 call assert_fails('set colorcolumn=1,', 'E474:')
670 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100671 call assert_fails('set cmdheight=-1', 'E487:')
672 call assert_fails('set cmdwinheight=-1', 'E487:')
673 if has('conceal')
674 call assert_fails('set conceallevel=-1', 'E487:')
675 call assert_fails('set conceallevel=4', 'E474:')
676 endif
677 call assert_fails('set helpheight=-1', 'E487:')
678 call assert_fails('set history=-1', 'E487:')
679 call assert_fails('set report=-1', 'E487:')
680 call assert_fails('set shiftwidth=-1', 'E487:')
681 call assert_fails('set sidescroll=-1', 'E487:')
682 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000683 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000684 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000685 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100686 call assert_fails('set textwidth=-1', 'E487:')
687 call assert_fails('set timeoutlen=-1', 'E487:')
688 call assert_fails('set updatecount=-1', 'E487:')
689 call assert_fails('set updatetime=-1', 'E487:')
690 call assert_fails('set winheight=-1', 'E487:')
691 call assert_fails('set tabstop!', 'E488:')
692 call assert_fails('set xxx', 'E518:')
693 call assert_fails('set beautify?', 'E519:')
694 call assert_fails('set undolevels=x', 'E521:')
695 call assert_fails('set tabstop=', 'E521:')
696 call assert_fails('set comments=-', 'E524:')
697 call assert_fails('set comments=a', 'E525:')
698 call assert_fails('set foldmarker=x', 'E536:')
699 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000700 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100701 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100702 call assert_fails('set rulerformat=%-', 'E539:')
703 call assert_fails('set rulerformat=%(', 'E542:')
704 call assert_fails('set rulerformat=%15(%%', 'E542:')
705 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100706 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100707 call assert_fails('set statusline=%{%', 'E540:')
708 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100709 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100710 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100711 call assert_fails('set tabline=%$', 'E539:')
712 call assert_fails('set tabline=%{', 'E540:')
713 call assert_fails('set tabline=%{%', 'E540:')
714 call assert_fails('set tabline=%{%}', 'E539:')
715 call assert_fails('set tabline=%(', 'E542:')
716 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100717
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100718 if has('cursorshape')
719 " This invalid value for 'guicursor' used to cause Vim to crash.
720 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
721 call assert_fails('set guicursor=i-ci', 'E545:')
722 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100723 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100724 call assert_fails('set guicursor=r-cr:horx', 'E548:')
725 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
726 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100727 if has('mouseshape')
728 call assert_fails('se mouseshape=i-r:x', 'E547:')
729 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000730
731 " Test for 'backupext' and 'patchmode' set to the same value
732 set backupext=.bak
733 set patchmode=.patch
734 call assert_fails('set patchmode=.bak', 'E589:')
735 call assert_equal('.patch', &patchmode)
736 call assert_fails('set backupext=.patch', 'E589:')
737 call assert_equal('.bak', &backupext)
738 set backupext& patchmode&
739
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100740 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200741 set winminheight& winheight&
742 set winheight=10 winminheight=10
743 call assert_fails('set winheight=9', 'E591:')
744 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100745 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200746 set winminwidth& winwidth&
747 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
748 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100749 call assert_fails("set showbreak=\x01", 'E595:')
750 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200751 call assert_fails('set tabstop??', 'E488:')
752 call assert_fails('set wrapscan!!', 'E488:')
753 call assert_fails('set tabstop&&', 'E488:')
754 call assert_fails('set wrapscan<<', 'E488:')
755 call assert_fails('set wrapscan=1', 'E474:')
756 call assert_fails('set autoindent@', 'E488:')
757 call assert_fails('set wildchar=<abc>', 'E474:')
758 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200759 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100760 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200761 call assert_fails('set pyxversion=6', 'E474:')
762 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100763 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200764 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100765 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
766 call assert_fails('set foldmarker={{{,', 'E474:')
767 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100768 setlocal listchars=trail:·
769 call assert_fails('set ambiwidth=double', 'E834:')
770 setlocal listchars=trail:-
771 setglobal listchars=trail:·
772 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100773 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100774 setlocal fillchars=stl:·
775 call assert_fails('set ambiwidth=double', 'E835:')
776 setlocal fillchars=stl:-
777 setglobal fillchars=stl:·
778 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100779 set fillchars&
780 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
781 set nomodifiable
782 call assert_fails('set fileencoding=latin1', 'E21:')
783 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200784 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000785 call assert_fails('let &formatoptions = "?"', 'E539:')
786 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100787 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
788 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
789 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
790 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
791 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
792 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100793endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100794
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000795func Test_set_encoding()
796 let save_encoding = &encoding
797
798 set enc=iso8859-1
799 call assert_equal('latin1', &enc)
800 set enc=iso8859_1
801 call assert_equal('latin1', &enc)
802 set enc=iso-8859-1
803 call assert_equal('latin1', &enc)
804 set enc=iso_8859_1
805 call assert_equal('latin1', &enc)
806 set enc=iso88591
807 call assert_equal('latin1', &enc)
808 set enc=iso8859
809 call assert_equal('latin1', &enc)
810 set enc=iso-8859
811 call assert_equal('latin1', &enc)
812 set enc=iso_8859
813 call assert_equal('latin1', &enc)
814 call assert_fails('set enc=iso8858', 'E474:')
815 call assert_equal('latin1', &enc)
816
817 let &encoding = save_encoding
818endfunc
819
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200820func CheckWasSet(name)
821 let verb_cm = execute('verbose set ' .. a:name .. '?')
822 call assert_match('Last set from.*test_options.vim', verb_cm)
823endfunc
824func CheckWasNotSet(name)
825 let verb_cm = execute('verbose set ' .. a:name .. '?')
826 call assert_notmatch('Last set from', verb_cm)
827endfunc
828
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200829" Must be executed before other tests that set 'term'.
830func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200831 CheckNotGui
832
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200833 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200834
835 let term_save = &term
836 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200837 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200838 let &term = term_save
839endfunc
840
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200841func Test_copy_context()
842 setlocal list
843 call CheckWasSet('list')
844 split
845 call CheckWasSet('list')
846 quit
847 setlocal nolist
848
849 set ai
850 call CheckWasSet('ai')
851 set filetype=perl
852 call CheckWasSet('filetype')
853 set fo=tcroq
854 call CheckWasSet('fo')
855
856 split Xsomebuf
857 call CheckWasSet('ai')
858 call CheckWasNotSet('filetype')
859 call CheckWasSet('fo')
860endfunc
861
Bram Moolenaar67391142017-02-19 21:07:04 +0100862func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200863 CheckUnix
864 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200865
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200866 " Setting 'ttytype' used to cause a double-free when exiting vim and
867 " when vim is compiled with -DEXITFREE.
868 set ttytype=ansi
869 call assert_equal('ansi', &ttytype)
870 call assert_equal(&ttytype, &term)
871 set ttytype=xterm
872 call assert_equal('xterm', &ttytype)
873 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200874 try
875 set ttytype=
876 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100877 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200878 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200879
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200880 " Some systems accept any terminal name and return dumb settings,
881 " check for failure of finding the entry and for missing 'cm' entry.
882 try
883 set ttytype=xxx
884 call assert_report('set ttytype=xxx did not fail')
885 catch /E522\|E437/
886 endtry
887
888 set ttytype&
889 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200890
891 if has('gui') && !has('gui_running')
892 call assert_fails('set term=gui', 'E531:')
893 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100894endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100895
896func Test_set_all()
897 set tw=75
898 set iskeyword=a-z,A-Z
899 set nosplitbelow
900 let out = execute('set all')
901 call assert_match('textwidth=75', out)
902 call assert_match('iskeyword=a-z,A-Z', out)
903 call assert_match('nosplitbelow', out)
904 set tw& iskeyword& splitbelow&
905endfunc
906
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100907func Test_set_one_column()
908 let out_mult = execute('set all')->split("\n")
909 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100910 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100911endfunc
912
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100913func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200914 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100915 if filereadable('opt_test.vim')
916 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100917 else
918 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100919 endif
920endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200921
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100922func Test_renderoptions()
923 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
924 " Doesn't hurt to do this on a non-Windows system.
925 if windowsversion() !~ '^[345]\.'
926 set renderoptions=type:directx
927 set rop=type:directx
928 endif
929endfunc
930
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200931func ResetIndentexpr()
932 set indentexpr=
933endfunc
934
935func Test_set_indentexpr()
936 " this was causing usage of freed memory
937 set indentexpr=ResetIndentexpr()
938 new
939 call feedkeys("i\<c-f>", 'x')
940 call assert_equal('', &indentexpr)
941 bwipe!
942endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200943
944func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100945 " Option 'backupskip' may contain several comma-separated path
946 " specifications if one or more of the environment variables TMPDIR, TMP,
947 " or TEMP is defined. To simplify testing, convert the string value into a
948 " list.
949 let bsklist = split(&bsk, ',')
950
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200951 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100952 let found = (index(bsklist, '/private/tmp/*') >= 0)
953 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200954 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100955 let found = (index(bsklist, '/tmp/*') >= 0)
956 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200957 endif
958
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100959 " If our test platform is Windows, the path(s) in option bsk will use
960 " backslash for the path separator and the components could be in short
961 " (8.3) format. As such, we need to replace the backslashes with forward
962 " slashes and convert the path components to long format. The expand()
963 " function will do this but it cannot handle comma-separated paths. This is
964 " why bsk was converted from a string into a list of strings above.
965 "
966 " One final complication is that the wildcard "/*" is at the end of each
967 " path and so expand() might return a list of matching files. To prevent
968 " this, we need to remove the wildcard before calling expand() and then
969 " append it afterwards.
970 if has('win32')
971 let item_nbr = 0
972 while item_nbr < len(bsklist)
973 let path_spec = bsklist[item_nbr]
974 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
975 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
976 let bsklist[item_nbr] = path_spec . '/*'
977 let item_nbr += 1
978 endwhile
979 endif
980
981 " Option bsk will also include these environment variables if defined.
982 " If they're defined, verify they appear in the option value.
983 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200984 if exists(var)
985 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100986 let varvalue = substitute(varvalue, '/$', '', '')
987 let varvalue .= '/*'
988 let found = (index(bsklist, varvalue) >= 0)
989 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200990 endif
991 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200992
Bram Moolenaarb00ef052020-09-12 14:53:53 +0200993 " Duplicates from environment variables should be filtered out (option has
994 " P_NODUP). Run this in a separate instance and write v:errors in a file,
995 " so that we see what happens on startup.
996 let after =<< trim [CODE]
997 let bsklist = split(&backupskip, ',')
998 call assert_equal(uniq(copy(bsklist)), bsklist)
999 call writefile(['errors:'] + v:errors, 'Xtestout')
1000 qall
1001 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001002 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001003 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1004
1005 let saveenv = {}
1006 for var in ['TMPDIR', 'TMP', 'TEMP']
1007 let saveenv[var] = getenv(var)
1008 call setenv(var, '/duplicate/path')
1009 endfor
1010
1011 exe 'silent !' . cmd
1012 call assert_equal(['errors:'], readfile('Xtestout'))
1013
1014 " restore environment variables
1015 for var in ['TMPDIR', 'TMP', 'TEMP']
1016 call setenv(var, saveenv[var])
1017 endfor
1018
1019 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001020
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001021 " Duplicates should be filtered out (option has P_NODUP)
1022 let backupskip = &backupskip
1023 set backupskip=
1024 set backupskip+=/test/dir
1025 set backupskip+=/other/dir
1026 set backupskip+=/test/dir
1027 call assert_equal('/test/dir,/other/dir', &backupskip)
1028 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001029endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001030
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001031func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001032 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001033
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001034 " Test copy option from current buffer in window
1035 split
1036 enew
1037 setlocal numberwidth=5
1038 wincmd w
1039 call assert_equal(4,&numberwidth)
1040 bnext
1041 call assert_equal(5,&numberwidth)
1042 bw!
1043 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001044
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001045 " Test copy value from window that used to be display the buffer
1046 split
1047 enew
1048 setlocal numberwidth=6
1049 bnext
1050 wincmd w
1051 call assert_equal(4,&numberwidth)
1052 bnext
1053 call assert_equal(6,&numberwidth)
1054 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001055
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001056 " Test that if buffer is current, don't use the stale cached value
1057 " from the last time the buffer was displayed.
1058 split
1059 enew
1060 setlocal numberwidth=7
1061 bnext
1062 bnext
1063 setlocal numberwidth=8
1064 wincmd w
1065 call assert_equal(4,&numberwidth)
1066 bnext
1067 call assert_equal(8,&numberwidth)
1068 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001069
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001070 " Test value is not copied if window already has seen the buffer
1071 enew
1072 split
1073 setlocal numberwidth=9
1074 bnext
1075 setlocal numberwidth=10
1076 wincmd w
1077 call assert_equal(4,&numberwidth)
1078 bnext
1079 call assert_equal(4,&numberwidth)
1080 bw!
1081
1082 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001083endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001084
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001085def Test_split_copy_options()
1086 var values = [
1087 ['cursorbind', true, false],
1088 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1089 ['list', true, 0],
1090 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1091 ['number', true, 0],
1092 ['relativenumber', true, false],
1093 ['scrollbind', true, false],
1094 ['smoothscroll', true, false],
1095 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1096 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1097 ['wrap', false, true],
1098 ]
1099 if has('linebreak')
1100 values += [
1101 ['breakindent', true, false],
1102 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1103 ['linebreak', true, false],
1104 ['numberwidth', 7, 4],
1105 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1106 ]
1107 endif
1108 if has('rightleft')
1109 values += [
1110 ['rightleft', true, false],
1111 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1112 ]
1113 endif
1114 if has('statusline')
1115 values += [
1116 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1117 ]
1118 endif
1119 if has('spell')
1120 values += [
1121 ['spell', true, false],
1122 ]
1123 endif
1124 if has('syntax')
1125 values += [
1126 ['cursorcolumn', true, false],
1127 ['cursorline', true, false],
1128 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1129 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1130 ]
1131 endif
1132 if has('diff')
1133 values += [
1134 ['diff', true, false],
1135 ]
1136 endif
1137 if has('conceal')
1138 values += [
1139 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1140 ['conceallevel', '3', &conceallevel],
1141 ]
1142 endif
1143 if has('terminal')
1144 values += [
1145 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1146 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1147 ]
1148 endif
1149 if has('folding')
1150 values += [
1151 ['foldcolumn', 5, &foldcolumn],
1152 ['foldenable', false, true],
1153 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1154 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1155 ['foldlevel', 4, &foldlevel],
1156 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1157 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1158 ['foldminlines', 3, &foldminlines],
1159 ['foldnestmax', 17, &foldnestmax],
1160 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1161 ]
1162 endif
1163 if has('signs')
1164 values += [
1165 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1166 ]
1167 endif
1168
1169 # set options to non-default value
1170 for item in values
1171 exe $'&l:{item[0]} = {item[1]}'
1172 endfor
1173
1174 # check values are set in new window
1175 split
1176 for item in values
1177 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1178 endfor
1179
1180 # restore
1181 close
1182 for item in values
1183 exe $'&l:{item[0]} = {item[2]}'
1184 endfor
1185enddef
1186
Bram Moolenaarfc089602018-06-24 16:53:35 +02001187func Test_shortmess_F()
1188 new
1189 call assert_match('\[No Name\]', execute('file'))
1190 set shortmess+=F
1191 call assert_match('\[No Name\]', execute('file'))
1192 call assert_match('^\s*$', execute('file foo'))
1193 call assert_match('foo', execute('file'))
1194 set shortmess-=F
1195 call assert_match('bar', execute('file bar'))
1196 call assert_match('bar', execute('file'))
1197 set shortmess&
1198 bwipe
1199endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001200
1201func Test_shortmess_F2()
1202 e file1
1203 e file2
1204 call assert_match('file1', execute('bn', ''))
1205 call assert_match('file2', execute('bn', ''))
1206 set shortmess+=F
1207 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001208 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001209 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001210 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001211 set hidden
1212 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001213 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001214 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 set nohidden
1217 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001218 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001219 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 set shortmess&
1222 call assert_match('file1', execute('bn', ''))
1223 call assert_match('file2', execute('bn', ''))
1224 bwipe
1225 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001226 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001227endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001228
1229func Test_local_scrolloff()
1230 set so=5
1231 set siso=7
1232 split
1233 call assert_equal(5, &so)
1234 setlocal so=3
1235 call assert_equal(3, &so)
1236 wincmd w
1237 call assert_equal(5, &so)
1238 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001239 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001240 setlocal so<
1241 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001242 setglob so=8
1243 call assert_equal(8, &so)
1244 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001245 setlocal so=0
1246 call assert_equal(0, &so)
1247 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001248 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001249
1250 call assert_equal(7, &siso)
1251 setlocal siso=3
1252 call assert_equal(3, &siso)
1253 wincmd w
1254 call assert_equal(7, &siso)
1255 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001256 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001257 setlocal siso<
1258 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001259 setglob siso=4
1260 call assert_equal(4, &siso)
1261 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001262 setlocal siso=0
1263 call assert_equal(0, &siso)
1264 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001265 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001266
1267 close
1268 set so&
1269 set siso&
1270endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001271
1272func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001273 CheckFunction reltimefloat
1274
Bram Moolenaar449ac472019-04-03 21:42:35 +02001275 new
1276 call setline(1, 'empty')
1277 redraw
1278 set writedelay=10
1279 let start = reltime()
1280 call setline(1, repeat('x', 70))
1281 redraw
1282 let elapsed = reltimefloat(reltime(start))
1283 set writedelay=0
1284 " With 'writedelay' set should take at least 30 * 10 msec
1285 call assert_inrange(30 * 0.01, 999.0, elapsed)
1286
1287 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001288endfunc
1289
1290func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001291 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001292 set visualbell
1293 call assert_beeps('normal 0h')
1294 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001295 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001296endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001297
1298" Test for the 'write' option
1299func Test_write()
1300 new
1301 call setline(1, ['L1'])
1302 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001303 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001304 set write
1305 close!
1306endfunc
1307
1308" Test for 'buftype' option
1309func Test_buftype()
1310 new
1311 call setline(1, ['L1'])
1312 set buftype=nowrite
1313 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001314
1315 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1316 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001317 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001318 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1319 endfor
1320
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001321 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001322endfunc
1323
Bram Moolenaar578fe942020-02-27 21:32:51 +01001324" Test for the 'rightleftcmd' option
1325func Test_rightleftcmd()
1326 CheckFeature rightleft
1327 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001328
1329 let g:l = []
1330 func AddPos()
1331 call add(g:l, screencol())
1332 return ''
1333 endfunc
1334 cmap <expr> <F2> AddPos()
1335
zeertzjqbb404f52022-07-23 06:25:29 +01001336 set rightleftcmd=
1337 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1338 \ "\<Right>\<F2>\<Esc>", 'xt')
1339 call assert_equal([2, 5, 3, 4], g:l)
1340
1341 let g:l = []
1342 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001343 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1344 \ "\<Left>\<F2>\<Esc>", 'xt')
1345 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1346
1347 cunmap <F2>
1348 unlet g:l
1349 set rightleftcmd&
1350 set rightleft&
1351endfunc
1352
zeertzjq28c162f2022-08-14 14:49:50 +01001353" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001354func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001355 " redraw to avoid matching previous messages
1356 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001357 set debug=beep
1358 exe "normal \<C-c>"
1359 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001360 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001361 " also check a line above, with a certain window width the colon is there
1362 call assert_match('Test_debug_option:$',
1363 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001364 set debug&
1365endfunc
1366
Bram Moolenaar004a6782020-04-11 17:09:31 +02001367" Test for the default CDPATH option
1368func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001369 let after =<< trim [CODE]
1370 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1371 call writefile(v:errors, 'Xtestout')
1372 qall
1373 [CODE]
1374 if has('unix')
1375 let $CDPATH='/path/to/dir1:/path/to/dir2'
1376 else
1377 let $CDPATH='/path/to/dir1;/path/to/dir2'
1378 endif
1379 if RunVim([], after, '')
1380 call assert_equal([], readfile('Xtestout'))
1381 call delete('Xtestout')
1382 endif
1383endfunc
1384
1385" Test for setting keycodes using set
1386func Test_opt_set_keycode()
1387 call assert_fails('set <t_k1=l', 'E474:')
1388 call assert_fails('set <Home=l', 'E474:')
1389 set <t_k9>=abcd
1390 call assert_equal('abcd', &t_k9)
1391 set <t_k9>&
1392 set <F9>=xyz
1393 call assert_equal('xyz', &t_k9)
1394 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001395
1396 " should we test all of them?
1397 set t_Ce=testCe
1398 set t_Cs=testCs
1399 set t_Us=testUs
1400 set t_ds=testds
1401 set t_Ds=testDs
1402 call assert_equal('testCe', &t_Ce)
1403 call assert_equal('testCs', &t_Cs)
1404 call assert_equal('testUs', &t_Us)
1405 call assert_equal('testds', &t_ds)
1406 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001407endfunc
1408
1409" Test for changing options in a sandbox
1410func Test_opt_sandbox()
1411 for opt in ['backupdir', 'cdpath', 'exrc']
1412 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001413 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001414 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001415 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001416endfunc
1417
1418" Test for setting an option with local value to global value
1419func Test_opt_local_to_global()
1420 setglobal equalprg=gprg
1421 setlocal equalprg=lprg
1422 call assert_equal('gprg', &g:equalprg)
1423 call assert_equal('lprg', &l:equalprg)
1424 call assert_equal('lprg', &equalprg)
1425 set equalprg<
1426 call assert_equal('', &l:equalprg)
1427 call assert_equal('gprg', &equalprg)
1428 setglobal equalprg=gnewprg
1429 setlocal equalprg=lnewprg
1430 setlocal equalprg<
1431 call assert_equal('gnewprg', &l:equalprg)
1432 call assert_equal('gnewprg', &equalprg)
1433 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001434
1435 " Test for setting the global/local value of a boolean option
1436 setglobal autoread
1437 setlocal noautoread
1438 call assert_false(&autoread)
1439 set autoread<
1440 call assert_true(&autoread)
1441 setglobal noautoread
1442 setlocal autoread
1443 setlocal autoread<
1444 call assert_false(&autoread)
1445 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001446endfunc
1447
Dominique Pelle042414f2021-07-12 21:43:19 +02001448func Test_set_in_sandbox()
1449 " Some boolean options cannot be set in sandbox, some can.
1450 call assert_fails('sandbox set modelineexpr', 'E48:')
1451 sandbox set number
1452 call assert_true(&number)
1453 set number&
1454
1455 " Some boolean options cannot be set in sandbox, some can.
1456 if has('python') || has('python3')
1457 call assert_fails('sandbox set pyxversion=3', 'E48:')
1458 endif
1459 sandbox set tabstop=4
1460 call assert_equal(4, &tabstop)
1461 set tabstop&
1462
1463 " Some string options cannot be set in sandbox, some can.
1464 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1465 sandbox set filetype=perl
1466 call assert_equal('perl', &filetype)
1467 set filetype&
1468endfunc
1469
Bram Moolenaar004a6782020-04-11 17:09:31 +02001470" Test for incrementing, decrementing and multiplying a number option value
1471func Test_opt_num_op()
1472 set shiftwidth=4
1473 set sw+=2
1474 call assert_equal(6, &sw)
1475 set sw-=2
1476 call assert_equal(4, &sw)
1477 set sw^=2
1478 call assert_equal(8, &sw)
1479 set shiftwidth&
1480endfunc
1481
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001482" Test for setting option values using v:false and v:true
1483func Test_opt_boolean()
1484 set number&
1485 set number
1486 call assert_equal(1, &nu)
1487 set nonu
1488 call assert_equal(0, &nu)
1489 let &nu = v:true
1490 call assert_equal(1, &nu)
1491 let &nu = v:false
1492 call assert_equal(0, &nu)
1493 set number&
1494endfunc
1495
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001496" Test for the 'window' option
1497func Test_window_opt()
1498 " Needs only one open widow
1499 %bw!
1500 call setline(1, range(1, 8))
1501 set window=5
1502 exe "normal \<C-F>"
1503 call assert_equal(4, line('w0'))
1504 exe "normal \<C-F>"
1505 call assert_equal(7, line('w0'))
1506 exe "normal \<C-F>"
1507 call assert_equal(8, line('w0'))
1508 exe "normal \<C-B>"
1509 call assert_equal(5, line('w0'))
1510 exe "normal \<C-B>"
1511 call assert_equal(2, line('w0'))
1512 exe "normal \<C-B>"
1513 call assert_equal(1, line('w0'))
1514 set window=1
1515 exe "normal gg\<C-F>"
1516 call assert_equal(2, line('w0'))
1517 exe "normal \<C-F>"
1518 call assert_equal(3, line('w0'))
1519 exe "normal \<C-B>"
1520 call assert_equal(2, line('w0'))
1521 exe "normal \<C-B>"
1522 call assert_equal(1, line('w0'))
1523 enew!
1524 set window&
1525endfunc
1526
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001527" Test for the 'winminheight' option
1528func Test_opt_winminheight()
1529 only!
1530 let &winheight = &lines + 4
1531 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1532 call assert_true(&winminheight <= &lines)
1533 set winminheight&
1534 set winheight&
1535endfunc
1536
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001537func Test_opt_winminheight_term()
1538 CheckRunVimInTerminal
1539
1540 " The tabline should be taken into account.
1541 let lines =<< trim END
1542 set wmh=0 stal=2
1543 below sp | wincmd _
1544 below sp | wincmd _
1545 below sp | wincmd _
1546 below sp
1547 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001548 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001549 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1550 call term_sendkeys(buf, ":set wmh=1\n")
1551 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1552
1553 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001554endfunc
1555
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001556func Test_opt_winminheight_term_tabs()
1557 CheckRunVimInTerminal
1558
1559 " The tabline should be taken into account.
1560 let lines =<< trim END
1561 set wmh=0 stal=2
1562 split
1563 split
1564 split
1565 split
1566 tabnew
1567 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001568 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001569 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1570 call term_sendkeys(buf, ":set wmh=1\n")
1571 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1572
1573 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001574endfunc
1575
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001576" Test for the 'winminwidth' option
1577func Test_opt_winminwidth()
1578 only!
1579 let &winwidth = &columns + 4
1580 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1581 call assert_true(&winminwidth <= &columns)
1582 set winminwidth&
1583 set winwidth&
1584endfunc
1585
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001586" Test for setting option value containing spaces with isfname+=32
1587func Test_isfname_with_options()
1588 set isfname+=32
1589 setlocal keywordprg=:term\ help.exe
1590 call assert_equal(':term help.exe', &keywordprg)
1591 set isfname&
1592 setlocal keywordprg&
1593endfunc
1594
Bram Moolenaar74667062020-12-28 15:41:41 +01001595" Test that resetting laststatus does change scroll option
1596func Test_opt_reset_scroll()
1597 CheckRunVimInTerminal
1598 let vimrc =<< trim [CODE]
1599 set scroll=2
1600 set laststatus=2
1601 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001602 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001603 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1604 call term_sendkeys(buf, ":verbose set scroll?\n")
1605 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1606 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001607
1608 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001609 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001610endfunc
1611
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001612" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1613func Test_VIM_POSIX()
1614 let saved_VIM_POSIX = getenv("VIM_POSIX")
1615
1616 call setenv('VIM_POSIX', "1")
1617 let after =<< trim [CODE]
1618 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1619 qall
1620 [CODE]
1621 if RunVim([], after, '')
1622 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1623 \ 'AS'], readfile('X_VIM_POSIX'))
1624 endif
1625
1626 call setenv('VIM_POSIX', v:null)
1627 let after =<< trim [CODE]
1628 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1629 qall
1630 [CODE]
1631 if RunVim([], after, '')
1632 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1633 \ 'S'], readfile('X_VIM_POSIX'))
1634 endif
1635
1636 call delete('X_VIM_POSIX')
1637 call setenv('VIM_POSIX', saved_VIM_POSIX)
1638endfunc
1639
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001640" Test for setting an option to a Vi or Vim default
1641func Test_opt_default()
1642 set formatoptions&vi
1643 call assert_equal('vt', &formatoptions)
1644 set formatoptions&vim
1645 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001646
1647 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1648 set fencs=latin1
1649 set fencs&
1650 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1651 set fencs=latin1
1652 set all&
1653 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001654endfunc
1655
1656" Test for the 'cmdheight' option
1657func Test_cmdheight()
1658 %bw!
1659 let ht = &lines
1660 set cmdheight=9999
1661 call assert_equal(1, winheight(0))
1662 call assert_equal(ht - 1, &cmdheight)
1663 set cmdheight&
1664endfunc
1665
Dominique Pelle923dce22021-11-21 11:36:04 +00001666" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001667func Test_opt_control_char()
1668 set wildchar=^v
1669 call assert_equal("\<C-V>", nr2char(&wildchar))
1670 set wildcharm=^r
1671 call assert_equal("\<C-R>", nr2char(&wildcharm))
1672 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1673 set wildchar& wildcharm&
1674endfunc
1675
1676" Test for the 'errorbells' option
1677func Test_opt_errorbells()
1678 set errorbells
1679 call assert_beeps('s/a1b2/x1y2/')
1680 set noerrorbells
1681endfunc
1682
Dominique Pelle042414f2021-07-12 21:43:19 +02001683func Test_opt_scrolljump()
1684 help
1685 resize 10
1686
1687 " Test with positive 'scrolljump'.
1688 set scrolljump=2
1689 norm! Lj
1690 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1691 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1692 \ winsaveview())
1693
1694 " Test with negative 'scrolljump' (percentage of window height).
1695 set scrolljump=-40
1696 norm! ggLj
1697 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1698 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1699 \ winsaveview())
1700
1701 set scrolljump&
1702 bw
1703endfunc
1704
Bakudankun29f3a452021-12-11 12:28:08 +00001705" Test for the 'cdhome' option
1706func Test_opt_cdhome()
1707 if has('unix') || has('vms')
1708 throw 'Skipped: only works on non-Unix'
1709 endif
1710
1711 set cdhome&
1712 call assert_equal(0, &cdhome)
1713 set cdhome
1714
1715 " This paragraph is copied from Test_cd_no_arg().
1716 let path = getcwd()
1717 cd
1718 call assert_equal($HOME, getcwd())
1719 call assert_notequal(path, getcwd())
1720 exe 'cd ' .. fnameescape(path)
1721 call assert_equal(path, getcwd())
1722
1723 set cdhome&
1724endfunc
1725
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001726func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001727 CheckOption termguicolors
1728
1729 " Test default option completion
1730 set wildoptions=
1731 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1732 call assert_equal('"set termguicolors', @:)
1733
1734 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1735 call assert_equal('"set notermguicolors', @:)
1736
1737 " Test fuzzy option completion
1738 set wildoptions=fuzzy
1739 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1740 call assert_equal('"set termguicolors termencoding', @:)
1741
1742 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1743 call assert_equal('"set notermguicolors', @:)
1744
1745 set wildoptions=
1746endfunc
1747
Sean Dewar39c46b42022-05-12 17:44:29 +01001748func Test_switchbuf_reset()
1749 set switchbuf=useopen
1750 sblast
1751 call assert_equal(1, winnr('$'))
1752 set all&
1753 call assert_equal('', &switchbuf)
1754 sblast
1755 call assert_equal(2, winnr('$'))
1756 only!
1757endfunc
1758
zeertzjqfcba86c2022-09-22 13:57:32 +01001759" :set empty string for global 'keywordprg' falls back to ":help"
1760func Test_keywordprg_empty()
1761 let k = &keywordprg
1762 set keywordprg=man
1763 call assert_equal('man', &keywordprg)
1764 set keywordprg=
1765 call assert_equal(':help', &keywordprg)
1766 set keywordprg=man
1767 call assert_equal('man', &keywordprg)
1768 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1769 let &keywordprg = k
1770endfunc
1771
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001772" check that the very first buffer created does not have 'endoffile' set
1773func Test_endoffile_default()
1774 let after =<< trim [CODE]
1775 call writefile([execute('set eof?')], 'Xtestout')
1776 qall!
1777 [CODE]
1778 if RunVim([], after, '')
1779 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1780 endif
1781 call delete('Xtestout')
1782endfunc
1783
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001784" Test for setting the 'lines' and 'columns' options to a minimum value
1785func Test_set_min_lines_columns()
1786 let save_lines = &lines
1787 let save_columns = &columns
1788
1789 let after =<< trim END
1790 set nomore
1791 let msg = []
1792 let v:errmsg = ''
1793 silent! let &columns=0
1794 call add(msg, v:errmsg)
1795 silent! set columns=0
1796 call add(msg, v:errmsg)
1797 silent! call setbufvar('', '&columns', 0)
1798 call add(msg, v:errmsg)
1799 "call writefile(msg, 'XResultsetminlines')
1800 silent! let &lines=0
1801 call add(msg, v:errmsg)
1802 silent! set lines=0
1803 call add(msg, v:errmsg)
1804 silent! call setbufvar('', '&lines', 0)
1805 call add(msg, v:errmsg)
1806 call writefile(msg, 'XResultsetminlines')
1807 qall!
1808 END
1809 if RunVim([], after, '')
1810 call assert_equal(['E594: Need at least 12 columns',
1811 \ 'E594: Need at least 12 columns: columns=0',
1812 \ 'E594: Need at least 12 columns',
1813 \ 'E593: Need at least 2 lines',
1814 \ 'E593: Need at least 2 lines: lines=0',
1815 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1816 endif
1817
1818 call delete('XResultsetminlines')
1819 let &lines = save_lines
1820 let &columns = save_columns
1821endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001822
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001823" Test for reverting a string option value if the new value is invalid.
1824func Test_string_option_revert_on_failure()
1825 new
1826 let optlist = [
1827 \ ['ambiwidth', 'double', 'a123'],
1828 \ ['background', 'dark', 'a123'],
1829 \ ['backspace', 'eol', 'a123'],
1830 \ ['backupcopy', 'no', 'a123'],
1831 \ ['belloff', 'showmatch', 'a123'],
1832 \ ['breakindentopt', 'min:10', 'list'],
1833 \ ['bufhidden', 'wipe', 'a123'],
1834 \ ['buftype', 'nowrite', 'a123'],
1835 \ ['casemap', 'keepascii', 'a123'],
1836 \ ['cedit', "\<C-Y>", 'z'],
1837 \ ['colorcolumn', '10', 'z'],
1838 \ ['commentstring', '#%s', 'a123'],
1839 \ ['complete', '.,t', 'a'],
1840 \ ['completefunc', 'MyCmplFunc', '1a-'],
1841 \ ['completeopt', 'popup', 'a123'],
1842 \ ['completepopup', 'width:20', 'border'],
1843 \ ['concealcursor', 'v', 'xyz'],
1844 \ ['cpoptions', 'HJ', '~'],
1845 \ ['cryptmethod', 'zip', 'a123'],
1846 \ ['cursorlineopt', 'screenline', 'a123'],
1847 \ ['debug', 'throw', 'a123'],
1848 \ ['diffopt', 'iwhite', 'a123'],
1849 \ ['display', 'uhex', 'a123'],
1850 \ ['eadirection', 'hor', 'a123'],
1851 \ ['encoding', 'utf-8', 'a123'],
1852 \ ['eventignore', 'TextYankPost', 'a123'],
1853 \ ['fileencoding', 'utf-8', 'a123,'],
1854 \ ['fileformat', 'mac', 'a123'],
1855 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001856 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001857 \ ['fillchars', 'diff:~', 'a123'],
1858 \ ['foldclose', 'all', 'a123'],
1859 \ ['foldmarker', '[[[,]]]', '[[['],
1860 \ ['foldmethod', 'marker', 'a123'],
1861 \ ['foldopen', 'percent', 'a123'],
1862 \ ['formatoptions', 'an', '*'],
1863 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1864 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001865 \ ['highlight', '!:CursorColumn', '8:'],
1866 \ ['keymodel', 'stopsel', 'a123'],
1867 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1868 \ ['lispoptions', 'expr:1', 'a123'],
1869 \ ['listchars', 'tab:->', 'tab:'],
1870 \ ['matchpairs', '<:>', '<:'],
1871 \ ['mkspellmem', '100000,1000,100', '100000'],
1872 \ ['mouse', 'nvi', 'z'],
1873 \ ['mousemodel', 'extend', 'a123'],
1874 \ ['nrformats', 'alpha', 'a123'],
1875 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1876 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1877 \ ['previewpopup', 'width:20', 'a123'],
1878 \ ['printoptions', 'paper:A4', 'a123:'],
1879 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1880 \ ['rulerformat', '%l', '%['],
1881 \ ['scrollopt', 'hor,jump', 'a123'],
1882 \ ['selection', 'exclusive', 'a123'],
1883 \ ['selectmode', 'cmd', 'a123'],
1884 \ ['sessionoptions', 'options', 'a123'],
1885 \ ['shortmess', 'w', '2'],
1886 \ ['showbreak', '>>', "\x01"],
1887 \ ['showcmdloc', 'statusline', 'a123'],
1888 \ ['signcolumn', 'no', 'a123'],
1889 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1890 \ ['spellfile', 'MySpell.en.add', "\x01"],
1891 \ ['spelllang', 'en', "#"],
1892 \ ['spelloptions', 'camel', 'a123'],
1893 \ ['spellsuggest', 'double', 'a123'],
1894 \ ['splitkeep', 'topline', 'a123'],
1895 \ ['statusline', '%f', '%['],
1896 \ ['swapsync', 'sync', 'a123'],
1897 \ ['switchbuf', 'usetab', 'a123'],
1898 \ ['syntax', 'abc', 'a^b'],
1899 \ ['tabline', '%f', '%['],
1900 \ ['tagcase', 'ignore', 'a123'],
1901 \ ['tagfunc', 'MyTagFunc', '1a-'],
1902 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1903 \ ['viewoptions', 'options', 'a123'],
1904 \ ['virtualedit', 'onemore', 'a123'],
1905 \ ['whichwrap', '<,>', '{,}'],
1906 \ ['wildmode', 'list', 'a123'],
1907 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001908 \ ]
1909 if has('gui')
1910 call add(optlist, ['browsedir', 'buffer', 'a123'])
1911 endif
1912 if has('clipboard_working')
1913 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1914 endif
1915 if has('win32')
1916 call add(optlist, ['completeslash', 'slash', 'a123'])
1917 endif
1918 if has('cscope')
1919 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1920 endif
1921 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001922 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1923 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1924 endif
1925 if has('keymap')
1926 call add(optlist, ['keymap', 'greek', '[]'])
1927 endif
1928 if has('mouseshape')
1929 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1930 endif
1931 if has('win32') && has('gui')
1932 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1933 endif
1934 if has('rightleft')
1935 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1936 endif
1937 if has('terminal')
1938 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1939 call add(optlist, ['termwinsize', '24x80', '100'])
1940 endif
1941 if has('win32') && has('terminal')
1942 call add(optlist, ['termwintype', 'winpty', 'a123'])
1943 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001944 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001945 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00001946 endif
1947 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001948 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
1949 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001950 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001951 call add(optlist, ['ttymouse', 'xterm', 'a123'])
1952 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001953 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001954 call add(optlist, ['varsofttabstop', '12', 'a123'])
1955 call add(optlist, ['vartabstop', '4,20', '4,'])
1956 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00001957 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001958 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001959 endif
1960 for opt in optlist
1961 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001962 try
1963 exe $"let &{opt[0]} = '{opt[1]}'"
1964 catch
1965 call assert_report($"Caught {v:exception} with {opt->string()}")
1966 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001967 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
1968 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
1969 exe $"let &{opt[0]} = save_opt"
1970 endfor
1971 bw!
1972endfunc
1973
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02001974func Test_set_option_window_global_local()
1975 new Xbuffer1
1976 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
1977 setlocal scrolloff=2
1978 setglobal scrolloff=3
1979 setl modified
1980 " A new buffer has its own window-local options
1981 hide enew
1982 call assert_equal(-1, &l:scrolloff)
1983 call assert_equal(3, &g:scrolloff)
1984 " A new window opened with its own buffer-local options
1985 new
1986 call assert_equal(-1, &l:scrolloff)
1987 call assert_equal(3, &g:scrolloff)
1988 " Re-open Xbuffer1 and it should use
1989 " the previous set window-local options
1990 b Xbuffer1
1991 call assert_equal(2, &l:scrolloff)
1992 call assert_equal(3, &g:scrolloff)
1993 bw!
1994 bw!
1995 let &g:scrolloff = _gso
1996endfunc
1997
1998func GetGlobalLocalWindowOptions()
1999 new
2000 sil! r $VIMRUNTIME/doc/options.txt
2001 " Filter for global or local to window
2002 v/^'.*'.*\n.*global or local to window |global-local/d
2003 " get option value and type
2004 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2005 sil %s/empty/""/g
2006 " split the result
2007 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2008 bw!
2009 return result
2010endfunc
2011
2012func Test_set_option_window_global_local_all()
2013 new Xbuffer2
2014
2015 let optionlist = GetGlobalLocalWindowOptions()
2016 for [opt, type, default] in optionlist
2017 let _old = eval('&g:' .. opt)
2018 if type == 'string'
2019 if opt == 'fillchars'
2020 exe 'setl ' .. opt .. '=vert:+'
2021 exe 'setg ' .. opt .. '=vert:+,fold:+'
2022 elseif opt == 'listchars'
2023 exe 'setl ' .. opt .. '=tab:>>'
2024 exe 'setg ' .. opt .. '=tab:++'
2025 elseif opt == 'virtualedit'
2026 exe 'setl ' .. opt .. '=all'
2027 exe 'setg ' .. opt .. '=block'
2028 else
2029 exe 'setl ' .. opt .. '=Local'
2030 exe 'setg ' .. opt .. '=Global'
2031 endif
2032 elseif type == 'number'
2033 exe 'setl ' .. opt .. '=5'
2034 exe 'setg ' .. opt .. '=10'
2035 endif
2036 setl modified
2037 hide enew
2038 if type == 'string'
2039 call assert_equal('', eval('&l:' .. opt))
2040 if opt == 'fillchars'
2041 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2042 elseif opt == 'listchars'
2043 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2044 elseif opt == 'virtualedit'
2045 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2046 else
2047 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2048 endif
2049 elseif type == 'number'
2050 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2051 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2052 endif
2053 bw!
2054 exe 'let &g:' .. opt .. '=' .. default
2055 endfor
2056 bw!
2057endfunc
2058
Christian Brabandt757593c2023-08-22 21:44:10 +02002059func Test_paste_depending_options()
2060 " setting the paste option, resets all dependent options
2061 " and will be reported correctly using :verbose set <option>?
2062 let lines =<< trim [CODE]
2063 " set paste test
2064 set autoindent
2065 set expandtab
2066 " disabled, because depends on compiled feature set
2067 " set hkmap
2068 " set revins
2069 " set varsofttabstop=8,32,8
2070 set ruler
2071 set showmatch
2072 set smarttab
2073 set softtabstop=4
2074 set textwidth=80
2075 set wrapmargin=10
2076
2077 source Xvimrc_paste2
2078
2079 redir > Xoutput_paste
2080 verbose set expandtab?
2081 verbose setg expandtab?
2082 verbose setl expandtab?
2083 redir END
2084
2085 qall!
2086 [CODE]
2087
2088 call writefile(lines, 'Xvimrc_paste', 'D')
2089 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2090 if !RunVim([], lines, '--clean')
2091 return
2092 endif
2093
2094 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2095 call assert_equal('noexpandtab', result[0])
2096 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2097 call assert_equal('noexpandtab', result[2])
2098 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2099 call assert_equal('noexpandtab', result[4])
2100 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2101
2102 call delete('Xoutput_paste')
2103endfunc
2104
2105func Test_binary_depending_options()
2106 " setting the paste option, resets all dependent options
2107 " and will be reported correctly using :verbose set <option>?
2108 let lines =<< trim [CODE]
2109 " set binary test
2110 set expandtab
2111
2112 source Xvimrc_bin2
2113
2114 redir > Xoutput_bin
2115 verbose set expandtab?
2116 verbose setg expandtab?
2117 verbose setl expandtab?
2118 redir END
2119
2120 qall!
2121 [CODE]
2122
2123 call writefile(lines, 'Xvimrc_bin', 'D')
2124 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2125 if !RunVim([], lines, '--clean')
2126 return
2127 endif
2128
2129 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2130 call assert_equal('noexpandtab', result[0])
2131 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2132 call assert_equal('noexpandtab', result[2])
2133 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2134 call assert_equal('noexpandtab', result[4])
2135 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2136
2137 call delete('Xoutput_bin')
2138endfunc
2139
Gregory Anders3695d0e2023-09-29 20:17:20 +02002140func Test_set_keyprotocol()
2141 CheckNotGui
2142
2143 let term = &term
2144 set term=ansi
2145 call assert_equal('', &t_TI)
2146
2147 " Setting 'keyprotocol' should affect terminal codes without needing to
2148 " reset 'term'
2149 set keyprotocol+=ansi:kitty
2150 call assert_equal("\<Esc>[=1;1u", &t_TI)
2151 let &term = term
2152endfunc
2153
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002154" vim: shiftwidth=2 sts=2 expandtab