blob: 70570cf27669bcd741bc8e827281310b4d243726 [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Bram Moolenaarb00ef052020-09-12 14:53:53 +02003source shared.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02005source view_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02006
Milly6eca04e2024-10-21 22:20:51 +02007scriptencoding utf-8
8
Bram Moolenaar1e115362019-01-09 23:01:02 +01009func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020010 set whichwrap=b,s
11 call assert_equal('b,s', &whichwrap)
12
13 set whichwrap+=h,l
14 call assert_equal('b,s,h,l', &whichwrap)
15
16 set whichwrap+=h,l
17 call assert_equal('b,s,h,l', &whichwrap)
18
19 set whichwrap+=h,l
20 call assert_equal('b,s,h,l', &whichwrap)
21
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010022 set whichwrap=h,h
23 call assert_equal('h', &whichwrap)
24
25 set whichwrap=h,h,h
26 call assert_equal('h', &whichwrap)
27
Bram Moolenaar004a6782020-04-11 17:09:31 +020028 " For compatibility with Vim 3.0 and before, number values are also
29 " supported for 'whichwrap'
30 set whichwrap=1
31 call assert_equal('b', &whichwrap)
32 set whichwrap=2
33 call assert_equal('s', &whichwrap)
34 set whichwrap=4
35 call assert_equal('h,l', &whichwrap)
36 set whichwrap=8
37 call assert_equal('<,>', &whichwrap)
38 set whichwrap=16
39 call assert_equal('[,]', &whichwrap)
40 set whichwrap=31
41 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
42
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020043 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010044endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020045
Bram Moolenaar1e115362019-01-09 23:01:02 +010046func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010047 " This used to cause Vim to access uninitialized memory.
48 set isfname=
49 call assert_equal("~X", expand("~X"))
50 set isfname&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000051 " Test for setting 'isfname' to an unsupported character
52 let save_isfname = &isfname
53 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
54 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010055endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010056
zeertzjq0519ce02022-05-09 12:16:19 +010057" Test for getting the value of 'pastetoggle'
58func Test_pastetoggle()
59 " character with K_SPECIAL byte
60 let &pastetoggle = '…'
61 call assert_equal('…', &pastetoggle)
62 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
63
64 " modified character with K_SPECIAL byte
65 let &pastetoggle = '<M-…>'
66 call assert_equal('<M-…>', &pastetoggle)
67 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
68
69 " illegal bytes
70 let str = ":\x7f:\x80:\x90:\xd0:"
71 let &pastetoggle = str
72 call assert_equal(str, &pastetoggle)
73 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010074
zeertzjq0519ce02022-05-09 12:16:19 +010075 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010076 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010077endfunc
78
Bram Moolenaar1e115362019-01-09 23:01:02 +010079func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010080 " Empty 'wildchar' used to access invalid memory.
81 call assert_fails('set wildchar=', 'E521:')
82 call assert_fails('set wildchar=abc', 'E521:')
83 set wildchar=<Esc>
84 let a=execute('set wildchar?')
85 call assert_equal("\n wildchar=<Esc>", a)
86 set wildchar=27
87 let a=execute('set wildchar?')
88 call assert_equal("\n wildchar=<Esc>", a)
89 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010090endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010091
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020092func Test_wildoptions()
93 set wildoptions=
94 set wildoptions+=tagfile
95 set wildoptions+=tagfile
96 call assert_equal('tagfile', &wildoptions)
97endfunc
98
Bram Moolenaar6b915c02020-01-18 15:53:19 +010099func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200100 let caught = 'ok'
101 try
102 options
103 catch
104 let caught = v:throwpoint . "\n" . v:exception
105 endtry
106 call assert_equal('ok', caught)
107
Bram Moolenaare0b59492019-05-21 20:54:45 +0200108 " Check if the option-window is opened horizontally.
109 wincmd j
110 call assert_notequal('option-window', bufname(''))
111 wincmd k
112 call assert_equal('option-window', bufname(''))
113 " close option-window
114 close
115
116 " Open the option-window vertically.
117 vert options
118 " Check if the option-window is opened vertically.
119 wincmd l
120 call assert_notequal('option-window', bufname(''))
121 wincmd h
122 call assert_equal('option-window', bufname(''))
123 " close option-window
124 close
125
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200126 " Open the option-window at the top.
127 set splitbelow
128 topleft options
129 call assert_equal(1, winnr())
130 close
131
132 " Open the option-window at the bottom.
133 set nosplitbelow
134 botright options
135 call assert_equal(winnr('$'), winnr())
136 close
137 set splitbelow&
138
Bram Moolenaare0b59492019-05-21 20:54:45 +0200139 " Open the option-window in a new tab.
140 tab options
141 " Check if the option-window is opened in a tab.
142 normal gT
143 call assert_notequal('option-window', bufname(''))
144 normal gt
145 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200146 " close option-window
147 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200148
149 " Open the options window browse
150 if has('browse')
151 browse set
152 call assert_equal('option-window', bufname(''))
153 close
154 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200156
Bram Moolenaar1e115362019-01-09 23:01:02 +0100157func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200158 " Test that changing 'path' keeps two commas.
159 set path=foo,,bar
160 set path-=bar
161 set path+=bar
162 call assert_equal('foo,,bar', &path)
163
164 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100165endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200166
Dominique Pellef645ee42021-12-05 13:21:18 +0000167func Test_path_too_long()
168 exe 'set path=' .. repeat('x', 10000)
169 call assert_fails('find x', 'E854:')
170 set path&
171endfunc
172
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200173func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200174 CheckFeature signs
175 call assert_equal("auto", &signcolumn)
176 set signcolumn=yes
177 set signcolumn=no
178 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200179endfunc
180
Bram Moolenaard0b51382016-11-04 15:23:45 +0100181func Test_filetype_valid()
182 set ft=valid_name
183 call assert_equal("valid_name", &filetype)
184 set ft=valid-name
185 call assert_equal("valid-name", &filetype)
186
187 call assert_fails(":set ft=wrong;name", "E474:")
188 call assert_fails(":set ft=wrong\\\\name", "E474:")
189 call assert_fails(":set ft=wrong\\|name", "E474:")
190 call assert_fails(":set ft=wrong/name", "E474:")
191 call assert_fails(":set ft=wrong\\\nname", "E474:")
192 call assert_equal("valid-name", &filetype)
193
194 exe "set ft=trunc\x00name"
195 call assert_equal("trunc", &filetype)
196endfunc
197
198func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200199 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100200 set syn=valid_name
201 call assert_equal("valid_name", &syntax)
202 set syn=valid-name
203 call assert_equal("valid-name", &syntax)
204
205 call assert_fails(":set syn=wrong;name", "E474:")
206 call assert_fails(":set syn=wrong\\\\name", "E474:")
207 call assert_fails(":set syn=wrong\\|name", "E474:")
208 call assert_fails(":set syn=wrong/name", "E474:")
209 call assert_fails(":set syn=wrong\\\nname", "E474:")
210 call assert_equal("valid-name", &syntax)
211
212 exe "set syn=trunc\x00name"
213 call assert_equal("trunc", &syntax)
214endfunc
215
216func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200217 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100218 call assert_fails(":set kmp=valid_name", "E544:")
219 call assert_fails(":set kmp=valid_name", "valid_name")
220 call assert_fails(":set kmp=valid-name", "E544:")
221 call assert_fails(":set kmp=valid-name", "valid-name")
222
223 call assert_fails(":set kmp=wrong;name", "E474:")
224 call assert_fails(":set kmp=wrong\\\\name", "E474:")
225 call assert_fails(":set kmp=wrong\\|name", "E474:")
226 call assert_fails(":set kmp=wrong/name", "E474:")
227 call assert_fails(":set kmp=wrong\\\nname", "E474:")
228
229 call assert_fails(":set kmp=trunc\x00name", "E544:")
230 call assert_fails(":set kmp=trunc\x00name", "trunc")
231endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100232
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200233func Test_wildchar_valid()
234 call assert_fails("set wildchar=<CR>", "E474:")
235 call assert_fails("set wildcharm=<C-C>", "E474:")
236endfunc
237
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100238func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100239 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100240 exe 'set ' . a:name . '=/usr/share/dict/words'
241 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
242 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
243 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
244 exe 'set ' . a:name . '=/usr/share/dict\ words'
245 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100246
247 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100248 call assert_fails("set " . a:name . "=/not&there", "E474:")
249 call assert_fails("set " . a:name . "=/not>there", "E474:")
250 call assert_fails("set " . a:name . "=/not.*there", "E474:")
251endfunc
252
Bram Moolenaar60629d62017-02-23 18:08:56 +0100253func Test_cinkeys()
254 " This used to cause invalid memory access
255 set cindent cinkeys=0
256 norm a
257 set cindent& cinkeys&
258endfunc
259
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100260func Test_dictionary()
261 call Check_dir_option('dictionary')
262endfunc
263
264func Test_thesaurus()
265 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100266endfun
267
Bram Moolenaar226c5342017-02-17 14:53:15 +0100268func Test_complete()
269 " Trailing single backslash used to cause invalid memory access.
270 set complete=s\
271 new
272 call feedkeys("i\<C-N>\<Esc>", 'xt')
273 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200274 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100275 set complete&
276endfun
277
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100278func Test_set_completion()
279 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
280 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
281
Bram Moolenaar297610b2019-12-27 17:20:55 +0100282 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
284
285 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
286 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
287
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100288 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
289 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100290 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100291 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100292
293 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100294 call assert_equal('"set invdiff invdigraph', @:)
295
296 " Expanding "set noinv" does nothing.
297 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
298 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100299
300 " Expand abbreviation of options.
301 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100302 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100303
304 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200305 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
306 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100307
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200308 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
309 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100310
311 " Expand key codes.
312 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
313 call assert_equal('"set <Help> <Home>', @:)
Yee Cheng Chin7d8e7df2025-03-27 17:43:41 +0100314 " <BackSpace> (alt name) and <BS> should both show up in auto-complete
315 call feedkeys(":set <B\<C-A>\<C-B>\"\<CR>", 'tx')
316 call assert_equal('"set <BackSpace> <Bar> <BS> <Bslash>', @:)
317 " <ScrollWheelDown> has alt name <MouseUp> but it should not show up here
318 " nor show up as duplicates
319 call feedkeys(":set <ScrollWheel\<C-A>\<C-B>\"\<CR>", 'tx')
320 call assert_equal('"set <ScrollWheelDown> <ScrollWheelLeft> <ScrollWheelRight> <ScrollWheelUp>', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100321
322 " Expand terminal options.
323 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200324 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200325 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100326
327 " Expand directories.
328 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
329 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200330 call assert_notmatch(' ./summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200331 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100332
333 " Expand files and directories.
334 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200335 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100336
337 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
338 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200339
340 " Expand files with spaces/commas in them. Make sure we delimit correctly.
341 "
342 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
343 " spaces requiring double escape, and commas need a single escape.
344 " 'dictionary' is a normal comma-separated option where only commas act as
345 " delimiters, and both space/comma need one single escape.
346 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
347 defer delete('Xfoo Xspace.txt')
348 defer delete('Xsp_dummy')
349 defer delete('Xbar,Xcomma.txt')
350 defer delete('Xcom_dummy')
351 call writefile([], 'Xfoo Xspace.txt')
352 call writefile([], 'Xsp_dummy')
353 call writefile([], 'Xbar,Xcomma.txt')
354 call writefile([], 'Xcom_dummy')
355
356 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
357 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
358 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
359 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
360 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
361 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
362
363 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
364 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
365 if has('win32')
366 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
367 " means we treat it as one file name.
368 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
369 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
370 else
371 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
372 " to split into a separate file name. You need '\\,' to escape the comma
373 " as part of the file name.
374 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
375 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
376
377 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
378 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
379 endif
380 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
381 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
382 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200383
384 " Expanding the option names
385 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
386 call assert_equal('"set all', @:)
387
388 " Expanding a second set of option names
389 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
390 call assert_equal('"set wrapscan all', @:)
391
392 " Expanding a special keycode
393 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
394 call assert_equal('"set <Home>', @:)
395
396 " Expanding an invalid special keycode
397 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
398 call assert_equal("\"set <abcd>\<Tab>", @:)
399
400 " Expanding a terminal keycode
401 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
402 call assert_equal("\"set t_AB", @:)
403
404 " Expanding an invalid option name
405 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
406 call assert_equal("\"set abcde=\<Tab>", @:)
407
408 " Expanding after a = for a boolean option
409 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
410 call assert_equal("\"set wrapscan=\<Tab>", @:)
411
412 " Expanding a numeric option
413 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
414 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
415
416 " Expanding a non-boolean option
417 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
418 call assert_equal("\"set invtabstop=", @:)
419
420 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200421 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
422 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
423 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
424 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200425
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200426 " Expanding value for 'key' is disallowed
427 if exists('+key')
428 set key=abcd
429 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
430 call assert_equal('"set key=', @:)
431 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
432 call assert_equal('"set key-=', @:)
433 set key=
434 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100435
436 " Expand values for 'filetype'
437 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
438 call assert_equal('"set filetype=sshdconfig', @:)
439 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
440 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200441
442 " Expand values for 'syntax'
443 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
444 call assert_equal('"set syntax=sshdconfig', @:)
445 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
446 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100447
448 if has('keymap')
449 " Expand values for 'keymap'
450 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
451 call assert_equal('"set keymap=accents', @:)
452 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
453 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
454 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100455endfunc
456
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200457" Test handling of expanding individual string option values
458func Test_set_completion_string_values()
459 "
460 " Test basic enum string options that have well-defined enum names
461 "
462
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200463 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
464 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
465 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200466
467 " Test that if a value is set, it will populate the results, but only if
468 " typed value is empty.
469 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200470 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
471 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200472 " If the set value is part of the enum list, it will show as the first
473 " result with no duplicate.
474 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200475 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200476 " If empty value, will just show the normal list without an empty item
477 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200478 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200479 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200480 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200481
482 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200483 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200484 " Also test the positioning of the expansion is correct
485 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
486 call assert_equal('"set display=truncate,lastline', @:)
487 set display&
488
489 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200490 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200491
492 " Test the other simple options to make sure they have basic auto-complete,
493 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200494 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200495 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Luca Saccarola959ef612024-12-01 16:25:53 +0100496 call assert_equal('indent,eol,start', getcompletion('set backspace=', 'cmdline')[0])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200497 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
498 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
499 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200500 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200501 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200502 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200503 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
504 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
505 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200506 if exists('+clipboard')
507 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
508 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200509 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
510 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
zeertzjq53d59ec2025-03-07 19:09:09 +0100511 call assert_equal('keyword', getcompletion('set completefuzzycollect=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200512 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200513 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200514 endif
515 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200516 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200517 endif
518 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200519 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200520 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200521 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
522 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
523 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200524 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200525 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200526 endif
527 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200528 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200529 endif
530 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200531 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200532 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200533 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
534 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
535 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200536 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200537 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200538 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200540 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200541 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
542 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
543 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200544 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200547 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200548 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200549 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200550 endif
551 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200552 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200553 endif
554 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200555 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200556 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200557 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
558 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
559 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
560 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
LemonBoy5247b0b2024-07-12 19:30:58 +0200561 if exists('+tabclose')
562 call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
563 endif
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200564 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200565 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200566 endif
567 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200568 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200569 endif
570 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200571 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200572 endif
573 if exists('+ttymouse')
574 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200575 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200576 set ttymouse&
577 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200578 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
579 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
580 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
581 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200582 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200583 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200584 endif
585
586 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200587 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
Luuk van Baalb7147f82025-02-08 18:52:39 +0100588 call assert_equal(['WinLeave', 'WinResized', 'WinScrolled'], getcompletion('set eiw=', 'cmdline')[-3:-1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200589 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
590 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
591 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200592
zeertzjq1f025b02023-09-30 12:43:07 +0200593 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
594 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
595 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
596 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
597 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
598 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200599
600 "
601 " Unique string options below
602 "
603
604 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200605 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200606 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
607 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
Christian Brabandt231b4fc2024-12-28 16:27:49 +0100608 call feedkeys(":set keyprotocol+=someterm:k\<Tab>\<C-B>\"\<CR>", 'xt')
609 call assert_equal('"set keyprotocol+=someterm:kitty', @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200610 set keyprotocol&
611
612 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200613 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
614 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200615 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
616 call assert_equal('"set previewpopup+=border:on', @:)
617 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
618 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200619 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200620 set previewpopup& completepopup&
621
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100622 " diffopt: special handling of algorithm:<alg_list> and inline:<inline_type>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200623 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
624 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
625 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100626 call assert_equal('char', getcompletion('set diffopt+=iwhite,inline:ch*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200627
628 " highlight: special parsing, including auto-completing highlight groups
629 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200630 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
631 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
632 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
633 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
634 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200635 " If all the display modes are used up we should be suggesting nothing. Make
636 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
637 " and make sure nothing is suggested from that.
638 let hl_display_modes = join(
639 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
640 \ {idx, val -> val[1]}),
641 \ {idx, val -> val != ':'}),
642 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200643 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200644 " Test completion in middle of the line
645 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
646 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200647
Christian Brabandt51d4d842024-12-06 17:26:25 +0100648 " messagesopt
649 call assert_equal(['history:', 'hit-enter', 'wait:'],
650 \ getcompletion('set messagesopt+=', 'cmdline')->sort())
651
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200652 "
653 " Test flag lists
654 "
655
656 " Test set=. Show the original value if nothing is typed after '='.
657 " Otherwise, the list should avoid showing what's already typed.
658 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200659 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200660 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200661 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
662 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200663
664 " Test set+=. Never show original value, and it also tries to avoid listing
665 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200666 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
667 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
668 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200669
670 " Test that the position of the expansion is correct (even if there are
671 " additional values after the current cursor)
672 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
673 call assert_equal('"set mouse=han', @:)
674 set mouse&
675
676 " Test that other flag list options have auto-complete, but don't
677 " exhaustively validate their results.
678 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200679 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200680 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200681 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
682 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200683 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200684 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200685 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200686 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
687 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200688
689 "
690 "Test set-=
691 "
692
693 " Normal single-value option just shows the existing value
694 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200695 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200696 set ambiwidth&
697
698 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200699 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200700 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200701 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 set t_Ce&
703
704 " Comma-separated lists should present each option
705 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200706 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
707 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
708 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200709 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200710 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200711 " Test empty option
712 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200713 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Christian Brabandt9162e632025-01-16 19:03:40 +0100714 " Test all possible values
715 call assert_equal(['filler', 'context:', 'iblank', 'icase', 'iwhite', 'iwhiteall', 'iwhiteeol', 'horizontal',
Yee Cheng Chin9943d472025-03-26 19:41:02 +0100716 \ 'vertical', 'closeoff', 'hiddenoff', 'foldcolumn:', 'followwrap', 'internal', 'indent-heuristic', 'algorithm:', 'inline:', 'linematch:'],
Christian Brabandt9162e632025-01-16 19:03:40 +0100717 \ getcompletion('set diffopt=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200718 set diffopt&
719
720 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200721 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200722
723 " Test files with commas in name are being parsed and escaped properly
724 set path=has\\\ space,file\\,with\\,comma,normal_file
725 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200726 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200727 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200728 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200729 endif
730 set path&
731
732 " Flag list should present orig value, then individual flags
733 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200734 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200735 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200736 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200737 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200738 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200739 " Test empty option
740 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200741 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200742 set mouse&
743
744 " 'whichwrap' is an odd case where it's both flag list and comma-separated
745 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200746 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200747 set ww&
748endfunc
749
zeertzjq4c7cb372023-06-14 16:39:54 +0100750func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100751 call assert_fails('set scroll=-1', 'E49:')
752 call assert_fails('set backupcopy=', 'E474:')
753 call assert_fails('set regexpengine=3', 'E474:')
754 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200755 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100756 call assert_fails('set colorcolumn=-a', 'E474:')
757 call assert_fails('set colorcolumn=a', 'E474:')
758 call assert_fails('set colorcolumn=1,', 'E474:')
759 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100760 call assert_fails('set cmdheight=-1', 'E487:')
761 call assert_fails('set cmdwinheight=-1', 'E487:')
762 if has('conceal')
763 call assert_fails('set conceallevel=-1', 'E487:')
764 call assert_fails('set conceallevel=4', 'E474:')
765 endif
766 call assert_fails('set helpheight=-1', 'E487:')
767 call assert_fails('set history=-1', 'E487:')
768 call assert_fails('set report=-1', 'E487:')
769 call assert_fails('set shiftwidth=-1', 'E487:')
770 call assert_fails('set sidescroll=-1', 'E487:')
771 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000772 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000773 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000774 call assert_fails('set tabstop=5500000000', 'E474:')
Milly6d5f4a02024-10-22 23:17:45 +0200775 if has('terminal')
776 call assert_fails('set termwinscroll=-1', 'E487:')
777 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100778 call assert_fails('set textwidth=-1', 'E487:')
779 call assert_fails('set timeoutlen=-1', 'E487:')
780 call assert_fails('set updatecount=-1', 'E487:')
781 call assert_fails('set updatetime=-1', 'E487:')
782 call assert_fails('set winheight=-1', 'E487:')
783 call assert_fails('set tabstop!', 'E488:')
Milly484face2024-10-12 11:26:06 +0200784
785 " Test for setting unknown option errors
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100786 call assert_fails('set xxx', 'E518:')
Milly484face2024-10-12 11:26:06 +0200787 call assert_fails('setlocal xxx', 'E518:')
788 call assert_fails('setglobal xxx', 'E518:')
789 call assert_fails('set xxx=', 'E518:')
790 call assert_fails('setlocal xxx=', 'E518:')
791 call assert_fails('setglobal xxx=', 'E518:')
792 call assert_fails('set xxx:', 'E518:')
793 call assert_fails('setlocal xxx:', 'E518:')
794 call assert_fails('setglobal xxx:', 'E518:')
795 call assert_fails('set xxx!', 'E518:')
796 call assert_fails('setlocal xxx!', 'E518:')
797 call assert_fails('setglobal xxx!', 'E518:')
798 call assert_fails('set xxx?', 'E518:')
799 call assert_fails('setlocal xxx?', 'E518:')
800 call assert_fails('setglobal xxx?', 'E518:')
801 call assert_fails('set xxx&', 'E518:')
802 call assert_fails('setlocal xxx&', 'E518:')
803 call assert_fails('setglobal xxx&', 'E518:')
804 call assert_fails('set xxx<', 'E518:')
805 call assert_fails('setlocal xxx<', 'E518:')
806 call assert_fails('setglobal xxx<', 'E518:')
807
808 " Test for missing-options errors.
809 call assert_fails('set autoprint?', 'E519:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100810 call assert_fails('set beautify?', 'E519:')
Milly484face2024-10-12 11:26:06 +0200811 call assert_fails('set flash?', 'E519:')
812 call assert_fails('set graphic?', 'E519:')
813 call assert_fails('set hardtabs?', 'E519:')
814 call assert_fails('set mesg?', 'E519:')
815 call assert_fails('set novice?', 'E519:')
816 call assert_fails('set open?', 'E519:')
817 call assert_fails('set optimize?', 'E519:')
818 call assert_fails('set redraw?', 'E519:')
819 call assert_fails('set slowopen?', 'E519:')
820 call assert_fails('set sourceany?', 'E519:')
821 call assert_fails('set w300?', 'E519:')
822 call assert_fails('set w1200?', 'E519:')
823 call assert_fails('set w9600?', 'E519:')
824
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100825 call assert_fails('set undolevels=x', 'E521:')
826 call assert_fails('set tabstop=', 'E521:')
827 call assert_fails('set comments=-', 'E524:')
828 call assert_fails('set comments=a', 'E525:')
829 call assert_fails('set foldmarker=x', 'E536:')
830 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000831 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100832 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100833 call assert_fails('set rulerformat=%-', 'E539:')
834 call assert_fails('set rulerformat=%(', 'E542:')
835 call assert_fails('set rulerformat=%15(%%', 'E542:')
Milly484face2024-10-12 11:26:06 +0200836
837 " Test for 'statusline' errors
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100838 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100839 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100840 call assert_fails('set statusline=%{%', 'E540:')
841 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100842 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100843 call assert_fails('set statusline=%)', 'E542:')
Milly484face2024-10-12 11:26:06 +0200844
845 " Test for 'tabline' errors
zeertzjq5dc294a2022-04-15 13:17:57 +0100846 call assert_fails('set tabline=%$', 'E539:')
847 call assert_fails('set tabline=%{', 'E540:')
848 call assert_fails('set tabline=%{%', 'E540:')
849 call assert_fails('set tabline=%{%}', 'E539:')
850 call assert_fails('set tabline=%(', 'E542:')
851 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100852
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100853 if has('cursorshape')
854 " This invalid value for 'guicursor' used to cause Vim to crash.
855 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
856 call assert_fails('set guicursor=i-ci', 'E545:')
857 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100858 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100859 call assert_fails('set guicursor=r-cr:horx', 'E548:')
860 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
861 endif
Milly484face2024-10-12 11:26:06 +0200862
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100863 if has('mouseshape')
864 call assert_fails('se mouseshape=i-r:x', 'E547:')
865 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000866
867 " Test for 'backupext' and 'patchmode' set to the same value
868 set backupext=.bak
869 set patchmode=.patch
870 call assert_fails('set patchmode=.bak', 'E589:')
871 call assert_equal('.patch', &patchmode)
872 call assert_fails('set backupext=.patch', 'E589:')
873 call assert_equal('.bak', &backupext)
874 set backupext& patchmode&
875
Milly484face2024-10-12 11:26:06 +0200876 " 'winheight' cannot be smaller than 'winminheight'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100877 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200878 set winminheight& winheight&
879 set winheight=10 winminheight=10
880 call assert_fails('set winheight=9', 'E591:')
881 set winminheight& winheight&
Milly484face2024-10-12 11:26:06 +0200882
883 " 'winwidth' cannot be smaller than 'winminwidth'
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100884 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200885 set winminwidth& winwidth&
886 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
887 set winwidth& winminwidth&
Milly484face2024-10-12 11:26:06 +0200888
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100889 call assert_fails("set showbreak=\x01", 'E595:')
890 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200891 call assert_fails('set tabstop??', 'E488:')
892 call assert_fails('set wrapscan!!', 'E488:')
893 call assert_fails('set tabstop&&', 'E488:')
894 call assert_fails('set wrapscan<<', 'E488:')
895 call assert_fails('set wrapscan=1', 'E474:')
896 call assert_fails('set autoindent@', 'E488:')
897 call assert_fails('set wildchar=<abc>', 'E474:')
898 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200899 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100900 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200901 call assert_fails('set pyxversion=6', 'E474:')
902 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100903 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200904 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100905 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
906 call assert_fails('set foldmarker={{{,', 'E474:')
907 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
Milly484face2024-10-12 11:26:06 +0200908
909 " 'ambiwidth' conflict 'listchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100910 setlocal listchars=trail:·
911 call assert_fails('set ambiwidth=double', 'E834:')
912 setlocal listchars=trail:-
913 setglobal listchars=trail:·
914 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100915 set listchars&
Milly484face2024-10-12 11:26:06 +0200916
917 " 'ambiwidth' conflict 'fillchars'
zeertzjq8ca29b62022-08-09 12:53:14 +0100918 setlocal fillchars=stl:·
919 call assert_fails('set ambiwidth=double', 'E835:')
920 setlocal fillchars=stl:-
921 setglobal fillchars=stl:·
922 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100923 set fillchars&
Milly484face2024-10-12 11:26:06 +0200924
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100925 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
926 set nomodifiable
927 call assert_fails('set fileencoding=latin1', 'E21:')
928 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200929 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000930 call assert_fails('let &formatoptions = "?"', 'E539:')
931 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
Milly484face2024-10-12 11:26:06 +0200932
933 " Should raises only one error if passing a wrong variable type.
zeertzjq4c7cb372023-06-14 16:39:54 +0100934 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
935 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
936 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
937 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
938 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
939 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100940endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100941
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000942func Test_set_encoding()
943 let save_encoding = &encoding
944
945 set enc=iso8859-1
946 call assert_equal('latin1', &enc)
947 set enc=iso8859_1
948 call assert_equal('latin1', &enc)
949 set enc=iso-8859-1
950 call assert_equal('latin1', &enc)
951 set enc=iso_8859_1
952 call assert_equal('latin1', &enc)
953 set enc=iso88591
954 call assert_equal('latin1', &enc)
955 set enc=iso8859
956 call assert_equal('latin1', &enc)
957 set enc=iso-8859
958 call assert_equal('latin1', &enc)
959 set enc=iso_8859
960 call assert_equal('latin1', &enc)
961 call assert_fails('set enc=iso8858', 'E474:')
962 call assert_equal('latin1', &enc)
963
964 let &encoding = save_encoding
965endfunc
966
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200967func CheckWasSet(name)
968 let verb_cm = execute('verbose set ' .. a:name .. '?')
969 call assert_match('Last set from.*test_options.vim', verb_cm)
970endfunc
971func CheckWasNotSet(name)
972 let verb_cm = execute('verbose set ' .. a:name .. '?')
973 call assert_notmatch('Last set from', verb_cm)
974endfunc
975
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200976" Must be executed before other tests that set 'term'.
977func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200978 CheckNotGui
979
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200980 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200981
982 let term_save = &term
983 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200984 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200985 let &term = term_save
986endfunc
987
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200988func Test_copy_context()
989 setlocal list
990 call CheckWasSet('list')
991 split
992 call CheckWasSet('list')
993 quit
994 setlocal nolist
995
996 set ai
997 call CheckWasSet('ai')
998 set filetype=perl
999 call CheckWasSet('filetype')
1000 set fo=tcroq
1001 call CheckWasSet('fo')
1002
1003 split Xsomebuf
1004 call CheckWasSet('ai')
1005 call CheckWasNotSet('filetype')
1006 call CheckWasSet('fo')
1007endfunc
1008
Bram Moolenaar67391142017-02-19 21:07:04 +01001009func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001010 CheckUnix
1011 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +02001012
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001013 " Setting 'ttytype' used to cause a double-free when exiting vim and
1014 " when vim is compiled with -DEXITFREE.
1015 set ttytype=ansi
1016 call assert_equal('ansi', &ttytype)
1017 call assert_equal(&ttytype, &term)
1018 set ttytype=xterm
1019 call assert_equal('xterm', &ttytype)
1020 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001021 try
1022 set ttytype=
1023 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +01001024 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001025 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +02001026
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02001027 " Some systems accept any terminal name and return dumb settings,
1028 " check for failure of finding the entry and for missing 'cm' entry.
1029 try
1030 set ttytype=xxx
1031 call assert_report('set ttytype=xxx did not fail')
1032 catch /E522\|E437/
1033 endtry
1034
1035 set ttytype&
1036 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001037
1038 if has('gui') && !has('gui_running')
1039 call assert_fails('set term=gui', 'E531:')
1040 endif
Bram Moolenaar67391142017-02-19 21:07:04 +01001041endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001042
Milly484face2024-10-12 11:26:06 +02001043" Test for :set all
Bram Moolenaar2f5463d2017-02-25 20:40:46 +01001044func Test_set_all()
1045 set tw=75
1046 set iskeyword=a-z,A-Z
1047 set nosplitbelow
1048 let out = execute('set all')
1049 call assert_match('textwidth=75', out)
1050 call assert_match('iskeyword=a-z,A-Z', out)
1051 call assert_match('nosplitbelow', out)
1052 set tw& iskeyword& splitbelow&
1053endfunc
1054
Milly484face2024-10-12 11:26:06 +02001055" Test for :set! all
1056func Test_set_all_one_column()
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001057 let out_mult = execute('set all')->split("\n")
1058 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +01001059 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +01001060 call assert_equal(out_one[0], '--- Options ---')
1061 let options = out_one[1:]->mapnew({_, line -> line[2:]})
1062 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +01001063endfunc
1064
Bram Moolenaar0c1e3742019-12-27 13:49:24 +01001065func Test_renderoptions()
1066 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
1067 " Doesn't hurt to do this on a non-Windows system.
1068 if windowsversion() !~ '^[345]\.'
1069 set renderoptions=type:directx
1070 set rop=type:directx
1071 endif
1072endfunc
1073
Bram Moolenaara701b3b2017-04-20 22:57:27 +02001074func ResetIndentexpr()
1075 set indentexpr=
1076endfunc
1077
1078func Test_set_indentexpr()
1079 " this was causing usage of freed memory
1080 set indentexpr=ResetIndentexpr()
1081 new
1082 call feedkeys("i\<c-f>", 'x')
1083 call assert_equal('', &indentexpr)
1084 bwipe!
1085endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001086
1087func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001088 " Option 'backupskip' may contain several comma-separated path
1089 " specifications if one or more of the environment variables TMPDIR, TMP,
1090 " or TEMP is defined. To simplify testing, convert the string value into a
1091 " list.
1092 let bsklist = split(&bsk, ',')
1093
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001094 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001095 let found = (index(bsklist, '/private/tmp/*') >= 0)
1096 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001097 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001098 let found = (index(bsklist, '/tmp/*') >= 0)
1099 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001100 endif
1101
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001102 " If our test platform is Windows, the path(s) in option bsk will use
1103 " backslash for the path separator and the components could be in short
1104 " (8.3) format. As such, we need to replace the backslashes with forward
1105 " slashes and convert the path components to long format. The expand()
1106 " function will do this but it cannot handle comma-separated paths. This is
1107 " why bsk was converted from a string into a list of strings above.
1108 "
1109 " One final complication is that the wildcard "/*" is at the end of each
1110 " path and so expand() might return a list of matching files. To prevent
1111 " this, we need to remove the wildcard before calling expand() and then
1112 " append it afterwards.
1113 if has('win32')
1114 let item_nbr = 0
1115 while item_nbr < len(bsklist)
1116 let path_spec = bsklist[item_nbr]
1117 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1118 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1119 let bsklist[item_nbr] = path_spec . '/*'
1120 let item_nbr += 1
1121 endwhile
1122 endif
1123
1124 " Option bsk will also include these environment variables if defined.
1125 " If they're defined, verify they appear in the option value.
1126 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001127 if exists(var)
1128 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001129 let varvalue = substitute(varvalue, '/$', '', '')
1130 let varvalue .= '/*'
1131 let found = (index(bsklist, varvalue) >= 0)
1132 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001133 endif
1134 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001135
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001136 " Duplicates from environment variables should be filtered out (option has
1137 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1138 " so that we see what happens on startup.
1139 let after =<< trim [CODE]
1140 let bsklist = split(&backupskip, ',')
1141 call assert_equal(uniq(copy(bsklist)), bsklist)
1142 call writefile(['errors:'] + v:errors, 'Xtestout')
1143 qall
1144 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001145 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001146 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1147
1148 let saveenv = {}
1149 for var in ['TMPDIR', 'TMP', 'TEMP']
1150 let saveenv[var] = getenv(var)
1151 call setenv(var, '/duplicate/path')
1152 endfor
1153
1154 exe 'silent !' . cmd
1155 call assert_equal(['errors:'], readfile('Xtestout'))
1156
1157 " restore environment variables
1158 for var in ['TMPDIR', 'TMP', 'TEMP']
1159 call setenv(var, saveenv[var])
1160 endfor
1161
1162 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001163
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001164 " Duplicates should be filtered out (option has P_NODUP)
1165 let backupskip = &backupskip
1166 set backupskip=
1167 set backupskip+=/test/dir
1168 set backupskip+=/other/dir
1169 set backupskip+=/test/dir
1170 call assert_equal('/test/dir,/other/dir', &backupskip)
1171 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001172endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001173
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001174func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001175 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001176
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001177 " Test copy option from current buffer in window
1178 split
1179 enew
1180 setlocal numberwidth=5
1181 wincmd w
1182 call assert_equal(4,&numberwidth)
1183 bnext
1184 call assert_equal(5,&numberwidth)
1185 bw!
1186 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001187
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001188 " Test copy value from window that used to be display the buffer
1189 split
1190 enew
1191 setlocal numberwidth=6
1192 bnext
1193 wincmd w
1194 call assert_equal(4,&numberwidth)
1195 bnext
1196 call assert_equal(6,&numberwidth)
1197 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001198
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001199 " Test that if buffer is current, don't use the stale cached value
1200 " from the last time the buffer was displayed.
1201 split
1202 enew
1203 setlocal numberwidth=7
1204 bnext
1205 bnext
1206 setlocal numberwidth=8
1207 wincmd w
1208 call assert_equal(4,&numberwidth)
1209 bnext
1210 call assert_equal(8,&numberwidth)
1211 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001212
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001213 " Test value is not copied if window already has seen the buffer
1214 enew
1215 split
1216 setlocal numberwidth=9
1217 bnext
1218 setlocal numberwidth=10
1219 wincmd w
1220 call assert_equal(4,&numberwidth)
1221 bnext
1222 call assert_equal(4,&numberwidth)
1223 bw!
1224
1225 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001226endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001227
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001228def Test_split_copy_options()
1229 var values = [
1230 ['cursorbind', true, false],
1231 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1232 ['list', true, 0],
1233 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1234 ['number', true, 0],
1235 ['relativenumber', true, false],
1236 ['scrollbind', true, false],
1237 ['smoothscroll', true, false],
1238 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1239 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1240 ['wrap', false, true],
1241 ]
1242 if has('linebreak')
1243 values += [
1244 ['breakindent', true, false],
1245 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1246 ['linebreak', true, false],
1247 ['numberwidth', 7, 4],
1248 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1249 ]
1250 endif
1251 if has('rightleft')
1252 values += [
1253 ['rightleft', true, false],
1254 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1255 ]
1256 endif
1257 if has('statusline')
1258 values += [
1259 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1260 ]
1261 endif
1262 if has('spell')
1263 values += [
1264 ['spell', true, false],
1265 ]
1266 endif
1267 if has('syntax')
1268 values += [
1269 ['cursorcolumn', true, false],
1270 ['cursorline', true, false],
1271 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1272 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1273 ]
1274 endif
1275 if has('diff')
1276 values += [
1277 ['diff', true, false],
1278 ]
1279 endif
1280 if has('conceal')
1281 values += [
1282 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1283 ['conceallevel', '3', &conceallevel],
1284 ]
1285 endif
1286 if has('terminal')
1287 values += [
1288 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1289 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1290 ]
1291 endif
1292 if has('folding')
1293 values += [
1294 ['foldcolumn', 5, &foldcolumn],
1295 ['foldenable', false, true],
1296 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1297 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1298 ['foldlevel', 4, &foldlevel],
1299 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1300 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1301 ['foldminlines', 3, &foldminlines],
1302 ['foldnestmax', 17, &foldnestmax],
1303 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1304 ]
1305 endif
1306 if has('signs')
1307 values += [
1308 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1309 ]
1310 endif
1311
1312 # set options to non-default value
1313 for item in values
1314 exe $'&l:{item[0]} = {item[1]}'
1315 endfor
1316
1317 # check values are set in new window
1318 split
1319 for item in values
1320 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1321 endfor
1322
1323 # restore
1324 close
1325 for item in values
1326 exe $'&l:{item[0]} = {item[2]}'
1327 endfor
1328enddef
1329
Bram Moolenaarfc089602018-06-24 16:53:35 +02001330func Test_shortmess_F()
1331 new
1332 call assert_match('\[No Name\]', execute('file'))
1333 set shortmess+=F
1334 call assert_match('\[No Name\]', execute('file'))
1335 call assert_match('^\s*$', execute('file foo'))
1336 call assert_match('foo', execute('file'))
1337 set shortmess-=F
1338 call assert_match('bar', execute('file bar'))
1339 call assert_match('bar', execute('file'))
1340 set shortmess&
1341 bwipe
1342endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001343
1344func Test_shortmess_F2()
1345 e file1
1346 e file2
1347 call assert_match('file1', execute('bn', ''))
1348 call assert_match('file2', execute('bn', ''))
1349 set shortmess+=F
1350 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001351 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001352 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001353 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001354 set hidden
1355 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001356 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001357 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001358 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001359 set nohidden
1360 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001361 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001362 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001363 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001364 set shortmess&
1365 call assert_match('file1', execute('bn', ''))
1366 call assert_match('file2', execute('bn', ''))
1367 bwipe
1368 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001369 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001370endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001371
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001372func Test_shortmess_F3()
zeertzjq8a017442024-03-07 21:48:33 +01001373 call writefile(['foo'], 'X_dummy', 'D')
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001374
1375 set hidden
1376 set autoread
1377 e X_dummy
zeertzjq8a017442024-03-07 21:48:33 +01001378 e Xotherfile
1379 call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001380 set shortmess+=F
zeertzjq8a017442024-03-07 21:48:33 +01001381 echo ''
1382
1383 if has('nanotime')
1384 sleep 10m
1385 else
1386 sleep 2
1387 endif
1388 call writefile(['bar'], 'X_dummy')
1389 bprev
1390 call assert_equal('', Screenline(&lines))
1391 call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
1392
1393 if has('nanotime')
1394 sleep 10m
1395 else
1396 sleep 2
1397 endif
1398 call writefile(['baz'], 'X_dummy')
1399 checktime
1400 call assert_equal('', Screenline(&lines))
1401 call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001402
1403 set shortmess&
1404 set autoread&
1405 set hidden&
zeertzjq8a017442024-03-07 21:48:33 +01001406 bwipe X_dummy
1407 bwipe Xotherfile
Shougo Matsushita9db39b02024-03-06 20:58:41 +01001408endfunc
1409
Bram Moolenaar375e3392019-01-31 18:26:10 +01001410func Test_local_scrolloff()
1411 set so=5
1412 set siso=7
1413 split
1414 call assert_equal(5, &so)
1415 setlocal so=3
1416 call assert_equal(3, &so)
1417 wincmd w
1418 call assert_equal(5, &so)
1419 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001420 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001421 setlocal so<
1422 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001423 setglob so=8
1424 call assert_equal(8, &so)
1425 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001426 setlocal so=0
1427 call assert_equal(0, &so)
1428 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001429 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001430
1431 call assert_equal(7, &siso)
1432 setlocal siso=3
1433 call assert_equal(3, &siso)
1434 wincmd w
1435 call assert_equal(7, &siso)
1436 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001437 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001438 setlocal siso<
1439 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001440 setglob siso=4
1441 call assert_equal(4, &siso)
1442 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001443 setlocal siso=0
1444 call assert_equal(0, &siso)
1445 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001446 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001447
1448 close
1449 set so&
1450 set siso&
1451endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001452
1453func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001454 CheckFunction reltimefloat
1455
Bram Moolenaar449ac472019-04-03 21:42:35 +02001456 new
1457 call setline(1, 'empty')
1458 redraw
1459 set writedelay=10
1460 let start = reltime()
1461 call setline(1, repeat('x', 70))
1462 redraw
1463 let elapsed = reltimefloat(reltime(start))
1464 set writedelay=0
1465 " With 'writedelay' set should take at least 30 * 10 msec
1466 call assert_inrange(30 * 0.01, 999.0, elapsed)
1467
1468 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001469endfunc
1470
1471func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001472 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001473 set visualbell
1474 call assert_beeps('normal 0h')
1475 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001476 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001477endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001478
1479" Test for the 'write' option
1480func Test_write()
1481 new
1482 call setline(1, ['L1'])
1483 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001484 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001485 set write
LemonBoy5247b0b2024-07-12 19:30:58 +02001486 " close swapfile
1487 bw!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001488endfunc
1489
1490" Test for 'buftype' option
1491func Test_buftype()
1492 new
1493 call setline(1, ['L1'])
1494 set buftype=nowrite
1495 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001496
1497 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1498 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001499 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001500 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1501 endfor
1502
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001503 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001504endfunc
1505
Bram Moolenaar578fe942020-02-27 21:32:51 +01001506" Test for the 'rightleftcmd' option
1507func Test_rightleftcmd()
1508 CheckFeature rightleft
1509 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001510
1511 let g:l = []
1512 func AddPos()
1513 call add(g:l, screencol())
1514 return ''
1515 endfunc
1516 cmap <expr> <F2> AddPos()
1517
zeertzjqbb404f52022-07-23 06:25:29 +01001518 set rightleftcmd=
1519 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1520 \ "\<Right>\<F2>\<Esc>", 'xt')
1521 call assert_equal([2, 5, 3, 4], g:l)
1522
1523 let g:l = []
1524 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001525 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1526 \ "\<Left>\<F2>\<Esc>", 'xt')
1527 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1528
1529 cunmap <F2>
1530 unlet g:l
1531 set rightleftcmd&
1532 set rightleft&
1533endfunc
1534
zeertzjq28c162f2022-08-14 14:49:50 +01001535" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001536func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001537 " redraw to avoid matching previous messages
1538 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001539 set debug=beep
1540 exe "normal \<C-c>"
1541 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001542 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001543 " also check a line above, with a certain window width the colon is there
1544 call assert_match('Test_debug_option:$',
1545 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001546 set debug&
1547endfunc
1548
Bram Moolenaar004a6782020-04-11 17:09:31 +02001549" Test for the default CDPATH option
1550func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001551 let after =<< trim [CODE]
1552 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1553 call writefile(v:errors, 'Xtestout')
1554 qall
1555 [CODE]
1556 if has('unix')
1557 let $CDPATH='/path/to/dir1:/path/to/dir2'
1558 else
1559 let $CDPATH='/path/to/dir1;/path/to/dir2'
1560 endif
1561 if RunVim([], after, '')
1562 call assert_equal([], readfile('Xtestout'))
1563 call delete('Xtestout')
1564 endif
1565endfunc
1566
1567" Test for setting keycodes using set
1568func Test_opt_set_keycode()
1569 call assert_fails('set <t_k1=l', 'E474:')
1570 call assert_fails('set <Home=l', 'E474:')
1571 set <t_k9>=abcd
1572 call assert_equal('abcd', &t_k9)
1573 set <t_k9>&
1574 set <F9>=xyz
1575 call assert_equal('xyz', &t_k9)
1576 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001577
1578 " should we test all of them?
1579 set t_Ce=testCe
1580 set t_Cs=testCs
1581 set t_Us=testUs
1582 set t_ds=testds
1583 set t_Ds=testDs
1584 call assert_equal('testCe', &t_Ce)
1585 call assert_equal('testCs', &t_Cs)
1586 call assert_equal('testUs', &t_Us)
1587 call assert_equal('testds', &t_ds)
1588 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001589endfunc
1590
1591" Test for changing options in a sandbox
1592func Test_opt_sandbox()
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01001593 for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
Bram Moolenaar004a6782020-04-11 17:09:31 +02001594 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001595 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001596 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001597 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001598endfunc
1599
Milly484face2024-10-12 11:26:06 +02001600" Test for setting string global-local option value
1601func Test_set_string_global_local_option()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001602 setglobal equalprg=gprg
1603 setlocal equalprg=lprg
1604 call assert_equal('gprg', &g:equalprg)
1605 call assert_equal('lprg', &l:equalprg)
1606 call assert_equal('lprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001607
1608 " :set {option}< removes the local value, so that the global value will be used.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001609 set equalprg<
1610 call assert_equal('', &l:equalprg)
1611 call assert_equal('gprg', &equalprg)
Milly484face2024-10-12 11:26:06 +02001612
1613 " :setlocal {option}< set the effective value of {option} to its global value.
Bram Moolenaar004a6782020-04-11 17:09:31 +02001614 setglobal equalprg=gnewprg
1615 setlocal equalprg=lnewprg
1616 setlocal equalprg<
1617 call assert_equal('gnewprg', &l:equalprg)
1618 call assert_equal('gnewprg', &equalprg)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001619
Milly484face2024-10-12 11:26:06 +02001620 set equalprg&
1621endfunc
1622
1623" Test for setting number global-local option value
1624func Test_set_number_global_local_option()
1625 setglobal scrolloff=10
1626 setlocal scrolloff=12
1627 call assert_equal(10, &g:scrolloff)
1628 call assert_equal(12, &l:scrolloff)
1629 call assert_equal(12, &scrolloff)
1630
1631 " :set {option}< set the effective value of {option} to its global value.
1632 set scrolloff<
1633 call assert_equal(10, &l:scrolloff)
1634 call assert_equal(10, &scrolloff)
1635
1636 " :setlocal {option}< removes the local value, so that the global value will be used.
1637 setglobal scrolloff=15
1638 setlocal scrolloff=18
1639 setlocal scrolloff<
1640 call assert_equal(-1, &l:scrolloff)
1641 call assert_equal(15, &scrolloff)
1642
1643 set scrolloff&
1644endfunc
1645
1646" Test for setting boolean global-local option value
1647func Test_set_boolean_global_local_option()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001648 setglobal autoread
1649 setlocal noautoread
Milly484face2024-10-12 11:26:06 +02001650 call assert_equal(1, &g:autoread)
1651 call assert_equal(0, &l:autoread)
1652 call assert_equal(0, &autoread)
1653
1654 " :set {option}< set the effective value of {option} to its global value.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001655 set autoread<
Milly484face2024-10-12 11:26:06 +02001656 call assert_equal(1, &l:autoread)
1657 call assert_equal(1, &autoread)
1658
1659 " :setlocal {option}< removes the local value, so that the global value will be used.
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001660 setglobal noautoread
1661 setlocal autoread
1662 setlocal autoread<
Milly484face2024-10-12 11:26:06 +02001663 call assert_equal(-1, &l:autoread)
1664 call assert_equal(0, &autoread)
1665
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001666 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001667endfunc
1668
Dominique Pelle042414f2021-07-12 21:43:19 +02001669func Test_set_in_sandbox()
1670 " Some boolean options cannot be set in sandbox, some can.
1671 call assert_fails('sandbox set modelineexpr', 'E48:')
1672 sandbox set number
1673 call assert_true(&number)
1674 set number&
1675
1676 " Some boolean options cannot be set in sandbox, some can.
1677 if has('python') || has('python3')
1678 call assert_fails('sandbox set pyxversion=3', 'E48:')
1679 endif
1680 sandbox set tabstop=4
1681 call assert_equal(4, &tabstop)
1682 set tabstop&
1683
1684 " Some string options cannot be set in sandbox, some can.
1685 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1686 sandbox set filetype=perl
1687 call assert_equal('perl', &filetype)
1688 set filetype&
1689endfunc
1690
Milly484face2024-10-12 11:26:06 +02001691" Test for setting string option value
1692func Test_set_string_option()
1693 " :set {option}=
1694 set makeprg=
1695 call assert_equal('', &mp)
1696 set makeprg=abc
1697 call assert_equal('abc', &mp)
1698
1699 " :set {option}:
1700 set makeprg:
1701 call assert_equal('', &mp)
1702 set makeprg:abc
1703 call assert_equal('abc', &mp)
1704
1705 " Let string
1706 let &makeprg = ''
1707 call assert_equal('', &mp)
1708 let &makeprg = 'abc'
1709 call assert_equal('abc', &mp)
1710
1711 " Let number converts to string
1712 let &makeprg = 42
1713 call assert_equal('42', &mp)
1714
1715 " Appending
1716 set makeprg=abc
1717 set makeprg+=def
1718 call assert_equal('abcdef', &mp)
1719 set makeprg+=def
1720 call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
1721 let &makeprg .= 'gh'
1722 call assert_equal('abcdefdefgh', &mp)
1723 let &makeprg ..= 'ij'
1724 call assert_equal('abcdefdefghij', &mp)
1725
1726 " Removing
1727 set makeprg=abcdefghi
1728 set makeprg-=def
1729 call assert_equal('abcghi', &mp)
1730 set makeprg-=def
1731 call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
1732
1733 " Prepending
1734 set makeprg=abc
1735 set makeprg^=def
1736 call assert_equal('defabc', &mp)
1737 set makeprg^=def
1738 call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
1739
1740 set makeprg&
1741endfunc
1742
1743" Test for setting string comma-separated list option value
1744func Test_set_string_comma_list_option()
1745 " :set {option}=
1746 set wildignore=
1747 call assert_equal('', &wildignore)
1748 set wildignore=*.png
1749 call assert_equal('*.png', &wildignore)
1750
1751 " :set {option}:
1752 set wildignore:
1753 call assert_equal('', &wildignore)
1754 set wildignore:*.png
1755 call assert_equal('*.png', &wildignore)
1756
1757 " Let string
1758 let &wildignore = ''
1759 call assert_equal('', &wildignore)
1760 let &wildignore = '*.png'
1761 call assert_equal('*.png', &wildignore)
1762
1763 " Let number converts to string
1764 let &wildignore = 42
1765 call assert_equal('42', &wildignore)
1766
1767 " Appending
1768 set wildignore=*.png
1769 set wildignore+=*.jpg
1770 call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
1771 set wildignore+=*.jpg
1772 call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
1773 set wildignore+=jpg
1774 call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
1775 let &wildignore .= 'foo'
1776 call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
1777 let &wildignore ..= 'bar'
1778 call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
1779
1780 " Removing
1781 set wildignore=*.png,*.jpg,*.obj
1782 set wildignore-=*.jpg
1783 call assert_equal('*.png,*.obj', &wildignore)
1784 set wildignore-=*.jpg
1785 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
1786 set wildignore-=jpg
1787 call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
1788
1789 " Prepending
1790 set wildignore=*.png
1791 set wildignore^=*.jpg
1792 call assert_equal('*.jpg,*.png', &wildignore)
1793 set wildignore^=*.jpg
1794 call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
1795 set wildignore^=jpg
1796 call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
1797
1798 set wildignore&
1799endfunc
1800
1801" Test for setting string flags option value
1802func Test_set_string_flags_option()
1803 " :set {option}=
1804 set formatoptions=
1805 call assert_equal('', &fo)
1806 set formatoptions=abc
1807 call assert_equal('abc', &fo)
1808
1809 " :set {option}:
1810 set formatoptions:
1811 call assert_equal('', &fo)
1812 set formatoptions:abc
1813 call assert_equal('abc', &fo)
1814
1815 " Let string
1816 let &formatoptions = ''
1817 call assert_equal('', &fo)
1818 let &formatoptions = 'abc'
1819 call assert_equal('abc', &fo)
1820
1821 " Let number converts to string
1822 let &formatoptions = 12
1823 call assert_equal('12', &fo)
1824
1825 " Appending
1826 set formatoptions=abc
1827 set formatoptions+=pqr
1828 call assert_equal('abcpqr', &fo)
1829 set formatoptions+=pqr
1830 call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
1831 let &formatoptions .= 'r'
1832 call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
1833 let &formatoptions ..= 'r'
1834 call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
1835
1836 " Removing
1837 set formatoptions=abcpqr
1838 set formatoptions-=cp
1839 call assert_equal('abqr', &fo)
1840 set formatoptions-=cp
1841 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
1842 set formatoptions-=ar
1843 call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
1844
1845 " Prepending
1846 set formatoptions=abc
1847 set formatoptions^=pqr
1848 call assert_equal('pqrabc', &fo)
1849 set formatoptions^=qr
1850 call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
1851
1852 set formatoptions&
1853endfunc
1854
1855" Test for setting number option value
1856func Test_set_number_option()
1857 " :set {option}=
1858 set scrolljump=5
1859 call assert_equal(5, &sj)
1860 set scrolljump=-3
1861 call assert_equal(-3, &sj)
1862
1863 " :set {option}:
1864 set scrolljump:7
1865 call assert_equal(7, &sj)
1866 set scrolljump:-5
1867 call assert_equal(-5, &sj)
1868
1869 " Set hex
1870 set scrolljump=0x10
1871 call assert_equal(16, &sj)
1872 set scrolljump=-0x10
1873 call assert_equal(-16, &sj)
1874 set scrolljump=0X12
1875 call assert_equal(18, &sj)
1876 set scrolljump=-0X12
1877 call assert_equal(-18, &sj)
1878
1879 " Set octal
1880 set scrolljump=010
1881 call assert_equal(8, &sj)
1882 set scrolljump=-010
1883 call assert_equal(-8, &sj)
1884 set scrolljump=0o12
1885 call assert_equal(10, &sj)
1886 set scrolljump=-0o12
1887 call assert_equal(-10, &sj)
1888 set scrolljump=0O15
1889 call assert_equal(13, &sj)
1890 set scrolljump=-0O15
1891 call assert_equal(-13, &sj)
1892
1893 " Let number
1894 let &scrolljump = 4
1895 call assert_equal(4, &sj)
1896 let &scrolljump = -6
1897 call assert_equal(-6, &sj)
1898
1899 " Let numeric string converts to number
1900 let &scrolljump = '7'
1901 call assert_equal(7, &sj)
1902 let &scrolljump = '-9'
1903 call assert_equal(-9, &sj)
1904
1905 " Incrementing
Bram Moolenaar004a6782020-04-11 17:09:31 +02001906 set shiftwidth=4
1907 set sw+=2
1908 call assert_equal(6, &sw)
Milly484face2024-10-12 11:26:06 +02001909 let &shiftwidth += 2
1910 call assert_equal(8, &sw)
1911
1912 " Decrementing
1913 set shiftwidth=6
Bram Moolenaar004a6782020-04-11 17:09:31 +02001914 set sw-=2
1915 call assert_equal(4, &sw)
Milly484face2024-10-12 11:26:06 +02001916 let &shiftwidth -= 2
1917 call assert_equal(2, &sw)
1918
1919 " Multiplying
1920 set shiftwidth=4
Bram Moolenaar004a6782020-04-11 17:09:31 +02001921 set sw^=2
1922 call assert_equal(8, &sw)
Milly484face2024-10-12 11:26:06 +02001923 let &shiftwidth *= 2
1924 call assert_equal(16, &sw)
1925
1926 set scrolljump&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001927 set shiftwidth&
1928endfunc
1929
Milly484face2024-10-12 11:26:06 +02001930" Test for setting boolean option value
1931func Test_set_boolean_option()
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001932 set number&
Milly484face2024-10-12 11:26:06 +02001933
1934 " :set {option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001935 set number
1936 call assert_equal(1, &nu)
Milly484face2024-10-12 11:26:06 +02001937
1938 " :set no{option}
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001939 set nonu
1940 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001941
1942 " :set {option}!
1943 set number!
1944 call assert_equal(1, &nu)
1945 set number!
1946 call assert_equal(0, &nu)
1947
1948 " :set inv{option}
1949 set invnumber
1950 call assert_equal(1, &nu)
1951 set invnumber
1952 call assert_equal(0, &nu)
1953
1954 " Let number
1955 let &number = 1
1956 call assert_equal(1, &nu)
1957 let &number = 0
1958 call assert_equal(0, &nu)
1959
1960 " Let numeric string converts to number
1961 let &number = '1'
1962 call assert_equal(1, &nu)
1963 let &number = '0'
1964 call assert_equal(0, &nu)
1965
1966 " Let v:true and v:false
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001967 let &nu = v:true
1968 call assert_equal(1, &nu)
1969 let &nu = v:false
1970 call assert_equal(0, &nu)
Milly484face2024-10-12 11:26:06 +02001971
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001972 set number&
1973endfunc
1974
Milly484face2024-10-12 11:26:06 +02001975" Test for setting string option errors
1976func Test_set_string_option_errors()
1977 " :set no{option}
1978 call assert_fails('set nomakeprg', 'E474:')
1979 call assert_fails('setlocal nomakeprg', 'E474:')
1980 call assert_fails('setglobal nomakeprg', 'E474:')
1981
1982 " :set inv{option}
1983 call assert_fails('set invmakeprg', 'E474:')
1984 call assert_fails('setlocal invmakeprg', 'E474:')
1985 call assert_fails('setglobal invmakeprg', 'E474:')
1986
1987 " :set {option}!
1988 call assert_fails('set makeprg!', 'E488:')
1989 call assert_fails('setlocal makeprg!', 'E488:')
1990 call assert_fails('setglobal makeprg!', 'E488:')
1991
1992 " Invalid trailing chars
1993 call assert_fails('set makeprg??', 'E488:')
1994 call assert_fails('setlocal makeprg??', 'E488:')
1995 call assert_fails('setglobal makeprg??', 'E488:')
1996 call assert_fails('set makeprg&&', 'E488:')
1997 call assert_fails('setlocal makeprg&&', 'E488:')
1998 call assert_fails('setglobal makeprg&&', 'E488:')
1999 call assert_fails('set makeprg<<', 'E488:')
2000 call assert_fails('setlocal makeprg<<', 'E488:')
2001 call assert_fails('setglobal makeprg<<', 'E488:')
2002 call assert_fails('set makeprg@', 'E488:')
2003 call assert_fails('setlocal makeprg@', 'E488:')
2004 call assert_fails('setglobal makeprg@', 'E488:')
2005
2006 " Invalid type
2007 call assert_fails("let &makeprg = ['xxx']", 'E730:')
2008endfunc
2009
2010" Test for setting number option errors
2011func Test_set_number_option_errors()
2012 " :set no{option}
2013 call assert_fails('set notabstop', 'E474:')
2014 call assert_fails('setlocal notabstop', 'E474:')
2015 call assert_fails('setglobal notabstop', 'E474:')
2016
2017 " :set inv{option}
2018 call assert_fails('set invtabstop', 'E474:')
2019 call assert_fails('setlocal invtabstop', 'E474:')
2020 call assert_fails('setglobal invtabstop', 'E474:')
2021
2022 " :set {option}!
2023 call assert_fails('set tabstop!', 'E488:')
2024 call assert_fails('setlocal tabstop!', 'E488:')
2025 call assert_fails('setglobal tabstop!', 'E488:')
2026
2027 " Invalid trailing chars
2028 call assert_fails('set tabstop??', 'E488:')
2029 call assert_fails('setlocal tabstop??', 'E488:')
2030 call assert_fails('setglobal tabstop??', 'E488:')
2031 call assert_fails('set tabstop&&', 'E488:')
2032 call assert_fails('setlocal tabstop&&', 'E488:')
2033 call assert_fails('setglobal tabstop&&', 'E488:')
2034 call assert_fails('set tabstop<<', 'E488:')
2035 call assert_fails('setlocal tabstop<<', 'E488:')
2036 call assert_fails('setglobal tabstop<<', 'E488:')
2037 call assert_fails('set tabstop@', 'E488:')
2038 call assert_fails('setlocal tabstop@', 'E488:')
2039 call assert_fails('setglobal tabstop@', 'E488:')
2040
2041 " Not a number
2042 call assert_fails('set tabstop=', 'E521:')
2043 call assert_fails('setlocal tabstop=', 'E521:')
2044 call assert_fails('setglobal tabstop=', 'E521:')
2045 call assert_fails('set tabstop=x', 'E521:')
2046 call assert_fails('setlocal tabstop=x', 'E521:')
2047 call assert_fails('setglobal tabstop=x', 'E521:')
2048 call assert_fails('set tabstop=1x', 'E521:')
2049 call assert_fails('setlocal tabstop=1x', 'E521:')
2050 call assert_fails('setglobal tabstop=1x', 'E521:')
2051 call assert_fails('set tabstop=-x', 'E521:')
2052 call assert_fails('setlocal tabstop=-x', 'E521:')
2053 call assert_fails('setglobal tabstop=-x', 'E521:')
2054 call assert_fails('set tabstop=0x', 'E521:')
2055 call assert_fails('setlocal tabstop=0x', 'E521:')
2056 call assert_fails('setglobal tabstop=0x', 'E521:')
2057 call assert_fails('set tabstop=0o', 'E521:')
2058 call assert_fails('setlocal tabstop=0o', 'E521:')
2059 call assert_fails('setglobal tabstop=0o', 'E521:')
2060 call assert_fails("let &tabstop = 'x'", 'E521:')
2061 call assert_fails("let &g:tabstop = 'x'", 'E521:')
2062 call assert_fails("let &l:tabstop = 'x'", 'E521:')
2063
2064 " Invalid type
2065 call assert_fails("let &tabstop = 'xxx'", 'E521:')
2066endfunc
2067
2068" Test for setting boolean option errors
2069func Test_set_boolean_option_errors()
2070 " :set {option}=
2071 call assert_fails('set number=', 'E474:')
2072 call assert_fails('setlocal number=', 'E474:')
2073 call assert_fails('setglobal number=', 'E474:')
2074 call assert_fails('set number=1', 'E474:')
2075 call assert_fails('setlocal number=1', 'E474:')
2076 call assert_fails('setglobal number=1', 'E474:')
2077
2078 " :set {option}:
2079 call assert_fails('set number:', 'E474:')
2080 call assert_fails('setlocal number:', 'E474:')
2081 call assert_fails('setglobal number:', 'E474:')
2082 call assert_fails('set number:1', 'E474:')
2083 call assert_fails('setlocal number:1', 'E474:')
2084 call assert_fails('setglobal number:1', 'E474:')
2085
2086 " :set {option}+=
2087 call assert_fails('set number+=1', 'E474:')
2088 call assert_fails('setlocal number+=1', 'E474:')
2089 call assert_fails('setglobal number+=1', 'E474:')
2090
2091 " :set {option}^=
2092 call assert_fails('set number^=1', 'E474:')
2093 call assert_fails('setlocal number^=1', 'E474:')
2094 call assert_fails('setglobal number^=1', 'E474:')
2095
2096 " :set {option}-=
2097 call assert_fails('set number-=1', 'E474:')
2098 call assert_fails('setlocal number-=1', 'E474:')
2099 call assert_fails('setglobal number-=1', 'E474:')
2100
2101 " Invalid trailing chars
2102 call assert_fails('set number!!', 'E488:')
2103 call assert_fails('setlocal number!!', 'E488:')
2104 call assert_fails('setglobal number!!', 'E488:')
2105 call assert_fails('set number??', 'E488:')
2106 call assert_fails('setlocal number??', 'E488:')
2107 call assert_fails('setglobal number??', 'E488:')
2108 call assert_fails('set number&&', 'E488:')
2109 call assert_fails('setlocal number&&', 'E488:')
2110 call assert_fails('setglobal number&&', 'E488:')
2111 call assert_fails('set number<<', 'E488:')
2112 call assert_fails('setlocal number<<', 'E488:')
2113 call assert_fails('setglobal number<<', 'E488:')
2114 call assert_fails('set number@', 'E488:')
2115 call assert_fails('setlocal number@', 'E488:')
2116 call assert_fails('setglobal number@', 'E488:')
2117
2118 " Invalid type
2119 call assert_fails("let &number = 'xxx'", 'E521:')
2120endfunc
2121
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02002122" Test for the 'window' option
2123func Test_window_opt()
2124 " Needs only one open widow
2125 %bw!
2126 call setline(1, range(1, 8))
2127 set window=5
2128 exe "normal \<C-F>"
2129 call assert_equal(4, line('w0'))
2130 exe "normal \<C-F>"
2131 call assert_equal(7, line('w0'))
2132 exe "normal \<C-F>"
2133 call assert_equal(8, line('w0'))
2134 exe "normal \<C-B>"
2135 call assert_equal(5, line('w0'))
2136 exe "normal \<C-B>"
2137 call assert_equal(2, line('w0'))
2138 exe "normal \<C-B>"
2139 call assert_equal(1, line('w0'))
2140 set window=1
2141 exe "normal gg\<C-F>"
2142 call assert_equal(2, line('w0'))
2143 exe "normal \<C-F>"
2144 call assert_equal(3, line('w0'))
2145 exe "normal \<C-B>"
2146 call assert_equal(2, line('w0'))
2147 exe "normal \<C-B>"
2148 call assert_equal(1, line('w0'))
2149 enew!
2150 set window&
2151endfunc
2152
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002153" Test for the 'winminheight' option
2154func Test_opt_winminheight()
2155 only!
2156 let &winheight = &lines + 4
2157 call assert_fails('let &winminheight = &lines + 2', 'E36:')
2158 call assert_true(&winminheight <= &lines)
2159 set winminheight&
2160 set winheight&
2161endfunc
2162
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002163func Test_opt_winminheight_term()
2164 CheckRunVimInTerminal
2165
2166 " The tabline should be taken into account.
2167 let lines =<< trim END
2168 set wmh=0 stal=2
2169 below sp | wincmd _
2170 below sp | wincmd _
2171 below sp | wincmd _
2172 below sp
2173 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002174 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002175 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
2176 call term_sendkeys(buf, ":set wmh=1\n")
2177 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
2178
2179 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01002180endfunc
2181
Bram Moolenaar9e813b32021-03-13 14:29:05 +01002182func Test_opt_winminheight_term_tabs()
2183 CheckRunVimInTerminal
2184
2185 " The tabline should be taken into account.
2186 let lines =<< trim END
2187 set wmh=0 stal=2
2188 split
2189 split
2190 split
2191 split
2192 tabnew
2193 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002194 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +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 Moolenaar9e813b32021-03-13 14:29:05 +01002200endfunc
2201
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02002202" Test for the 'winminwidth' option
2203func Test_opt_winminwidth()
2204 only!
2205 let &winwidth = &columns + 4
2206 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
2207 call assert_true(&winminwidth <= &columns)
2208 set winminwidth&
2209 set winwidth&
2210endfunc
2211
Bram Moolenaar994b89d2020-08-07 19:12:41 +02002212" Test for setting option value containing spaces with isfname+=32
2213func Test_isfname_with_options()
2214 set isfname+=32
2215 setlocal keywordprg=:term\ help.exe
2216 call assert_equal(':term help.exe', &keywordprg)
2217 set isfname&
2218 setlocal keywordprg&
2219endfunc
2220
Bram Moolenaar74667062020-12-28 15:41:41 +01002221" Test that resetting laststatus does change scroll option
2222func Test_opt_reset_scroll()
2223 CheckRunVimInTerminal
2224 let vimrc =<< trim [CODE]
2225 set scroll=2
2226 set laststatus=2
2227 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002228 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01002229 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
2230 call term_sendkeys(buf, ":verbose set scroll?\n")
2231 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
2232 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01002233
2234 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01002235 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01002236endfunc
2237
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002238" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
2239func Test_VIM_POSIX()
2240 let saved_VIM_POSIX = getenv("VIM_POSIX")
2241
2242 call setenv('VIM_POSIX', "1")
2243 let after =<< trim [CODE]
2244 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2245 qall
2246 [CODE]
2247 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002248 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>#{|&/\.;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002249 \ 'AS'], readfile('X_VIM_POSIX'))
2250 endif
2251
2252 call setenv('VIM_POSIX', v:null)
2253 let after =<< trim [CODE]
2254 call writefile([&cpo, &shm], 'X_VIM_POSIX')
2255 qall
2256 [CODE]
2257 if RunVim([], after, '')
Christian Brabandt22105fd2024-07-15 20:51:11 +02002258 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZz$!%*-+<>;',
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02002259 \ 'S'], readfile('X_VIM_POSIX'))
2260 endif
2261
2262 call delete('X_VIM_POSIX')
2263 call setenv('VIM_POSIX', saved_VIM_POSIX)
2264endfunc
2265
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002266" Test for setting an option to a Vi or Vim default
2267func Test_opt_default()
2268 set formatoptions&vi
2269 call assert_equal('vt', &formatoptions)
2270 set formatoptions&vim
2271 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02002272
2273 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2274 set fencs=latin1
2275 set fencs&
2276 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
2277 set fencs=latin1
2278 set all&
2279 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002280endfunc
2281
2282" Test for the 'cmdheight' option
Milly2cddf0e2024-11-28 18:16:55 +01002283func Test_opt_cmdheight()
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002284 %bw!
2285 let ht = &lines
2286 set cmdheight=9999
2287 call assert_equal(1, winheight(0))
2288 call assert_equal(ht - 1, &cmdheight)
2289 set cmdheight&
Milly2cddf0e2024-11-28 18:16:55 +01002290
2291 " The status line should be taken into account.
2292 set laststatus=2
2293 set cmdheight=9999
2294 call assert_equal(ht - 2, &cmdheight)
2295 set cmdheight& laststatus&
2296
2297 " The tabline should be taken into account only non-GUI.
2298 set showtabline=2
2299 set cmdheight=9999
2300 if has('gui_running')
2301 call assert_equal(ht - 1, &cmdheight)
2302 else
2303 call assert_equal(ht - 2, &cmdheight)
2304 endif
2305 set cmdheight& showtabline&
2306
2307 " The 'winminheight' should be taken into account.
2308 set winheight=3 winminheight=3
2309 split
2310 set cmdheight=9999
2311 call assert_equal(ht - 8, &cmdheight)
2312 %bw!
2313 set cmdheight& winminheight& winheight&
2314
2315 " Only the windows in the current tabpage are taken into account.
2316 set winheight=3 winminheight=3 showtabline=0
2317 split
2318 tabnew
2319 set cmdheight=9999
2320 call assert_equal(ht - 3, &cmdheight)
2321 %bw!
2322 set cmdheight& winminheight& winheight& showtabline&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02002323endfunc
2324
Dominique Pelle923dce22021-11-21 11:36:04 +00002325" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02002326func Test_opt_control_char()
2327 set wildchar=^v
2328 call assert_equal("\<C-V>", nr2char(&wildchar))
2329 set wildcharm=^r
2330 call assert_equal("\<C-R>", nr2char(&wildcharm))
2331 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
2332 set wildchar& wildcharm&
2333endfunc
2334
2335" Test for the 'errorbells' option
2336func Test_opt_errorbells()
2337 set errorbells
2338 call assert_beeps('s/a1b2/x1y2/')
2339 set noerrorbells
2340endfunc
2341
Dominique Pelle042414f2021-07-12 21:43:19 +02002342func Test_opt_scrolljump()
2343 help
2344 resize 10
2345
2346 " Test with positive 'scrolljump'.
2347 set scrolljump=2
2348 norm! Lj
2349 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2350 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
2351 \ winsaveview())
2352
2353 " Test with negative 'scrolljump' (percentage of window height).
2354 set scrolljump=-40
2355 norm! ggLj
2356 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
2357 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
2358 \ winsaveview())
2359
2360 set scrolljump&
2361 bw
2362endfunc
2363
Bakudankun29f3a452021-12-11 12:28:08 +00002364" Test for the 'cdhome' option
2365func Test_opt_cdhome()
2366 if has('unix') || has('vms')
2367 throw 'Skipped: only works on non-Unix'
2368 endif
2369
2370 set cdhome&
2371 call assert_equal(0, &cdhome)
2372 set cdhome
2373
2374 " This paragraph is copied from Test_cd_no_arg().
2375 let path = getcwd()
2376 cd
2377 call assert_equal($HOME, getcwd())
2378 call assert_notequal(path, getcwd())
2379 exe 'cd ' .. fnameescape(path)
2380 call assert_equal(path, getcwd())
2381
2382 set cdhome&
2383endfunc
2384
Yee Cheng Chin900894b2023-09-29 20:42:32 +02002385func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01002386 CheckOption termguicolors
2387
2388 " Test default option completion
2389 set wildoptions=
2390 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2391 call assert_equal('"set termguicolors', @:)
2392
2393 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2394 call assert_equal('"set notermguicolors', @:)
2395
2396 " Test fuzzy option completion
2397 set wildoptions=fuzzy
2398 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
2399 call assert_equal('"set termguicolors termencoding', @:)
2400
2401 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
2402 call assert_equal('"set notermguicolors', @:)
2403
2404 set wildoptions=
2405endfunc
2406
Sean Dewar39c46b42022-05-12 17:44:29 +01002407func Test_switchbuf_reset()
2408 set switchbuf=useopen
2409 sblast
2410 call assert_equal(1, winnr('$'))
2411 set all&
2412 call assert_equal('', &switchbuf)
2413 sblast
2414 call assert_equal(2, winnr('$'))
2415 only!
2416endfunc
2417
zeertzjqfcba86c2022-09-22 13:57:32 +01002418" :set empty string for global 'keywordprg' falls back to ":help"
2419func Test_keywordprg_empty()
2420 let k = &keywordprg
2421 set keywordprg=man
2422 call assert_equal('man', &keywordprg)
2423 set keywordprg=
2424 call assert_equal(':help', &keywordprg)
2425 set keywordprg=man
2426 call assert_equal('man', &keywordprg)
2427 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
2428 let &keywordprg = k
2429endfunc
2430
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00002431" check that the very first buffer created does not have 'endoffile' set
2432func Test_endoffile_default()
2433 let after =<< trim [CODE]
2434 call writefile([execute('set eof?')], 'Xtestout')
2435 qall!
2436 [CODE]
2437 if RunVim([], after, '')
2438 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
2439 endif
2440 call delete('Xtestout')
2441endfunc
2442
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00002443" Test for setting the 'lines' and 'columns' options to a minimum value
2444func Test_set_min_lines_columns()
2445 let save_lines = &lines
2446 let save_columns = &columns
2447
2448 let after =<< trim END
2449 set nomore
2450 let msg = []
2451 let v:errmsg = ''
2452 silent! let &columns=0
2453 call add(msg, v:errmsg)
2454 silent! set columns=0
2455 call add(msg, v:errmsg)
2456 silent! call setbufvar('', '&columns', 0)
2457 call add(msg, v:errmsg)
2458 "call writefile(msg, 'XResultsetminlines')
2459 silent! let &lines=0
2460 call add(msg, v:errmsg)
2461 silent! set lines=0
2462 call add(msg, v:errmsg)
2463 silent! call setbufvar('', '&lines', 0)
2464 call add(msg, v:errmsg)
2465 call writefile(msg, 'XResultsetminlines')
2466 qall!
2467 END
2468 if RunVim([], after, '')
2469 call assert_equal(['E594: Need at least 12 columns',
2470 \ 'E594: Need at least 12 columns: columns=0',
2471 \ 'E594: Need at least 12 columns',
2472 \ 'E593: Need at least 2 lines',
2473 \ 'E593: Need at least 2 lines: lines=0',
2474 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
2475 endif
2476
2477 call delete('XResultsetminlines')
2478 let &lines = save_lines
2479 let &columns = save_columns
2480endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01002481
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002482" Test for reverting a string option value if the new value is invalid.
2483func Test_string_option_revert_on_failure()
2484 new
2485 let optlist = [
2486 \ ['ambiwidth', 'double', 'a123'],
2487 \ ['background', 'dark', 'a123'],
2488 \ ['backspace', 'eol', 'a123'],
2489 \ ['backupcopy', 'no', 'a123'],
2490 \ ['belloff', 'showmatch', 'a123'],
2491 \ ['breakindentopt', 'min:10', 'list'],
2492 \ ['bufhidden', 'wipe', 'a123'],
2493 \ ['buftype', 'nowrite', 'a123'],
2494 \ ['casemap', 'keepascii', 'a123'],
2495 \ ['cedit', "\<C-Y>", 'z'],
2496 \ ['colorcolumn', '10', 'z'],
2497 \ ['commentstring', '#%s', 'a123'],
2498 \ ['complete', '.,t', 'a'],
2499 \ ['completefunc', 'MyCmplFunc', '1a-'],
2500 \ ['completeopt', 'popup', 'a123'],
2501 \ ['completepopup', 'width:20', 'border'],
2502 \ ['concealcursor', 'v', 'xyz'],
2503 \ ['cpoptions', 'HJ', '~'],
2504 \ ['cryptmethod', 'zip', 'a123'],
2505 \ ['cursorlineopt', 'screenline', 'a123'],
2506 \ ['debug', 'throw', 'a123'],
2507 \ ['diffopt', 'iwhite', 'a123'],
2508 \ ['display', 'uhex', 'a123'],
2509 \ ['eadirection', 'hor', 'a123'],
2510 \ ['encoding', 'utf-8', 'a123'],
2511 \ ['eventignore', 'TextYankPost', 'a123'],
Luuk van Baalb7147f82025-02-08 18:52:39 +01002512 \ ['eventignorewin', 'WinScrolled', 'a123'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002513 \ ['fileencoding', 'utf-8', 'a123,'],
2514 \ ['fileformat', 'mac', 'a123'],
2515 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002516 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002517 \ ['fillchars', 'diff:~', 'a123'],
2518 \ ['foldclose', 'all', 'a123'],
2519 \ ['foldmarker', '[[[,]]]', '[[['],
2520 \ ['foldmethod', 'marker', 'a123'],
2521 \ ['foldopen', 'percent', 'a123'],
2522 \ ['formatoptions', 'an', '*'],
2523 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
2524 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002525 \ ['highlight', '!:CursorColumn', '8:'],
2526 \ ['keymodel', 'stopsel', 'a123'],
2527 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
2528 \ ['lispoptions', 'expr:1', 'a123'],
2529 \ ['listchars', 'tab:->', 'tab:'],
2530 \ ['matchpairs', '<:>', '<:'],
Christian Brabandt51d4d842024-12-06 17:26:25 +01002531 \ ['messagesopt', 'hit-enter,history:100', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002532 \ ['mkspellmem', '100000,1000,100', '100000'],
2533 \ ['mouse', 'nvi', 'z'],
2534 \ ['mousemodel', 'extend', 'a123'],
2535 \ ['nrformats', 'alpha', 'a123'],
2536 \ ['omnifunc', 'MyOmniFunc', '1a-'],
2537 \ ['operatorfunc', 'MyOpFunc', '1a-'],
2538 \ ['previewpopup', 'width:20', 'a123'],
2539 \ ['printoptions', 'paper:A4', 'a123:'],
2540 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
2541 \ ['rulerformat', '%l', '%['],
2542 \ ['scrollopt', 'hor,jump', 'a123'],
2543 \ ['selection', 'exclusive', 'a123'],
2544 \ ['selectmode', 'cmd', 'a123'],
2545 \ ['sessionoptions', 'options', 'a123'],
2546 \ ['shortmess', 'w', '2'],
2547 \ ['showbreak', '>>', "\x01"],
2548 \ ['showcmdloc', 'statusline', 'a123'],
2549 \ ['signcolumn', 'no', 'a123'],
2550 \ ['spellcapcheck', '[.?!]\+', '%\{'],
2551 \ ['spellfile', 'MySpell.en.add', "\x01"],
2552 \ ['spelllang', 'en', "#"],
2553 \ ['spelloptions', 'camel', 'a123'],
2554 \ ['spellsuggest', 'double', 'a123'],
2555 \ ['splitkeep', 'topline', 'a123'],
2556 \ ['statusline', '%f', '%['],
2557 \ ['swapsync', 'sync', 'a123'],
2558 \ ['switchbuf', 'usetab', 'a123'],
2559 \ ['syntax', 'abc', 'a^b'],
2560 \ ['tabline', '%f', '%['],
2561 \ ['tagcase', 'ignore', 'a123'],
2562 \ ['tagfunc', 'MyTagFunc', '1a-'],
2563 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
2564 \ ['viewoptions', 'options', 'a123'],
2565 \ ['virtualedit', 'onemore', 'a123'],
2566 \ ['whichwrap', '<,>', '{,}'],
2567 \ ['wildmode', 'list', 'a123'],
2568 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002569 \ ]
2570 if has('gui')
2571 call add(optlist, ['browsedir', 'buffer', 'a123'])
2572 endif
2573 if has('clipboard_working')
2574 call add(optlist, ['clipboard', 'unnamed', 'a123'])
2575 endif
2576 if has('win32')
2577 call add(optlist, ['completeslash', 'slash', 'a123'])
2578 endif
2579 if has('cscope')
2580 call add(optlist, ['cscopequickfix', 't-', 'z-'])
2581 endif
2582 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002583 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
2584 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
2585 endif
2586 if has('keymap')
2587 call add(optlist, ['keymap', 'greek', '[]'])
2588 endif
2589 if has('mouseshape')
2590 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
2591 endif
2592 if has('win32') && has('gui')
2593 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2594 endif
2595 if has('rightleft')
2596 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2597 endif
2598 if has('terminal')
2599 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2600 call add(optlist, ['termwinsize', '24x80', '100'])
2601 endif
2602 if has('win32') && has('terminal')
2603 call add(optlist, ['termwintype', 'winpty', 'a123'])
2604 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002605 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002606 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002607 endif
2608 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002609 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2610 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002611 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002612 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2613 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002614 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002615 call add(optlist, ['varsofttabstop', '12', 'a123'])
2616 call add(optlist, ['vartabstop', '4,20', '4,'])
2617 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002618 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002619 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002620 endif
2621 for opt in optlist
2622 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002623 try
2624 exe $"let &{opt[0]} = '{opt[1]}'"
2625 catch
2626 call assert_report($"Caught {v:exception} with {opt->string()}")
2627 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002628 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2629 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2630 exe $"let &{opt[0]} = save_opt"
2631 endfor
2632 bw!
2633endfunc
2634
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002635func Test_set_option_window_global_local()
2636 new Xbuffer1
2637 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2638 setlocal scrolloff=2
2639 setglobal scrolloff=3
2640 setl modified
2641 " A new buffer has its own window-local options
2642 hide enew
2643 call assert_equal(-1, &l:scrolloff)
2644 call assert_equal(3, &g:scrolloff)
2645 " A new window opened with its own buffer-local options
2646 new
2647 call assert_equal(-1, &l:scrolloff)
2648 call assert_equal(3, &g:scrolloff)
2649 " Re-open Xbuffer1 and it should use
2650 " the previous set window-local options
2651 b Xbuffer1
2652 call assert_equal(2, &l:scrolloff)
2653 call assert_equal(3, &g:scrolloff)
2654 bw!
2655 bw!
2656 let &g:scrolloff = _gso
2657endfunc
2658
2659func GetGlobalLocalWindowOptions()
2660 new
2661 sil! r $VIMRUNTIME/doc/options.txt
2662 " Filter for global or local to window
2663 v/^'.*'.*\n.*global or local to window |global-local/d
2664 " get option value and type
2665 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2666 sil %s/empty/""/g
2667 " split the result
2668 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2669 bw!
2670 return result
2671endfunc
2672
2673func Test_set_option_window_global_local_all()
2674 new Xbuffer2
2675
2676 let optionlist = GetGlobalLocalWindowOptions()
2677 for [opt, type, default] in optionlist
2678 let _old = eval('&g:' .. opt)
2679 if type == 'string'
2680 if opt == 'fillchars'
2681 exe 'setl ' .. opt .. '=vert:+'
2682 exe 'setg ' .. opt .. '=vert:+,fold:+'
2683 elseif opt == 'listchars'
2684 exe 'setl ' .. opt .. '=tab:>>'
2685 exe 'setg ' .. opt .. '=tab:++'
2686 elseif opt == 'virtualedit'
2687 exe 'setl ' .. opt .. '=all'
2688 exe 'setg ' .. opt .. '=block'
2689 else
2690 exe 'setl ' .. opt .. '=Local'
2691 exe 'setg ' .. opt .. '=Global'
2692 endif
2693 elseif type == 'number'
2694 exe 'setl ' .. opt .. '=5'
2695 exe 'setg ' .. opt .. '=10'
2696 endif
2697 setl modified
2698 hide enew
2699 if type == 'string'
2700 call assert_equal('', eval('&l:' .. opt))
2701 if opt == 'fillchars'
2702 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2703 elseif opt == 'listchars'
2704 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2705 elseif opt == 'virtualedit'
2706 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2707 else
2708 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2709 endif
2710 elseif type == 'number'
2711 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2712 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2713 endif
2714 bw!
2715 exe 'let &g:' .. opt .. '=' .. default
2716 endfor
2717 bw!
2718endfunc
2719
Christian Brabandt757593c2023-08-22 21:44:10 +02002720func Test_paste_depending_options()
2721 " setting the paste option, resets all dependent options
2722 " and will be reported correctly using :verbose set <option>?
2723 let lines =<< trim [CODE]
2724 " set paste test
2725 set autoindent
2726 set expandtab
2727 " disabled, because depends on compiled feature set
2728 " set hkmap
2729 " set revins
2730 " set varsofttabstop=8,32,8
2731 set ruler
2732 set showmatch
2733 set smarttab
2734 set softtabstop=4
2735 set textwidth=80
2736 set wrapmargin=10
2737
2738 source Xvimrc_paste2
2739
2740 redir > Xoutput_paste
2741 verbose set expandtab?
2742 verbose setg expandtab?
2743 verbose setl expandtab?
2744 redir END
2745
2746 qall!
2747 [CODE]
2748
2749 call writefile(lines, 'Xvimrc_paste', 'D')
2750 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2751 if !RunVim([], lines, '--clean')
2752 return
2753 endif
2754
2755 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2756 call assert_equal('noexpandtab', result[0])
2757 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2758 call assert_equal('noexpandtab', result[2])
2759 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2760 call assert_equal('noexpandtab', result[4])
2761 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2762
2763 call delete('Xoutput_paste')
2764endfunc
2765
2766func Test_binary_depending_options()
2767 " setting the paste option, resets all dependent options
2768 " and will be reported correctly using :verbose set <option>?
2769 let lines =<< trim [CODE]
2770 " set binary test
2771 set expandtab
2772
2773 source Xvimrc_bin2
2774
2775 redir > Xoutput_bin
2776 verbose set expandtab?
2777 verbose setg expandtab?
2778 verbose setl expandtab?
2779 redir END
2780
2781 qall!
2782 [CODE]
2783
2784 call writefile(lines, 'Xvimrc_bin', 'D')
2785 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2786 if !RunVim([], lines, '--clean')
2787 return
2788 endif
2789
2790 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2791 call assert_equal('noexpandtab', result[0])
2792 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2793 call assert_equal('noexpandtab', result[2])
2794 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2795 call assert_equal('noexpandtab', result[4])
2796 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2797
2798 call delete('Xoutput_bin')
2799endfunc
2800
Gregory Anders3695d0e2023-09-29 20:17:20 +02002801func Test_set_keyprotocol()
2802 CheckNotGui
2803
2804 let term = &term
2805 set term=ansi
2806 call assert_equal('', &t_TI)
2807
2808 " Setting 'keyprotocol' should affect terminal codes without needing to
2809 " reset 'term'
2810 set keyprotocol+=ansi:kitty
2811 call assert_equal("\<Esc>[=1;1u", &t_TI)
2812 let &term = term
2813endfunc
2814
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002815func Test_set_wrap()
2816 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2817 " cursor position.
2818 set wrap smoothscroll scrolloff=5
2819
2820 call setline(1, ['', 'aaaa'->repeat(500)])
2821 20 split
2822 20 vsplit
2823 norm 2G$
2824 redraw
2825 set nowrap
2826 call assert_equal(2, winline())
2827
2828 set wrap& smoothscroll& scrolloff&
2829endfunc
2830
zeertzjqcd3a13e2024-02-24 16:51:32 +01002831func Test_delcombine()
2832 new
2833 set backspace=indent,eol,start
2834
2835 set delcombine
2836 call setline(1, 'β̳̈:β̳̈')
2837 normal! 0x
2838 call assert_equal('β̈:β̳̈', getline(1))
2839 exe "normal! A\<BS>"
2840 call assert_equal('β̈:β̈', getline(1))
2841 normal! 0x
2842 call assert_equal('β:β̈', getline(1))
2843 exe "normal! A\<BS>"
2844 call assert_equal('β:β', getline(1))
2845 normal! 0x
2846 call assert_equal(':β', getline(1))
2847 exe "normal! A\<BS>"
2848 call assert_equal(':', getline(1))
2849
2850 set nodelcombine
2851 call setline(1, 'β̳̈:β̳̈')
2852 normal! 0x
2853 call assert_equal(':β̳̈', getline(1))
2854 exe "normal! A\<BS>"
2855 call assert_equal(':', getline(1))
2856
2857 set backspace& delcombine&
2858 bwipe!
2859endfunc
2860
Milly484face2024-10-12 11:26:06 +02002861" Should not raise errors when set missing-options.
2862func Test_set_missing_options()
2863 set autoprint
2864 set beautify
2865 set flash
2866 set graphic
2867 set hardtabs=8
2868 set mesg
2869 set novice
2870 set open
2871 set optimize
2872 set redraw
2873 set slowopen
2874 set sourceany
2875 set w300=23
2876 set w1200=23
2877 set w9600=23
2878endfunc
2879
Christian Brabandt231b4fc2024-12-28 16:27:49 +01002880func Test_default_keyprotocol()
2881 " default value of keyprotocol
2882 call assert_equal('kitty:kitty,foot:kitty,ghostty:kitty,wezterm:kitty,xterm:mok2', &keyprotocol)
2883endfunc
2884
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002885" vim: shiftwidth=2 sts=2 expandtab