blob: 84a0035b9a48c6cbab158c97ef1cef19469fee38 [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
Milly6eca04e2024-10-21 22:20:51 +02007scriptencoding utf-8
8
Bram Moolenaar1e115362019-01-09 23:01:02 +01009func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020010 set whichwrap=b,s
11 call assert_equal('b,s', &whichwrap)
12
13 set whichwrap+=h,l
14 call assert_equal('b,s,h,l', &whichwrap)
15
16 set whichwrap+=h,l
17 call assert_equal('b,s,h,l', &whichwrap)
18
19 set whichwrap+=h,l
20 call assert_equal('b,s,h,l', &whichwrap)
21
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010022 set whichwrap=h,h
23 call assert_equal('h', &whichwrap)
24
25 set whichwrap=h,h,h
26 call assert_equal('h', &whichwrap)
27
Bram Moolenaar004a6782020-04-11 17:09:31 +020028 " For compatibility with Vim 3.0 and before, number values are also
29 " supported for 'whichwrap'
30 set whichwrap=1
31 call assert_equal('b', &whichwrap)
32 set whichwrap=2
33 call assert_equal('s', &whichwrap)
34 set whichwrap=4
35 call assert_equal('h,l', &whichwrap)
36 set whichwrap=8
37 call assert_equal('<,>', &whichwrap)
38 set whichwrap=16
39 call assert_equal('[,]', &whichwrap)
40 set whichwrap=31
41 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
42
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020043 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010044endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020045
Bram Moolenaar1e115362019-01-09 23:01:02 +010046func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010047 " This used to cause Vim to access uninitialized memory.
48 set isfname=
49 call assert_equal("~X", expand("~X"))
50 set isfname&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000051 " Test for setting 'isfname' to an unsupported character
52 let save_isfname = &isfname
53 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
54 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010055endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010056
zeertzjq0519ce02022-05-09 12:16:19 +010057" Test for getting the value of 'pastetoggle'
58func Test_pastetoggle()
59 " character with K_SPECIAL byte
60 let &pastetoggle = '…'
61 call assert_equal('…', &pastetoggle)
62 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
63
64 " modified character with K_SPECIAL byte
65 let &pastetoggle = '<M-…>'
66 call assert_equal('<M-…>', &pastetoggle)
67 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
68
69 " illegal bytes
70 let str = ":\x7f:\x80:\x90:\xd0:"
71 let &pastetoggle = str
72 call assert_equal(str, &pastetoggle)
73 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010074
zeertzjq0519ce02022-05-09 12:16:19 +010075 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010076 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010077endfunc
78
Bram Moolenaar1e115362019-01-09 23:01:02 +010079func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010080 " Empty 'wildchar' used to access invalid memory.
81 call assert_fails('set wildchar=', 'E521:')
82 call assert_fails('set wildchar=abc', 'E521:')
83 set wildchar=<Esc>
84 let a=execute('set wildchar?')
85 call assert_equal("\n wildchar=<Esc>", a)
86 set wildchar=27
87 let a=execute('set wildchar?')
88 call assert_equal("\n wildchar=<Esc>", a)
89 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010090endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010091
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020092func Test_wildoptions()
93 set wildoptions=
94 set wildoptions+=tagfile
95 set wildoptions+=tagfile
96 call assert_equal('tagfile', &wildoptions)
97endfunc
98
Bram Moolenaar6b915c02020-01-18 15:53:19 +010099func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200100 let caught = 'ok'
101 try
102 options
103 catch
104 let caught = v:throwpoint . "\n" . v:exception
105 endtry
106 call assert_equal('ok', caught)
107
Bram Moolenaare0b59492019-05-21 20:54:45 +0200108 " Check if the option-window is opened horizontally.
109 wincmd j
110 call assert_notequal('option-window', bufname(''))
111 wincmd k
112 call assert_equal('option-window', bufname(''))
113 " close option-window
114 close
115
116 " Open the option-window vertically.
117 vert options
118 " Check if the option-window is opened vertically.
119 wincmd l
120 call assert_notequal('option-window', bufname(''))
121 wincmd h
122 call assert_equal('option-window', bufname(''))
123 " close option-window
124 close
125
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200126 " Open the option-window at the top.
127 set splitbelow
128 topleft options
129 call assert_equal(1, winnr())
130 close
131
132 " Open the option-window at the bottom.
133 set nosplitbelow
134 botright options
135 call assert_equal(winnr('$'), winnr())
136 close
137 set splitbelow&
138
Bram Moolenaare0b59492019-05-21 20:54:45 +0200139 " Open the option-window in a new tab.
140 tab options
141 " Check if the option-window is opened in a tab.
142 normal gT
143 call assert_notequal('option-window', bufname(''))
144 normal gt
145 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200146 " close option-window
147 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200148
149 " Open the options window browse
150 if has('browse')
151 browse set
152 call assert_equal('option-window', bufname(''))
153 close
154 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200156
Bram Moolenaar1e115362019-01-09 23:01:02 +0100157func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200158 " Test that changing 'path' keeps two commas.
159 set path=foo,,bar
160 set path-=bar
161 set path+=bar
162 call assert_equal('foo,,bar', &path)
163
164 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100165endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200166
Dominique Pellef645ee42021-12-05 13:21:18 +0000167func Test_path_too_long()
168 exe 'set path=' .. repeat('x', 10000)
169 call assert_fails('find x', 'E854:')
170 set path&
171endfunc
172
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200173func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200174 CheckFeature signs
175 call assert_equal("auto", &signcolumn)
176 set signcolumn=yes
177 set signcolumn=no
178 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200179endfunc
180
Bram Moolenaard0b51382016-11-04 15:23:45 +0100181func Test_filetype_valid()
182 set ft=valid_name
183 call assert_equal("valid_name", &filetype)
184 set ft=valid-name
185 call assert_equal("valid-name", &filetype)
186
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\\|name", "E474:")
190 call assert_fails(":set ft=wrong/name", "E474:")
191 call assert_fails(":set ft=wrong\\\nname", "E474:")
192 call assert_equal("valid-name", &filetype)
193
194 exe "set ft=trunc\x00name"
195 call assert_equal("trunc", &filetype)
196endfunc
197
198func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200199 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100200 set syn=valid_name
201 call assert_equal("valid_name", &syntax)
202 set syn=valid-name
203 call assert_equal("valid-name", &syntax)
204
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\\|name", "E474:")
208 call assert_fails(":set syn=wrong/name", "E474:")
209 call assert_fails(":set syn=wrong\\\nname", "E474:")
210 call assert_equal("valid-name", &syntax)
211
212 exe "set syn=trunc\x00name"
213 call assert_equal("trunc", &syntax)
214endfunc
215
216func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200217 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100218 call assert_fails(":set kmp=valid_name", "E544:")
219 call assert_fails(":set kmp=valid_name", "valid_name")
220 call assert_fails(":set kmp=valid-name", "E544:")
221 call assert_fails(":set kmp=valid-name", "valid-name")
222
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\\|name", "E474:")
226 call assert_fails(":set kmp=wrong/name", "E474:")
227 call assert_fails(":set kmp=wrong\\\nname", "E474:")
228
229 call assert_fails(":set kmp=trunc\x00name", "E544:")
230 call assert_fails(":set kmp=trunc\x00name", "trunc")
231endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100232
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200233func Test_wildchar_valid()
234 call assert_fails("set wildchar=<CR>", "E474:")
235 call assert_fails("set wildcharm=<C-C>", "E474:")
236endfunc
237
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100238func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100239 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100240 exe 'set ' . a:name . '=/usr/share/dict/words'
241 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
242 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
243 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
244 exe 'set ' . a:name . '=/usr/share/dict\ words'
245 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100246
247 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100248 call assert_fails("set " . a:name . "=/not&there", "E474:")
249 call assert_fails("set " . a:name . "=/not>there", "E474:")
250 call assert_fails("set " . a:name . "=/not.*there", "E474:")
251endfunc
252
Bram Moolenaar60629d62017-02-23 18:08:56 +0100253func Test_cinkeys()
254 " This used to cause invalid memory access
255 set cindent cinkeys=0
256 norm a
257 set cindent& cinkeys&
258endfunc
259
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100260func Test_dictionary()
261 call Check_dir_option('dictionary')
262endfunc
263
264func Test_thesaurus()
265 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100266endfun
267
Bram Moolenaar226c5342017-02-17 14:53:15 +0100268func Test_complete()
269 " Trailing single backslash used to cause invalid memory access.
270 set complete=s\
271 new
272 call feedkeys("i\<C-N>\<Esc>", 'xt')
273 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200274 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100275 set complete&
276endfun
277
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100278func Test_set_completion()
279 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
280 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
281
Bram Moolenaar297610b2019-12-27 17:20:55 +0100282 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
284
285 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
286 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
287
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100288 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
289 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100290 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100291 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100292
293 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100294 call assert_equal('"set invdiff invdigraph', @:)
295
296 " Expanding "set noinv" does nothing.
297 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
298 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100299
300 " Expand abbreviation of options.
301 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100302 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100303
304 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200305 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
306 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100307
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200308 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
309 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100310
311 " Expand key codes.
312 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
313 call assert_equal('"set <Help> <Home>', @:)
314
315 " Expand terminal options.
316 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200317 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200318 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100319
320 " Expand directories.
321 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
322 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200323 call assert_notmatch(' ./summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200324 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100325
326 " Expand files and directories.
327 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200328 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100329
330 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
331 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200332
333 " Expand files with spaces/commas in them. Make sure we delimit correctly.
334 "
335 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
336 " spaces requiring double escape, and commas need a single escape.
337 " 'dictionary' is a normal comma-separated option where only commas act as
338 " delimiters, and both space/comma need one single escape.
339 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
340 defer delete('Xfoo Xspace.txt')
341 defer delete('Xsp_dummy')
342 defer delete('Xbar,Xcomma.txt')
343 defer delete('Xcom_dummy')
344 call writefile([], 'Xfoo Xspace.txt')
345 call writefile([], 'Xsp_dummy')
346 call writefile([], 'Xbar,Xcomma.txt')
347 call writefile([], 'Xcom_dummy')
348
349 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
350 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
351 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
352 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
353 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
354 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
355
356 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
357 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
358 if has('win32')
359 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
360 " means we treat it as one file name.
361 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
362 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
363 else
364 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
365 " to split into a separate file name. You need '\\,' to escape the comma
366 " as part of the file name.
367 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
368 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
369
370 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
371 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
372 endif
373 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
374 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
375 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200376
377 " Expanding the option names
378 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
379 call assert_equal('"set all', @:)
380
381 " Expanding a second set of option names
382 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
383 call assert_equal('"set wrapscan all', @:)
384
385 " Expanding a special keycode
386 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
387 call assert_equal('"set <Home>', @:)
388
389 " Expanding an invalid special keycode
390 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
391 call assert_equal("\"set <abcd>\<Tab>", @:)
392
393 " Expanding a terminal keycode
394 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
395 call assert_equal("\"set t_AB", @:)
396
397 " Expanding an invalid option name
398 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
399 call assert_equal("\"set abcde=\<Tab>", @:)
400
401 " Expanding after a = for a boolean option
402 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
403 call assert_equal("\"set wrapscan=\<Tab>", @:)
404
405 " Expanding a numeric option
406 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
407 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
408
409 " Expanding a non-boolean option
410 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
411 call assert_equal("\"set invtabstop=", @:)
412
413 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200414 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
415 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
416 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
417 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200418
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200419 " Expanding value for 'key' is disallowed
420 if exists('+key')
421 set key=abcd
422 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal('"set key=', @:)
424 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
425 call assert_equal('"set key-=', @:)
426 set key=
427 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100428
429 " Expand values for 'filetype'
430 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
431 call assert_equal('"set filetype=sshdconfig', @:)
432 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
433 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200434
435 " Expand values for 'syntax'
436 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
437 call assert_equal('"set syntax=sshdconfig', @:)
438 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
439 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100440
441 if has('keymap')
442 " Expand values for 'keymap'
443 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
444 call assert_equal('"set keymap=accents', @:)
445 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
446 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
447 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100448endfunc
449
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200450" Test handling of expanding individual string option values
451func Test_set_completion_string_values()
452 "
453 " Test basic enum string options that have well-defined enum names
454 "
455
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200456 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
457 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
458 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200459
460 " Test that if a value is set, it will populate the results, but only if
461 " typed value is empty.
462 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200463 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
464 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200465 " If the set value is part of the enum list, it will show as the first
466 " result with no duplicate.
467 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200468 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200469 " If empty value, will just show the normal list without an empty item
470 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200471 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200472 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200473 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200474
475 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200476 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200477 " Also test the positioning of the expansion is correct
478 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
479 call assert_equal('"set display=truncate,lastline', @:)
480 set display&
481
482 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200483 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200484
485 " Test the other simple options to make sure they have basic auto-complete,
486 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200487 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200488 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Luca Saccarola959ef612024-12-01 16:25:53 +0100489 call assert_equal('indent,eol,start', getcompletion('set backspace=', 'cmdline')[0])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200490 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
491 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
492 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200493 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200494 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200495 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200496 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
497 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
498 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200499 if exists('+clipboard')
500 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
501 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200502 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
503 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200504 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200505 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200506 endif
507 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200508 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200509 endif
510 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200511 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200512 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200513 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
514 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
515 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200516 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200517 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200518 endif
519 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200520 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200521 endif
522 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200523 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200524 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200525 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
526 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
527 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200528 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200529 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200530 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200531 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200532 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200533 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
534 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
535 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200536 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200537 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200538 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200540 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200541 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200542 endif
543 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200544 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200545 endif
546 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200547 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200548 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200549 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
550 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
551 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
552 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200553 if exists('+tabclose')
554 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
555 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200556 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200557 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200558 endif
559 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200560 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200561 endif
562 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200563 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200564 endif
565 if exists('+ttymouse')
566 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200567 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200568 set ttymouse&
569 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200570 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
571 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
572 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
573 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200574 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200575 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200576 endif
577
578 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200579 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100580 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200581 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
582 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
583 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200584
zeertzjq1f025b02023-09-30 12:43:07 +0200585 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
586 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
587 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
588 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
589 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
590 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200591
592 "
593 " Unique string options below
594 "
595
596 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200597 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200598 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
599 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100600 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
601 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200602 set keyprotocol&
603
604 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200605 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
606 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200607 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
608 call assert_equal('"set previewpopup+=border:on', @:)
609 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
610 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200611 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200612 set previewpopup& completepopup&
613
614 " diffopt: special handling of algorithm:<alg_list>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200615 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
616 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
617 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200618
619 " highlight: special parsing, including auto-completing highlight groups
620 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200621 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
622 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
623 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
624 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
625 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200626 " If all the display modes are used up we should be suggesting nothing. Make
627 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
628 " and make sure nothing is suggested from that.
629 let hl_display_modes = join(
630 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
631 \ {idx, val -> val[1]}),
632 \ {idx, val -> val != ':'}),
633 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200634 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200635 " Test completion in middle of the line
636 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
637 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200638
Christian Brabandt51d4d842024-12-06 17:26:25 +0100639 " messagesopt
640 call assert_equal(['history:', 'hit-enter', 'wait:'],
641 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
642
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200643 "
644 " Test flag lists
645 "
646
647 " Test set=. Show the original value if nothing is typed after '='.
648 " Otherwise, the list should avoid showing what's already typed.
649 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200650 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200651 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200652 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
653 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200654
655 " Test set+=. Never show original value, and it also tries to avoid listing
656 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200657 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
658 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
659 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200660
661 " Test that the position of the expansion is correct (even if there are
662 " additional values after the current cursor)
663 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
664 call assert_equal('"set mouse=han', @:)
665 set mouse&
666
667 " Test that other flag list options have auto-complete, but don't
668 " exhaustively validate their results.
669 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200670 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200671 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200672 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
673 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200674 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200675 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200676 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200677 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
678 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200679
680 "
681 "Test set-=
682 "
683
684 " Normal single-value option just shows the existing value
685 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200686 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200687 set ambiwidth&
688
689 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200690 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200691 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200692 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200693 set t_Ce&
694
695 " Comma-separated lists should present each option
696 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200697 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
698 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
699 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200700 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200701 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 " Test empty option
703 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200704 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100705 " Test all possible values
706 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
707 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'linematch:'],
708 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200709 set diffopt&
710
711 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200712 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200713
714 " Test files with commas in name are being parsed and escaped properly
715 set path=has\\\ space,file\\,with\\,comma,normal_file
716 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200717 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200718 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200719 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200720 endif
721 set path&
722
723 " Flag list should present orig value, then individual flags
724 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200725 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200726 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200727 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200728 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200729 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200730 " Test empty option
731 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200732 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200733 set mouse&
734
735 " 'whichwrap' is an odd case where it's both flag list and comma-separated
736 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200737 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200738 set ww&
739endfunc
740
zeertzjq4c7cb372023-06-14 16:39:54 +0100741func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100742 call assert_fails('set scroll=-1', 'E49:')
743 call assert_fails('set backupcopy=', 'E474:')
744 call assert_fails('set regexpengine=3', 'E474:')
745 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200746 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100747 call assert_fails('set colorcolumn=-a', 'E474:')
748 call assert_fails('set colorcolumn=a', 'E474:')
749 call assert_fails('set colorcolumn=1,', 'E474:')
750 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100751 call assert_fails('set cmdheight=-1', 'E487:')
752 call assert_fails('set cmdwinheight=-1', 'E487:')
753 if has('conceal')
754 call assert_fails('set conceallevel=-1', 'E487:')
755 call assert_fails('set conceallevel=4', 'E474:')
756 endif
757 call assert_fails('set helpheight=-1', 'E487:')
758 call assert_fails('set history=-1', 'E487:')
759 call assert_fails('set report=-1', 'E487:')
760 call assert_fails('set shiftwidth=-1', 'E487:')
761 call assert_fails('set sidescroll=-1', 'E487:')
762 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000763 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000764 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000765 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200766 if has('terminal')
767 call assert_fails('set termwinscroll=-1', 'E487:')
768 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100769 call assert_fails('set textwidth=-1', 'E487:')
770 call assert_fails('set timeoutlen=-1', 'E487:')
771 call assert_fails('set updatecount=-1', 'E487:')
772 call assert_fails('set updatetime=-1', 'E487:')
773 call assert_fails('set winheight=-1', 'E487:')
774 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200775
776 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100777 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200778 call assert_fails('setlocal xxx', 'E518:')
779 call assert_fails('setglobal xxx', 'E518:')
780 call assert_fails('set xxx=', 'E518:')
781 call assert_fails('setlocal xxx=', 'E518:')
782 call assert_fails('setglobal xxx=', 'E518:')
783 call assert_fails('set xxx:', 'E518:')
784 call assert_fails('setlocal xxx:', 'E518:')
785 call assert_fails('setglobal xxx:', 'E518:')
786 call assert_fails('set xxx!', 'E518:')
787 call assert_fails('setlocal xxx!', 'E518:')
788 call assert_fails('setglobal xxx!', 'E518:')
789 call assert_fails('set xxx?', 'E518:')
790 call assert_fails('setlocal xxx?', 'E518:')
791 call assert_fails('setglobal xxx?', 'E518:')
792 call assert_fails('set xxx&', 'E518:')
793 call assert_fails('setlocal xxx&', 'E518:')
794 call assert_fails('setglobal xxx&', 'E518:')
795 call assert_fails('set xxx<', 'E518:')
796 call assert_fails('setlocal xxx<', 'E518:')
797 call assert_fails('setglobal xxx<', 'E518:')
798
799 " Test for missing-options errors.
800 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100801 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200802 call assert_fails('set flash?', 'E519:')
803 call assert_fails('set graphic?', 'E519:')
804 call assert_fails('set hardtabs?', 'E519:')
805 call assert_fails('set mesg?', 'E519:')
806 call assert_fails('set novice?', 'E519:')
807 call assert_fails('set open?', 'E519:')
808 call assert_fails('set optimize?', 'E519:')
809 call assert_fails('set redraw?', 'E519:')
810 call assert_fails('set slowopen?', 'E519:')
811 call assert_fails('set sourceany?', 'E519:')
812 call assert_fails('set w300?', 'E519:')
813 call assert_fails('set w1200?', 'E519:')
814 call assert_fails('set w9600?', 'E519:')
815
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100816 call assert_fails('set undolevels=x', 'E521:')
817 call assert_fails('set tabstop=', 'E521:')
818 call assert_fails('set comments=-', 'E524:')
819 call assert_fails('set comments=a', 'E525:')
820 call assert_fails('set foldmarker=x', 'E536:')
821 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000822 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100823 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100824 call assert_fails('set rulerformat=%-', 'E539:')
825 call assert_fails('set rulerformat=%(', 'E542:')
826 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200827
828 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100829 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100830 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100831 call assert_fails('set statusline=%{%', 'E540:')
832 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100833 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100834 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200835
836 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100837 call assert_fails('set tabline=%$', 'E539:')
838 call assert_fails('set tabline=%{', 'E540:')
839 call assert_fails('set tabline=%{%', 'E540:')
840 call assert_fails('set tabline=%{%}', 'E539:')
841 call assert_fails('set tabline=%(', 'E542:')
842 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100843
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100844 if has('cursorshape')
845 " This invalid value for 'guicursor' used to cause Vim to crash.
846 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
847 call assert_fails('set guicursor=i-ci', 'E545:')
848 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100849 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100850 call assert_fails('set guicursor=r-cr:horx', 'E548:')
851 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
852 endif
Milly484face2024-10-12 11:26:06 +0200853
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100854 if has('mouseshape')
855 call assert_fails('se mouseshape=i-r:x', 'E547:')
856 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000857
858 " Test for 'backupext' and 'patchmode' set to the same value
859 set backupext=.bak
860 set patchmode=.patch
861 call assert_fails('set patchmode=.bak', 'E589:')
862 call assert_equal('.patch', &patchmode)
863 call assert_fails('set backupext=.patch', 'E589:')
864 call assert_equal('.bak', &backupext)
865 set backupext& patchmode&
866
Milly484face2024-10-12 11:26:06 +0200867 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100868 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200869 set winminheight& winheight&
870 set winheight=10 winminheight=10
871 call assert_fails('set winheight=9', 'E591:')
872 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200873
874 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100875 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200876 set winminwidth& winwidth&
877 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
878 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200879
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100880 call assert_fails("set showbreak=\x01", 'E595:')
881 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200882 call assert_fails('set tabstop??', 'E488:')
883 call assert_fails('set wrapscan!!', 'E488:')
884 call assert_fails('set tabstop&&', 'E488:')
885 call assert_fails('set wrapscan<<', 'E488:')
886 call assert_fails('set wrapscan=1', 'E474:')
887 call assert_fails('set autoindent@', 'E488:')
888 call assert_fails('set wildchar=<abc>', 'E474:')
889 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200890 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100891 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200892 call assert_fails('set pyxversion=6', 'E474:')
893 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100894 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200895 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100896 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
897 call assert_fails('set foldmarker={{{,', 'E474:')
898 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200899
900 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100901 setlocal listchars=trail:·
902 call assert_fails('set ambiwidth=double', 'E834:')
903 setlocal listchars=trail:-
904 setglobal listchars=trail:·
905 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100906 set listchars&
Milly484face2024-10-12 11:26:06 +0200907
908 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100909 setlocal fillchars=stl:·
910 call assert_fails('set ambiwidth=double', 'E835:')
911 setlocal fillchars=stl:-
912 setglobal fillchars=stl:·
913 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100914 set fillchars&
Milly484face2024-10-12 11:26:06 +0200915
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100916 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
917 set nomodifiable
918 call assert_fails('set fileencoding=latin1', 'E21:')
919 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200920 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000921 call assert_fails('let &formatoptions = "?"', 'E539:')
922 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200923
924 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100925 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
926 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
927 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
928 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
929 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
930 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100931endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100932
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000933func Test_set_encoding()
934 let save_encoding = &encoding
935
936 set enc=iso8859-1
937 call assert_equal('latin1', &enc)
938 set enc=iso8859_1
939 call assert_equal('latin1', &enc)
940 set enc=iso-8859-1
941 call assert_equal('latin1', &enc)
942 set enc=iso_8859_1
943 call assert_equal('latin1', &enc)
944 set enc=iso88591
945 call assert_equal('latin1', &enc)
946 set enc=iso8859
947 call assert_equal('latin1', &enc)
948 set enc=iso-8859
949 call assert_equal('latin1', &enc)
950 set enc=iso_8859
951 call assert_equal('latin1', &enc)
952 call assert_fails('set enc=iso8858', 'E474:')
953 call assert_equal('latin1', &enc)
954
955 let &encoding = save_encoding
956endfunc
957
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200958func CheckWasSet(name)
959 let verb_cm = execute('verbose set ' .. a:name .. '?')
960 call assert_match('Last set from.*test_options.vim', verb_cm)
961endfunc
962func CheckWasNotSet(name)
963 let verb_cm = execute('verbose set ' .. a:name .. '?')
964 call assert_notmatch('Last set from', verb_cm)
965endfunc
966
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200967" Must be executed before other tests that set 'term'.
968func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200969 CheckNotGui
970
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200971 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200972
973 let term_save = &term
974 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200975 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200976 let &term = term_save
977endfunc
978
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200979func Test_copy_context()
980 setlocal list
981 call CheckWasSet('list')
982 split
983 call CheckWasSet('list')
984 quit
985 setlocal nolist
986
987 set ai
988 call CheckWasSet('ai')
989 set filetype=perl
990 call CheckWasSet('filetype')
991 set fo=tcroq
992 call CheckWasSet('fo')
993
994 split Xsomebuf
995 call CheckWasSet('ai')
996 call CheckWasNotSet('filetype')
997 call CheckWasSet('fo')
998endfunc
999
Bram Moolenaar67391142017-02-19 21:07:04 +01001000func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001001 CheckUnix
1002 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001003
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001004 " Setting 'ttytype' used to cause a double-free when exiting vim and
1005 " when vim is compiled with -DEXITFREE.
1006 set ttytype=ansi
1007 call assert_equal('ansi', &ttytype)
1008 call assert_equal(&ttytype, &term)
1009 set ttytype=xterm
1010 call assert_equal('xterm', &ttytype)
1011 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001012 try
1013 set ttytype=
1014 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001015 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001016 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001017
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001018 " Some systems accept any terminal name and return dumb settings,
1019 " check for failure of finding the entry and for missing 'cm' entry.
1020 try
1021 set ttytype=xxx
1022 call assert_report('set ttytype=xxx did not fail')
1023 catch /E522\|E437/
1024 endtry
1025
1026 set ttytype&
1027 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001028
1029 if has('gui') && !has('gui_running')
1030 call assert_fails('set term=gui', 'E531:')
1031 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001032endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001033
Milly484face2024-10-12 11:26:06 +02001034" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001035func Test_set_all()
1036 set tw=75
1037 set iskeyword=a-z,A-Z
1038 set nosplitbelow
1039 let out = execute('set all')
1040 call assert_match('textwidth=75', out)
1041 call assert_match('iskeyword=a-z,A-Z', out)
1042 call assert_match('nosplitbelow', out)
1043 set tw& iskeyword& splitbelow&
1044endfunc
1045
Milly484face2024-10-12 11:26:06 +02001046" Test for :set! all
1047func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001048 let out_mult = execute('set all')->split("\n")
1049 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001050 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001051 call assert_equal(out_one[0], '--- Options ---')
1052 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1053 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001054endfunc
1055
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001056func Test_renderoptions()
1057 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1058 " Doesn't hurt to do this on a non-Windows system.
1059 if windowsversion() !~ '^[345]\.'
1060 set renderoptions=type:directx
1061 set rop=type:directx
1062 endif
1063endfunc
1064
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001065func ResetIndentexpr()
1066 set indentexpr=
1067endfunc
1068
1069func Test_set_indentexpr()
1070 " this was causing usage of freed memory
1071 set indentexpr=ResetIndentexpr()
1072 new
1073 call feedkeys("i\<c-f>", 'x')
1074 call assert_equal('', &indentexpr)
1075 bwipe!
1076endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001077
1078func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001079 " Option 'backupskip' may contain several comma-separated path
1080 " specifications if one or more of the environment variables TMPDIR, TMP,
1081 " or TEMP is defined. To simplify testing, convert the string value into a
1082 " list.
1083 let bsklist = split(&bsk, ',')
1084
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001085 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001086 let found = (index(bsklist, '/private/tmp/*') >= 0)
1087 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001088 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001089 let found = (index(bsklist, '/tmp/*') >= 0)
1090 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001091 endif
1092
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001093 " If our test platform is Windows, the path(s) in option bsk will use
1094 " backslash for the path separator and the components could be in short
1095 " (8.3) format. As such, we need to replace the backslashes with forward
1096 " slashes and convert the path components to long format. The expand()
1097 " function will do this but it cannot handle comma-separated paths. This is
1098 " why bsk was converted from a string into a list of strings above.
1099 "
1100 " One final complication is that the wildcard "/*" is at the end of each
1101 " path and so expand() might return a list of matching files. To prevent
1102 " this, we need to remove the wildcard before calling expand() and then
1103 " append it afterwards.
1104 if has('win32')
1105 let item_nbr = 0
1106 while item_nbr < len(bsklist)
1107 let path_spec = bsklist[item_nbr]
1108 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1109 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1110 let bsklist[item_nbr] = path_spec . '/*'
1111 let item_nbr += 1
1112 endwhile
1113 endif
1114
1115 " Option bsk will also include these environment variables if defined.
1116 " If they're defined, verify they appear in the option value.
1117 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001118 if exists(var)
1119 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001120 let varvalue = substitute(varvalue, '/$', '', '')
1121 let varvalue .= '/*'
1122 let found = (index(bsklist, varvalue) >= 0)
1123 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001124 endif
1125 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001126
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001127 " Duplicates from environment variables should be filtered out (option has
1128 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1129 " so that we see what happens on startup.
1130 let after =<< trim [CODE]
1131 let bsklist = split(&backupskip, ',')
1132 call assert_equal(uniq(copy(bsklist)), bsklist)
1133 call writefile(['errors:'] + v:errors, 'Xtestout')
1134 qall
1135 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001136 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001137 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1138
1139 let saveenv = {}
1140 for var in ['TMPDIR', 'TMP', 'TEMP']
1141 let saveenv[var] = getenv(var)
1142 call setenv(var, '/duplicate/path')
1143 endfor
1144
1145 exe 'silent !' . cmd
1146 call assert_equal(['errors:'], readfile('Xtestout'))
1147
1148 " restore environment variables
1149 for var in ['TMPDIR', 'TMP', 'TEMP']
1150 call setenv(var, saveenv[var])
1151 endfor
1152
1153 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001154
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001155 " Duplicates should be filtered out (option has P_NODUP)
1156 let backupskip = &backupskip
1157 set backupskip=
1158 set backupskip+=/test/dir
1159 set backupskip+=/other/dir
1160 set backupskip+=/test/dir
1161 call assert_equal('/test/dir,/other/dir', &backupskip)
1162 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001163endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001164
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001165func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001166 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001167
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001168 " Test copy option from current buffer in window
1169 split
1170 enew
1171 setlocal numberwidth=5
1172 wincmd w
1173 call assert_equal(4,&numberwidth)
1174 bnext
1175 call assert_equal(5,&numberwidth)
1176 bw!
1177 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001178
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001179 " Test copy value from window that used to be display the buffer
1180 split
1181 enew
1182 setlocal numberwidth=6
1183 bnext
1184 wincmd w
1185 call assert_equal(4,&numberwidth)
1186 bnext
1187 call assert_equal(6,&numberwidth)
1188 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001189
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001190 " Test that if buffer is current, don't use the stale cached value
1191 " from the last time the buffer was displayed.
1192 split
1193 enew
1194 setlocal numberwidth=7
1195 bnext
1196 bnext
1197 setlocal numberwidth=8
1198 wincmd w
1199 call assert_equal(4,&numberwidth)
1200 bnext
1201 call assert_equal(8,&numberwidth)
1202 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001203
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001204 " Test value is not copied if window already has seen the buffer
1205 enew
1206 split
1207 setlocal numberwidth=9
1208 bnext
1209 setlocal numberwidth=10
1210 wincmd w
1211 call assert_equal(4,&numberwidth)
1212 bnext
1213 call assert_equal(4,&numberwidth)
1214 bw!
1215
1216 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001217endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001218
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001219def Test_split_copy_options()
1220 var values = [
1221 ['cursorbind', true, false],
1222 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1223 ['list', true, 0],
1224 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1225 ['number', true, 0],
1226 ['relativenumber', true, false],
1227 ['scrollbind', true, false],
1228 ['smoothscroll', true, false],
1229 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1230 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1231 ['wrap', false, true],
1232 ]
1233 if has('linebreak')
1234 values += [
1235 ['breakindent', true, false],
1236 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1237 ['linebreak', true, false],
1238 ['numberwidth', 7, 4],
1239 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1240 ]
1241 endif
1242 if has('rightleft')
1243 values += [
1244 ['rightleft', true, false],
1245 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1246 ]
1247 endif
1248 if has('statusline')
1249 values += [
1250 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1251 ]
1252 endif
1253 if has('spell')
1254 values += [
1255 ['spell', true, false],
1256 ]
1257 endif
1258 if has('syntax')
1259 values += [
1260 ['cursorcolumn', true, false],
1261 ['cursorline', true, false],
1262 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1263 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1264 ]
1265 endif
1266 if has('diff')
1267 values += [
1268 ['diff', true, false],
1269 ]
1270 endif
1271 if has('conceal')
1272 values += [
1273 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1274 ['conceallevel', '3', &conceallevel],
1275 ]
1276 endif
1277 if has('terminal')
1278 values += [
1279 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1280 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1281 ]
1282 endif
1283 if has('folding')
1284 values += [
1285 ['foldcolumn', 5, &foldcolumn],
1286 ['foldenable', false, true],
1287 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1288 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1289 ['foldlevel', 4, &foldlevel],
1290 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1291 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1292 ['foldminlines', 3, &foldminlines],
1293 ['foldnestmax', 17, &foldnestmax],
1294 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1295 ]
1296 endif
1297 if has('signs')
1298 values += [
1299 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1300 ]
1301 endif
1302
1303 # set options to non-default value
1304 for item in values
1305 exe $'&l:{item[0]} = {item[1]}'
1306 endfor
1307
1308 # check values are set in new window
1309 split
1310 for item in values
1311 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1312 endfor
1313
1314 # restore
1315 close
1316 for item in values
1317 exe $'&l:{item[0]} = {item[2]}'
1318 endfor
1319enddef
1320
Bram Moolenaarfc089602018-06-24 16:53:35 +02001321func Test_shortmess_F()
1322 new
1323 call assert_match('\[No Name\]', execute('file'))
1324 set shortmess+=F
1325 call assert_match('\[No Name\]', execute('file'))
1326 call assert_match('^\s*$', execute('file foo'))
1327 call assert_match('foo', execute('file'))
1328 set shortmess-=F
1329 call assert_match('bar', execute('file bar'))
1330 call assert_match('bar', execute('file'))
1331 set shortmess&
1332 bwipe
1333endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001334
1335func Test_shortmess_F2()
1336 e file1
1337 e file2
1338 call assert_match('file1', execute('bn', ''))
1339 call assert_match('file2', execute('bn', ''))
1340 set shortmess+=F
1341 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001342 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001343 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001344 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001345 set hidden
1346 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001347 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001348 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001349 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001350 set nohidden
1351 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001352 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001353 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001354 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001355 set shortmess&
1356 call assert_match('file1', execute('bn', ''))
1357 call assert_match('file2', execute('bn', ''))
1358 bwipe
1359 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001360 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001361endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001362
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001363func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001364 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001365
1366 set hidden
1367 set autoread
1368 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001369 e Xotherfile
1370 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001371 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001372 echo ''
1373
1374 if has('nanotime')
1375 sleep 10m
1376 else
1377 sleep 2
1378 endif
1379 call writefile(['bar'], 'X_dummy')
1380 bprev
1381 call assert_equal('', Screenline(&lines))
1382 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1383
1384 if has('nanotime')
1385 sleep 10m
1386 else
1387 sleep 2
1388 endif
1389 call writefile(['baz'], 'X_dummy')
1390 checktime
1391 call assert_equal('', Screenline(&lines))
1392 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001393
1394 set shortmess&
1395 set autoread&
1396 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001397 bwipe X_dummy
1398 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001399endfunc
1400
Bram Moolenaar375e3392019-01-31 18:26:10 +01001401func Test_local_scrolloff()
1402 set so=5
1403 set siso=7
1404 split
1405 call assert_equal(5, &so)
1406 setlocal so=3
1407 call assert_equal(3, &so)
1408 wincmd w
1409 call assert_equal(5, &so)
1410 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001411 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001412 setlocal so<
1413 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001414 setglob so=8
1415 call assert_equal(8, &so)
1416 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001417 setlocal so=0
1418 call assert_equal(0, &so)
1419 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001420 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001421
1422 call assert_equal(7, &siso)
1423 setlocal siso=3
1424 call assert_equal(3, &siso)
1425 wincmd w
1426 call assert_equal(7, &siso)
1427 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001428 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001429 setlocal siso<
1430 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001431 setglob siso=4
1432 call assert_equal(4, &siso)
1433 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001434 setlocal siso=0
1435 call assert_equal(0, &siso)
1436 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001437 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001438
1439 close
1440 set so&
1441 set siso&
1442endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001443
1444func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001445 CheckFunction reltimefloat
1446
Bram Moolenaar449ac472019-04-03 21:42:35 +02001447 new
1448 call setline(1, 'empty')
1449 redraw
1450 set writedelay=10
1451 let start = reltime()
1452 call setline(1, repeat('x', 70))
1453 redraw
1454 let elapsed = reltimefloat(reltime(start))
1455 set writedelay=0
1456 " With 'writedelay' set should take at least 30 * 10 msec
1457 call assert_inrange(30 * 0.01, 999.0, elapsed)
1458
1459 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001460endfunc
1461
1462func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001463 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001464 set visualbell
1465 call assert_beeps('normal 0h')
1466 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001467 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001468endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001469
1470" Test for the 'write' option
1471func Test_write()
1472 new
1473 call setline(1, ['L1'])
1474 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001475 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001476 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001477 " close swapfile
1478 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001479endfunc
1480
1481" Test for 'buftype' option
1482func Test_buftype()
1483 new
1484 call setline(1, ['L1'])
1485 set buftype=nowrite
1486 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001487
1488 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1489 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001490 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001491 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1492 endfor
1493
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001494 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001495endfunc
1496
Bram Moolenaar578fe942020-02-27 21:32:51 +01001497" Test for the 'rightleftcmd' option
1498func Test_rightleftcmd()
1499 CheckFeature rightleft
1500 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001501
1502 let g:l = []
1503 func AddPos()
1504 call add(g:l, screencol())
1505 return ''
1506 endfunc
1507 cmap <expr> <F2> AddPos()
1508
zeertzjqbb404f52022-07-23 06:25:29 +01001509 set rightleftcmd=
1510 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1511 \ "\<Right>\<F2>\<Esc>", 'xt')
1512 call assert_equal([2, 5, 3, 4], g:l)
1513
1514 let g:l = []
1515 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001516 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1517 \ "\<Left>\<F2>\<Esc>", 'xt')
1518 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1519
1520 cunmap <F2>
1521 unlet g:l
1522 set rightleftcmd&
1523 set rightleft&
1524endfunc
1525
zeertzjq28c162f2022-08-14 14:49:50 +01001526" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001527func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001528 " redraw to avoid matching previous messages
1529 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001530 set debug=beep
1531 exe "normal \<C-c>"
1532 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001533 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001534 " also check a line above, with a certain window width the colon is there
1535 call assert_match('Test_debug_option:$',
1536 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001537 set debug&
1538endfunc
1539
Bram Moolenaar004a6782020-04-11 17:09:31 +02001540" Test for the default CDPATH option
1541func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001542 let after =<< trim [CODE]
1543 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1544 call writefile(v:errors, 'Xtestout')
1545 qall
1546 [CODE]
1547 if has('unix')
1548 let $CDPATH='/path/to/dir1:/path/to/dir2'
1549 else
1550 let $CDPATH='/path/to/dir1;/path/to/dir2'
1551 endif
1552 if RunVim([], after, '')
1553 call assert_equal([], readfile('Xtestout'))
1554 call delete('Xtestout')
1555 endif
1556endfunc
1557
1558" Test for setting keycodes using set
1559func Test_opt_set_keycode()
1560 call assert_fails('set <t_k1=l', 'E474:')
1561 call assert_fails('set <Home=l', 'E474:')
1562 set <t_k9>=abcd
1563 call assert_equal('abcd', &t_k9)
1564 set <t_k9>&
1565 set <F9>=xyz
1566 call assert_equal('xyz', &t_k9)
1567 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001568
1569 " should we test all of them?
1570 set t_Ce=testCe
1571 set t_Cs=testCs
1572 set t_Us=testUs
1573 set t_ds=testds
1574 set t_Ds=testDs
1575 call assert_equal('testCe', &t_Ce)
1576 call assert_equal('testCs', &t_Cs)
1577 call assert_equal('testUs', &t_Us)
1578 call assert_equal('testds', &t_ds)
1579 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001580endfunc
1581
1582" Test for changing options in a sandbox
1583func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001584 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001585 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001586 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001587 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001588 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001589endfunc
1590
Milly484face2024-10-12 11:26:06 +02001591" Test for setting string global-local option value
1592func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001593 setglobal equalprg=gprg
1594 setlocal equalprg=lprg
1595 call assert_equal('gprg', &g:equalprg)
1596 call assert_equal('lprg', &l:equalprg)
1597 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001598
1599 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001600 set equalprg<
1601 call assert_equal('', &l:equalprg)
1602 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001603
1604 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001605 setglobal equalprg=gnewprg
1606 setlocal equalprg=lnewprg
1607 setlocal equalprg<
1608 call assert_equal('gnewprg', &l:equalprg)
1609 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001610
Milly484face2024-10-12 11:26:06 +02001611 set equalprg&
1612endfunc
1613
1614" Test for setting number global-local option value
1615func Test_set_number_global_local_option()
1616 setglobal scrolloff=10
1617 setlocal scrolloff=12
1618 call assert_equal(10, &g:scrolloff)
1619 call assert_equal(12, &l:scrolloff)
1620 call assert_equal(12, &scrolloff)
1621
1622 " :set {option}< set the effective value of {option} to its global value.
1623 set scrolloff<
1624 call assert_equal(10, &l:scrolloff)
1625 call assert_equal(10, &scrolloff)
1626
1627 " :setlocal {option}< removes the local value, so that the global value will be used.
1628 setglobal scrolloff=15
1629 setlocal scrolloff=18
1630 setlocal scrolloff<
1631 call assert_equal(-1, &l:scrolloff)
1632 call assert_equal(15, &scrolloff)
1633
1634 set scrolloff&
1635endfunc
1636
1637" Test for setting boolean global-local option value
1638func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001639 setglobal autoread
1640 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001641 call assert_equal(1, &g:autoread)
1642 call assert_equal(0, &l:autoread)
1643 call assert_equal(0, &autoread)
1644
1645 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001646 set autoread<
Milly484face2024-10-12 11:26:06 +02001647 call assert_equal(1, &l:autoread)
1648 call assert_equal(1, &autoread)
1649
1650 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001651 setglobal noautoread
1652 setlocal autoread
1653 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001654 call assert_equal(-1, &l:autoread)
1655 call assert_equal(0, &autoread)
1656
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001657 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001658endfunc
1659
Dominique Pelle042414f2021-07-12 21:43:19 +02001660func Test_set_in_sandbox()
1661 " Some boolean options cannot be set in sandbox, some can.
1662 call assert_fails('sandbox set modelineexpr', 'E48:')
1663 sandbox set number
1664 call assert_true(&number)
1665 set number&
1666
1667 " Some boolean options cannot be set in sandbox, some can.
1668 if has('python') || has('python3')
1669 call assert_fails('sandbox set pyxversion=3', 'E48:')
1670 endif
1671 sandbox set tabstop=4
1672 call assert_equal(4, &tabstop)
1673 set tabstop&
1674
1675 " Some string options cannot be set in sandbox, some can.
1676 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1677 sandbox set filetype=perl
1678 call assert_equal('perl', &filetype)
1679 set filetype&
1680endfunc
1681
Milly484face2024-10-12 11:26:06 +02001682" Test for setting string option value
1683func Test_set_string_option()
1684 " :set {option}=
1685 set makeprg=
1686 call assert_equal('', &mp)
1687 set makeprg=abc
1688 call assert_equal('abc', &mp)
1689
1690 " :set {option}:
1691 set makeprg:
1692 call assert_equal('', &mp)
1693 set makeprg:abc
1694 call assert_equal('abc', &mp)
1695
1696 " Let string
1697 let &makeprg = ''
1698 call assert_equal('', &mp)
1699 let &makeprg = 'abc'
1700 call assert_equal('abc', &mp)
1701
1702 " Let number converts to string
1703 let &makeprg = 42
1704 call assert_equal('42', &mp)
1705
1706 " Appending
1707 set makeprg=abc
1708 set makeprg+=def
1709 call assert_equal('abcdef', &mp)
1710 set makeprg+=def
1711 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1712 let &makeprg .= 'gh'
1713 call assert_equal('abcdefdefgh', &mp)
1714 let &makeprg ..= 'ij'
1715 call assert_equal('abcdefdefghij', &mp)
1716
1717 " Removing
1718 set makeprg=abcdefghi
1719 set makeprg-=def
1720 call assert_equal('abcghi', &mp)
1721 set makeprg-=def
1722 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1723
1724 " Prepending
1725 set makeprg=abc
1726 set makeprg^=def
1727 call assert_equal('defabc', &mp)
1728 set makeprg^=def
1729 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1730
1731 set makeprg&
1732endfunc
1733
1734" Test for setting string comma-separated list option value
1735func Test_set_string_comma_list_option()
1736 " :set {option}=
1737 set wildignore=
1738 call assert_equal('', &wildignore)
1739 set wildignore=*.png
1740 call assert_equal('*.png', &wildignore)
1741
1742 " :set {option}:
1743 set wildignore:
1744 call assert_equal('', &wildignore)
1745 set wildignore:*.png
1746 call assert_equal('*.png', &wildignore)
1747
1748 " Let string
1749 let &wildignore = ''
1750 call assert_equal('', &wildignore)
1751 let &wildignore = '*.png'
1752 call assert_equal('*.png', &wildignore)
1753
1754 " Let number converts to string
1755 let &wildignore = 42
1756 call assert_equal('42', &wildignore)
1757
1758 " Appending
1759 set wildignore=*.png
1760 set wildignore+=*.jpg
1761 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1762 set wildignore+=*.jpg
1763 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1764 set wildignore+=jpg
1765 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1766 let &wildignore .= 'foo'
1767 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1768 let &wildignore ..= 'bar'
1769 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1770
1771 " Removing
1772 set wildignore=*.png,*.jpg,*.obj
1773 set wildignore-=*.jpg
1774 call assert_equal('*.png,*.obj', &wildignore)
1775 set wildignore-=*.jpg
1776 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1777 set wildignore-=jpg
1778 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1779
1780 " Prepending
1781 set wildignore=*.png
1782 set wildignore^=*.jpg
1783 call assert_equal('*.jpg,*.png', &wildignore)
1784 set wildignore^=*.jpg
1785 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1786 set wildignore^=jpg
1787 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1788
1789 set wildignore&
1790endfunc
1791
1792" Test for setting string flags option value
1793func Test_set_string_flags_option()
1794 " :set {option}=
1795 set formatoptions=
1796 call assert_equal('', &fo)
1797 set formatoptions=abc
1798 call assert_equal('abc', &fo)
1799
1800 " :set {option}:
1801 set formatoptions:
1802 call assert_equal('', &fo)
1803 set formatoptions:abc
1804 call assert_equal('abc', &fo)
1805
1806 " Let string
1807 let &formatoptions = ''
1808 call assert_equal('', &fo)
1809 let &formatoptions = 'abc'
1810 call assert_equal('abc', &fo)
1811
1812 " Let number converts to string
1813 let &formatoptions = 12
1814 call assert_equal('12', &fo)
1815
1816 " Appending
1817 set formatoptions=abc
1818 set formatoptions+=pqr
1819 call assert_equal('abcpqr', &fo)
1820 set formatoptions+=pqr
1821 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1822 let &formatoptions .= 'r'
1823 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1824 let &formatoptions ..= 'r'
1825 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1826
1827 " Removing
1828 set formatoptions=abcpqr
1829 set formatoptions-=cp
1830 call assert_equal('abqr', &fo)
1831 set formatoptions-=cp
1832 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1833 set formatoptions-=ar
1834 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1835
1836 " Prepending
1837 set formatoptions=abc
1838 set formatoptions^=pqr
1839 call assert_equal('pqrabc', &fo)
1840 set formatoptions^=qr
1841 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1842
1843 set formatoptions&
1844endfunc
1845
1846" Test for setting number option value
1847func Test_set_number_option()
1848 " :set {option}=
1849 set scrolljump=5
1850 call assert_equal(5, &sj)
1851 set scrolljump=-3
1852 call assert_equal(-3, &sj)
1853
1854 " :set {option}:
1855 set scrolljump:7
1856 call assert_equal(7, &sj)
1857 set scrolljump:-5
1858 call assert_equal(-5, &sj)
1859
1860 " Set hex
1861 set scrolljump=0x10
1862 call assert_equal(16, &sj)
1863 set scrolljump=-0x10
1864 call assert_equal(-16, &sj)
1865 set scrolljump=0X12
1866 call assert_equal(18, &sj)
1867 set scrolljump=-0X12
1868 call assert_equal(-18, &sj)
1869
1870 " Set octal
1871 set scrolljump=010
1872 call assert_equal(8, &sj)
1873 set scrolljump=-010
1874 call assert_equal(-8, &sj)
1875 set scrolljump=0o12
1876 call assert_equal(10, &sj)
1877 set scrolljump=-0o12
1878 call assert_equal(-10, &sj)
1879 set scrolljump=0O15
1880 call assert_equal(13, &sj)
1881 set scrolljump=-0O15
1882 call assert_equal(-13, &sj)
1883
1884 " Let number
1885 let &scrolljump = 4
1886 call assert_equal(4, &sj)
1887 let &scrolljump = -6
1888 call assert_equal(-6, &sj)
1889
1890 " Let numeric string converts to number
1891 let &scrolljump = '7'
1892 call assert_equal(7, &sj)
1893 let &scrolljump = '-9'
1894 call assert_equal(-9, &sj)
1895
1896 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001897 set shiftwidth=4
1898 set sw+=2
1899 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001900 let &shiftwidth += 2
1901 call assert_equal(8, &sw)
1902
1903 " Decrementing
1904 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001905 set sw-=2
1906 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001907 let &shiftwidth -= 2
1908 call assert_equal(2, &sw)
1909
1910 " Multiplying
1911 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001912 set sw^=2
1913 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001914 let &shiftwidth *= 2
1915 call assert_equal(16, &sw)
1916
1917 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001918 set shiftwidth&
1919endfunc
1920
Milly484face2024-10-12 11:26:06 +02001921" Test for setting boolean option value
1922func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001923 set number&
Milly484face2024-10-12 11:26:06 +02001924
1925 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001926 set number
1927 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001928
1929 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001930 set nonu
1931 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001932
1933 " :set {option}!
1934 set number!
1935 call assert_equal(1, &nu)
1936 set number!
1937 call assert_equal(0, &nu)
1938
1939 " :set inv{option}
1940 set invnumber
1941 call assert_equal(1, &nu)
1942 set invnumber
1943 call assert_equal(0, &nu)
1944
1945 " Let number
1946 let &number = 1
1947 call assert_equal(1, &nu)
1948 let &number = 0
1949 call assert_equal(0, &nu)
1950
1951 " Let numeric string converts to number
1952 let &number = '1'
1953 call assert_equal(1, &nu)
1954 let &number = '0'
1955 call assert_equal(0, &nu)
1956
1957 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001958 let &nu = v:true
1959 call assert_equal(1, &nu)
1960 let &nu = v:false
1961 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001962
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001963 set number&
1964endfunc
1965
Milly484face2024-10-12 11:26:06 +02001966" Test for setting string option errors
1967func Test_set_string_option_errors()
1968 " :set no{option}
1969 call assert_fails('set nomakeprg', 'E474:')
1970 call assert_fails('setlocal nomakeprg', 'E474:')
1971 call assert_fails('setglobal nomakeprg', 'E474:')
1972
1973 " :set inv{option}
1974 call assert_fails('set invmakeprg', 'E474:')
1975 call assert_fails('setlocal invmakeprg', 'E474:')
1976 call assert_fails('setglobal invmakeprg', 'E474:')
1977
1978 " :set {option}!
1979 call assert_fails('set makeprg!', 'E488:')
1980 call assert_fails('setlocal makeprg!', 'E488:')
1981 call assert_fails('setglobal makeprg!', 'E488:')
1982
1983 " Invalid trailing chars
1984 call assert_fails('set makeprg??', 'E488:')
1985 call assert_fails('setlocal makeprg??', 'E488:')
1986 call assert_fails('setglobal makeprg??', 'E488:')
1987 call assert_fails('set makeprg&&', 'E488:')
1988 call assert_fails('setlocal makeprg&&', 'E488:')
1989 call assert_fails('setglobal makeprg&&', 'E488:')
1990 call assert_fails('set makeprg<<', 'E488:')
1991 call assert_fails('setlocal makeprg<<', 'E488:')
1992 call assert_fails('setglobal makeprg<<', 'E488:')
1993 call assert_fails('set makeprg@', 'E488:')
1994 call assert_fails('setlocal makeprg@', 'E488:')
1995 call assert_fails('setglobal makeprg@', 'E488:')
1996
1997 " Invalid type
1998 call assert_fails("let &makeprg = ['xxx']", 'E730:')
1999endfunc
2000
2001" Test for setting number option errors
2002func Test_set_number_option_errors()
2003 " :set no{option}
2004 call assert_fails('set notabstop', 'E474:')
2005 call assert_fails('setlocal notabstop', 'E474:')
2006 call assert_fails('setglobal notabstop', 'E474:')
2007
2008 " :set inv{option}
2009 call assert_fails('set invtabstop', 'E474:')
2010 call assert_fails('setlocal invtabstop', 'E474:')
2011 call assert_fails('setglobal invtabstop', 'E474:')
2012
2013 " :set {option}!
2014 call assert_fails('set tabstop!', 'E488:')
2015 call assert_fails('setlocal tabstop!', 'E488:')
2016 call assert_fails('setglobal tabstop!', 'E488:')
2017
2018 " Invalid trailing chars
2019 call assert_fails('set tabstop??', 'E488:')
2020 call assert_fails('setlocal tabstop??', 'E488:')
2021 call assert_fails('setglobal tabstop??', 'E488:')
2022 call assert_fails('set tabstop&&', 'E488:')
2023 call assert_fails('setlocal tabstop&&', 'E488:')
2024 call assert_fails('setglobal tabstop&&', 'E488:')
2025 call assert_fails('set tabstop<<', 'E488:')
2026 call assert_fails('setlocal tabstop<<', 'E488:')
2027 call assert_fails('setglobal tabstop<<', 'E488:')
2028 call assert_fails('set tabstop@', 'E488:')
2029 call assert_fails('setlocal tabstop@', 'E488:')
2030 call assert_fails('setglobal tabstop@', 'E488:')
2031
2032 " Not a number
2033 call assert_fails('set tabstop=', 'E521:')
2034 call assert_fails('setlocal tabstop=', 'E521:')
2035 call assert_fails('setglobal tabstop=', 'E521:')
2036 call assert_fails('set tabstop=x', 'E521:')
2037 call assert_fails('setlocal tabstop=x', 'E521:')
2038 call assert_fails('setglobal tabstop=x', 'E521:')
2039 call assert_fails('set tabstop=1x', 'E521:')
2040 call assert_fails('setlocal tabstop=1x', 'E521:')
2041 call assert_fails('setglobal tabstop=1x', 'E521:')
2042 call assert_fails('set tabstop=-x', 'E521:')
2043 call assert_fails('setlocal tabstop=-x', 'E521:')
2044 call assert_fails('setglobal tabstop=-x', 'E521:')
2045 call assert_fails('set tabstop=0x', 'E521:')
2046 call assert_fails('setlocal tabstop=0x', 'E521:')
2047 call assert_fails('setglobal tabstop=0x', 'E521:')
2048 call assert_fails('set tabstop=0o', 'E521:')
2049 call assert_fails('setlocal tabstop=0o', 'E521:')
2050 call assert_fails('setglobal tabstop=0o', 'E521:')
2051 call assert_fails("let &tabstop = 'x'", 'E521:')
2052 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2053 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2054
2055 " Invalid type
2056 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2057endfunc
2058
2059" Test for setting boolean option errors
2060func Test_set_boolean_option_errors()
2061 " :set {option}=
2062 call assert_fails('set number=', 'E474:')
2063 call assert_fails('setlocal number=', 'E474:')
2064 call assert_fails('setglobal number=', 'E474:')
2065 call assert_fails('set number=1', 'E474:')
2066 call assert_fails('setlocal number=1', 'E474:')
2067 call assert_fails('setglobal number=1', 'E474:')
2068
2069 " :set {option}:
2070 call assert_fails('set number:', 'E474:')
2071 call assert_fails('setlocal number:', 'E474:')
2072 call assert_fails('setglobal number:', 'E474:')
2073 call assert_fails('set number:1', 'E474:')
2074 call assert_fails('setlocal number:1', 'E474:')
2075 call assert_fails('setglobal number:1', 'E474:')
2076
2077 " :set {option}+=
2078 call assert_fails('set number+=1', 'E474:')
2079 call assert_fails('setlocal number+=1', 'E474:')
2080 call assert_fails('setglobal number+=1', 'E474:')
2081
2082 " :set {option}^=
2083 call assert_fails('set number^=1', 'E474:')
2084 call assert_fails('setlocal number^=1', 'E474:')
2085 call assert_fails('setglobal number^=1', 'E474:')
2086
2087 " :set {option}-=
2088 call assert_fails('set number-=1', 'E474:')
2089 call assert_fails('setlocal number-=1', 'E474:')
2090 call assert_fails('setglobal number-=1', 'E474:')
2091
2092 " Invalid trailing chars
2093 call assert_fails('set number!!', 'E488:')
2094 call assert_fails('setlocal number!!', 'E488:')
2095 call assert_fails('setglobal number!!', 'E488:')
2096 call assert_fails('set number??', 'E488:')
2097 call assert_fails('setlocal number??', 'E488:')
2098 call assert_fails('setglobal number??', 'E488:')
2099 call assert_fails('set number&&', 'E488:')
2100 call assert_fails('setlocal number&&', 'E488:')
2101 call assert_fails('setglobal number&&', 'E488:')
2102 call assert_fails('set number<<', 'E488:')
2103 call assert_fails('setlocal number<<', 'E488:')
2104 call assert_fails('setglobal number<<', 'E488:')
2105 call assert_fails('set number@', 'E488:')
2106 call assert_fails('setlocal number@', 'E488:')
2107 call assert_fails('setglobal number@', 'E488:')
2108
2109 " Invalid type
2110 call assert_fails("let &number = 'xxx'", 'E521:')
2111endfunc
2112
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002113" Test for the 'window' option
2114func Test_window_opt()
2115 " Needs only one open widow
2116 %bw!
2117 call setline(1, range(1, 8))
2118 set window=5
2119 exe "normal \<C-F>"
2120 call assert_equal(4, line('w0'))
2121 exe "normal \<C-F>"
2122 call assert_equal(7, line('w0'))
2123 exe "normal \<C-F>"
2124 call assert_equal(8, line('w0'))
2125 exe "normal \<C-B>"
2126 call assert_equal(5, line('w0'))
2127 exe "normal \<C-B>"
2128 call assert_equal(2, line('w0'))
2129 exe "normal \<C-B>"
2130 call assert_equal(1, line('w0'))
2131 set window=1
2132 exe "normal gg\<C-F>"
2133 call assert_equal(2, line('w0'))
2134 exe "normal \<C-F>"
2135 call assert_equal(3, line('w0'))
2136 exe "normal \<C-B>"
2137 call assert_equal(2, line('w0'))
2138 exe "normal \<C-B>"
2139 call assert_equal(1, line('w0'))
2140 enew!
2141 set window&
2142endfunc
2143
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002144" Test for the 'winminheight' option
2145func Test_opt_winminheight()
2146 only!
2147 let &winheight = &lines + 4
2148 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2149 call assert_true(&winminheight <= &lines)
2150 set winminheight&
2151 set winheight&
2152endfunc
2153
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002154func Test_opt_winminheight_term()
2155 CheckRunVimInTerminal
2156
2157 " The tabline should be taken into account.
2158 let lines =<< trim END
2159 set wmh=0 stal=2
2160 below sp | wincmd _
2161 below sp | wincmd _
2162 below sp | wincmd _
2163 below sp
2164 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002165 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002166 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2167 call term_sendkeys(buf, ":set wmh=1\n")
2168 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2169
2170 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002171endfunc
2172
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002173func Test_opt_winminheight_term_tabs()
2174 CheckRunVimInTerminal
2175
2176 " The tabline should be taken into account.
2177 let lines =<< trim END
2178 set wmh=0 stal=2
2179 split
2180 split
2181 split
2182 split
2183 tabnew
2184 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002185 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002186 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2187 call term_sendkeys(buf, ":set wmh=1\n")
2188 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2189
2190 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002191endfunc
2192
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002193" Test for the 'winminwidth' option
2194func Test_opt_winminwidth()
2195 only!
2196 let &winwidth = &columns + 4
2197 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2198 call assert_true(&winminwidth <= &columns)
2199 set winminwidth&
2200 set winwidth&
2201endfunc
2202
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002203" Test for setting option value containing spaces with isfname+=32
2204func Test_isfname_with_options()
2205 set isfname+=32
2206 setlocal keywordprg=:term\ help.exe
2207 call assert_equal(':term help.exe', &keywordprg)
2208 set isfname&
2209 setlocal keywordprg&
2210endfunc
2211
Bram Moolenaar74667062020-12-28 15:41:41 +01002212" Test that resetting laststatus does change scroll option
2213func Test_opt_reset_scroll()
2214 CheckRunVimInTerminal
2215 let vimrc =<< trim [CODE]
2216 set scroll=2
2217 set laststatus=2
2218 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002219 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002220 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2221 call term_sendkeys(buf, ":verbose set scroll?\n")
2222 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2223 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002224
2225 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002226 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002227endfunc
2228
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002229" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2230func Test_VIM_POSIX()
2231 let saved_VIM_POSIX = getenv("VIM_POSIX")
2232
2233 call setenv('VIM_POSIX', "1")
2234 let after =<< trim [CODE]
2235 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2236 qall
2237 [CODE]
2238 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002239 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002240 \ 'AS'], readfile('X_VIM_POSIX'))
2241 endif
2242
2243 call setenv('VIM_POSIX', v:null)
2244 let after =<< trim [CODE]
2245 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2246 qall
2247 [CODE]
2248 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002249 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002250 \ 'S'], readfile('X_VIM_POSIX'))
2251 endif
2252
2253 call delete('X_VIM_POSIX')
2254 call setenv('VIM_POSIX', saved_VIM_POSIX)
2255endfunc
2256
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002257" Test for setting an option to a Vi or Vim default
2258func Test_opt_default()
2259 set formatoptions&vi
2260 call assert_equal('vt', &formatoptions)
2261 set formatoptions&vim
2262 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002263
2264 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2265 set fencs=latin1
2266 set fencs&
2267 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2268 set fencs=latin1
2269 set all&
2270 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002271endfunc
2272
2273" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002274func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002275 %bw!
2276 let ht = &lines
2277 set cmdheight=9999
2278 call assert_equal(1, winheight(0))
2279 call assert_equal(ht - 1, &cmdheight)
2280 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002281
2282 " The status line should be taken into account.
2283 set laststatus=2
2284 set cmdheight=9999
2285 call assert_equal(ht - 2, &cmdheight)
2286 set cmdheight& laststatus&
2287
2288 " The tabline should be taken into account only non-GUI.
2289 set showtabline=2
2290 set cmdheight=9999
2291 if has('gui_running')
2292 call assert_equal(ht - 1, &cmdheight)
2293 else
2294 call assert_equal(ht - 2, &cmdheight)
2295 endif
2296 set cmdheight& showtabline&
2297
2298 " The 'winminheight' should be taken into account.
2299 set winheight=3 winminheight=3
2300 split
2301 set cmdheight=9999
2302 call assert_equal(ht - 8, &cmdheight)
2303 %bw!
2304 set cmdheight& winminheight& winheight&
2305
2306 " Only the windows in the current tabpage are taken into account.
2307 set winheight=3 winminheight=3 showtabline=0
2308 split
2309 tabnew
2310 set cmdheight=9999
2311 call assert_equal(ht - 3, &cmdheight)
2312 %bw!
2313 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002314endfunc
2315
Dominique Pelle923dce22021-11-21 11:36:04 +00002316" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002317func Test_opt_control_char()
2318 set wildchar=^v
2319 call assert_equal("\<C-V>", nr2char(&wildchar))
2320 set wildcharm=^r
2321 call assert_equal("\<C-R>", nr2char(&wildcharm))
2322 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2323 set wildchar& wildcharm&
2324endfunc
2325
2326" Test for the 'errorbells' option
2327func Test_opt_errorbells()
2328 set errorbells
2329 call assert_beeps('s/a1b2/x1y2/')
2330 set noerrorbells
2331endfunc
2332
Dominique Pelle042414f2021-07-12 21:43:19 +02002333func Test_opt_scrolljump()
2334 help
2335 resize 10
2336
2337 " Test with positive 'scrolljump'.
2338 set scrolljump=2
2339 norm! Lj
2340 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2341 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2342 \ winsaveview())
2343
2344 " Test with negative 'scrolljump' (percentage of window height).
2345 set scrolljump=-40
2346 norm! ggLj
2347 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2348 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2349 \ winsaveview())
2350
2351 set scrolljump&
2352 bw
2353endfunc
2354
Bakudankun29f3a452021-12-11 12:28:08 +00002355" Test for the 'cdhome' option
2356func Test_opt_cdhome()
2357 if has('unix') || has('vms')
2358 throw 'Skipped: only works on non-Unix'
2359 endif
2360
2361 set cdhome&
2362 call assert_equal(0, &cdhome)
2363 set cdhome
2364
2365 " This paragraph is copied from Test_cd_no_arg().
2366 let path = getcwd()
2367 cd
2368 call assert_equal($HOME, getcwd())
2369 call assert_notequal(path, getcwd())
2370 exe 'cd ' .. fnameescape(path)
2371 call assert_equal(path, getcwd())
2372
2373 set cdhome&
2374endfunc
2375
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002376func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002377 CheckOption termguicolors
2378
2379 " Test default option completion
2380 set wildoptions=
2381 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2382 call assert_equal('"set termguicolors', @:)
2383
2384 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2385 call assert_equal('"set notermguicolors', @:)
2386
2387 " Test fuzzy option completion
2388 set wildoptions=fuzzy
2389 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2390 call assert_equal('"set termguicolors termencoding', @:)
2391
2392 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2393 call assert_equal('"set notermguicolors', @:)
2394
2395 set wildoptions=
2396endfunc
2397
Sean Dewar39c46b42022-05-12 17:44:29 +01002398func Test_switchbuf_reset()
2399 set switchbuf=useopen
2400 sblast
2401 call assert_equal(1, winnr('$'))
2402 set all&
2403 call assert_equal('', &switchbuf)
2404 sblast
2405 call assert_equal(2, winnr('$'))
2406 only!
2407endfunc
2408
zeertzjqfcba86c2022-09-22 13:57:32 +01002409" :set empty string for global 'keywordprg' falls back to ":help"
2410func Test_keywordprg_empty()
2411 let k = &keywordprg
2412 set keywordprg=man
2413 call assert_equal('man', &keywordprg)
2414 set keywordprg=
2415 call assert_equal(':help', &keywordprg)
2416 set keywordprg=man
2417 call assert_equal('man', &keywordprg)
2418 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2419 let &keywordprg = k
2420endfunc
2421
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002422" check that the very first buffer created does not have 'endoffile' set
2423func Test_endoffile_default()
2424 let after =<< trim [CODE]
2425 call writefile([execute('set eof?')], 'Xtestout')
2426 qall!
2427 [CODE]
2428 if RunVim([], after, '')
2429 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2430 endif
2431 call delete('Xtestout')
2432endfunc
2433
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002434" Test for setting the 'lines' and 'columns' options to a minimum value
2435func Test_set_min_lines_columns()
2436 let save_lines = &lines
2437 let save_columns = &columns
2438
2439 let after =<< trim END
2440 set nomore
2441 let msg = []
2442 let v:errmsg = ''
2443 silent! let &columns=0
2444 call add(msg, v:errmsg)
2445 silent! set columns=0
2446 call add(msg, v:errmsg)
2447 silent! call setbufvar('', '&columns', 0)
2448 call add(msg, v:errmsg)
2449 "call writefile(msg, 'XResultsetminlines')
2450 silent! let &lines=0
2451 call add(msg, v:errmsg)
2452 silent! set lines=0
2453 call add(msg, v:errmsg)
2454 silent! call setbufvar('', '&lines', 0)
2455 call add(msg, v:errmsg)
2456 call writefile(msg, 'XResultsetminlines')
2457 qall!
2458 END
2459 if RunVim([], after, '')
2460 call assert_equal(['E594: Need at least 12 columns',
2461 \ 'E594: Need at least 12 columns: columns=0',
2462 \ 'E594: Need at least 12 columns',
2463 \ 'E593: Need at least 2 lines',
2464 \ 'E593: Need at least 2 lines: lines=0',
2465 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2466 endif
2467
2468 call delete('XResultsetminlines')
2469 let &lines = save_lines
2470 let &columns = save_columns
2471endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002472
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002473" Test for reverting a string option value if the new value is invalid.
2474func Test_string_option_revert_on_failure()
2475 new
2476 let optlist = [
2477 \ ['ambiwidth', 'double', 'a123'],
2478 \ ['background', 'dark', 'a123'],
2479 \ ['backspace', 'eol', 'a123'],
2480 \ ['backupcopy', 'no', 'a123'],
2481 \ ['belloff', 'showmatch', 'a123'],
2482 \ ['breakindentopt', 'min:10', 'list'],
2483 \ ['bufhidden', 'wipe', 'a123'],
2484 \ ['buftype', 'nowrite', 'a123'],
2485 \ ['casemap', 'keepascii', 'a123'],
2486 \ ['cedit', "\<C-Y>", 'z'],
2487 \ ['colorcolumn', '10', 'z'],
2488 \ ['commentstring', '#%s', 'a123'],
2489 \ ['complete', '.,t', 'a'],
2490 \ ['completefunc', 'MyCmplFunc', '1a-'],
2491 \ ['completeopt', 'popup', 'a123'],
2492 \ ['completepopup', 'width:20', 'border'],
2493 \ ['concealcursor', 'v', 'xyz'],
2494 \ ['cpoptions', 'HJ', '~'],
2495 \ ['cryptmethod', 'zip', 'a123'],
2496 \ ['cursorlineopt', 'screenline', 'a123'],
2497 \ ['debug', 'throw', 'a123'],
2498 \ ['diffopt', 'iwhite', 'a123'],
2499 \ ['display', 'uhex', 'a123'],
2500 \ ['eadirection', 'hor', 'a123'],
2501 \ ['encoding', 'utf-8', 'a123'],
2502 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002503 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002504 \ ['fileencoding', 'utf-8', 'a123,'],
2505 \ ['fileformat', 'mac', 'a123'],
2506 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002507 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002508 \ ['fillchars', 'diff:~', 'a123'],
2509 \ ['foldclose', 'all', 'a123'],
2510 \ ['foldmarker', '[[[,]]]', '[[['],
2511 \ ['foldmethod', 'marker', 'a123'],
2512 \ ['foldopen', 'percent', 'a123'],
2513 \ ['formatoptions', 'an', '*'],
2514 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2515 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002516 \ ['highlight', '!:CursorColumn', '8:'],
2517 \ ['keymodel', 'stopsel', 'a123'],
2518 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2519 \ ['lispoptions', 'expr:1', 'a123'],
2520 \ ['listchars', 'tab:->', 'tab:'],
2521 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002522 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002523 \ ['mkspellmem', '100000,1000,100', '100000'],
2524 \ ['mouse', 'nvi', 'z'],
2525 \ ['mousemodel', 'extend', 'a123'],
2526 \ ['nrformats', 'alpha', 'a123'],
2527 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2528 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2529 \ ['previewpopup', 'width:20', 'a123'],
2530 \ ['printoptions', 'paper:A4', 'a123:'],
2531 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2532 \ ['rulerformat', '%l', '%['],
2533 \ ['scrollopt', 'hor,jump', 'a123'],
2534 \ ['selection', 'exclusive', 'a123'],
2535 \ ['selectmode', 'cmd', 'a123'],
2536 \ ['sessionoptions', 'options', 'a123'],
2537 \ ['shortmess', 'w', '2'],
2538 \ ['showbreak', '>>', "\x01"],
2539 \ ['showcmdloc', 'statusline', 'a123'],
2540 \ ['signcolumn', 'no', 'a123'],
2541 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2542 \ ['spellfile', 'MySpell.en.add', "\x01"],
2543 \ ['spelllang', 'en', "#"],
2544 \ ['spelloptions', 'camel', 'a123'],
2545 \ ['spellsuggest', 'double', 'a123'],
2546 \ ['splitkeep', 'topline', 'a123'],
2547 \ ['statusline', '%f', '%['],
2548 \ ['swapsync', 'sync', 'a123'],
2549 \ ['switchbuf', 'usetab', 'a123'],
2550 \ ['syntax', 'abc', 'a^b'],
2551 \ ['tabline', '%f', '%['],
2552 \ ['tagcase', 'ignore', 'a123'],
2553 \ ['tagfunc', 'MyTagFunc', '1a-'],
2554 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2555 \ ['viewoptions', 'options', 'a123'],
2556 \ ['virtualedit', 'onemore', 'a123'],
2557 \ ['whichwrap', '<,>', '{,}'],
2558 \ ['wildmode', 'list', 'a123'],
2559 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002560 \ ]
2561 if has('gui')
2562 call add(optlist, ['browsedir', 'buffer', 'a123'])
2563 endif
2564 if has('clipboard_working')
2565 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2566 endif
2567 if has('win32')
2568 call add(optlist, ['completeslash', 'slash', 'a123'])
2569 endif
2570 if has('cscope')
2571 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2572 endif
2573 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002574 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2575 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2576 endif
2577 if has('keymap')
2578 call add(optlist, ['keymap', 'greek', '[]'])
2579 endif
2580 if has('mouseshape')
2581 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2582 endif
2583 if has('win32') && has('gui')
2584 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2585 endif
2586 if has('rightleft')
2587 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2588 endif
2589 if has('terminal')
2590 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2591 call add(optlist, ['termwinsize', '24x80', '100'])
2592 endif
2593 if has('win32') && has('terminal')
2594 call add(optlist, ['termwintype', 'winpty', 'a123'])
2595 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002596 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002597 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002598 endif
2599 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002600 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2601 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002602 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002603 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2604 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002605 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002606 call add(optlist, ['varsofttabstop', '12', 'a123'])
2607 call add(optlist, ['vartabstop', '4,20', '4,'])
2608 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002609 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002610 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002611 endif
2612 for opt in optlist
2613 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002614 try
2615 exe $"let &{opt[0]} = '{opt[1]}'"
2616 catch
2617 call assert_report($"Caught {v:exception} with {opt->string()}")
2618 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002619 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2620 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2621 exe $"let &{opt[0]} = save_opt"
2622 endfor
2623 bw!
2624endfunc
2625
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002626func Test_set_option_window_global_local()
2627 new Xbuffer1
2628 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2629 setlocal scrolloff=2
2630 setglobal scrolloff=3
2631 setl modified
2632 " A new buffer has its own window-local options
2633 hide enew
2634 call assert_equal(-1, &l:scrolloff)
2635 call assert_equal(3, &g:scrolloff)
2636 " A new window opened with its own buffer-local options
2637 new
2638 call assert_equal(-1, &l:scrolloff)
2639 call assert_equal(3, &g:scrolloff)
2640 " Re-open Xbuffer1 and it should use
2641 " the previous set window-local options
2642 b Xbuffer1
2643 call assert_equal(2, &l:scrolloff)
2644 call assert_equal(3, &g:scrolloff)
2645 bw!
2646 bw!
2647 let &g:scrolloff = _gso
2648endfunc
2649
2650func GetGlobalLocalWindowOptions()
2651 new
2652 sil! r $VIMRUNTIME/doc/options.txt
2653 " Filter for global or local to window
2654 v/^'.*'.*\n.*global or local to window |global-local/d
2655 " get option value and type
2656 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2657 sil %s/empty/""/g
2658 " split the result
2659 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2660 bw!
2661 return result
2662endfunc
2663
2664func Test_set_option_window_global_local_all()
2665 new Xbuffer2
2666
2667 let optionlist = GetGlobalLocalWindowOptions()
2668 for [opt, type, default] in optionlist
2669 let _old = eval('&g:' .. opt)
2670 if type == 'string'
2671 if opt == 'fillchars'
2672 exe 'setl ' .. opt .. '=vert:+'
2673 exe 'setg ' .. opt .. '=vert:+,fold:+'
2674 elseif opt == 'listchars'
2675 exe 'setl ' .. opt .. '=tab:>>'
2676 exe 'setg ' .. opt .. '=tab:++'
2677 elseif opt == 'virtualedit'
2678 exe 'setl ' .. opt .. '=all'
2679 exe 'setg ' .. opt .. '=block'
2680 else
2681 exe 'setl ' .. opt .. '=Local'
2682 exe 'setg ' .. opt .. '=Global'
2683 endif
2684 elseif type == 'number'
2685 exe 'setl ' .. opt .. '=5'
2686 exe 'setg ' .. opt .. '=10'
2687 endif
2688 setl modified
2689 hide enew
2690 if type == 'string'
2691 call assert_equal('', eval('&l:' .. opt))
2692 if opt == 'fillchars'
2693 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2694 elseif opt == 'listchars'
2695 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2696 elseif opt == 'virtualedit'
2697 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2698 else
2699 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2700 endif
2701 elseif type == 'number'
2702 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2703 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2704 endif
2705 bw!
2706 exe 'let &g:' .. opt .. '=' .. default
2707 endfor
2708 bw!
2709endfunc
2710
Christian Brabandt757593c2023-08-22 21:44:10 +02002711func Test_paste_depending_options()
2712 " setting the paste option, resets all dependent options
2713 " and will be reported correctly using :verbose set <option>?
2714 let lines =<< trim [CODE]
2715 " set paste test
2716 set autoindent
2717 set expandtab
2718 " disabled, because depends on compiled feature set
2719 " set hkmap
2720 " set revins
2721 " set varsofttabstop=8,32,8
2722 set ruler
2723 set showmatch
2724 set smarttab
2725 set softtabstop=4
2726 set textwidth=80
2727 set wrapmargin=10
2728
2729 source Xvimrc_paste2
2730
2731 redir > Xoutput_paste
2732 verbose set expandtab?
2733 verbose setg expandtab?
2734 verbose setl expandtab?
2735 redir END
2736
2737 qall!
2738 [CODE]
2739
2740 call writefile(lines, 'Xvimrc_paste', 'D')
2741 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2742 if !RunVim([], lines, '--clean')
2743 return
2744 endif
2745
2746 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2747 call assert_equal('noexpandtab', result[0])
2748 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2749 call assert_equal('noexpandtab', result[2])
2750 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2751 call assert_equal('noexpandtab', result[4])
2752 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2753
2754 call delete('Xoutput_paste')
2755endfunc
2756
2757func Test_binary_depending_options()
2758 " setting the paste option, resets all dependent options
2759 " and will be reported correctly using :verbose set <option>?
2760 let lines =<< trim [CODE]
2761 " set binary test
2762 set expandtab
2763
2764 source Xvimrc_bin2
2765
2766 redir > Xoutput_bin
2767 verbose set expandtab?
2768 verbose setg expandtab?
2769 verbose setl expandtab?
2770 redir END
2771
2772 qall!
2773 [CODE]
2774
2775 call writefile(lines, 'Xvimrc_bin', 'D')
2776 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2777 if !RunVim([], lines, '--clean')
2778 return
2779 endif
2780
2781 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2782 call assert_equal('noexpandtab', result[0])
2783 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2784 call assert_equal('noexpandtab', result[2])
2785 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2786 call assert_equal('noexpandtab', result[4])
2787 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2788
2789 call delete('Xoutput_bin')
2790endfunc
2791
Gregory Anders3695d0e2023-09-29 20:17:20 +02002792func Test_set_keyprotocol()
2793 CheckNotGui
2794
2795 let term = &term
2796 set term=ansi
2797 call assert_equal('', &t_TI)
2798
2799 " Setting 'keyprotocol' should affect terminal codes without needing to
2800 " reset 'term'
2801 set keyprotocol+=ansi:kitty
2802 call assert_equal("\<Esc>[=1;1u", &t_TI)
2803 let &term = term
2804endfunc
2805
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002806func Test_set_wrap()
2807 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2808 " cursor position.
2809 set wrap smoothscroll scrolloff=5
2810
2811 call setline(1, ['', 'aaaa'->repeat(500)])
2812 20 split
2813 20 vsplit
2814 norm 2G$
2815 redraw
2816 set nowrap
2817 call assert_equal(2, winline())
2818
2819 set wrap& smoothscroll& scrolloff&
2820endfunc
2821
zeertzjqcd3a13e2024-02-24 16:51:32 +01002822func Test_delcombine()
2823 new
2824 set backspace=indent,eol,start
2825
2826 set delcombine
2827 call setline(1, 'β̳̈:β̳̈')
2828 normal! 0x
2829 call assert_equal('β̈:β̳̈', getline(1))
2830 exe "normal! A\<BS>"
2831 call assert_equal('β̈:β̈', getline(1))
2832 normal! 0x
2833 call assert_equal('β:β̈', getline(1))
2834 exe "normal! A\<BS>"
2835 call assert_equal('β:β', getline(1))
2836 normal! 0x
2837 call assert_equal(':β', getline(1))
2838 exe "normal! A\<BS>"
2839 call assert_equal(':', getline(1))
2840
2841 set nodelcombine
2842 call setline(1, 'β̳̈:β̳̈')
2843 normal! 0x
2844 call assert_equal(':β̳̈', getline(1))
2845 exe "normal! A\<BS>"
2846 call assert_equal(':', getline(1))
2847
2848 set backspace& delcombine&
2849 bwipe!
2850endfunc
2851
Milly484face2024-10-12 11:26:06 +02002852" Should not raise errors when set missing-options.
2853func Test_set_missing_options()
2854 set autoprint
2855 set beautify
2856 set flash
2857 set graphic
2858 set hardtabs=8
2859 set mesg
2860 set novice
2861 set open
2862 set optimize
2863 set redraw
2864 set slowopen
2865 set sourceany
2866 set w300=23
2867 set w1200=23
2868 set w9600=23
2869endfunc
2870
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002871func Test_default_keyprotocol()
2872 " default value of keyprotocol
2873 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2874endfunc
2875
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002876" vim: shiftwidth=2 sts=2 expandtab