blob: d8ad3f210bf5d3916a1d456d107d37a3c12e5579 [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Bram Moolenaarb00ef052020-09-12 14:53:53 +02003source shared.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02005source view_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02006
Milly6eca04e2024-10-21 22:20:51 +02007scriptencoding utf-8
8
Bram Moolenaar1e115362019-01-09 23:01:02 +01009func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020010 set whichwrap=b,s
11 call assert_equal('b,s', &whichwrap)
12
13 set whichwrap+=h,l
14 call assert_equal('b,s,h,l', &whichwrap)
15
16 set whichwrap+=h,l
17 call assert_equal('b,s,h,l', &whichwrap)
18
19 set whichwrap+=h,l
20 call assert_equal('b,s,h,l', &whichwrap)
21
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010022 set whichwrap=h,h
23 call assert_equal('h', &whichwrap)
24
25 set whichwrap=h,h,h
26 call assert_equal('h', &whichwrap)
27
Bram Moolenaar004a6782020-04-11 17:09:31 +020028 " For compatibility with Vim 3.0 and before, number values are also
29 " supported for 'whichwrap'
30 set whichwrap=1
31 call assert_equal('b', &whichwrap)
32 set whichwrap=2
33 call assert_equal('s', &whichwrap)
34 set whichwrap=4
35 call assert_equal('h,l', &whichwrap)
36 set whichwrap=8
37 call assert_equal('<,>', &whichwrap)
38 set whichwrap=16
39 call assert_equal('[,]', &whichwrap)
40 set whichwrap=31
41 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
42
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020043 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010044endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020045
Bram Moolenaar1e115362019-01-09 23:01:02 +010046func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010047 " This used to cause Vim to access uninitialized memory.
48 set isfname=
49 call assert_equal("~X", expand("~X"))
50 set isfname&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000051 " Test for setting 'isfname' to an unsupported character
52 let save_isfname = &isfname
53 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
54 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010055endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010056
zeertzjq0519ce02022-05-09 12:16:19 +010057" Test for getting the value of 'pastetoggle'
58func Test_pastetoggle()
59 " character with K_SPECIAL byte
60 let &pastetoggle = '…'
61 call assert_equal('…', &pastetoggle)
62 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
63
64 " modified character with K_SPECIAL byte
65 let &pastetoggle = '<M-…>'
66 call assert_equal('<M-…>', &pastetoggle)
67 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
68
69 " illegal bytes
70 let str = ":\x7f:\x80:\x90:\xd0:"
71 let &pastetoggle = str
72 call assert_equal(str, &pastetoggle)
73 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010074
zeertzjq0519ce02022-05-09 12:16:19 +010075 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010076 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010077endfunc
78
Bram Moolenaar1e115362019-01-09 23:01:02 +010079func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010080 " Empty 'wildchar' used to access invalid memory.
81 call assert_fails('set wildchar=', 'E521:')
82 call assert_fails('set wildchar=abc', 'E521:')
83 set wildchar=<Esc>
84 let a=execute('set wildchar?')
85 call assert_equal("\n wildchar=<Esc>", a)
86 set wildchar=27
87 let a=execute('set wildchar?')
88 call assert_equal("\n wildchar=<Esc>", a)
89 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010090endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010091
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020092func Test_wildoptions()
93 set wildoptions=
94 set wildoptions+=tagfile
95 set wildoptions+=tagfile
96 call assert_equal('tagfile', &wildoptions)
97endfunc
98
Bram Moolenaar6b915c02020-01-18 15:53:19 +010099func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200100 let caught = 'ok'
101 try
102 options
103 catch
104 let caught = v:throwpoint . "\n" . v:exception
105 endtry
106 call assert_equal('ok', caught)
107
Bram Moolenaare0b59492019-05-21 20:54:45 +0200108 " Check if the option-window is opened horizontally.
109 wincmd j
110 call assert_notequal('option-window', bufname(''))
111 wincmd k
112 call assert_equal('option-window', bufname(''))
113 " close option-window
114 close
115
116 " Open the option-window vertically.
117 vert options
118 " Check if the option-window is opened vertically.
119 wincmd l
120 call assert_notequal('option-window', bufname(''))
121 wincmd h
122 call assert_equal('option-window', bufname(''))
123 " close option-window
124 close
125
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200126 " Open the option-window at the top.
127 set splitbelow
128 topleft options
129 call assert_equal(1, winnr())
130 close
131
132 " Open the option-window at the bottom.
133 set nosplitbelow
134 botright options
135 call assert_equal(winnr('$'), winnr())
136 close
137 set splitbelow&
138
Bram Moolenaare0b59492019-05-21 20:54:45 +0200139 " Open the option-window in a new tab.
140 tab options
141 " Check if the option-window is opened in a tab.
142 normal gT
143 call assert_notequal('option-window', bufname(''))
144 normal gt
145 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200146 " close option-window
147 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200148
149 " Open the options window browse
150 if has('browse')
151 browse set
152 call assert_equal('option-window', bufname(''))
153 close
154 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200156
Bram Moolenaar1e115362019-01-09 23:01:02 +0100157func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200158 " Test that changing 'path' keeps two commas.
159 set path=foo,,bar
160 set path-=bar
161 set path+=bar
162 call assert_equal('foo,,bar', &path)
163
164 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100165endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200166
Dominique Pellef645ee42021-12-05 13:21:18 +0000167func Test_path_too_long()
168 exe 'set path=' .. repeat('x', 10000)
169 call assert_fails('find x', 'E854:')
170 set path&
171endfunc
172
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200173func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200174 CheckFeature signs
175 call assert_equal("auto", &signcolumn)
176 set signcolumn=yes
177 set signcolumn=no
178 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200179endfunc
180
Bram Moolenaard0b51382016-11-04 15:23:45 +0100181func Test_filetype_valid()
182 set ft=valid_name
183 call assert_equal("valid_name", &filetype)
184 set ft=valid-name
185 call assert_equal("valid-name", &filetype)
186
187 call assert_fails(":set ft=wrong;name", "E474:")
188 call assert_fails(":set ft=wrong\\\\name", "E474:")
189 call assert_fails(":set ft=wrong\\|name", "E474:")
190 call assert_fails(":set ft=wrong/name", "E474:")
191 call assert_fails(":set ft=wrong\\\nname", "E474:")
192 call assert_equal("valid-name", &filetype)
193
194 exe "set ft=trunc\x00name"
195 call assert_equal("trunc", &filetype)
196endfunc
197
198func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200199 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100200 set syn=valid_name
201 call assert_equal("valid_name", &syntax)
202 set syn=valid-name
203 call assert_equal("valid-name", &syntax)
204
205 call assert_fails(":set syn=wrong;name", "E474:")
206 call assert_fails(":set syn=wrong\\\\name", "E474:")
207 call assert_fails(":set syn=wrong\\|name", "E474:")
208 call assert_fails(":set syn=wrong/name", "E474:")
209 call assert_fails(":set syn=wrong\\\nname", "E474:")
210 call assert_equal("valid-name", &syntax)
211
212 exe "set syn=trunc\x00name"
213 call assert_equal("trunc", &syntax)
214endfunc
215
216func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200217 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100218 call assert_fails(":set kmp=valid_name", "E544:")
219 call assert_fails(":set kmp=valid_name", "valid_name")
220 call assert_fails(":set kmp=valid-name", "E544:")
221 call assert_fails(":set kmp=valid-name", "valid-name")
222
223 call assert_fails(":set kmp=wrong;name", "E474:")
224 call assert_fails(":set kmp=wrong\\\\name", "E474:")
225 call assert_fails(":set kmp=wrong\\|name", "E474:")
226 call assert_fails(":set kmp=wrong/name", "E474:")
227 call assert_fails(":set kmp=wrong\\\nname", "E474:")
228
229 call assert_fails(":set kmp=trunc\x00name", "E544:")
230 call assert_fails(":set kmp=trunc\x00name", "trunc")
231endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100232
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200233func Test_wildchar_valid()
234 call assert_fails("set wildchar=<CR>", "E474:")
235 call assert_fails("set wildcharm=<C-C>", "E474:")
236endfunc
237
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100238func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100239 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100240 exe 'set ' . a:name . '=/usr/share/dict/words'
241 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
242 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
243 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
244 exe 'set ' . a:name . '=/usr/share/dict\ words'
245 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100246
247 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100248 call assert_fails("set " . a:name . "=/not&there", "E474:")
249 call assert_fails("set " . a:name . "=/not>there", "E474:")
250 call assert_fails("set " . a:name . "=/not.*there", "E474:")
251endfunc
252
Bram Moolenaar60629d62017-02-23 18:08:56 +0100253func Test_cinkeys()
254 " This used to cause invalid memory access
255 set cindent cinkeys=0
256 norm a
257 set cindent& cinkeys&
258endfunc
259
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100260func Test_dictionary()
261 call Check_dir_option('dictionary')
262endfunc
263
264func Test_thesaurus()
265 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100266endfun
267
Bram Moolenaar226c5342017-02-17 14:53:15 +0100268func Test_complete()
269 " Trailing single backslash used to cause invalid memory access.
270 set complete=s\
271 new
272 call feedkeys("i\<C-N>\<Esc>", 'xt')
273 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200274 call assert_fails('set complete=ix', 'E535:')
Girish Palyacbe53192025-04-14 22:13:15 +0200275 call assert_fails('set complete=x', 'E539:')
276 call assert_fails('set complete=..', 'E535:')
277 set complete=.,w,b,u,k,\ s,i,d,],t,U,f,o
Girish Palya0ac1eb32025-04-16 20:18:33 +0200278 call assert_fails('set complete=i^-10', 'E535:')
279 call assert_fails('set complete=i^x', 'E535:')
280 call assert_fails('set complete=k^2,t^-1,s^', 'E535')
281 call assert_fails('set complete=t^-1', 'E535')
282 call assert_fails('set complete=kfoo^foo2', 'E535')
283 call assert_fails('set complete=kfoo^', 'E535')
284 call assert_fails('set complete=.^', 'E535')
285 set complete=.,w,b,u,k,s,i,d,],t,U,f,o
Girish Palyacbe53192025-04-14 22:13:15 +0200286 set complete=.
Girish Palya0ac1eb32025-04-16 20:18:33 +0200287 set complete=.^10,t^0
Girish Palyacbe53192025-04-14 22:13:15 +0200288 set complete+=ffuncref('foo'\\,\ [10])
Girish Palya0ac1eb32025-04-16 20:18:33 +0200289 set complete=ffuncref('foo'\\,\ [10])^10
Girish Palyacbe53192025-04-14 22:13:15 +0200290 set complete&
Girish Palya0ac1eb32025-04-16 20:18:33 +0200291 set complete+=ffunction('g:foo'\\,\ [10\\,\ 20])
Bram Moolenaar226c5342017-02-17 14:53:15 +0100292 set complete&
293endfun
294
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100295func Test_set_completion()
296 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
297 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
298
Bram Moolenaar297610b2019-12-27 17:20:55 +0100299 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
300 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
301
302 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
303 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
304
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100305 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
306 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100307 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100308 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100309
310 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100311 call assert_equal('"set invdiff invdigraph', @:)
312
313 " Expanding "set noinv" does nothing.
314 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
315 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100316
317 " Expand abbreviation of options.
318 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100319 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100320
321 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200322 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
323 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100324
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200325 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
326 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100327
328 " Expand key codes.
329 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
330 call assert_equal('"set <Help> <Home>', @:)
Yee Cheng Chin7d8e7df2025-03-27 17:43:41 +0100331 " <BackSpace> (alt name) and <BS> should both show up in auto-complete
332 call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx')
333 call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:)
334 " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here
335 " nor show up as duplicates
336 call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx')
337 call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100338
339 " Expand terminal options.
340 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200341 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200342 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100343
344 " Expand directories.
345 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
346 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200347 call assert_notmatch(' ./summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200348 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100349
350 " Expand files and directories.
351 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200352 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100353
354 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
355 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200356
357 " Expand files with spaces/commas in them. Make sure we delimit correctly.
358 "
359 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
360 " spaces requiring double escape, and commas need a single escape.
361 " 'dictionary' is a normal comma-separated option where only commas act as
362 " delimiters, and both space/comma need one single escape.
363 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
364 defer delete('Xfoo Xspace.txt')
365 defer delete('Xsp_dummy')
366 defer delete('Xbar,Xcomma.txt')
367 defer delete('Xcom_dummy')
368 call writefile([], 'Xfoo Xspace.txt')
369 call writefile([], 'Xsp_dummy')
370 call writefile([], 'Xbar,Xcomma.txt')
371 call writefile([], 'Xcom_dummy')
372
373 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
374 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
375 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
376 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
377 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
378 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
379
380 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
381 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
382 if has('win32')
383 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
384 " means we treat it as one file name.
385 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
386 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
387 else
388 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
389 " to split into a separate file name. You need '\\,' to escape the comma
390 " as part of the file name.
391 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
392 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
393
394 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
395 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
396 endif
397 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
398 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
399 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200400
401 " Expanding the option names
402 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
403 call assert_equal('"set all', @:)
404
405 " Expanding a second set of option names
406 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
407 call assert_equal('"set wrapscan all', @:)
408
409 " Expanding a special keycode
410 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
411 call assert_equal('"set <Home>', @:)
412
413 " Expanding an invalid special keycode
414 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
415 call assert_equal("\"set <abcd>\<Tab>", @:)
416
417 " Expanding a terminal keycode
418 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
419 call assert_equal("\"set t_AB", @:)
420
421 " Expanding an invalid option name
422 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal("\"set abcde=\<Tab>", @:)
424
425 " Expanding after a = for a boolean option
426 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
427 call assert_equal("\"set wrapscan=\<Tab>", @:)
428
429 " Expanding a numeric option
430 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
431 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
432
433 " Expanding a non-boolean option
434 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
435 call assert_equal("\"set invtabstop=", @:)
436
437 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200438 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
439 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
440 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
441 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200442
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200443 " Expanding value for 'key' is disallowed
444 if exists('+key')
445 set key=abcd
446 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
447 call assert_equal('"set key=', @:)
448 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
449 call assert_equal('"set key-=', @:)
450 set key=
451 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100452
453 " Expand values for 'filetype'
454 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
455 call assert_equal('"set filetype=sshdconfig', @:)
456 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
457 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200458
459 " Expand values for 'syntax'
460 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
461 call assert_equal('"set syntax=sshdconfig', @:)
462 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
463 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100464
465 if has('keymap')
466 " Expand values for 'keymap'
467 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
468 call assert_equal('"set keymap=accents', @:)
469 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
470 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
471 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100472endfunc
473
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200474" Test handling of expanding individual string option values
475func Test_set_completion_string_values()
476 "
477 " Test basic enum string options that have well-defined enum names
478 "
479
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200480 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
481 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
482 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200483
484 " Test that if a value is set, it will populate the results, but only if
485 " typed value is empty.
486 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200487 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
488 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200489 " If the set value is part of the enum list, it will show as the first
490 " result with no duplicate.
491 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200492 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200493 " If empty value, will just show the normal list without an empty item
494 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200495 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200496 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200497 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200498
499 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200500 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200501 " Also test the positioning of the expansion is correct
502 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
503 call assert_equal('"set display=truncate,lastline', @:)
504 set display&
505
506 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200507 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200508
509 " Test the other simple options to make sure they have basic auto-complete,
510 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200511 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200512 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Luca Saccarola959ef612024-12-01 16:25:53 +0100513 call assert_equal('indent,eol,start', getcompletion('set backspace=', 'cmdline')[0])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200514 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
515 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
516 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200517 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200518 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200519 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200520 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
521 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
522 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200523 if exists('+clipboard')
524 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
525 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200526 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
527 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
zeertzjq53d59ec2025-03-07 19:09:09 +0100528 call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200529 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200530 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200531 endif
532 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200533 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200534 endif
535 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200536 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200537 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200538 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
539 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
540 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200541 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200542 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200543 endif
544 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
547 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200548 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200549 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200550 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
551 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
552 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200553 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200554 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200555 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200556 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200557 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200558 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
559 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
560 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200561 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200562 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200563 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200564 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200565 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200566 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200567 endif
568 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200569 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200570 endif
571 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200572 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200573 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200574 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
575 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
576 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
577 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200578 if exists('+tabclose')
579 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
580 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200581 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200582 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200583 endif
584 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200585 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200586 endif
587 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200588 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200589 endif
590 if exists('+ttymouse')
591 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200592 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200593 set ttymouse&
594 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200595 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
596 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
597 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
598 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200599 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200600 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200601 endif
602
603 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200604 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100605 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200606 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
607 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
608 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200609
zeertzjq1f025b02023-09-30 12:43:07 +0200610 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
611 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
612 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
613 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
614 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
615 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200616
617 "
618 " Unique string options below
619 "
620
621 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200622 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200623 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
624 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100625 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
626 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200627 set keyprotocol&
628
629 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200630 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
631 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200632 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
633 call assert_equal('"set previewpopup+=border:on', @:)
634 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
635 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200636 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200637 set previewpopup& completepopup&
638
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100639 " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200640 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
641 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
642 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100643 call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200644
645 " highlight: special parsing, including auto-completing highlight groups
646 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200647 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
648 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
649 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
650 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
651 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200652 " If all the display modes are used up we should be suggesting nothing. Make
653 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
654 " and make sure nothing is suggested from that.
655 let hl_display_modes = join(
656 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
657 \ {idx, val -> val[1]}),
658 \ {idx, val -> val != ':'}),
659 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200660 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200661 " Test completion in middle of the line
662 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
663 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200664
Christian Brabandt51d4d842024-12-06 17:26:25 +0100665 " messagesopt
666 call assert_equal(['history:', 'hit-enter', 'wait:'],
667 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
668
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200669 "
670 " Test flag lists
671 "
672
673 " Test set=. Show the original value if nothing is typed after '='.
674 " Otherwise, the list should avoid showing what's already typed.
675 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200676 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200677 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200678 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
679 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200680
681 " Test set+=. Never show original value, and it also tries to avoid listing
682 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200683 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
684 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
685 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200686
687 " Test that the position of the expansion is correct (even if there are
688 " additional values after the current cursor)
689 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
690 call assert_equal('"set mouse=han', @:)
691 set mouse&
692
693 " Test that other flag list options have auto-complete, but don't
694 " exhaustively validate their results.
695 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200696 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200697 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200698 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
699 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200700 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200701 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200703 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
704 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200705
706 "
707 "Test set-=
708 "
709
710 " Normal single-value option just shows the existing value
711 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200712 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200713 set ambiwidth&
714
715 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200716 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200717 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200718 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200719 set t_Ce&
720
721 " Comma-separated lists should present each option
722 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200723 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
724 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
725 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200726 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200727 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200728 " Test empty option
729 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200730 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100731 " Test all possible values
732 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100733 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'],
Christian Brabandt9162e632025-01-16 19:03:40 +0100734 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200735 set diffopt&
736
737 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200738 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200739
740 " Test files with commas in name are being parsed and escaped properly
741 set path=has\\\ space,file\\,with\\,comma,normal_file
742 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200743 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200744 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200745 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200746 endif
747 set path&
748
749 " Flag list should present orig value, then individual flags
750 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200751 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200752 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200753 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200754 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200755 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200756 " Test empty option
757 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200758 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200759 set mouse&
760
761 " 'whichwrap' is an odd case where it's both flag list and comma-separated
762 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200763 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200764 set ww&
765endfunc
766
zeertzjq4c7cb372023-06-14 16:39:54 +0100767func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100768 call assert_fails('set scroll=-1', 'E49:')
769 call assert_fails('set backupcopy=', 'E474:')
770 call assert_fails('set regexpengine=3', 'E474:')
771 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200772 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100773 call assert_fails('set colorcolumn=-a', 'E474:')
774 call assert_fails('set colorcolumn=a', 'E474:')
775 call assert_fails('set colorcolumn=1,', 'E474:')
776 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100777 call assert_fails('set cmdheight=-1', 'E487:')
778 call assert_fails('set cmdwinheight=-1', 'E487:')
779 if has('conceal')
780 call assert_fails('set conceallevel=-1', 'E487:')
781 call assert_fails('set conceallevel=4', 'E474:')
782 endif
783 call assert_fails('set helpheight=-1', 'E487:')
784 call assert_fails('set history=-1', 'E487:')
785 call assert_fails('set report=-1', 'E487:')
786 call assert_fails('set shiftwidth=-1', 'E487:')
787 call assert_fails('set sidescroll=-1', 'E487:')
788 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000789 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000790 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000791 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200792 if has('terminal')
793 call assert_fails('set termwinscroll=-1', 'E487:')
794 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100795 call assert_fails('set textwidth=-1', 'E487:')
796 call assert_fails('set timeoutlen=-1', 'E487:')
797 call assert_fails('set updatecount=-1', 'E487:')
798 call assert_fails('set updatetime=-1', 'E487:')
799 call assert_fails('set winheight=-1', 'E487:')
800 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200801
802 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100803 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200804 call assert_fails('setlocal xxx', 'E518:')
805 call assert_fails('setglobal xxx', 'E518:')
806 call assert_fails('set xxx=', 'E518:')
807 call assert_fails('setlocal xxx=', 'E518:')
808 call assert_fails('setglobal xxx=', 'E518:')
809 call assert_fails('set xxx:', 'E518:')
810 call assert_fails('setlocal xxx:', 'E518:')
811 call assert_fails('setglobal xxx:', 'E518:')
812 call assert_fails('set xxx!', 'E518:')
813 call assert_fails('setlocal xxx!', 'E518:')
814 call assert_fails('setglobal xxx!', 'E518:')
815 call assert_fails('set xxx?', 'E518:')
816 call assert_fails('setlocal xxx?', 'E518:')
817 call assert_fails('setglobal xxx?', 'E518:')
818 call assert_fails('set xxx&', 'E518:')
819 call assert_fails('setlocal xxx&', 'E518:')
820 call assert_fails('setglobal xxx&', 'E518:')
821 call assert_fails('set xxx<', 'E518:')
822 call assert_fails('setlocal xxx<', 'E518:')
823 call assert_fails('setglobal xxx<', 'E518:')
824
825 " Test for missing-options errors.
826 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100827 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200828 call assert_fails('set flash?', 'E519:')
829 call assert_fails('set graphic?', 'E519:')
830 call assert_fails('set hardtabs?', 'E519:')
831 call assert_fails('set mesg?', 'E519:')
832 call assert_fails('set novice?', 'E519:')
833 call assert_fails('set open?', 'E519:')
834 call assert_fails('set optimize?', 'E519:')
835 call assert_fails('set redraw?', 'E519:')
836 call assert_fails('set slowopen?', 'E519:')
837 call assert_fails('set sourceany?', 'E519:')
838 call assert_fails('set w300?', 'E519:')
839 call assert_fails('set w1200?', 'E519:')
840 call assert_fails('set w9600?', 'E519:')
841
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100842 call assert_fails('set undolevels=x', 'E521:')
843 call assert_fails('set tabstop=', 'E521:')
844 call assert_fails('set comments=-', 'E524:')
845 call assert_fails('set comments=a', 'E525:')
846 call assert_fails('set foldmarker=x', 'E536:')
847 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000848 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100849 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100850 call assert_fails('set rulerformat=%-', 'E539:')
851 call assert_fails('set rulerformat=%(', 'E542:')
852 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200853
854 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100855 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100856 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100857 call assert_fails('set statusline=%{%', 'E540:')
858 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100859 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100860 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200861
862 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100863 call assert_fails('set tabline=%$', 'E539:')
864 call assert_fails('set tabline=%{', 'E540:')
865 call assert_fails('set tabline=%{%', 'E540:')
866 call assert_fails('set tabline=%{%}', 'E539:')
867 call assert_fails('set tabline=%(', 'E542:')
868 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100869
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100870 if has('cursorshape')
871 " This invalid value for 'guicursor' used to cause Vim to crash.
872 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
873 call assert_fails('set guicursor=i-ci', 'E545:')
874 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100875 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100876 call assert_fails('set guicursor=r-cr:horx', 'E548:')
877 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
878 endif
Milly484face2024-10-12 11:26:06 +0200879
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100880 if has('mouseshape')
881 call assert_fails('se mouseshape=i-r:x', 'E547:')
882 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000883
884 " Test for 'backupext' and 'patchmode' set to the same value
885 set backupext=.bak
886 set patchmode=.patch
887 call assert_fails('set patchmode=.bak', 'E589:')
888 call assert_equal('.patch', &patchmode)
889 call assert_fails('set backupext=.patch', 'E589:')
890 call assert_equal('.bak', &backupext)
891 set backupext& patchmode&
892
Milly484face2024-10-12 11:26:06 +0200893 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100894 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200895 set winminheight& winheight&
896 set winheight=10 winminheight=10
897 call assert_fails('set winheight=9', 'E591:')
898 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200899
900 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100901 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200902 set winminwidth& winwidth&
903 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
904 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200905
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100906 call assert_fails("set showbreak=\x01", 'E595:')
907 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200908 call assert_fails('set tabstop??', 'E488:')
909 call assert_fails('set wrapscan!!', 'E488:')
910 call assert_fails('set tabstop&&', 'E488:')
911 call assert_fails('set wrapscan<<', 'E488:')
912 call assert_fails('set wrapscan=1', 'E474:')
913 call assert_fails('set autoindent@', 'E488:')
914 call assert_fails('set wildchar=<abc>', 'E474:')
915 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200916 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100917 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200918 call assert_fails('set pyxversion=6', 'E474:')
919 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100920 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200921 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100922 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
923 call assert_fails('set foldmarker={{{,', 'E474:')
924 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200925
926 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100927 setlocal listchars=trail:·
928 call assert_fails('set ambiwidth=double', 'E834:')
929 setlocal listchars=trail:-
930 setglobal listchars=trail:·
931 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100932 set listchars&
Milly484face2024-10-12 11:26:06 +0200933
934 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100935 setlocal fillchars=stl:·
936 call assert_fails('set ambiwidth=double', 'E835:')
937 setlocal fillchars=stl:-
938 setglobal fillchars=stl:·
939 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100940 set fillchars&
Milly484face2024-10-12 11:26:06 +0200941
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100942 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
943 set nomodifiable
944 call assert_fails('set fileencoding=latin1', 'E21:')
945 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200946 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000947 call assert_fails('let &formatoptions = "?"', 'E539:')
948 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200949
950 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100951 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
952 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
953 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
954 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
955 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
956 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100957endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100958
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000959func Test_set_encoding()
960 let save_encoding = &encoding
961
962 set enc=iso8859-1
963 call assert_equal('latin1', &enc)
964 set enc=iso8859_1
965 call assert_equal('latin1', &enc)
966 set enc=iso-8859-1
967 call assert_equal('latin1', &enc)
968 set enc=iso_8859_1
969 call assert_equal('latin1', &enc)
970 set enc=iso88591
971 call assert_equal('latin1', &enc)
972 set enc=iso8859
973 call assert_equal('latin1', &enc)
974 set enc=iso-8859
975 call assert_equal('latin1', &enc)
976 set enc=iso_8859
977 call assert_equal('latin1', &enc)
978 call assert_fails('set enc=iso8858', 'E474:')
979 call assert_equal('latin1', &enc)
980
981 let &encoding = save_encoding
982endfunc
983
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200984func CheckWasSet(name)
985 let verb_cm = execute('verbose set ' .. a:name .. '?')
986 call assert_match('Last set from.*test_options.vim', verb_cm)
987endfunc
988func CheckWasNotSet(name)
989 let verb_cm = execute('verbose set ' .. a:name .. '?')
990 call assert_notmatch('Last set from', verb_cm)
991endfunc
992
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200993" Must be executed before other tests that set 'term'.
994func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200995 CheckNotGui
996
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200997 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200998
999 let term_save = &term
1000 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001001 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001002 let &term = term_save
1003endfunc
1004
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001005func Test_copy_context()
1006 setlocal list
1007 call CheckWasSet('list')
1008 split
1009 call CheckWasSet('list')
1010 quit
1011 setlocal nolist
1012
1013 set ai
1014 call CheckWasSet('ai')
1015 set filetype=perl
1016 call CheckWasSet('filetype')
1017 set fo=tcroq
1018 call CheckWasSet('fo')
1019
1020 split Xsomebuf
1021 call CheckWasSet('ai')
1022 call CheckWasNotSet('filetype')
1023 call CheckWasSet('fo')
1024endfunc
1025
Bram Moolenaar67391142017-02-19 21:07:04 +01001026func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001027 CheckUnix
1028 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001029
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001030 " Setting 'ttytype' used to cause a double-free when exiting vim and
1031 " when vim is compiled with -DEXITFREE.
1032 set ttytype=ansi
1033 call assert_equal('ansi', &ttytype)
1034 call assert_equal(&ttytype, &term)
1035 set ttytype=xterm
1036 call assert_equal('xterm', &ttytype)
1037 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001038 try
1039 set ttytype=
1040 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001041 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001042 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001043
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001044 " Some systems accept any terminal name and return dumb settings,
1045 " check for failure of finding the entry and for missing 'cm' entry.
1046 try
1047 set ttytype=xxx
1048 call assert_report('set ttytype=xxx did not fail')
1049 catch /E522\|E437/
1050 endtry
1051
1052 set ttytype&
1053 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001054
1055 if has('gui') && !has('gui_running')
1056 call assert_fails('set term=gui', 'E531:')
1057 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001058endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001059
Milly484face2024-10-12 11:26:06 +02001060" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001061func Test_set_all()
1062 set tw=75
1063 set iskeyword=a-z,A-Z
1064 set nosplitbelow
1065 let out = execute('set all')
1066 call assert_match('textwidth=75', out)
1067 call assert_match('iskeyword=a-z,A-Z', out)
1068 call assert_match('nosplitbelow', out)
1069 set tw& iskeyword& splitbelow&
1070endfunc
1071
Milly484face2024-10-12 11:26:06 +02001072" Test for :set! all
1073func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001074 let out_mult = execute('set all')->split("\n")
1075 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001076 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001077 call assert_equal(out_one[0], '--- Options ---')
1078 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1079 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001080endfunc
1081
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001082func Test_renderoptions()
1083 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1084 " Doesn't hurt to do this on a non-Windows system.
1085 if windowsversion() !~ '^[345]\.'
1086 set renderoptions=type:directx
1087 set rop=type:directx
1088 endif
1089endfunc
1090
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001091func ResetIndentexpr()
1092 set indentexpr=
1093endfunc
1094
1095func Test_set_indentexpr()
1096 " this was causing usage of freed memory
1097 set indentexpr=ResetIndentexpr()
1098 new
1099 call feedkeys("i\<c-f>", 'x')
1100 call assert_equal('', &indentexpr)
1101 bwipe!
1102endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001103
1104func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001105 " Option 'backupskip' may contain several comma-separated path
1106 " specifications if one or more of the environment variables TMPDIR, TMP,
1107 " or TEMP is defined. To simplify testing, convert the string value into a
1108 " list.
1109 let bsklist = split(&bsk, ',')
1110
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001111 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001112 let found = (index(bsklist, '/private/tmp/*') >= 0)
1113 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001114 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001115 let found = (index(bsklist, '/tmp/*') >= 0)
1116 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001117 endif
1118
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001119 " If our test platform is Windows, the path(s) in option bsk will use
1120 " backslash for the path separator and the components could be in short
1121 " (8.3) format. As such, we need to replace the backslashes with forward
1122 " slashes and convert the path components to long format. The expand()
1123 " function will do this but it cannot handle comma-separated paths. This is
1124 " why bsk was converted from a string into a list of strings above.
1125 "
1126 " One final complication is that the wildcard "/*" is at the end of each
1127 " path and so expand() might return a list of matching files. To prevent
1128 " this, we need to remove the wildcard before calling expand() and then
1129 " append it afterwards.
1130 if has('win32')
1131 let item_nbr = 0
1132 while item_nbr < len(bsklist)
1133 let path_spec = bsklist[item_nbr]
1134 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1135 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1136 let bsklist[item_nbr] = path_spec . '/*'
1137 let item_nbr += 1
1138 endwhile
1139 endif
1140
1141 " Option bsk will also include these environment variables if defined.
1142 " If they're defined, verify they appear in the option value.
1143 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001144 if exists(var)
1145 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001146 let varvalue = substitute(varvalue, '/$', '', '')
1147 let varvalue .= '/*'
1148 let found = (index(bsklist, varvalue) >= 0)
1149 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001150 endif
1151 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001152
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001153 " Duplicates from environment variables should be filtered out (option has
1154 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1155 " so that we see what happens on startup.
1156 let after =<< trim [CODE]
1157 let bsklist = split(&backupskip, ',')
1158 call assert_equal(uniq(copy(bsklist)), bsklist)
1159 call writefile(['errors:'] + v:errors, 'Xtestout')
1160 qall
1161 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001162 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001163 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1164
1165 let saveenv = {}
1166 for var in ['TMPDIR', 'TMP', 'TEMP']
1167 let saveenv[var] = getenv(var)
1168 call setenv(var, '/duplicate/path')
1169 endfor
1170
1171 exe 'silent !' . cmd
1172 call assert_equal(['errors:'], readfile('Xtestout'))
1173
1174 " restore environment variables
1175 for var in ['TMPDIR', 'TMP', 'TEMP']
1176 call setenv(var, saveenv[var])
1177 endfor
1178
1179 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001180
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001181 " Duplicates should be filtered out (option has P_NODUP)
1182 let backupskip = &backupskip
1183 set backupskip=
1184 set backupskip+=/test/dir
1185 set backupskip+=/other/dir
1186 set backupskip+=/test/dir
1187 call assert_equal('/test/dir,/other/dir', &backupskip)
1188 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001189endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001190
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001191func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001192 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001193
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001194 " Test copy option from current buffer in window
1195 split
1196 enew
1197 setlocal numberwidth=5
1198 wincmd w
1199 call assert_equal(4,&numberwidth)
1200 bnext
1201 call assert_equal(5,&numberwidth)
1202 bw!
1203 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001204
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001205 " Test copy value from window that used to be display the buffer
1206 split
1207 enew
1208 setlocal numberwidth=6
1209 bnext
1210 wincmd w
1211 call assert_equal(4,&numberwidth)
1212 bnext
1213 call assert_equal(6,&numberwidth)
1214 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001215
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001216 " Test that if buffer is current, don't use the stale cached value
1217 " from the last time the buffer was displayed.
1218 split
1219 enew
1220 setlocal numberwidth=7
1221 bnext
1222 bnext
1223 setlocal numberwidth=8
1224 wincmd w
1225 call assert_equal(4,&numberwidth)
1226 bnext
1227 call assert_equal(8,&numberwidth)
1228 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001229
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001230 " Test value is not copied if window already has seen the buffer
1231 enew
1232 split
1233 setlocal numberwidth=9
1234 bnext
1235 setlocal numberwidth=10
1236 wincmd w
1237 call assert_equal(4,&numberwidth)
1238 bnext
1239 call assert_equal(4,&numberwidth)
1240 bw!
1241
1242 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001243endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001244
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001245def Test_split_copy_options()
1246 var values = [
1247 ['cursorbind', true, false],
1248 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1249 ['list', true, 0],
1250 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1251 ['number', true, 0],
1252 ['relativenumber', true, false],
1253 ['scrollbind', true, false],
1254 ['smoothscroll', true, false],
1255 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1256 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1257 ['wrap', false, true],
1258 ]
1259 if has('linebreak')
1260 values += [
1261 ['breakindent', true, false],
1262 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1263 ['linebreak', true, false],
1264 ['numberwidth', 7, 4],
1265 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1266 ]
1267 endif
1268 if has('rightleft')
1269 values += [
1270 ['rightleft', true, false],
1271 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1272 ]
1273 endif
1274 if has('statusline')
1275 values += [
1276 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1277 ]
1278 endif
1279 if has('spell')
1280 values += [
1281 ['spell', true, false],
1282 ]
1283 endif
1284 if has('syntax')
1285 values += [
1286 ['cursorcolumn', true, false],
1287 ['cursorline', true, false],
1288 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1289 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1290 ]
1291 endif
1292 if has('diff')
1293 values += [
1294 ['diff', true, false],
1295 ]
1296 endif
1297 if has('conceal')
1298 values += [
1299 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1300 ['conceallevel', '3', &conceallevel],
1301 ]
1302 endif
1303 if has('terminal')
1304 values += [
1305 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1306 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1307 ]
1308 endif
1309 if has('folding')
1310 values += [
1311 ['foldcolumn', 5, &foldcolumn],
1312 ['foldenable', false, true],
1313 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1314 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1315 ['foldlevel', 4, &foldlevel],
1316 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1317 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1318 ['foldminlines', 3, &foldminlines],
1319 ['foldnestmax', 17, &foldnestmax],
1320 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1321 ]
1322 endif
1323 if has('signs')
1324 values += [
1325 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1326 ]
1327 endif
1328
1329 # set options to non-default value
1330 for item in values
1331 exe $'&l:{item[0]} = {item[1]}'
1332 endfor
1333
1334 # check values are set in new window
1335 split
1336 for item in values
1337 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1338 endfor
1339
1340 # restore
1341 close
1342 for item in values
1343 exe $'&l:{item[0]} = {item[2]}'
1344 endfor
1345enddef
1346
Bram Moolenaarfc089602018-06-24 16:53:35 +02001347func Test_shortmess_F()
1348 new
1349 call assert_match('\[No Name\]', execute('file'))
1350 set shortmess+=F
1351 call assert_match('\[No Name\]', execute('file'))
1352 call assert_match('^\s*$', execute('file foo'))
1353 call assert_match('foo', execute('file'))
1354 set shortmess-=F
1355 call assert_match('bar', execute('file bar'))
1356 call assert_match('bar', execute('file'))
1357 set shortmess&
1358 bwipe
1359endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001360
1361func Test_shortmess_F2()
1362 e file1
1363 e file2
1364 call assert_match('file1', execute('bn', ''))
1365 call assert_match('file2', execute('bn', ''))
1366 set shortmess+=F
1367 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001368 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001369 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001370 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001371 set hidden
1372 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001373 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001374 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 set nohidden
1377 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001378 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001379 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 set shortmess&
1382 call assert_match('file1', execute('bn', ''))
1383 call assert_match('file2', execute('bn', ''))
1384 bwipe
1385 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001386 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001387endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001388
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001389func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001390 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001391
1392 set hidden
1393 set autoread
1394 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001395 e Xotherfile
1396 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001397 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001398 echo ''
1399
1400 if has('nanotime')
1401 sleep 10m
1402 else
1403 sleep 2
1404 endif
1405 call writefile(['bar'], 'X_dummy')
1406 bprev
1407 call assert_equal('', Screenline(&lines))
1408 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1409
1410 if has('nanotime')
1411 sleep 10m
1412 else
1413 sleep 2
1414 endif
1415 call writefile(['baz'], 'X_dummy')
1416 checktime
1417 call assert_equal('', Screenline(&lines))
1418 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001419
1420 set shortmess&
1421 set autoread&
1422 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001423 bwipe X_dummy
1424 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001425endfunc
1426
Bram Moolenaar375e3392019-01-31 18:26:10 +01001427func Test_local_scrolloff()
1428 set so=5
1429 set siso=7
1430 split
1431 call assert_equal(5, &so)
1432 setlocal so=3
1433 call assert_equal(3, &so)
1434 wincmd w
1435 call assert_equal(5, &so)
1436 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001437 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001438 setlocal so<
1439 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001440 setglob so=8
1441 call assert_equal(8, &so)
1442 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001443 setlocal so=0
1444 call assert_equal(0, &so)
1445 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001446 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001447
1448 call assert_equal(7, &siso)
1449 setlocal siso=3
1450 call assert_equal(3, &siso)
1451 wincmd w
1452 call assert_equal(7, &siso)
1453 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001454 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001455 setlocal siso<
1456 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001457 setglob siso=4
1458 call assert_equal(4, &siso)
1459 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001460 setlocal siso=0
1461 call assert_equal(0, &siso)
1462 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001463 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001464
1465 close
1466 set so&
1467 set siso&
1468endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001469
1470func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001471 CheckFunction reltimefloat
1472
Bram Moolenaar449ac472019-04-03 21:42:35 +02001473 new
1474 call setline(1, 'empty')
1475 redraw
1476 set writedelay=10
1477 let start = reltime()
1478 call setline(1, repeat('x', 70))
1479 redraw
1480 let elapsed = reltimefloat(reltime(start))
1481 set writedelay=0
1482 " With 'writedelay' set should take at least 30 * 10 msec
1483 call assert_inrange(30 * 0.01, 999.0, elapsed)
1484
1485 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001486endfunc
1487
1488func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001489 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001490 set visualbell
1491 call assert_beeps('normal 0h')
1492 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001493 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001494endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001495
1496" Test for the 'write' option
1497func Test_write()
1498 new
1499 call setline(1, ['L1'])
1500 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001501 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001502 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001503 " close swapfile
1504 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001505endfunc
1506
1507" Test for 'buftype' option
1508func Test_buftype()
1509 new
1510 call setline(1, ['L1'])
1511 set buftype=nowrite
1512 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001513
1514 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1515 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001516 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001517 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1518 endfor
1519
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001520 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001521endfunc
1522
Bram Moolenaar578fe942020-02-27 21:32:51 +01001523" Test for the 'rightleftcmd' option
1524func Test_rightleftcmd()
1525 CheckFeature rightleft
1526 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001527
1528 let g:l = []
1529 func AddPos()
1530 call add(g:l, screencol())
1531 return ''
1532 endfunc
1533 cmap <expr> <F2> AddPos()
1534
zeertzjqbb404f52022-07-23 06:25:29 +01001535 set rightleftcmd=
1536 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1537 \ "\<Right>\<F2>\<Esc>", 'xt')
1538 call assert_equal([2, 5, 3, 4], g:l)
1539
1540 let g:l = []
1541 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001542 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1543 \ "\<Left>\<F2>\<Esc>", 'xt')
1544 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1545
1546 cunmap <F2>
1547 unlet g:l
1548 set rightleftcmd&
1549 set rightleft&
1550endfunc
1551
zeertzjq28c162f2022-08-14 14:49:50 +01001552" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001553func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001554 " redraw to avoid matching previous messages
1555 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001556 set debug=beep
1557 exe "normal \<C-c>"
1558 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001559 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001560 " also check a line above, with a certain window width the colon is there
1561 call assert_match('Test_debug_option:$',
1562 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001563 set debug&
1564endfunc
1565
Bram Moolenaar004a6782020-04-11 17:09:31 +02001566" Test for the default CDPATH option
1567func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001568 let after =<< trim [CODE]
1569 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1570 call writefile(v:errors, 'Xtestout')
1571 qall
1572 [CODE]
1573 if has('unix')
1574 let $CDPATH='/path/to/dir1:/path/to/dir2'
1575 else
1576 let $CDPATH='/path/to/dir1;/path/to/dir2'
1577 endif
1578 if RunVim([], after, '')
1579 call assert_equal([], readfile('Xtestout'))
1580 call delete('Xtestout')
1581 endif
1582endfunc
1583
1584" Test for setting keycodes using set
1585func Test_opt_set_keycode()
1586 call assert_fails('set <t_k1=l', 'E474:')
1587 call assert_fails('set <Home=l', 'E474:')
1588 set <t_k9>=abcd
1589 call assert_equal('abcd', &t_k9)
1590 set <t_k9>&
1591 set <F9>=xyz
1592 call assert_equal('xyz', &t_k9)
1593 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001594
1595 " should we test all of them?
1596 set t_Ce=testCe
1597 set t_Cs=testCs
1598 set t_Us=testUs
1599 set t_ds=testds
1600 set t_Ds=testDs
1601 call assert_equal('testCe', &t_Ce)
1602 call assert_equal('testCs', &t_Cs)
1603 call assert_equal('testUs', &t_Us)
1604 call assert_equal('testds', &t_ds)
1605 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001606endfunc
1607
1608" Test for changing options in a sandbox
1609func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001610 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001611 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001612 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001613 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001614 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001615endfunc
1616
Milly484face2024-10-12 11:26:06 +02001617" Test for setting string global-local option value
1618func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001619 setglobal equalprg=gprg
1620 setlocal equalprg=lprg
1621 call assert_equal('gprg', &g:equalprg)
1622 call assert_equal('lprg', &l:equalprg)
1623 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001624
1625 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001626 set equalprg<
1627 call assert_equal('', &l:equalprg)
1628 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001629
1630 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001631 setglobal equalprg=gnewprg
1632 setlocal equalprg=lnewprg
1633 setlocal equalprg<
1634 call assert_equal('gnewprg', &l:equalprg)
1635 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001636
Milly484face2024-10-12 11:26:06 +02001637 set equalprg&
1638endfunc
1639
1640" Test for setting number global-local option value
1641func Test_set_number_global_local_option()
1642 setglobal scrolloff=10
1643 setlocal scrolloff=12
1644 call assert_equal(10, &g:scrolloff)
1645 call assert_equal(12, &l:scrolloff)
1646 call assert_equal(12, &scrolloff)
1647
1648 " :set {option}< set the effective value of {option} to its global value.
1649 set scrolloff<
1650 call assert_equal(10, &l:scrolloff)
1651 call assert_equal(10, &scrolloff)
1652
1653 " :setlocal {option}< removes the local value, so that the global value will be used.
1654 setglobal scrolloff=15
1655 setlocal scrolloff=18
1656 setlocal scrolloff<
1657 call assert_equal(-1, &l:scrolloff)
1658 call assert_equal(15, &scrolloff)
1659
1660 set scrolloff&
1661endfunc
1662
1663" Test for setting boolean global-local option value
1664func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001665 setglobal autoread
1666 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001667 call assert_equal(1, &g:autoread)
1668 call assert_equal(0, &l:autoread)
1669 call assert_equal(0, &autoread)
1670
1671 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001672 set autoread<
Milly484face2024-10-12 11:26:06 +02001673 call assert_equal(1, &l:autoread)
1674 call assert_equal(1, &autoread)
1675
1676 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001677 setglobal noautoread
1678 setlocal autoread
1679 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001680 call assert_equal(-1, &l:autoread)
1681 call assert_equal(0, &autoread)
1682
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001683 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001684endfunc
1685
Dominique Pelle042414f2021-07-12 21:43:19 +02001686func Test_set_in_sandbox()
1687 " Some boolean options cannot be set in sandbox, some can.
1688 call assert_fails('sandbox set modelineexpr', 'E48:')
1689 sandbox set number
1690 call assert_true(&number)
1691 set number&
1692
1693 " Some boolean options cannot be set in sandbox, some can.
1694 if has('python') || has('python3')
1695 call assert_fails('sandbox set pyxversion=3', 'E48:')
1696 endif
1697 sandbox set tabstop=4
1698 call assert_equal(4, &tabstop)
1699 set tabstop&
1700
1701 " Some string options cannot be set in sandbox, some can.
1702 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1703 sandbox set filetype=perl
1704 call assert_equal('perl', &filetype)
1705 set filetype&
1706endfunc
1707
Milly484face2024-10-12 11:26:06 +02001708" Test for setting string option value
1709func Test_set_string_option()
1710 " :set {option}=
1711 set makeprg=
1712 call assert_equal('', &mp)
1713 set makeprg=abc
1714 call assert_equal('abc', &mp)
1715
1716 " :set {option}:
1717 set makeprg:
1718 call assert_equal('', &mp)
1719 set makeprg:abc
1720 call assert_equal('abc', &mp)
1721
1722 " Let string
1723 let &makeprg = ''
1724 call assert_equal('', &mp)
1725 let &makeprg = 'abc'
1726 call assert_equal('abc', &mp)
1727
1728 " Let number converts to string
1729 let &makeprg = 42
1730 call assert_equal('42', &mp)
1731
1732 " Appending
1733 set makeprg=abc
1734 set makeprg+=def
1735 call assert_equal('abcdef', &mp)
1736 set makeprg+=def
1737 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1738 let &makeprg .= 'gh'
1739 call assert_equal('abcdefdefgh', &mp)
1740 let &makeprg ..= 'ij'
1741 call assert_equal('abcdefdefghij', &mp)
1742
1743 " Removing
1744 set makeprg=abcdefghi
1745 set makeprg-=def
1746 call assert_equal('abcghi', &mp)
1747 set makeprg-=def
1748 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1749
1750 " Prepending
1751 set makeprg=abc
1752 set makeprg^=def
1753 call assert_equal('defabc', &mp)
1754 set makeprg^=def
1755 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1756
1757 set makeprg&
1758endfunc
1759
1760" Test for setting string comma-separated list option value
1761func Test_set_string_comma_list_option()
1762 " :set {option}=
1763 set wildignore=
1764 call assert_equal('', &wildignore)
1765 set wildignore=*.png
1766 call assert_equal('*.png', &wildignore)
1767
1768 " :set {option}:
1769 set wildignore:
1770 call assert_equal('', &wildignore)
1771 set wildignore:*.png
1772 call assert_equal('*.png', &wildignore)
1773
1774 " Let string
1775 let &wildignore = ''
1776 call assert_equal('', &wildignore)
1777 let &wildignore = '*.png'
1778 call assert_equal('*.png', &wildignore)
1779
1780 " Let number converts to string
1781 let &wildignore = 42
1782 call assert_equal('42', &wildignore)
1783
1784 " Appending
1785 set wildignore=*.png
1786 set wildignore+=*.jpg
1787 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1788 set wildignore+=*.jpg
1789 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1790 set wildignore+=jpg
1791 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1792 let &wildignore .= 'foo'
1793 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1794 let &wildignore ..= 'bar'
1795 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1796
1797 " Removing
1798 set wildignore=*.png,*.jpg,*.obj
1799 set wildignore-=*.jpg
1800 call assert_equal('*.png,*.obj', &wildignore)
1801 set wildignore-=*.jpg
1802 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1803 set wildignore-=jpg
1804 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1805
1806 " Prepending
1807 set wildignore=*.png
1808 set wildignore^=*.jpg
1809 call assert_equal('*.jpg,*.png', &wildignore)
1810 set wildignore^=*.jpg
1811 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1812 set wildignore^=jpg
1813 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1814
1815 set wildignore&
1816endfunc
1817
1818" Test for setting string flags option value
1819func Test_set_string_flags_option()
1820 " :set {option}=
1821 set formatoptions=
1822 call assert_equal('', &fo)
1823 set formatoptions=abc
1824 call assert_equal('abc', &fo)
1825
1826 " :set {option}:
1827 set formatoptions:
1828 call assert_equal('', &fo)
1829 set formatoptions:abc
1830 call assert_equal('abc', &fo)
1831
1832 " Let string
1833 let &formatoptions = ''
1834 call assert_equal('', &fo)
1835 let &formatoptions = 'abc'
1836 call assert_equal('abc', &fo)
1837
1838 " Let number converts to string
1839 let &formatoptions = 12
1840 call assert_equal('12', &fo)
1841
1842 " Appending
1843 set formatoptions=abc
1844 set formatoptions+=pqr
1845 call assert_equal('abcpqr', &fo)
1846 set formatoptions+=pqr
1847 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1848 let &formatoptions .= 'r'
1849 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1850 let &formatoptions ..= 'r'
1851 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1852
1853 " Removing
1854 set formatoptions=abcpqr
1855 set formatoptions-=cp
1856 call assert_equal('abqr', &fo)
1857 set formatoptions-=cp
1858 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1859 set formatoptions-=ar
1860 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1861
1862 " Prepending
1863 set formatoptions=abc
1864 set formatoptions^=pqr
1865 call assert_equal('pqrabc', &fo)
1866 set formatoptions^=qr
1867 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1868
1869 set formatoptions&
1870endfunc
1871
1872" Test for setting number option value
1873func Test_set_number_option()
1874 " :set {option}=
1875 set scrolljump=5
1876 call assert_equal(5, &sj)
1877 set scrolljump=-3
1878 call assert_equal(-3, &sj)
1879
1880 " :set {option}:
1881 set scrolljump:7
1882 call assert_equal(7, &sj)
1883 set scrolljump:-5
1884 call assert_equal(-5, &sj)
1885
1886 " Set hex
1887 set scrolljump=0x10
1888 call assert_equal(16, &sj)
1889 set scrolljump=-0x10
1890 call assert_equal(-16, &sj)
1891 set scrolljump=0X12
1892 call assert_equal(18, &sj)
1893 set scrolljump=-0X12
1894 call assert_equal(-18, &sj)
1895
1896 " Set octal
1897 set scrolljump=010
1898 call assert_equal(8, &sj)
1899 set scrolljump=-010
1900 call assert_equal(-8, &sj)
1901 set scrolljump=0o12
1902 call assert_equal(10, &sj)
1903 set scrolljump=-0o12
1904 call assert_equal(-10, &sj)
1905 set scrolljump=0O15
1906 call assert_equal(13, &sj)
1907 set scrolljump=-0O15
1908 call assert_equal(-13, &sj)
1909
1910 " Let number
1911 let &scrolljump = 4
1912 call assert_equal(4, &sj)
1913 let &scrolljump = -6
1914 call assert_equal(-6, &sj)
1915
1916 " Let numeric string converts to number
1917 let &scrolljump = '7'
1918 call assert_equal(7, &sj)
1919 let &scrolljump = '-9'
1920 call assert_equal(-9, &sj)
1921
1922 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001923 set shiftwidth=4
1924 set sw+=2
1925 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001926 let &shiftwidth += 2
1927 call assert_equal(8, &sw)
1928
1929 " Decrementing
1930 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001931 set sw-=2
1932 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001933 let &shiftwidth -= 2
1934 call assert_equal(2, &sw)
1935
1936 " Multiplying
1937 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001938 set sw^=2
1939 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001940 let &shiftwidth *= 2
1941 call assert_equal(16, &sw)
1942
1943 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001944 set shiftwidth&
1945endfunc
1946
Milly484face2024-10-12 11:26:06 +02001947" Test for setting boolean option value
1948func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001949 set number&
Milly484face2024-10-12 11:26:06 +02001950
1951 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001952 set number
1953 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001954
1955 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001956 set nonu
1957 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001958
1959 " :set {option}!
1960 set number!
1961 call assert_equal(1, &nu)
1962 set number!
1963 call assert_equal(0, &nu)
1964
1965 " :set inv{option}
1966 set invnumber
1967 call assert_equal(1, &nu)
1968 set invnumber
1969 call assert_equal(0, &nu)
1970
1971 " Let number
1972 let &number = 1
1973 call assert_equal(1, &nu)
1974 let &number = 0
1975 call assert_equal(0, &nu)
1976
1977 " Let numeric string converts to number
1978 let &number = '1'
1979 call assert_equal(1, &nu)
1980 let &number = '0'
1981 call assert_equal(0, &nu)
1982
1983 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001984 let &nu = v:true
1985 call assert_equal(1, &nu)
1986 let &nu = v:false
1987 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001988
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001989 set number&
1990endfunc
1991
Milly484face2024-10-12 11:26:06 +02001992" Test for setting string option errors
1993func Test_set_string_option_errors()
1994 " :set no{option}
1995 call assert_fails('set nomakeprg', 'E474:')
1996 call assert_fails('setlocal nomakeprg', 'E474:')
1997 call assert_fails('setglobal nomakeprg', 'E474:')
1998
1999 " :set inv{option}
2000 call assert_fails('set invmakeprg', 'E474:')
2001 call assert_fails('setlocal invmakeprg', 'E474:')
2002 call assert_fails('setglobal invmakeprg', 'E474:')
2003
2004 " :set {option}!
2005 call assert_fails('set makeprg!', 'E488:')
2006 call assert_fails('setlocal makeprg!', 'E488:')
2007 call assert_fails('setglobal makeprg!', 'E488:')
2008
2009 " Invalid trailing chars
2010 call assert_fails('set makeprg??', 'E488:')
2011 call assert_fails('setlocal makeprg??', 'E488:')
2012 call assert_fails('setglobal makeprg??', 'E488:')
2013 call assert_fails('set makeprg&&', 'E488:')
2014 call assert_fails('setlocal makeprg&&', 'E488:')
2015 call assert_fails('setglobal makeprg&&', 'E488:')
2016 call assert_fails('set makeprg<<', 'E488:')
2017 call assert_fails('setlocal makeprg<<', 'E488:')
2018 call assert_fails('setglobal makeprg<<', 'E488:')
2019 call assert_fails('set makeprg@', 'E488:')
2020 call assert_fails('setlocal makeprg@', 'E488:')
2021 call assert_fails('setglobal makeprg@', 'E488:')
2022
2023 " Invalid type
2024 call assert_fails("let &makeprg = ['xxx']", 'E730:')
2025endfunc
2026
2027" Test for setting number option errors
2028func Test_set_number_option_errors()
2029 " :set no{option}
2030 call assert_fails('set notabstop', 'E474:')
2031 call assert_fails('setlocal notabstop', 'E474:')
2032 call assert_fails('setglobal notabstop', 'E474:')
2033
2034 " :set inv{option}
2035 call assert_fails('set invtabstop', 'E474:')
2036 call assert_fails('setlocal invtabstop', 'E474:')
2037 call assert_fails('setglobal invtabstop', 'E474:')
2038
2039 " :set {option}!
2040 call assert_fails('set tabstop!', 'E488:')
2041 call assert_fails('setlocal tabstop!', 'E488:')
2042 call assert_fails('setglobal tabstop!', 'E488:')
2043
2044 " Invalid trailing chars
2045 call assert_fails('set tabstop??', 'E488:')
2046 call assert_fails('setlocal tabstop??', 'E488:')
2047 call assert_fails('setglobal tabstop??', 'E488:')
2048 call assert_fails('set tabstop&&', 'E488:')
2049 call assert_fails('setlocal tabstop&&', 'E488:')
2050 call assert_fails('setglobal tabstop&&', 'E488:')
2051 call assert_fails('set tabstop<<', 'E488:')
2052 call assert_fails('setlocal tabstop<<', 'E488:')
2053 call assert_fails('setglobal tabstop<<', 'E488:')
2054 call assert_fails('set tabstop@', 'E488:')
2055 call assert_fails('setlocal tabstop@', 'E488:')
2056 call assert_fails('setglobal tabstop@', 'E488:')
2057
2058 " Not a number
2059 call assert_fails('set tabstop=', 'E521:')
2060 call assert_fails('setlocal tabstop=', 'E521:')
2061 call assert_fails('setglobal tabstop=', 'E521:')
2062 call assert_fails('set tabstop=x', 'E521:')
2063 call assert_fails('setlocal tabstop=x', 'E521:')
2064 call assert_fails('setglobal tabstop=x', 'E521:')
2065 call assert_fails('set tabstop=1x', 'E521:')
2066 call assert_fails('setlocal tabstop=1x', 'E521:')
2067 call assert_fails('setglobal tabstop=1x', 'E521:')
2068 call assert_fails('set tabstop=-x', 'E521:')
2069 call assert_fails('setlocal tabstop=-x', 'E521:')
2070 call assert_fails('setglobal tabstop=-x', 'E521:')
2071 call assert_fails('set tabstop=0x', 'E521:')
2072 call assert_fails('setlocal tabstop=0x', 'E521:')
2073 call assert_fails('setglobal tabstop=0x', 'E521:')
2074 call assert_fails('set tabstop=0o', 'E521:')
2075 call assert_fails('setlocal tabstop=0o', 'E521:')
2076 call assert_fails('setglobal tabstop=0o', 'E521:')
2077 call assert_fails("let &tabstop = 'x'", 'E521:')
2078 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2079 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2080
2081 " Invalid type
2082 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2083endfunc
2084
2085" Test for setting boolean option errors
2086func Test_set_boolean_option_errors()
2087 " :set {option}=
2088 call assert_fails('set number=', 'E474:')
2089 call assert_fails('setlocal number=', 'E474:')
2090 call assert_fails('setglobal number=', 'E474:')
2091 call assert_fails('set number=1', 'E474:')
2092 call assert_fails('setlocal number=1', 'E474:')
2093 call assert_fails('setglobal number=1', 'E474:')
2094
2095 " :set {option}:
2096 call assert_fails('set number:', 'E474:')
2097 call assert_fails('setlocal number:', 'E474:')
2098 call assert_fails('setglobal number:', 'E474:')
2099 call assert_fails('set number:1', 'E474:')
2100 call assert_fails('setlocal number:1', 'E474:')
2101 call assert_fails('setglobal number:1', 'E474:')
2102
2103 " :set {option}+=
2104 call assert_fails('set number+=1', 'E474:')
2105 call assert_fails('setlocal number+=1', 'E474:')
2106 call assert_fails('setglobal number+=1', 'E474:')
2107
2108 " :set {option}^=
2109 call assert_fails('set number^=1', 'E474:')
2110 call assert_fails('setlocal number^=1', 'E474:')
2111 call assert_fails('setglobal number^=1', 'E474:')
2112
2113 " :set {option}-=
2114 call assert_fails('set number-=1', 'E474:')
2115 call assert_fails('setlocal number-=1', 'E474:')
2116 call assert_fails('setglobal number-=1', 'E474:')
2117
2118 " Invalid trailing chars
2119 call assert_fails('set number!!', 'E488:')
2120 call assert_fails('setlocal number!!', 'E488:')
2121 call assert_fails('setglobal number!!', 'E488:')
2122 call assert_fails('set number??', 'E488:')
2123 call assert_fails('setlocal number??', 'E488:')
2124 call assert_fails('setglobal number??', 'E488:')
2125 call assert_fails('set number&&', 'E488:')
2126 call assert_fails('setlocal number&&', 'E488:')
2127 call assert_fails('setglobal number&&', 'E488:')
2128 call assert_fails('set number<<', 'E488:')
2129 call assert_fails('setlocal number<<', 'E488:')
2130 call assert_fails('setglobal number<<', 'E488:')
2131 call assert_fails('set number@', 'E488:')
2132 call assert_fails('setlocal number@', 'E488:')
2133 call assert_fails('setglobal number@', 'E488:')
2134
2135 " Invalid type
2136 call assert_fails("let &number = 'xxx'", 'E521:')
2137endfunc
2138
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002139" Test for the 'window' option
2140func Test_window_opt()
2141 " Needs only one open widow
2142 %bw!
2143 call setline(1, range(1, 8))
2144 set window=5
2145 exe "normal \<C-F>"
2146 call assert_equal(4, line('w0'))
2147 exe "normal \<C-F>"
2148 call assert_equal(7, line('w0'))
2149 exe "normal \<C-F>"
2150 call assert_equal(8, line('w0'))
2151 exe "normal \<C-B>"
2152 call assert_equal(5, line('w0'))
2153 exe "normal \<C-B>"
2154 call assert_equal(2, line('w0'))
2155 exe "normal \<C-B>"
2156 call assert_equal(1, line('w0'))
2157 set window=1
2158 exe "normal gg\<C-F>"
2159 call assert_equal(2, line('w0'))
2160 exe "normal \<C-F>"
2161 call assert_equal(3, line('w0'))
2162 exe "normal \<C-B>"
2163 call assert_equal(2, line('w0'))
2164 exe "normal \<C-B>"
2165 call assert_equal(1, line('w0'))
2166 enew!
2167 set window&
2168endfunc
2169
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002170" Test for the 'winminheight' option
2171func Test_opt_winminheight()
2172 only!
2173 let &winheight = &lines + 4
2174 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2175 call assert_true(&winminheight <= &lines)
2176 set winminheight&
2177 set winheight&
2178endfunc
2179
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002180func Test_opt_winminheight_term()
2181 CheckRunVimInTerminal
2182
2183 " The tabline should be taken into account.
2184 let lines =<< trim END
2185 set wmh=0 stal=2
2186 below sp | wincmd _
2187 below sp | wincmd _
2188 below sp | wincmd _
2189 below sp
2190 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002191 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002192 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2193 call term_sendkeys(buf, ":set wmh=1\n")
2194 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2195
2196 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002197endfunc
2198
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002199func Test_opt_winminheight_term_tabs()
2200 CheckRunVimInTerminal
2201
2202 " The tabline should be taken into account.
2203 let lines =<< trim END
2204 set wmh=0 stal=2
2205 split
2206 split
2207 split
2208 split
2209 tabnew
2210 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002211 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002212 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2213 call term_sendkeys(buf, ":set wmh=1\n")
2214 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2215
2216 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002217endfunc
2218
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002219" Test for the 'winminwidth' option
2220func Test_opt_winminwidth()
2221 only!
2222 let &winwidth = &columns + 4
2223 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2224 call assert_true(&winminwidth <= &columns)
2225 set winminwidth&
2226 set winwidth&
2227endfunc
2228
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002229" Test for setting option value containing spaces with isfname+=32
2230func Test_isfname_with_options()
2231 set isfname+=32
2232 setlocal keywordprg=:term\ help.exe
2233 call assert_equal(':term help.exe', &keywordprg)
2234 set isfname&
2235 setlocal keywordprg&
2236endfunc
2237
Bram Moolenaar74667062020-12-28 15:41:41 +01002238" Test that resetting laststatus does change scroll option
2239func Test_opt_reset_scroll()
2240 CheckRunVimInTerminal
2241 let vimrc =<< trim [CODE]
2242 set scroll=2
2243 set laststatus=2
2244 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002245 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002246 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2247 call term_sendkeys(buf, ":verbose set scroll?\n")
2248 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2249 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002250
2251 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002252 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002253endfunc
2254
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002255" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2256func Test_VIM_POSIX()
2257 let saved_VIM_POSIX = getenv("VIM_POSIX")
2258
2259 call setenv('VIM_POSIX', "1")
2260 let after =<< trim [CODE]
2261 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2262 qall
2263 [CODE]
2264 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002265 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002266 \ 'AS'], readfile('X_VIM_POSIX'))
2267 endif
2268
2269 call setenv('VIM_POSIX', v:null)
2270 let after =<< trim [CODE]
2271 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2272 qall
2273 [CODE]
2274 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002275 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002276 \ 'S'], readfile('X_VIM_POSIX'))
2277 endif
2278
2279 call delete('X_VIM_POSIX')
2280 call setenv('VIM_POSIX', saved_VIM_POSIX)
2281endfunc
2282
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002283" Test for setting an option to a Vi or Vim default
2284func Test_opt_default()
2285 set formatoptions&vi
2286 call assert_equal('vt', &formatoptions)
2287 set formatoptions&vim
2288 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002289
2290 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2291 set fencs=latin1
2292 set fencs&
2293 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2294 set fencs=latin1
2295 set all&
2296 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002297endfunc
2298
2299" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002300func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002301 %bw!
2302 let ht = &lines
2303 set cmdheight=9999
2304 call assert_equal(1, winheight(0))
2305 call assert_equal(ht - 1, &cmdheight)
2306 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002307
2308 " The status line should be taken into account.
2309 set laststatus=2
2310 set cmdheight=9999
2311 call assert_equal(ht - 2, &cmdheight)
2312 set cmdheight& laststatus&
2313
2314 " The tabline should be taken into account only non-GUI.
2315 set showtabline=2
2316 set cmdheight=9999
2317 if has('gui_running')
2318 call assert_equal(ht - 1, &cmdheight)
2319 else
2320 call assert_equal(ht - 2, &cmdheight)
2321 endif
2322 set cmdheight& showtabline&
2323
2324 " The 'winminheight' should be taken into account.
2325 set winheight=3 winminheight=3
2326 split
2327 set cmdheight=9999
2328 call assert_equal(ht - 8, &cmdheight)
2329 %bw!
2330 set cmdheight& winminheight& winheight&
2331
2332 " Only the windows in the current tabpage are taken into account.
2333 set winheight=3 winminheight=3 showtabline=0
2334 split
2335 tabnew
2336 set cmdheight=9999
2337 call assert_equal(ht - 3, &cmdheight)
2338 %bw!
2339 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002340endfunc
2341
Dominique Pelle923dce22021-11-21 11:36:04 +00002342" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002343func Test_opt_control_char()
2344 set wildchar=^v
2345 call assert_equal("\<C-V>", nr2char(&wildchar))
2346 set wildcharm=^r
2347 call assert_equal("\<C-R>", nr2char(&wildcharm))
2348 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2349 set wildchar& wildcharm&
2350endfunc
2351
2352" Test for the 'errorbells' option
2353func Test_opt_errorbells()
2354 set errorbells
2355 call assert_beeps('s/a1b2/x1y2/')
2356 set noerrorbells
2357endfunc
2358
Dominique Pelle042414f2021-07-12 21:43:19 +02002359func Test_opt_scrolljump()
2360 help
2361 resize 10
2362
2363 " Test with positive 'scrolljump'.
2364 set scrolljump=2
2365 norm! Lj
2366 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2367 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2368 \ winsaveview())
2369
2370 " Test with negative 'scrolljump' (percentage of window height).
2371 set scrolljump=-40
2372 norm! ggLj
2373 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2374 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2375 \ winsaveview())
2376
2377 set scrolljump&
2378 bw
2379endfunc
2380
Bakudankun29f3a452021-12-11 12:28:08 +00002381" Test for the 'cdhome' option
2382func Test_opt_cdhome()
2383 if has('unix') || has('vms')
2384 throw 'Skipped: only works on non-Unix'
2385 endif
2386
2387 set cdhome&
2388 call assert_equal(0, &cdhome)
2389 set cdhome
2390
2391 " This paragraph is copied from Test_cd_no_arg().
2392 let path = getcwd()
2393 cd
2394 call assert_equal($HOME, getcwd())
2395 call assert_notequal(path, getcwd())
2396 exe 'cd ' .. fnameescape(path)
2397 call assert_equal(path, getcwd())
2398
2399 set cdhome&
2400endfunc
2401
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002402func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002403 CheckOption termguicolors
2404
2405 " Test default option completion
2406 set wildoptions=
2407 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2408 call assert_equal('"set termguicolors', @:)
2409
2410 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2411 call assert_equal('"set notermguicolors', @:)
2412
2413 " Test fuzzy option completion
2414 set wildoptions=fuzzy
2415 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2416 call assert_equal('"set termguicolors termencoding', @:)
2417
2418 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2419 call assert_equal('"set notermguicolors', @:)
2420
2421 set wildoptions=
2422endfunc
2423
Sean Dewar39c46b42022-05-12 17:44:29 +01002424func Test_switchbuf_reset()
2425 set switchbuf=useopen
2426 sblast
2427 call assert_equal(1, winnr('$'))
2428 set all&
2429 call assert_equal('', &switchbuf)
2430 sblast
2431 call assert_equal(2, winnr('$'))
2432 only!
2433endfunc
2434
zeertzjqfcba86c2022-09-22 13:57:32 +01002435" :set empty string for global 'keywordprg' falls back to ":help"
2436func Test_keywordprg_empty()
2437 let k = &keywordprg
2438 set keywordprg=man
2439 call assert_equal('man', &keywordprg)
2440 set keywordprg=
2441 call assert_equal(':help', &keywordprg)
2442 set keywordprg=man
2443 call assert_equal('man', &keywordprg)
2444 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2445 let &keywordprg = k
2446endfunc
2447
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002448" check that the very first buffer created does not have 'endoffile' set
2449func Test_endoffile_default()
2450 let after =<< trim [CODE]
2451 call writefile([execute('set eof?')], 'Xtestout')
2452 qall!
2453 [CODE]
2454 if RunVim([], after, '')
2455 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2456 endif
2457 call delete('Xtestout')
2458endfunc
2459
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002460" Test for setting the 'lines' and 'columns' options to a minimum value
2461func Test_set_min_lines_columns()
2462 let save_lines = &lines
2463 let save_columns = &columns
2464
2465 let after =<< trim END
2466 set nomore
2467 let msg = []
2468 let v:errmsg = ''
2469 silent! let &columns=0
2470 call add(msg, v:errmsg)
2471 silent! set columns=0
2472 call add(msg, v:errmsg)
2473 silent! call setbufvar('', '&columns', 0)
2474 call add(msg, v:errmsg)
2475 "call writefile(msg, 'XResultsetminlines')
2476 silent! let &lines=0
2477 call add(msg, v:errmsg)
2478 silent! set lines=0
2479 call add(msg, v:errmsg)
2480 silent! call setbufvar('', '&lines', 0)
2481 call add(msg, v:errmsg)
2482 call writefile(msg, 'XResultsetminlines')
2483 qall!
2484 END
2485 if RunVim([], after, '')
2486 call assert_equal(['E594: Need at least 12 columns',
2487 \ 'E594: Need at least 12 columns: columns=0',
2488 \ 'E594: Need at least 12 columns',
2489 \ 'E593: Need at least 2 lines',
2490 \ 'E593: Need at least 2 lines: lines=0',
2491 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2492 endif
2493
2494 call delete('XResultsetminlines')
2495 let &lines = save_lines
2496 let &columns = save_columns
2497endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002498
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002499" Test for reverting a string option value if the new value is invalid.
2500func Test_string_option_revert_on_failure()
2501 new
2502 let optlist = [
2503 \ ['ambiwidth', 'double', 'a123'],
2504 \ ['background', 'dark', 'a123'],
2505 \ ['backspace', 'eol', 'a123'],
2506 \ ['backupcopy', 'no', 'a123'],
2507 \ ['belloff', 'showmatch', 'a123'],
2508 \ ['breakindentopt', 'min:10', 'list'],
2509 \ ['bufhidden', 'wipe', 'a123'],
2510 \ ['buftype', 'nowrite', 'a123'],
2511 \ ['casemap', 'keepascii', 'a123'],
2512 \ ['cedit', "\<C-Y>", 'z'],
2513 \ ['colorcolumn', '10', 'z'],
2514 \ ['commentstring', '#%s', 'a123'],
2515 \ ['complete', '.,t', 'a'],
2516 \ ['completefunc', 'MyCmplFunc', '1a-'],
2517 \ ['completeopt', 'popup', 'a123'],
2518 \ ['completepopup', 'width:20', 'border'],
2519 \ ['concealcursor', 'v', 'xyz'],
2520 \ ['cpoptions', 'HJ', '~'],
2521 \ ['cryptmethod', 'zip', 'a123'],
2522 \ ['cursorlineopt', 'screenline', 'a123'],
2523 \ ['debug', 'throw', 'a123'],
2524 \ ['diffopt', 'iwhite', 'a123'],
2525 \ ['display', 'uhex', 'a123'],
2526 \ ['eadirection', 'hor', 'a123'],
2527 \ ['encoding', 'utf-8', 'a123'],
2528 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002529 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002530 \ ['fileencoding', 'utf-8', 'a123,'],
2531 \ ['fileformat', 'mac', 'a123'],
2532 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002533 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002534 \ ['fillchars', 'diff:~', 'a123'],
2535 \ ['foldclose', 'all', 'a123'],
2536 \ ['foldmarker', '[[[,]]]', '[[['],
2537 \ ['foldmethod', 'marker', 'a123'],
2538 \ ['foldopen', 'percent', 'a123'],
2539 \ ['formatoptions', 'an', '*'],
2540 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2541 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002542 \ ['highlight', '!:CursorColumn', '8:'],
2543 \ ['keymodel', 'stopsel', 'a123'],
2544 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2545 \ ['lispoptions', 'expr:1', 'a123'],
2546 \ ['listchars', 'tab:->', 'tab:'],
2547 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002548 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002549 \ ['mkspellmem', '100000,1000,100', '100000'],
2550 \ ['mouse', 'nvi', 'z'],
2551 \ ['mousemodel', 'extend', 'a123'],
2552 \ ['nrformats', 'alpha', 'a123'],
2553 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2554 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2555 \ ['previewpopup', 'width:20', 'a123'],
2556 \ ['printoptions', 'paper:A4', 'a123:'],
2557 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2558 \ ['rulerformat', '%l', '%['],
2559 \ ['scrollopt', 'hor,jump', 'a123'],
2560 \ ['selection', 'exclusive', 'a123'],
2561 \ ['selectmode', 'cmd', 'a123'],
2562 \ ['sessionoptions', 'options', 'a123'],
2563 \ ['shortmess', 'w', '2'],
2564 \ ['showbreak', '>>', "\x01"],
2565 \ ['showcmdloc', 'statusline', 'a123'],
2566 \ ['signcolumn', 'no', 'a123'],
2567 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2568 \ ['spellfile', 'MySpell.en.add', "\x01"],
2569 \ ['spelllang', 'en', "#"],
2570 \ ['spelloptions', 'camel', 'a123'],
2571 \ ['spellsuggest', 'double', 'a123'],
2572 \ ['splitkeep', 'topline', 'a123'],
2573 \ ['statusline', '%f', '%['],
2574 \ ['swapsync', 'sync', 'a123'],
2575 \ ['switchbuf', 'usetab', 'a123'],
2576 \ ['syntax', 'abc', 'a^b'],
2577 \ ['tabline', '%f', '%['],
2578 \ ['tagcase', 'ignore', 'a123'],
2579 \ ['tagfunc', 'MyTagFunc', '1a-'],
2580 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2581 \ ['viewoptions', 'options', 'a123'],
2582 \ ['virtualedit', 'onemore', 'a123'],
2583 \ ['whichwrap', '<,>', '{,}'],
2584 \ ['wildmode', 'list', 'a123'],
2585 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002586 \ ]
2587 if has('gui')
2588 call add(optlist, ['browsedir', 'buffer', 'a123'])
2589 endif
2590 if has('clipboard_working')
2591 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2592 endif
2593 if has('win32')
2594 call add(optlist, ['completeslash', 'slash', 'a123'])
2595 endif
2596 if has('cscope')
2597 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2598 endif
2599 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002600 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2601 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2602 endif
2603 if has('keymap')
2604 call add(optlist, ['keymap', 'greek', '[]'])
2605 endif
2606 if has('mouseshape')
2607 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2608 endif
2609 if has('win32') && has('gui')
2610 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2611 endif
2612 if has('rightleft')
2613 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2614 endif
2615 if has('terminal')
2616 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2617 call add(optlist, ['termwinsize', '24x80', '100'])
2618 endif
2619 if has('win32') && has('terminal')
2620 call add(optlist, ['termwintype', 'winpty', 'a123'])
2621 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002622 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002623 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002624 endif
2625 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002626 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2627 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002628 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002629 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2630 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002631 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002632 call add(optlist, ['varsofttabstop', '12', 'a123'])
2633 call add(optlist, ['vartabstop', '4,20', '4,'])
2634 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002635 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002636 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002637 endif
2638 for opt in optlist
2639 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002640 try
2641 exe $"let &{opt[0]} = '{opt[1]}'"
2642 catch
2643 call assert_report($"Caught {v:exception} with {opt->string()}")
2644 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002645 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2646 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2647 exe $"let &{opt[0]} = save_opt"
2648 endfor
2649 bw!
2650endfunc
2651
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002652func Test_set_option_window_global_local()
2653 new Xbuffer1
2654 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2655 setlocal scrolloff=2
2656 setglobal scrolloff=3
2657 setl modified
2658 " A new buffer has its own window-local options
2659 hide enew
2660 call assert_equal(-1, &l:scrolloff)
2661 call assert_equal(3, &g:scrolloff)
2662 " A new window opened with its own buffer-local options
2663 new
2664 call assert_equal(-1, &l:scrolloff)
2665 call assert_equal(3, &g:scrolloff)
2666 " Re-open Xbuffer1 and it should use
2667 " the previous set window-local options
2668 b Xbuffer1
2669 call assert_equal(2, &l:scrolloff)
2670 call assert_equal(3, &g:scrolloff)
2671 bw!
2672 bw!
2673 let &g:scrolloff = _gso
2674endfunc
2675
2676func GetGlobalLocalWindowOptions()
2677 new
2678 sil! r $VIMRUNTIME/doc/options.txt
2679 " Filter for global or local to window
2680 v/^'.*'.*\n.*global or local to window |global-local/d
2681 " get option value and type
2682 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2683 sil %s/empty/""/g
2684 " split the result
2685 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2686 bw!
2687 return result
2688endfunc
2689
2690func Test_set_option_window_global_local_all()
2691 new Xbuffer2
2692
2693 let optionlist = GetGlobalLocalWindowOptions()
2694 for [opt, type, default] in optionlist
2695 let _old = eval('&g:' .. opt)
2696 if type == 'string'
2697 if opt == 'fillchars'
2698 exe 'setl ' .. opt .. '=vert:+'
2699 exe 'setg ' .. opt .. '=vert:+,fold:+'
2700 elseif opt == 'listchars'
2701 exe 'setl ' .. opt .. '=tab:>>'
2702 exe 'setg ' .. opt .. '=tab:++'
2703 elseif opt == 'virtualedit'
2704 exe 'setl ' .. opt .. '=all'
2705 exe 'setg ' .. opt .. '=block'
2706 else
2707 exe 'setl ' .. opt .. '=Local'
2708 exe 'setg ' .. opt .. '=Global'
2709 endif
2710 elseif type == 'number'
2711 exe 'setl ' .. opt .. '=5'
2712 exe 'setg ' .. opt .. '=10'
2713 endif
2714 setl modified
2715 hide enew
2716 if type == 'string'
2717 call assert_equal('', eval('&l:' .. opt))
2718 if opt == 'fillchars'
2719 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2720 elseif opt == 'listchars'
2721 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2722 elseif opt == 'virtualedit'
2723 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2724 else
2725 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2726 endif
2727 elseif type == 'number'
2728 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2729 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2730 endif
2731 bw!
2732 exe 'let &g:' .. opt .. '=' .. default
2733 endfor
2734 bw!
2735endfunc
2736
Christian Brabandt757593c2023-08-22 21:44:10 +02002737func Test_paste_depending_options()
2738 " setting the paste option, resets all dependent options
2739 " and will be reported correctly using :verbose set <option>?
2740 let lines =<< trim [CODE]
2741 " set paste test
2742 set autoindent
2743 set expandtab
2744 " disabled, because depends on compiled feature set
2745 " set hkmap
2746 " set revins
2747 " set varsofttabstop=8,32,8
2748 set ruler
2749 set showmatch
2750 set smarttab
2751 set softtabstop=4
2752 set textwidth=80
2753 set wrapmargin=10
2754
2755 source Xvimrc_paste2
2756
2757 redir > Xoutput_paste
2758 verbose set expandtab?
2759 verbose setg expandtab?
2760 verbose setl expandtab?
2761 redir END
2762
2763 qall!
2764 [CODE]
2765
2766 call writefile(lines, 'Xvimrc_paste', 'D')
2767 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2768 if !RunVim([], lines, '--clean')
2769 return
2770 endif
2771
2772 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2773 call assert_equal('noexpandtab', result[0])
2774 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2775 call assert_equal('noexpandtab', result[2])
2776 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2777 call assert_equal('noexpandtab', result[4])
2778 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2779
2780 call delete('Xoutput_paste')
2781endfunc
2782
2783func Test_binary_depending_options()
2784 " setting the paste option, resets all dependent options
2785 " and will be reported correctly using :verbose set <option>?
2786 let lines =<< trim [CODE]
2787 " set binary test
2788 set expandtab
2789
2790 source Xvimrc_bin2
2791
2792 redir > Xoutput_bin
2793 verbose set expandtab?
2794 verbose setg expandtab?
2795 verbose setl expandtab?
2796 redir END
2797
2798 qall!
2799 [CODE]
2800
2801 call writefile(lines, 'Xvimrc_bin', 'D')
2802 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2803 if !RunVim([], lines, '--clean')
2804 return
2805 endif
2806
2807 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2808 call assert_equal('noexpandtab', result[0])
2809 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2810 call assert_equal('noexpandtab', result[2])
2811 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2812 call assert_equal('noexpandtab', result[4])
2813 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2814
2815 call delete('Xoutput_bin')
2816endfunc
2817
Gregory Anders3695d0e2023-09-29 20:17:20 +02002818func Test_set_keyprotocol()
2819 CheckNotGui
2820
2821 let term = &term
2822 set term=ansi
2823 call assert_equal('', &t_TI)
2824
2825 " Setting 'keyprotocol' should affect terminal codes without needing to
2826 " reset 'term'
2827 set keyprotocol+=ansi:kitty
2828 call assert_equal("\<Esc>[=1;1u", &t_TI)
2829 let &term = term
2830endfunc
2831
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002832func Test_set_wrap()
2833 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2834 " cursor position.
2835 set wrap smoothscroll scrolloff=5
2836
2837 call setline(1, ['', 'aaaa'->repeat(500)])
2838 20 split
2839 20 vsplit
2840 norm 2G$
2841 redraw
2842 set nowrap
2843 call assert_equal(2, winline())
2844
2845 set wrap& smoothscroll& scrolloff&
2846endfunc
2847
zeertzjqcd3a13e2024-02-24 16:51:32 +01002848func Test_delcombine()
2849 new
2850 set backspace=indent,eol,start
2851
2852 set delcombine
2853 call setline(1, 'β̳̈:β̳̈')
2854 normal! 0x
2855 call assert_equal('β̈:β̳̈', getline(1))
2856 exe "normal! A\<BS>"
2857 call assert_equal('β̈:β̈', getline(1))
2858 normal! 0x
2859 call assert_equal('β:β̈', getline(1))
2860 exe "normal! A\<BS>"
2861 call assert_equal('β:β', getline(1))
2862 normal! 0x
2863 call assert_equal(':β', getline(1))
2864 exe "normal! A\<BS>"
2865 call assert_equal(':', getline(1))
2866
2867 set nodelcombine
2868 call setline(1, 'β̳̈:β̳̈')
2869 normal! 0x
2870 call assert_equal(':β̳̈', getline(1))
2871 exe "normal! A\<BS>"
2872 call assert_equal(':', getline(1))
2873
2874 set backspace& delcombine&
2875 bwipe!
2876endfunc
2877
Milly484face2024-10-12 11:26:06 +02002878" Should not raise errors when set missing-options.
2879func Test_set_missing_options()
2880 set autoprint
2881 set beautify
2882 set flash
2883 set graphic
2884 set hardtabs=8
2885 set mesg
2886 set novice
2887 set open
2888 set optimize
2889 set redraw
2890 set slowopen
2891 set sourceany
2892 set w300=23
2893 set w1200=23
2894 set w9600=23
2895endfunc
2896
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002897func Test_default_keyprotocol()
2898 " default value of keyprotocol
2899 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2900endfunc
2901
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002902" vim: shiftwidth=2 sts=2 expandtab