blob: 2b90459b2dd1cf56d05262149ca6b24aa59abcfd [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])
zeertzjq53d59ec2025-03-07 19:09:09 +0100504 call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200505 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200506 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200507 endif
508 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200509 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200510 endif
511 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200512 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200513 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200514 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
515 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
516 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200517 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200518 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200519 endif
520 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200521 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200522 endif
523 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200524 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200525 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200526 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
527 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
528 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200529 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200530 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200531 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200532 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200533 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200534 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
535 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
536 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200537 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200538 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200539 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200540 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200541 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200542 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200543 endif
544 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
547 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200548 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200549 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200550 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
551 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
552 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
553 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200554 if exists('+tabclose')
555 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
556 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200557 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200558 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200559 endif
560 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200561 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200562 endif
563 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200564 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200565 endif
566 if exists('+ttymouse')
567 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200568 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200569 set ttymouse&
570 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200571 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
572 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
573 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
574 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200575 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200576 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200577 endif
578
579 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200580 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100581 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200582 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
583 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
584 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200585
zeertzjq1f025b02023-09-30 12:43:07 +0200586 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
587 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
588 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
589 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
590 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
591 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200592
593 "
594 " Unique string options below
595 "
596
597 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200598 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200599 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
600 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100601 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
602 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200603 set keyprotocol&
604
605 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200606 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
607 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200608 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
609 call assert_equal('"set previewpopup+=border:on', @:)
610 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
611 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200612 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200613 set previewpopup& completepopup&
614
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100615 " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200616 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
617 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
618 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100619 call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200620
621 " highlight: special parsing, including auto-completing highlight groups
622 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200623 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
624 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
625 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
626 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
627 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200628 " If all the display modes are used up we should be suggesting nothing. Make
629 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
630 " and make sure nothing is suggested from that.
631 let hl_display_modes = join(
632 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
633 \ {idx, val -> val[1]}),
634 \ {idx, val -> val != ':'}),
635 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200636 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200637 " Test completion in middle of the line
638 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
639 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200640
Christian Brabandt51d4d842024-12-06 17:26:25 +0100641 " messagesopt
642 call assert_equal(['history:', 'hit-enter', 'wait:'],
643 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
644
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200645 "
646 " Test flag lists
647 "
648
649 " Test set=. Show the original value if nothing is typed after '='.
650 " Otherwise, the list should avoid showing what's already typed.
651 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200652 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200653 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200654 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
655 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200656
657 " Test set+=. Never show original value, and it also tries to avoid listing
658 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200659 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
660 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
661 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200662
663 " Test that the position of the expansion is correct (even if there are
664 " additional values after the current cursor)
665 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
666 call assert_equal('"set mouse=han', @:)
667 set mouse&
668
669 " Test that other flag list options have auto-complete, but don't
670 " exhaustively validate their results.
671 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200672 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200673 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200674 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
675 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200676 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200677 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200678 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200679 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
680 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200681
682 "
683 "Test set-=
684 "
685
686 " Normal single-value option just shows the existing value
687 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200688 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200689 set ambiwidth&
690
691 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200692 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200693 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200694 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200695 set t_Ce&
696
697 " Comma-separated lists should present each option
698 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200699 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
700 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
701 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200703 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200704 " Test empty option
705 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200706 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100707 " Test all possible values
708 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100709 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'],
Christian Brabandt9162e632025-01-16 19:03:40 +0100710 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200711 set diffopt&
712
713 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200714 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200715
716 " Test files with commas in name are being parsed and escaped properly
717 set path=has\\\ space,file\\,with\\,comma,normal_file
718 if exists('+completeslash')
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 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200721 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200722 endif
723 set path&
724
725 " Flag list should present orig value, then individual flags
726 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200727 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200728 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200729 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200730 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200731 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200732 " Test empty option
733 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200734 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200735 set mouse&
736
737 " 'whichwrap' is an odd case where it's both flag list and comma-separated
738 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200739 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200740 set ww&
741endfunc
742
zeertzjq4c7cb372023-06-14 16:39:54 +0100743func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100744 call assert_fails('set scroll=-1', 'E49:')
745 call assert_fails('set backupcopy=', 'E474:')
746 call assert_fails('set regexpengine=3', 'E474:')
747 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200748 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100749 call assert_fails('set colorcolumn=-a', 'E474:')
750 call assert_fails('set colorcolumn=a', 'E474:')
751 call assert_fails('set colorcolumn=1,', 'E474:')
752 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100753 call assert_fails('set cmdheight=-1', 'E487:')
754 call assert_fails('set cmdwinheight=-1', 'E487:')
755 if has('conceal')
756 call assert_fails('set conceallevel=-1', 'E487:')
757 call assert_fails('set conceallevel=4', 'E474:')
758 endif
759 call assert_fails('set helpheight=-1', 'E487:')
760 call assert_fails('set history=-1', 'E487:')
761 call assert_fails('set report=-1', 'E487:')
762 call assert_fails('set shiftwidth=-1', 'E487:')
763 call assert_fails('set sidescroll=-1', 'E487:')
764 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000765 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000766 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000767 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200768 if has('terminal')
769 call assert_fails('set termwinscroll=-1', 'E487:')
770 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100771 call assert_fails('set textwidth=-1', 'E487:')
772 call assert_fails('set timeoutlen=-1', 'E487:')
773 call assert_fails('set updatecount=-1', 'E487:')
774 call assert_fails('set updatetime=-1', 'E487:')
775 call assert_fails('set winheight=-1', 'E487:')
776 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200777
778 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100779 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200780 call assert_fails('setlocal xxx', 'E518:')
781 call assert_fails('setglobal xxx', 'E518:')
782 call assert_fails('set xxx=', 'E518:')
783 call assert_fails('setlocal xxx=', 'E518:')
784 call assert_fails('setglobal xxx=', 'E518:')
785 call assert_fails('set xxx:', 'E518:')
786 call assert_fails('setlocal xxx:', 'E518:')
787 call assert_fails('setglobal xxx:', 'E518:')
788 call assert_fails('set xxx!', 'E518:')
789 call assert_fails('setlocal xxx!', 'E518:')
790 call assert_fails('setglobal xxx!', 'E518:')
791 call assert_fails('set xxx?', 'E518:')
792 call assert_fails('setlocal xxx?', 'E518:')
793 call assert_fails('setglobal xxx?', 'E518:')
794 call assert_fails('set xxx&', 'E518:')
795 call assert_fails('setlocal xxx&', 'E518:')
796 call assert_fails('setglobal xxx&', 'E518:')
797 call assert_fails('set xxx<', 'E518:')
798 call assert_fails('setlocal xxx<', 'E518:')
799 call assert_fails('setglobal xxx<', 'E518:')
800
801 " Test for missing-options errors.
802 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100803 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200804 call assert_fails('set flash?', 'E519:')
805 call assert_fails('set graphic?', 'E519:')
806 call assert_fails('set hardtabs?', 'E519:')
807 call assert_fails('set mesg?', 'E519:')
808 call assert_fails('set novice?', 'E519:')
809 call assert_fails('set open?', 'E519:')
810 call assert_fails('set optimize?', 'E519:')
811 call assert_fails('set redraw?', 'E519:')
812 call assert_fails('set slowopen?', 'E519:')
813 call assert_fails('set sourceany?', 'E519:')
814 call assert_fails('set w300?', 'E519:')
815 call assert_fails('set w1200?', 'E519:')
816 call assert_fails('set w9600?', 'E519:')
817
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100818 call assert_fails('set undolevels=x', 'E521:')
819 call assert_fails('set tabstop=', 'E521:')
820 call assert_fails('set comments=-', 'E524:')
821 call assert_fails('set comments=a', 'E525:')
822 call assert_fails('set foldmarker=x', 'E536:')
823 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000824 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100825 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100826 call assert_fails('set rulerformat=%-', 'E539:')
827 call assert_fails('set rulerformat=%(', 'E542:')
828 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200829
830 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100831 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100832 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100833 call assert_fails('set statusline=%{%', 'E540:')
834 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100835 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100836 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200837
838 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100839 call assert_fails('set tabline=%$', 'E539:')
840 call assert_fails('set tabline=%{', 'E540:')
841 call assert_fails('set tabline=%{%', 'E540:')
842 call assert_fails('set tabline=%{%}', 'E539:')
843 call assert_fails('set tabline=%(', 'E542:')
844 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100845
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100846 if has('cursorshape')
847 " This invalid value for 'guicursor' used to cause Vim to crash.
848 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
849 call assert_fails('set guicursor=i-ci', 'E545:')
850 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100851 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100852 call assert_fails('set guicursor=r-cr:horx', 'E548:')
853 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
854 endif
Milly484face2024-10-12 11:26:06 +0200855
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100856 if has('mouseshape')
857 call assert_fails('se mouseshape=i-r:x', 'E547:')
858 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000859
860 " Test for 'backupext' and 'patchmode' set to the same value
861 set backupext=.bak
862 set patchmode=.patch
863 call assert_fails('set patchmode=.bak', 'E589:')
864 call assert_equal('.patch', &patchmode)
865 call assert_fails('set backupext=.patch', 'E589:')
866 call assert_equal('.bak', &backupext)
867 set backupext& patchmode&
868
Milly484face2024-10-12 11:26:06 +0200869 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100870 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200871 set winminheight& winheight&
872 set winheight=10 winminheight=10
873 call assert_fails('set winheight=9', 'E591:')
874 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200875
876 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100877 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200878 set winminwidth& winwidth&
879 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
880 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200881
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100882 call assert_fails("set showbreak=\x01", 'E595:')
883 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200884 call assert_fails('set tabstop??', 'E488:')
885 call assert_fails('set wrapscan!!', 'E488:')
886 call assert_fails('set tabstop&&', 'E488:')
887 call assert_fails('set wrapscan<<', 'E488:')
888 call assert_fails('set wrapscan=1', 'E474:')
889 call assert_fails('set autoindent@', 'E488:')
890 call assert_fails('set wildchar=<abc>', 'E474:')
891 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200892 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100893 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200894 call assert_fails('set pyxversion=6', 'E474:')
895 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100896 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200897 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100898 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
899 call assert_fails('set foldmarker={{{,', 'E474:')
900 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200901
902 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100903 setlocal listchars=trail:·
904 call assert_fails('set ambiwidth=double', 'E834:')
905 setlocal listchars=trail:-
906 setglobal listchars=trail:·
907 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100908 set listchars&
Milly484face2024-10-12 11:26:06 +0200909
910 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100911 setlocal fillchars=stl:·
912 call assert_fails('set ambiwidth=double', 'E835:')
913 setlocal fillchars=stl:-
914 setglobal fillchars=stl:·
915 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100916 set fillchars&
Milly484face2024-10-12 11:26:06 +0200917
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100918 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
919 set nomodifiable
920 call assert_fails('set fileencoding=latin1', 'E21:')
921 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200922 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000923 call assert_fails('let &formatoptions = "?"', 'E539:')
924 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200925
926 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100927 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
928 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
929 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
930 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
931 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
932 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100933endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100934
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000935func Test_set_encoding()
936 let save_encoding = &encoding
937
938 set enc=iso8859-1
939 call assert_equal('latin1', &enc)
940 set enc=iso8859_1
941 call assert_equal('latin1', &enc)
942 set enc=iso-8859-1
943 call assert_equal('latin1', &enc)
944 set enc=iso_8859_1
945 call assert_equal('latin1', &enc)
946 set enc=iso88591
947 call assert_equal('latin1', &enc)
948 set enc=iso8859
949 call assert_equal('latin1', &enc)
950 set enc=iso-8859
951 call assert_equal('latin1', &enc)
952 set enc=iso_8859
953 call assert_equal('latin1', &enc)
954 call assert_fails('set enc=iso8858', 'E474:')
955 call assert_equal('latin1', &enc)
956
957 let &encoding = save_encoding
958endfunc
959
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200960func CheckWasSet(name)
961 let verb_cm = execute('verbose set ' .. a:name .. '?')
962 call assert_match('Last set from.*test_options.vim', verb_cm)
963endfunc
964func CheckWasNotSet(name)
965 let verb_cm = execute('verbose set ' .. a:name .. '?')
966 call assert_notmatch('Last set from', verb_cm)
967endfunc
968
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200969" Must be executed before other tests that set 'term'.
970func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200971 CheckNotGui
972
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200973 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200974
975 let term_save = &term
976 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200977 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200978 let &term = term_save
979endfunc
980
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200981func Test_copy_context()
982 setlocal list
983 call CheckWasSet('list')
984 split
985 call CheckWasSet('list')
986 quit
987 setlocal nolist
988
989 set ai
990 call CheckWasSet('ai')
991 set filetype=perl
992 call CheckWasSet('filetype')
993 set fo=tcroq
994 call CheckWasSet('fo')
995
996 split Xsomebuf
997 call CheckWasSet('ai')
998 call CheckWasNotSet('filetype')
999 call CheckWasSet('fo')
1000endfunc
1001
Bram Moolenaar67391142017-02-19 21:07:04 +01001002func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001003 CheckUnix
1004 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001005
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001006 " Setting 'ttytype' used to cause a double-free when exiting vim and
1007 " when vim is compiled with -DEXITFREE.
1008 set ttytype=ansi
1009 call assert_equal('ansi', &ttytype)
1010 call assert_equal(&ttytype, &term)
1011 set ttytype=xterm
1012 call assert_equal('xterm', &ttytype)
1013 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001014 try
1015 set ttytype=
1016 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001017 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001018 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001019
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001020 " Some systems accept any terminal name and return dumb settings,
1021 " check for failure of finding the entry and for missing 'cm' entry.
1022 try
1023 set ttytype=xxx
1024 call assert_report('set ttytype=xxx did not fail')
1025 catch /E522\|E437/
1026 endtry
1027
1028 set ttytype&
1029 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001030
1031 if has('gui') && !has('gui_running')
1032 call assert_fails('set term=gui', 'E531:')
1033 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001034endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001035
Milly484face2024-10-12 11:26:06 +02001036" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001037func Test_set_all()
1038 set tw=75
1039 set iskeyword=a-z,A-Z
1040 set nosplitbelow
1041 let out = execute('set all')
1042 call assert_match('textwidth=75', out)
1043 call assert_match('iskeyword=a-z,A-Z', out)
1044 call assert_match('nosplitbelow', out)
1045 set tw& iskeyword& splitbelow&
1046endfunc
1047
Milly484face2024-10-12 11:26:06 +02001048" Test for :set! all
1049func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001050 let out_mult = execute('set all')->split("\n")
1051 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001052 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001053 call assert_equal(out_one[0], '--- Options ---')
1054 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1055 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001056endfunc
1057
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001058func Test_renderoptions()
1059 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1060 " Doesn't hurt to do this on a non-Windows system.
1061 if windowsversion() !~ '^[345]\.'
1062 set renderoptions=type:directx
1063 set rop=type:directx
1064 endif
1065endfunc
1066
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001067func ResetIndentexpr()
1068 set indentexpr=
1069endfunc
1070
1071func Test_set_indentexpr()
1072 " this was causing usage of freed memory
1073 set indentexpr=ResetIndentexpr()
1074 new
1075 call feedkeys("i\<c-f>", 'x')
1076 call assert_equal('', &indentexpr)
1077 bwipe!
1078endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001079
1080func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001081 " Option 'backupskip' may contain several comma-separated path
1082 " specifications if one or more of the environment variables TMPDIR, TMP,
1083 " or TEMP is defined. To simplify testing, convert the string value into a
1084 " list.
1085 let bsklist = split(&bsk, ',')
1086
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001087 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001088 let found = (index(bsklist, '/private/tmp/*') >= 0)
1089 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001090 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001091 let found = (index(bsklist, '/tmp/*') >= 0)
1092 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001093 endif
1094
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001095 " If our test platform is Windows, the path(s) in option bsk will use
1096 " backslash for the path separator and the components could be in short
1097 " (8.3) format. As such, we need to replace the backslashes with forward
1098 " slashes and convert the path components to long format. The expand()
1099 " function will do this but it cannot handle comma-separated paths. This is
1100 " why bsk was converted from a string into a list of strings above.
1101 "
1102 " One final complication is that the wildcard "/*" is at the end of each
1103 " path and so expand() might return a list of matching files. To prevent
1104 " this, we need to remove the wildcard before calling expand() and then
1105 " append it afterwards.
1106 if has('win32')
1107 let item_nbr = 0
1108 while item_nbr < len(bsklist)
1109 let path_spec = bsklist[item_nbr]
1110 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1111 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1112 let bsklist[item_nbr] = path_spec . '/*'
1113 let item_nbr += 1
1114 endwhile
1115 endif
1116
1117 " Option bsk will also include these environment variables if defined.
1118 " If they're defined, verify they appear in the option value.
1119 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001120 if exists(var)
1121 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001122 let varvalue = substitute(varvalue, '/$', '', '')
1123 let varvalue .= '/*'
1124 let found = (index(bsklist, varvalue) >= 0)
1125 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001126 endif
1127 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001128
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001129 " Duplicates from environment variables should be filtered out (option has
1130 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1131 " so that we see what happens on startup.
1132 let after =<< trim [CODE]
1133 let bsklist = split(&backupskip, ',')
1134 call assert_equal(uniq(copy(bsklist)), bsklist)
1135 call writefile(['errors:'] + v:errors, 'Xtestout')
1136 qall
1137 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001138 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001139 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1140
1141 let saveenv = {}
1142 for var in ['TMPDIR', 'TMP', 'TEMP']
1143 let saveenv[var] = getenv(var)
1144 call setenv(var, '/duplicate/path')
1145 endfor
1146
1147 exe 'silent !' . cmd
1148 call assert_equal(['errors:'], readfile('Xtestout'))
1149
1150 " restore environment variables
1151 for var in ['TMPDIR', 'TMP', 'TEMP']
1152 call setenv(var, saveenv[var])
1153 endfor
1154
1155 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001156
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001157 " Duplicates should be filtered out (option has P_NODUP)
1158 let backupskip = &backupskip
1159 set backupskip=
1160 set backupskip+=/test/dir
1161 set backupskip+=/other/dir
1162 set backupskip+=/test/dir
1163 call assert_equal('/test/dir,/other/dir', &backupskip)
1164 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001165endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001166
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001167func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001168 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001169
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001170 " Test copy option from current buffer in window
1171 split
1172 enew
1173 setlocal numberwidth=5
1174 wincmd w
1175 call assert_equal(4,&numberwidth)
1176 bnext
1177 call assert_equal(5,&numberwidth)
1178 bw!
1179 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001180
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001181 " Test copy value from window that used to be display the buffer
1182 split
1183 enew
1184 setlocal numberwidth=6
1185 bnext
1186 wincmd w
1187 call assert_equal(4,&numberwidth)
1188 bnext
1189 call assert_equal(6,&numberwidth)
1190 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001191
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001192 " Test that if buffer is current, don't use the stale cached value
1193 " from the last time the buffer was displayed.
1194 split
1195 enew
1196 setlocal numberwidth=7
1197 bnext
1198 bnext
1199 setlocal numberwidth=8
1200 wincmd w
1201 call assert_equal(4,&numberwidth)
1202 bnext
1203 call assert_equal(8,&numberwidth)
1204 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001205
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001206 " Test value is not copied if window already has seen the buffer
1207 enew
1208 split
1209 setlocal numberwidth=9
1210 bnext
1211 setlocal numberwidth=10
1212 wincmd w
1213 call assert_equal(4,&numberwidth)
1214 bnext
1215 call assert_equal(4,&numberwidth)
1216 bw!
1217
1218 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001219endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001220
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001221def Test_split_copy_options()
1222 var values = [
1223 ['cursorbind', true, false],
1224 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1225 ['list', true, 0],
1226 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1227 ['number', true, 0],
1228 ['relativenumber', true, false],
1229 ['scrollbind', true, false],
1230 ['smoothscroll', true, false],
1231 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1232 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1233 ['wrap', false, true],
1234 ]
1235 if has('linebreak')
1236 values += [
1237 ['breakindent', true, false],
1238 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1239 ['linebreak', true, false],
1240 ['numberwidth', 7, 4],
1241 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1242 ]
1243 endif
1244 if has('rightleft')
1245 values += [
1246 ['rightleft', true, false],
1247 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1248 ]
1249 endif
1250 if has('statusline')
1251 values += [
1252 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1253 ]
1254 endif
1255 if has('spell')
1256 values += [
1257 ['spell', true, false],
1258 ]
1259 endif
1260 if has('syntax')
1261 values += [
1262 ['cursorcolumn', true, false],
1263 ['cursorline', true, false],
1264 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1265 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1266 ]
1267 endif
1268 if has('diff')
1269 values += [
1270 ['diff', true, false],
1271 ]
1272 endif
1273 if has('conceal')
1274 values += [
1275 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1276 ['conceallevel', '3', &conceallevel],
1277 ]
1278 endif
1279 if has('terminal')
1280 values += [
1281 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1282 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1283 ]
1284 endif
1285 if has('folding')
1286 values += [
1287 ['foldcolumn', 5, &foldcolumn],
1288 ['foldenable', false, true],
1289 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1290 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1291 ['foldlevel', 4, &foldlevel],
1292 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1293 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1294 ['foldminlines', 3, &foldminlines],
1295 ['foldnestmax', 17, &foldnestmax],
1296 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1297 ]
1298 endif
1299 if has('signs')
1300 values += [
1301 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1302 ]
1303 endif
1304
1305 # set options to non-default value
1306 for item in values
1307 exe $'&l:{item[0]} = {item[1]}'
1308 endfor
1309
1310 # check values are set in new window
1311 split
1312 for item in values
1313 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1314 endfor
1315
1316 # restore
1317 close
1318 for item in values
1319 exe $'&l:{item[0]} = {item[2]}'
1320 endfor
1321enddef
1322
Bram Moolenaarfc089602018-06-24 16:53:35 +02001323func Test_shortmess_F()
1324 new
1325 call assert_match('\[No Name\]', execute('file'))
1326 set shortmess+=F
1327 call assert_match('\[No Name\]', execute('file'))
1328 call assert_match('^\s*$', execute('file foo'))
1329 call assert_match('foo', execute('file'))
1330 set shortmess-=F
1331 call assert_match('bar', execute('file bar'))
1332 call assert_match('bar', execute('file'))
1333 set shortmess&
1334 bwipe
1335endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001336
1337func Test_shortmess_F2()
1338 e file1
1339 e file2
1340 call assert_match('file1', execute('bn', ''))
1341 call assert_match('file2', execute('bn', ''))
1342 set shortmess+=F
1343 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001344 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001345 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001346 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001347 set hidden
1348 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 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001351 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001352 set nohidden
1353 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 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001356 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001357 set shortmess&
1358 call assert_match('file1', execute('bn', ''))
1359 call assert_match('file2', execute('bn', ''))
1360 bwipe
1361 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001362 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001363endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001364
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001365func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001366 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001367
1368 set hidden
1369 set autoread
1370 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001371 e Xotherfile
1372 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001373 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001374 echo ''
1375
1376 if has('nanotime')
1377 sleep 10m
1378 else
1379 sleep 2
1380 endif
1381 call writefile(['bar'], 'X_dummy')
1382 bprev
1383 call assert_equal('', Screenline(&lines))
1384 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1385
1386 if has('nanotime')
1387 sleep 10m
1388 else
1389 sleep 2
1390 endif
1391 call writefile(['baz'], 'X_dummy')
1392 checktime
1393 call assert_equal('', Screenline(&lines))
1394 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001395
1396 set shortmess&
1397 set autoread&
1398 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001399 bwipe X_dummy
1400 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001401endfunc
1402
Bram Moolenaar375e3392019-01-31 18:26:10 +01001403func Test_local_scrolloff()
1404 set so=5
1405 set siso=7
1406 split
1407 call assert_equal(5, &so)
1408 setlocal so=3
1409 call assert_equal(3, &so)
1410 wincmd w
1411 call assert_equal(5, &so)
1412 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001413 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001414 setlocal so<
1415 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001416 setglob so=8
1417 call assert_equal(8, &so)
1418 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001419 setlocal so=0
1420 call assert_equal(0, &so)
1421 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001422 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001423
1424 call assert_equal(7, &siso)
1425 setlocal siso=3
1426 call assert_equal(3, &siso)
1427 wincmd w
1428 call assert_equal(7, &siso)
1429 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001430 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001431 setlocal siso<
1432 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001433 setglob siso=4
1434 call assert_equal(4, &siso)
1435 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001436 setlocal siso=0
1437 call assert_equal(0, &siso)
1438 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001439 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001440
1441 close
1442 set so&
1443 set siso&
1444endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001445
1446func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001447 CheckFunction reltimefloat
1448
Bram Moolenaar449ac472019-04-03 21:42:35 +02001449 new
1450 call setline(1, 'empty')
1451 redraw
1452 set writedelay=10
1453 let start = reltime()
1454 call setline(1, repeat('x', 70))
1455 redraw
1456 let elapsed = reltimefloat(reltime(start))
1457 set writedelay=0
1458 " With 'writedelay' set should take at least 30 * 10 msec
1459 call assert_inrange(30 * 0.01, 999.0, elapsed)
1460
1461 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001462endfunc
1463
1464func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001465 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001466 set visualbell
1467 call assert_beeps('normal 0h')
1468 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001469 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001470endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001471
1472" Test for the 'write' option
1473func Test_write()
1474 new
1475 call setline(1, ['L1'])
1476 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001477 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001478 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001479 " close swapfile
1480 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001481endfunc
1482
1483" Test for 'buftype' option
1484func Test_buftype()
1485 new
1486 call setline(1, ['L1'])
1487 set buftype=nowrite
1488 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001489
1490 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1491 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001492 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001493 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1494 endfor
1495
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001496 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001497endfunc
1498
Bram Moolenaar578fe942020-02-27 21:32:51 +01001499" Test for the 'rightleftcmd' option
1500func Test_rightleftcmd()
1501 CheckFeature rightleft
1502 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001503
1504 let g:l = []
1505 func AddPos()
1506 call add(g:l, screencol())
1507 return ''
1508 endfunc
1509 cmap <expr> <F2> AddPos()
1510
zeertzjqbb404f52022-07-23 06:25:29 +01001511 set rightleftcmd=
1512 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1513 \ "\<Right>\<F2>\<Esc>", 'xt')
1514 call assert_equal([2, 5, 3, 4], g:l)
1515
1516 let g:l = []
1517 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001518 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1519 \ "\<Left>\<F2>\<Esc>", 'xt')
1520 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1521
1522 cunmap <F2>
1523 unlet g:l
1524 set rightleftcmd&
1525 set rightleft&
1526endfunc
1527
zeertzjq28c162f2022-08-14 14:49:50 +01001528" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001529func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001530 " redraw to avoid matching previous messages
1531 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001532 set debug=beep
1533 exe "normal \<C-c>"
1534 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001535 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001536 " also check a line above, with a certain window width the colon is there
1537 call assert_match('Test_debug_option:$',
1538 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001539 set debug&
1540endfunc
1541
Bram Moolenaar004a6782020-04-11 17:09:31 +02001542" Test for the default CDPATH option
1543func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001544 let after =<< trim [CODE]
1545 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1546 call writefile(v:errors, 'Xtestout')
1547 qall
1548 [CODE]
1549 if has('unix')
1550 let $CDPATH='/path/to/dir1:/path/to/dir2'
1551 else
1552 let $CDPATH='/path/to/dir1;/path/to/dir2'
1553 endif
1554 if RunVim([], after, '')
1555 call assert_equal([], readfile('Xtestout'))
1556 call delete('Xtestout')
1557 endif
1558endfunc
1559
1560" Test for setting keycodes using set
1561func Test_opt_set_keycode()
1562 call assert_fails('set <t_k1=l', 'E474:')
1563 call assert_fails('set <Home=l', 'E474:')
1564 set <t_k9>=abcd
1565 call assert_equal('abcd', &t_k9)
1566 set <t_k9>&
1567 set <F9>=xyz
1568 call assert_equal('xyz', &t_k9)
1569 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001570
1571 " should we test all of them?
1572 set t_Ce=testCe
1573 set t_Cs=testCs
1574 set t_Us=testUs
1575 set t_ds=testds
1576 set t_Ds=testDs
1577 call assert_equal('testCe', &t_Ce)
1578 call assert_equal('testCs', &t_Cs)
1579 call assert_equal('testUs', &t_Us)
1580 call assert_equal('testds', &t_ds)
1581 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001582endfunc
1583
1584" Test for changing options in a sandbox
1585func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001586 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001587 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001588 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001589 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001590 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001591endfunc
1592
Milly484face2024-10-12 11:26:06 +02001593" Test for setting string global-local option value
1594func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001595 setglobal equalprg=gprg
1596 setlocal equalprg=lprg
1597 call assert_equal('gprg', &g:equalprg)
1598 call assert_equal('lprg', &l:equalprg)
1599 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001600
1601 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001602 set equalprg<
1603 call assert_equal('', &l:equalprg)
1604 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001605
1606 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001607 setglobal equalprg=gnewprg
1608 setlocal equalprg=lnewprg
1609 setlocal equalprg<
1610 call assert_equal('gnewprg', &l:equalprg)
1611 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001612
Milly484face2024-10-12 11:26:06 +02001613 set equalprg&
1614endfunc
1615
1616" Test for setting number global-local option value
1617func Test_set_number_global_local_option()
1618 setglobal scrolloff=10
1619 setlocal scrolloff=12
1620 call assert_equal(10, &g:scrolloff)
1621 call assert_equal(12, &l:scrolloff)
1622 call assert_equal(12, &scrolloff)
1623
1624 " :set {option}< set the effective value of {option} to its global value.
1625 set scrolloff<
1626 call assert_equal(10, &l:scrolloff)
1627 call assert_equal(10, &scrolloff)
1628
1629 " :setlocal {option}< removes the local value, so that the global value will be used.
1630 setglobal scrolloff=15
1631 setlocal scrolloff=18
1632 setlocal scrolloff<
1633 call assert_equal(-1, &l:scrolloff)
1634 call assert_equal(15, &scrolloff)
1635
1636 set scrolloff&
1637endfunc
1638
1639" Test for setting boolean global-local option value
1640func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001641 setglobal autoread
1642 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001643 call assert_equal(1, &g:autoread)
1644 call assert_equal(0, &l:autoread)
1645 call assert_equal(0, &autoread)
1646
1647 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001648 set autoread<
Milly484face2024-10-12 11:26:06 +02001649 call assert_equal(1, &l:autoread)
1650 call assert_equal(1, &autoread)
1651
1652 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001653 setglobal noautoread
1654 setlocal autoread
1655 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001656 call assert_equal(-1, &l:autoread)
1657 call assert_equal(0, &autoread)
1658
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001659 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001660endfunc
1661
Dominique Pelle042414f2021-07-12 21:43:19 +02001662func Test_set_in_sandbox()
1663 " Some boolean options cannot be set in sandbox, some can.
1664 call assert_fails('sandbox set modelineexpr', 'E48:')
1665 sandbox set number
1666 call assert_true(&number)
1667 set number&
1668
1669 " Some boolean options cannot be set in sandbox, some can.
1670 if has('python') || has('python3')
1671 call assert_fails('sandbox set pyxversion=3', 'E48:')
1672 endif
1673 sandbox set tabstop=4
1674 call assert_equal(4, &tabstop)
1675 set tabstop&
1676
1677 " Some string options cannot be set in sandbox, some can.
1678 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1679 sandbox set filetype=perl
1680 call assert_equal('perl', &filetype)
1681 set filetype&
1682endfunc
1683
Milly484face2024-10-12 11:26:06 +02001684" Test for setting string option value
1685func Test_set_string_option()
1686 " :set {option}=
1687 set makeprg=
1688 call assert_equal('', &mp)
1689 set makeprg=abc
1690 call assert_equal('abc', &mp)
1691
1692 " :set {option}:
1693 set makeprg:
1694 call assert_equal('', &mp)
1695 set makeprg:abc
1696 call assert_equal('abc', &mp)
1697
1698 " Let string
1699 let &makeprg = ''
1700 call assert_equal('', &mp)
1701 let &makeprg = 'abc'
1702 call assert_equal('abc', &mp)
1703
1704 " Let number converts to string
1705 let &makeprg = 42
1706 call assert_equal('42', &mp)
1707
1708 " Appending
1709 set makeprg=abc
1710 set makeprg+=def
1711 call assert_equal('abcdef', &mp)
1712 set makeprg+=def
1713 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1714 let &makeprg .= 'gh'
1715 call assert_equal('abcdefdefgh', &mp)
1716 let &makeprg ..= 'ij'
1717 call assert_equal('abcdefdefghij', &mp)
1718
1719 " Removing
1720 set makeprg=abcdefghi
1721 set makeprg-=def
1722 call assert_equal('abcghi', &mp)
1723 set makeprg-=def
1724 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1725
1726 " Prepending
1727 set makeprg=abc
1728 set makeprg^=def
1729 call assert_equal('defabc', &mp)
1730 set makeprg^=def
1731 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1732
1733 set makeprg&
1734endfunc
1735
1736" Test for setting string comma-separated list option value
1737func Test_set_string_comma_list_option()
1738 " :set {option}=
1739 set wildignore=
1740 call assert_equal('', &wildignore)
1741 set wildignore=*.png
1742 call assert_equal('*.png', &wildignore)
1743
1744 " :set {option}:
1745 set wildignore:
1746 call assert_equal('', &wildignore)
1747 set wildignore:*.png
1748 call assert_equal('*.png', &wildignore)
1749
1750 " Let string
1751 let &wildignore = ''
1752 call assert_equal('', &wildignore)
1753 let &wildignore = '*.png'
1754 call assert_equal('*.png', &wildignore)
1755
1756 " Let number converts to string
1757 let &wildignore = 42
1758 call assert_equal('42', &wildignore)
1759
1760 " Appending
1761 set wildignore=*.png
1762 set wildignore+=*.jpg
1763 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1764 set wildignore+=*.jpg
1765 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1766 set wildignore+=jpg
1767 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1768 let &wildignore .= 'foo'
1769 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1770 let &wildignore ..= 'bar'
1771 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1772
1773 " Removing
1774 set wildignore=*.png,*.jpg,*.obj
1775 set wildignore-=*.jpg
1776 call assert_equal('*.png,*.obj', &wildignore)
1777 set wildignore-=*.jpg
1778 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1779 set wildignore-=jpg
1780 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1781
1782 " Prepending
1783 set wildignore=*.png
1784 set wildignore^=*.jpg
1785 call assert_equal('*.jpg,*.png', &wildignore)
1786 set wildignore^=*.jpg
1787 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1788 set wildignore^=jpg
1789 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1790
1791 set wildignore&
1792endfunc
1793
1794" Test for setting string flags option value
1795func Test_set_string_flags_option()
1796 " :set {option}=
1797 set formatoptions=
1798 call assert_equal('', &fo)
1799 set formatoptions=abc
1800 call assert_equal('abc', &fo)
1801
1802 " :set {option}:
1803 set formatoptions:
1804 call assert_equal('', &fo)
1805 set formatoptions:abc
1806 call assert_equal('abc', &fo)
1807
1808 " Let string
1809 let &formatoptions = ''
1810 call assert_equal('', &fo)
1811 let &formatoptions = 'abc'
1812 call assert_equal('abc', &fo)
1813
1814 " Let number converts to string
1815 let &formatoptions = 12
1816 call assert_equal('12', &fo)
1817
1818 " Appending
1819 set formatoptions=abc
1820 set formatoptions+=pqr
1821 call assert_equal('abcpqr', &fo)
1822 set formatoptions+=pqr
1823 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1824 let &formatoptions .= 'r'
1825 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1826 let &formatoptions ..= 'r'
1827 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1828
1829 " Removing
1830 set formatoptions=abcpqr
1831 set formatoptions-=cp
1832 call assert_equal('abqr', &fo)
1833 set formatoptions-=cp
1834 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1835 set formatoptions-=ar
1836 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1837
1838 " Prepending
1839 set formatoptions=abc
1840 set formatoptions^=pqr
1841 call assert_equal('pqrabc', &fo)
1842 set formatoptions^=qr
1843 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1844
1845 set formatoptions&
1846endfunc
1847
1848" Test for setting number option value
1849func Test_set_number_option()
1850 " :set {option}=
1851 set scrolljump=5
1852 call assert_equal(5, &sj)
1853 set scrolljump=-3
1854 call assert_equal(-3, &sj)
1855
1856 " :set {option}:
1857 set scrolljump:7
1858 call assert_equal(7, &sj)
1859 set scrolljump:-5
1860 call assert_equal(-5, &sj)
1861
1862 " Set hex
1863 set scrolljump=0x10
1864 call assert_equal(16, &sj)
1865 set scrolljump=-0x10
1866 call assert_equal(-16, &sj)
1867 set scrolljump=0X12
1868 call assert_equal(18, &sj)
1869 set scrolljump=-0X12
1870 call assert_equal(-18, &sj)
1871
1872 " Set octal
1873 set scrolljump=010
1874 call assert_equal(8, &sj)
1875 set scrolljump=-010
1876 call assert_equal(-8, &sj)
1877 set scrolljump=0o12
1878 call assert_equal(10, &sj)
1879 set scrolljump=-0o12
1880 call assert_equal(-10, &sj)
1881 set scrolljump=0O15
1882 call assert_equal(13, &sj)
1883 set scrolljump=-0O15
1884 call assert_equal(-13, &sj)
1885
1886 " Let number
1887 let &scrolljump = 4
1888 call assert_equal(4, &sj)
1889 let &scrolljump = -6
1890 call assert_equal(-6, &sj)
1891
1892 " Let numeric string converts to number
1893 let &scrolljump = '7'
1894 call assert_equal(7, &sj)
1895 let &scrolljump = '-9'
1896 call assert_equal(-9, &sj)
1897
1898 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001899 set shiftwidth=4
1900 set sw+=2
1901 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001902 let &shiftwidth += 2
1903 call assert_equal(8, &sw)
1904
1905 " Decrementing
1906 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001907 set sw-=2
1908 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001909 let &shiftwidth -= 2
1910 call assert_equal(2, &sw)
1911
1912 " Multiplying
1913 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001914 set sw^=2
1915 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001916 let &shiftwidth *= 2
1917 call assert_equal(16, &sw)
1918
1919 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001920 set shiftwidth&
1921endfunc
1922
Milly484face2024-10-12 11:26:06 +02001923" Test for setting boolean option value
1924func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001925 set number&
Milly484face2024-10-12 11:26:06 +02001926
1927 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001928 set number
1929 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001930
1931 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001932 set nonu
1933 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001934
1935 " :set {option}!
1936 set number!
1937 call assert_equal(1, &nu)
1938 set number!
1939 call assert_equal(0, &nu)
1940
1941 " :set inv{option}
1942 set invnumber
1943 call assert_equal(1, &nu)
1944 set invnumber
1945 call assert_equal(0, &nu)
1946
1947 " Let number
1948 let &number = 1
1949 call assert_equal(1, &nu)
1950 let &number = 0
1951 call assert_equal(0, &nu)
1952
1953 " Let numeric string converts to number
1954 let &number = '1'
1955 call assert_equal(1, &nu)
1956 let &number = '0'
1957 call assert_equal(0, &nu)
1958
1959 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001960 let &nu = v:true
1961 call assert_equal(1, &nu)
1962 let &nu = v:false
1963 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001964
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001965 set number&
1966endfunc
1967
Milly484face2024-10-12 11:26:06 +02001968" Test for setting string option errors
1969func Test_set_string_option_errors()
1970 " :set no{option}
1971 call assert_fails('set nomakeprg', 'E474:')
1972 call assert_fails('setlocal nomakeprg', 'E474:')
1973 call assert_fails('setglobal nomakeprg', 'E474:')
1974
1975 " :set inv{option}
1976 call assert_fails('set invmakeprg', 'E474:')
1977 call assert_fails('setlocal invmakeprg', 'E474:')
1978 call assert_fails('setglobal invmakeprg', 'E474:')
1979
1980 " :set {option}!
1981 call assert_fails('set makeprg!', 'E488:')
1982 call assert_fails('setlocal makeprg!', 'E488:')
1983 call assert_fails('setglobal makeprg!', 'E488:')
1984
1985 " Invalid trailing chars
1986 call assert_fails('set makeprg??', 'E488:')
1987 call assert_fails('setlocal makeprg??', 'E488:')
1988 call assert_fails('setglobal makeprg??', 'E488:')
1989 call assert_fails('set makeprg&&', 'E488:')
1990 call assert_fails('setlocal makeprg&&', 'E488:')
1991 call assert_fails('setglobal makeprg&&', 'E488:')
1992 call assert_fails('set makeprg<<', 'E488:')
1993 call assert_fails('setlocal makeprg<<', 'E488:')
1994 call assert_fails('setglobal makeprg<<', 'E488:')
1995 call assert_fails('set makeprg@', 'E488:')
1996 call assert_fails('setlocal makeprg@', 'E488:')
1997 call assert_fails('setglobal makeprg@', 'E488:')
1998
1999 " Invalid type
2000 call assert_fails("let &makeprg = ['xxx']", 'E730:')
2001endfunc
2002
2003" Test for setting number option errors
2004func Test_set_number_option_errors()
2005 " :set no{option}
2006 call assert_fails('set notabstop', 'E474:')
2007 call assert_fails('setlocal notabstop', 'E474:')
2008 call assert_fails('setglobal notabstop', 'E474:')
2009
2010 " :set inv{option}
2011 call assert_fails('set invtabstop', 'E474:')
2012 call assert_fails('setlocal invtabstop', 'E474:')
2013 call assert_fails('setglobal invtabstop', 'E474:')
2014
2015 " :set {option}!
2016 call assert_fails('set tabstop!', 'E488:')
2017 call assert_fails('setlocal tabstop!', 'E488:')
2018 call assert_fails('setglobal tabstop!', 'E488:')
2019
2020 " Invalid trailing chars
2021 call assert_fails('set tabstop??', 'E488:')
2022 call assert_fails('setlocal tabstop??', 'E488:')
2023 call assert_fails('setglobal tabstop??', 'E488:')
2024 call assert_fails('set tabstop&&', 'E488:')
2025 call assert_fails('setlocal tabstop&&', 'E488:')
2026 call assert_fails('setglobal tabstop&&', 'E488:')
2027 call assert_fails('set tabstop<<', 'E488:')
2028 call assert_fails('setlocal tabstop<<', 'E488:')
2029 call assert_fails('setglobal tabstop<<', 'E488:')
2030 call assert_fails('set tabstop@', 'E488:')
2031 call assert_fails('setlocal tabstop@', 'E488:')
2032 call assert_fails('setglobal tabstop@', 'E488:')
2033
2034 " Not a number
2035 call assert_fails('set tabstop=', 'E521:')
2036 call assert_fails('setlocal tabstop=', 'E521:')
2037 call assert_fails('setglobal tabstop=', 'E521:')
2038 call assert_fails('set tabstop=x', 'E521:')
2039 call assert_fails('setlocal tabstop=x', 'E521:')
2040 call assert_fails('setglobal tabstop=x', 'E521:')
2041 call assert_fails('set tabstop=1x', 'E521:')
2042 call assert_fails('setlocal tabstop=1x', 'E521:')
2043 call assert_fails('setglobal tabstop=1x', 'E521:')
2044 call assert_fails('set tabstop=-x', 'E521:')
2045 call assert_fails('setlocal tabstop=-x', 'E521:')
2046 call assert_fails('setglobal tabstop=-x', 'E521:')
2047 call assert_fails('set tabstop=0x', 'E521:')
2048 call assert_fails('setlocal tabstop=0x', 'E521:')
2049 call assert_fails('setglobal tabstop=0x', 'E521:')
2050 call assert_fails('set tabstop=0o', 'E521:')
2051 call assert_fails('setlocal tabstop=0o', 'E521:')
2052 call assert_fails('setglobal tabstop=0o', 'E521:')
2053 call assert_fails("let &tabstop = 'x'", 'E521:')
2054 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2055 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2056
2057 " Invalid type
2058 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2059endfunc
2060
2061" Test for setting boolean option errors
2062func Test_set_boolean_option_errors()
2063 " :set {option}=
2064 call assert_fails('set number=', 'E474:')
2065 call assert_fails('setlocal number=', 'E474:')
2066 call assert_fails('setglobal number=', 'E474:')
2067 call assert_fails('set number=1', 'E474:')
2068 call assert_fails('setlocal number=1', 'E474:')
2069 call assert_fails('setglobal number=1', 'E474:')
2070
2071 " :set {option}:
2072 call assert_fails('set number:', 'E474:')
2073 call assert_fails('setlocal number:', 'E474:')
2074 call assert_fails('setglobal number:', 'E474:')
2075 call assert_fails('set number:1', 'E474:')
2076 call assert_fails('setlocal number:1', 'E474:')
2077 call assert_fails('setglobal number:1', 'E474:')
2078
2079 " :set {option}+=
2080 call assert_fails('set number+=1', 'E474:')
2081 call assert_fails('setlocal number+=1', 'E474:')
2082 call assert_fails('setglobal number+=1', 'E474:')
2083
2084 " :set {option}^=
2085 call assert_fails('set number^=1', 'E474:')
2086 call assert_fails('setlocal number^=1', 'E474:')
2087 call assert_fails('setglobal number^=1', 'E474:')
2088
2089 " :set {option}-=
2090 call assert_fails('set number-=1', 'E474:')
2091 call assert_fails('setlocal number-=1', 'E474:')
2092 call assert_fails('setglobal number-=1', 'E474:')
2093
2094 " Invalid trailing chars
2095 call assert_fails('set number!!', 'E488:')
2096 call assert_fails('setlocal number!!', 'E488:')
2097 call assert_fails('setglobal number!!', 'E488:')
2098 call assert_fails('set number??', 'E488:')
2099 call assert_fails('setlocal number??', 'E488:')
2100 call assert_fails('setglobal number??', 'E488:')
2101 call assert_fails('set number&&', 'E488:')
2102 call assert_fails('setlocal number&&', 'E488:')
2103 call assert_fails('setglobal number&&', 'E488:')
2104 call assert_fails('set number<<', 'E488:')
2105 call assert_fails('setlocal number<<', 'E488:')
2106 call assert_fails('setglobal number<<', 'E488:')
2107 call assert_fails('set number@', 'E488:')
2108 call assert_fails('setlocal number@', 'E488:')
2109 call assert_fails('setglobal number@', 'E488:')
2110
2111 " Invalid type
2112 call assert_fails("let &number = 'xxx'", 'E521:')
2113endfunc
2114
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002115" Test for the 'window' option
2116func Test_window_opt()
2117 " Needs only one open widow
2118 %bw!
2119 call setline(1, range(1, 8))
2120 set window=5
2121 exe "normal \<C-F>"
2122 call assert_equal(4, line('w0'))
2123 exe "normal \<C-F>"
2124 call assert_equal(7, line('w0'))
2125 exe "normal \<C-F>"
2126 call assert_equal(8, line('w0'))
2127 exe "normal \<C-B>"
2128 call assert_equal(5, line('w0'))
2129 exe "normal \<C-B>"
2130 call assert_equal(2, line('w0'))
2131 exe "normal \<C-B>"
2132 call assert_equal(1, line('w0'))
2133 set window=1
2134 exe "normal gg\<C-F>"
2135 call assert_equal(2, line('w0'))
2136 exe "normal \<C-F>"
2137 call assert_equal(3, line('w0'))
2138 exe "normal \<C-B>"
2139 call assert_equal(2, line('w0'))
2140 exe "normal \<C-B>"
2141 call assert_equal(1, line('w0'))
2142 enew!
2143 set window&
2144endfunc
2145
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002146" Test for the 'winminheight' option
2147func Test_opt_winminheight()
2148 only!
2149 let &winheight = &lines + 4
2150 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2151 call assert_true(&winminheight <= &lines)
2152 set winminheight&
2153 set winheight&
2154endfunc
2155
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002156func Test_opt_winminheight_term()
2157 CheckRunVimInTerminal
2158
2159 " The tabline should be taken into account.
2160 let lines =<< trim END
2161 set wmh=0 stal=2
2162 below sp | wincmd _
2163 below sp | wincmd _
2164 below sp | wincmd _
2165 below sp
2166 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002167 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002168 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2169 call term_sendkeys(buf, ":set wmh=1\n")
2170 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2171
2172 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002173endfunc
2174
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002175func Test_opt_winminheight_term_tabs()
2176 CheckRunVimInTerminal
2177
2178 " The tabline should be taken into account.
2179 let lines =<< trim END
2180 set wmh=0 stal=2
2181 split
2182 split
2183 split
2184 split
2185 tabnew
2186 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002187 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002188 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2189 call term_sendkeys(buf, ":set wmh=1\n")
2190 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2191
2192 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002193endfunc
2194
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002195" Test for the 'winminwidth' option
2196func Test_opt_winminwidth()
2197 only!
2198 let &winwidth = &columns + 4
2199 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2200 call assert_true(&winminwidth <= &columns)
2201 set winminwidth&
2202 set winwidth&
2203endfunc
2204
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002205" Test for setting option value containing spaces with isfname+=32
2206func Test_isfname_with_options()
2207 set isfname+=32
2208 setlocal keywordprg=:term\ help.exe
2209 call assert_equal(':term help.exe', &keywordprg)
2210 set isfname&
2211 setlocal keywordprg&
2212endfunc
2213
Bram Moolenaar74667062020-12-28 15:41:41 +01002214" Test that resetting laststatus does change scroll option
2215func Test_opt_reset_scroll()
2216 CheckRunVimInTerminal
2217 let vimrc =<< trim [CODE]
2218 set scroll=2
2219 set laststatus=2
2220 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002221 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002222 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2223 call term_sendkeys(buf, ":verbose set scroll?\n")
2224 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2225 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002226
2227 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002228 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002229endfunc
2230
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002231" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2232func Test_VIM_POSIX()
2233 let saved_VIM_POSIX = getenv("VIM_POSIX")
2234
2235 call setenv('VIM_POSIX', "1")
2236 let after =<< trim [CODE]
2237 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2238 qall
2239 [CODE]
2240 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002241 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002242 \ 'AS'], readfile('X_VIM_POSIX'))
2243 endif
2244
2245 call setenv('VIM_POSIX', v:null)
2246 let after =<< trim [CODE]
2247 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2248 qall
2249 [CODE]
2250 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002251 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002252 \ 'S'], readfile('X_VIM_POSIX'))
2253 endif
2254
2255 call delete('X_VIM_POSIX')
2256 call setenv('VIM_POSIX', saved_VIM_POSIX)
2257endfunc
2258
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002259" Test for setting an option to a Vi or Vim default
2260func Test_opt_default()
2261 set formatoptions&vi
2262 call assert_equal('vt', &formatoptions)
2263 set formatoptions&vim
2264 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002265
2266 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2267 set fencs=latin1
2268 set fencs&
2269 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2270 set fencs=latin1
2271 set all&
2272 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002273endfunc
2274
2275" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002276func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002277 %bw!
2278 let ht = &lines
2279 set cmdheight=9999
2280 call assert_equal(1, winheight(0))
2281 call assert_equal(ht - 1, &cmdheight)
2282 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002283
2284 " The status line should be taken into account.
2285 set laststatus=2
2286 set cmdheight=9999
2287 call assert_equal(ht - 2, &cmdheight)
2288 set cmdheight& laststatus&
2289
2290 " The tabline should be taken into account only non-GUI.
2291 set showtabline=2
2292 set cmdheight=9999
2293 if has('gui_running')
2294 call assert_equal(ht - 1, &cmdheight)
2295 else
2296 call assert_equal(ht - 2, &cmdheight)
2297 endif
2298 set cmdheight& showtabline&
2299
2300 " The 'winminheight' should be taken into account.
2301 set winheight=3 winminheight=3
2302 split
2303 set cmdheight=9999
2304 call assert_equal(ht - 8, &cmdheight)
2305 %bw!
2306 set cmdheight& winminheight& winheight&
2307
2308 " Only the windows in the current tabpage are taken into account.
2309 set winheight=3 winminheight=3 showtabline=0
2310 split
2311 tabnew
2312 set cmdheight=9999
2313 call assert_equal(ht - 3, &cmdheight)
2314 %bw!
2315 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002316endfunc
2317
Dominique Pelle923dce22021-11-21 11:36:04 +00002318" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002319func Test_opt_control_char()
2320 set wildchar=^v
2321 call assert_equal("\<C-V>", nr2char(&wildchar))
2322 set wildcharm=^r
2323 call assert_equal("\<C-R>", nr2char(&wildcharm))
2324 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2325 set wildchar& wildcharm&
2326endfunc
2327
2328" Test for the 'errorbells' option
2329func Test_opt_errorbells()
2330 set errorbells
2331 call assert_beeps('s/a1b2/x1y2/')
2332 set noerrorbells
2333endfunc
2334
Dominique Pelle042414f2021-07-12 21:43:19 +02002335func Test_opt_scrolljump()
2336 help
2337 resize 10
2338
2339 " Test with positive 'scrolljump'.
2340 set scrolljump=2
2341 norm! Lj
2342 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2343 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2344 \ winsaveview())
2345
2346 " Test with negative 'scrolljump' (percentage of window height).
2347 set scrolljump=-40
2348 norm! ggLj
2349 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2350 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2351 \ winsaveview())
2352
2353 set scrolljump&
2354 bw
2355endfunc
2356
Bakudankun29f3a452021-12-11 12:28:08 +00002357" Test for the 'cdhome' option
2358func Test_opt_cdhome()
2359 if has('unix') || has('vms')
2360 throw 'Skipped: only works on non-Unix'
2361 endif
2362
2363 set cdhome&
2364 call assert_equal(0, &cdhome)
2365 set cdhome
2366
2367 " This paragraph is copied from Test_cd_no_arg().
2368 let path = getcwd()
2369 cd
2370 call assert_equal($HOME, getcwd())
2371 call assert_notequal(path, getcwd())
2372 exe 'cd ' .. fnameescape(path)
2373 call assert_equal(path, getcwd())
2374
2375 set cdhome&
2376endfunc
2377
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002378func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002379 CheckOption termguicolors
2380
2381 " Test default option completion
2382 set wildoptions=
2383 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2384 call assert_equal('"set termguicolors', @:)
2385
2386 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2387 call assert_equal('"set notermguicolors', @:)
2388
2389 " Test fuzzy option completion
2390 set wildoptions=fuzzy
2391 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2392 call assert_equal('"set termguicolors termencoding', @:)
2393
2394 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2395 call assert_equal('"set notermguicolors', @:)
2396
2397 set wildoptions=
2398endfunc
2399
Sean Dewar39c46b42022-05-12 17:44:29 +01002400func Test_switchbuf_reset()
2401 set switchbuf=useopen
2402 sblast
2403 call assert_equal(1, winnr('$'))
2404 set all&
2405 call assert_equal('', &switchbuf)
2406 sblast
2407 call assert_equal(2, winnr('$'))
2408 only!
2409endfunc
2410
zeertzjqfcba86c2022-09-22 13:57:32 +01002411" :set empty string for global 'keywordprg' falls back to ":help"
2412func Test_keywordprg_empty()
2413 let k = &keywordprg
2414 set keywordprg=man
2415 call assert_equal('man', &keywordprg)
2416 set keywordprg=
2417 call assert_equal(':help', &keywordprg)
2418 set keywordprg=man
2419 call assert_equal('man', &keywordprg)
2420 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2421 let &keywordprg = k
2422endfunc
2423
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002424" check that the very first buffer created does not have 'endoffile' set
2425func Test_endoffile_default()
2426 let after =<< trim [CODE]
2427 call writefile([execute('set eof?')], 'Xtestout')
2428 qall!
2429 [CODE]
2430 if RunVim([], after, '')
2431 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2432 endif
2433 call delete('Xtestout')
2434endfunc
2435
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002436" Test for setting the 'lines' and 'columns' options to a minimum value
2437func Test_set_min_lines_columns()
2438 let save_lines = &lines
2439 let save_columns = &columns
2440
2441 let after =<< trim END
2442 set nomore
2443 let msg = []
2444 let v:errmsg = ''
2445 silent! let &columns=0
2446 call add(msg, v:errmsg)
2447 silent! set columns=0
2448 call add(msg, v:errmsg)
2449 silent! call setbufvar('', '&columns', 0)
2450 call add(msg, v:errmsg)
2451 "call writefile(msg, 'XResultsetminlines')
2452 silent! let &lines=0
2453 call add(msg, v:errmsg)
2454 silent! set lines=0
2455 call add(msg, v:errmsg)
2456 silent! call setbufvar('', '&lines', 0)
2457 call add(msg, v:errmsg)
2458 call writefile(msg, 'XResultsetminlines')
2459 qall!
2460 END
2461 if RunVim([], after, '')
2462 call assert_equal(['E594: Need at least 12 columns',
2463 \ 'E594: Need at least 12 columns: columns=0',
2464 \ 'E594: Need at least 12 columns',
2465 \ 'E593: Need at least 2 lines',
2466 \ 'E593: Need at least 2 lines: lines=0',
2467 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2468 endif
2469
2470 call delete('XResultsetminlines')
2471 let &lines = save_lines
2472 let &columns = save_columns
2473endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002474
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002475" Test for reverting a string option value if the new value is invalid.
2476func Test_string_option_revert_on_failure()
2477 new
2478 let optlist = [
2479 \ ['ambiwidth', 'double', 'a123'],
2480 \ ['background', 'dark', 'a123'],
2481 \ ['backspace', 'eol', 'a123'],
2482 \ ['backupcopy', 'no', 'a123'],
2483 \ ['belloff', 'showmatch', 'a123'],
2484 \ ['breakindentopt', 'min:10', 'list'],
2485 \ ['bufhidden', 'wipe', 'a123'],
2486 \ ['buftype', 'nowrite', 'a123'],
2487 \ ['casemap', 'keepascii', 'a123'],
2488 \ ['cedit', "\<C-Y>", 'z'],
2489 \ ['colorcolumn', '10', 'z'],
2490 \ ['commentstring', '#%s', 'a123'],
2491 \ ['complete', '.,t', 'a'],
2492 \ ['completefunc', 'MyCmplFunc', '1a-'],
2493 \ ['completeopt', 'popup', 'a123'],
2494 \ ['completepopup', 'width:20', 'border'],
2495 \ ['concealcursor', 'v', 'xyz'],
2496 \ ['cpoptions', 'HJ', '~'],
2497 \ ['cryptmethod', 'zip', 'a123'],
2498 \ ['cursorlineopt', 'screenline', 'a123'],
2499 \ ['debug', 'throw', 'a123'],
2500 \ ['diffopt', 'iwhite', 'a123'],
2501 \ ['display', 'uhex', 'a123'],
2502 \ ['eadirection', 'hor', 'a123'],
2503 \ ['encoding', 'utf-8', 'a123'],
2504 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002505 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002506 \ ['fileencoding', 'utf-8', 'a123,'],
2507 \ ['fileformat', 'mac', 'a123'],
2508 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002509 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002510 \ ['fillchars', 'diff:~', 'a123'],
2511 \ ['foldclose', 'all', 'a123'],
2512 \ ['foldmarker', '[[[,]]]', '[[['],
2513 \ ['foldmethod', 'marker', 'a123'],
2514 \ ['foldopen', 'percent', 'a123'],
2515 \ ['formatoptions', 'an', '*'],
2516 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2517 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002518 \ ['highlight', '!:CursorColumn', '8:'],
2519 \ ['keymodel', 'stopsel', 'a123'],
2520 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2521 \ ['lispoptions', 'expr:1', 'a123'],
2522 \ ['listchars', 'tab:->', 'tab:'],
2523 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002524 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002525 \ ['mkspellmem', '100000,1000,100', '100000'],
2526 \ ['mouse', 'nvi', 'z'],
2527 \ ['mousemodel', 'extend', 'a123'],
2528 \ ['nrformats', 'alpha', 'a123'],
2529 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2530 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2531 \ ['previewpopup', 'width:20', 'a123'],
2532 \ ['printoptions', 'paper:A4', 'a123:'],
2533 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2534 \ ['rulerformat', '%l', '%['],
2535 \ ['scrollopt', 'hor,jump', 'a123'],
2536 \ ['selection', 'exclusive', 'a123'],
2537 \ ['selectmode', 'cmd', 'a123'],
2538 \ ['sessionoptions', 'options', 'a123'],
2539 \ ['shortmess', 'w', '2'],
2540 \ ['showbreak', '>>', "\x01"],
2541 \ ['showcmdloc', 'statusline', 'a123'],
2542 \ ['signcolumn', 'no', 'a123'],
2543 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2544 \ ['spellfile', 'MySpell.en.add', "\x01"],
2545 \ ['spelllang', 'en', "#"],
2546 \ ['spelloptions', 'camel', 'a123'],
2547 \ ['spellsuggest', 'double', 'a123'],
2548 \ ['splitkeep', 'topline', 'a123'],
2549 \ ['statusline', '%f', '%['],
2550 \ ['swapsync', 'sync', 'a123'],
2551 \ ['switchbuf', 'usetab', 'a123'],
2552 \ ['syntax', 'abc', 'a^b'],
2553 \ ['tabline', '%f', '%['],
2554 \ ['tagcase', 'ignore', 'a123'],
2555 \ ['tagfunc', 'MyTagFunc', '1a-'],
2556 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2557 \ ['viewoptions', 'options', 'a123'],
2558 \ ['virtualedit', 'onemore', 'a123'],
2559 \ ['whichwrap', '<,>', '{,}'],
2560 \ ['wildmode', 'list', 'a123'],
2561 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002562 \ ]
2563 if has('gui')
2564 call add(optlist, ['browsedir', 'buffer', 'a123'])
2565 endif
2566 if has('clipboard_working')
2567 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2568 endif
2569 if has('win32')
2570 call add(optlist, ['completeslash', 'slash', 'a123'])
2571 endif
2572 if has('cscope')
2573 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2574 endif
2575 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002576 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2577 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2578 endif
2579 if has('keymap')
2580 call add(optlist, ['keymap', 'greek', '[]'])
2581 endif
2582 if has('mouseshape')
2583 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2584 endif
2585 if has('win32') && has('gui')
2586 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2587 endif
2588 if has('rightleft')
2589 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2590 endif
2591 if has('terminal')
2592 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2593 call add(optlist, ['termwinsize', '24x80', '100'])
2594 endif
2595 if has('win32') && has('terminal')
2596 call add(optlist, ['termwintype', 'winpty', 'a123'])
2597 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002598 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002599 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002600 endif
2601 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002602 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2603 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002604 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002605 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2606 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002607 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002608 call add(optlist, ['varsofttabstop', '12', 'a123'])
2609 call add(optlist, ['vartabstop', '4,20', '4,'])
2610 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002611 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002612 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002613 endif
2614 for opt in optlist
2615 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002616 try
2617 exe $"let &{opt[0]} = '{opt[1]}'"
2618 catch
2619 call assert_report($"Caught {v:exception} with {opt->string()}")
2620 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002621 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2622 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2623 exe $"let &{opt[0]} = save_opt"
2624 endfor
2625 bw!
2626endfunc
2627
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002628func Test_set_option_window_global_local()
2629 new Xbuffer1
2630 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2631 setlocal scrolloff=2
2632 setglobal scrolloff=3
2633 setl modified
2634 " A new buffer has its own window-local options
2635 hide enew
2636 call assert_equal(-1, &l:scrolloff)
2637 call assert_equal(3, &g:scrolloff)
2638 " A new window opened with its own buffer-local options
2639 new
2640 call assert_equal(-1, &l:scrolloff)
2641 call assert_equal(3, &g:scrolloff)
2642 " Re-open Xbuffer1 and it should use
2643 " the previous set window-local options
2644 b Xbuffer1
2645 call assert_equal(2, &l:scrolloff)
2646 call assert_equal(3, &g:scrolloff)
2647 bw!
2648 bw!
2649 let &g:scrolloff = _gso
2650endfunc
2651
2652func GetGlobalLocalWindowOptions()
2653 new
2654 sil! r $VIMRUNTIME/doc/options.txt
2655 " Filter for global or local to window
2656 v/^'.*'.*\n.*global or local to window |global-local/d
2657 " get option value and type
2658 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2659 sil %s/empty/""/g
2660 " split the result
2661 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2662 bw!
2663 return result
2664endfunc
2665
2666func Test_set_option_window_global_local_all()
2667 new Xbuffer2
2668
2669 let optionlist = GetGlobalLocalWindowOptions()
2670 for [opt, type, default] in optionlist
2671 let _old = eval('&g:' .. opt)
2672 if type == 'string'
2673 if opt == 'fillchars'
2674 exe 'setl ' .. opt .. '=vert:+'
2675 exe 'setg ' .. opt .. '=vert:+,fold:+'
2676 elseif opt == 'listchars'
2677 exe 'setl ' .. opt .. '=tab:>>'
2678 exe 'setg ' .. opt .. '=tab:++'
2679 elseif opt == 'virtualedit'
2680 exe 'setl ' .. opt .. '=all'
2681 exe 'setg ' .. opt .. '=block'
2682 else
2683 exe 'setl ' .. opt .. '=Local'
2684 exe 'setg ' .. opt .. '=Global'
2685 endif
2686 elseif type == 'number'
2687 exe 'setl ' .. opt .. '=5'
2688 exe 'setg ' .. opt .. '=10'
2689 endif
2690 setl modified
2691 hide enew
2692 if type == 'string'
2693 call assert_equal('', eval('&l:' .. opt))
2694 if opt == 'fillchars'
2695 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2696 elseif opt == 'listchars'
2697 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2698 elseif opt == 'virtualedit'
2699 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2700 else
2701 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2702 endif
2703 elseif type == 'number'
2704 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2705 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2706 endif
2707 bw!
2708 exe 'let &g:' .. opt .. '=' .. default
2709 endfor
2710 bw!
2711endfunc
2712
Christian Brabandt757593c2023-08-22 21:44:10 +02002713func Test_paste_depending_options()
2714 " setting the paste option, resets all dependent options
2715 " and will be reported correctly using :verbose set <option>?
2716 let lines =<< trim [CODE]
2717 " set paste test
2718 set autoindent
2719 set expandtab
2720 " disabled, because depends on compiled feature set
2721 " set hkmap
2722 " set revins
2723 " set varsofttabstop=8,32,8
2724 set ruler
2725 set showmatch
2726 set smarttab
2727 set softtabstop=4
2728 set textwidth=80
2729 set wrapmargin=10
2730
2731 source Xvimrc_paste2
2732
2733 redir > Xoutput_paste
2734 verbose set expandtab?
2735 verbose setg expandtab?
2736 verbose setl expandtab?
2737 redir END
2738
2739 qall!
2740 [CODE]
2741
2742 call writefile(lines, 'Xvimrc_paste', 'D')
2743 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2744 if !RunVim([], lines, '--clean')
2745 return
2746 endif
2747
2748 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2749 call assert_equal('noexpandtab', result[0])
2750 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2751 call assert_equal('noexpandtab', result[2])
2752 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2753 call assert_equal('noexpandtab', result[4])
2754 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2755
2756 call delete('Xoutput_paste')
2757endfunc
2758
2759func Test_binary_depending_options()
2760 " setting the paste option, resets all dependent options
2761 " and will be reported correctly using :verbose set <option>?
2762 let lines =<< trim [CODE]
2763 " set binary test
2764 set expandtab
2765
2766 source Xvimrc_bin2
2767
2768 redir > Xoutput_bin
2769 verbose set expandtab?
2770 verbose setg expandtab?
2771 verbose setl expandtab?
2772 redir END
2773
2774 qall!
2775 [CODE]
2776
2777 call writefile(lines, 'Xvimrc_bin', 'D')
2778 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2779 if !RunVim([], lines, '--clean')
2780 return
2781 endif
2782
2783 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2784 call assert_equal('noexpandtab', result[0])
2785 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2786 call assert_equal('noexpandtab', result[2])
2787 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2788 call assert_equal('noexpandtab', result[4])
2789 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2790
2791 call delete('Xoutput_bin')
2792endfunc
2793
Gregory Anders3695d0e2023-09-29 20:17:20 +02002794func Test_set_keyprotocol()
2795 CheckNotGui
2796
2797 let term = &term
2798 set term=ansi
2799 call assert_equal('', &t_TI)
2800
2801 " Setting 'keyprotocol' should affect terminal codes without needing to
2802 " reset 'term'
2803 set keyprotocol+=ansi:kitty
2804 call assert_equal("\<Esc>[=1;1u", &t_TI)
2805 let &term = term
2806endfunc
2807
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002808func Test_set_wrap()
2809 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2810 " cursor position.
2811 set wrap smoothscroll scrolloff=5
2812
2813 call setline(1, ['', 'aaaa'->repeat(500)])
2814 20 split
2815 20 vsplit
2816 norm 2G$
2817 redraw
2818 set nowrap
2819 call assert_equal(2, winline())
2820
2821 set wrap& smoothscroll& scrolloff&
2822endfunc
2823
zeertzjqcd3a13e2024-02-24 16:51:32 +01002824func Test_delcombine()
2825 new
2826 set backspace=indent,eol,start
2827
2828 set delcombine
2829 call setline(1, 'β̳̈:β̳̈')
2830 normal! 0x
2831 call assert_equal('β̈:β̳̈', getline(1))
2832 exe "normal! A\<BS>"
2833 call assert_equal('β̈:β̈', getline(1))
2834 normal! 0x
2835 call assert_equal('β:β̈', getline(1))
2836 exe "normal! A\<BS>"
2837 call assert_equal('β:β', getline(1))
2838 normal! 0x
2839 call assert_equal(':β', getline(1))
2840 exe "normal! A\<BS>"
2841 call assert_equal(':', getline(1))
2842
2843 set nodelcombine
2844 call setline(1, 'β̳̈:β̳̈')
2845 normal! 0x
2846 call assert_equal(':β̳̈', getline(1))
2847 exe "normal! A\<BS>"
2848 call assert_equal(':', getline(1))
2849
2850 set backspace& delcombine&
2851 bwipe!
2852endfunc
2853
Milly484face2024-10-12 11:26:06 +02002854" Should not raise errors when set missing-options.
2855func Test_set_missing_options()
2856 set autoprint
2857 set beautify
2858 set flash
2859 set graphic
2860 set hardtabs=8
2861 set mesg
2862 set novice
2863 set open
2864 set optimize
2865 set redraw
2866 set slowopen
2867 set sourceany
2868 set w300=23
2869 set w1200=23
2870 set w9600=23
2871endfunc
2872
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002873func Test_default_keyprotocol()
2874 " default value of keyprotocol
2875 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2876endfunc
2877
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002878" vim: shiftwidth=2 sts=2 expandtab