blob: 94c98fea11879913f0e4ba5651c9b6ba4d0061df [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
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200231func Test_wildchar_valid()
232 call assert_fails("set wildchar=<CR>", "E474:")
233 call assert_fails("set wildcharm=<C-C>", "E474:")
234endfunc
235
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100236func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100237 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100238 exe 'set ' . a:name . '=/usr/share/dict/words'
239 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
240 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
241 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
242 exe 'set ' . a:name . '=/usr/share/dict\ words'
243 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100244
245 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100246 call assert_fails("set " . a:name . "=/not&there", "E474:")
247 call assert_fails("set " . a:name . "=/not>there", "E474:")
248 call assert_fails("set " . a:name . "=/not.*there", "E474:")
249endfunc
250
Bram Moolenaar60629d62017-02-23 18:08:56 +0100251func Test_cinkeys()
252 " This used to cause invalid memory access
253 set cindent cinkeys=0
254 norm a
255 set cindent& cinkeys&
256endfunc
257
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100258func Test_dictionary()
259 call Check_dir_option('dictionary')
260endfunc
261
262func Test_thesaurus()
263 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100264endfun
265
Bram Moolenaar226c5342017-02-17 14:53:15 +0100266func Test_complete()
267 " Trailing single backslash used to cause invalid memory access.
268 set complete=s\
269 new
270 call feedkeys("i\<C-N>\<Esc>", 'xt')
271 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200272 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100273 set complete&
274endfun
275
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100276func Test_set_completion()
277 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
278 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
279
Bram Moolenaar297610b2019-12-27 17:20:55 +0100280 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
281 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
282
283 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
284 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
285
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100286 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
287 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100288 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100289 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100290
291 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100292 call assert_equal('"set invdiff invdigraph', @:)
293
294 " Expanding "set noinv" does nothing.
295 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
296 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100297
298 " Expand abbreviation of options.
299 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100300 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100301
302 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200303 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
304 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100305
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200306 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
307 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100308
309 " Expand key codes.
310 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
311 call assert_equal('"set <Help> <Home>', @:)
312
313 " Expand terminal options.
314 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200315 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200316 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100317
318 " Expand directories.
319 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
320 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200321 call assert_notmatch(' ./summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200322 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100323
324 " Expand files and directories.
325 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200326 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100327
328 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
329 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200330
331 " Expand files with spaces/commas in them. Make sure we delimit correctly.
332 "
333 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
334 " spaces requiring double escape, and commas need a single escape.
335 " 'dictionary' is a normal comma-separated option where only commas act as
336 " delimiters, and both space/comma need one single escape.
337 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
338 defer delete('Xfoo Xspace.txt')
339 defer delete('Xsp_dummy')
340 defer delete('Xbar,Xcomma.txt')
341 defer delete('Xcom_dummy')
342 call writefile([], 'Xfoo Xspace.txt')
343 call writefile([], 'Xsp_dummy')
344 call writefile([], 'Xbar,Xcomma.txt')
345 call writefile([], 'Xcom_dummy')
346
347 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
348 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
349 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
350 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
351 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
352 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
353
354 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
355 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
356 if has('win32')
357 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
358 " means we treat it as one file name.
359 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
360 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
361 else
362 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
363 " to split into a separate file name. You need '\\,' to escape the comma
364 " as part of the file name.
365 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
366 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
367
368 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
369 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
370 endif
371 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
372 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
373 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200374
375 " Expanding the option names
376 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
377 call assert_equal('"set all', @:)
378
379 " Expanding a second set of option names
380 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
381 call assert_equal('"set wrapscan all', @:)
382
383 " Expanding a special keycode
384 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
385 call assert_equal('"set <Home>', @:)
386
387 " Expanding an invalid special keycode
388 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
389 call assert_equal("\"set <abcd>\<Tab>", @:)
390
391 " Expanding a terminal keycode
392 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
393 call assert_equal("\"set t_AB", @:)
394
395 " Expanding an invalid option name
396 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
397 call assert_equal("\"set abcde=\<Tab>", @:)
398
399 " Expanding after a = for a boolean option
400 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
401 call assert_equal("\"set wrapscan=\<Tab>", @:)
402
403 " Expanding a numeric option
404 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
405 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
406
407 " Expanding a non-boolean option
408 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
409 call assert_equal("\"set invtabstop=", @:)
410
411 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200412 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
413 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
414 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
415 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200416
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200417 " Expanding value for 'key' is disallowed
418 if exists('+key')
419 set key=abcd
420 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
421 call assert_equal('"set key=', @:)
422 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal('"set key-=', @:)
424 set key=
425 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100426
427 " Expand values for 'filetype'
428 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
429 call assert_equal('"set filetype=sshdconfig', @:)
430 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
431 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200432
433 " Expand values for 'syntax'
434 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
435 call assert_equal('"set syntax=sshdconfig', @:)
436 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
437 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100438
439 if has('keymap')
440 " Expand values for 'keymap'
441 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
442 call assert_equal('"set keymap=accents', @:)
443 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
444 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
445 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100446endfunc
447
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200448" Test handling of expanding individual string option values
449func Test_set_completion_string_values()
450 "
451 " Test basic enum string options that have well-defined enum names
452 "
453
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200454 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
455 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
456 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200457
458 " Test that if a value is set, it will populate the results, but only if
459 " typed value is empty.
460 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200461 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
462 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200463 " If the set value is part of the enum list, it will show as the first
464 " result with no duplicate.
465 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200466 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200467 " If empty value, will just show the normal list without an empty item
468 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200469 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200470 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200471 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200472
473 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200474 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200475 " Also test the positioning of the expansion is correct
476 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
477 call assert_equal('"set display=truncate,lastline', @:)
478 set display&
479
480 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200481 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200482
483 " Test the other simple options to make sure they have basic auto-complete,
484 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200485 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200486 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200487 call assert_equal('indent', getcompletion('set backspace=', 'cmdline')[0])
488 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
489 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
490 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200491 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200492 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200493 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200494 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
495 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
496 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200497 if exists('+clipboard')
498 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
499 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200500 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
501 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200502 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200503 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200504 endif
505 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200506 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200507 endif
508 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200509 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200510 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200511 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
512 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
513 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200514 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200515 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200516 endif
517 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200518 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200519 endif
520 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200521 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200522 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200523 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
524 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
525 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200526 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200527 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200528 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200529 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200530 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200531 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
532 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
533 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200534 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200535 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200536 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200537 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200538 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200540 endif
541 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200542 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200543 endif
544 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200547 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
548 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
549 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
550 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200551 if exists('+tabclose')
552 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
553 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200554 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200555 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200556 endif
557 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200558 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200559 endif
560 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200561 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200562 endif
563 if exists('+ttymouse')
564 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200565 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200566 set ttymouse&
567 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200568 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
569 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
570 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
571 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200572 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200573 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200574 endif
575
576 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200577 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
578 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
579 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
580 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200581
zeertzjq1f025b02023-09-30 12:43:07 +0200582 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
583 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
584 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
585 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
586 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
587 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200588
589 "
590 " Unique string options below
591 "
592
593 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200594 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200595 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
596 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
597 set keyprotocol&
598
599 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200600 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
601 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200602 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
603 call assert_equal('"set previewpopup+=border:on', @:)
604 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
605 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200606 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200607 set previewpopup& completepopup&
608
609 " diffopt: special handling of algorithm:<alg_list>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200610 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
611 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
612 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200613
614 " highlight: special parsing, including auto-completing highlight groups
615 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200616 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
617 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
618 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
619 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
620 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200621 " If all the display modes are used up we should be suggesting nothing. Make
622 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
623 " and make sure nothing is suggested from that.
624 let hl_display_modes = join(
625 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
626 \ {idx, val -> val[1]}),
627 \ {idx, val -> val != ':'}),
628 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200629 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200630 " Test completion in middle of the line
631 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
632 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200633
634 "
635 " Test flag lists
636 "
637
638 " Test set=. Show the original value if nothing is typed after '='.
639 " Otherwise, the list should avoid showing what's already typed.
640 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200641 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200642 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200643 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
644 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200645
646 " Test set+=. Never show original value, and it also tries to avoid listing
647 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200648 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
649 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
650 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200651
652 " Test that the position of the expansion is correct (even if there are
653 " additional values after the current cursor)
654 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
655 call assert_equal('"set mouse=han', @:)
656 set mouse&
657
658 " Test that other flag list options have auto-complete, but don't
659 " exhaustively validate their results.
660 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200661 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200662 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200663 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
664 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200665 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200666 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200667 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200668 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
669 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200670
671 "
672 "Test set-=
673 "
674
675 " Normal single-value option just shows the existing value
676 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200677 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200678 set ambiwidth&
679
680 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200681 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200682 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200683 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200684 set t_Ce&
685
686 " Comma-separated lists should present each option
687 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200688 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
689 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
690 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200691 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200692 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200693 " Test empty option
694 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200695 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200696 set diffopt&
697
698 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200699 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200700
701 " Test files with commas in name are being parsed and escaped properly
702 set path=has\\\ space,file\\,with\\,comma,normal_file
703 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200704 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200705 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200706 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200707 endif
708 set path&
709
710 " Flag list should present orig value, then individual flags
711 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200712 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200713 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200714 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200715 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200716 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200717 " Test empty option
718 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200719 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200720 set mouse&
721
722 " 'whichwrap' is an odd case where it's both flag list and comma-separated
723 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200724 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200725 set ww&
726endfunc
727
zeertzjq4c7cb372023-06-14 16:39:54 +0100728func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100729 call assert_fails('set scroll=-1', 'E49:')
730 call assert_fails('set backupcopy=', 'E474:')
731 call assert_fails('set regexpengine=3', 'E474:')
732 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200733 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100734 call assert_fails('set colorcolumn=-a', 'E474:')
735 call assert_fails('set colorcolumn=a', 'E474:')
736 call assert_fails('set colorcolumn=1,', 'E474:')
737 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100738 call assert_fails('set cmdheight=-1', 'E487:')
739 call assert_fails('set cmdwinheight=-1', 'E487:')
740 if has('conceal')
741 call assert_fails('set conceallevel=-1', 'E487:')
742 call assert_fails('set conceallevel=4', 'E474:')
743 endif
744 call assert_fails('set helpheight=-1', 'E487:')
745 call assert_fails('set history=-1', 'E487:')
746 call assert_fails('set report=-1', 'E487:')
747 call assert_fails('set shiftwidth=-1', 'E487:')
748 call assert_fails('set sidescroll=-1', 'E487:')
749 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000750 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000751 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000752 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100753 call assert_fails('set textwidth=-1', 'E487:')
754 call assert_fails('set timeoutlen=-1', 'E487:')
755 call assert_fails('set updatecount=-1', 'E487:')
756 call assert_fails('set updatetime=-1', 'E487:')
757 call assert_fails('set winheight=-1', 'E487:')
758 call assert_fails('set tabstop!', 'E488:')
759 call assert_fails('set xxx', 'E518:')
760 call assert_fails('set beautify?', 'E519:')
761 call assert_fails('set undolevels=x', 'E521:')
762 call assert_fails('set tabstop=', 'E521:')
763 call assert_fails('set comments=-', 'E524:')
764 call assert_fails('set comments=a', 'E525:')
765 call assert_fails('set foldmarker=x', 'E536:')
766 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000767 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100768 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100769 call assert_fails('set rulerformat=%-', 'E539:')
770 call assert_fails('set rulerformat=%(', 'E542:')
771 call assert_fails('set rulerformat=%15(%%', 'E542:')
772 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100773 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100774 call assert_fails('set statusline=%{%', 'E540:')
775 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100776 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100777 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100778 call assert_fails('set tabline=%$', 'E539:')
779 call assert_fails('set tabline=%{', 'E540:')
780 call assert_fails('set tabline=%{%', 'E540:')
781 call assert_fails('set tabline=%{%}', 'E539:')
782 call assert_fails('set tabline=%(', 'E542:')
783 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100784
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100785 if has('cursorshape')
786 " This invalid value for 'guicursor' used to cause Vim to crash.
787 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
788 call assert_fails('set guicursor=i-ci', 'E545:')
789 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100790 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100791 call assert_fails('set guicursor=r-cr:horx', 'E548:')
792 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
793 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100794 if has('mouseshape')
795 call assert_fails('se mouseshape=i-r:x', 'E547:')
796 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000797
798 " Test for 'backupext' and 'patchmode' set to the same value
799 set backupext=.bak
800 set patchmode=.patch
801 call assert_fails('set patchmode=.bak', 'E589:')
802 call assert_equal('.patch', &patchmode)
803 call assert_fails('set backupext=.patch', 'E589:')
804 call assert_equal('.bak', &backupext)
805 set backupext& patchmode&
806
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100807 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200808 set winminheight& winheight&
809 set winheight=10 winminheight=10
810 call assert_fails('set winheight=9', 'E591:')
811 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100812 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200813 set winminwidth& winwidth&
814 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
815 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100816 call assert_fails("set showbreak=\x01", 'E595:')
817 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200818 call assert_fails('set tabstop??', 'E488:')
819 call assert_fails('set wrapscan!!', 'E488:')
820 call assert_fails('set tabstop&&', 'E488:')
821 call assert_fails('set wrapscan<<', 'E488:')
822 call assert_fails('set wrapscan=1', 'E474:')
823 call assert_fails('set autoindent@', 'E488:')
824 call assert_fails('set wildchar=<abc>', 'E474:')
825 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200826 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100827 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200828 call assert_fails('set pyxversion=6', 'E474:')
829 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100830 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200831 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100832 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
833 call assert_fails('set foldmarker={{{,', 'E474:')
834 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100835 setlocal listchars=trail
836 call assert_fails('set ambiwidth=double', 'E834:')
837 setlocal listchars=trail:-
838 setglobal listchars=trail
839 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100840 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100841 setlocal fillchars=stl
842 call assert_fails('set ambiwidth=double', 'E835:')
843 setlocal fillchars=stl:-
844 setglobal fillchars=stl
845 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100846 set fillchars&
847 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
848 set nomodifiable
849 call assert_fails('set fileencoding=latin1', 'E21:')
850 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200851 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000852 call assert_fails('let &formatoptions = "?"', 'E539:')
853 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100854 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
855 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
856 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
857 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
858 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
859 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100860endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100861
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000862func Test_set_encoding()
863 let save_encoding = &encoding
864
865 set enc=iso8859-1
866 call assert_equal('latin1', &enc)
867 set enc=iso8859_1
868 call assert_equal('latin1', &enc)
869 set enc=iso-8859-1
870 call assert_equal('latin1', &enc)
871 set enc=iso_8859_1
872 call assert_equal('latin1', &enc)
873 set enc=iso88591
874 call assert_equal('latin1', &enc)
875 set enc=iso8859
876 call assert_equal('latin1', &enc)
877 set enc=iso-8859
878 call assert_equal('latin1', &enc)
879 set enc=iso_8859
880 call assert_equal('latin1', &enc)
881 call assert_fails('set enc=iso8858', 'E474:')
882 call assert_equal('latin1', &enc)
883
884 let &encoding = save_encoding
885endfunc
886
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200887func CheckWasSet(name)
888 let verb_cm = execute('verbose set ' .. a:name .. '?')
889 call assert_match('Last set from.*test_options.vim', verb_cm)
890endfunc
891func CheckWasNotSet(name)
892 let verb_cm = execute('verbose set ' .. a:name .. '?')
893 call assert_notmatch('Last set from', verb_cm)
894endfunc
895
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200896" Must be executed before other tests that set 'term'.
897func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200898 CheckNotGui
899
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200900 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200901
902 let term_save = &term
903 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200904 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200905 let &term = term_save
906endfunc
907
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200908func Test_copy_context()
909 setlocal list
910 call CheckWasSet('list')
911 split
912 call CheckWasSet('list')
913 quit
914 setlocal nolist
915
916 set ai
917 call CheckWasSet('ai')
918 set filetype=perl
919 call CheckWasSet('filetype')
920 set fo=tcroq
921 call CheckWasSet('fo')
922
923 split Xsomebuf
924 call CheckWasSet('ai')
925 call CheckWasNotSet('filetype')
926 call CheckWasSet('fo')
927endfunc
928
Bram Moolenaar67391142017-02-19 21:07:04 +0100929func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200930 CheckUnix
931 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200932
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200933 " Setting 'ttytype' used to cause a double-free when exiting vim and
934 " when vim is compiled with -DEXITFREE.
935 set ttytype=ansi
936 call assert_equal('ansi', &ttytype)
937 call assert_equal(&ttytype, &term)
938 set ttytype=xterm
939 call assert_equal('xterm', &ttytype)
940 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200941 try
942 set ttytype=
943 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100944 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200945 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200946
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200947 " Some systems accept any terminal name and return dumb settings,
948 " check for failure of finding the entry and for missing 'cm' entry.
949 try
950 set ttytype=xxx
951 call assert_report('set ttytype=xxx did not fail')
952 catch /E522\|E437/
953 endtry
954
955 set ttytype&
956 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200957
958 if has('gui') && !has('gui_running')
959 call assert_fails('set term=gui', 'E531:')
960 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100961endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100962
963func Test_set_all()
964 set tw=75
965 set iskeyword=a-z,A-Z
966 set nosplitbelow
967 let out = execute('set all')
968 call assert_match('textwidth=75', out)
969 call assert_match('iskeyword=a-z,A-Z', out)
970 call assert_match('nosplitbelow', out)
971 set tw& iskeyword& splitbelow&
972endfunc
973
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100974func Test_set_one_column()
975 let out_mult = execute('set all')->split("\n")
976 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100977 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +0100978 call assert_equal(out_one[0], '--- Options ---')
979 let options = out_one[1:]->mapnew({_, line -> line[2:]})
980 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100981endfunc
982
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100983func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200984 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100985 if filereadable('opt_test.vim')
986 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100987 else
988 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100989 endif
990endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200991
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100992func Test_renderoptions()
993 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
994 " Doesn't hurt to do this on a non-Windows system.
995 if windowsversion() !~ '^[345]\.'
996 set renderoptions=type:directx
997 set rop=type:directx
998 endif
999endfunc
1000
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001001func ResetIndentexpr()
1002 set indentexpr=
1003endfunc
1004
1005func Test_set_indentexpr()
1006 " this was causing usage of freed memory
1007 set indentexpr=ResetIndentexpr()
1008 new
1009 call feedkeys("i\<c-f>", 'x')
1010 call assert_equal('', &indentexpr)
1011 bwipe!
1012endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001013
1014func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001015 " Option 'backupskip' may contain several comma-separated path
1016 " specifications if one or more of the environment variables TMPDIR, TMP,
1017 " or TEMP is defined. To simplify testing, convert the string value into a
1018 " list.
1019 let bsklist = split(&bsk, ',')
1020
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001021 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001022 let found = (index(bsklist, '/private/tmp/*') >= 0)
1023 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001024 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001025 let found = (index(bsklist, '/tmp/*') >= 0)
1026 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001027 endif
1028
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001029 " If our test platform is Windows, the path(s) in option bsk will use
1030 " backslash for the path separator and the components could be in short
1031 " (8.3) format. As such, we need to replace the backslashes with forward
1032 " slashes and convert the path components to long format. The expand()
1033 " function will do this but it cannot handle comma-separated paths. This is
1034 " why bsk was converted from a string into a list of strings above.
1035 "
1036 " One final complication is that the wildcard "/*" is at the end of each
1037 " path and so expand() might return a list of matching files. To prevent
1038 " this, we need to remove the wildcard before calling expand() and then
1039 " append it afterwards.
1040 if has('win32')
1041 let item_nbr = 0
1042 while item_nbr < len(bsklist)
1043 let path_spec = bsklist[item_nbr]
1044 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1045 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1046 let bsklist[item_nbr] = path_spec . '/*'
1047 let item_nbr += 1
1048 endwhile
1049 endif
1050
1051 " Option bsk will also include these environment variables if defined.
1052 " If they're defined, verify they appear in the option value.
1053 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001054 if exists(var)
1055 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001056 let varvalue = substitute(varvalue, '/$', '', '')
1057 let varvalue .= '/*'
1058 let found = (index(bsklist, varvalue) >= 0)
1059 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001060 endif
1061 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001062
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001063 " Duplicates from environment variables should be filtered out (option has
1064 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1065 " so that we see what happens on startup.
1066 let after =<< trim [CODE]
1067 let bsklist = split(&backupskip, ',')
1068 call assert_equal(uniq(copy(bsklist)), bsklist)
1069 call writefile(['errors:'] + v:errors, 'Xtestout')
1070 qall
1071 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001072 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001073 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1074
1075 let saveenv = {}
1076 for var in ['TMPDIR', 'TMP', 'TEMP']
1077 let saveenv[var] = getenv(var)
1078 call setenv(var, '/duplicate/path')
1079 endfor
1080
1081 exe 'silent !' . cmd
1082 call assert_equal(['errors:'], readfile('Xtestout'))
1083
1084 " restore environment variables
1085 for var in ['TMPDIR', 'TMP', 'TEMP']
1086 call setenv(var, saveenv[var])
1087 endfor
1088
1089 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001090
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001091 " Duplicates should be filtered out (option has P_NODUP)
1092 let backupskip = &backupskip
1093 set backupskip=
1094 set backupskip+=/test/dir
1095 set backupskip+=/other/dir
1096 set backupskip+=/test/dir
1097 call assert_equal('/test/dir,/other/dir', &backupskip)
1098 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001099endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001100
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001101func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001102 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001103
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001104 " Test copy option from current buffer in window
1105 split
1106 enew
1107 setlocal numberwidth=5
1108 wincmd w
1109 call assert_equal(4,&numberwidth)
1110 bnext
1111 call assert_equal(5,&numberwidth)
1112 bw!
1113 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001114
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001115 " Test copy value from window that used to be display the buffer
1116 split
1117 enew
1118 setlocal numberwidth=6
1119 bnext
1120 wincmd w
1121 call assert_equal(4,&numberwidth)
1122 bnext
1123 call assert_equal(6,&numberwidth)
1124 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001125
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001126 " Test that if buffer is current, don't use the stale cached value
1127 " from the last time the buffer was displayed.
1128 split
1129 enew
1130 setlocal numberwidth=7
1131 bnext
1132 bnext
1133 setlocal numberwidth=8
1134 wincmd w
1135 call assert_equal(4,&numberwidth)
1136 bnext
1137 call assert_equal(8,&numberwidth)
1138 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001139
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001140 " Test value is not copied if window already has seen the buffer
1141 enew
1142 split
1143 setlocal numberwidth=9
1144 bnext
1145 setlocal numberwidth=10
1146 wincmd w
1147 call assert_equal(4,&numberwidth)
1148 bnext
1149 call assert_equal(4,&numberwidth)
1150 bw!
1151
1152 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001153endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001154
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001155def Test_split_copy_options()
1156 var values = [
1157 ['cursorbind', true, false],
1158 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1159 ['list', true, 0],
1160 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1161 ['number', true, 0],
1162 ['relativenumber', true, false],
1163 ['scrollbind', true, false],
1164 ['smoothscroll', true, false],
1165 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1166 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1167 ['wrap', false, true],
1168 ]
1169 if has('linebreak')
1170 values += [
1171 ['breakindent', true, false],
1172 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1173 ['linebreak', true, false],
1174 ['numberwidth', 7, 4],
1175 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1176 ]
1177 endif
1178 if has('rightleft')
1179 values += [
1180 ['rightleft', true, false],
1181 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1182 ]
1183 endif
1184 if has('statusline')
1185 values += [
1186 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1187 ]
1188 endif
1189 if has('spell')
1190 values += [
1191 ['spell', true, false],
1192 ]
1193 endif
1194 if has('syntax')
1195 values += [
1196 ['cursorcolumn', true, false],
1197 ['cursorline', true, false],
1198 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1199 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1200 ]
1201 endif
1202 if has('diff')
1203 values += [
1204 ['diff', true, false],
1205 ]
1206 endif
1207 if has('conceal')
1208 values += [
1209 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1210 ['conceallevel', '3', &conceallevel],
1211 ]
1212 endif
1213 if has('terminal')
1214 values += [
1215 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1216 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1217 ]
1218 endif
1219 if has('folding')
1220 values += [
1221 ['foldcolumn', 5, &foldcolumn],
1222 ['foldenable', false, true],
1223 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1224 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1225 ['foldlevel', 4, &foldlevel],
1226 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1227 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1228 ['foldminlines', 3, &foldminlines],
1229 ['foldnestmax', 17, &foldnestmax],
1230 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1231 ]
1232 endif
1233 if has('signs')
1234 values += [
1235 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1236 ]
1237 endif
1238
1239 # set options to non-default value
1240 for item in values
1241 exe $'&l:{item[0]} = {item[1]}'
1242 endfor
1243
1244 # check values are set in new window
1245 split
1246 for item in values
1247 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1248 endfor
1249
1250 # restore
1251 close
1252 for item in values
1253 exe $'&l:{item[0]} = {item[2]}'
1254 endfor
1255enddef
1256
Bram Moolenaarfc089602018-06-24 16:53:35 +02001257func Test_shortmess_F()
1258 new
1259 call assert_match('\[No Name\]', execute('file'))
1260 set shortmess+=F
1261 call assert_match('\[No Name\]', execute('file'))
1262 call assert_match('^\s*$', execute('file foo'))
1263 call assert_match('foo', execute('file'))
1264 set shortmess-=F
1265 call assert_match('bar', execute('file bar'))
1266 call assert_match('bar', execute('file'))
1267 set shortmess&
1268 bwipe
1269endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001270
1271func Test_shortmess_F2()
1272 e file1
1273 e file2
1274 call assert_match('file1', execute('bn', ''))
1275 call assert_match('file2', execute('bn', ''))
1276 set shortmess+=F
1277 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001278 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001279 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001280 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001281 set hidden
1282 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001283 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001284 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001285 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001286 set nohidden
1287 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001288 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001289 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001290 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001291 set shortmess&
1292 call assert_match('file1', execute('bn', ''))
1293 call assert_match('file2', execute('bn', ''))
1294 bwipe
1295 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001296 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001297endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001298
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001299func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001300 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001301
1302 set hidden
1303 set autoread
1304 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001305 e Xotherfile
1306 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001307 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001308 echo ''
1309
1310 if has('nanotime')
1311 sleep 10m
1312 else
1313 sleep 2
1314 endif
1315 call writefile(['bar'], 'X_dummy')
1316 bprev
1317 call assert_equal('', Screenline(&lines))
1318 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1319
1320 if has('nanotime')
1321 sleep 10m
1322 else
1323 sleep 2
1324 endif
1325 call writefile(['baz'], 'X_dummy')
1326 checktime
1327 call assert_equal('', Screenline(&lines))
1328 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001329
1330 set shortmess&
1331 set autoread&
1332 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001333 bwipe X_dummy
1334 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001335endfunc
1336
Bram Moolenaar375e3392019-01-31 18:26:10 +01001337func Test_local_scrolloff()
1338 set so=5
1339 set siso=7
1340 split
1341 call assert_equal(5, &so)
1342 setlocal so=3
1343 call assert_equal(3, &so)
1344 wincmd w
1345 call assert_equal(5, &so)
1346 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001347 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001348 setlocal so<
1349 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001350 setglob so=8
1351 call assert_equal(8, &so)
1352 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001353 setlocal so=0
1354 call assert_equal(0, &so)
1355 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001356 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001357
1358 call assert_equal(7, &siso)
1359 setlocal siso=3
1360 call assert_equal(3, &siso)
1361 wincmd w
1362 call assert_equal(7, &siso)
1363 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001364 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001365 setlocal siso<
1366 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001367 setglob siso=4
1368 call assert_equal(4, &siso)
1369 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001370 setlocal siso=0
1371 call assert_equal(0, &siso)
1372 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001373 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001374
1375 close
1376 set so&
1377 set siso&
1378endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001379
1380func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001381 CheckFunction reltimefloat
1382
Bram Moolenaar449ac472019-04-03 21:42:35 +02001383 new
1384 call setline(1, 'empty')
1385 redraw
1386 set writedelay=10
1387 let start = reltime()
1388 call setline(1, repeat('x', 70))
1389 redraw
1390 let elapsed = reltimefloat(reltime(start))
1391 set writedelay=0
1392 " With 'writedelay' set should take at least 30 * 10 msec
1393 call assert_inrange(30 * 0.01, 999.0, elapsed)
1394
1395 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001396endfunc
1397
1398func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001399 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001400 set visualbell
1401 call assert_beeps('normal 0h')
1402 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001403 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001404endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001405
1406" Test for the 'write' option
1407func Test_write()
1408 new
1409 call setline(1, ['L1'])
1410 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001411 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001412 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001413 " close swapfile
1414 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001415endfunc
1416
1417" Test for 'buftype' option
1418func Test_buftype()
1419 new
1420 call setline(1, ['L1'])
1421 set buftype=nowrite
1422 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001423
1424 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1425 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001426 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001427 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1428 endfor
1429
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001430 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001431endfunc
1432
Bram Moolenaar578fe942020-02-27 21:32:51 +01001433" Test for the 'rightleftcmd' option
1434func Test_rightleftcmd()
1435 CheckFeature rightleft
1436 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001437
1438 let g:l = []
1439 func AddPos()
1440 call add(g:l, screencol())
1441 return ''
1442 endfunc
1443 cmap <expr> <F2> AddPos()
1444
zeertzjqbb404f52022-07-23 06:25:29 +01001445 set rightleftcmd=
1446 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1447 \ "\<Right>\<F2>\<Esc>", 'xt')
1448 call assert_equal([2, 5, 3, 4], g:l)
1449
1450 let g:l = []
1451 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001452 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1453 \ "\<Left>\<F2>\<Esc>", 'xt')
1454 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1455
1456 cunmap <F2>
1457 unlet g:l
1458 set rightleftcmd&
1459 set rightleft&
1460endfunc
1461
zeertzjq28c162f2022-08-14 14:49:50 +01001462" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001463func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001464 " redraw to avoid matching previous messages
1465 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001466 set debug=beep
1467 exe "normal \<C-c>"
1468 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001469 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001470 " also check a line above, with a certain window width the colon is there
1471 call assert_match('Test_debug_option:$',
1472 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001473 set debug&
1474endfunc
1475
Bram Moolenaar004a6782020-04-11 17:09:31 +02001476" Test for the default CDPATH option
1477func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001478 let after =<< trim [CODE]
1479 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1480 call writefile(v:errors, 'Xtestout')
1481 qall
1482 [CODE]
1483 if has('unix')
1484 let $CDPATH='/path/to/dir1:/path/to/dir2'
1485 else
1486 let $CDPATH='/path/to/dir1;/path/to/dir2'
1487 endif
1488 if RunVim([], after, '')
1489 call assert_equal([], readfile('Xtestout'))
1490 call delete('Xtestout')
1491 endif
1492endfunc
1493
1494" Test for setting keycodes using set
1495func Test_opt_set_keycode()
1496 call assert_fails('set <t_k1=l', 'E474:')
1497 call assert_fails('set <Home=l', 'E474:')
1498 set <t_k9>=abcd
1499 call assert_equal('abcd', &t_k9)
1500 set <t_k9>&
1501 set <F9>=xyz
1502 call assert_equal('xyz', &t_k9)
1503 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001504
1505 " should we test all of them?
1506 set t_Ce=testCe
1507 set t_Cs=testCs
1508 set t_Us=testUs
1509 set t_ds=testds
1510 set t_Ds=testDs
1511 call assert_equal('testCe', &t_Ce)
1512 call assert_equal('testCs', &t_Cs)
1513 call assert_equal('testUs', &t_Us)
1514 call assert_equal('testds', &t_ds)
1515 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001516endfunc
1517
1518" Test for changing options in a sandbox
1519func Test_opt_sandbox()
1520 for opt in ['backupdir', 'cdpath', 'exrc']
1521 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001522 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001523 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001524 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001525endfunc
1526
1527" Test for setting an option with local value to global value
1528func Test_opt_local_to_global()
1529 setglobal equalprg=gprg
1530 setlocal equalprg=lprg
1531 call assert_equal('gprg', &g:equalprg)
1532 call assert_equal('lprg', &l:equalprg)
1533 call assert_equal('lprg', &equalprg)
1534 set equalprg<
1535 call assert_equal('', &l:equalprg)
1536 call assert_equal('gprg', &equalprg)
1537 setglobal equalprg=gnewprg
1538 setlocal equalprg=lnewprg
1539 setlocal equalprg<
1540 call assert_equal('gnewprg', &l:equalprg)
1541 call assert_equal('gnewprg', &equalprg)
1542 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001543
1544 " Test for setting the global/local value of a boolean option
1545 setglobal autoread
1546 setlocal noautoread
1547 call assert_false(&autoread)
1548 set autoread<
1549 call assert_true(&autoread)
1550 setglobal noautoread
1551 setlocal autoread
1552 setlocal autoread<
1553 call assert_false(&autoread)
1554 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001555endfunc
1556
Dominique Pelle042414f2021-07-12 21:43:19 +02001557func Test_set_in_sandbox()
1558 " Some boolean options cannot be set in sandbox, some can.
1559 call assert_fails('sandbox set modelineexpr', 'E48:')
1560 sandbox set number
1561 call assert_true(&number)
1562 set number&
1563
1564 " Some boolean options cannot be set in sandbox, some can.
1565 if has('python') || has('python3')
1566 call assert_fails('sandbox set pyxversion=3', 'E48:')
1567 endif
1568 sandbox set tabstop=4
1569 call assert_equal(4, &tabstop)
1570 set tabstop&
1571
1572 " Some string options cannot be set in sandbox, some can.
1573 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1574 sandbox set filetype=perl
1575 call assert_equal('perl', &filetype)
1576 set filetype&
1577endfunc
1578
Bram Moolenaar004a6782020-04-11 17:09:31 +02001579" Test for incrementing, decrementing and multiplying a number option value
1580func Test_opt_num_op()
1581 set shiftwidth=4
1582 set sw+=2
1583 call assert_equal(6, &sw)
1584 set sw-=2
1585 call assert_equal(4, &sw)
1586 set sw^=2
1587 call assert_equal(8, &sw)
1588 set shiftwidth&
1589endfunc
1590
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001591" Test for setting option values using v:false and v:true
1592func Test_opt_boolean()
1593 set number&
1594 set number
1595 call assert_equal(1, &nu)
1596 set nonu
1597 call assert_equal(0, &nu)
1598 let &nu = v:true
1599 call assert_equal(1, &nu)
1600 let &nu = v:false
1601 call assert_equal(0, &nu)
1602 set number&
1603endfunc
1604
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001605" Test for the 'window' option
1606func Test_window_opt()
1607 " Needs only one open widow
1608 %bw!
1609 call setline(1, range(1, 8))
1610 set window=5
1611 exe "normal \<C-F>"
1612 call assert_equal(4, line('w0'))
1613 exe "normal \<C-F>"
1614 call assert_equal(7, line('w0'))
1615 exe "normal \<C-F>"
1616 call assert_equal(8, line('w0'))
1617 exe "normal \<C-B>"
1618 call assert_equal(5, line('w0'))
1619 exe "normal \<C-B>"
1620 call assert_equal(2, line('w0'))
1621 exe "normal \<C-B>"
1622 call assert_equal(1, line('w0'))
1623 set window=1
1624 exe "normal gg\<C-F>"
1625 call assert_equal(2, line('w0'))
1626 exe "normal \<C-F>"
1627 call assert_equal(3, line('w0'))
1628 exe "normal \<C-B>"
1629 call assert_equal(2, line('w0'))
1630 exe "normal \<C-B>"
1631 call assert_equal(1, line('w0'))
1632 enew!
1633 set window&
1634endfunc
1635
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001636" Test for the 'winminheight' option
1637func Test_opt_winminheight()
1638 only!
1639 let &winheight = &lines + 4
1640 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1641 call assert_true(&winminheight <= &lines)
1642 set winminheight&
1643 set winheight&
1644endfunc
1645
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001646func Test_opt_winminheight_term()
1647 CheckRunVimInTerminal
1648
1649 " The tabline should be taken into account.
1650 let lines =<< trim END
1651 set wmh=0 stal=2
1652 below sp | wincmd _
1653 below sp | wincmd _
1654 below sp | wincmd _
1655 below sp
1656 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001657 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001658 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1659 call term_sendkeys(buf, ":set wmh=1\n")
1660 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1661
1662 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001663endfunc
1664
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001665func Test_opt_winminheight_term_tabs()
1666 CheckRunVimInTerminal
1667
1668 " The tabline should be taken into account.
1669 let lines =<< trim END
1670 set wmh=0 stal=2
1671 split
1672 split
1673 split
1674 split
1675 tabnew
1676 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001677 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001678 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1679 call term_sendkeys(buf, ":set wmh=1\n")
1680 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1681
1682 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001683endfunc
1684
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001685" Test for the 'winminwidth' option
1686func Test_opt_winminwidth()
1687 only!
1688 let &winwidth = &columns + 4
1689 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1690 call assert_true(&winminwidth <= &columns)
1691 set winminwidth&
1692 set winwidth&
1693endfunc
1694
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001695" Test for setting option value containing spaces with isfname+=32
1696func Test_isfname_with_options()
1697 set isfname+=32
1698 setlocal keywordprg=:term\ help.exe
1699 call assert_equal(':term help.exe', &keywordprg)
1700 set isfname&
1701 setlocal keywordprg&
1702endfunc
1703
Bram Moolenaar74667062020-12-28 15:41:41 +01001704" Test that resetting laststatus does change scroll option
1705func Test_opt_reset_scroll()
1706 CheckRunVimInTerminal
1707 let vimrc =<< trim [CODE]
1708 set scroll=2
1709 set laststatus=2
1710 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001711 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001712 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1713 call term_sendkeys(buf, ":verbose set scroll?\n")
1714 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1715 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001716
1717 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001718 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001719endfunc
1720
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001721" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1722func Test_VIM_POSIX()
1723 let saved_VIM_POSIX = getenv("VIM_POSIX")
1724
1725 call setenv('VIM_POSIX', "1")
1726 let after =<< trim [CODE]
1727 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1728 qall
1729 [CODE]
1730 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02001731 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001732 \ 'AS'], readfile('X_VIM_POSIX'))
1733 endif
1734
1735 call setenv('VIM_POSIX', v:null)
1736 let after =<< trim [CODE]
1737 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1738 qall
1739 [CODE]
1740 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02001741 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001742 \ 'S'], readfile('X_VIM_POSIX'))
1743 endif
1744
1745 call delete('X_VIM_POSIX')
1746 call setenv('VIM_POSIX', saved_VIM_POSIX)
1747endfunc
1748
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001749" Test for setting an option to a Vi or Vim default
1750func Test_opt_default()
1751 set formatoptions&vi
1752 call assert_equal('vt', &formatoptions)
1753 set formatoptions&vim
1754 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001755
1756 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1757 set fencs=latin1
1758 set fencs&
1759 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1760 set fencs=latin1
1761 set all&
1762 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001763endfunc
1764
1765" Test for the 'cmdheight' option
1766func Test_cmdheight()
1767 %bw!
1768 let ht = &lines
1769 set cmdheight=9999
1770 call assert_equal(1, winheight(0))
1771 call assert_equal(ht - 1, &cmdheight)
1772 set cmdheight&
1773endfunc
1774
Dominique Pelle923dce22021-11-21 11:36:04 +00001775" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001776func Test_opt_control_char()
1777 set wildchar=^v
1778 call assert_equal("\<C-V>", nr2char(&wildchar))
1779 set wildcharm=^r
1780 call assert_equal("\<C-R>", nr2char(&wildcharm))
1781 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1782 set wildchar& wildcharm&
1783endfunc
1784
1785" Test for the 'errorbells' option
1786func Test_opt_errorbells()
1787 set errorbells
1788 call assert_beeps('s/a1b2/x1y2/')
1789 set noerrorbells
1790endfunc
1791
Dominique Pelle042414f2021-07-12 21:43:19 +02001792func Test_opt_scrolljump()
1793 help
1794 resize 10
1795
1796 " Test with positive 'scrolljump'.
1797 set scrolljump=2
1798 norm! Lj
1799 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1800 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1801 \ winsaveview())
1802
1803 " Test with negative 'scrolljump' (percentage of window height).
1804 set scrolljump=-40
1805 norm! ggLj
1806 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1807 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1808 \ winsaveview())
1809
1810 set scrolljump&
1811 bw
1812endfunc
1813
Bakudankun29f3a452021-12-11 12:28:08 +00001814" Test for the 'cdhome' option
1815func Test_opt_cdhome()
1816 if has('unix') || has('vms')
1817 throw 'Skipped: only works on non-Unix'
1818 endif
1819
1820 set cdhome&
1821 call assert_equal(0, &cdhome)
1822 set cdhome
1823
1824 " This paragraph is copied from Test_cd_no_arg().
1825 let path = getcwd()
1826 cd
1827 call assert_equal($HOME, getcwd())
1828 call assert_notequal(path, getcwd())
1829 exe 'cd ' .. fnameescape(path)
1830 call assert_equal(path, getcwd())
1831
1832 set cdhome&
1833endfunc
1834
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001835func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001836 CheckOption termguicolors
1837
1838 " Test default option completion
1839 set wildoptions=
1840 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1841 call assert_equal('"set termguicolors', @:)
1842
1843 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1844 call assert_equal('"set notermguicolors', @:)
1845
1846 " Test fuzzy option completion
1847 set wildoptions=fuzzy
1848 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1849 call assert_equal('"set termguicolors termencoding', @:)
1850
1851 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1852 call assert_equal('"set notermguicolors', @:)
1853
1854 set wildoptions=
1855endfunc
1856
Sean Dewar39c46b42022-05-12 17:44:29 +01001857func Test_switchbuf_reset()
1858 set switchbuf=useopen
1859 sblast
1860 call assert_equal(1, winnr('$'))
1861 set all&
1862 call assert_equal('', &switchbuf)
1863 sblast
1864 call assert_equal(2, winnr('$'))
1865 only!
1866endfunc
1867
zeertzjqfcba86c2022-09-22 13:57:32 +01001868" :set empty string for global 'keywordprg' falls back to ":help"
1869func Test_keywordprg_empty()
1870 let k = &keywordprg
1871 set keywordprg=man
1872 call assert_equal('man', &keywordprg)
1873 set keywordprg=
1874 call assert_equal(':help', &keywordprg)
1875 set keywordprg=man
1876 call assert_equal('man', &keywordprg)
1877 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1878 let &keywordprg = k
1879endfunc
1880
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001881" check that the very first buffer created does not have 'endoffile' set
1882func Test_endoffile_default()
1883 let after =<< trim [CODE]
1884 call writefile([execute('set eof?')], 'Xtestout')
1885 qall!
1886 [CODE]
1887 if RunVim([], after, '')
1888 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1889 endif
1890 call delete('Xtestout')
1891endfunc
1892
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001893" Test for setting the 'lines' and 'columns' options to a minimum value
1894func Test_set_min_lines_columns()
1895 let save_lines = &lines
1896 let save_columns = &columns
1897
1898 let after =<< trim END
1899 set nomore
1900 let msg = []
1901 let v:errmsg = ''
1902 silent! let &columns=0
1903 call add(msg, v:errmsg)
1904 silent! set columns=0
1905 call add(msg, v:errmsg)
1906 silent! call setbufvar('', '&columns', 0)
1907 call add(msg, v:errmsg)
1908 "call writefile(msg, 'XResultsetminlines')
1909 silent! let &lines=0
1910 call add(msg, v:errmsg)
1911 silent! set lines=0
1912 call add(msg, v:errmsg)
1913 silent! call setbufvar('', '&lines', 0)
1914 call add(msg, v:errmsg)
1915 call writefile(msg, 'XResultsetminlines')
1916 qall!
1917 END
1918 if RunVim([], after, '')
1919 call assert_equal(['E594: Need at least 12 columns',
1920 \ 'E594: Need at least 12 columns: columns=0',
1921 \ 'E594: Need at least 12 columns',
1922 \ 'E593: Need at least 2 lines',
1923 \ 'E593: Need at least 2 lines: lines=0',
1924 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1925 endif
1926
1927 call delete('XResultsetminlines')
1928 let &lines = save_lines
1929 let &columns = save_columns
1930endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001931
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001932" Test for reverting a string option value if the new value is invalid.
1933func Test_string_option_revert_on_failure()
1934 new
1935 let optlist = [
1936 \ ['ambiwidth', 'double', 'a123'],
1937 \ ['background', 'dark', 'a123'],
1938 \ ['backspace', 'eol', 'a123'],
1939 \ ['backupcopy', 'no', 'a123'],
1940 \ ['belloff', 'showmatch', 'a123'],
1941 \ ['breakindentopt', 'min:10', 'list'],
1942 \ ['bufhidden', 'wipe', 'a123'],
1943 \ ['buftype', 'nowrite', 'a123'],
1944 \ ['casemap', 'keepascii', 'a123'],
1945 \ ['cedit', "\<C-Y>", 'z'],
1946 \ ['colorcolumn', '10', 'z'],
1947 \ ['commentstring', '#%s', 'a123'],
1948 \ ['complete', '.,t', 'a'],
1949 \ ['completefunc', 'MyCmplFunc', '1a-'],
1950 \ ['completeopt', 'popup', 'a123'],
1951 \ ['completepopup', 'width:20', 'border'],
1952 \ ['concealcursor', 'v', 'xyz'],
1953 \ ['cpoptions', 'HJ', '~'],
1954 \ ['cryptmethod', 'zip', 'a123'],
1955 \ ['cursorlineopt', 'screenline', 'a123'],
1956 \ ['debug', 'throw', 'a123'],
1957 \ ['diffopt', 'iwhite', 'a123'],
1958 \ ['display', 'uhex', 'a123'],
1959 \ ['eadirection', 'hor', 'a123'],
1960 \ ['encoding', 'utf-8', 'a123'],
1961 \ ['eventignore', 'TextYankPost', 'a123'],
1962 \ ['fileencoding', 'utf-8', 'a123,'],
1963 \ ['fileformat', 'mac', 'a123'],
1964 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001965 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001966 \ ['fillchars', 'diff:~', 'a123'],
1967 \ ['foldclose', 'all', 'a123'],
1968 \ ['foldmarker', '[[[,]]]', '[[['],
1969 \ ['foldmethod', 'marker', 'a123'],
1970 \ ['foldopen', 'percent', 'a123'],
1971 \ ['formatoptions', 'an', '*'],
1972 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1973 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001974 \ ['highlight', '!:CursorColumn', '8:'],
1975 \ ['keymodel', 'stopsel', 'a123'],
1976 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1977 \ ['lispoptions', 'expr:1', 'a123'],
1978 \ ['listchars', 'tab:->', 'tab:'],
1979 \ ['matchpairs', '<:>', '<:'],
1980 \ ['mkspellmem', '100000,1000,100', '100000'],
1981 \ ['mouse', 'nvi', 'z'],
1982 \ ['mousemodel', 'extend', 'a123'],
1983 \ ['nrformats', 'alpha', 'a123'],
1984 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1985 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1986 \ ['previewpopup', 'width:20', 'a123'],
1987 \ ['printoptions', 'paper:A4', 'a123:'],
1988 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1989 \ ['rulerformat', '%l', '%['],
1990 \ ['scrollopt', 'hor,jump', 'a123'],
1991 \ ['selection', 'exclusive', 'a123'],
1992 \ ['selectmode', 'cmd', 'a123'],
1993 \ ['sessionoptions', 'options', 'a123'],
1994 \ ['shortmess', 'w', '2'],
1995 \ ['showbreak', '>>', "\x01"],
1996 \ ['showcmdloc', 'statusline', 'a123'],
1997 \ ['signcolumn', 'no', 'a123'],
1998 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1999 \ ['spellfile', 'MySpell.en.add', "\x01"],
2000 \ ['spelllang', 'en', "#"],
2001 \ ['spelloptions', 'camel', 'a123'],
2002 \ ['spellsuggest', 'double', 'a123'],
2003 \ ['splitkeep', 'topline', 'a123'],
2004 \ ['statusline', '%f', '%['],
2005 \ ['swapsync', 'sync', 'a123'],
2006 \ ['switchbuf', 'usetab', 'a123'],
2007 \ ['syntax', 'abc', 'a^b'],
2008 \ ['tabline', '%f', '%['],
2009 \ ['tagcase', 'ignore', 'a123'],
2010 \ ['tagfunc', 'MyTagFunc', '1a-'],
2011 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2012 \ ['viewoptions', 'options', 'a123'],
2013 \ ['virtualedit', 'onemore', 'a123'],
2014 \ ['whichwrap', '<,>', '{,}'],
2015 \ ['wildmode', 'list', 'a123'],
2016 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002017 \ ]
2018 if has('gui')
2019 call add(optlist, ['browsedir', 'buffer', 'a123'])
2020 endif
2021 if has('clipboard_working')
2022 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2023 endif
2024 if has('win32')
2025 call add(optlist, ['completeslash', 'slash', 'a123'])
2026 endif
2027 if has('cscope')
2028 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2029 endif
2030 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002031 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2032 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2033 endif
2034 if has('keymap')
2035 call add(optlist, ['keymap', 'greek', '[]'])
2036 endif
2037 if has('mouseshape')
2038 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2039 endif
2040 if has('win32') && has('gui')
2041 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2042 endif
2043 if has('rightleft')
2044 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2045 endif
2046 if has('terminal')
2047 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2048 call add(optlist, ['termwinsize', '24x80', '100'])
2049 endif
2050 if has('win32') && has('terminal')
2051 call add(optlist, ['termwintype', 'winpty', 'a123'])
2052 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002053 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002054 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002055 endif
2056 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002057 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2058 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002059 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002060 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2061 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002062 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002063 call add(optlist, ['varsofttabstop', '12', 'a123'])
2064 call add(optlist, ['vartabstop', '4,20', '4,'])
2065 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002066 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002067 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002068 endif
2069 for opt in optlist
2070 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002071 try
2072 exe $"let &{opt[0]} = '{opt[1]}'"
2073 catch
2074 call assert_report($"Caught {v:exception} with {opt->string()}")
2075 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002076 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2077 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2078 exe $"let &{opt[0]} = save_opt"
2079 endfor
2080 bw!
2081endfunc
2082
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002083func Test_set_option_window_global_local()
2084 new Xbuffer1
2085 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2086 setlocal scrolloff=2
2087 setglobal scrolloff=3
2088 setl modified
2089 " A new buffer has its own window-local options
2090 hide enew
2091 call assert_equal(-1, &l:scrolloff)
2092 call assert_equal(3, &g:scrolloff)
2093 " A new window opened with its own buffer-local options
2094 new
2095 call assert_equal(-1, &l:scrolloff)
2096 call assert_equal(3, &g:scrolloff)
2097 " Re-open Xbuffer1 and it should use
2098 " the previous set window-local options
2099 b Xbuffer1
2100 call assert_equal(2, &l:scrolloff)
2101 call assert_equal(3, &g:scrolloff)
2102 bw!
2103 bw!
2104 let &g:scrolloff = _gso
2105endfunc
2106
2107func GetGlobalLocalWindowOptions()
2108 new
2109 sil! r $VIMRUNTIME/doc/options.txt
2110 " Filter for global or local to window
2111 v/^'.*'.*\n.*global or local to window |global-local/d
2112 " get option value and type
2113 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2114 sil %s/empty/""/g
2115 " split the result
2116 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2117 bw!
2118 return result
2119endfunc
2120
2121func Test_set_option_window_global_local_all()
2122 new Xbuffer2
2123
2124 let optionlist = GetGlobalLocalWindowOptions()
2125 for [opt, type, default] in optionlist
2126 let _old = eval('&g:' .. opt)
2127 if type == 'string'
2128 if opt == 'fillchars'
2129 exe 'setl ' .. opt .. '=vert:+'
2130 exe 'setg ' .. opt .. '=vert:+,fold:+'
2131 elseif opt == 'listchars'
2132 exe 'setl ' .. opt .. '=tab:>>'
2133 exe 'setg ' .. opt .. '=tab:++'
2134 elseif opt == 'virtualedit'
2135 exe 'setl ' .. opt .. '=all'
2136 exe 'setg ' .. opt .. '=block'
2137 else
2138 exe 'setl ' .. opt .. '=Local'
2139 exe 'setg ' .. opt .. '=Global'
2140 endif
2141 elseif type == 'number'
2142 exe 'setl ' .. opt .. '=5'
2143 exe 'setg ' .. opt .. '=10'
2144 endif
2145 setl modified
2146 hide enew
2147 if type == 'string'
2148 call assert_equal('', eval('&l:' .. opt))
2149 if opt == 'fillchars'
2150 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2151 elseif opt == 'listchars'
2152 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2153 elseif opt == 'virtualedit'
2154 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2155 else
2156 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2157 endif
2158 elseif type == 'number'
2159 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2160 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2161 endif
2162 bw!
2163 exe 'let &g:' .. opt .. '=' .. default
2164 endfor
2165 bw!
2166endfunc
2167
Christian Brabandt757593c2023-08-22 21:44:10 +02002168func Test_paste_depending_options()
2169 " setting the paste option, resets all dependent options
2170 " and will be reported correctly using :verbose set <option>?
2171 let lines =<< trim [CODE]
2172 " set paste test
2173 set autoindent
2174 set expandtab
2175 " disabled, because depends on compiled feature set
2176 " set hkmap
2177 " set revins
2178 " set varsofttabstop=8,32,8
2179 set ruler
2180 set showmatch
2181 set smarttab
2182 set softtabstop=4
2183 set textwidth=80
2184 set wrapmargin=10
2185
2186 source Xvimrc_paste2
2187
2188 redir > Xoutput_paste
2189 verbose set expandtab?
2190 verbose setg expandtab?
2191 verbose setl expandtab?
2192 redir END
2193
2194 qall!
2195 [CODE]
2196
2197 call writefile(lines, 'Xvimrc_paste', 'D')
2198 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2199 if !RunVim([], lines, '--clean')
2200 return
2201 endif
2202
2203 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2204 call assert_equal('noexpandtab', result[0])
2205 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2206 call assert_equal('noexpandtab', result[2])
2207 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2208 call assert_equal('noexpandtab', result[4])
2209 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2210
2211 call delete('Xoutput_paste')
2212endfunc
2213
2214func Test_binary_depending_options()
2215 " setting the paste option, resets all dependent options
2216 " and will be reported correctly using :verbose set <option>?
2217 let lines =<< trim [CODE]
2218 " set binary test
2219 set expandtab
2220
2221 source Xvimrc_bin2
2222
2223 redir > Xoutput_bin
2224 verbose set expandtab?
2225 verbose setg expandtab?
2226 verbose setl expandtab?
2227 redir END
2228
2229 qall!
2230 [CODE]
2231
2232 call writefile(lines, 'Xvimrc_bin', 'D')
2233 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2234 if !RunVim([], lines, '--clean')
2235 return
2236 endif
2237
2238 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2239 call assert_equal('noexpandtab', result[0])
2240 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2241 call assert_equal('noexpandtab', result[2])
2242 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2243 call assert_equal('noexpandtab', result[4])
2244 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2245
2246 call delete('Xoutput_bin')
2247endfunc
2248
Gregory Anders3695d0e2023-09-29 20:17:20 +02002249func Test_set_keyprotocol()
2250 CheckNotGui
2251
2252 let term = &term
2253 set term=ansi
2254 call assert_equal('', &t_TI)
2255
2256 " Setting 'keyprotocol' should affect terminal codes without needing to
2257 " reset 'term'
2258 set keyprotocol+=ansi:kitty
2259 call assert_equal("\<Esc>[=1;1u", &t_TI)
2260 let &term = term
2261endfunc
2262
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002263func Test_set_wrap()
2264 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2265 " cursor position.
2266 set wrap smoothscroll scrolloff=5
2267
2268 call setline(1, ['', 'aaaa'->repeat(500)])
2269 20 split
2270 20 vsplit
2271 norm 2G$
2272 redraw
2273 set nowrap
2274 call assert_equal(2, winline())
2275
2276 set wrap& smoothscroll& scrolloff&
2277endfunc
2278
zeertzjqcd3a13e2024-02-24 16:51:32 +01002279func Test_delcombine()
2280 new
2281 set backspace=indent,eol,start
2282
2283 set delcombine
2284 call setline(1, 'β̳̈:β̳̈')
2285 normal! 0x
2286 call assert_equal('β̈:β̳̈', getline(1))
2287 exe "normal! A\<BS>"
2288 call assert_equal('β̈:β̈', getline(1))
2289 normal! 0x
2290 call assert_equal('β:β̈', getline(1))
2291 exe "normal! A\<BS>"
2292 call assert_equal('β:β', getline(1))
2293 normal! 0x
2294 call assert_equal(':β', getline(1))
2295 exe "normal! A\<BS>"
2296 call assert_equal(':', getline(1))
2297
2298 set nodelcombine
2299 call setline(1, 'β̳̈:β̳̈')
2300 normal! 0x
2301 call assert_equal(':β̳̈', getline(1))
2302 exe "normal! A\<BS>"
2303 call assert_equal(':', getline(1))
2304
2305 set backspace& delcombine&
2306 bwipe!
2307endfunc
2308
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002309" vim: shiftwidth=2 sts=2 expandtab