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