blob: 908f0da1247742456fd044c5f31b3e32aea0f76f [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
Bram Moolenaar1e115362019-01-09 23:01:02 +01007func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02008 set whichwrap=b,s
9 call assert_equal('b,s', &whichwrap)
10
11 set whichwrap+=h,l
12 call assert_equal('b,s,h,l', &whichwrap)
13
14 set whichwrap+=h,l
15 call assert_equal('b,s,h,l', &whichwrap)
16
17 set whichwrap+=h,l
18 call assert_equal('b,s,h,l', &whichwrap)
19
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010020 set whichwrap=h,h
21 call assert_equal('h', &whichwrap)
22
23 set whichwrap=h,h,h
24 call assert_equal('h', &whichwrap)
25
Bram Moolenaar004a6782020-04-11 17:09:31 +020026 " For compatibility with Vim 3.0 and before, number values are also
27 " supported for 'whichwrap'
28 set whichwrap=1
29 call assert_equal('b', &whichwrap)
30 set whichwrap=2
31 call assert_equal('s', &whichwrap)
32 set whichwrap=4
33 call assert_equal('h,l', &whichwrap)
34 set whichwrap=8
35 call assert_equal('<,>', &whichwrap)
36 set whichwrap=16
37 call assert_equal('[,]', &whichwrap)
38 set whichwrap=31
39 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
40
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020041 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010042endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020043
Bram Moolenaar1e115362019-01-09 23:01:02 +010044func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010045 " This used to cause Vim to access uninitialized memory.
46 set isfname=
47 call assert_equal("~X", expand("~X"))
48 set isfname&
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +000049 " Test for setting 'isfname' to an unsupported character
50 let save_isfname = &isfname
51 call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
52 call assert_equal(save_isfname, &isfname)
Bram Moolenaar1e115362019-01-09 23:01:02 +010053endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010054
zeertzjq0519ce02022-05-09 12:16:19 +010055" Test for getting the value of 'pastetoggle'
56func Test_pastetoggle()
57 " character with K_SPECIAL byte
58 let &pastetoggle = '…'
59 call assert_equal('…', &pastetoggle)
60 call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
61
62 " modified character with K_SPECIAL byte
63 let &pastetoggle = '<M-…>'
64 call assert_equal('<M-…>', &pastetoggle)
65 call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
66
67 " illegal bytes
68 let str = ":\x7f:\x80:\x90:\xd0:"
69 let &pastetoggle = str
70 call assert_equal(str, &pastetoggle)
71 call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
zeertzjqbb404f52022-07-23 06:25:29 +010072
zeertzjq0519ce02022-05-09 12:16:19 +010073 unlet str
zeertzjqbb404f52022-07-23 06:25:29 +010074 set pastetoggle&
zeertzjq0519ce02022-05-09 12:16:19 +010075endfunc
76
Bram Moolenaar1e115362019-01-09 23:01:02 +010077func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010078 " Empty 'wildchar' used to access invalid memory.
79 call assert_fails('set wildchar=', 'E521:')
80 call assert_fails('set wildchar=abc', 'E521:')
81 set wildchar=<Esc>
82 let a=execute('set wildchar?')
83 call assert_equal("\n wildchar=<Esc>", a)
84 set wildchar=27
85 let a=execute('set wildchar?')
86 call assert_equal("\n wildchar=<Esc>", a)
87 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010088endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010089
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020090func Test_wildoptions()
91 set wildoptions=
92 set wildoptions+=tagfile
93 set wildoptions+=tagfile
94 call assert_equal('tagfile', &wildoptions)
95endfunc
96
Bram Moolenaar6b915c02020-01-18 15:53:19 +010097func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020098 let caught = 'ok'
99 try
100 options
101 catch
102 let caught = v:throwpoint . "\n" . v:exception
103 endtry
104 call assert_equal('ok', caught)
105
Bram Moolenaare0b59492019-05-21 20:54:45 +0200106 " Check if the option-window is opened horizontally.
107 wincmd j
108 call assert_notequal('option-window', bufname(''))
109 wincmd k
110 call assert_equal('option-window', bufname(''))
111 " close option-window
112 close
113
114 " Open the option-window vertically.
115 vert options
116 " Check if the option-window is opened vertically.
117 wincmd l
118 call assert_notequal('option-window', bufname(''))
119 wincmd h
120 call assert_equal('option-window', bufname(''))
121 " close option-window
122 close
123
Bram Moolenaar7a1637f2020-04-13 21:16:21 +0200124 " Open the option-window at the top.
125 set splitbelow
126 topleft options
127 call assert_equal(1, winnr())
128 close
129
130 " Open the option-window at the bottom.
131 set nosplitbelow
132 botright options
133 call assert_equal(winnr('$'), winnr())
134 close
135 set splitbelow&
136
Bram Moolenaare0b59492019-05-21 20:54:45 +0200137 " Open the option-window in a new tab.
138 tab options
139 " Check if the option-window is opened in a tab.
140 normal gT
141 call assert_notequal('option-window', bufname(''))
142 normal gt
143 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200144 " close option-window
145 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200146
147 " Open the options window browse
148 if has('browse')
149 browse set
150 call assert_equal('option-window', bufname(''))
151 close
152 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100153endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200154
Bram Moolenaar1e115362019-01-09 23:01:02 +0100155func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200156 " Test that changing 'path' keeps two commas.
157 set path=foo,,bar
158 set path-=bar
159 set path+=bar
160 call assert_equal('foo,,bar', &path)
161
162 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100163endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200164
Dominique Pellef645ee42021-12-05 13:21:18 +0000165func Test_path_too_long()
166 exe 'set path=' .. repeat('x', 10000)
167 call assert_fails('find x', 'E854:')
168 set path&
169endfunc
170
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200171func Test_signcolumn()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200172 CheckFeature signs
173 call assert_equal("auto", &signcolumn)
174 set signcolumn=yes
175 set signcolumn=no
176 call assert_fails('set signcolumn=nope')
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200177endfunc
178
Bram Moolenaard0b51382016-11-04 15:23:45 +0100179func Test_filetype_valid()
180 set ft=valid_name
181 call assert_equal("valid_name", &filetype)
182 set ft=valid-name
183 call assert_equal("valid-name", &filetype)
184
185 call assert_fails(":set ft=wrong;name", "E474:")
186 call assert_fails(":set ft=wrong\\\\name", "E474:")
187 call assert_fails(":set ft=wrong\\|name", "E474:")
188 call assert_fails(":set ft=wrong/name", "E474:")
189 call assert_fails(":set ft=wrong\\\nname", "E474:")
190 call assert_equal("valid-name", &filetype)
191
192 exe "set ft=trunc\x00name"
193 call assert_equal("trunc", &filetype)
194endfunc
195
196func Test_syntax_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200197 CheckFeature syntax
Bram Moolenaard0b51382016-11-04 15:23:45 +0100198 set syn=valid_name
199 call assert_equal("valid_name", &syntax)
200 set syn=valid-name
201 call assert_equal("valid-name", &syntax)
202
203 call assert_fails(":set syn=wrong;name", "E474:")
204 call assert_fails(":set syn=wrong\\\\name", "E474:")
205 call assert_fails(":set syn=wrong\\|name", "E474:")
206 call assert_fails(":set syn=wrong/name", "E474:")
207 call assert_fails(":set syn=wrong\\\nname", "E474:")
208 call assert_equal("valid-name", &syntax)
209
210 exe "set syn=trunc\x00name"
211 call assert_equal("trunc", &syntax)
212endfunc
213
214func Test_keymap_valid()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200215 CheckFeature keymap
Bram Moolenaard0b51382016-11-04 15:23:45 +0100216 call assert_fails(":set kmp=valid_name", "E544:")
217 call assert_fails(":set kmp=valid_name", "valid_name")
218 call assert_fails(":set kmp=valid-name", "E544:")
219 call assert_fails(":set kmp=valid-name", "valid-name")
220
221 call assert_fails(":set kmp=wrong;name", "E474:")
222 call assert_fails(":set kmp=wrong\\\\name", "E474:")
223 call assert_fails(":set kmp=wrong\\|name", "E474:")
224 call assert_fails(":set kmp=wrong/name", "E474:")
225 call assert_fails(":set kmp=wrong\\\nname", "E474:")
226
227 call assert_fails(":set kmp=trunc\x00name", "E544:")
228 call assert_fails(":set kmp=trunc\x00name", "trunc")
229endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100230
Yee Cheng Chin8f4fb002023-10-17 10:06:56 +0200231func Test_wildchar_valid()
232 call assert_fails("set wildchar=<CR>", "E474:")
233 call assert_fails("set wildcharm=<C-C>", "E474:")
234endfunc
235
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100236func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100237 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100238 exe 'set ' . a:name . '=/usr/share/dict/words'
239 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
240 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
241 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
242 exe 'set ' . a:name . '=/usr/share/dict\ words'
243 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100244
245 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100246 call assert_fails("set " . a:name . "=/not&there", "E474:")
247 call assert_fails("set " . a:name . "=/not>there", "E474:")
248 call assert_fails("set " . a:name . "=/not.*there", "E474:")
249endfunc
250
Bram Moolenaar60629d62017-02-23 18:08:56 +0100251func Test_cinkeys()
252 " This used to cause invalid memory access
253 set cindent cinkeys=0
254 norm a
255 set cindent& cinkeys&
256endfunc
257
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100258func Test_dictionary()
259 call Check_dir_option('dictionary')
260endfunc
261
262func Test_thesaurus()
263 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100264endfun
265
Bram Moolenaar226c5342017-02-17 14:53:15 +0100266func Test_complete()
267 " Trailing single backslash used to cause invalid memory access.
268 set complete=s\
269 new
270 call feedkeys("i\<C-N>\<Esc>", 'xt')
271 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200272 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100273 set complete&
274endfun
275
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100276func Test_set_completion()
277 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
278 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
279
Bram Moolenaar297610b2019-12-27 17:20:55 +0100280 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
281 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
282
283 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
284 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
285
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100286 " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
287 " names with "no".
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100288 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100289 call assert_equal('"set nodiff nodigraph', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100290
291 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100292 call assert_equal('"set invdiff invdigraph', @:)
293
294 " Expanding "set noinv" does nothing.
295 call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
296 call assert_equal('"set noinv', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100297
298 " Expand abbreviation of options.
299 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarabdcfd12021-10-16 16:48:27 +0100300 call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100301
302 " Expand current value
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200303 call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
304 call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100305
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200306 call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
307 call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100308
309 " Expand key codes.
310 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
311 call assert_equal('"set <Help> <Home>', @:)
312
313 " Expand terminal options.
314 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200315 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200316 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100317
318 " Expand directories.
319 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
320 call assert_match(' ./samples/ ', @:)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200321 call assert_notmatch(' ./summarize.vim ', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200322 set cdpath&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100323
324 " Expand files and directories.
325 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200326 call assert_match(' ./samples/.* ./summarize.vim', @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100327
328 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
329 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Yee Cheng Chin54844852023-10-09 18:12:31 +0200330
331 " Expand files with spaces/commas in them. Make sure we delimit correctly.
332 "
333 " 'tags' allow for for spaces/commas to both act as delimiters, with actual
334 " spaces requiring double escape, and commas need a single escape.
335 " 'dictionary' is a normal comma-separated option where only commas act as
336 " delimiters, and both space/comma need one single escape.
337 " 'makeprg' is a non-comma-separated option. Commas don't need escape.
338 defer delete('Xfoo Xspace.txt')
339 defer delete('Xsp_dummy')
340 defer delete('Xbar,Xcomma.txt')
341 defer delete('Xcom_dummy')
342 call writefile([], 'Xfoo Xspace.txt')
343 call writefile([], 'Xsp_dummy')
344 call writefile([], 'Xbar,Xcomma.txt')
345 call writefile([], 'Xcom_dummy')
346
347 call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
348 call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
349 call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
350 call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
351 call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
352 call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
353
354 call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
355 call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
356 if has('win32')
357 " In Windows, '\,' is literal, see `:help filename-backslash`, so this
358 " means we treat it as one file name.
359 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
360 call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
361 else
362 " In other platforms, '\,' simply escape to ',', and indicate a delimiter
363 " to split into a separate file name. You need '\\,' to escape the comma
364 " as part of the file name.
365 call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
366 call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
367
368 call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
369 call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
370 endif
371 call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
372 call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
373 set tags& dictionary& makeprg&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200374
375 " Expanding the option names
376 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
377 call assert_equal('"set all', @:)
378
379 " Expanding a second set of option names
380 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
381 call assert_equal('"set wrapscan all', @:)
382
383 " Expanding a special keycode
384 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
385 call assert_equal('"set <Home>', @:)
386
387 " Expanding an invalid special keycode
388 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
389 call assert_equal("\"set <abcd>\<Tab>", @:)
390
391 " Expanding a terminal keycode
392 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
393 call assert_equal("\"set t_AB", @:)
394
395 " Expanding an invalid option name
396 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
397 call assert_equal("\"set abcde=\<Tab>", @:)
398
399 " Expanding after a = for a boolean option
400 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
401 call assert_equal("\"set wrapscan=\<Tab>", @:)
402
403 " Expanding a numeric option
404 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
405 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
406
407 " Expanding a non-boolean option
408 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
409 call assert_equal("\"set invtabstop=", @:)
410
411 " Expand options for 'spellsuggest'
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200412 call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
413 call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
414 call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
415 call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
Bram Moolenaar1363a302020-04-12 13:50:26 +0200416
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200417 " Expanding value for 'key' is disallowed
418 if exists('+key')
419 set key=abcd
420 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
421 call assert_equal('"set key=', @:)
422 call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
423 call assert_equal('"set key-=', @:)
424 set key=
425 endif
Bram Moolenaard5e8c922021-02-02 21:10:01 +0100426
427 " Expand values for 'filetype'
428 call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
429 call assert_equal('"set filetype=sshdconfig', @:)
430 call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
431 call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
Doug Kearns6dfdff32023-08-27 18:48:51 +0200432
433 " Expand values for 'syntax'
434 call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
435 call assert_equal('"set syntax=sshdconfig', @:)
436 call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
437 call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
Doug Kearns81642d92024-01-04 22:37:44 +0100438
439 if has('keymap')
440 " Expand values for 'keymap'
441 call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
442 call assert_equal('"set keymap=accents', @:)
443 call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
444 call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
445 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100446endfunc
447
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200448" Test handling of expanding individual string option values
449func Test_set_completion_string_values()
450 "
451 " Test basic enum string options that have well-defined enum names
452 "
453
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200454 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
455 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
456 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200457
458 " Test that if a value is set, it will populate the results, but only if
459 " typed value is empty.
460 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200461 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
462 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200463 " If the set value is part of the enum list, it will show as the first
464 " result with no duplicate.
465 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200466 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200467 " If empty value, will just show the normal list without an empty item
468 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200469 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200470 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200471 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200472
473 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200474 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200475 " Also test the positioning of the expansion is correct
476 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
477 call assert_equal('"set display=truncate,lastline', @:)
478 set display&
479
480 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200481 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200482
483 " Test the other simple options to make sure they have basic auto-complete,
484 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200485 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200486 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200487 call assert_equal('indent', getcompletion('set backspace=', 'cmdline')[0])
488 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
489 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
490 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200491 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200492 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200493 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200494 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
495 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
496 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200497 if exists('+clipboard')
498 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
499 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200500 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
501 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200502 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200503 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200504 endif
505 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200506 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200507 endif
508 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200509 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200510 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200511 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
512 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
513 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200514 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200515 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200516 endif
517 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200518 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200519 endif
520 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200521 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200522 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200523 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
524 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
525 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200526 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200527 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200528 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200529 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200530 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200531 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
532 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
533 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200534 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200535 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200536 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200537 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200538 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200540 endif
541 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200542 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200543 endif
544 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200545 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200546 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200547 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
548 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
549 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
550 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200551 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200552 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200553 endif
554 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200555 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200556 endif
557 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200558 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200559 endif
560 if exists('+ttymouse')
561 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200562 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200563 set ttymouse&
564 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200565 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
566 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
567 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
568 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200569 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200570 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200571 endif
572
573 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200574 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
575 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
576 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
577 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200578
zeertzjq1f025b02023-09-30 12:43:07 +0200579 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
580 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
581 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
582 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
583 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
584 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200585
586 "
587 " Unique string options below
588 "
589
590 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200591 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200592 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
593 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
594 set keyprotocol&
595
596 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200597 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
598 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200599 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
600 call assert_equal('"set previewpopup+=border:on', @:)
601 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
602 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200603 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200604 set previewpopup& completepopup&
605
606 " diffopt: special handling of algorithm:<alg_list>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200607 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
608 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
609 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200610
611 " highlight: special parsing, including auto-completing highlight groups
612 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200613 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
614 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
615 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
616 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
617 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200618 " If all the display modes are used up we should be suggesting nothing. Make
619 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
620 " and make sure nothing is suggested from that.
621 let hl_display_modes = join(
622 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
623 \ {idx, val -> val[1]}),
624 \ {idx, val -> val != ':'}),
625 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200626 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200627 " Test completion in middle of the line
628 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
629 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200630
631 "
632 " Test flag lists
633 "
634
635 " Test set=. Show the original value if nothing is typed after '='.
636 " Otherwise, the list should avoid showing what's already typed.
637 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200638 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200639 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200640 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
641 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200642
643 " Test set+=. Never show original value, and it also tries to avoid listing
644 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200645 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
646 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
647 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200648
649 " Test that the position of the expansion is correct (even if there are
650 " additional values after the current cursor)
651 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
652 call assert_equal('"set mouse=han', @:)
653 set mouse&
654
655 " Test that other flag list options have auto-complete, but don't
656 " exhaustively validate their results.
657 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200658 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200659 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200660 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
661 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200662 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200663 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200664 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200665 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
666 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200667
668 "
669 "Test set-=
670 "
671
672 " Normal single-value option just shows the existing value
673 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200674 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200675 set ambiwidth&
676
677 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200678 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200679 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200680 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200681 set t_Ce&
682
683 " Comma-separated lists should present each option
684 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200685 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
686 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
687 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200688 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200689 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200690 " Test empty option
691 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200692 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200693 set diffopt&
694
695 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200696 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200697
698 " Test files with commas in name are being parsed and escaped properly
699 set path=has\\\ space,file\\,with\\,comma,normal_file
700 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200701 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200703 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200704 endif
705 set path&
706
707 " Flag list should present orig value, then individual flags
708 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200709 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200710 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200711 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200712 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200713 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200714 " Test empty option
715 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200716 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200717 set mouse&
718
719 " 'whichwrap' is an odd case where it's both flag list and comma-separated
720 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200721 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200722 set ww&
723endfunc
724
zeertzjq4c7cb372023-06-14 16:39:54 +0100725func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100726 call assert_fails('set scroll=-1', 'E49:')
727 call assert_fails('set backupcopy=', 'E474:')
728 call assert_fails('set regexpengine=3', 'E474:')
729 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200730 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100731 call assert_fails('set colorcolumn=-a', 'E474:')
732 call assert_fails('set colorcolumn=a', 'E474:')
733 call assert_fails('set colorcolumn=1,', 'E474:')
734 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100735 call assert_fails('set cmdheight=-1', 'E487:')
736 call assert_fails('set cmdwinheight=-1', 'E487:')
737 if has('conceal')
738 call assert_fails('set conceallevel=-1', 'E487:')
739 call assert_fails('set conceallevel=4', 'E474:')
740 endif
741 call assert_fails('set helpheight=-1', 'E487:')
742 call assert_fails('set history=-1', 'E487:')
743 call assert_fails('set report=-1', 'E487:')
744 call assert_fails('set shiftwidth=-1', 'E487:')
745 call assert_fails('set sidescroll=-1', 'E487:')
746 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000747 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000748 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000749 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100750 call assert_fails('set textwidth=-1', 'E487:')
751 call assert_fails('set timeoutlen=-1', 'E487:')
752 call assert_fails('set updatecount=-1', 'E487:')
753 call assert_fails('set updatetime=-1', 'E487:')
754 call assert_fails('set winheight=-1', 'E487:')
755 call assert_fails('set tabstop!', 'E488:')
756 call assert_fails('set xxx', 'E518:')
757 call assert_fails('set beautify?', 'E519:')
758 call assert_fails('set undolevels=x', 'E521:')
759 call assert_fails('set tabstop=', 'E521:')
760 call assert_fails('set comments=-', 'E524:')
761 call assert_fails('set comments=a', 'E525:')
762 call assert_fails('set foldmarker=x', 'E536:')
763 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000764 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100765 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100766 call assert_fails('set rulerformat=%-', 'E539:')
767 call assert_fails('set rulerformat=%(', 'E542:')
768 call assert_fails('set rulerformat=%15(%%', 'E542:')
769 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100770 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100771 call assert_fails('set statusline=%{%', 'E540:')
772 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100773 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100774 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100775 call assert_fails('set tabline=%$', 'E539:')
776 call assert_fails('set tabline=%{', 'E540:')
777 call assert_fails('set tabline=%{%', 'E540:')
778 call assert_fails('set tabline=%{%}', 'E539:')
779 call assert_fails('set tabline=%(', 'E542:')
780 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100781
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100782 if has('cursorshape')
783 " This invalid value for 'guicursor' used to cause Vim to crash.
784 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
785 call assert_fails('set guicursor=i-ci', 'E545:')
786 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100787 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100788 call assert_fails('set guicursor=r-cr:horx', 'E548:')
789 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
790 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100791 if has('mouseshape')
792 call assert_fails('se mouseshape=i-r:x', 'E547:')
793 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000794
795 " Test for 'backupext' and 'patchmode' set to the same value
796 set backupext=.bak
797 set patchmode=.patch
798 call assert_fails('set patchmode=.bak', 'E589:')
799 call assert_equal('.patch', &patchmode)
800 call assert_fails('set backupext=.patch', 'E589:')
801 call assert_equal('.bak', &backupext)
802 set backupext& patchmode&
803
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100804 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200805 set winminheight& winheight&
806 set winheight=10 winminheight=10
807 call assert_fails('set winheight=9', 'E591:')
808 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100809 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200810 set winminwidth& winwidth&
811 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
812 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100813 call assert_fails("set showbreak=\x01", 'E595:')
814 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200815 call assert_fails('set tabstop??', 'E488:')
816 call assert_fails('set wrapscan!!', 'E488:')
817 call assert_fails('set tabstop&&', 'E488:')
818 call assert_fails('set wrapscan<<', 'E488:')
819 call assert_fails('set wrapscan=1', 'E474:')
820 call assert_fails('set autoindent@', 'E488:')
821 call assert_fails('set wildchar=<abc>', 'E474:')
822 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200823 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100824 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200825 call assert_fails('set pyxversion=6', 'E474:')
826 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100827 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200828 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100829 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
830 call assert_fails('set foldmarker={{{,', 'E474:')
831 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100832 setlocal listchars=trail
833 call assert_fails('set ambiwidth=double', 'E834:')
834 setlocal listchars=trail:-
835 setglobal listchars=trail
836 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100837 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100838 setlocal fillchars=stl
839 call assert_fails('set ambiwidth=double', 'E835:')
840 setlocal fillchars=stl:-
841 setglobal fillchars=stl
842 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100843 set fillchars&
844 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
845 set nomodifiable
846 call assert_fails('set fileencoding=latin1', 'E21:')
847 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200848 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000849 call assert_fails('let &formatoptions = "?"', 'E539:')
850 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100851 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
852 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
853 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
854 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
855 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
856 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100857endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100858
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000859func Test_set_encoding()
860 let save_encoding = &encoding
861
862 set enc=iso8859-1
863 call assert_equal('latin1', &enc)
864 set enc=iso8859_1
865 call assert_equal('latin1', &enc)
866 set enc=iso-8859-1
867 call assert_equal('latin1', &enc)
868 set enc=iso_8859_1
869 call assert_equal('latin1', &enc)
870 set enc=iso88591
871 call assert_equal('latin1', &enc)
872 set enc=iso8859
873 call assert_equal('latin1', &enc)
874 set enc=iso-8859
875 call assert_equal('latin1', &enc)
876 set enc=iso_8859
877 call assert_equal('latin1', &enc)
878 call assert_fails('set enc=iso8858', 'E474:')
879 call assert_equal('latin1', &enc)
880
881 let &encoding = save_encoding
882endfunc
883
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200884func CheckWasSet(name)
885 let verb_cm = execute('verbose set ' .. a:name .. '?')
886 call assert_match('Last set from.*test_options.vim', verb_cm)
887endfunc
888func CheckWasNotSet(name)
889 let verb_cm = execute('verbose set ' .. a:name .. '?')
890 call assert_notmatch('Last set from', verb_cm)
891endfunc
892
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200893" Must be executed before other tests that set 'term'.
894func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200895 CheckNotGui
896
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200897 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200898
899 let term_save = &term
900 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200901 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200902 let &term = term_save
903endfunc
904
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200905func Test_copy_context()
906 setlocal list
907 call CheckWasSet('list')
908 split
909 call CheckWasSet('list')
910 quit
911 setlocal nolist
912
913 set ai
914 call CheckWasSet('ai')
915 set filetype=perl
916 call CheckWasSet('filetype')
917 set fo=tcroq
918 call CheckWasSet('fo')
919
920 split Xsomebuf
921 call CheckWasSet('ai')
922 call CheckWasNotSet('filetype')
923 call CheckWasSet('fo')
924endfunc
925
Bram Moolenaar67391142017-02-19 21:07:04 +0100926func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200927 CheckUnix
928 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200929
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200930 " Setting 'ttytype' used to cause a double-free when exiting vim and
931 " when vim is compiled with -DEXITFREE.
932 set ttytype=ansi
933 call assert_equal('ansi', &ttytype)
934 call assert_equal(&ttytype, &term)
935 set ttytype=xterm
936 call assert_equal('xterm', &ttytype)
937 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200938 try
939 set ttytype=
940 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100941 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200942 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200943
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200944 " Some systems accept any terminal name and return dumb settings,
945 " check for failure of finding the entry and for missing 'cm' entry.
946 try
947 set ttytype=xxx
948 call assert_report('set ttytype=xxx did not fail')
949 catch /E522\|E437/
950 endtry
951
952 set ttytype&
953 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200954
955 if has('gui') && !has('gui_running')
956 call assert_fails('set term=gui', 'E531:')
957 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100958endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100959
960func Test_set_all()
961 set tw=75
962 set iskeyword=a-z,A-Z
963 set nosplitbelow
964 let out = execute('set all')
965 call assert_match('textwidth=75', out)
966 call assert_match('iskeyword=a-z,A-Z', out)
967 call assert_match('nosplitbelow', out)
968 set tw& iskeyword& splitbelow&
969endfunc
970
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100971func Test_set_one_column()
972 let out_mult = execute('set all')->split("\n")
973 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100974 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +0100975 call assert_equal(out_one[0], '--- Options ---')
976 let options = out_one[1:]->mapnew({_, line -> line[2:]})
977 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100978endfunc
979
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100980func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200981 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100982 if filereadable('opt_test.vim')
983 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100984 else
985 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100986 endif
987endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200988
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100989func Test_renderoptions()
990 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
991 " Doesn't hurt to do this on a non-Windows system.
992 if windowsversion() !~ '^[345]\.'
993 set renderoptions=type:directx
994 set rop=type:directx
995 endif
996endfunc
997
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200998func ResetIndentexpr()
999 set indentexpr=
1000endfunc
1001
1002func Test_set_indentexpr()
1003 " this was causing usage of freed memory
1004 set indentexpr=ResetIndentexpr()
1005 new
1006 call feedkeys("i\<c-f>", 'x')
1007 call assert_equal('', &indentexpr)
1008 bwipe!
1009endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001010
1011func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001012 " Option 'backupskip' may contain several comma-separated path
1013 " specifications if one or more of the environment variables TMPDIR, TMP,
1014 " or TEMP is defined. To simplify testing, convert the string value into a
1015 " list.
1016 let bsklist = split(&bsk, ',')
1017
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001018 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001019 let found = (index(bsklist, '/private/tmp/*') >= 0)
1020 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001021 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001022 let found = (index(bsklist, '/tmp/*') >= 0)
1023 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001024 endif
1025
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001026 " If our test platform is Windows, the path(s) in option bsk will use
1027 " backslash for the path separator and the components could be in short
1028 " (8.3) format. As such, we need to replace the backslashes with forward
1029 " slashes and convert the path components to long format. The expand()
1030 " function will do this but it cannot handle comma-separated paths. This is
1031 " why bsk was converted from a string into a list of strings above.
1032 "
1033 " One final complication is that the wildcard "/*" is at the end of each
1034 " path and so expand() might return a list of matching files. To prevent
1035 " this, we need to remove the wildcard before calling expand() and then
1036 " append it afterwards.
1037 if has('win32')
1038 let item_nbr = 0
1039 while item_nbr < len(bsklist)
1040 let path_spec = bsklist[item_nbr]
1041 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1042 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1043 let bsklist[item_nbr] = path_spec . '/*'
1044 let item_nbr += 1
1045 endwhile
1046 endif
1047
1048 " Option bsk will also include these environment variables if defined.
1049 " If they're defined, verify they appear in the option value.
1050 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001051 if exists(var)
1052 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001053 let varvalue = substitute(varvalue, '/$', '', '')
1054 let varvalue .= '/*'
1055 let found = (index(bsklist, varvalue) >= 0)
1056 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001057 endif
1058 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001059
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001060 " Duplicates from environment variables should be filtered out (option has
1061 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1062 " so that we see what happens on startup.
1063 let after =<< trim [CODE]
1064 let bsklist = split(&backupskip, ',')
1065 call assert_equal(uniq(copy(bsklist)), bsklist)
1066 call writefile(['errors:'] + v:errors, 'Xtestout')
1067 qall
1068 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001069 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001070 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1071
1072 let saveenv = {}
1073 for var in ['TMPDIR', 'TMP', 'TEMP']
1074 let saveenv[var] = getenv(var)
1075 call setenv(var, '/duplicate/path')
1076 endfor
1077
1078 exe 'silent !' . cmd
1079 call assert_equal(['errors:'], readfile('Xtestout'))
1080
1081 " restore environment variables
1082 for var in ['TMPDIR', 'TMP', 'TEMP']
1083 call setenv(var, saveenv[var])
1084 endfor
1085
1086 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001087
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001088 " Duplicates should be filtered out (option has P_NODUP)
1089 let backupskip = &backupskip
1090 set backupskip=
1091 set backupskip+=/test/dir
1092 set backupskip+=/other/dir
1093 set backupskip+=/test/dir
1094 call assert_equal('/test/dir,/other/dir', &backupskip)
1095 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001096endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001097
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001098func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001099 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001100
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001101 " Test copy option from current buffer in window
1102 split
1103 enew
1104 setlocal numberwidth=5
1105 wincmd w
1106 call assert_equal(4,&numberwidth)
1107 bnext
1108 call assert_equal(5,&numberwidth)
1109 bw!
1110 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001111
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001112 " Test copy value from window that used to be display the buffer
1113 split
1114 enew
1115 setlocal numberwidth=6
1116 bnext
1117 wincmd w
1118 call assert_equal(4,&numberwidth)
1119 bnext
1120 call assert_equal(6,&numberwidth)
1121 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001122
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001123 " Test that if buffer is current, don't use the stale cached value
1124 " from the last time the buffer was displayed.
1125 split
1126 enew
1127 setlocal numberwidth=7
1128 bnext
1129 bnext
1130 setlocal numberwidth=8
1131 wincmd w
1132 call assert_equal(4,&numberwidth)
1133 bnext
1134 call assert_equal(8,&numberwidth)
1135 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001136
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001137 " Test value is not copied if window already has seen the buffer
1138 enew
1139 split
1140 setlocal numberwidth=9
1141 bnext
1142 setlocal numberwidth=10
1143 wincmd w
1144 call assert_equal(4,&numberwidth)
1145 bnext
1146 call assert_equal(4,&numberwidth)
1147 bw!
1148
1149 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001150endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001151
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001152def Test_split_copy_options()
1153 var values = [
1154 ['cursorbind', true, false],
1155 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1156 ['list', true, 0],
1157 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1158 ['number', true, 0],
1159 ['relativenumber', true, false],
1160 ['scrollbind', true, false],
1161 ['smoothscroll', true, false],
1162 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1163 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1164 ['wrap', false, true],
1165 ]
1166 if has('linebreak')
1167 values += [
1168 ['breakindent', true, false],
1169 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1170 ['linebreak', true, false],
1171 ['numberwidth', 7, 4],
1172 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1173 ]
1174 endif
1175 if has('rightleft')
1176 values += [
1177 ['rightleft', true, false],
1178 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1179 ]
1180 endif
1181 if has('statusline')
1182 values += [
1183 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1184 ]
1185 endif
1186 if has('spell')
1187 values += [
1188 ['spell', true, false],
1189 ]
1190 endif
1191 if has('syntax')
1192 values += [
1193 ['cursorcolumn', true, false],
1194 ['cursorline', true, false],
1195 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1196 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1197 ]
1198 endif
1199 if has('diff')
1200 values += [
1201 ['diff', true, false],
1202 ]
1203 endif
1204 if has('conceal')
1205 values += [
1206 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1207 ['conceallevel', '3', &conceallevel],
1208 ]
1209 endif
1210 if has('terminal')
1211 values += [
1212 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1213 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1214 ]
1215 endif
1216 if has('folding')
1217 values += [
1218 ['foldcolumn', 5, &foldcolumn],
1219 ['foldenable', false, true],
1220 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1221 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1222 ['foldlevel', 4, &foldlevel],
1223 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1224 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1225 ['foldminlines', 3, &foldminlines],
1226 ['foldnestmax', 17, &foldnestmax],
1227 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1228 ]
1229 endif
1230 if has('signs')
1231 values += [
1232 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1233 ]
1234 endif
1235
1236 # set options to non-default value
1237 for item in values
1238 exe $'&l:{item[0]} = {item[1]}'
1239 endfor
1240
1241 # check values are set in new window
1242 split
1243 for item in values
1244 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1245 endfor
1246
1247 # restore
1248 close
1249 for item in values
1250 exe $'&l:{item[0]} = {item[2]}'
1251 endfor
1252enddef
1253
Bram Moolenaarfc089602018-06-24 16:53:35 +02001254func Test_shortmess_F()
1255 new
1256 call assert_match('\[No Name\]', execute('file'))
1257 set shortmess+=F
1258 call assert_match('\[No Name\]', execute('file'))
1259 call assert_match('^\s*$', execute('file foo'))
1260 call assert_match('foo', execute('file'))
1261 set shortmess-=F
1262 call assert_match('bar', execute('file bar'))
1263 call assert_match('bar', execute('file'))
1264 set shortmess&
1265 bwipe
1266endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001267
1268func Test_shortmess_F2()
1269 e file1
1270 e file2
1271 call assert_match('file1', execute('bn', ''))
1272 call assert_match('file2', execute('bn', ''))
1273 set shortmess+=F
1274 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001275 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001276 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001277 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001278 set hidden
1279 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001280 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001281 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001282 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001283 set nohidden
1284 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001285 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001286 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001287 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001288 set shortmess&
1289 call assert_match('file1', execute('bn', ''))
1290 call assert_match('file2', execute('bn', ''))
1291 bwipe
1292 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001293 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001294endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001295
1296func Test_local_scrolloff()
1297 set so=5
1298 set siso=7
1299 split
1300 call assert_equal(5, &so)
1301 setlocal so=3
1302 call assert_equal(3, &so)
1303 wincmd w
1304 call assert_equal(5, &so)
1305 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001306 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001307 setlocal so<
1308 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001309 setglob so=8
1310 call assert_equal(8, &so)
1311 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001312 setlocal so=0
1313 call assert_equal(0, &so)
1314 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001315 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001316
1317 call assert_equal(7, &siso)
1318 setlocal siso=3
1319 call assert_equal(3, &siso)
1320 wincmd w
1321 call assert_equal(7, &siso)
1322 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001323 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001324 setlocal siso<
1325 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001326 setglob siso=4
1327 call assert_equal(4, &siso)
1328 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001329 setlocal siso=0
1330 call assert_equal(0, &siso)
1331 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001332 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001333
1334 close
1335 set so&
1336 set siso&
1337endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001338
1339func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001340 CheckFunction reltimefloat
1341
Bram Moolenaar449ac472019-04-03 21:42:35 +02001342 new
1343 call setline(1, 'empty')
1344 redraw
1345 set writedelay=10
1346 let start = reltime()
1347 call setline(1, repeat('x', 70))
1348 redraw
1349 let elapsed = reltimefloat(reltime(start))
1350 set writedelay=0
1351 " With 'writedelay' set should take at least 30 * 10 msec
1352 call assert_inrange(30 * 0.01, 999.0, elapsed)
1353
1354 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001355endfunc
1356
1357func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001358 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001359 set visualbell
1360 call assert_beeps('normal 0h')
1361 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001362 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001363endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001364
1365" Test for the 'write' option
1366func Test_write()
1367 new
1368 call setline(1, ['L1'])
1369 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001370 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001371 set write
1372 close!
1373endfunc
1374
1375" Test for 'buftype' option
1376func Test_buftype()
1377 new
1378 call setline(1, ['L1'])
1379 set buftype=nowrite
1380 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001381
1382 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1383 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001384 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001385 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1386 endfor
1387
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001388 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001389endfunc
1390
Bram Moolenaar578fe942020-02-27 21:32:51 +01001391" Test for the 'rightleftcmd' option
1392func Test_rightleftcmd()
1393 CheckFeature rightleft
1394 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001395
1396 let g:l = []
1397 func AddPos()
1398 call add(g:l, screencol())
1399 return ''
1400 endfunc
1401 cmap <expr> <F2> AddPos()
1402
zeertzjqbb404f52022-07-23 06:25:29 +01001403 set rightleftcmd=
1404 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1405 \ "\<Right>\<F2>\<Esc>", 'xt')
1406 call assert_equal([2, 5, 3, 4], g:l)
1407
1408 let g:l = []
1409 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001410 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1411 \ "\<Left>\<F2>\<Esc>", 'xt')
1412 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1413
1414 cunmap <F2>
1415 unlet g:l
1416 set rightleftcmd&
1417 set rightleft&
1418endfunc
1419
zeertzjq28c162f2022-08-14 14:49:50 +01001420" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001421func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001422 " redraw to avoid matching previous messages
1423 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001424 set debug=beep
1425 exe "normal \<C-c>"
1426 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001427 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001428 " also check a line above, with a certain window width the colon is there
1429 call assert_match('Test_debug_option:$',
1430 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001431 set debug&
1432endfunc
1433
Bram Moolenaar004a6782020-04-11 17:09:31 +02001434" Test for the default CDPATH option
1435func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001436 let after =<< trim [CODE]
1437 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1438 call writefile(v:errors, 'Xtestout')
1439 qall
1440 [CODE]
1441 if has('unix')
1442 let $CDPATH='/path/to/dir1:/path/to/dir2'
1443 else
1444 let $CDPATH='/path/to/dir1;/path/to/dir2'
1445 endif
1446 if RunVim([], after, '')
1447 call assert_equal([], readfile('Xtestout'))
1448 call delete('Xtestout')
1449 endif
1450endfunc
1451
1452" Test for setting keycodes using set
1453func Test_opt_set_keycode()
1454 call assert_fails('set <t_k1=l', 'E474:')
1455 call assert_fails('set <Home=l', 'E474:')
1456 set <t_k9>=abcd
1457 call assert_equal('abcd', &t_k9)
1458 set <t_k9>&
1459 set <F9>=xyz
1460 call assert_equal('xyz', &t_k9)
1461 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001462
1463 " should we test all of them?
1464 set t_Ce=testCe
1465 set t_Cs=testCs
1466 set t_Us=testUs
1467 set t_ds=testds
1468 set t_Ds=testDs
1469 call assert_equal('testCe', &t_Ce)
1470 call assert_equal('testCs', &t_Cs)
1471 call assert_equal('testUs', &t_Us)
1472 call assert_equal('testds', &t_ds)
1473 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001474endfunc
1475
1476" Test for changing options in a sandbox
1477func Test_opt_sandbox()
1478 for opt in ['backupdir', 'cdpath', 'exrc']
1479 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001480 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001481 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001482 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001483endfunc
1484
1485" Test for setting an option with local value to global value
1486func Test_opt_local_to_global()
1487 setglobal equalprg=gprg
1488 setlocal equalprg=lprg
1489 call assert_equal('gprg', &g:equalprg)
1490 call assert_equal('lprg', &l:equalprg)
1491 call assert_equal('lprg', &equalprg)
1492 set equalprg<
1493 call assert_equal('', &l:equalprg)
1494 call assert_equal('gprg', &equalprg)
1495 setglobal equalprg=gnewprg
1496 setlocal equalprg=lnewprg
1497 setlocal equalprg<
1498 call assert_equal('gnewprg', &l:equalprg)
1499 call assert_equal('gnewprg', &equalprg)
1500 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001501
1502 " Test for setting the global/local value of a boolean option
1503 setglobal autoread
1504 setlocal noautoread
1505 call assert_false(&autoread)
1506 set autoread<
1507 call assert_true(&autoread)
1508 setglobal noautoread
1509 setlocal autoread
1510 setlocal autoread<
1511 call assert_false(&autoread)
1512 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001513endfunc
1514
Dominique Pelle042414f2021-07-12 21:43:19 +02001515func Test_set_in_sandbox()
1516 " Some boolean options cannot be set in sandbox, some can.
1517 call assert_fails('sandbox set modelineexpr', 'E48:')
1518 sandbox set number
1519 call assert_true(&number)
1520 set number&
1521
1522 " Some boolean options cannot be set in sandbox, some can.
1523 if has('python') || has('python3')
1524 call assert_fails('sandbox set pyxversion=3', 'E48:')
1525 endif
1526 sandbox set tabstop=4
1527 call assert_equal(4, &tabstop)
1528 set tabstop&
1529
1530 " Some string options cannot be set in sandbox, some can.
1531 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1532 sandbox set filetype=perl
1533 call assert_equal('perl', &filetype)
1534 set filetype&
1535endfunc
1536
Bram Moolenaar004a6782020-04-11 17:09:31 +02001537" Test for incrementing, decrementing and multiplying a number option value
1538func Test_opt_num_op()
1539 set shiftwidth=4
1540 set sw+=2
1541 call assert_equal(6, &sw)
1542 set sw-=2
1543 call assert_equal(4, &sw)
1544 set sw^=2
1545 call assert_equal(8, &sw)
1546 set shiftwidth&
1547endfunc
1548
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001549" Test for setting option values using v:false and v:true
1550func Test_opt_boolean()
1551 set number&
1552 set number
1553 call assert_equal(1, &nu)
1554 set nonu
1555 call assert_equal(0, &nu)
1556 let &nu = v:true
1557 call assert_equal(1, &nu)
1558 let &nu = v:false
1559 call assert_equal(0, &nu)
1560 set number&
1561endfunc
1562
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001563" Test for the 'window' option
1564func Test_window_opt()
1565 " Needs only one open widow
1566 %bw!
1567 call setline(1, range(1, 8))
1568 set window=5
1569 exe "normal \<C-F>"
1570 call assert_equal(4, line('w0'))
1571 exe "normal \<C-F>"
1572 call assert_equal(7, line('w0'))
1573 exe "normal \<C-F>"
1574 call assert_equal(8, line('w0'))
1575 exe "normal \<C-B>"
1576 call assert_equal(5, line('w0'))
1577 exe "normal \<C-B>"
1578 call assert_equal(2, line('w0'))
1579 exe "normal \<C-B>"
1580 call assert_equal(1, line('w0'))
1581 set window=1
1582 exe "normal gg\<C-F>"
1583 call assert_equal(2, line('w0'))
1584 exe "normal \<C-F>"
1585 call assert_equal(3, line('w0'))
1586 exe "normal \<C-B>"
1587 call assert_equal(2, line('w0'))
1588 exe "normal \<C-B>"
1589 call assert_equal(1, line('w0'))
1590 enew!
1591 set window&
1592endfunc
1593
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001594" Test for the 'winminheight' option
1595func Test_opt_winminheight()
1596 only!
1597 let &winheight = &lines + 4
1598 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1599 call assert_true(&winminheight <= &lines)
1600 set winminheight&
1601 set winheight&
1602endfunc
1603
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001604func Test_opt_winminheight_term()
1605 CheckRunVimInTerminal
1606
1607 " The tabline should be taken into account.
1608 let lines =<< trim END
1609 set wmh=0 stal=2
1610 below sp | wincmd _
1611 below sp | wincmd _
1612 below sp | wincmd _
1613 below sp
1614 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001615 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001616 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1617 call term_sendkeys(buf, ":set wmh=1\n")
1618 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1619
1620 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001621endfunc
1622
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001623func Test_opt_winminheight_term_tabs()
1624 CheckRunVimInTerminal
1625
1626 " The tabline should be taken into account.
1627 let lines =<< trim END
1628 set wmh=0 stal=2
1629 split
1630 split
1631 split
1632 split
1633 tabnew
1634 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001635 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001636 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1637 call term_sendkeys(buf, ":set wmh=1\n")
1638 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1639
1640 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001641endfunc
1642
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001643" Test for the 'winminwidth' option
1644func Test_opt_winminwidth()
1645 only!
1646 let &winwidth = &columns + 4
1647 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1648 call assert_true(&winminwidth <= &columns)
1649 set winminwidth&
1650 set winwidth&
1651endfunc
1652
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001653" Test for setting option value containing spaces with isfname+=32
1654func Test_isfname_with_options()
1655 set isfname+=32
1656 setlocal keywordprg=:term\ help.exe
1657 call assert_equal(':term help.exe', &keywordprg)
1658 set isfname&
1659 setlocal keywordprg&
1660endfunc
1661
Bram Moolenaar74667062020-12-28 15:41:41 +01001662" Test that resetting laststatus does change scroll option
1663func Test_opt_reset_scroll()
1664 CheckRunVimInTerminal
1665 let vimrc =<< trim [CODE]
1666 set scroll=2
1667 set laststatus=2
1668 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001669 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001670 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1671 call term_sendkeys(buf, ":verbose set scroll?\n")
1672 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1673 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001674
1675 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001676 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001677endfunc
1678
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001679" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1680func Test_VIM_POSIX()
1681 let saved_VIM_POSIX = getenv("VIM_POSIX")
1682
1683 call setenv('VIM_POSIX', "1")
1684 let after =<< trim [CODE]
1685 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1686 qall
1687 [CODE]
1688 if RunVim([], after, '')
1689 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1690 \ 'AS'], readfile('X_VIM_POSIX'))
1691 endif
1692
1693 call setenv('VIM_POSIX', v:null)
1694 let after =<< trim [CODE]
1695 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1696 qall
1697 [CODE]
1698 if RunVim([], after, '')
1699 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1700 \ 'S'], readfile('X_VIM_POSIX'))
1701 endif
1702
1703 call delete('X_VIM_POSIX')
1704 call setenv('VIM_POSIX', saved_VIM_POSIX)
1705endfunc
1706
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001707" Test for setting an option to a Vi or Vim default
1708func Test_opt_default()
1709 set formatoptions&vi
1710 call assert_equal('vt', &formatoptions)
1711 set formatoptions&vim
1712 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001713
1714 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1715 set fencs=latin1
1716 set fencs&
1717 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1718 set fencs=latin1
1719 set all&
1720 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001721endfunc
1722
1723" Test for the 'cmdheight' option
1724func Test_cmdheight()
1725 %bw!
1726 let ht = &lines
1727 set cmdheight=9999
1728 call assert_equal(1, winheight(0))
1729 call assert_equal(ht - 1, &cmdheight)
1730 set cmdheight&
1731endfunc
1732
Dominique Pelle923dce22021-11-21 11:36:04 +00001733" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001734func Test_opt_control_char()
1735 set wildchar=^v
1736 call assert_equal("\<C-V>", nr2char(&wildchar))
1737 set wildcharm=^r
1738 call assert_equal("\<C-R>", nr2char(&wildcharm))
1739 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1740 set wildchar& wildcharm&
1741endfunc
1742
1743" Test for the 'errorbells' option
1744func Test_opt_errorbells()
1745 set errorbells
1746 call assert_beeps('s/a1b2/x1y2/')
1747 set noerrorbells
1748endfunc
1749
Dominique Pelle042414f2021-07-12 21:43:19 +02001750func Test_opt_scrolljump()
1751 help
1752 resize 10
1753
1754 " Test with positive 'scrolljump'.
1755 set scrolljump=2
1756 norm! Lj
1757 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1758 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1759 \ winsaveview())
1760
1761 " Test with negative 'scrolljump' (percentage of window height).
1762 set scrolljump=-40
1763 norm! ggLj
1764 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1765 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1766 \ winsaveview())
1767
1768 set scrolljump&
1769 bw
1770endfunc
1771
Bakudankun29f3a452021-12-11 12:28:08 +00001772" Test for the 'cdhome' option
1773func Test_opt_cdhome()
1774 if has('unix') || has('vms')
1775 throw 'Skipped: only works on non-Unix'
1776 endif
1777
1778 set cdhome&
1779 call assert_equal(0, &cdhome)
1780 set cdhome
1781
1782 " This paragraph is copied from Test_cd_no_arg().
1783 let path = getcwd()
1784 cd
1785 call assert_equal($HOME, getcwd())
1786 call assert_notequal(path, getcwd())
1787 exe 'cd ' .. fnameescape(path)
1788 call assert_equal(path, getcwd())
1789
1790 set cdhome&
1791endfunc
1792
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001793func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001794 CheckOption termguicolors
1795
1796 " Test default option completion
1797 set wildoptions=
1798 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1799 call assert_equal('"set termguicolors', @:)
1800
1801 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1802 call assert_equal('"set notermguicolors', @:)
1803
1804 " Test fuzzy option completion
1805 set wildoptions=fuzzy
1806 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1807 call assert_equal('"set termguicolors termencoding', @:)
1808
1809 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1810 call assert_equal('"set notermguicolors', @:)
1811
1812 set wildoptions=
1813endfunc
1814
Sean Dewar39c46b42022-05-12 17:44:29 +01001815func Test_switchbuf_reset()
1816 set switchbuf=useopen
1817 sblast
1818 call assert_equal(1, winnr('$'))
1819 set all&
1820 call assert_equal('', &switchbuf)
1821 sblast
1822 call assert_equal(2, winnr('$'))
1823 only!
1824endfunc
1825
zeertzjqfcba86c2022-09-22 13:57:32 +01001826" :set empty string for global 'keywordprg' falls back to ":help"
1827func Test_keywordprg_empty()
1828 let k = &keywordprg
1829 set keywordprg=man
1830 call assert_equal('man', &keywordprg)
1831 set keywordprg=
1832 call assert_equal(':help', &keywordprg)
1833 set keywordprg=man
1834 call assert_equal('man', &keywordprg)
1835 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1836 let &keywordprg = k
1837endfunc
1838
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001839" check that the very first buffer created does not have 'endoffile' set
1840func Test_endoffile_default()
1841 let after =<< trim [CODE]
1842 call writefile([execute('set eof?')], 'Xtestout')
1843 qall!
1844 [CODE]
1845 if RunVim([], after, '')
1846 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1847 endif
1848 call delete('Xtestout')
1849endfunc
1850
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001851" Test for setting the 'lines' and 'columns' options to a minimum value
1852func Test_set_min_lines_columns()
1853 let save_lines = &lines
1854 let save_columns = &columns
1855
1856 let after =<< trim END
1857 set nomore
1858 let msg = []
1859 let v:errmsg = ''
1860 silent! let &columns=0
1861 call add(msg, v:errmsg)
1862 silent! set columns=0
1863 call add(msg, v:errmsg)
1864 silent! call setbufvar('', '&columns', 0)
1865 call add(msg, v:errmsg)
1866 "call writefile(msg, 'XResultsetminlines')
1867 silent! let &lines=0
1868 call add(msg, v:errmsg)
1869 silent! set lines=0
1870 call add(msg, v:errmsg)
1871 silent! call setbufvar('', '&lines', 0)
1872 call add(msg, v:errmsg)
1873 call writefile(msg, 'XResultsetminlines')
1874 qall!
1875 END
1876 if RunVim([], after, '')
1877 call assert_equal(['E594: Need at least 12 columns',
1878 \ 'E594: Need at least 12 columns: columns=0',
1879 \ 'E594: Need at least 12 columns',
1880 \ 'E593: Need at least 2 lines',
1881 \ 'E593: Need at least 2 lines: lines=0',
1882 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1883 endif
1884
1885 call delete('XResultsetminlines')
1886 let &lines = save_lines
1887 let &columns = save_columns
1888endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001889
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001890" Test for reverting a string option value if the new value is invalid.
1891func Test_string_option_revert_on_failure()
1892 new
1893 let optlist = [
1894 \ ['ambiwidth', 'double', 'a123'],
1895 \ ['background', 'dark', 'a123'],
1896 \ ['backspace', 'eol', 'a123'],
1897 \ ['backupcopy', 'no', 'a123'],
1898 \ ['belloff', 'showmatch', 'a123'],
1899 \ ['breakindentopt', 'min:10', 'list'],
1900 \ ['bufhidden', 'wipe', 'a123'],
1901 \ ['buftype', 'nowrite', 'a123'],
1902 \ ['casemap', 'keepascii', 'a123'],
1903 \ ['cedit', "\<C-Y>", 'z'],
1904 \ ['colorcolumn', '10', 'z'],
1905 \ ['commentstring', '#%s', 'a123'],
1906 \ ['complete', '.,t', 'a'],
1907 \ ['completefunc', 'MyCmplFunc', '1a-'],
1908 \ ['completeopt', 'popup', 'a123'],
1909 \ ['completepopup', 'width:20', 'border'],
1910 \ ['concealcursor', 'v', 'xyz'],
1911 \ ['cpoptions', 'HJ', '~'],
1912 \ ['cryptmethod', 'zip', 'a123'],
1913 \ ['cursorlineopt', 'screenline', 'a123'],
1914 \ ['debug', 'throw', 'a123'],
1915 \ ['diffopt', 'iwhite', 'a123'],
1916 \ ['display', 'uhex', 'a123'],
1917 \ ['eadirection', 'hor', 'a123'],
1918 \ ['encoding', 'utf-8', 'a123'],
1919 \ ['eventignore', 'TextYankPost', 'a123'],
1920 \ ['fileencoding', 'utf-8', 'a123,'],
1921 \ ['fileformat', 'mac', 'a123'],
1922 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001923 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001924 \ ['fillchars', 'diff:~', 'a123'],
1925 \ ['foldclose', 'all', 'a123'],
1926 \ ['foldmarker', '[[[,]]]', '[[['],
1927 \ ['foldmethod', 'marker', 'a123'],
1928 \ ['foldopen', 'percent', 'a123'],
1929 \ ['formatoptions', 'an', '*'],
1930 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1931 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001932 \ ['highlight', '!:CursorColumn', '8:'],
1933 \ ['keymodel', 'stopsel', 'a123'],
1934 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1935 \ ['lispoptions', 'expr:1', 'a123'],
1936 \ ['listchars', 'tab:->', 'tab:'],
1937 \ ['matchpairs', '<:>', '<:'],
1938 \ ['mkspellmem', '100000,1000,100', '100000'],
1939 \ ['mouse', 'nvi', 'z'],
1940 \ ['mousemodel', 'extend', 'a123'],
1941 \ ['nrformats', 'alpha', 'a123'],
1942 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1943 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1944 \ ['previewpopup', 'width:20', 'a123'],
1945 \ ['printoptions', 'paper:A4', 'a123:'],
1946 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1947 \ ['rulerformat', '%l', '%['],
1948 \ ['scrollopt', 'hor,jump', 'a123'],
1949 \ ['selection', 'exclusive', 'a123'],
1950 \ ['selectmode', 'cmd', 'a123'],
1951 \ ['sessionoptions', 'options', 'a123'],
1952 \ ['shortmess', 'w', '2'],
1953 \ ['showbreak', '>>', "\x01"],
1954 \ ['showcmdloc', 'statusline', 'a123'],
1955 \ ['signcolumn', 'no', 'a123'],
1956 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1957 \ ['spellfile', 'MySpell.en.add', "\x01"],
1958 \ ['spelllang', 'en', "#"],
1959 \ ['spelloptions', 'camel', 'a123'],
1960 \ ['spellsuggest', 'double', 'a123'],
1961 \ ['splitkeep', 'topline', 'a123'],
1962 \ ['statusline', '%f', '%['],
1963 \ ['swapsync', 'sync', 'a123'],
1964 \ ['switchbuf', 'usetab', 'a123'],
1965 \ ['syntax', 'abc', 'a^b'],
1966 \ ['tabline', '%f', '%['],
1967 \ ['tagcase', 'ignore', 'a123'],
1968 \ ['tagfunc', 'MyTagFunc', '1a-'],
1969 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1970 \ ['viewoptions', 'options', 'a123'],
1971 \ ['virtualedit', 'onemore', 'a123'],
1972 \ ['whichwrap', '<,>', '{,}'],
1973 \ ['wildmode', 'list', 'a123'],
1974 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001975 \ ]
1976 if has('gui')
1977 call add(optlist, ['browsedir', 'buffer', 'a123'])
1978 endif
1979 if has('clipboard_working')
1980 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1981 endif
1982 if has('win32')
1983 call add(optlist, ['completeslash', 'slash', 'a123'])
1984 endif
1985 if has('cscope')
1986 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1987 endif
1988 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001989 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1990 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1991 endif
1992 if has('keymap')
1993 call add(optlist, ['keymap', 'greek', '[]'])
1994 endif
1995 if has('mouseshape')
1996 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1997 endif
1998 if has('win32') && has('gui')
1999 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
2000 endif
2001 if has('rightleft')
2002 call add(optlist, ['rightleftcmd', 'search', 'a123'])
2003 endif
2004 if has('terminal')
2005 call add(optlist, ['termwinkey', '<C-L>', '<C'])
2006 call add(optlist, ['termwinsize', '24x80', '100'])
2007 endif
2008 if has('win32') && has('terminal')
2009 call add(optlist, ['termwintype', 'winpty', 'a123'])
2010 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002011 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002012 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002013 endif
2014 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002015 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2016 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002017 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002018 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2019 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002020 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002021 call add(optlist, ['varsofttabstop', '12', 'a123'])
2022 call add(optlist, ['vartabstop', '4,20', '4,'])
2023 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002024 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002025 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002026 endif
2027 for opt in optlist
2028 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002029 try
2030 exe $"let &{opt[0]} = '{opt[1]}'"
2031 catch
2032 call assert_report($"Caught {v:exception} with {opt->string()}")
2033 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002034 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2035 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2036 exe $"let &{opt[0]} = save_opt"
2037 endfor
2038 bw!
2039endfunc
2040
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002041func Test_set_option_window_global_local()
2042 new Xbuffer1
2043 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2044 setlocal scrolloff=2
2045 setglobal scrolloff=3
2046 setl modified
2047 " A new buffer has its own window-local options
2048 hide enew
2049 call assert_equal(-1, &l:scrolloff)
2050 call assert_equal(3, &g:scrolloff)
2051 " A new window opened with its own buffer-local options
2052 new
2053 call assert_equal(-1, &l:scrolloff)
2054 call assert_equal(3, &g:scrolloff)
2055 " Re-open Xbuffer1 and it should use
2056 " the previous set window-local options
2057 b Xbuffer1
2058 call assert_equal(2, &l:scrolloff)
2059 call assert_equal(3, &g:scrolloff)
2060 bw!
2061 bw!
2062 let &g:scrolloff = _gso
2063endfunc
2064
2065func GetGlobalLocalWindowOptions()
2066 new
2067 sil! r $VIMRUNTIME/doc/options.txt
2068 " Filter for global or local to window
2069 v/^'.*'.*\n.*global or local to window |global-local/d
2070 " get option value and type
2071 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2072 sil %s/empty/""/g
2073 " split the result
2074 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2075 bw!
2076 return result
2077endfunc
2078
2079func Test_set_option_window_global_local_all()
2080 new Xbuffer2
2081
2082 let optionlist = GetGlobalLocalWindowOptions()
2083 for [opt, type, default] in optionlist
2084 let _old = eval('&g:' .. opt)
2085 if type == 'string'
2086 if opt == 'fillchars'
2087 exe 'setl ' .. opt .. '=vert:+'
2088 exe 'setg ' .. opt .. '=vert:+,fold:+'
2089 elseif opt == 'listchars'
2090 exe 'setl ' .. opt .. '=tab:>>'
2091 exe 'setg ' .. opt .. '=tab:++'
2092 elseif opt == 'virtualedit'
2093 exe 'setl ' .. opt .. '=all'
2094 exe 'setg ' .. opt .. '=block'
2095 else
2096 exe 'setl ' .. opt .. '=Local'
2097 exe 'setg ' .. opt .. '=Global'
2098 endif
2099 elseif type == 'number'
2100 exe 'setl ' .. opt .. '=5'
2101 exe 'setg ' .. opt .. '=10'
2102 endif
2103 setl modified
2104 hide enew
2105 if type == 'string'
2106 call assert_equal('', eval('&l:' .. opt))
2107 if opt == 'fillchars'
2108 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2109 elseif opt == 'listchars'
2110 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2111 elseif opt == 'virtualedit'
2112 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2113 else
2114 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2115 endif
2116 elseif type == 'number'
2117 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2118 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2119 endif
2120 bw!
2121 exe 'let &g:' .. opt .. '=' .. default
2122 endfor
2123 bw!
2124endfunc
2125
Christian Brabandt757593c2023-08-22 21:44:10 +02002126func Test_paste_depending_options()
2127 " setting the paste option, resets all dependent options
2128 " and will be reported correctly using :verbose set <option>?
2129 let lines =<< trim [CODE]
2130 " set paste test
2131 set autoindent
2132 set expandtab
2133 " disabled, because depends on compiled feature set
2134 " set hkmap
2135 " set revins
2136 " set varsofttabstop=8,32,8
2137 set ruler
2138 set showmatch
2139 set smarttab
2140 set softtabstop=4
2141 set textwidth=80
2142 set wrapmargin=10
2143
2144 source Xvimrc_paste2
2145
2146 redir > Xoutput_paste
2147 verbose set expandtab?
2148 verbose setg expandtab?
2149 verbose setl expandtab?
2150 redir END
2151
2152 qall!
2153 [CODE]
2154
2155 call writefile(lines, 'Xvimrc_paste', 'D')
2156 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2157 if !RunVim([], lines, '--clean')
2158 return
2159 endif
2160
2161 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2162 call assert_equal('noexpandtab', result[0])
2163 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2164 call assert_equal('noexpandtab', result[2])
2165 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2166 call assert_equal('noexpandtab', result[4])
2167 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2168
2169 call delete('Xoutput_paste')
2170endfunc
2171
2172func Test_binary_depending_options()
2173 " setting the paste option, resets all dependent options
2174 " and will be reported correctly using :verbose set <option>?
2175 let lines =<< trim [CODE]
2176 " set binary test
2177 set expandtab
2178
2179 source Xvimrc_bin2
2180
2181 redir > Xoutput_bin
2182 verbose set expandtab?
2183 verbose setg expandtab?
2184 verbose setl expandtab?
2185 redir END
2186
2187 qall!
2188 [CODE]
2189
2190 call writefile(lines, 'Xvimrc_bin', 'D')
2191 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2192 if !RunVim([], lines, '--clean')
2193 return
2194 endif
2195
2196 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2197 call assert_equal('noexpandtab', result[0])
2198 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2199 call assert_equal('noexpandtab', result[2])
2200 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2201 call assert_equal('noexpandtab', result[4])
2202 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2203
2204 call delete('Xoutput_bin')
2205endfunc
2206
Gregory Anders3695d0e2023-09-29 20:17:20 +02002207func Test_set_keyprotocol()
2208 CheckNotGui
2209
2210 let term = &term
2211 set term=ansi
2212 call assert_equal('', &t_TI)
2213
2214 " Setting 'keyprotocol' should affect terminal codes without needing to
2215 " reset 'term'
2216 set keyprotocol+=ansi:kitty
2217 call assert_equal("\<Esc>[=1;1u", &t_TI)
2218 let &term = term
2219endfunc
2220
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002221func Test_set_wrap()
2222 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2223 " cursor position.
2224 set wrap smoothscroll scrolloff=5
2225
2226 call setline(1, ['', 'aaaa'->repeat(500)])
2227 20 split
2228 20 vsplit
2229 norm 2G$
2230 redraw
2231 set nowrap
2232 call assert_equal(2, winline())
2233
2234 set wrap& smoothscroll& scrolloff&
2235endfunc
2236
zeertzjqcd3a13e2024-02-24 16:51:32 +01002237func Test_delcombine()
2238 new
2239 set backspace=indent,eol,start
2240
2241 set delcombine
2242 call setline(1, 'β̳̈:β̳̈')
2243 normal! 0x
2244 call assert_equal('β̈:β̳̈', getline(1))
2245 exe "normal! A\<BS>"
2246 call assert_equal('β̈:β̈', getline(1))
2247 normal! 0x
2248 call assert_equal('β:β̈', getline(1))
2249 exe "normal! A\<BS>"
2250 call assert_equal('β:β', getline(1))
2251 normal! 0x
2252 call assert_equal(':β', getline(1))
2253 exe "normal! A\<BS>"
2254 call assert_equal(':', getline(1))
2255
2256 set nodelcombine
2257 call setline(1, 'β̳̈:β̳̈')
2258 normal! 0x
2259 call assert_equal(':β̳̈', getline(1))
2260 exe "normal! A\<BS>"
2261 call assert_equal(':', getline(1))
2262
2263 set backspace& delcombine&
2264 bwipe!
2265endfunc
2266
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002267" vim: shiftwidth=2 sts=2 expandtab