blob: e85dd6a9cc42d6da15c4208e78bf1156260aa29e [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:')
Girish Palya14f6da52025-05-26 19:04:25 +0200277 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:')
zeertzjq67fe77d2025-04-20 10:21:18 +0200280 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:')
Girish Palya14f6da52025-05-26 19:04:25 +0200285 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 Palya14f6da52025-05-26 19:04:25 +0200288 set complete+=Ffuncref('foo'\\,\ [10])
289 set complete=Ffuncref('foo'\\,\ [10])^10
Girish Palyacbe53192025-04-14 22:13:15 +0200290 set complete&
Girish Palya14f6da52025-05-26 19:04:25 +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 Baal8cc6d8b2025-05-31 12:10:31 +0200605 call assert_equal(['-BufAdd', '-BufCreate'], getcompletion('set eventignore=all,-', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100606 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200607 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
608 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
609 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200610
zeertzjq1f025b02023-09-30 12:43:07 +0200611 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
612 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
613 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
614 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
615 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
616 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200617
618 "
619 " Unique string options below
620 "
621
622 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200623 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200624 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
625 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100626 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
627 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200628 set keyprotocol&
629
630 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200631 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
632 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200633 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
634 call assert_equal('"set previewpopup+=border:on', @:)
635 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
636 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200637 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200638 set previewpopup& completepopup&
639
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100640 " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200641 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
642 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
643 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100644 call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200645
646 " highlight: special parsing, including auto-completing highlight groups
647 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200648 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
649 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
650 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
651 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
652 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200653 " If all the display modes are used up we should be suggesting nothing. Make
654 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
655 " and make sure nothing is suggested from that.
656 let hl_display_modes = join(
657 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
658 \ {idx, val -> val[1]}),
659 \ {idx, val -> val != ':'}),
660 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200661 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200662 " Test completion in middle of the line
663 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
664 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200665
Christian Brabandt51d4d842024-12-06 17:26:25 +0100666 " messagesopt
667 call assert_equal(['history:', 'hit-enter', 'wait:'],
668 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
669
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200670 "
671 " Test flag lists
672 "
673
674 " Test set=. Show the original value if nothing is typed after '='.
675 " Otherwise, the list should avoid showing what's already typed.
676 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200677 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200678 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200679 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
680 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200681
682 " Test set+=. Never show original value, and it also tries to avoid listing
683 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200684 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
685 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
686 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200687
688 " Test that the position of the expansion is correct (even if there are
689 " additional values after the current cursor)
690 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
691 call assert_equal('"set mouse=han', @:)
692 set mouse&
693
694 " Test that other flag list options have auto-complete, but don't
695 " exhaustively validate their results.
696 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200697 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200698 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200699 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
700 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200701 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200702 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200703 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200704 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
705 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200706
707 "
708 "Test set-=
709 "
710
711 " Normal single-value option just shows the existing value
712 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200713 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200714 set ambiwidth&
715
716 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200717 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200718 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200719 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200720 set t_Ce&
721
722 " Comma-separated lists should present each option
723 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200724 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
725 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
726 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200727 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200728 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200729 " Test empty option
730 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200731 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100732 " Test all possible values
733 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100734 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'],
Christian Brabandt9162e632025-01-16 19:03:40 +0100735 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200736 set diffopt&
737
738 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200739 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200740
741 " Test files with commas in name are being parsed and escaped properly
742 set path=has\\\ space,file\\,with\\,comma,normal_file
743 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200744 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200745 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200746 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200747 endif
748 set path&
749
750 " Flag list should present orig value, then individual flags
751 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200752 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200753 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200754 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200755 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200756 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200757 " Test empty option
758 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200759 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200760 set mouse&
761
762 " 'whichwrap' is an odd case where it's both flag list and comma-separated
763 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200764 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200765 set ww&
766endfunc
767
zeertzjq4c7cb372023-06-14 16:39:54 +0100768func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100769 call assert_fails('set scroll=-1', 'E49:')
770 call assert_fails('set backupcopy=', 'E474:')
771 call assert_fails('set regexpengine=3', 'E474:')
772 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200773 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100774 call assert_fails('set colorcolumn=-a', 'E474:')
775 call assert_fails('set colorcolumn=a', 'E474:')
776 call assert_fails('set colorcolumn=1,', 'E474:')
777 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100778 call assert_fails('set cmdheight=-1', 'E487:')
779 call assert_fails('set cmdwinheight=-1', 'E487:')
780 if has('conceal')
781 call assert_fails('set conceallevel=-1', 'E487:')
782 call assert_fails('set conceallevel=4', 'E474:')
783 endif
784 call assert_fails('set helpheight=-1', 'E487:')
785 call assert_fails('set history=-1', 'E487:')
786 call assert_fails('set report=-1', 'E487:')
787 call assert_fails('set shiftwidth=-1', 'E487:')
788 call assert_fails('set sidescroll=-1', 'E487:')
789 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000790 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000791 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000792 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200793 if has('terminal')
794 call assert_fails('set termwinscroll=-1', 'E487:')
795 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100796 call assert_fails('set textwidth=-1', 'E487:')
797 call assert_fails('set timeoutlen=-1', 'E487:')
798 call assert_fails('set updatecount=-1', 'E487:')
799 call assert_fails('set updatetime=-1', 'E487:')
800 call assert_fails('set winheight=-1', 'E487:')
801 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200802
803 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100804 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200805 call assert_fails('setlocal xxx', 'E518:')
806 call assert_fails('setglobal xxx', 'E518:')
807 call assert_fails('set xxx=', 'E518:')
808 call assert_fails('setlocal xxx=', 'E518:')
809 call assert_fails('setglobal xxx=', 'E518:')
810 call assert_fails('set xxx:', 'E518:')
811 call assert_fails('setlocal xxx:', 'E518:')
812 call assert_fails('setglobal xxx:', 'E518:')
813 call assert_fails('set xxx!', 'E518:')
814 call assert_fails('setlocal xxx!', 'E518:')
815 call assert_fails('setglobal xxx!', 'E518:')
816 call assert_fails('set xxx?', 'E518:')
817 call assert_fails('setlocal xxx?', 'E518:')
818 call assert_fails('setglobal xxx?', 'E518:')
819 call assert_fails('set xxx&', 'E518:')
820 call assert_fails('setlocal xxx&', 'E518:')
821 call assert_fails('setglobal xxx&', 'E518:')
822 call assert_fails('set xxx<', 'E518:')
823 call assert_fails('setlocal xxx<', 'E518:')
824 call assert_fails('setglobal xxx<', 'E518:')
825
826 " Test for missing-options errors.
827 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100828 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200829 call assert_fails('set flash?', 'E519:')
830 call assert_fails('set graphic?', 'E519:')
831 call assert_fails('set hardtabs?', 'E519:')
832 call assert_fails('set mesg?', 'E519:')
833 call assert_fails('set novice?', 'E519:')
834 call assert_fails('set open?', 'E519:')
835 call assert_fails('set optimize?', 'E519:')
836 call assert_fails('set redraw?', 'E519:')
837 call assert_fails('set slowopen?', 'E519:')
838 call assert_fails('set sourceany?', 'E519:')
839 call assert_fails('set w300?', 'E519:')
840 call assert_fails('set w1200?', 'E519:')
841 call assert_fails('set w9600?', 'E519:')
842
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100843 call assert_fails('set undolevels=x', 'E521:')
844 call assert_fails('set tabstop=', 'E521:')
845 call assert_fails('set comments=-', 'E524:')
846 call assert_fails('set comments=a', 'E525:')
847 call assert_fails('set foldmarker=x', 'E536:')
848 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000849 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100850 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100851 call assert_fails('set rulerformat=%-', 'E539:')
852 call assert_fails('set rulerformat=%(', 'E542:')
853 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200854
855 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100856 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100857 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100858 call assert_fails('set statusline=%{%', 'E540:')
859 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100860 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100861 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200862
863 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100864 call assert_fails('set tabline=%$', 'E539:')
865 call assert_fails('set tabline=%{', 'E540:')
866 call assert_fails('set tabline=%{%', 'E540:')
867 call assert_fails('set tabline=%{%}', 'E539:')
868 call assert_fails('set tabline=%(', 'E542:')
869 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100870
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100871 if has('cursorshape')
872 " This invalid value for 'guicursor' used to cause Vim to crash.
873 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
874 call assert_fails('set guicursor=i-ci', 'E545:')
875 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100876 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100877 call assert_fails('set guicursor=r-cr:horx', 'E548:')
878 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
879 endif
Milly484face2024-10-12 11:26:06 +0200880
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100881 if has('mouseshape')
882 call assert_fails('se mouseshape=i-r:x', 'E547:')
883 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000884
885 " Test for 'backupext' and 'patchmode' set to the same value
886 set backupext=.bak
887 set patchmode=.patch
888 call assert_fails('set patchmode=.bak', 'E589:')
889 call assert_equal('.patch', &patchmode)
890 call assert_fails('set backupext=.patch', 'E589:')
891 call assert_equal('.bak', &backupext)
892 set backupext& patchmode&
893
Milly484face2024-10-12 11:26:06 +0200894 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100895 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200896 set winminheight& winheight&
897 set winheight=10 winminheight=10
898 call assert_fails('set winheight=9', 'E591:')
899 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200900
901 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100902 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200903 set winminwidth& winwidth&
904 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
905 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200906
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100907 call assert_fails("set showbreak=\x01", 'E595:')
908 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200909 call assert_fails('set tabstop??', 'E488:')
910 call assert_fails('set wrapscan!!', 'E488:')
911 call assert_fails('set tabstop&&', 'E488:')
912 call assert_fails('set wrapscan<<', 'E488:')
913 call assert_fails('set wrapscan=1', 'E474:')
914 call assert_fails('set autoindent@', 'E488:')
915 call assert_fails('set wildchar=<abc>', 'E474:')
916 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200917 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100918 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200919 call assert_fails('set pyxversion=6', 'E474:')
920 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100921 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200922 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100923 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
924 call assert_fails('set foldmarker={{{,', 'E474:')
925 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200926
927 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100928 setlocal listchars=trail:·
929 call assert_fails('set ambiwidth=double', 'E834:')
930 setlocal listchars=trail:-
931 setglobal listchars=trail:·
932 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100933 set listchars&
Milly484face2024-10-12 11:26:06 +0200934
935 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100936 setlocal fillchars=stl:·
937 call assert_fails('set ambiwidth=double', 'E835:')
938 setlocal fillchars=stl:-
939 setglobal fillchars=stl:·
940 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100941 set fillchars&
Milly484face2024-10-12 11:26:06 +0200942
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100943 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
944 set nomodifiable
945 call assert_fails('set fileencoding=latin1', 'E21:')
946 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200947 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000948 call assert_fails('let &formatoptions = "?"', 'E539:')
949 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200950
951 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100952 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
953 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
954 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
955 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
956 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
957 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100958endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100959
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000960func Test_set_encoding()
961 let save_encoding = &encoding
962
963 set enc=iso8859-1
964 call assert_equal('latin1', &enc)
965 set enc=iso8859_1
966 call assert_equal('latin1', &enc)
967 set enc=iso-8859-1
968 call assert_equal('latin1', &enc)
969 set enc=iso_8859_1
970 call assert_equal('latin1', &enc)
971 set enc=iso88591
972 call assert_equal('latin1', &enc)
973 set enc=iso8859
974 call assert_equal('latin1', &enc)
975 set enc=iso-8859
976 call assert_equal('latin1', &enc)
977 set enc=iso_8859
978 call assert_equal('latin1', &enc)
979 call assert_fails('set enc=iso8858', 'E474:')
980 call assert_equal('latin1', &enc)
981
982 let &encoding = save_encoding
983endfunc
984
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200985func CheckWasSet(name)
986 let verb_cm = execute('verbose set ' .. a:name .. '?')
987 call assert_match('Last set from.*test_options.vim', verb_cm)
988endfunc
989func CheckWasNotSet(name)
990 let verb_cm = execute('verbose set ' .. a:name .. '?')
991 call assert_notmatch('Last set from', verb_cm)
992endfunc
993
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200994" Must be executed before other tests that set 'term'.
995func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200996 CheckNotGui
997
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200998 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200999
1000 let term_save = &term
1001 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001002 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001003 let &term = term_save
1004endfunc
1005
Bram Moolenaarcfb38142019-10-19 20:18:47 +02001006func Test_copy_context()
1007 setlocal list
1008 call CheckWasSet('list')
1009 split
1010 call CheckWasSet('list')
1011 quit
1012 setlocal nolist
1013
1014 set ai
1015 call CheckWasSet('ai')
1016 set filetype=perl
1017 call CheckWasSet('filetype')
1018 set fo=tcroq
1019 call CheckWasSet('fo')
1020
1021 split Xsomebuf
1022 call CheckWasSet('ai')
1023 call CheckWasNotSet('filetype')
1024 call CheckWasSet('fo')
1025endfunc
1026
Bram Moolenaar67391142017-02-19 21:07:04 +01001027func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001028 CheckUnix
1029 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001030
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001031 " Setting 'ttytype' used to cause a double-free when exiting vim and
1032 " when vim is compiled with -DEXITFREE.
1033 set ttytype=ansi
1034 call assert_equal('ansi', &ttytype)
1035 call assert_equal(&ttytype, &term)
1036 set ttytype=xterm
1037 call assert_equal('xterm', &ttytype)
1038 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001039 try
1040 set ttytype=
1041 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001042 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001043 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001044
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001045 " Some systems accept any terminal name and return dumb settings,
1046 " check for failure of finding the entry and for missing 'cm' entry.
1047 try
1048 set ttytype=xxx
1049 call assert_report('set ttytype=xxx did not fail')
1050 catch /E522\|E437/
1051 endtry
1052
1053 set ttytype&
1054 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001055
1056 if has('gui') && !has('gui_running')
1057 call assert_fails('set term=gui', 'E531:')
1058 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001059endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001060
Milly484face2024-10-12 11:26:06 +02001061" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001062func Test_set_all()
1063 set tw=75
1064 set iskeyword=a-z,A-Z
1065 set nosplitbelow
1066 let out = execute('set all')
1067 call assert_match('textwidth=75', out)
1068 call assert_match('iskeyword=a-z,A-Z', out)
1069 call assert_match('nosplitbelow', out)
1070 set tw& iskeyword& splitbelow&
1071endfunc
1072
Milly484face2024-10-12 11:26:06 +02001073" Test for :set! all
1074func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001075 let out_mult = execute('set all')->split("\n")
1076 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001077 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001078 call assert_equal(out_one[0], '--- Options ---')
1079 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1080 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001081endfunc
1082
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001083func Test_renderoptions()
1084 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1085 " Doesn't hurt to do this on a non-Windows system.
1086 if windowsversion() !~ '^[345]\.'
1087 set renderoptions=type:directx
1088 set rop=type:directx
1089 endif
1090endfunc
1091
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001092func ResetIndentexpr()
1093 set indentexpr=
1094endfunc
1095
1096func Test_set_indentexpr()
1097 " this was causing usage of freed memory
1098 set indentexpr=ResetIndentexpr()
1099 new
1100 call feedkeys("i\<c-f>", 'x')
1101 call assert_equal('', &indentexpr)
1102 bwipe!
1103endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001104
1105func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001106 " Option 'backupskip' may contain several comma-separated path
1107 " specifications if one or more of the environment variables TMPDIR, TMP,
1108 " or TEMP is defined. To simplify testing, convert the string value into a
1109 " list.
1110 let bsklist = split(&bsk, ',')
1111
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001112 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001113 let found = (index(bsklist, '/private/tmp/*') >= 0)
1114 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001115 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001116 let found = (index(bsklist, '/tmp/*') >= 0)
1117 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001118 endif
1119
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001120 " If our test platform is Windows, the path(s) in option bsk will use
1121 " backslash for the path separator and the components could be in short
1122 " (8.3) format. As such, we need to replace the backslashes with forward
1123 " slashes and convert the path components to long format. The expand()
1124 " function will do this but it cannot handle comma-separated paths. This is
1125 " why bsk was converted from a string into a list of strings above.
1126 "
1127 " One final complication is that the wildcard "/*" is at the end of each
1128 " path and so expand() might return a list of matching files. To prevent
1129 " this, we need to remove the wildcard before calling expand() and then
1130 " append it afterwards.
1131 if has('win32')
1132 let item_nbr = 0
1133 while item_nbr < len(bsklist)
1134 let path_spec = bsklist[item_nbr]
1135 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1136 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1137 let bsklist[item_nbr] = path_spec . '/*'
1138 let item_nbr += 1
1139 endwhile
1140 endif
1141
1142 " Option bsk will also include these environment variables if defined.
1143 " If they're defined, verify they appear in the option value.
1144 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001145 if exists(var)
1146 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001147 let varvalue = substitute(varvalue, '/$', '', '')
1148 let varvalue .= '/*'
1149 let found = (index(bsklist, varvalue) >= 0)
1150 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001151 endif
1152 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001153
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001154 " Duplicates from environment variables should be filtered out (option has
1155 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1156 " so that we see what happens on startup.
1157 let after =<< trim [CODE]
1158 let bsklist = split(&backupskip, ',')
1159 call assert_equal(uniq(copy(bsklist)), bsklist)
1160 call writefile(['errors:'] + v:errors, 'Xtestout')
1161 qall
1162 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001163 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001164 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1165
1166 let saveenv = {}
1167 for var in ['TMPDIR', 'TMP', 'TEMP']
1168 let saveenv[var] = getenv(var)
1169 call setenv(var, '/duplicate/path')
1170 endfor
1171
Christian Brabandtad503fe2025-04-16 20:25:47 +02001172 " unset $HOME, so that it won't try to read init files
1173 let saveenv['HOME'] = getenv("HOME")
1174 call setenv('HOME', v:null)
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001175 exe 'silent !' . cmd
1176 call assert_equal(['errors:'], readfile('Xtestout'))
1177
1178 " restore environment variables
Christian Brabandtad503fe2025-04-16 20:25:47 +02001179 for var in ['TMPDIR', 'TMP', 'TEMP', 'HOME']
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001180 call setenv(var, saveenv[var])
1181 endfor
1182
1183 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001184
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001185 " Duplicates should be filtered out (option has P_NODUP)
1186 let backupskip = &backupskip
1187 set backupskip=
1188 set backupskip+=/test/dir
1189 set backupskip+=/other/dir
1190 set backupskip+=/test/dir
1191 call assert_equal('/test/dir,/other/dir', &backupskip)
1192 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001193endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001194
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001195func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001196 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001197
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001198 " Test copy option from current buffer in window
1199 split
1200 enew
1201 setlocal numberwidth=5
1202 wincmd w
1203 call assert_equal(4,&numberwidth)
1204 bnext
1205 call assert_equal(5,&numberwidth)
1206 bw!
1207 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001208
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001209 " Test copy value from window that used to be display the buffer
1210 split
1211 enew
1212 setlocal numberwidth=6
1213 bnext
1214 wincmd w
1215 call assert_equal(4,&numberwidth)
1216 bnext
1217 call assert_equal(6,&numberwidth)
1218 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001219
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001220 " Test that if buffer is current, don't use the stale cached value
1221 " from the last time the buffer was displayed.
1222 split
1223 enew
1224 setlocal numberwidth=7
1225 bnext
1226 bnext
1227 setlocal numberwidth=8
1228 wincmd w
1229 call assert_equal(4,&numberwidth)
1230 bnext
1231 call assert_equal(8,&numberwidth)
1232 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001233
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001234 " Test value is not copied if window already has seen the buffer
1235 enew
1236 split
1237 setlocal numberwidth=9
1238 bnext
1239 setlocal numberwidth=10
1240 wincmd w
1241 call assert_equal(4,&numberwidth)
1242 bnext
1243 call assert_equal(4,&numberwidth)
1244 bw!
1245
1246 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001247endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001248
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001249def Test_split_copy_options()
1250 var values = [
1251 ['cursorbind', true, false],
1252 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1253 ['list', true, 0],
1254 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1255 ['number', true, 0],
1256 ['relativenumber', true, false],
1257 ['scrollbind', true, false],
1258 ['smoothscroll', true, false],
1259 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1260 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1261 ['wrap', false, true],
1262 ]
1263 if has('linebreak')
1264 values += [
1265 ['breakindent', true, false],
1266 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1267 ['linebreak', true, false],
1268 ['numberwidth', 7, 4],
1269 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1270 ]
1271 endif
1272 if has('rightleft')
1273 values += [
1274 ['rightleft', true, false],
1275 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1276 ]
1277 endif
1278 if has('statusline')
1279 values += [
1280 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1281 ]
1282 endif
1283 if has('spell')
1284 values += [
1285 ['spell', true, false],
1286 ]
1287 endif
1288 if has('syntax')
1289 values += [
1290 ['cursorcolumn', true, false],
1291 ['cursorline', true, false],
1292 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1293 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1294 ]
1295 endif
1296 if has('diff')
1297 values += [
1298 ['diff', true, false],
1299 ]
1300 endif
1301 if has('conceal')
1302 values += [
1303 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1304 ['conceallevel', '3', &conceallevel],
1305 ]
1306 endif
1307 if has('terminal')
1308 values += [
1309 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1310 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1311 ]
1312 endif
1313 if has('folding')
1314 values += [
1315 ['foldcolumn', 5, &foldcolumn],
1316 ['foldenable', false, true],
1317 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1318 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1319 ['foldlevel', 4, &foldlevel],
1320 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1321 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1322 ['foldminlines', 3, &foldminlines],
1323 ['foldnestmax', 17, &foldnestmax],
1324 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1325 ]
1326 endif
1327 if has('signs')
1328 values += [
1329 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1330 ]
1331 endif
1332
1333 # set options to non-default value
1334 for item in values
1335 exe $'&l:{item[0]} = {item[1]}'
1336 endfor
1337
1338 # check values are set in new window
1339 split
1340 for item in values
1341 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1342 endfor
1343
1344 # restore
1345 close
1346 for item in values
1347 exe $'&l:{item[0]} = {item[2]}'
1348 endfor
1349enddef
1350
Bram Moolenaarfc089602018-06-24 16:53:35 +02001351func Test_shortmess_F()
1352 new
1353 call assert_match('\[No Name\]', execute('file'))
1354 set shortmess+=F
1355 call assert_match('\[No Name\]', execute('file'))
1356 call assert_match('^\s*$', execute('file foo'))
1357 call assert_match('foo', execute('file'))
1358 set shortmess-=F
1359 call assert_match('bar', execute('file bar'))
1360 call assert_match('bar', execute('file'))
1361 set shortmess&
1362 bwipe
1363endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001364
1365func Test_shortmess_F2()
1366 e file1
1367 e file2
1368 call assert_match('file1', execute('bn', ''))
1369 call assert_match('file2', execute('bn', ''))
1370 set shortmess+=F
1371 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001372 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001373 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001374 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001375 set hidden
1376 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001377 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001378 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001379 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001380 set nohidden
1381 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001382 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001383 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001384 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001385 set shortmess&
1386 call assert_match('file1', execute('bn', ''))
1387 call assert_match('file2', execute('bn', ''))
1388 bwipe
1389 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001390 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001391endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001392
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001393func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001394 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001395
1396 set hidden
1397 set autoread
1398 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001399 e Xotherfile
1400 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001401 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001402 echo ''
1403
1404 if has('nanotime')
1405 sleep 10m
1406 else
1407 sleep 2
1408 endif
1409 call writefile(['bar'], 'X_dummy')
1410 bprev
1411 call assert_equal('', Screenline(&lines))
1412 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1413
1414 if has('nanotime')
1415 sleep 10m
1416 else
1417 sleep 2
1418 endif
1419 call writefile(['baz'], 'X_dummy')
1420 checktime
1421 call assert_equal('', Screenline(&lines))
1422 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001423
1424 set shortmess&
1425 set autoread&
1426 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001427 bwipe X_dummy
1428 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001429endfunc
1430
Bram Moolenaar375e3392019-01-31 18:26:10 +01001431func Test_local_scrolloff()
1432 set so=5
1433 set siso=7
1434 split
1435 call assert_equal(5, &so)
1436 setlocal so=3
1437 call assert_equal(3, &so)
1438 wincmd w
1439 call assert_equal(5, &so)
1440 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001441 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001442 setlocal so<
1443 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001444 setglob so=8
1445 call assert_equal(8, &so)
1446 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001447 setlocal so=0
1448 call assert_equal(0, &so)
1449 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001450 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001451
1452 call assert_equal(7, &siso)
1453 setlocal siso=3
1454 call assert_equal(3, &siso)
1455 wincmd w
1456 call assert_equal(7, &siso)
1457 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001458 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001459 setlocal siso<
1460 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001461 setglob siso=4
1462 call assert_equal(4, &siso)
1463 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001464 setlocal siso=0
1465 call assert_equal(0, &siso)
1466 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001467 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001468
1469 close
1470 set so&
1471 set siso&
1472endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001473
1474func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001475 CheckFunction reltimefloat
1476
Bram Moolenaar449ac472019-04-03 21:42:35 +02001477 new
1478 call setline(1, 'empty')
1479 redraw
1480 set writedelay=10
1481 let start = reltime()
1482 call setline(1, repeat('x', 70))
1483 redraw
1484 let elapsed = reltimefloat(reltime(start))
1485 set writedelay=0
1486 " With 'writedelay' set should take at least 30 * 10 msec
1487 call assert_inrange(30 * 0.01, 999.0, elapsed)
1488
1489 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001490endfunc
1491
1492func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001493 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001494 set visualbell
1495 call assert_beeps('normal 0h')
1496 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001497 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001498endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001499
1500" Test for the 'write' option
1501func Test_write()
1502 new
1503 call setline(1, ['L1'])
1504 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001505 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001506 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001507 " close swapfile
1508 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001509endfunc
1510
1511" Test for 'buftype' option
1512func Test_buftype()
1513 new
1514 call setline(1, ['L1'])
1515 set buftype=nowrite
1516 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001517
1518 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1519 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001520 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001521 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1522 endfor
1523
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001524 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001525endfunc
1526
Bram Moolenaar578fe942020-02-27 21:32:51 +01001527" Test for the 'rightleftcmd' option
1528func Test_rightleftcmd()
1529 CheckFeature rightleft
1530 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001531
1532 let g:l = []
1533 func AddPos()
1534 call add(g:l, screencol())
1535 return ''
1536 endfunc
1537 cmap <expr> <F2> AddPos()
1538
zeertzjqbb404f52022-07-23 06:25:29 +01001539 set rightleftcmd=
1540 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1541 \ "\<Right>\<F2>\<Esc>", 'xt')
1542 call assert_equal([2, 5, 3, 4], g:l)
1543
1544 let g:l = []
1545 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001546 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1547 \ "\<Left>\<F2>\<Esc>", 'xt')
1548 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1549
1550 cunmap <F2>
1551 unlet g:l
1552 set rightleftcmd&
1553 set rightleft&
1554endfunc
1555
zeertzjq28c162f2022-08-14 14:49:50 +01001556" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001557func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001558 " redraw to avoid matching previous messages
1559 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001560 set debug=beep
1561 exe "normal \<C-c>"
1562 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001563 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001564 " also check a line above, with a certain window width the colon is there
1565 call assert_match('Test_debug_option:$',
1566 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001567 set debug&
1568endfunc
1569
Bram Moolenaar004a6782020-04-11 17:09:31 +02001570" Test for the default CDPATH option
1571func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001572 let after =<< trim [CODE]
1573 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1574 call writefile(v:errors, 'Xtestout')
1575 qall
1576 [CODE]
1577 if has('unix')
1578 let $CDPATH='/path/to/dir1:/path/to/dir2'
1579 else
1580 let $CDPATH='/path/to/dir1;/path/to/dir2'
1581 endif
1582 if RunVim([], after, '')
1583 call assert_equal([], readfile('Xtestout'))
1584 call delete('Xtestout')
1585 endif
1586endfunc
1587
1588" Test for setting keycodes using set
1589func Test_opt_set_keycode()
1590 call assert_fails('set <t_k1=l', 'E474:')
1591 call assert_fails('set <Home=l', 'E474:')
1592 set <t_k9>=abcd
1593 call assert_equal('abcd', &t_k9)
1594 set <t_k9>&
1595 set <F9>=xyz
1596 call assert_equal('xyz', &t_k9)
1597 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001598
1599 " should we test all of them?
1600 set t_Ce=testCe
1601 set t_Cs=testCs
1602 set t_Us=testUs
1603 set t_ds=testds
1604 set t_Ds=testDs
1605 call assert_equal('testCe', &t_Ce)
1606 call assert_equal('testCs', &t_Cs)
1607 call assert_equal('testUs', &t_Us)
1608 call assert_equal('testds', &t_ds)
1609 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001610endfunc
1611
1612" Test for changing options in a sandbox
1613func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001614 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001615 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001616 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001617 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001618 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001619endfunc
1620
Milly484face2024-10-12 11:26:06 +02001621" Test for setting string global-local option value
1622func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001623 setglobal equalprg=gprg
1624 setlocal equalprg=lprg
1625 call assert_equal('gprg', &g:equalprg)
1626 call assert_equal('lprg', &l:equalprg)
1627 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001628
1629 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001630 set equalprg<
1631 call assert_equal('', &l:equalprg)
1632 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001633
1634 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001635 setglobal equalprg=gnewprg
1636 setlocal equalprg=lnewprg
1637 setlocal equalprg<
1638 call assert_equal('gnewprg', &l:equalprg)
1639 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001640
Milly484face2024-10-12 11:26:06 +02001641 set equalprg&
1642endfunc
1643
1644" Test for setting number global-local option value
1645func Test_set_number_global_local_option()
1646 setglobal scrolloff=10
1647 setlocal scrolloff=12
1648 call assert_equal(10, &g:scrolloff)
1649 call assert_equal(12, &l:scrolloff)
1650 call assert_equal(12, &scrolloff)
1651
1652 " :set {option}< set the effective value of {option} to its global value.
1653 set scrolloff<
1654 call assert_equal(10, &l:scrolloff)
1655 call assert_equal(10, &scrolloff)
1656
1657 " :setlocal {option}< removes the local value, so that the global value will be used.
1658 setglobal scrolloff=15
1659 setlocal scrolloff=18
1660 setlocal scrolloff<
1661 call assert_equal(-1, &l:scrolloff)
1662 call assert_equal(15, &scrolloff)
1663
1664 set scrolloff&
1665endfunc
1666
1667" Test for setting boolean global-local option value
1668func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001669 setglobal autoread
1670 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001671 call assert_equal(1, &g:autoread)
1672 call assert_equal(0, &l:autoread)
1673 call assert_equal(0, &autoread)
1674
1675 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001676 set autoread<
Milly484face2024-10-12 11:26:06 +02001677 call assert_equal(1, &l:autoread)
1678 call assert_equal(1, &autoread)
1679
1680 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001681 setglobal noautoread
1682 setlocal autoread
1683 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001684 call assert_equal(-1, &l:autoread)
1685 call assert_equal(0, &autoread)
1686
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001687 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001688endfunc
1689
Dominique Pelle042414f2021-07-12 21:43:19 +02001690func Test_set_in_sandbox()
1691 " Some boolean options cannot be set in sandbox, some can.
1692 call assert_fails('sandbox set modelineexpr', 'E48:')
1693 sandbox set number
1694 call assert_true(&number)
1695 set number&
1696
1697 " Some boolean options cannot be set in sandbox, some can.
1698 if has('python') || has('python3')
1699 call assert_fails('sandbox set pyxversion=3', 'E48:')
1700 endif
1701 sandbox set tabstop=4
1702 call assert_equal(4, &tabstop)
1703 set tabstop&
1704
1705 " Some string options cannot be set in sandbox, some can.
1706 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1707 sandbox set filetype=perl
1708 call assert_equal('perl', &filetype)
1709 set filetype&
1710endfunc
1711
Milly484face2024-10-12 11:26:06 +02001712" Test for setting string option value
1713func Test_set_string_option()
1714 " :set {option}=
1715 set makeprg=
1716 call assert_equal('', &mp)
1717 set makeprg=abc
1718 call assert_equal('abc', &mp)
1719
1720 " :set {option}:
1721 set makeprg:
1722 call assert_equal('', &mp)
1723 set makeprg:abc
1724 call assert_equal('abc', &mp)
1725
1726 " Let string
1727 let &makeprg = ''
1728 call assert_equal('', &mp)
1729 let &makeprg = 'abc'
1730 call assert_equal('abc', &mp)
1731
1732 " Let number converts to string
1733 let &makeprg = 42
1734 call assert_equal('42', &mp)
1735
1736 " Appending
1737 set makeprg=abc
1738 set makeprg+=def
1739 call assert_equal('abcdef', &mp)
1740 set makeprg+=def
1741 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1742 let &makeprg .= 'gh'
1743 call assert_equal('abcdefdefgh', &mp)
1744 let &makeprg ..= 'ij'
1745 call assert_equal('abcdefdefghij', &mp)
1746
1747 " Removing
1748 set makeprg=abcdefghi
1749 set makeprg-=def
1750 call assert_equal('abcghi', &mp)
1751 set makeprg-=def
1752 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1753
1754 " Prepending
1755 set makeprg=abc
1756 set makeprg^=def
1757 call assert_equal('defabc', &mp)
1758 set makeprg^=def
1759 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1760
1761 set makeprg&
1762endfunc
1763
1764" Test for setting string comma-separated list option value
1765func Test_set_string_comma_list_option()
1766 " :set {option}=
1767 set wildignore=
1768 call assert_equal('', &wildignore)
1769 set wildignore=*.png
1770 call assert_equal('*.png', &wildignore)
1771
1772 " :set {option}:
1773 set wildignore:
1774 call assert_equal('', &wildignore)
1775 set wildignore:*.png
1776 call assert_equal('*.png', &wildignore)
1777
1778 " Let string
1779 let &wildignore = ''
1780 call assert_equal('', &wildignore)
1781 let &wildignore = '*.png'
1782 call assert_equal('*.png', &wildignore)
1783
1784 " Let number converts to string
1785 let &wildignore = 42
1786 call assert_equal('42', &wildignore)
1787
1788 " Appending
1789 set wildignore=*.png
1790 set wildignore+=*.jpg
1791 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1792 set wildignore+=*.jpg
1793 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1794 set wildignore+=jpg
1795 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1796 let &wildignore .= 'foo'
1797 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1798 let &wildignore ..= 'bar'
1799 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1800
1801 " Removing
1802 set wildignore=*.png,*.jpg,*.obj
1803 set wildignore-=*.jpg
1804 call assert_equal('*.png,*.obj', &wildignore)
1805 set wildignore-=*.jpg
1806 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1807 set wildignore-=jpg
1808 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1809
1810 " Prepending
1811 set wildignore=*.png
1812 set wildignore^=*.jpg
1813 call assert_equal('*.jpg,*.png', &wildignore)
1814 set wildignore^=*.jpg
1815 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1816 set wildignore^=jpg
1817 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1818
1819 set wildignore&
1820endfunc
1821
1822" Test for setting string flags option value
1823func Test_set_string_flags_option()
1824 " :set {option}=
1825 set formatoptions=
1826 call assert_equal('', &fo)
1827 set formatoptions=abc
1828 call assert_equal('abc', &fo)
1829
1830 " :set {option}:
1831 set formatoptions:
1832 call assert_equal('', &fo)
1833 set formatoptions:abc
1834 call assert_equal('abc', &fo)
1835
1836 " Let string
1837 let &formatoptions = ''
1838 call assert_equal('', &fo)
1839 let &formatoptions = 'abc'
1840 call assert_equal('abc', &fo)
1841
1842 " Let number converts to string
1843 let &formatoptions = 12
1844 call assert_equal('12', &fo)
1845
1846 " Appending
1847 set formatoptions=abc
1848 set formatoptions+=pqr
1849 call assert_equal('abcpqr', &fo)
1850 set formatoptions+=pqr
1851 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1852 let &formatoptions .= 'r'
1853 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1854 let &formatoptions ..= 'r'
1855 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1856
1857 " Removing
1858 set formatoptions=abcpqr
1859 set formatoptions-=cp
1860 call assert_equal('abqr', &fo)
1861 set formatoptions-=cp
1862 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1863 set formatoptions-=ar
1864 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1865
1866 " Prepending
1867 set formatoptions=abc
1868 set formatoptions^=pqr
1869 call assert_equal('pqrabc', &fo)
1870 set formatoptions^=qr
1871 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1872
1873 set formatoptions&
1874endfunc
1875
1876" Test for setting number option value
1877func Test_set_number_option()
1878 " :set {option}=
1879 set scrolljump=5
1880 call assert_equal(5, &sj)
1881 set scrolljump=-3
1882 call assert_equal(-3, &sj)
1883
1884 " :set {option}:
1885 set scrolljump:7
1886 call assert_equal(7, &sj)
1887 set scrolljump:-5
1888 call assert_equal(-5, &sj)
1889
1890 " Set hex
1891 set scrolljump=0x10
1892 call assert_equal(16, &sj)
1893 set scrolljump=-0x10
1894 call assert_equal(-16, &sj)
1895 set scrolljump=0X12
1896 call assert_equal(18, &sj)
1897 set scrolljump=-0X12
1898 call assert_equal(-18, &sj)
1899
1900 " Set octal
1901 set scrolljump=010
1902 call assert_equal(8, &sj)
1903 set scrolljump=-010
1904 call assert_equal(-8, &sj)
1905 set scrolljump=0o12
1906 call assert_equal(10, &sj)
1907 set scrolljump=-0o12
1908 call assert_equal(-10, &sj)
1909 set scrolljump=0O15
1910 call assert_equal(13, &sj)
1911 set scrolljump=-0O15
1912 call assert_equal(-13, &sj)
1913
1914 " Let number
1915 let &scrolljump = 4
1916 call assert_equal(4, &sj)
1917 let &scrolljump = -6
1918 call assert_equal(-6, &sj)
1919
1920 " Let numeric string converts to number
1921 let &scrolljump = '7'
1922 call assert_equal(7, &sj)
1923 let &scrolljump = '-9'
1924 call assert_equal(-9, &sj)
1925
1926 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001927 set shiftwidth=4
1928 set sw+=2
1929 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001930 let &shiftwidth += 2
1931 call assert_equal(8, &sw)
1932
1933 " Decrementing
1934 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001935 set sw-=2
1936 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001937 let &shiftwidth -= 2
1938 call assert_equal(2, &sw)
1939
1940 " Multiplying
1941 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001942 set sw^=2
1943 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001944 let &shiftwidth *= 2
1945 call assert_equal(16, &sw)
1946
1947 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001948 set shiftwidth&
1949endfunc
1950
Milly484face2024-10-12 11:26:06 +02001951" Test for setting boolean option value
1952func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001953 set number&
Milly484face2024-10-12 11:26:06 +02001954
1955 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001956 set number
1957 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001958
1959 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001960 set nonu
1961 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001962
1963 " :set {option}!
1964 set number!
1965 call assert_equal(1, &nu)
1966 set number!
1967 call assert_equal(0, &nu)
1968
1969 " :set inv{option}
1970 set invnumber
1971 call assert_equal(1, &nu)
1972 set invnumber
1973 call assert_equal(0, &nu)
1974
1975 " Let number
1976 let &number = 1
1977 call assert_equal(1, &nu)
1978 let &number = 0
1979 call assert_equal(0, &nu)
1980
1981 " Let numeric string converts to number
1982 let &number = '1'
1983 call assert_equal(1, &nu)
1984 let &number = '0'
1985 call assert_equal(0, &nu)
1986
1987 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001988 let &nu = v:true
1989 call assert_equal(1, &nu)
1990 let &nu = v:false
1991 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001992
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001993 set number&
1994endfunc
1995
Milly484face2024-10-12 11:26:06 +02001996" Test for setting string option errors
1997func Test_set_string_option_errors()
1998 " :set no{option}
1999 call assert_fails('set nomakeprg', 'E474:')
2000 call assert_fails('setlocal nomakeprg', 'E474:')
2001 call assert_fails('setglobal nomakeprg', 'E474:')
2002
2003 " :set inv{option}
2004 call assert_fails('set invmakeprg', 'E474:')
2005 call assert_fails('setlocal invmakeprg', 'E474:')
2006 call assert_fails('setglobal invmakeprg', 'E474:')
2007
2008 " :set {option}!
2009 call assert_fails('set makeprg!', 'E488:')
2010 call assert_fails('setlocal makeprg!', 'E488:')
2011 call assert_fails('setglobal makeprg!', 'E488:')
2012
2013 " Invalid trailing chars
2014 call assert_fails('set makeprg??', 'E488:')
2015 call assert_fails('setlocal makeprg??', 'E488:')
2016 call assert_fails('setglobal makeprg??', 'E488:')
2017 call assert_fails('set makeprg&&', 'E488:')
2018 call assert_fails('setlocal makeprg&&', 'E488:')
2019 call assert_fails('setglobal makeprg&&', 'E488:')
2020 call assert_fails('set makeprg<<', 'E488:')
2021 call assert_fails('setlocal makeprg<<', 'E488:')
2022 call assert_fails('setglobal makeprg<<', 'E488:')
2023 call assert_fails('set makeprg@', 'E488:')
2024 call assert_fails('setlocal makeprg@', 'E488:')
2025 call assert_fails('setglobal makeprg@', 'E488:')
2026
2027 " Invalid type
2028 call assert_fails("let &makeprg = ['xxx']", 'E730:')
2029endfunc
2030
2031" Test for setting number option errors
2032func Test_set_number_option_errors()
2033 " :set no{option}
2034 call assert_fails('set notabstop', 'E474:')
2035 call assert_fails('setlocal notabstop', 'E474:')
2036 call assert_fails('setglobal notabstop', 'E474:')
2037
2038 " :set inv{option}
2039 call assert_fails('set invtabstop', 'E474:')
2040 call assert_fails('setlocal invtabstop', 'E474:')
2041 call assert_fails('setglobal invtabstop', 'E474:')
2042
2043 " :set {option}!
2044 call assert_fails('set tabstop!', 'E488:')
2045 call assert_fails('setlocal tabstop!', 'E488:')
2046 call assert_fails('setglobal tabstop!', 'E488:')
2047
2048 " Invalid trailing chars
2049 call assert_fails('set tabstop??', 'E488:')
2050 call assert_fails('setlocal tabstop??', 'E488:')
2051 call assert_fails('setglobal tabstop??', 'E488:')
2052 call assert_fails('set tabstop&&', 'E488:')
2053 call assert_fails('setlocal tabstop&&', 'E488:')
2054 call assert_fails('setglobal tabstop&&', 'E488:')
2055 call assert_fails('set tabstop<<', 'E488:')
2056 call assert_fails('setlocal tabstop<<', 'E488:')
2057 call assert_fails('setglobal tabstop<<', 'E488:')
2058 call assert_fails('set tabstop@', 'E488:')
2059 call assert_fails('setlocal tabstop@', 'E488:')
2060 call assert_fails('setglobal tabstop@', 'E488:')
2061
2062 " Not a number
2063 call assert_fails('set tabstop=', 'E521:')
2064 call assert_fails('setlocal tabstop=', 'E521:')
2065 call assert_fails('setglobal tabstop=', 'E521:')
2066 call assert_fails('set tabstop=x', 'E521:')
2067 call assert_fails('setlocal tabstop=x', 'E521:')
2068 call assert_fails('setglobal tabstop=x', 'E521:')
2069 call assert_fails('set tabstop=1x', 'E521:')
2070 call assert_fails('setlocal tabstop=1x', 'E521:')
2071 call assert_fails('setglobal tabstop=1x', 'E521:')
2072 call assert_fails('set tabstop=-x', 'E521:')
2073 call assert_fails('setlocal tabstop=-x', 'E521:')
2074 call assert_fails('setglobal tabstop=-x', 'E521:')
2075 call assert_fails('set tabstop=0x', 'E521:')
2076 call assert_fails('setlocal tabstop=0x', 'E521:')
2077 call assert_fails('setglobal tabstop=0x', 'E521:')
2078 call assert_fails('set tabstop=0o', 'E521:')
2079 call assert_fails('setlocal tabstop=0o', 'E521:')
2080 call assert_fails('setglobal tabstop=0o', 'E521:')
2081 call assert_fails("let &tabstop = 'x'", 'E521:')
2082 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2083 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2084
2085 " Invalid type
2086 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2087endfunc
2088
2089" Test for setting boolean option errors
2090func Test_set_boolean_option_errors()
2091 " :set {option}=
2092 call assert_fails('set number=', 'E474:')
2093 call assert_fails('setlocal number=', 'E474:')
2094 call assert_fails('setglobal number=', 'E474:')
2095 call assert_fails('set number=1', 'E474:')
2096 call assert_fails('setlocal number=1', 'E474:')
2097 call assert_fails('setglobal number=1', 'E474:')
2098
2099 " :set {option}:
2100 call assert_fails('set number:', 'E474:')
2101 call assert_fails('setlocal number:', 'E474:')
2102 call assert_fails('setglobal number:', 'E474:')
2103 call assert_fails('set number:1', 'E474:')
2104 call assert_fails('setlocal number:1', 'E474:')
2105 call assert_fails('setglobal number:1', 'E474:')
2106
2107 " :set {option}+=
2108 call assert_fails('set number+=1', 'E474:')
2109 call assert_fails('setlocal number+=1', 'E474:')
2110 call assert_fails('setglobal number+=1', 'E474:')
2111
2112 " :set {option}^=
2113 call assert_fails('set number^=1', 'E474:')
2114 call assert_fails('setlocal number^=1', 'E474:')
2115 call assert_fails('setglobal number^=1', 'E474:')
2116
2117 " :set {option}-=
2118 call assert_fails('set number-=1', 'E474:')
2119 call assert_fails('setlocal number-=1', 'E474:')
2120 call assert_fails('setglobal number-=1', 'E474:')
2121
2122 " Invalid trailing chars
2123 call assert_fails('set number!!', 'E488:')
2124 call assert_fails('setlocal number!!', 'E488:')
2125 call assert_fails('setglobal number!!', 'E488:')
2126 call assert_fails('set number??', 'E488:')
2127 call assert_fails('setlocal number??', 'E488:')
2128 call assert_fails('setglobal number??', 'E488:')
2129 call assert_fails('set number&&', 'E488:')
2130 call assert_fails('setlocal number&&', 'E488:')
2131 call assert_fails('setglobal number&&', 'E488:')
2132 call assert_fails('set number<<', 'E488:')
2133 call assert_fails('setlocal number<<', 'E488:')
2134 call assert_fails('setglobal number<<', 'E488:')
2135 call assert_fails('set number@', 'E488:')
2136 call assert_fails('setlocal number@', 'E488:')
2137 call assert_fails('setglobal number@', 'E488:')
2138
2139 " Invalid type
2140 call assert_fails("let &number = 'xxx'", 'E521:')
2141endfunc
2142
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002143" Test for the 'window' option
2144func Test_window_opt()
2145 " Needs only one open widow
2146 %bw!
2147 call setline(1, range(1, 8))
2148 set window=5
2149 exe "normal \<C-F>"
2150 call assert_equal(4, line('w0'))
2151 exe "normal \<C-F>"
2152 call assert_equal(7, line('w0'))
2153 exe "normal \<C-F>"
2154 call assert_equal(8, line('w0'))
2155 exe "normal \<C-B>"
2156 call assert_equal(5, line('w0'))
2157 exe "normal \<C-B>"
2158 call assert_equal(2, line('w0'))
2159 exe "normal \<C-B>"
2160 call assert_equal(1, line('w0'))
2161 set window=1
2162 exe "normal gg\<C-F>"
2163 call assert_equal(2, line('w0'))
2164 exe "normal \<C-F>"
2165 call assert_equal(3, line('w0'))
2166 exe "normal \<C-B>"
2167 call assert_equal(2, line('w0'))
2168 exe "normal \<C-B>"
2169 call assert_equal(1, line('w0'))
2170 enew!
2171 set window&
2172endfunc
2173
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002174" Test for the 'winminheight' option
2175func Test_opt_winminheight()
2176 only!
2177 let &winheight = &lines + 4
2178 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2179 call assert_true(&winminheight <= &lines)
2180 set winminheight&
2181 set winheight&
2182endfunc
2183
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002184func Test_opt_winminheight_term()
2185 CheckRunVimInTerminal
2186
2187 " The tabline should be taken into account.
2188 let lines =<< trim END
2189 set wmh=0 stal=2
2190 below sp | wincmd _
2191 below sp | wincmd _
2192 below sp | wincmd _
2193 below sp
2194 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002195 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002196 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2197 call term_sendkeys(buf, ":set wmh=1\n")
2198 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2199
2200 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002201endfunc
2202
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002203func Test_opt_winminheight_term_tabs()
2204 CheckRunVimInTerminal
2205
2206 " The tabline should be taken into account.
2207 let lines =<< trim END
2208 set wmh=0 stal=2
2209 split
2210 split
2211 split
2212 split
2213 tabnew
2214 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002215 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002216 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2217 call term_sendkeys(buf, ":set wmh=1\n")
2218 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2219
2220 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002221endfunc
2222
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002223" Test for the 'winminwidth' option
2224func Test_opt_winminwidth()
2225 only!
2226 let &winwidth = &columns + 4
2227 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2228 call assert_true(&winminwidth <= &columns)
2229 set winminwidth&
2230 set winwidth&
2231endfunc
2232
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002233" Test for setting option value containing spaces with isfname+=32
2234func Test_isfname_with_options()
2235 set isfname+=32
2236 setlocal keywordprg=:term\ help.exe
2237 call assert_equal(':term help.exe', &keywordprg)
2238 set isfname&
2239 setlocal keywordprg&
2240endfunc
2241
Bram Moolenaar74667062020-12-28 15:41:41 +01002242" Test that resetting laststatus does change scroll option
2243func Test_opt_reset_scroll()
2244 CheckRunVimInTerminal
2245 let vimrc =<< trim [CODE]
2246 set scroll=2
2247 set laststatus=2
2248 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002249 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002250 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2251 call term_sendkeys(buf, ":verbose set scroll?\n")
2252 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2253 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002254
2255 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002256 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002257endfunc
2258
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002259" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2260func Test_VIM_POSIX()
2261 let saved_VIM_POSIX = getenv("VIM_POSIX")
2262
2263 call setenv('VIM_POSIX', "1")
2264 let after =<< trim [CODE]
2265 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2266 qall
2267 [CODE]
2268 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002269 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002270 \ 'AS'], readfile('X_VIM_POSIX'))
2271 endif
2272
2273 call setenv('VIM_POSIX', v:null)
2274 let after =<< trim [CODE]
2275 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2276 qall
2277 [CODE]
2278 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002279 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002280 \ 'S'], readfile('X_VIM_POSIX'))
2281 endif
2282
2283 call delete('X_VIM_POSIX')
2284 call setenv('VIM_POSIX', saved_VIM_POSIX)
2285endfunc
2286
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002287" Test for setting an option to a Vi or Vim default
2288func Test_opt_default()
2289 set formatoptions&vi
2290 call assert_equal('vt', &formatoptions)
2291 set formatoptions&vim
2292 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002293
2294 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2295 set fencs=latin1
2296 set fencs&
2297 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2298 set fencs=latin1
2299 set all&
2300 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002301endfunc
2302
2303" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002304func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002305 %bw!
2306 let ht = &lines
2307 set cmdheight=9999
2308 call assert_equal(1, winheight(0))
2309 call assert_equal(ht - 1, &cmdheight)
2310 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002311
2312 " The status line should be taken into account.
2313 set laststatus=2
2314 set cmdheight=9999
2315 call assert_equal(ht - 2, &cmdheight)
2316 set cmdheight& laststatus&
2317
2318 " The tabline should be taken into account only non-GUI.
2319 set showtabline=2
2320 set cmdheight=9999
2321 if has('gui_running')
2322 call assert_equal(ht - 1, &cmdheight)
2323 else
2324 call assert_equal(ht - 2, &cmdheight)
2325 endif
2326 set cmdheight& showtabline&
2327
2328 " The 'winminheight' should be taken into account.
2329 set winheight=3 winminheight=3
2330 split
2331 set cmdheight=9999
2332 call assert_equal(ht - 8, &cmdheight)
2333 %bw!
2334 set cmdheight& winminheight& winheight&
2335
2336 " Only the windows in the current tabpage are taken into account.
2337 set winheight=3 winminheight=3 showtabline=0
2338 split
2339 tabnew
2340 set cmdheight=9999
2341 call assert_equal(ht - 3, &cmdheight)
2342 %bw!
2343 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002344endfunc
2345
Dominique Pelle923dce22021-11-21 11:36:04 +00002346" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002347func Test_opt_control_char()
2348 set wildchar=^v
2349 call assert_equal("\<C-V>", nr2char(&wildchar))
2350 set wildcharm=^r
2351 call assert_equal("\<C-R>", nr2char(&wildcharm))
2352 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2353 set wildchar& wildcharm&
2354endfunc
2355
2356" Test for the 'errorbells' option
2357func Test_opt_errorbells()
2358 set errorbells
2359 call assert_beeps('s/a1b2/x1y2/')
2360 set noerrorbells
2361endfunc
2362
Dominique Pelle042414f2021-07-12 21:43:19 +02002363func Test_opt_scrolljump()
2364 help
2365 resize 10
2366
2367 " Test with positive 'scrolljump'.
2368 set scrolljump=2
2369 norm! Lj
2370 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2371 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2372 \ winsaveview())
2373
2374 " Test with negative 'scrolljump' (percentage of window height).
2375 set scrolljump=-40
2376 norm! ggLj
2377 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2378 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2379 \ winsaveview())
2380
2381 set scrolljump&
2382 bw
2383endfunc
2384
Bakudankun29f3a452021-12-11 12:28:08 +00002385" Test for the 'cdhome' option
2386func Test_opt_cdhome()
2387 if has('unix') || has('vms')
2388 throw 'Skipped: only works on non-Unix'
2389 endif
2390
2391 set cdhome&
2392 call assert_equal(0, &cdhome)
2393 set cdhome
2394
2395 " This paragraph is copied from Test_cd_no_arg().
2396 let path = getcwd()
2397 cd
2398 call assert_equal($HOME, getcwd())
2399 call assert_notequal(path, getcwd())
2400 exe 'cd ' .. fnameescape(path)
2401 call assert_equal(path, getcwd())
2402
2403 set cdhome&
2404endfunc
2405
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002406func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002407 CheckOption termguicolors
2408
2409 " Test default option completion
2410 set wildoptions=
2411 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2412 call assert_equal('"set termguicolors', @:)
2413
2414 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2415 call assert_equal('"set notermguicolors', @:)
2416
2417 " Test fuzzy option completion
2418 set wildoptions=fuzzy
2419 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2420 call assert_equal('"set termguicolors termencoding', @:)
2421
2422 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2423 call assert_equal('"set notermguicolors', @:)
2424
2425 set wildoptions=
2426endfunc
2427
Sean Dewar39c46b42022-05-12 17:44:29 +01002428func Test_switchbuf_reset()
2429 set switchbuf=useopen
2430 sblast
2431 call assert_equal(1, winnr('$'))
2432 set all&
2433 call assert_equal('', &switchbuf)
2434 sblast
2435 call assert_equal(2, winnr('$'))
2436 only!
2437endfunc
2438
zeertzjqfcba86c2022-09-22 13:57:32 +01002439" :set empty string for global 'keywordprg' falls back to ":help"
2440func Test_keywordprg_empty()
2441 let k = &keywordprg
2442 set keywordprg=man
2443 call assert_equal('man', &keywordprg)
2444 set keywordprg=
2445 call assert_equal(':help', &keywordprg)
2446 set keywordprg=man
2447 call assert_equal('man', &keywordprg)
2448 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2449 let &keywordprg = k
2450endfunc
2451
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002452" check that the very first buffer created does not have 'endoffile' set
2453func Test_endoffile_default()
2454 let after =<< trim [CODE]
2455 call writefile([execute('set eof?')], 'Xtestout')
2456 qall!
2457 [CODE]
2458 if RunVim([], after, '')
2459 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2460 endif
2461 call delete('Xtestout')
2462endfunc
2463
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002464" Test for setting the 'lines' and 'columns' options to a minimum value
2465func Test_set_min_lines_columns()
2466 let save_lines = &lines
2467 let save_columns = &columns
2468
2469 let after =<< trim END
2470 set nomore
2471 let msg = []
2472 let v:errmsg = ''
2473 silent! let &columns=0
2474 call add(msg, v:errmsg)
2475 silent! set columns=0
2476 call add(msg, v:errmsg)
2477 silent! call setbufvar('', '&columns', 0)
2478 call add(msg, v:errmsg)
2479 "call writefile(msg, 'XResultsetminlines')
2480 silent! let &lines=0
2481 call add(msg, v:errmsg)
2482 silent! set lines=0
2483 call add(msg, v:errmsg)
2484 silent! call setbufvar('', '&lines', 0)
2485 call add(msg, v:errmsg)
2486 call writefile(msg, 'XResultsetminlines')
2487 qall!
2488 END
2489 if RunVim([], after, '')
2490 call assert_equal(['E594: Need at least 12 columns',
2491 \ 'E594: Need at least 12 columns: columns=0',
2492 \ 'E594: Need at least 12 columns',
2493 \ 'E593: Need at least 2 lines',
2494 \ 'E593: Need at least 2 lines: lines=0',
2495 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2496 endif
2497
2498 call delete('XResultsetminlines')
2499 let &lines = save_lines
2500 let &columns = save_columns
2501endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002502
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002503" Test for reverting a string option value if the new value is invalid.
2504func Test_string_option_revert_on_failure()
2505 new
2506 let optlist = [
2507 \ ['ambiwidth', 'double', 'a123'],
2508 \ ['background', 'dark', 'a123'],
2509 \ ['backspace', 'eol', 'a123'],
2510 \ ['backupcopy', 'no', 'a123'],
2511 \ ['belloff', 'showmatch', 'a123'],
2512 \ ['breakindentopt', 'min:10', 'list'],
2513 \ ['bufhidden', 'wipe', 'a123'],
2514 \ ['buftype', 'nowrite', 'a123'],
2515 \ ['casemap', 'keepascii', 'a123'],
2516 \ ['cedit', "\<C-Y>", 'z'],
2517 \ ['colorcolumn', '10', 'z'],
2518 \ ['commentstring', '#%s', 'a123'],
2519 \ ['complete', '.,t', 'a'],
2520 \ ['completefunc', 'MyCmplFunc', '1a-'],
2521 \ ['completeopt', 'popup', 'a123'],
2522 \ ['completepopup', 'width:20', 'border'],
2523 \ ['concealcursor', 'v', 'xyz'],
2524 \ ['cpoptions', 'HJ', '~'],
2525 \ ['cryptmethod', 'zip', 'a123'],
2526 \ ['cursorlineopt', 'screenline', 'a123'],
2527 \ ['debug', 'throw', 'a123'],
2528 \ ['diffopt', 'iwhite', 'a123'],
2529 \ ['display', 'uhex', 'a123'],
2530 \ ['eadirection', 'hor', 'a123'],
2531 \ ['encoding', 'utf-8', 'a123'],
2532 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002533 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002534 \ ['fileencoding', 'utf-8', 'a123,'],
2535 \ ['fileformat', 'mac', 'a123'],
2536 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002537 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002538 \ ['fillchars', 'diff:~', 'a123'],
2539 \ ['foldclose', 'all', 'a123'],
2540 \ ['foldmarker', '[[[,]]]', '[[['],
2541 \ ['foldmethod', 'marker', 'a123'],
2542 \ ['foldopen', 'percent', 'a123'],
2543 \ ['formatoptions', 'an', '*'],
2544 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2545 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002546 \ ['highlight', '!:CursorColumn', '8:'],
2547 \ ['keymodel', 'stopsel', 'a123'],
2548 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2549 \ ['lispoptions', 'expr:1', 'a123'],
2550 \ ['listchars', 'tab:->', 'tab:'],
2551 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002552 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002553 \ ['mkspellmem', '100000,1000,100', '100000'],
2554 \ ['mouse', 'nvi', 'z'],
2555 \ ['mousemodel', 'extend', 'a123'],
2556 \ ['nrformats', 'alpha', 'a123'],
2557 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2558 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2559 \ ['previewpopup', 'width:20', 'a123'],
2560 \ ['printoptions', 'paper:A4', 'a123:'],
2561 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2562 \ ['rulerformat', '%l', '%['],
2563 \ ['scrollopt', 'hor,jump', 'a123'],
2564 \ ['selection', 'exclusive', 'a123'],
2565 \ ['selectmode', 'cmd', 'a123'],
2566 \ ['sessionoptions', 'options', 'a123'],
2567 \ ['shortmess', 'w', '2'],
2568 \ ['showbreak', '>>', "\x01"],
2569 \ ['showcmdloc', 'statusline', 'a123'],
2570 \ ['signcolumn', 'no', 'a123'],
2571 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2572 \ ['spellfile', 'MySpell.en.add', "\x01"],
2573 \ ['spelllang', 'en', "#"],
2574 \ ['spelloptions', 'camel', 'a123'],
2575 \ ['spellsuggest', 'double', 'a123'],
2576 \ ['splitkeep', 'topline', 'a123'],
2577 \ ['statusline', '%f', '%['],
2578 \ ['swapsync', 'sync', 'a123'],
2579 \ ['switchbuf', 'usetab', 'a123'],
2580 \ ['syntax', 'abc', 'a^b'],
2581 \ ['tabline', '%f', '%['],
2582 \ ['tagcase', 'ignore', 'a123'],
2583 \ ['tagfunc', 'MyTagFunc', '1a-'],
2584 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2585 \ ['viewoptions', 'options', 'a123'],
2586 \ ['virtualedit', 'onemore', 'a123'],
2587 \ ['whichwrap', '<,>', '{,}'],
2588 \ ['wildmode', 'list', 'a123'],
2589 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002590 \ ]
2591 if has('gui')
2592 call add(optlist, ['browsedir', 'buffer', 'a123'])
2593 endif
2594 if has('clipboard_working')
2595 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2596 endif
2597 if has('win32')
2598 call add(optlist, ['completeslash', 'slash', 'a123'])
2599 endif
2600 if has('cscope')
2601 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2602 endif
2603 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002604 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2605 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2606 endif
2607 if has('keymap')
2608 call add(optlist, ['keymap', 'greek', '[]'])
2609 endif
2610 if has('mouseshape')
2611 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2612 endif
2613 if has('win32') && has('gui')
2614 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2615 endif
2616 if has('rightleft')
2617 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2618 endif
2619 if has('terminal')
2620 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2621 call add(optlist, ['termwinsize', '24x80', '100'])
2622 endif
2623 if has('win32') && has('terminal')
2624 call add(optlist, ['termwintype', 'winpty', 'a123'])
2625 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002626 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002627 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002628 endif
2629 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002630 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2631 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002632 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002633 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2634 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002635 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002636 call add(optlist, ['varsofttabstop', '12', 'a123'])
2637 call add(optlist, ['vartabstop', '4,20', '4,'])
2638 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002639 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002640 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002641 endif
2642 for opt in optlist
2643 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002644 try
2645 exe $"let &{opt[0]} = '{opt[1]}'"
2646 catch
2647 call assert_report($"Caught {v:exception} with {opt->string()}")
2648 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002649 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2650 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2651 exe $"let &{opt[0]} = save_opt"
2652 endfor
2653 bw!
2654endfunc
2655
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002656func Test_set_option_window_global_local()
2657 new Xbuffer1
2658 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2659 setlocal scrolloff=2
2660 setglobal scrolloff=3
2661 setl modified
2662 " A new buffer has its own window-local options
2663 hide enew
2664 call assert_equal(-1, &l:scrolloff)
2665 call assert_equal(3, &g:scrolloff)
2666 " A new window opened with its own buffer-local options
2667 new
2668 call assert_equal(-1, &l:scrolloff)
2669 call assert_equal(3, &g:scrolloff)
2670 " Re-open Xbuffer1 and it should use
2671 " the previous set window-local options
2672 b Xbuffer1
2673 call assert_equal(2, &l:scrolloff)
2674 call assert_equal(3, &g:scrolloff)
2675 bw!
2676 bw!
2677 let &g:scrolloff = _gso
2678endfunc
2679
2680func GetGlobalLocalWindowOptions()
2681 new
2682 sil! r $VIMRUNTIME/doc/options.txt
2683 " Filter for global or local to window
2684 v/^'.*'.*\n.*global or local to window |global-local/d
2685 " get option value and type
2686 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2687 sil %s/empty/""/g
2688 " split the result
2689 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2690 bw!
2691 return result
2692endfunc
2693
2694func Test_set_option_window_global_local_all()
2695 new Xbuffer2
2696
2697 let optionlist = GetGlobalLocalWindowOptions()
2698 for [opt, type, default] in optionlist
2699 let _old = eval('&g:' .. opt)
2700 if type == 'string'
2701 if opt == 'fillchars'
2702 exe 'setl ' .. opt .. '=vert:+'
2703 exe 'setg ' .. opt .. '=vert:+,fold:+'
2704 elseif opt == 'listchars'
2705 exe 'setl ' .. opt .. '=tab:>>'
2706 exe 'setg ' .. opt .. '=tab:++'
2707 elseif opt == 'virtualedit'
2708 exe 'setl ' .. opt .. '=all'
2709 exe 'setg ' .. opt .. '=block'
2710 else
2711 exe 'setl ' .. opt .. '=Local'
2712 exe 'setg ' .. opt .. '=Global'
2713 endif
2714 elseif type == 'number'
2715 exe 'setl ' .. opt .. '=5'
2716 exe 'setg ' .. opt .. '=10'
2717 endif
2718 setl modified
2719 hide enew
2720 if type == 'string'
2721 call assert_equal('', eval('&l:' .. opt))
2722 if opt == 'fillchars'
2723 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2724 elseif opt == 'listchars'
2725 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2726 elseif opt == 'virtualedit'
2727 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2728 else
2729 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2730 endif
2731 elseif type == 'number'
2732 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2733 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2734 endif
2735 bw!
2736 exe 'let &g:' .. opt .. '=' .. default
2737 endfor
2738 bw!
2739endfunc
2740
Christian Brabandt757593c2023-08-22 21:44:10 +02002741func Test_paste_depending_options()
2742 " setting the paste option, resets all dependent options
2743 " and will be reported correctly using :verbose set <option>?
2744 let lines =<< trim [CODE]
2745 " set paste test
2746 set autoindent
2747 set expandtab
2748 " disabled, because depends on compiled feature set
2749 " set hkmap
2750 " set revins
2751 " set varsofttabstop=8,32,8
2752 set ruler
2753 set showmatch
2754 set smarttab
2755 set softtabstop=4
2756 set textwidth=80
2757 set wrapmargin=10
2758
2759 source Xvimrc_paste2
2760
2761 redir > Xoutput_paste
2762 verbose set expandtab?
2763 verbose setg expandtab?
2764 verbose setl expandtab?
2765 redir END
2766
2767 qall!
2768 [CODE]
2769
2770 call writefile(lines, 'Xvimrc_paste', 'D')
2771 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2772 if !RunVim([], lines, '--clean')
2773 return
2774 endif
2775
2776 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2777 call assert_equal('noexpandtab', result[0])
2778 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2779 call assert_equal('noexpandtab', result[2])
2780 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2781 call assert_equal('noexpandtab', result[4])
2782 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2783
2784 call delete('Xoutput_paste')
2785endfunc
2786
2787func Test_binary_depending_options()
2788 " setting the paste option, resets all dependent options
2789 " and will be reported correctly using :verbose set <option>?
2790 let lines =<< trim [CODE]
2791 " set binary test
2792 set expandtab
2793
2794 source Xvimrc_bin2
2795
2796 redir > Xoutput_bin
2797 verbose set expandtab?
2798 verbose setg expandtab?
2799 verbose setl expandtab?
2800 redir END
2801
2802 qall!
2803 [CODE]
2804
2805 call writefile(lines, 'Xvimrc_bin', 'D')
2806 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2807 if !RunVim([], lines, '--clean')
2808 return
2809 endif
2810
2811 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2812 call assert_equal('noexpandtab', result[0])
2813 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2814 call assert_equal('noexpandtab', result[2])
2815 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2816 call assert_equal('noexpandtab', result[4])
2817 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2818
2819 call delete('Xoutput_bin')
2820endfunc
2821
Gregory Anders3695d0e2023-09-29 20:17:20 +02002822func Test_set_keyprotocol()
2823 CheckNotGui
2824
2825 let term = &term
2826 set term=ansi
2827 call assert_equal('', &t_TI)
2828
2829 " Setting 'keyprotocol' should affect terminal codes without needing to
2830 " reset 'term'
2831 set keyprotocol+=ansi:kitty
2832 call assert_equal("\<Esc>[=1;1u", &t_TI)
2833 let &term = term
2834endfunc
2835
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002836func Test_set_wrap()
2837 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2838 " cursor position.
2839 set wrap smoothscroll scrolloff=5
2840
2841 call setline(1, ['', 'aaaa'->repeat(500)])
2842 20 split
2843 20 vsplit
2844 norm 2G$
2845 redraw
2846 set nowrap
2847 call assert_equal(2, winline())
2848
2849 set wrap& smoothscroll& scrolloff&
2850endfunc
2851
zeertzjqcd3a13e2024-02-24 16:51:32 +01002852func Test_delcombine()
2853 new
2854 set backspace=indent,eol,start
2855
2856 set delcombine
2857 call setline(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 normal! 0x
2867 call assert_equal(':β', getline(1))
2868 exe "normal! A\<BS>"
2869 call assert_equal(':', getline(1))
2870
2871 set nodelcombine
2872 call setline(1, 'β̳̈:β̳̈')
2873 normal! 0x
2874 call assert_equal(':β̳̈', getline(1))
2875 exe "normal! A\<BS>"
2876 call assert_equal(':', getline(1))
2877
2878 set backspace& delcombine&
2879 bwipe!
2880endfunc
2881
Milly484face2024-10-12 11:26:06 +02002882" Should not raise errors when set missing-options.
2883func Test_set_missing_options()
2884 set autoprint
2885 set beautify
2886 set flash
2887 set graphic
2888 set hardtabs=8
2889 set mesg
2890 set novice
2891 set open
2892 set optimize
2893 set redraw
2894 set slowopen
2895 set sourceany
2896 set w300=23
2897 set w1200=23
2898 set w9600=23
2899endfunc
2900
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002901func Test_default_keyprotocol()
2902 " default value of keyprotocol
2903 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2904endfunc
2905
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002906" vim: shiftwidth=2 sts=2 expandtab