blob: 084646699d0195602e7c1ed4ffb49da661e0da1d [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Milly6eca04e2024-10-21 22:20:51 +02003scriptencoding utf-8
4
Bram Moolenaar1e115362019-01-09 23:01:02 +01005func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02006 set whichwrap=b,s
7 call assert_equal('b,s', &whichwrap)
8
9 set whichwrap+=h,l
10 call assert_equal('b,s,h,l', &whichwrap)
11
12 set whichwrap+=h,l
13 call assert_equal('b,s,h,l', &whichwrap)
14
15 set whichwrap+=h,l
16 call assert_equal('b,s,h,l', &whichwrap)
17
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010018 set whichwrap=h,h
19 call assert_equal('h', &whichwrap)
20
21 set whichwrap=h,h,h
22 call assert_equal('h', &whichwrap)
23
Bram Moolenaar004a6782020-04-11 17:09:31 +020024 " For compatibility with Vim 3.0 and before, number values are also
25 " supported for 'whichwrap'
26 set whichwrap=1
27 call assert_equal('b', &whichwrap)
28 set whichwrap=2
29 call assert_equal('s', &whichwrap)
30 set whichwrap=4
31 call assert_equal('h,l', &whichwrap)
32 set whichwrap=8
33 call assert_equal('<,>', &whichwrap)
34 set whichwrap=16
35 call assert_equal('[,]', &whichwrap)
36 set whichwrap=31
37 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
38
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020039 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010040endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020041
Bram Moolenaar1e115362019-01-09 23:01:02 +010042func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010043 " This used to cause Vim to access uninitialized memory.
44 set isfname=
45 call assert_equal("~X", expand("~X"))
46 set isfname&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000047 " Test for setting 'isfname' to an unsupported character
48 let save_isfname = &isfname
49 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
50 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010051endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010052
zeertzjq0519ce02022-05-09 12:16:19 +010053" Test for getting the value of 'pastetoggle'
54func Test_pastetoggle()
55 " character with K_SPECIAL byte
56 let &pastetoggle = '…'
57 call assert_equal('…', &pastetoggle)
58 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
59
60 " modified character with K_SPECIAL byte
61 let &pastetoggle = '<M-…>'
62 call assert_equal('<M-…>', &pastetoggle)
63 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
64
65 " illegal bytes
66 let str = ":\x7f:\x80:\x90:\xd0:"
67 let &pastetoggle = str
68 call assert_equal(str, &pastetoggle)
69 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010070
zeertzjq0519ce02022-05-09 12:16:19 +010071 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010072 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010073endfunc
74
Bram Moolenaar1e115362019-01-09 23:01:02 +010075func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010076 " Empty 'wildchar' used to access invalid memory.
77 call assert_fails('set wildchar=', 'E521:')
78 call assert_fails('set wildchar=abc', 'E521:')
79 set wildchar=<Esc>
80 let a=execute('set wildchar?')
81 call assert_equal("\n wildchar=<Esc>", a)
82 set wildchar=27
83 let a=execute('set wildchar?')
84 call assert_equal("\n wildchar=<Esc>", a)
85 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010086endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010087
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020088func Test_wildoptions()
89 set wildoptions=
90 set wildoptions+=tagfile
91 set wildoptions+=tagfile
92 call assert_equal('tagfile', &wildoptions)
93endfunc
94
Bram Moolenaar6b915c02020-01-18 15:53:19 +010095func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020096 let caught = 'ok'
97 try
98 options
99 catch
100 let caught = v:throwpoint . "\n" . v:exception
101 endtry
102 call assert_equal('ok', caught)
103
Bram Moolenaare0b59492019-05-21 20:54:45 +0200104 " Check if the option-window is opened horizontally.
105 wincmd j
106 call assert_notequal('option-window', bufname(''))
107 wincmd k
108 call assert_equal('option-window', bufname(''))
109 " close option-window
110 close
111
112 " Open the option-window vertically.
113 vert options
114 " Check if the option-window is opened vertically.
115 wincmd l
116 call assert_notequal('option-window', bufname(''))
117 wincmd h
118 call assert_equal('option-window', bufname(''))
119 " close option-window
120 close
121
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200122 " Open the option-window at the top.
123 set splitbelow
124 topleft options
125 call assert_equal(1, winnr())
126 close
127
128 " Open the option-window at the bottom.
129 set nosplitbelow
130 botright options
131 call assert_equal(winnr('$'), winnr())
132 close
133 set splitbelow&
134
Bram Moolenaare0b59492019-05-21 20:54:45 +0200135 " Open the option-window in a new tab.
136 tab options
137 " Check if the option-window is opened in a tab.
138 normal gT
139 call assert_notequal('option-window', bufname(''))
140 normal gt
141 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200142 " close option-window
143 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200144
145 " Open the options window browse
146 if has('browse')
147 browse set
148 call assert_equal('option-window', bufname(''))
149 close
150 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100151endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200152
Bram Moolenaar1e115362019-01-09 23:01:02 +0100153func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200154 " Test that changing 'path' keeps two commas.
155 set path=foo,,bar
156 set path-=bar
157 set path+=bar
158 call assert_equal('foo,,bar', &path)
159
160 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100161endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200162
Dominique Pellef645ee42021-12-05 13:21:18 +0000163func Test_path_too_long()
164 exe 'set path=' .. repeat('x', 10000)
165 call assert_fails('find x', 'E854:')
166 set path&
167endfunc
168
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200169func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200170 CheckFeature signs
171 call assert_equal("auto", &signcolumn)
172 set signcolumn=yes
173 set signcolumn=no
174 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200175endfunc
176
Bram Moolenaard0b51382016-11-04 15:23:45 +0100177func Test_filetype_valid()
178 set ft=valid_name
179 call assert_equal("valid_name", &filetype)
180 set ft=valid-name
181 call assert_equal("valid-name", &filetype)
182
183 call assert_fails(":set ft=wrong;name", "E474:")
184 call assert_fails(":set ft=wrong\\\\name", "E474:")
185 call assert_fails(":set ft=wrong\\|name", "E474:")
186 call assert_fails(":set ft=wrong/name", "E474:")
187 call assert_fails(":set ft=wrong\\\nname", "E474:")
188 call assert_equal("valid-name", &filetype)
189
190 exe "set ft=trunc\x00name"
191 call assert_equal("trunc", &filetype)
192endfunc
193
194func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200195 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100196 set syn=valid_name
197 call assert_equal("valid_name", &syntax)
198 set syn=valid-name
199 call assert_equal("valid-name", &syntax)
200
201 call assert_fails(":set syn=wrong;name", "E474:")
202 call assert_fails(":set syn=wrong\\\\name", "E474:")
203 call assert_fails(":set syn=wrong\\|name", "E474:")
204 call assert_fails(":set syn=wrong/name", "E474:")
205 call assert_fails(":set syn=wrong\\\nname", "E474:")
206 call assert_equal("valid-name", &syntax)
207
208 exe "set syn=trunc\x00name"
209 call assert_equal("trunc", &syntax)
210endfunc
211
212func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200213 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100214 call assert_fails(":set kmp=valid_name", "E544:")
215 call assert_fails(":set kmp=valid_name", "valid_name")
216 call assert_fails(":set kmp=valid-name", "E544:")
217 call assert_fails(":set kmp=valid-name", "valid-name")
218
219 call assert_fails(":set kmp=wrong;name", "E474:")
220 call assert_fails(":set kmp=wrong\\\\name", "E474:")
221 call assert_fails(":set kmp=wrong\\|name", "E474:")
222 call assert_fails(":set kmp=wrong/name", "E474:")
223 call assert_fails(":set kmp=wrong\\\nname", "E474:")
224
225 call assert_fails(":set kmp=trunc\x00name", "E544:")
226 call assert_fails(":set kmp=trunc\x00name", "trunc")
227endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100228
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200229func Test_wildchar_valid()
230 call assert_fails("set wildchar=<CR>", "E474:")
231 call assert_fails("set wildcharm=<C-C>", "E474:")
232endfunc
233
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100234func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100235 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100236 exe 'set ' . a:name . '=/usr/share/dict/words'
237 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
238 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
239 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
240 exe 'set ' . a:name . '=/usr/share/dict\ words'
241 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100242
243 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100244 call assert_fails("set " . a:name . "=/not&there", "E474:")
245 call assert_fails("set " . a:name . "=/not>there", "E474:")
246 call assert_fails("set " . a:name . "=/not.*there", "E474:")
247endfunc
248
Bram Moolenaar60629d62017-02-23 18:08:56 +0100249func Test_cinkeys()
250 " This used to cause invalid memory access
251 set cindent cinkeys=0
252 norm a
253 set cindent& cinkeys&
254endfunc
255
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100256func Test_dictionary()
257 call Check_dir_option('dictionary')
258endfunc
259
260func Test_thesaurus()
261 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100262endfun
263
Bram Moolenaar226c5342017-02-17 14:53:15 +0100264func Test_complete()
265 " Trailing single backslash used to cause invalid memory access.
266 set complete=s\
267 new
268 call feedkeys("i\<C-N>\<Esc>", 'xt')
269 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200270 call assert_fails('set complete=ix', 'E535:')
Girish Palyacbe53192025-04-14 22:13:15 +0200271 call assert_fails('set complete=x', 'E539:')
272 call assert_fails('set complete=..', 'E535:')
Girish Palya14f6da52025-05-26 19:04:25 +0200273 set complete=.,w,b,u,k,\ s,i,d,],t,U,F,o
Girish Palya0ac1eb32025-04-16 20:18:33 +0200274 call assert_fails('set complete=i^-10', 'E535:')
275 call assert_fails('set complete=i^x', 'E535:')
zeertzjq67fe77d2025-04-20 10:21:18 +0200276 call assert_fails('set complete=k^2,t^-1,s^', 'E535:')
277 call assert_fails('set complete=t^-1', 'E535:')
278 call assert_fails('set complete=kfoo^foo2', 'E535:')
279 call assert_fails('set complete=kfoo^', 'E535:')
280 call assert_fails('set complete=.^', 'E535:')
Girish Palya14f6da52025-05-26 19:04:25 +0200281 set complete=.,w,b,u,k,s,i,d,],t,U,F,o
Girish Palyacbe53192025-04-14 22:13:15 +0200282 set complete=.
Girish Palya0ac1eb32025-04-16 20:18:33 +0200283 set complete=.^10,t^0
Girish Palya14f6da52025-05-26 19:04:25 +0200284 set complete+=Ffuncref('foo'\\,\ [10])
285 set complete=Ffuncref('foo'\\,\ [10])^10
Girish Palyacbe53192025-04-14 22:13:15 +0200286 set complete&
Girish Palya14f6da52025-05-26 19:04:25 +0200287 set complete+=Ffunction('g:foo'\\,\ [10\\,\ 20])
Bram Moolenaar226c5342017-02-17 14:53:15 +0100288 set complete&
289endfun
290
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100291func Test_set_completion()
292 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
293 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
294
Bram Moolenaar297610b2019-12-27 17:20:55 +0100295 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
296 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
297
298 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
299 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
300
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100301 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
302 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100303 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100304 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100305
306 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100307 call assert_equal('"set invdiff invdigraph', @:)
308
309 " Expanding "set noinv" does nothing.
310 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
311 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100312
313 " Expand abbreviation of options.
314 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100315 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100316
317 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200318 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
319 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100320
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200321 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
322 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100323
324 " Expand key codes.
325 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
326 call assert_equal('"set <Help> <Home>', @:)
Yee Cheng Chin7d8e7df2025-03-27 17:43:41 +0100327 " <BackSpace> (alt name) and <BS> should both show up in auto-complete
328 call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx')
329 call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:)
330 " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here
331 " nor show up as duplicates
332 call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx')
333 call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100334
335 " Expand terminal options.
336 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200337 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200338 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100339
340 " Expand directories.
341 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
342 call assert_match(' ./samples/ ', @:)
Christian Brabandteb380b92025-07-07 20:53:55 +0200343 call assert_notmatch(' ./util/summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200344 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100345
346 " Expand files and directories.
347 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Christian Brabandteb380b92025-07-07 20:53:55 +0200348 call assert_match(' ./samples/.* ./test10.in', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100349
350 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
351 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200352
353 " Expand files with spaces/commas in them. Make sure we delimit correctly.
354 "
355 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
356 " spaces requiring double escape, and commas need a single escape.
357 " 'dictionary' is a normal comma-separated option where only commas act as
358 " delimiters, and both space/comma need one single escape.
359 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
360 defer delete('Xfoo Xspace.txt')
361 defer delete('Xsp_dummy')
362 defer delete('Xbar,Xcomma.txt')
363 defer delete('Xcom_dummy')
364 call writefile([], 'Xfoo Xspace.txt')
365 call writefile([], 'Xsp_dummy')
366 call writefile([], 'Xbar,Xcomma.txt')
367 call writefile([], 'Xcom_dummy')
368
369 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
370 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
371 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
372 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
373 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
374 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
375
376 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
377 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
378 if has('win32')
379 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
380 " means we treat it as one file name.
381 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
382 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
383 else
384 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
385 " to split into a separate file name. You need '\\,' to escape the comma
386 " as part of the file name.
387 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
388 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
389
390 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
391 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
392 endif
393 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
394 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
395 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200396
397 " Expanding the option names
398 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
399 call assert_equal('"set all', @:)
400
401 " Expanding a second set of option names
402 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
403 call assert_equal('"set wrapscan all', @:)
404
405 " Expanding a special keycode
406 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
407 call assert_equal('"set <Home>', @:)
408
409 " Expanding an invalid special keycode
410 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
411 call assert_equal("\"set <abcd>\<Tab>", @:)
412
413 " Expanding a terminal keycode
414 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
415 call assert_equal("\"set t_AB", @:)
416
417 " Expanding an invalid option name
418 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"set abcde=\<Tab>", @:)
420
421 " Expanding after a = for a boolean option
422 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal("\"set wrapscan=\<Tab>", @:)
424
425 " Expanding a numeric option
426 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
427 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
428
429 " Expanding a non-boolean option
430 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
431 call assert_equal("\"set invtabstop=", @:)
432
433 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200434 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
435 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
436 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
437 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200438
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200439 " Expanding value for 'key' is disallowed
440 if exists('+key')
441 set key=abcd
442 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
443 call assert_equal('"set key=', @:)
444 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
445 call assert_equal('"set key-=', @:)
446 set key=
447 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100448
449 " Expand values for 'filetype'
450 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
451 call assert_equal('"set filetype=sshdconfig', @:)
452 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
453 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200454
455 " Expand values for 'syntax'
456 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
457 call assert_equal('"set syntax=sshdconfig', @:)
458 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
459 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100460
461 if has('keymap')
462 " Expand values for 'keymap'
463 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
464 call assert_equal('"set keymap=accents', @:)
465 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
466 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
467 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100468endfunc
469
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200470" Test handling of expanding individual string option values
471func Test_set_completion_string_values()
472 "
473 " Test basic enum string options that have well-defined enum names
474 "
475
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200476 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
477 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
478 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200479
480 " Test that if a value is set, it will populate the results, but only if
481 " typed value is empty.
482 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200483 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
484 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200485 " If the set value is part of the enum list, it will show as the first
486 " result with no duplicate.
487 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200488 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200489 " If empty value, will just show the normal list without an empty item
490 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200491 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200492 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200493 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200494
495 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200496 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200497 " Also test the positioning of the expansion is correct
498 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
499 call assert_equal('"set display=truncate,lastline', @:)
500 set display&
501
502 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200503 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200504
505 " Test the other simple options to make sure they have basic auto-complete,
506 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200507 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200508 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Luca Saccarola959ef612024-12-01 16:25:53 +0100509 call assert_equal('indent,eol,start', getcompletion('set backspace=', 'cmdline')[0])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200510 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
511 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
512 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200513 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200514 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200515 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200516 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
517 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
518 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200519 if exists('+clipboard')
520 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
521 endif
Foxe Chenb90c2392025-06-27 21:10:35 +0200522 if exists('+clipmethod')
523 if has('unix') || has('vms')
524 call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[1])
525 else
526 call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[0])
527 endif
528 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200529 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
530 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
zeertzjq53d59ec2025-03-07 19:09:09 +0100531 call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200532 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200533 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200534 endif
535 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200536 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200537 endif
538 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200540 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200541 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
542 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
543 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200544 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
547 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200548 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200549 endif
550 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200551 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200552 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200553 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
554 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
555 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200556 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200557 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200558 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200559 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200560 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200561 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
562 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
563 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200564 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200565 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200566 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200567 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200568 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200569 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200570 endif
571 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200572 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200573 endif
574 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200575 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200576 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200577 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
578 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
579 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
580 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200581 if exists('+tabclose')
582 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
583 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200584 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200585 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200586 endif
587 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200588 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200589 endif
590 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200591 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200592 endif
593 if exists('+ttymouse')
594 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200595 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200596 set ttymouse&
597 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200598 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
599 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
600 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
601 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200602 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200603 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200604 endif
605
606 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200607 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
Luuk van Baal8cc6d8b2025-05-31 12:10:31 +0200608 call assert_equal(['-BufAdd', '-BufCreate'], getcompletion('set eventignore=all,-', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100609 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200610 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
611 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
612 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200613
zeertzjq1f025b02023-09-30 12:43:07 +0200614 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
615 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
616 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
617 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
618 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
619 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200620
621 "
622 " Unique string options below
623 "
624
625 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200626 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200627 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
628 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100629 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
630 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200631 set keyprotocol&
632
633 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200634 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
635 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200636 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
637 call assert_equal('"set previewpopup+=border:on', @:)
638 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
639 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200640 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200641 set previewpopup& completepopup&
642
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100643 " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200644 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
645 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
646 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100647 call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200648
649 " highlight: special parsing, including auto-completing highlight groups
650 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200651 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
652 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
653 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
654 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
655 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200656 " If all the display modes are used up we should be suggesting nothing. Make
657 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
658 " and make sure nothing is suggested from that.
659 let hl_display_modes = join(
660 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
661 \ {idx, val -> val[1]}),
662 \ {idx, val -> val != ':'}),
663 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200664 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200665 " Test completion in middle of the line
666 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
667 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200668
Christian Brabandt51d4d842024-12-06 17:26:25 +0100669 " messagesopt
670 call assert_equal(['history:', 'hit-enter', 'wait:'],
671 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
672
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200673 "
674 " Test flag lists
675 "
676
677 " Test set=. Show the original value if nothing is typed after '='.
678 " Otherwise, the list should avoid showing what's already typed.
679 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200680 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200681 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200682 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
683 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200684
685 " Test set+=. Never show original value, and it also tries to avoid listing
686 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200687 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
688 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
689 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200690
691 " Test that the position of the expansion is correct (even if there are
692 " additional values after the current cursor)
693 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
694 call assert_equal('"set mouse=han', @:)
695 set mouse&
696
697 " Test that other flag list options have auto-complete, but don't
698 " exhaustively validate their results.
699 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200700 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200701 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200702 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
703 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200704 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200705 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200706 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200707 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
708 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200709
710 "
711 "Test set-=
712 "
713
714 " Normal single-value option just shows the existing value
715 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200716 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200717 set ambiwidth&
718
719 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200720 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200721 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200722 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200723 set t_Ce&
724
725 " Comma-separated lists should present each option
726 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200727 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
728 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
729 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200730 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200731 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200732 " Test empty option
733 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200734 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100735 " Test all possible values
736 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100737 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'],
Christian Brabandt9162e632025-01-16 19:03:40 +0100738 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200739 set diffopt&
740
741 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200742 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200743
744 " Test files with commas in name are being parsed and escaped properly
745 set path=has\\\ space,file\\,with\\,comma,normal_file
746 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200747 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200748 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200749 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200750 endif
751 set path&
752
753 " Flag list should present orig value, then individual flags
754 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200755 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200756 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200757 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200758 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200759 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200760 " Test empty option
761 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200762 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200763 set mouse&
764
765 " 'whichwrap' is an odd case where it's both flag list and comma-separated
766 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200767 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200768 set ww&
769endfunc
770
zeertzjq4c7cb372023-06-14 16:39:54 +0100771func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100772 call assert_fails('set scroll=-1', 'E49:')
773 call assert_fails('set backupcopy=', 'E474:')
774 call assert_fails('set regexpengine=3', 'E474:')
775 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200776 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100777 call assert_fails('set colorcolumn=-a', 'E474:')
778 call assert_fails('set colorcolumn=a', 'E474:')
779 call assert_fails('set colorcolumn=1,', 'E474:')
780 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100781 call assert_fails('set cmdheight=-1', 'E487:')
782 call assert_fails('set cmdwinheight=-1', 'E487:')
783 if has('conceal')
784 call assert_fails('set conceallevel=-1', 'E487:')
785 call assert_fails('set conceallevel=4', 'E474:')
786 endif
787 call assert_fails('set helpheight=-1', 'E487:')
788 call assert_fails('set history=-1', 'E487:')
789 call assert_fails('set report=-1', 'E487:')
790 call assert_fails('set shiftwidth=-1', 'E487:')
791 call assert_fails('set sidescroll=-1', 'E487:')
792 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000793 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000794 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000795 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200796 if has('terminal')
797 call assert_fails('set termwinscroll=-1', 'E487:')
798 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100799 call assert_fails('set textwidth=-1', 'E487:')
800 call assert_fails('set timeoutlen=-1', 'E487:')
801 call assert_fails('set updatecount=-1', 'E487:')
802 call assert_fails('set updatetime=-1', 'E487:')
803 call assert_fails('set winheight=-1', 'E487:')
804 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200805
806 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100807 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200808 call assert_fails('setlocal xxx', 'E518:')
809 call assert_fails('setglobal xxx', 'E518:')
810 call assert_fails('set xxx=', 'E518:')
811 call assert_fails('setlocal xxx=', 'E518:')
812 call assert_fails('setglobal xxx=', 'E518:')
813 call assert_fails('set xxx:', 'E518:')
814 call assert_fails('setlocal xxx:', 'E518:')
815 call assert_fails('setglobal xxx:', 'E518:')
816 call assert_fails('set xxx!', 'E518:')
817 call assert_fails('setlocal xxx!', 'E518:')
818 call assert_fails('setglobal xxx!', 'E518:')
819 call assert_fails('set xxx?', 'E518:')
820 call assert_fails('setlocal xxx?', 'E518:')
821 call assert_fails('setglobal xxx?', 'E518:')
822 call assert_fails('set xxx&', 'E518:')
823 call assert_fails('setlocal xxx&', 'E518:')
824 call assert_fails('setglobal xxx&', 'E518:')
825 call assert_fails('set xxx<', 'E518:')
826 call assert_fails('setlocal xxx<', 'E518:')
827 call assert_fails('setglobal xxx<', 'E518:')
828
829 " Test for missing-options errors.
830 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100831 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200832 call assert_fails('set flash?', 'E519:')
833 call assert_fails('set graphic?', 'E519:')
834 call assert_fails('set hardtabs?', 'E519:')
835 call assert_fails('set mesg?', 'E519:')
836 call assert_fails('set novice?', 'E519:')
837 call assert_fails('set open?', 'E519:')
838 call assert_fails('set optimize?', 'E519:')
839 call assert_fails('set redraw?', 'E519:')
840 call assert_fails('set slowopen?', 'E519:')
841 call assert_fails('set sourceany?', 'E519:')
842 call assert_fails('set w300?', 'E519:')
843 call assert_fails('set w1200?', 'E519:')
844 call assert_fails('set w9600?', 'E519:')
845
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100846 call assert_fails('set undolevels=x', 'E521:')
847 call assert_fails('set tabstop=', 'E521:')
848 call assert_fails('set comments=-', 'E524:')
849 call assert_fails('set comments=a', 'E525:')
850 call assert_fails('set foldmarker=x', 'E536:')
851 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000852 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100853 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100854 call assert_fails('set rulerformat=%-', 'E539:')
855 call assert_fails('set rulerformat=%(', 'E542:')
856 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200857
858 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100859 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100860 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100861 call assert_fails('set statusline=%{%', 'E540:')
862 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100863 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100864 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200865
866 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100867 call assert_fails('set tabline=%$', 'E539:')
868 call assert_fails('set tabline=%{', 'E540:')
869 call assert_fails('set tabline=%{%', 'E540:')
870 call assert_fails('set tabline=%{%}', 'E539:')
871 call assert_fails('set tabline=%(', 'E542:')
872 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100873
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100874 if has('cursorshape')
875 " This invalid value for 'guicursor' used to cause Vim to crash.
876 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
877 call assert_fails('set guicursor=i-ci', 'E545:')
878 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100879 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100880 call assert_fails('set guicursor=r-cr:horx', 'E548:')
881 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
882 endif
Milly484face2024-10-12 11:26:06 +0200883
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100884 if has('mouseshape')
885 call assert_fails('se mouseshape=i-r:x', 'E547:')
886 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000887
888 " Test for 'backupext' and 'patchmode' set to the same value
889 set backupext=.bak
890 set patchmode=.patch
891 call assert_fails('set patchmode=.bak', 'E589:')
892 call assert_equal('.patch', &patchmode)
893 call assert_fails('set backupext=.patch', 'E589:')
894 call assert_equal('.bak', &backupext)
895 set backupext& patchmode&
896
Milly484face2024-10-12 11:26:06 +0200897 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100898 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200899 set winminheight& winheight&
900 set winheight=10 winminheight=10
901 call assert_fails('set winheight=9', 'E591:')
902 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200903
904 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100905 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200906 set winminwidth& winwidth&
907 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
908 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200909
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100910 call assert_fails("set showbreak=\x01", 'E595:')
911 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200912 call assert_fails('set tabstop??', 'E488:')
913 call assert_fails('set wrapscan!!', 'E488:')
914 call assert_fails('set tabstop&&', 'E488:')
915 call assert_fails('set wrapscan<<', 'E488:')
916 call assert_fails('set wrapscan=1', 'E474:')
917 call assert_fails('set autoindent@', 'E488:')
918 call assert_fails('set wildchar=<abc>', 'E474:')
919 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200920 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100921 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200922 call assert_fails('set pyxversion=6', 'E474:')
923 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100924 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200925 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100926 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
927 call assert_fails('set foldmarker={{{,', 'E474:')
928 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200929
930 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100931 setlocal listchars=trail:·
932 call assert_fails('set ambiwidth=double', 'E834:')
933 setlocal listchars=trail:-
934 setglobal listchars=trail:·
935 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100936 set listchars&
Milly484face2024-10-12 11:26:06 +0200937
938 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100939 setlocal fillchars=stl:·
940 call assert_fails('set ambiwidth=double', 'E835:')
941 setlocal fillchars=stl:-
942 setglobal fillchars=stl:·
943 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100944 set fillchars&
Milly484face2024-10-12 11:26:06 +0200945
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100946 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
947 set nomodifiable
948 call assert_fails('set fileencoding=latin1', 'E21:')
949 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200950 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000951 call assert_fails('let &formatoptions = "?"', 'E539:')
952 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200953
954 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100955 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
956 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
957 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
958 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
959 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
960 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100961endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100962
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000963func Test_set_encoding()
964 let save_encoding = &encoding
965
966 set enc=iso8859-1
967 call assert_equal('latin1', &enc)
968 set enc=iso8859_1
969 call assert_equal('latin1', &enc)
970 set enc=iso-8859-1
971 call assert_equal('latin1', &enc)
972 set enc=iso_8859_1
973 call assert_equal('latin1', &enc)
974 set enc=iso88591
975 call assert_equal('latin1', &enc)
976 set enc=iso8859
977 call assert_equal('latin1', &enc)
978 set enc=iso-8859
979 call assert_equal('latin1', &enc)
980 set enc=iso_8859
981 call assert_equal('latin1', &enc)
982 call assert_fails('set enc=iso8858', 'E474:')
983 call assert_equal('latin1', &enc)
984
985 let &encoding = save_encoding
986endfunc
987
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200988func CheckWasSet(name)
989 let verb_cm = execute('verbose set ' .. a:name .. '?')
990 call assert_match('Last set from.*test_options.vim', verb_cm)
991endfunc
992func CheckWasNotSet(name)
993 let verb_cm = execute('verbose set ' .. a:name .. '?')
994 call assert_notmatch('Last set from', verb_cm)
995endfunc
996
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200997" Must be executed before other tests that set 'term'.
998func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200999 CheckNotGui
1000
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001001 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001002
1003 let term_save = &term
1004 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001005 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001006 let &term = term_save
1007endfunc
1008
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001009func Test_copy_context()
1010 setlocal list
1011 call CheckWasSet('list')
1012 split
1013 call CheckWasSet('list')
1014 quit
1015 setlocal nolist
1016
1017 set ai
1018 call CheckWasSet('ai')
1019 set filetype=perl
1020 call CheckWasSet('filetype')
1021 set fo=tcroq
1022 call CheckWasSet('fo')
1023
1024 split Xsomebuf
1025 call CheckWasSet('ai')
1026 call CheckWasNotSet('filetype')
1027 call CheckWasSet('fo')
1028endfunc
1029
Bram Moolenaar67391142017-02-19 21:07:04 +01001030func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001031 CheckUnix
1032 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001033
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001034 " Setting 'ttytype' used to cause a double-free when exiting vim and
1035 " when vim is compiled with -DEXITFREE.
1036 set ttytype=ansi
1037 call assert_equal('ansi', &ttytype)
1038 call assert_equal(&ttytype, &term)
1039 set ttytype=xterm
1040 call assert_equal('xterm', &ttytype)
1041 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001042 try
1043 set ttytype=
1044 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001045 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001046 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001047
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001048 " Some systems accept any terminal name and return dumb settings,
1049 " check for failure of finding the entry and for missing 'cm' entry.
1050 try
1051 set ttytype=xxx
1052 call assert_report('set ttytype=xxx did not fail')
1053 catch /E522\|E437/
1054 endtry
1055
1056 set ttytype&
1057 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001058
1059 if has('gui') && !has('gui_running')
1060 call assert_fails('set term=gui', 'E531:')
1061 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001062endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001063
Milly484face2024-10-12 11:26:06 +02001064" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001065func Test_set_all()
1066 set tw=75
1067 set iskeyword=a-z,A-Z
1068 set nosplitbelow
1069 let out = execute('set all')
1070 call assert_match('textwidth=75', out)
1071 call assert_match('iskeyword=a-z,A-Z', out)
1072 call assert_match('nosplitbelow', out)
1073 set tw& iskeyword& splitbelow&
1074endfunc
1075
Milly484face2024-10-12 11:26:06 +02001076" Test for :set! all
1077func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001078 let out_mult = execute('set all')->split("\n")
1079 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001080 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001081 call assert_equal(out_one[0], '--- Options ---')
1082 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1083 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001084endfunc
1085
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001086func Test_renderoptions()
1087 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1088 " Doesn't hurt to do this on a non-Windows system.
1089 if windowsversion() !~ '^[345]\.'
1090 set renderoptions=type:directx
1091 set rop=type:directx
1092 endif
1093endfunc
1094
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001095func ResetIndentexpr()
1096 set indentexpr=
1097endfunc
1098
1099func Test_set_indentexpr()
1100 " this was causing usage of freed memory
1101 set indentexpr=ResetIndentexpr()
1102 new
1103 call feedkeys("i\<c-f>", 'x')
1104 call assert_equal('', &indentexpr)
1105 bwipe!
1106endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001107
1108func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001109 " Option 'backupskip' may contain several comma-separated path
1110 " specifications if one or more of the environment variables TMPDIR, TMP,
1111 " or TEMP is defined. To simplify testing, convert the string value into a
1112 " list.
1113 let bsklist = split(&bsk, ',')
1114
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001115 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001116 let found = (index(bsklist, '/private/tmp/*') >= 0)
1117 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001118 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001119 let found = (index(bsklist, '/tmp/*') >= 0)
1120 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001121 endif
1122
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001123 " If our test platform is Windows, the path(s) in option bsk will use
1124 " backslash for the path separator and the components could be in short
1125 " (8.3) format. As such, we need to replace the backslashes with forward
1126 " slashes and convert the path components to long format. The expand()
1127 " function will do this but it cannot handle comma-separated paths. This is
1128 " why bsk was converted from a string into a list of strings above.
1129 "
1130 " One final complication is that the wildcard "/*" is at the end of each
1131 " path and so expand() might return a list of matching files. To prevent
1132 " this, we need to remove the wildcard before calling expand() and then
1133 " append it afterwards.
1134 if has('win32')
1135 let item_nbr = 0
1136 while item_nbr < len(bsklist)
1137 let path_spec = bsklist[item_nbr]
1138 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1139 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1140 let bsklist[item_nbr] = path_spec . '/*'
1141 let item_nbr += 1
1142 endwhile
1143 endif
1144
1145 " Option bsk will also include these environment variables if defined.
1146 " If they're defined, verify they appear in the option value.
1147 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001148 if exists(var)
1149 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001150 let varvalue = substitute(varvalue, '/$', '', '')
1151 let varvalue .= '/*'
1152 let found = (index(bsklist, varvalue) >= 0)
1153 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001154 endif
1155 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001156
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001157 " Duplicates from environment variables should be filtered out (option has
1158 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1159 " so that we see what happens on startup.
1160 let after =<< trim [CODE]
1161 let bsklist = split(&backupskip, ',')
1162 call assert_equal(uniq(copy(bsklist)), bsklist)
1163 call writefile(['errors:'] + v:errors, 'Xtestout')
1164 qall
1165 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001166 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001167 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1168
1169 let saveenv = {}
1170 for var in ['TMPDIR', 'TMP', 'TEMP']
1171 let saveenv[var] = getenv(var)
1172 call setenv(var, '/duplicate/path')
1173 endfor
1174
Christian Brabandtad503fe2025-04-16 20:25:47 +02001175 " unset $HOME, so that it won't try to read init files
1176 let saveenv['HOME'] = getenv("HOME")
1177 call setenv('HOME', v:null)
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001178 exe 'silent !' . cmd
1179 call assert_equal(['errors:'], readfile('Xtestout'))
1180
1181 " restore environment variables
Christian Brabandtad503fe2025-04-16 20:25:47 +02001182 for var in ['TMPDIR', 'TMP', 'TEMP', 'HOME']
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001183 call setenv(var, saveenv[var])
1184 endfor
1185
1186 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001187
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001188 " Duplicates should be filtered out (option has P_NODUP)
1189 let backupskip = &backupskip
1190 set backupskip=
1191 set backupskip+=/test/dir
1192 set backupskip+=/other/dir
1193 set backupskip+=/test/dir
1194 call assert_equal('/test/dir,/other/dir', &backupskip)
1195 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001196endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001197
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001198func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001199 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001200
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001201 " Test copy option from current buffer in window
1202 split
1203 enew
1204 setlocal numberwidth=5
1205 wincmd w
1206 call assert_equal(4,&numberwidth)
1207 bnext
1208 call assert_equal(5,&numberwidth)
1209 bw!
1210 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001211
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001212 " Test copy value from window that used to be display the buffer
1213 split
1214 enew
1215 setlocal numberwidth=6
1216 bnext
1217 wincmd w
1218 call assert_equal(4,&numberwidth)
1219 bnext
1220 call assert_equal(6,&numberwidth)
1221 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001222
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001223 " Test that if buffer is current, don't use the stale cached value
1224 " from the last time the buffer was displayed.
1225 split
1226 enew
1227 setlocal numberwidth=7
1228 bnext
1229 bnext
1230 setlocal numberwidth=8
1231 wincmd w
1232 call assert_equal(4,&numberwidth)
1233 bnext
1234 call assert_equal(8,&numberwidth)
1235 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001236
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001237 " Test value is not copied if window already has seen the buffer
1238 enew
1239 split
1240 setlocal numberwidth=9
1241 bnext
1242 setlocal numberwidth=10
1243 wincmd w
1244 call assert_equal(4,&numberwidth)
1245 bnext
1246 call assert_equal(4,&numberwidth)
1247 bw!
1248
1249 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001250endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001251
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001252def Test_split_copy_options()
1253 var values = [
1254 ['cursorbind', true, false],
1255 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1256 ['list', true, 0],
1257 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1258 ['number', true, 0],
1259 ['relativenumber', true, false],
1260 ['scrollbind', true, false],
1261 ['smoothscroll', true, false],
1262 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1263 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1264 ['wrap', false, true],
1265 ]
1266 if has('linebreak')
1267 values += [
1268 ['breakindent', true, false],
1269 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1270 ['linebreak', true, false],
1271 ['numberwidth', 7, 4],
1272 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1273 ]
1274 endif
1275 if has('rightleft')
1276 values += [
1277 ['rightleft', true, false],
1278 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1279 ]
1280 endif
1281 if has('statusline')
1282 values += [
1283 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1284 ]
1285 endif
1286 if has('spell')
1287 values += [
1288 ['spell', true, false],
1289 ]
1290 endif
1291 if has('syntax')
1292 values += [
1293 ['cursorcolumn', true, false],
1294 ['cursorline', true, false],
1295 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1296 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1297 ]
1298 endif
1299 if has('diff')
1300 values += [
1301 ['diff', true, false],
1302 ]
1303 endif
1304 if has('conceal')
1305 values += [
1306 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1307 ['conceallevel', '3', &conceallevel],
1308 ]
1309 endif
1310 if has('terminal')
1311 values += [
1312 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1313 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1314 ]
1315 endif
1316 if has('folding')
1317 values += [
1318 ['foldcolumn', 5, &foldcolumn],
1319 ['foldenable', false, true],
1320 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1321 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1322 ['foldlevel', 4, &foldlevel],
1323 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1324 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1325 ['foldminlines', 3, &foldminlines],
1326 ['foldnestmax', 17, &foldnestmax],
1327 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1328 ]
1329 endif
1330 if has('signs')
1331 values += [
1332 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1333 ]
1334 endif
1335
1336 # set options to non-default value
1337 for item in values
1338 exe $'&l:{item[0]} = {item[1]}'
1339 endfor
1340
1341 # check values are set in new window
1342 split
1343 for item in values
1344 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1345 endfor
1346
1347 # restore
1348 close
1349 for item in values
1350 exe $'&l:{item[0]} = {item[2]}'
1351 endfor
1352enddef
1353
Bram Moolenaarfc089602018-06-24 16:53:35 +02001354func Test_shortmess_F()
1355 new
1356 call assert_match('\[No Name\]', execute('file'))
1357 set shortmess+=F
1358 call assert_match('\[No Name\]', execute('file'))
1359 call assert_match('^\s*$', execute('file foo'))
1360 call assert_match('foo', execute('file'))
1361 set shortmess-=F
1362 call assert_match('bar', execute('file bar'))
1363 call assert_match('bar', execute('file'))
1364 set shortmess&
1365 bwipe
1366endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001367
1368func Test_shortmess_F2()
1369 e file1
1370 e file2
1371 call assert_match('file1', execute('bn', ''))
1372 call assert_match('file2', execute('bn', ''))
1373 set shortmess+=F
1374 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001375 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001376 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001377 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001378 set hidden
1379 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001380 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001381 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001382 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001383 set nohidden
1384 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001385 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001386 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001387 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001388 set shortmess&
1389 call assert_match('file1', execute('bn', ''))
1390 call assert_match('file2', execute('bn', ''))
1391 bwipe
1392 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001393 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001394endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001395
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001396func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001397 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001398
1399 set hidden
1400 set autoread
1401 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001402 e Xotherfile
1403 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001404 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001405 echo ''
1406
1407 if has('nanotime')
1408 sleep 10m
1409 else
1410 sleep 2
1411 endif
1412 call writefile(['bar'], 'X_dummy')
1413 bprev
1414 call assert_equal('', Screenline(&lines))
1415 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1416
1417 if has('nanotime')
1418 sleep 10m
1419 else
1420 sleep 2
1421 endif
1422 call writefile(['baz'], 'X_dummy')
1423 checktime
1424 call assert_equal('', Screenline(&lines))
1425 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001426
1427 set shortmess&
1428 set autoread&
1429 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001430 bwipe X_dummy
1431 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001432endfunc
1433
Bram Moolenaar375e3392019-01-31 18:26:10 +01001434func Test_local_scrolloff()
1435 set so=5
1436 set siso=7
1437 split
1438 call assert_equal(5, &so)
1439 setlocal so=3
1440 call assert_equal(3, &so)
1441 wincmd w
1442 call assert_equal(5, &so)
1443 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001444 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001445 setlocal so<
1446 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001447 setglob so=8
1448 call assert_equal(8, &so)
1449 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001450 setlocal so=0
1451 call assert_equal(0, &so)
1452 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001453 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001454
1455 call assert_equal(7, &siso)
1456 setlocal siso=3
1457 call assert_equal(3, &siso)
1458 wincmd w
1459 call assert_equal(7, &siso)
1460 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001461 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001462 setlocal siso<
1463 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001464 setglob siso=4
1465 call assert_equal(4, &siso)
1466 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001467 setlocal siso=0
1468 call assert_equal(0, &siso)
1469 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001470 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001471
1472 close
1473 set so&
1474 set siso&
1475endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001476
1477func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001478 CheckFunction reltimefloat
1479
Bram Moolenaar449ac472019-04-03 21:42:35 +02001480 new
1481 call setline(1, 'empty')
1482 redraw
1483 set writedelay=10
1484 let start = reltime()
1485 call setline(1, repeat('x', 70))
1486 redraw
1487 let elapsed = reltimefloat(reltime(start))
1488 set writedelay=0
1489 " With 'writedelay' set should take at least 30 * 10 msec
1490 call assert_inrange(30 * 0.01, 999.0, elapsed)
1491
1492 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001493endfunc
1494
1495func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001496 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001497 set visualbell
1498 call assert_beeps('normal 0h')
1499 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001500 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001501endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001502
1503" Test for the 'write' option
1504func Test_write()
1505 new
1506 call setline(1, ['L1'])
1507 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001508 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001509 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001510 " close swapfile
1511 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001512endfunc
1513
1514" Test for 'buftype' option
1515func Test_buftype()
1516 new
1517 call setline(1, ['L1'])
1518 set buftype=nowrite
1519 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001520
1521 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1522 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001523 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001524 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1525 endfor
1526
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001527 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001528endfunc
1529
Bram Moolenaar578fe942020-02-27 21:32:51 +01001530" Test for the 'rightleftcmd' option
1531func Test_rightleftcmd()
1532 CheckFeature rightleft
1533 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001534
1535 let g:l = []
1536 func AddPos()
1537 call add(g:l, screencol())
1538 return ''
1539 endfunc
1540 cmap <expr> <F2> AddPos()
1541
zeertzjqbb404f52022-07-23 06:25:29 +01001542 set rightleftcmd=
1543 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1544 \ "\<Right>\<F2>\<Esc>", 'xt')
1545 call assert_equal([2, 5, 3, 4], g:l)
1546
1547 let g:l = []
1548 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001549 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1550 \ "\<Left>\<F2>\<Esc>", 'xt')
1551 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1552
1553 cunmap <F2>
1554 unlet g:l
1555 set rightleftcmd&
1556 set rightleft&
1557endfunc
1558
zeertzjq28c162f2022-08-14 14:49:50 +01001559" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001560func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001561 " redraw to avoid matching previous messages
1562 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001563 set debug=beep
1564 exe "normal \<C-c>"
1565 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001566 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001567 " also check a line above, with a certain window width the colon is there
1568 call assert_match('Test_debug_option:$',
1569 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001570 set debug&
1571endfunc
1572
Bram Moolenaar004a6782020-04-11 17:09:31 +02001573" Test for the default CDPATH option
1574func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001575 let after =<< trim [CODE]
1576 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1577 call writefile(v:errors, 'Xtestout')
1578 qall
1579 [CODE]
1580 if has('unix')
1581 let $CDPATH='/path/to/dir1:/path/to/dir2'
1582 else
1583 let $CDPATH='/path/to/dir1;/path/to/dir2'
1584 endif
1585 if RunVim([], after, '')
1586 call assert_equal([], readfile('Xtestout'))
1587 call delete('Xtestout')
1588 endif
1589endfunc
1590
1591" Test for setting keycodes using set
1592func Test_opt_set_keycode()
1593 call assert_fails('set <t_k1=l', 'E474:')
1594 call assert_fails('set <Home=l', 'E474:')
1595 set <t_k9>=abcd
1596 call assert_equal('abcd', &t_k9)
1597 set <t_k9>&
1598 set <F9>=xyz
1599 call assert_equal('xyz', &t_k9)
1600 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001601
1602 " should we test all of them?
1603 set t_Ce=testCe
1604 set t_Cs=testCs
1605 set t_Us=testUs
1606 set t_ds=testds
1607 set t_Ds=testDs
1608 call assert_equal('testCe', &t_Ce)
1609 call assert_equal('testCs', &t_Cs)
1610 call assert_equal('testUs', &t_Us)
1611 call assert_equal('testds', &t_ds)
1612 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001613endfunc
1614
1615" Test for changing options in a sandbox
1616func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001617 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001618 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001619 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001620 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001621 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001622endfunc
1623
Milly484face2024-10-12 11:26:06 +02001624" Test for setting string global-local option value
1625func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001626 setglobal equalprg=gprg
1627 setlocal equalprg=lprg
1628 call assert_equal('gprg', &g:equalprg)
1629 call assert_equal('lprg', &l:equalprg)
1630 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001631
1632 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001633 set equalprg<
1634 call assert_equal('', &l:equalprg)
1635 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001636
1637 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001638 setglobal equalprg=gnewprg
1639 setlocal equalprg=lnewprg
1640 setlocal equalprg<
1641 call assert_equal('gnewprg', &l:equalprg)
1642 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001643
Milly484face2024-10-12 11:26:06 +02001644 set equalprg&
1645endfunc
1646
1647" Test for setting number global-local option value
1648func Test_set_number_global_local_option()
1649 setglobal scrolloff=10
1650 setlocal scrolloff=12
1651 call assert_equal(10, &g:scrolloff)
1652 call assert_equal(12, &l:scrolloff)
1653 call assert_equal(12, &scrolloff)
1654
1655 " :set {option}< set the effective value of {option} to its global value.
1656 set scrolloff<
1657 call assert_equal(10, &l:scrolloff)
1658 call assert_equal(10, &scrolloff)
1659
1660 " :setlocal {option}< removes the local value, so that the global value will be used.
1661 setglobal scrolloff=15
1662 setlocal scrolloff=18
1663 setlocal scrolloff<
1664 call assert_equal(-1, &l:scrolloff)
1665 call assert_equal(15, &scrolloff)
1666
1667 set scrolloff&
1668endfunc
1669
1670" Test for setting boolean global-local option value
1671func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001672 setglobal autoread
1673 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001674 call assert_equal(1, &g:autoread)
1675 call assert_equal(0, &l:autoread)
1676 call assert_equal(0, &autoread)
1677
1678 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001679 set autoread<
Milly484face2024-10-12 11:26:06 +02001680 call assert_equal(1, &l:autoread)
1681 call assert_equal(1, &autoread)
1682
1683 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001684 setglobal noautoread
1685 setlocal autoread
1686 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001687 call assert_equal(-1, &l:autoread)
1688 call assert_equal(0, &autoread)
1689
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001690 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001691endfunc
1692
Dominique Pelle042414f2021-07-12 21:43:19 +02001693func Test_set_in_sandbox()
1694 " Some boolean options cannot be set in sandbox, some can.
1695 call assert_fails('sandbox set modelineexpr', 'E48:')
1696 sandbox set number
1697 call assert_true(&number)
1698 set number&
1699
1700 " Some boolean options cannot be set in sandbox, some can.
1701 if has('python') || has('python3')
1702 call assert_fails('sandbox set pyxversion=3', 'E48:')
1703 endif
1704 sandbox set tabstop=4
1705 call assert_equal(4, &tabstop)
1706 set tabstop&
1707
1708 " Some string options cannot be set in sandbox, some can.
1709 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1710 sandbox set filetype=perl
1711 call assert_equal('perl', &filetype)
1712 set filetype&
1713endfunc
1714
Milly484face2024-10-12 11:26:06 +02001715" Test for setting string option value
1716func Test_set_string_option()
1717 " :set {option}=
1718 set makeprg=
1719 call assert_equal('', &mp)
1720 set makeprg=abc
1721 call assert_equal('abc', &mp)
1722
1723 " :set {option}:
1724 set makeprg:
1725 call assert_equal('', &mp)
1726 set makeprg:abc
1727 call assert_equal('abc', &mp)
1728
1729 " Let string
1730 let &makeprg = ''
1731 call assert_equal('', &mp)
1732 let &makeprg = 'abc'
1733 call assert_equal('abc', &mp)
1734
1735 " Let number converts to string
1736 let &makeprg = 42
1737 call assert_equal('42', &mp)
1738
1739 " Appending
1740 set makeprg=abc
1741 set makeprg+=def
1742 call assert_equal('abcdef', &mp)
1743 set makeprg+=def
1744 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1745 let &makeprg .= 'gh'
1746 call assert_equal('abcdefdefgh', &mp)
1747 let &makeprg ..= 'ij'
1748 call assert_equal('abcdefdefghij', &mp)
1749
1750 " Removing
1751 set makeprg=abcdefghi
1752 set makeprg-=def
1753 call assert_equal('abcghi', &mp)
1754 set makeprg-=def
1755 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1756
1757 " Prepending
1758 set makeprg=abc
1759 set makeprg^=def
1760 call assert_equal('defabc', &mp)
1761 set makeprg^=def
1762 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1763
1764 set makeprg&
1765endfunc
1766
1767" Test for setting string comma-separated list option value
1768func Test_set_string_comma_list_option()
1769 " :set {option}=
1770 set wildignore=
1771 call assert_equal('', &wildignore)
1772 set wildignore=*.png
1773 call assert_equal('*.png', &wildignore)
1774
1775 " :set {option}:
1776 set wildignore:
1777 call assert_equal('', &wildignore)
1778 set wildignore:*.png
1779 call assert_equal('*.png', &wildignore)
1780
1781 " Let string
1782 let &wildignore = ''
1783 call assert_equal('', &wildignore)
1784 let &wildignore = '*.png'
1785 call assert_equal('*.png', &wildignore)
1786
1787 " Let number converts to string
1788 let &wildignore = 42
1789 call assert_equal('42', &wildignore)
1790
1791 " Appending
1792 set wildignore=*.png
1793 set wildignore+=*.jpg
1794 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1795 set wildignore+=*.jpg
1796 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1797 set wildignore+=jpg
1798 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1799 let &wildignore .= 'foo'
1800 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1801 let &wildignore ..= 'bar'
1802 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1803
1804 " Removing
1805 set wildignore=*.png,*.jpg,*.obj
1806 set wildignore-=*.jpg
1807 call assert_equal('*.png,*.obj', &wildignore)
1808 set wildignore-=*.jpg
1809 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1810 set wildignore-=jpg
1811 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1812
1813 " Prepending
1814 set wildignore=*.png
1815 set wildignore^=*.jpg
1816 call assert_equal('*.jpg,*.png', &wildignore)
1817 set wildignore^=*.jpg
1818 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1819 set wildignore^=jpg
1820 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1821
1822 set wildignore&
1823endfunc
1824
1825" Test for setting string flags option value
1826func Test_set_string_flags_option()
1827 " :set {option}=
1828 set formatoptions=
1829 call assert_equal('', &fo)
1830 set formatoptions=abc
1831 call assert_equal('abc', &fo)
1832
1833 " :set {option}:
1834 set formatoptions:
1835 call assert_equal('', &fo)
1836 set formatoptions:abc
1837 call assert_equal('abc', &fo)
1838
1839 " Let string
1840 let &formatoptions = ''
1841 call assert_equal('', &fo)
1842 let &formatoptions = 'abc'
1843 call assert_equal('abc', &fo)
1844
1845 " Let number converts to string
1846 let &formatoptions = 12
1847 call assert_equal('12', &fo)
1848
1849 " Appending
1850 set formatoptions=abc
1851 set formatoptions+=pqr
1852 call assert_equal('abcpqr', &fo)
1853 set formatoptions+=pqr
1854 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1855 let &formatoptions .= 'r'
1856 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1857 let &formatoptions ..= 'r'
1858 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1859
1860 " Removing
1861 set formatoptions=abcpqr
1862 set formatoptions-=cp
1863 call assert_equal('abqr', &fo)
1864 set formatoptions-=cp
1865 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1866 set formatoptions-=ar
1867 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1868
1869 " Prepending
1870 set formatoptions=abc
1871 set formatoptions^=pqr
1872 call assert_equal('pqrabc', &fo)
1873 set formatoptions^=qr
1874 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1875
1876 set formatoptions&
1877endfunc
1878
1879" Test for setting number option value
1880func Test_set_number_option()
1881 " :set {option}=
1882 set scrolljump=5
1883 call assert_equal(5, &sj)
1884 set scrolljump=-3
1885 call assert_equal(-3, &sj)
1886
1887 " :set {option}:
1888 set scrolljump:7
1889 call assert_equal(7, &sj)
1890 set scrolljump:-5
1891 call assert_equal(-5, &sj)
1892
1893 " Set hex
1894 set scrolljump=0x10
1895 call assert_equal(16, &sj)
1896 set scrolljump=-0x10
1897 call assert_equal(-16, &sj)
1898 set scrolljump=0X12
1899 call assert_equal(18, &sj)
1900 set scrolljump=-0X12
1901 call assert_equal(-18, &sj)
1902
1903 " Set octal
1904 set scrolljump=010
1905 call assert_equal(8, &sj)
1906 set scrolljump=-010
1907 call assert_equal(-8, &sj)
1908 set scrolljump=0o12
1909 call assert_equal(10, &sj)
1910 set scrolljump=-0o12
1911 call assert_equal(-10, &sj)
1912 set scrolljump=0O15
1913 call assert_equal(13, &sj)
1914 set scrolljump=-0O15
1915 call assert_equal(-13, &sj)
1916
1917 " Let number
1918 let &scrolljump = 4
1919 call assert_equal(4, &sj)
1920 let &scrolljump = -6
1921 call assert_equal(-6, &sj)
1922
1923 " Let numeric string converts to number
1924 let &scrolljump = '7'
1925 call assert_equal(7, &sj)
1926 let &scrolljump = '-9'
1927 call assert_equal(-9, &sj)
1928
1929 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001930 set shiftwidth=4
1931 set sw+=2
1932 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001933 let &shiftwidth += 2
1934 call assert_equal(8, &sw)
1935
1936 " Decrementing
1937 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001938 set sw-=2
1939 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001940 let &shiftwidth -= 2
1941 call assert_equal(2, &sw)
1942
1943 " Multiplying
1944 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001945 set sw^=2
1946 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001947 let &shiftwidth *= 2
1948 call assert_equal(16, &sw)
1949
1950 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001951 set shiftwidth&
1952endfunc
1953
Milly484face2024-10-12 11:26:06 +02001954" Test for setting boolean option value
1955func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001956 set number&
Milly484face2024-10-12 11:26:06 +02001957
1958 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001959 set number
1960 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001961
1962 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001963 set nonu
1964 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001965
1966 " :set {option}!
1967 set number!
1968 call assert_equal(1, &nu)
1969 set number!
1970 call assert_equal(0, &nu)
1971
1972 " :set inv{option}
1973 set invnumber
1974 call assert_equal(1, &nu)
1975 set invnumber
1976 call assert_equal(0, &nu)
1977
1978 " Let number
1979 let &number = 1
1980 call assert_equal(1, &nu)
1981 let &number = 0
1982 call assert_equal(0, &nu)
1983
1984 " Let numeric string converts to number
1985 let &number = '1'
1986 call assert_equal(1, &nu)
1987 let &number = '0'
1988 call assert_equal(0, &nu)
1989
1990 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001991 let &nu = v:true
1992 call assert_equal(1, &nu)
1993 let &nu = v:false
1994 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001995
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001996 set number&
1997endfunc
1998
Milly484face2024-10-12 11:26:06 +02001999" Test for setting string option errors
2000func Test_set_string_option_errors()
2001 " :set no{option}
2002 call assert_fails('set nomakeprg', 'E474:')
2003 call assert_fails('setlocal nomakeprg', 'E474:')
2004 call assert_fails('setglobal nomakeprg', 'E474:')
2005
2006 " :set inv{option}
2007 call assert_fails('set invmakeprg', 'E474:')
2008 call assert_fails('setlocal invmakeprg', 'E474:')
2009 call assert_fails('setglobal invmakeprg', 'E474:')
2010
2011 " :set {option}!
2012 call assert_fails('set makeprg!', 'E488:')
2013 call assert_fails('setlocal makeprg!', 'E488:')
2014 call assert_fails('setglobal makeprg!', 'E488:')
2015
2016 " Invalid trailing chars
2017 call assert_fails('set makeprg??', 'E488:')
2018 call assert_fails('setlocal makeprg??', 'E488:')
2019 call assert_fails('setglobal makeprg??', 'E488:')
2020 call assert_fails('set makeprg&&', 'E488:')
2021 call assert_fails('setlocal makeprg&&', 'E488:')
2022 call assert_fails('setglobal makeprg&&', 'E488:')
2023 call assert_fails('set makeprg<<', 'E488:')
2024 call assert_fails('setlocal makeprg<<', 'E488:')
2025 call assert_fails('setglobal makeprg<<', 'E488:')
2026 call assert_fails('set makeprg@', 'E488:')
2027 call assert_fails('setlocal makeprg@', 'E488:')
2028 call assert_fails('setglobal makeprg@', 'E488:')
2029
2030 " Invalid type
2031 call assert_fails("let &makeprg = ['xxx']", 'E730:')
2032endfunc
2033
2034" Test for setting number option errors
2035func Test_set_number_option_errors()
2036 " :set no{option}
2037 call assert_fails('set notabstop', 'E474:')
2038 call assert_fails('setlocal notabstop', 'E474:')
2039 call assert_fails('setglobal notabstop', 'E474:')
2040
2041 " :set inv{option}
2042 call assert_fails('set invtabstop', 'E474:')
2043 call assert_fails('setlocal invtabstop', 'E474:')
2044 call assert_fails('setglobal invtabstop', 'E474:')
2045
2046 " :set {option}!
2047 call assert_fails('set tabstop!', 'E488:')
2048 call assert_fails('setlocal tabstop!', 'E488:')
2049 call assert_fails('setglobal tabstop!', 'E488:')
2050
2051 " Invalid trailing chars
2052 call assert_fails('set tabstop??', 'E488:')
2053 call assert_fails('setlocal tabstop??', 'E488:')
2054 call assert_fails('setglobal tabstop??', 'E488:')
2055 call assert_fails('set tabstop&&', 'E488:')
2056 call assert_fails('setlocal tabstop&&', 'E488:')
2057 call assert_fails('setglobal tabstop&&', 'E488:')
2058 call assert_fails('set tabstop<<', 'E488:')
2059 call assert_fails('setlocal tabstop<<', 'E488:')
2060 call assert_fails('setglobal tabstop<<', 'E488:')
2061 call assert_fails('set tabstop@', 'E488:')
2062 call assert_fails('setlocal tabstop@', 'E488:')
2063 call assert_fails('setglobal tabstop@', 'E488:')
2064
2065 " Not a number
2066 call assert_fails('set tabstop=', 'E521:')
2067 call assert_fails('setlocal tabstop=', 'E521:')
2068 call assert_fails('setglobal tabstop=', 'E521:')
2069 call assert_fails('set tabstop=x', 'E521:')
2070 call assert_fails('setlocal tabstop=x', 'E521:')
2071 call assert_fails('setglobal tabstop=x', 'E521:')
2072 call assert_fails('set tabstop=1x', 'E521:')
2073 call assert_fails('setlocal tabstop=1x', 'E521:')
2074 call assert_fails('setglobal tabstop=1x', 'E521:')
2075 call assert_fails('set tabstop=-x', 'E521:')
2076 call assert_fails('setlocal tabstop=-x', 'E521:')
2077 call assert_fails('setglobal tabstop=-x', 'E521:')
2078 call assert_fails('set tabstop=0x', 'E521:')
2079 call assert_fails('setlocal tabstop=0x', 'E521:')
2080 call assert_fails('setglobal tabstop=0x', 'E521:')
2081 call assert_fails('set tabstop=0o', 'E521:')
2082 call assert_fails('setlocal tabstop=0o', 'E521:')
2083 call assert_fails('setglobal tabstop=0o', 'E521:')
2084 call assert_fails("let &tabstop = 'x'", 'E521:')
2085 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2086 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2087
2088 " Invalid type
2089 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2090endfunc
2091
2092" Test for setting boolean option errors
2093func Test_set_boolean_option_errors()
2094 " :set {option}=
2095 call assert_fails('set number=', 'E474:')
2096 call assert_fails('setlocal number=', 'E474:')
2097 call assert_fails('setglobal number=', 'E474:')
2098 call assert_fails('set number=1', 'E474:')
2099 call assert_fails('setlocal number=1', 'E474:')
2100 call assert_fails('setglobal number=1', 'E474:')
2101
2102 " :set {option}:
2103 call assert_fails('set number:', 'E474:')
2104 call assert_fails('setlocal number:', 'E474:')
2105 call assert_fails('setglobal number:', 'E474:')
2106 call assert_fails('set number:1', 'E474:')
2107 call assert_fails('setlocal number:1', 'E474:')
2108 call assert_fails('setglobal number:1', 'E474:')
2109
2110 " :set {option}+=
2111 call assert_fails('set number+=1', 'E474:')
2112 call assert_fails('setlocal number+=1', 'E474:')
2113 call assert_fails('setglobal number+=1', 'E474:')
2114
2115 " :set {option}^=
2116 call assert_fails('set number^=1', 'E474:')
2117 call assert_fails('setlocal number^=1', 'E474:')
2118 call assert_fails('setglobal number^=1', 'E474:')
2119
2120 " :set {option}-=
2121 call assert_fails('set number-=1', 'E474:')
2122 call assert_fails('setlocal number-=1', 'E474:')
2123 call assert_fails('setglobal number-=1', 'E474:')
2124
2125 " Invalid trailing chars
2126 call assert_fails('set number!!', 'E488:')
2127 call assert_fails('setlocal number!!', 'E488:')
2128 call assert_fails('setglobal number!!', 'E488:')
2129 call assert_fails('set number??', 'E488:')
2130 call assert_fails('setlocal number??', 'E488:')
2131 call assert_fails('setglobal number??', 'E488:')
2132 call assert_fails('set number&&', 'E488:')
2133 call assert_fails('setlocal number&&', 'E488:')
2134 call assert_fails('setglobal number&&', 'E488:')
2135 call assert_fails('set number<<', 'E488:')
2136 call assert_fails('setlocal number<<', 'E488:')
2137 call assert_fails('setglobal number<<', 'E488:')
2138 call assert_fails('set number@', 'E488:')
2139 call assert_fails('setlocal number@', 'E488:')
2140 call assert_fails('setglobal number@', 'E488:')
2141
2142 " Invalid type
2143 call assert_fails("let &number = 'xxx'", 'E521:')
2144endfunc
2145
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002146" Test for the 'window' option
2147func Test_window_opt()
2148 " Needs only one open widow
2149 %bw!
2150 call setline(1, range(1, 8))
2151 set window=5
2152 exe "normal \<C-F>"
2153 call assert_equal(4, line('w0'))
2154 exe "normal \<C-F>"
2155 call assert_equal(7, line('w0'))
2156 exe "normal \<C-F>"
2157 call assert_equal(8, line('w0'))
2158 exe "normal \<C-B>"
2159 call assert_equal(5, line('w0'))
2160 exe "normal \<C-B>"
2161 call assert_equal(2, line('w0'))
2162 exe "normal \<C-B>"
2163 call assert_equal(1, line('w0'))
2164 set window=1
2165 exe "normal gg\<C-F>"
2166 call assert_equal(2, line('w0'))
2167 exe "normal \<C-F>"
2168 call assert_equal(3, line('w0'))
2169 exe "normal \<C-B>"
2170 call assert_equal(2, line('w0'))
2171 exe "normal \<C-B>"
2172 call assert_equal(1, line('w0'))
2173 enew!
2174 set window&
2175endfunc
2176
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002177" Test for the 'winminheight' option
2178func Test_opt_winminheight()
2179 only!
2180 let &winheight = &lines + 4
2181 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2182 call assert_true(&winminheight <= &lines)
2183 set winminheight&
2184 set winheight&
2185endfunc
2186
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002187func Test_opt_winminheight_term()
2188 CheckRunVimInTerminal
2189
2190 " The tabline should be taken into account.
2191 let lines =<< trim END
2192 set wmh=0 stal=2
2193 below sp | wincmd _
2194 below sp | wincmd _
2195 below sp | wincmd _
2196 below sp
2197 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002198 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002199 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2200 call term_sendkeys(buf, ":set wmh=1\n")
2201 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2202
2203 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002204endfunc
2205
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002206func Test_opt_winminheight_term_tabs()
2207 CheckRunVimInTerminal
2208
2209 " The tabline should be taken into account.
2210 let lines =<< trim END
2211 set wmh=0 stal=2
2212 split
2213 split
2214 split
2215 split
2216 tabnew
2217 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002218 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002219 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2220 call term_sendkeys(buf, ":set wmh=1\n")
2221 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2222
2223 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002224endfunc
2225
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002226" Test for the 'winminwidth' option
2227func Test_opt_winminwidth()
2228 only!
2229 let &winwidth = &columns + 4
2230 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2231 call assert_true(&winminwidth <= &columns)
2232 set winminwidth&
2233 set winwidth&
2234endfunc
2235
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002236" Test for setting option value containing spaces with isfname+=32
2237func Test_isfname_with_options()
2238 set isfname+=32
2239 setlocal keywordprg=:term\ help.exe
2240 call assert_equal(':term help.exe', &keywordprg)
2241 set isfname&
2242 setlocal keywordprg&
2243endfunc
2244
Bram Moolenaar74667062020-12-28 15:41:41 +01002245" Test that resetting laststatus does change scroll option
2246func Test_opt_reset_scroll()
2247 CheckRunVimInTerminal
2248 let vimrc =<< trim [CODE]
2249 set scroll=2
2250 set laststatus=2
2251 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002252 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002253 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2254 call term_sendkeys(buf, ":verbose set scroll?\n")
2255 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2256 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002257
2258 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002259 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002260endfunc
2261
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002262" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2263func Test_VIM_POSIX()
2264 let saved_VIM_POSIX = getenv("VIM_POSIX")
2265
2266 call setenv('VIM_POSIX', "1")
2267 let after =<< trim [CODE]
2268 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2269 qall
2270 [CODE]
2271 if RunVim([], after, '')
glepnir4ade6682025-07-03 20:41:23 +02002272 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;~',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002273 \ 'AS'], readfile('X_VIM_POSIX'))
2274 endif
2275
2276 call setenv('VIM_POSIX', v:null)
2277 let after =<< trim [CODE]
2278 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2279 qall
2280 [CODE]
2281 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002282 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002283 \ 'S'], readfile('X_VIM_POSIX'))
2284 endif
2285
2286 call delete('X_VIM_POSIX')
2287 call setenv('VIM_POSIX', saved_VIM_POSIX)
2288endfunc
2289
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002290" Test for setting an option to a Vi or Vim default
2291func Test_opt_default()
2292 set formatoptions&vi
2293 call assert_equal('vt', &formatoptions)
2294 set formatoptions&vim
2295 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002296
2297 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2298 set fencs=latin1
2299 set fencs&
2300 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2301 set fencs=latin1
2302 set all&
2303 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002304endfunc
2305
2306" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002307func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002308 %bw!
2309 let ht = &lines
2310 set cmdheight=9999
2311 call assert_equal(1, winheight(0))
2312 call assert_equal(ht - 1, &cmdheight)
2313 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002314
2315 " The status line should be taken into account.
2316 set laststatus=2
2317 set cmdheight=9999
2318 call assert_equal(ht - 2, &cmdheight)
2319 set cmdheight& laststatus&
2320
2321 " The tabline should be taken into account only non-GUI.
2322 set showtabline=2
2323 set cmdheight=9999
2324 if has('gui_running')
2325 call assert_equal(ht - 1, &cmdheight)
2326 else
2327 call assert_equal(ht - 2, &cmdheight)
2328 endif
2329 set cmdheight& showtabline&
2330
2331 " The 'winminheight' should be taken into account.
2332 set winheight=3 winminheight=3
2333 split
2334 set cmdheight=9999
2335 call assert_equal(ht - 8, &cmdheight)
2336 %bw!
2337 set cmdheight& winminheight& winheight&
2338
2339 " Only the windows in the current tabpage are taken into account.
2340 set winheight=3 winminheight=3 showtabline=0
2341 split
2342 tabnew
2343 set cmdheight=9999
2344 call assert_equal(ht - 3, &cmdheight)
2345 %bw!
2346 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002347endfunc
2348
Dominique Pelle923dce22021-11-21 11:36:04 +00002349" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002350func Test_opt_control_char()
2351 set wildchar=^v
2352 call assert_equal("\<C-V>", nr2char(&wildchar))
2353 set wildcharm=^r
2354 call assert_equal("\<C-R>", nr2char(&wildcharm))
2355 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2356 set wildchar& wildcharm&
2357endfunc
2358
2359" Test for the 'errorbells' option
2360func Test_opt_errorbells()
2361 set errorbells
2362 call assert_beeps('s/a1b2/x1y2/')
2363 set noerrorbells
2364endfunc
2365
Dominique Pelle042414f2021-07-12 21:43:19 +02002366func Test_opt_scrolljump()
2367 help
2368 resize 10
2369
2370 " Test with positive 'scrolljump'.
2371 set scrolljump=2
2372 norm! Lj
2373 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2374 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2375 \ winsaveview())
2376
2377 " Test with negative 'scrolljump' (percentage of window height).
2378 set scrolljump=-40
2379 norm! ggLj
2380 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2381 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2382 \ winsaveview())
2383
2384 set scrolljump&
2385 bw
2386endfunc
2387
Bakudankun29f3a452021-12-11 12:28:08 +00002388" Test for the 'cdhome' option
2389func Test_opt_cdhome()
2390 if has('unix') || has('vms')
2391 throw 'Skipped: only works on non-Unix'
2392 endif
2393
2394 set cdhome&
2395 call assert_equal(0, &cdhome)
2396 set cdhome
2397
2398 " This paragraph is copied from Test_cd_no_arg().
2399 let path = getcwd()
2400 cd
2401 call assert_equal($HOME, getcwd())
2402 call assert_notequal(path, getcwd())
2403 exe 'cd ' .. fnameescape(path)
2404 call assert_equal(path, getcwd())
2405
2406 set cdhome&
2407endfunc
2408
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002409func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002410 CheckOption termguicolors
2411
2412 " Test default option completion
2413 set wildoptions=
2414 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2415 call assert_equal('"set termguicolors', @:)
2416
2417 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2418 call assert_equal('"set notermguicolors', @:)
2419
2420 " Test fuzzy option completion
2421 set wildoptions=fuzzy
2422 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2423 call assert_equal('"set termguicolors termencoding', @:)
2424
2425 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2426 call assert_equal('"set notermguicolors', @:)
2427
2428 set wildoptions=
2429endfunc
2430
Sean Dewar39c46b42022-05-12 17:44:29 +01002431func Test_switchbuf_reset()
2432 set switchbuf=useopen
2433 sblast
2434 call assert_equal(1, winnr('$'))
2435 set all&
2436 call assert_equal('', &switchbuf)
2437 sblast
2438 call assert_equal(2, winnr('$'))
2439 only!
2440endfunc
2441
zeertzjqfcba86c2022-09-22 13:57:32 +01002442" :set empty string for global 'keywordprg' falls back to ":help"
2443func Test_keywordprg_empty()
2444 let k = &keywordprg
2445 set keywordprg=man
2446 call assert_equal('man', &keywordprg)
2447 set keywordprg=
2448 call assert_equal(':help', &keywordprg)
2449 set keywordprg=man
2450 call assert_equal('man', &keywordprg)
2451 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2452 let &keywordprg = k
2453endfunc
2454
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002455" check that the very first buffer created does not have 'endoffile' set
2456func Test_endoffile_default()
2457 let after =<< trim [CODE]
2458 call writefile([execute('set eof?')], 'Xtestout')
2459 qall!
2460 [CODE]
2461 if RunVim([], after, '')
2462 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2463 endif
2464 call delete('Xtestout')
2465endfunc
2466
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002467" Test for setting the 'lines' and 'columns' options to a minimum value
2468func Test_set_min_lines_columns()
2469 let save_lines = &lines
2470 let save_columns = &columns
2471
2472 let after =<< trim END
2473 set nomore
2474 let msg = []
2475 let v:errmsg = ''
2476 silent! let &columns=0
2477 call add(msg, v:errmsg)
2478 silent! set columns=0
2479 call add(msg, v:errmsg)
2480 silent! call setbufvar('', '&columns', 0)
2481 call add(msg, v:errmsg)
2482 "call writefile(msg, 'XResultsetminlines')
2483 silent! let &lines=0
2484 call add(msg, v:errmsg)
2485 silent! set lines=0
2486 call add(msg, v:errmsg)
2487 silent! call setbufvar('', '&lines', 0)
2488 call add(msg, v:errmsg)
2489 call writefile(msg, 'XResultsetminlines')
2490 qall!
2491 END
2492 if RunVim([], after, '')
2493 call assert_equal(['E594: Need at least 12 columns',
2494 \ 'E594: Need at least 12 columns: columns=0',
2495 \ 'E594: Need at least 12 columns',
2496 \ 'E593: Need at least 2 lines',
2497 \ 'E593: Need at least 2 lines: lines=0',
2498 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2499 endif
2500
2501 call delete('XResultsetminlines')
2502 let &lines = save_lines
2503 let &columns = save_columns
2504endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002505
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002506" Test for reverting a string option value if the new value is invalid.
2507func Test_string_option_revert_on_failure()
2508 new
2509 let optlist = [
2510 \ ['ambiwidth', 'double', 'a123'],
2511 \ ['background', 'dark', 'a123'],
2512 \ ['backspace', 'eol', 'a123'],
2513 \ ['backupcopy', 'no', 'a123'],
2514 \ ['belloff', 'showmatch', 'a123'],
2515 \ ['breakindentopt', 'min:10', 'list'],
2516 \ ['bufhidden', 'wipe', 'a123'],
2517 \ ['buftype', 'nowrite', 'a123'],
2518 \ ['casemap', 'keepascii', 'a123'],
2519 \ ['cedit', "\<C-Y>", 'z'],
2520 \ ['colorcolumn', '10', 'z'],
2521 \ ['commentstring', '#%s', 'a123'],
2522 \ ['complete', '.,t', 'a'],
2523 \ ['completefunc', 'MyCmplFunc', '1a-'],
2524 \ ['completeopt', 'popup', 'a123'],
2525 \ ['completepopup', 'width:20', 'border'],
2526 \ ['concealcursor', 'v', 'xyz'],
glepnir4ade6682025-07-03 20:41:23 +02002527 \ ['cpoptions', 'HJ', 'Q'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002528 \ ['cryptmethod', 'zip', 'a123'],
2529 \ ['cursorlineopt', 'screenline', 'a123'],
2530 \ ['debug', 'throw', 'a123'],
2531 \ ['diffopt', 'iwhite', 'a123'],
2532 \ ['display', 'uhex', 'a123'],
2533 \ ['eadirection', 'hor', 'a123'],
2534 \ ['encoding', 'utf-8', 'a123'],
2535 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002536 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002537 \ ['fileencoding', 'utf-8', 'a123,'],
2538 \ ['fileformat', 'mac', 'a123'],
2539 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002540 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002541 \ ['fillchars', 'diff:~', 'a123'],
2542 \ ['foldclose', 'all', 'a123'],
2543 \ ['foldmarker', '[[[,]]]', '[[['],
2544 \ ['foldmethod', 'marker', 'a123'],
2545 \ ['foldopen', 'percent', 'a123'],
2546 \ ['formatoptions', 'an', '*'],
2547 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2548 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002549 \ ['highlight', '!:CursorColumn', '8:'],
2550 \ ['keymodel', 'stopsel', 'a123'],
2551 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2552 \ ['lispoptions', 'expr:1', 'a123'],
2553 \ ['listchars', 'tab:->', 'tab:'],
2554 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002555 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002556 \ ['mkspellmem', '100000,1000,100', '100000'],
2557 \ ['mouse', 'nvi', 'z'],
2558 \ ['mousemodel', 'extend', 'a123'],
2559 \ ['nrformats', 'alpha', 'a123'],
2560 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2561 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2562 \ ['previewpopup', 'width:20', 'a123'],
2563 \ ['printoptions', 'paper:A4', 'a123:'],
2564 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2565 \ ['rulerformat', '%l', '%['],
2566 \ ['scrollopt', 'hor,jump', 'a123'],
2567 \ ['selection', 'exclusive', 'a123'],
2568 \ ['selectmode', 'cmd', 'a123'],
2569 \ ['sessionoptions', 'options', 'a123'],
2570 \ ['shortmess', 'w', '2'],
2571 \ ['showbreak', '>>', "\x01"],
2572 \ ['showcmdloc', 'statusline', 'a123'],
2573 \ ['signcolumn', 'no', 'a123'],
2574 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2575 \ ['spellfile', 'MySpell.en.add', "\x01"],
2576 \ ['spelllang', 'en', "#"],
2577 \ ['spelloptions', 'camel', 'a123'],
2578 \ ['spellsuggest', 'double', 'a123'],
2579 \ ['splitkeep', 'topline', 'a123'],
2580 \ ['statusline', '%f', '%['],
2581 \ ['swapsync', 'sync', 'a123'],
2582 \ ['switchbuf', 'usetab', 'a123'],
2583 \ ['syntax', 'abc', 'a^b'],
2584 \ ['tabline', '%f', '%['],
2585 \ ['tagcase', 'ignore', 'a123'],
2586 \ ['tagfunc', 'MyTagFunc', '1a-'],
2587 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2588 \ ['viewoptions', 'options', 'a123'],
2589 \ ['virtualedit', 'onemore', 'a123'],
2590 \ ['whichwrap', '<,>', '{,}'],
2591 \ ['wildmode', 'list', 'a123'],
2592 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002593 \ ]
2594 if has('gui')
2595 call add(optlist, ['browsedir', 'buffer', 'a123'])
2596 endif
2597 if has('clipboard_working')
2598 call add(optlist, ['clipboard', 'unnamed', 'a123'])
Foxe Chenb90c2392025-06-27 21:10:35 +02002599 call add(optlist, ['clipmethod', 'wayland', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002600 endif
2601 if has('win32')
2602 call add(optlist, ['completeslash', 'slash', 'a123'])
2603 endif
2604 if has('cscope')
2605 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2606 endif
2607 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002608 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2609 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2610 endif
2611 if has('keymap')
2612 call add(optlist, ['keymap', 'greek', '[]'])
2613 endif
2614 if has('mouseshape')
2615 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2616 endif
2617 if has('win32') && has('gui')
2618 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2619 endif
2620 if has('rightleft')
2621 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2622 endif
2623 if has('terminal')
2624 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2625 call add(optlist, ['termwinsize', '24x80', '100'])
2626 endif
2627 if has('win32') && has('terminal')
2628 call add(optlist, ['termwintype', 'winpty', 'a123'])
2629 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002630 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002631 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002632 endif
2633 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002634 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2635 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002636 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002637 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2638 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002639 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002640 call add(optlist, ['varsofttabstop', '12', 'a123'])
2641 call add(optlist, ['vartabstop', '4,20', '4,'])
2642 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002643 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002644 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002645 endif
2646 for opt in optlist
2647 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002648 try
2649 exe $"let &{opt[0]} = '{opt[1]}'"
2650 catch
2651 call assert_report($"Caught {v:exception} with {opt->string()}")
2652 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002653 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2654 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2655 exe $"let &{opt[0]} = save_opt"
2656 endfor
2657 bw!
2658endfunc
2659
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002660func Test_set_option_window_global_local()
2661 new Xbuffer1
2662 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2663 setlocal scrolloff=2
2664 setglobal scrolloff=3
2665 setl modified
2666 " A new buffer has its own window-local options
2667 hide enew
2668 call assert_equal(-1, &l:scrolloff)
2669 call assert_equal(3, &g:scrolloff)
2670 " A new window opened with its own buffer-local options
2671 new
2672 call assert_equal(-1, &l:scrolloff)
2673 call assert_equal(3, &g:scrolloff)
2674 " Re-open Xbuffer1 and it should use
2675 " the previous set window-local options
2676 b Xbuffer1
2677 call assert_equal(2, &l:scrolloff)
2678 call assert_equal(3, &g:scrolloff)
2679 bw!
2680 bw!
2681 let &g:scrolloff = _gso
2682endfunc
2683
2684func GetGlobalLocalWindowOptions()
2685 new
2686 sil! r $VIMRUNTIME/doc/options.txt
2687 " Filter for global or local to window
2688 v/^'.*'.*\n.*global or local to window |global-local/d
2689 " get option value and type
2690 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2691 sil %s/empty/""/g
2692 " split the result
2693 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2694 bw!
2695 return result
2696endfunc
2697
2698func Test_set_option_window_global_local_all()
2699 new Xbuffer2
2700
2701 let optionlist = GetGlobalLocalWindowOptions()
2702 for [opt, type, default] in optionlist
2703 let _old = eval('&g:' .. opt)
2704 if type == 'string'
2705 if opt == 'fillchars'
2706 exe 'setl ' .. opt .. '=vert:+'
2707 exe 'setg ' .. opt .. '=vert:+,fold:+'
2708 elseif opt == 'listchars'
2709 exe 'setl ' .. opt .. '=tab:>>'
2710 exe 'setg ' .. opt .. '=tab:++'
2711 elseif opt == 'virtualedit'
2712 exe 'setl ' .. opt .. '=all'
2713 exe 'setg ' .. opt .. '=block'
2714 else
2715 exe 'setl ' .. opt .. '=Local'
2716 exe 'setg ' .. opt .. '=Global'
2717 endif
2718 elseif type == 'number'
2719 exe 'setl ' .. opt .. '=5'
2720 exe 'setg ' .. opt .. '=10'
2721 endif
2722 setl modified
2723 hide enew
2724 if type == 'string'
2725 call assert_equal('', eval('&l:' .. opt))
2726 if opt == 'fillchars'
2727 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2728 elseif opt == 'listchars'
2729 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2730 elseif opt == 'virtualedit'
2731 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2732 else
2733 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2734 endif
2735 elseif type == 'number'
2736 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2737 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2738 endif
2739 bw!
2740 exe 'let &g:' .. opt .. '=' .. default
2741 endfor
2742 bw!
2743endfunc
2744
Christian Brabandt757593c2023-08-22 21:44:10 +02002745func Test_paste_depending_options()
2746 " setting the paste option, resets all dependent options
2747 " and will be reported correctly using :verbose set <option>?
2748 let lines =<< trim [CODE]
2749 " set paste test
2750 set autoindent
2751 set expandtab
2752 " disabled, because depends on compiled feature set
2753 " set hkmap
2754 " set revins
2755 " set varsofttabstop=8,32,8
2756 set ruler
2757 set showmatch
2758 set smarttab
2759 set softtabstop=4
2760 set textwidth=80
2761 set wrapmargin=10
2762
2763 source Xvimrc_paste2
2764
2765 redir > Xoutput_paste
2766 verbose set expandtab?
2767 verbose setg expandtab?
2768 verbose setl expandtab?
2769 redir END
2770
2771 qall!
2772 [CODE]
2773
2774 call writefile(lines, 'Xvimrc_paste', 'D')
2775 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2776 if !RunVim([], lines, '--clean')
2777 return
2778 endif
2779
2780 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2781 call assert_equal('noexpandtab', result[0])
2782 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2783 call assert_equal('noexpandtab', result[2])
2784 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2785 call assert_equal('noexpandtab', result[4])
2786 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2787
2788 call delete('Xoutput_paste')
2789endfunc
2790
2791func Test_binary_depending_options()
2792 " setting the paste option, resets all dependent options
2793 " and will be reported correctly using :verbose set <option>?
2794 let lines =<< trim [CODE]
2795 " set binary test
2796 set expandtab
2797
2798 source Xvimrc_bin2
2799
2800 redir > Xoutput_bin
2801 verbose set expandtab?
2802 verbose setg expandtab?
2803 verbose setl expandtab?
2804 redir END
2805
2806 qall!
2807 [CODE]
2808
2809 call writefile(lines, 'Xvimrc_bin', 'D')
2810 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2811 if !RunVim([], lines, '--clean')
2812 return
2813 endif
2814
2815 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2816 call assert_equal('noexpandtab', result[0])
2817 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2818 call assert_equal('noexpandtab', result[2])
2819 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2820 call assert_equal('noexpandtab', result[4])
2821 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2822
2823 call delete('Xoutput_bin')
2824endfunc
2825
Gregory Anders3695d0e2023-09-29 20:17:20 +02002826func Test_set_keyprotocol()
2827 CheckNotGui
2828
2829 let term = &term
2830 set term=ansi
2831 call assert_equal('', &t_TI)
2832
2833 " Setting 'keyprotocol' should affect terminal codes without needing to
2834 " reset 'term'
2835 set keyprotocol+=ansi:kitty
2836 call assert_equal("\<Esc>[=1;1u", &t_TI)
2837 let &term = term
2838endfunc
2839
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002840func Test_set_wrap()
2841 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2842 " cursor position.
2843 set wrap smoothscroll scrolloff=5
2844
2845 call setline(1, ['', 'aaaa'->repeat(500)])
2846 20 split
2847 20 vsplit
2848 norm 2G$
2849 redraw
2850 set nowrap
2851 call assert_equal(2, winline())
2852
2853 set wrap& smoothscroll& scrolloff&
2854endfunc
2855
zeertzjqcd3a13e2024-02-24 16:51:32 +01002856func Test_delcombine()
2857 new
2858 set backspace=indent,eol,start
2859
2860 set delcombine
2861 call setline(1, 'β̳̈:β̳̈')
2862 normal! 0x
2863 call assert_equal('β̈:β̳̈', getline(1))
2864 exe "normal! A\<BS>"
2865 call assert_equal('β̈:β̈', getline(1))
2866 normal! 0x
2867 call assert_equal('β:β̈', getline(1))
2868 exe "normal! A\<BS>"
2869 call assert_equal('β:β', getline(1))
2870 normal! 0x
2871 call assert_equal(':β', getline(1))
2872 exe "normal! A\<BS>"
2873 call assert_equal(':', getline(1))
2874
2875 set nodelcombine
2876 call setline(1, 'β̳̈:β̳̈')
2877 normal! 0x
2878 call assert_equal(':β̳̈', getline(1))
2879 exe "normal! A\<BS>"
2880 call assert_equal(':', getline(1))
2881
2882 set backspace& delcombine&
2883 bwipe!
2884endfunc
2885
Milly484face2024-10-12 11:26:06 +02002886" Should not raise errors when set missing-options.
2887func Test_set_missing_options()
2888 set autoprint
2889 set beautify
2890 set flash
2891 set graphic
2892 set hardtabs=8
2893 set mesg
2894 set novice
2895 set open
2896 set optimize
2897 set redraw
2898 set slowopen
2899 set sourceany
2900 set w300=23
2901 set w1200=23
2902 set w9600=23
2903endfunc
2904
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002905func Test_default_keyprotocol()
2906 " default value of keyprotocol
2907 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2908endfunc
2909
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002910" vim: shiftwidth=2 sts=2 expandtab