blob: 8c336abf7d53a57cbec094ea6ff8dfff3d43bf5f [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(), @:)
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100438endfunc
439
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200440" Test handling of expanding individual string option values
441func Test_set_completion_string_values()
442 "
443 " Test basic enum string options that have well-defined enum names
444 "
445
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200446 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
447 call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
448 call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200449
450 " Test that if a value is set, it will populate the results, but only if
451 " typed value is empty.
452 set display=uhex,lastline
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200453 call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
454 call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200455 " If the set value is part of the enum list, it will show as the first
456 " result with no duplicate.
457 set display=uhex
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200458 call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200459 " If empty value, will just show the normal list without an empty item
460 set display=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200461 call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200462 " Test escaping of the values
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200463 call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200464
465 " Test comma-separated lists will expand after a comma.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200466 call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200467 " Also test the positioning of the expansion is correct
468 call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
469 call assert_equal('"set display=truncate,lastline', @:)
470 set display&
471
472 " Test single-value options will not expand after a comma
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200473 call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200474
475 " Test the other simple options to make sure they have basic auto-complete,
476 " but don't exhaustively validate their results.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200477 call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200478 call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200479 call assert_equal('indent', getcompletion('set backspace=', 'cmdline')[0])
480 call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
481 call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
482 call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200483 if exists('+browsedir')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200484 call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200485 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200486 call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
487 call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
488 call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200489 if exists('+clipboard')
490 call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
491 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200492 call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
493 call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200494 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200495 call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200496 endif
497 if exists('+cryptmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200498 call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200499 endif
500 if exists('+cursorlineopt')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200501 call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200502 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200503 call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
504 call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
505 call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200506 if exists('+foldclose')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200507 call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200508 endif
509 if exists('+foldmethod')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200510 call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200511 endif
512 if exists('+foldopen')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200513 call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200514 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200515 call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
516 call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
517 call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200518 call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200519 call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200520 if exists('+rightleftcmd')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200521 call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200522 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200523 call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
524 call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
525 call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200526 if exists('+ssop')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200527 call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200528 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200529 call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200530 if exists('+signcolumn')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200531 call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200532 endif
533 if exists('+spelloptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200534 call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200535 endif
536 if exists('+spellsuggest')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200537 call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200538 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200539 call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
540 call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
541 call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
542 call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200543 if exists('+termwintype')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200544 call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200545 endif
546 if exists('+toolbar')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200547 call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200548 endif
549 if exists('+tbis')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200550 call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200551 endif
552 if exists('+ttymouse')
553 set ttymouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200554 call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200555 set ttymouse&
556 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200557 call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
558 call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
559 call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
560 call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200561 if exists('+winaltkeys')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200562 call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200563 endif
564
565 " Other string options that queries the system rather than fixed enum names
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200566 call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
567 call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
568 call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
569 call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200570
zeertzjq1f025b02023-09-30 12:43:07 +0200571 call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
572 call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
573 call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
574 call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
575 call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
576 call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200577
578 "
579 " Unique string options below
580 "
581
582 " keyprotocol: only auto-complete when after ':' with known protocol types
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200583 call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200584 call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
585 call assert_equal('"set keyprotocol+=someterm:mok2', @:)
586 set keyprotocol&
587
588 " previewpopup / completepopup
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200589 call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
590 call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200591 call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
592 call assert_equal('"set previewpopup+=border:on', @:)
593 call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
594 call assert_equal('"set completepopup=height:10,align:item', @:)
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200595 call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200596 set previewpopup& completepopup&
597
598 " diffopt: special handling of algorithm:<alg_list>
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200599 call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
600 call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
601 call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200602
603 " highlight: special parsing, including auto-completing highlight groups
604 " after ':'
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200605 call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
606 call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
607 call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
608 call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
609 call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200610 " If all the display modes are used up we should be suggesting nothing. Make
611 " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
612 " and make sure nothing is suggested from that.
613 let hl_display_modes = join(
614 \ filter(map(getcompletion('set hl+=8', 'cmdline'),
615 \ {idx, val -> val[1]}),
616 \ {idx, val -> val != ':'}),
617 \ '')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200618 call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
Yee Cheng Chin209ec902023-10-17 10:56:25 +0200619 " Test completion in middle of the line
620 call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
621 call assert_equal("\"set hl=8bi i", @:)
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200622
623 "
624 " Test flag lists
625 "
626
627 " Test set=. Show the original value if nothing is typed after '='.
628 " Otherwise, the list should avoid showing what's already typed.
629 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200630 call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200631 set mouse=nvi
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200632 call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
633 call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200634
635 " Test set+=. Never show original value, and it also tries to avoid listing
636 " flags that's already in the option value.
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200637 call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
638 call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
639 call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200640
641 " Test that the position of the expansion is correct (even if there are
642 " additional values after the current cursor)
643 call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
644 call assert_equal('"set mouse=han', @:)
645 set mouse&
646
647 " Test that other flag list options have auto-complete, but don't
648 " exhaustively validate their results.
649 if exists('+concealcursor')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200650 call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200651 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200652 call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
653 call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200654 if exists('+guioptions')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200655 call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200656 endif
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200657 call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
658 call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200659
660 "
661 "Test set-=
662 "
663
664 " Normal single-value option just shows the existing value
665 set ambiwidth=double
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200666 call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200667 set ambiwidth&
668
669 " Works on numbers and term options as well
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200670 call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200671 set t_Ce=testCe
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200672 call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200673 set t_Ce&
674
675 " Comma-separated lists should present each option
676 set diffopt=context:123,,,,,iblank,iwhiteall
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200677 call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
678 call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
679 call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200680 " Don't present more than one option as it doesn't make sense in set-=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200681 call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200682 " Test empty option
683 set diffopt=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200684 call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200685 set diffopt&
686
687 " Test escaping output
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200688 call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200689
690 " Test files with commas in name are being parsed and escaped properly
691 set path=has\\\ space,file\\,with\\,comma,normal_file
692 if exists('+completeslash')
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200693 call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200694 else
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200695 call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200696 endif
697 set path&
698
699 " Flag list should present orig value, then individual flags
700 set mouse=v
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200701 call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200702 set mouse=avn
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200703 call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200704 " Don't auto-complete when we have at least one flags already
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200705 call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200706 " Test empty option
707 set mouse=
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200708 call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200709 set mouse&
710
711 " 'whichwrap' is an odd case where it's both flag list and comma-separated
712 set ww=b,h
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200713 call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
Yee Cheng Chin900894b2023-09-29 20:42:32 +0200714 set ww&
715endfunc
716
zeertzjq4c7cb372023-06-14 16:39:54 +0100717func Test_set_option_errors()
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100718 call assert_fails('set scroll=-1', 'E49:')
719 call assert_fails('set backupcopy=', 'E474:')
720 call assert_fails('set regexpengine=3', 'E474:')
721 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200722 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100723 call assert_fails('set colorcolumn=-a', 'E474:')
724 call assert_fails('set colorcolumn=a', 'E474:')
725 call assert_fails('set colorcolumn=1,', 'E474:')
726 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100727 call assert_fails('set cmdheight=-1', 'E487:')
728 call assert_fails('set cmdwinheight=-1', 'E487:')
729 if has('conceal')
730 call assert_fails('set conceallevel=-1', 'E487:')
731 call assert_fails('set conceallevel=4', 'E474:')
732 endif
733 call assert_fails('set helpheight=-1', 'E487:')
734 call assert_fails('set history=-1', 'E487:')
735 call assert_fails('set report=-1', 'E487:')
736 call assert_fails('set shiftwidth=-1', 'E487:')
737 call assert_fails('set sidescroll=-1', 'E487:')
738 call assert_fails('set tabstop=-1', 'E487:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000739 call assert_fails('set tabstop=10000', 'E474:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000740 call assert_fails('let &tabstop = 10000', 'E474:')
Bram Moolenaar652dee42022-01-28 20:47:49 +0000741 call assert_fails('set tabstop=5500000000', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100742 call assert_fails('set textwidth=-1', 'E487:')
743 call assert_fails('set timeoutlen=-1', 'E487:')
744 call assert_fails('set updatecount=-1', 'E487:')
745 call assert_fails('set updatetime=-1', 'E487:')
746 call assert_fails('set winheight=-1', 'E487:')
747 call assert_fails('set tabstop!', 'E488:')
748 call assert_fails('set xxx', 'E518:')
749 call assert_fails('set beautify?', 'E519:')
750 call assert_fails('set undolevels=x', 'E521:')
751 call assert_fails('set tabstop=', 'E521:')
752 call assert_fails('set comments=-', 'E524:')
753 call assert_fails('set comments=a', 'E525:')
754 call assert_fails('set foldmarker=x', 'E536:')
755 call assert_fails('set commentstring=x', 'E537:')
Bram Moolenaar8ccbbeb2022-03-02 19:49:38 +0000756 call assert_fails('let &commentstring = "x"', 'E537:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100757 call assert_fails('set complete=x', 'E539:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100758 call assert_fails('set rulerformat=%-', 'E539:')
759 call assert_fails('set rulerformat=%(', 'E542:')
760 call assert_fails('set rulerformat=%15(%%', 'E542:')
761 call assert_fails('set statusline=%$', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100762 call assert_fails('set statusline=%{', 'E540:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100763 call assert_fails('set statusline=%{%', 'E540:')
764 call assert_fails('set statusline=%{%}', 'E539:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100765 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100766 call assert_fails('set statusline=%)', 'E542:')
zeertzjq5dc294a2022-04-15 13:17:57 +0100767 call assert_fails('set tabline=%$', 'E539:')
768 call assert_fails('set tabline=%{', 'E540:')
769 call assert_fails('set tabline=%{%', 'E540:')
770 call assert_fails('set tabline=%{%}', 'E539:')
771 call assert_fails('set tabline=%(', 'E542:')
772 call assert_fails('set tabline=%)', 'E542:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100773
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100774 if has('cursorshape')
775 " This invalid value for 'guicursor' used to cause Vim to crash.
776 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
777 call assert_fails('set guicursor=i-ci', 'E545:')
778 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100779 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100780 call assert_fails('set guicursor=r-cr:horx', 'E548:')
781 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
782 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100783 if has('mouseshape')
784 call assert_fails('se mouseshape=i-r:x', 'E547:')
785 endif
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +0000786
787 " Test for 'backupext' and 'patchmode' set to the same value
788 set backupext=.bak
789 set patchmode=.patch
790 call assert_fails('set patchmode=.bak', 'E589:')
791 call assert_equal('.patch', &patchmode)
792 call assert_fails('set backupext=.patch', 'E589:')
793 call assert_equal('.bak', &backupext)
794 set backupext& patchmode&
795
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100796 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200797 set winminheight& winheight&
798 set winheight=10 winminheight=10
799 call assert_fails('set winheight=9', 'E591:')
800 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100801 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200802 set winminwidth& winwidth&
803 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
804 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100805 call assert_fails("set showbreak=\x01", 'E595:')
806 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200807 call assert_fails('set tabstop??', 'E488:')
808 call assert_fails('set wrapscan!!', 'E488:')
809 call assert_fails('set tabstop&&', 'E488:')
810 call assert_fails('set wrapscan<<', 'E488:')
811 call assert_fails('set wrapscan=1', 'E474:')
812 call assert_fails('set autoindent@', 'E488:')
813 call assert_fails('set wildchar=<abc>', 'E474:')
814 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200815 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100816 if has('python') || has('python3')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200817 call assert_fails('set pyxversion=6', 'E474:')
818 endif
zeertzjq4c7cb372023-06-14 16:39:54 +0100819 call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
Bram Moolenaar531be472020-09-23 22:38:05 +0200820 call assert_fails('set spellcapcheck=%\\(', 'E54:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100821 call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
822 call assert_fails('set foldmarker={{{,', 'E474:')
823 call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
zeertzjq8ca29b62022-08-09 12:53:14 +0100824 setlocal listchars=trail
825 call assert_fails('set ambiwidth=double', 'E834:')
826 setlocal listchars=trail:-
827 setglobal listchars=trail
828 call assert_fails('set ambiwidth=double', 'E834:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100829 set listchars&
zeertzjq8ca29b62022-08-09 12:53:14 +0100830 setlocal fillchars=stl
831 call assert_fails('set ambiwidth=double', 'E835:')
832 setlocal fillchars=stl:-
833 setglobal fillchars=stl
834 call assert_fails('set ambiwidth=double', 'E835:')
Bram Moolenaar85773bf2021-01-17 13:48:03 +0100835 set fillchars&
836 call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
837 set nomodifiable
838 call assert_fails('set fileencoding=latin1', 'E21:')
839 set modifiable&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +0200840 call assert_fails('set t_#-&', 'E522:')
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +0000841 call assert_fails('let &formatoptions = "?"', 'E539:')
842 call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
zeertzjq4c7cb372023-06-14 16:39:54 +0100843 call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
844 call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
845 call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
846 call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
847 call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
848 call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
Bram Moolenaar7554da42016-11-25 22:04:13 +0100849endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100850
Bram Moolenaar1349bd72022-02-22 12:34:28 +0000851func Test_set_encoding()
852 let save_encoding = &encoding
853
854 set enc=iso8859-1
855 call assert_equal('latin1', &enc)
856 set enc=iso8859_1
857 call assert_equal('latin1', &enc)
858 set enc=iso-8859-1
859 call assert_equal('latin1', &enc)
860 set enc=iso_8859_1
861 call assert_equal('latin1', &enc)
862 set enc=iso88591
863 call assert_equal('latin1', &enc)
864 set enc=iso8859
865 call assert_equal('latin1', &enc)
866 set enc=iso-8859
867 call assert_equal('latin1', &enc)
868 set enc=iso_8859
869 call assert_equal('latin1', &enc)
870 call assert_fails('set enc=iso8858', 'E474:')
871 call assert_equal('latin1', &enc)
872
873 let &encoding = save_encoding
874endfunc
875
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200876func CheckWasSet(name)
877 let verb_cm = execute('verbose set ' .. a:name .. '?')
878 call assert_match('Last set from.*test_options.vim', verb_cm)
879endfunc
880func CheckWasNotSet(name)
881 let verb_cm = execute('verbose set ' .. a:name .. '?')
882 call assert_notmatch('Last set from', verb_cm)
883endfunc
884
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200885" Must be executed before other tests that set 'term'.
886func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200887 CheckNotGui
888
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200889 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200890
891 let term_save = &term
892 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200893 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200894 let &term = term_save
895endfunc
896
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200897func Test_copy_context()
898 setlocal list
899 call CheckWasSet('list')
900 split
901 call CheckWasSet('list')
902 quit
903 setlocal nolist
904
905 set ai
906 call CheckWasSet('ai')
907 set filetype=perl
908 call CheckWasSet('filetype')
909 set fo=tcroq
910 call CheckWasSet('fo')
911
912 split Xsomebuf
913 call CheckWasSet('ai')
914 call CheckWasNotSet('filetype')
915 call CheckWasSet('fo')
916endfunc
917
Bram Moolenaar67391142017-02-19 21:07:04 +0100918func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200919 CheckUnix
920 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200921
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200922 " Setting 'ttytype' used to cause a double-free when exiting vim and
923 " when vim is compiled with -DEXITFREE.
924 set ttytype=ansi
925 call assert_equal('ansi', &ttytype)
926 call assert_equal(&ttytype, &term)
927 set ttytype=xterm
928 call assert_equal('xterm', &ttytype)
929 call assert_equal(&ttytype, &term)
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200930 try
931 set ttytype=
932 call assert_report('set ttytype= did not fail')
Bram Moolenaar5daa9112021-02-01 18:39:47 +0100933 catch /E529/
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200934 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200935
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200936 " Some systems accept any terminal name and return dumb settings,
937 " check for failure of finding the entry and for missing 'cm' entry.
938 try
939 set ttytype=xxx
940 call assert_report('set ttytype=xxx did not fail')
941 catch /E522\|E437/
942 endtry
943
944 set ttytype&
945 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200946
947 if has('gui') && !has('gui_running')
948 call assert_fails('set term=gui', 'E531:')
949 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100950endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100951
952func Test_set_all()
953 set tw=75
954 set iskeyword=a-z,A-Z
955 set nosplitbelow
956 let out = execute('set all')
957 call assert_match('textwidth=75', out)
958 call assert_match('iskeyword=a-z,A-Z', out)
959 call assert_match('nosplitbelow', out)
960 set tw& iskeyword& splitbelow&
961endfunc
962
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100963func Test_set_one_column()
964 let out_mult = execute('set all')->split("\n")
965 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100966 call assert_true(len(out_mult) < len(out_one))
zeertzjqf48558e2023-12-08 21:34:31 +0100967 call assert_equal(out_one[0], '--- Options ---')
968 let options = out_one[1:]->mapnew({_, line -> line[2:]})
969 call assert_equal(sort(copy(options)), options)
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100970endfunc
971
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100972func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200973 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100974 if filereadable('opt_test.vim')
975 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100976 else
977 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100978 endif
979endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200980
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100981func Test_renderoptions()
982 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
983 " Doesn't hurt to do this on a non-Windows system.
984 if windowsversion() !~ '^[345]\.'
985 set renderoptions=type:directx
986 set rop=type:directx
987 endif
988endfunc
989
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200990func ResetIndentexpr()
991 set indentexpr=
992endfunc
993
994func Test_set_indentexpr()
995 " this was causing usage of freed memory
996 set indentexpr=ResetIndentexpr()
997 new
998 call feedkeys("i\<c-f>", 'x')
999 call assert_equal('', &indentexpr)
1000 bwipe!
1001endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001002
1003func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001004 " Option 'backupskip' may contain several comma-separated path
1005 " specifications if one or more of the environment variables TMPDIR, TMP,
1006 " or TEMP is defined. To simplify testing, convert the string value into a
1007 " list.
1008 let bsklist = split(&bsk, ',')
1009
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001010 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001011 let found = (index(bsklist, '/private/tmp/*') >= 0)
1012 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001013 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001014 let found = (index(bsklist, '/tmp/*') >= 0)
1015 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001016 endif
1017
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001018 " If our test platform is Windows, the path(s) in option bsk will use
1019 " backslash for the path separator and the components could be in short
1020 " (8.3) format. As such, we need to replace the backslashes with forward
1021 " slashes and convert the path components to long format. The expand()
1022 " function will do this but it cannot handle comma-separated paths. This is
1023 " why bsk was converted from a string into a list of strings above.
1024 "
1025 " One final complication is that the wildcard "/*" is at the end of each
1026 " path and so expand() might return a list of matching files. To prevent
1027 " this, we need to remove the wildcard before calling expand() and then
1028 " append it afterwards.
1029 if has('win32')
1030 let item_nbr = 0
1031 while item_nbr < len(bsklist)
1032 let path_spec = bsklist[item_nbr]
1033 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1034 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1035 let bsklist[item_nbr] = path_spec . '/*'
1036 let item_nbr += 1
1037 endwhile
1038 endif
1039
1040 " Option bsk will also include these environment variables if defined.
1041 " If they're defined, verify they appear in the option value.
1042 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001043 if exists(var)
1044 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001045 let varvalue = substitute(varvalue, '/$', '', '')
1046 let varvalue .= '/*'
1047 let found = (index(bsklist, varvalue) >= 0)
1048 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001049 endif
1050 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001051
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001052 " Duplicates from environment variables should be filtered out (option has
1053 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1054 " so that we see what happens on startup.
1055 let after =<< trim [CODE]
1056 let bsklist = split(&backupskip, ',')
1057 call assert_equal(uniq(copy(bsklist)), bsklist)
1058 call writefile(['errors:'] + v:errors, 'Xtestout')
1059 qall
1060 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001061 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001062 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1063
1064 let saveenv = {}
1065 for var in ['TMPDIR', 'TMP', 'TEMP']
1066 let saveenv[var] = getenv(var)
1067 call setenv(var, '/duplicate/path')
1068 endfor
1069
1070 exe 'silent !' . cmd
1071 call assert_equal(['errors:'], readfile('Xtestout'))
1072
1073 " restore environment variables
1074 for var in ['TMPDIR', 'TMP', 'TEMP']
1075 call setenv(var, saveenv[var])
1076 endfor
1077
1078 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001079
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001080 " Duplicates should be filtered out (option has P_NODUP)
1081 let backupskip = &backupskip
1082 set backupskip=
1083 set backupskip+=/test/dir
1084 set backupskip+=/other/dir
1085 set backupskip+=/test/dir
1086 call assert_equal('/test/dir,/other/dir', &backupskip)
1087 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001088endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001089
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001090func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001091 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001092
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001093 " Test copy option from current buffer in window
1094 split
1095 enew
1096 setlocal numberwidth=5
1097 wincmd w
1098 call assert_equal(4,&numberwidth)
1099 bnext
1100 call assert_equal(5,&numberwidth)
1101 bw!
1102 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001103
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001104 " Test copy value from window that used to be display the buffer
1105 split
1106 enew
1107 setlocal numberwidth=6
1108 bnext
1109 wincmd w
1110 call assert_equal(4,&numberwidth)
1111 bnext
1112 call assert_equal(6,&numberwidth)
1113 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001114
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001115 " Test that if buffer is current, don't use the stale cached value
1116 " from the last time the buffer was displayed.
1117 split
1118 enew
1119 setlocal numberwidth=7
1120 bnext
1121 bnext
1122 setlocal numberwidth=8
1123 wincmd w
1124 call assert_equal(4,&numberwidth)
1125 bnext
1126 call assert_equal(8,&numberwidth)
1127 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001128
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001129 " Test value is not copied if window already has seen the buffer
1130 enew
1131 split
1132 setlocal numberwidth=9
1133 bnext
1134 setlocal numberwidth=10
1135 wincmd w
1136 call assert_equal(4,&numberwidth)
1137 bnext
1138 call assert_equal(4,&numberwidth)
1139 bw!
1140
1141 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001142endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001143
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001144def Test_split_copy_options()
1145 var values = [
1146 ['cursorbind', true, false],
1147 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1148 ['list', true, 0],
1149 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1150 ['number', true, 0],
1151 ['relativenumber', true, false],
1152 ['scrollbind', true, false],
1153 ['smoothscroll', true, false],
1154 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1155 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1156 ['wrap', false, true],
1157 ]
1158 if has('linebreak')
1159 values += [
1160 ['breakindent', true, false],
1161 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1162 ['linebreak', true, false],
1163 ['numberwidth', 7, 4],
1164 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1165 ]
1166 endif
1167 if has('rightleft')
1168 values += [
1169 ['rightleft', true, false],
1170 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1171 ]
1172 endif
1173 if has('statusline')
1174 values += [
1175 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1176 ]
1177 endif
1178 if has('spell')
1179 values += [
1180 ['spell', true, false],
1181 ]
1182 endif
1183 if has('syntax')
1184 values += [
1185 ['cursorcolumn', true, false],
1186 ['cursorline', true, false],
1187 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1188 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1189 ]
1190 endif
1191 if has('diff')
1192 values += [
1193 ['diff', true, false],
1194 ]
1195 endif
1196 if has('conceal')
1197 values += [
1198 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1199 ['conceallevel', '3', &conceallevel],
1200 ]
1201 endif
1202 if has('terminal')
1203 values += [
1204 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1205 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1206 ]
1207 endif
1208 if has('folding')
1209 values += [
1210 ['foldcolumn', 5, &foldcolumn],
1211 ['foldenable', false, true],
1212 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1213 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1214 ['foldlevel', 4, &foldlevel],
1215 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1216 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1217 ['foldminlines', 3, &foldminlines],
1218 ['foldnestmax', 17, &foldnestmax],
1219 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1220 ]
1221 endif
1222 if has('signs')
1223 values += [
1224 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1225 ]
1226 endif
1227
1228 # set options to non-default value
1229 for item in values
1230 exe $'&l:{item[0]} = {item[1]}'
1231 endfor
1232
1233 # check values are set in new window
1234 split
1235 for item in values
1236 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1237 endfor
1238
1239 # restore
1240 close
1241 for item in values
1242 exe $'&l:{item[0]} = {item[2]}'
1243 endfor
1244enddef
1245
Bram Moolenaarfc089602018-06-24 16:53:35 +02001246func Test_shortmess_F()
1247 new
1248 call assert_match('\[No Name\]', execute('file'))
1249 set shortmess+=F
1250 call assert_match('\[No Name\]', execute('file'))
1251 call assert_match('^\s*$', execute('file foo'))
1252 call assert_match('foo', execute('file'))
1253 set shortmess-=F
1254 call assert_match('bar', execute('file bar'))
1255 call assert_match('bar', execute('file'))
1256 set shortmess&
1257 bwipe
1258endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001259
1260func Test_shortmess_F2()
1261 e file1
1262 e file2
1263 call assert_match('file1', execute('bn', ''))
1264 call assert_match('file2', execute('bn', ''))
1265 set shortmess+=F
1266 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001267 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001268 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001269 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001270 set hidden
1271 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001272 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001273 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001274 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001275 set nohidden
1276 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001277 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001278 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001279 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001280 set shortmess&
1281 call assert_match('file1', execute('bn', ''))
1282 call assert_match('file2', execute('bn', ''))
1283 bwipe
1284 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001285 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001286endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001287
1288func Test_local_scrolloff()
1289 set so=5
1290 set siso=7
1291 split
1292 call assert_equal(5, &so)
1293 setlocal so=3
1294 call assert_equal(3, &so)
1295 wincmd w
1296 call assert_equal(5, &so)
1297 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001298 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001299 setlocal so<
1300 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001301 setglob so=8
1302 call assert_equal(8, &so)
1303 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001304 setlocal so=0
1305 call assert_equal(0, &so)
1306 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001307 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001308
1309 call assert_equal(7, &siso)
1310 setlocal siso=3
1311 call assert_equal(3, &siso)
1312 wincmd w
1313 call assert_equal(7, &siso)
1314 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001315 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001316 setlocal siso<
1317 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001318 setglob siso=4
1319 call assert_equal(4, &siso)
1320 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001321 setlocal siso=0
1322 call assert_equal(0, &siso)
1323 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001324 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001325
1326 close
1327 set so&
1328 set siso&
1329endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001330
1331func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001332 CheckFunction reltimefloat
1333
Bram Moolenaar449ac472019-04-03 21:42:35 +02001334 new
1335 call setline(1, 'empty')
1336 redraw
1337 set writedelay=10
1338 let start = reltime()
1339 call setline(1, repeat('x', 70))
1340 redraw
1341 let elapsed = reltimefloat(reltime(start))
1342 set writedelay=0
1343 " With 'writedelay' set should take at least 30 * 10 msec
1344 call assert_inrange(30 * 0.01, 999.0, elapsed)
1345
1346 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001347endfunc
1348
1349func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001350 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001351 set visualbell
1352 call assert_beeps('normal 0h')
1353 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001354 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001355endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001356
1357" Test for the 'write' option
1358func Test_write()
1359 new
1360 call setline(1, ['L1'])
1361 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001362 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001363 set write
1364 close!
1365endfunc
1366
1367" Test for 'buftype' option
1368func Test_buftype()
1369 new
1370 call setline(1, ['L1'])
1371 set buftype=nowrite
1372 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001373
1374 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1375 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001376 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001377 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1378 endfor
1379
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001380 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001381endfunc
1382
Bram Moolenaar578fe942020-02-27 21:32:51 +01001383" Test for the 'rightleftcmd' option
1384func Test_rightleftcmd()
1385 CheckFeature rightleft
1386 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001387
1388 let g:l = []
1389 func AddPos()
1390 call add(g:l, screencol())
1391 return ''
1392 endfunc
1393 cmap <expr> <F2> AddPos()
1394
zeertzjqbb404f52022-07-23 06:25:29 +01001395 set rightleftcmd=
1396 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1397 \ "\<Right>\<F2>\<Esc>", 'xt')
1398 call assert_equal([2, 5, 3, 4], g:l)
1399
1400 let g:l = []
1401 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001402 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1403 \ "\<Left>\<F2>\<Esc>", 'xt')
1404 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1405
1406 cunmap <F2>
1407 unlet g:l
1408 set rightleftcmd&
1409 set rightleft&
1410endfunc
1411
zeertzjq28c162f2022-08-14 14:49:50 +01001412" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001413func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001414 " redraw to avoid matching previous messages
1415 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001416 set debug=beep
1417 exe "normal \<C-c>"
1418 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001419 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001420 " also check a line above, with a certain window width the colon is there
1421 call assert_match('Test_debug_option:$',
1422 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001423 set debug&
1424endfunc
1425
Bram Moolenaar004a6782020-04-11 17:09:31 +02001426" Test for the default CDPATH option
1427func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001428 let after =<< trim [CODE]
1429 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1430 call writefile(v:errors, 'Xtestout')
1431 qall
1432 [CODE]
1433 if has('unix')
1434 let $CDPATH='/path/to/dir1:/path/to/dir2'
1435 else
1436 let $CDPATH='/path/to/dir1;/path/to/dir2'
1437 endif
1438 if RunVim([], after, '')
1439 call assert_equal([], readfile('Xtestout'))
1440 call delete('Xtestout')
1441 endif
1442endfunc
1443
1444" Test for setting keycodes using set
1445func Test_opt_set_keycode()
1446 call assert_fails('set <t_k1=l', 'E474:')
1447 call assert_fails('set <Home=l', 'E474:')
1448 set <t_k9>=abcd
1449 call assert_equal('abcd', &t_k9)
1450 set <t_k9>&
1451 set <F9>=xyz
1452 call assert_equal('xyz', &t_k9)
1453 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001454
1455 " should we test all of them?
1456 set t_Ce=testCe
1457 set t_Cs=testCs
1458 set t_Us=testUs
1459 set t_ds=testds
1460 set t_Ds=testDs
1461 call assert_equal('testCe', &t_Ce)
1462 call assert_equal('testCs', &t_Cs)
1463 call assert_equal('testUs', &t_Us)
1464 call assert_equal('testds', &t_ds)
1465 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001466endfunc
1467
1468" Test for changing options in a sandbox
1469func Test_opt_sandbox()
1470 for opt in ['backupdir', 'cdpath', 'exrc']
1471 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001472 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001473 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001474 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001475endfunc
1476
1477" Test for setting an option with local value to global value
1478func Test_opt_local_to_global()
1479 setglobal equalprg=gprg
1480 setlocal equalprg=lprg
1481 call assert_equal('gprg', &g:equalprg)
1482 call assert_equal('lprg', &l:equalprg)
1483 call assert_equal('lprg', &equalprg)
1484 set equalprg<
1485 call assert_equal('', &l:equalprg)
1486 call assert_equal('gprg', &equalprg)
1487 setglobal equalprg=gnewprg
1488 setlocal equalprg=lnewprg
1489 setlocal equalprg<
1490 call assert_equal('gnewprg', &l:equalprg)
1491 call assert_equal('gnewprg', &equalprg)
1492 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001493
1494 " Test for setting the global/local value of a boolean option
1495 setglobal autoread
1496 setlocal noautoread
1497 call assert_false(&autoread)
1498 set autoread<
1499 call assert_true(&autoread)
1500 setglobal noautoread
1501 setlocal autoread
1502 setlocal autoread<
1503 call assert_false(&autoread)
1504 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001505endfunc
1506
Dominique Pelle042414f2021-07-12 21:43:19 +02001507func Test_set_in_sandbox()
1508 " Some boolean options cannot be set in sandbox, some can.
1509 call assert_fails('sandbox set modelineexpr', 'E48:')
1510 sandbox set number
1511 call assert_true(&number)
1512 set number&
1513
1514 " Some boolean options cannot be set in sandbox, some can.
1515 if has('python') || has('python3')
1516 call assert_fails('sandbox set pyxversion=3', 'E48:')
1517 endif
1518 sandbox set tabstop=4
1519 call assert_equal(4, &tabstop)
1520 set tabstop&
1521
1522 " Some string options cannot be set in sandbox, some can.
1523 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1524 sandbox set filetype=perl
1525 call assert_equal('perl', &filetype)
1526 set filetype&
1527endfunc
1528
Bram Moolenaar004a6782020-04-11 17:09:31 +02001529" Test for incrementing, decrementing and multiplying a number option value
1530func Test_opt_num_op()
1531 set shiftwidth=4
1532 set sw+=2
1533 call assert_equal(6, &sw)
1534 set sw-=2
1535 call assert_equal(4, &sw)
1536 set sw^=2
1537 call assert_equal(8, &sw)
1538 set shiftwidth&
1539endfunc
1540
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001541" Test for setting option values using v:false and v:true
1542func Test_opt_boolean()
1543 set number&
1544 set number
1545 call assert_equal(1, &nu)
1546 set nonu
1547 call assert_equal(0, &nu)
1548 let &nu = v:true
1549 call assert_equal(1, &nu)
1550 let &nu = v:false
1551 call assert_equal(0, &nu)
1552 set number&
1553endfunc
1554
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001555" Test for the 'window' option
1556func Test_window_opt()
1557 " Needs only one open widow
1558 %bw!
1559 call setline(1, range(1, 8))
1560 set window=5
1561 exe "normal \<C-F>"
1562 call assert_equal(4, line('w0'))
1563 exe "normal \<C-F>"
1564 call assert_equal(7, line('w0'))
1565 exe "normal \<C-F>"
1566 call assert_equal(8, line('w0'))
1567 exe "normal \<C-B>"
1568 call assert_equal(5, line('w0'))
1569 exe "normal \<C-B>"
1570 call assert_equal(2, line('w0'))
1571 exe "normal \<C-B>"
1572 call assert_equal(1, line('w0'))
1573 set window=1
1574 exe "normal gg\<C-F>"
1575 call assert_equal(2, line('w0'))
1576 exe "normal \<C-F>"
1577 call assert_equal(3, line('w0'))
1578 exe "normal \<C-B>"
1579 call assert_equal(2, line('w0'))
1580 exe "normal \<C-B>"
1581 call assert_equal(1, line('w0'))
1582 enew!
1583 set window&
1584endfunc
1585
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001586" Test for the 'winminheight' option
1587func Test_opt_winminheight()
1588 only!
1589 let &winheight = &lines + 4
1590 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1591 call assert_true(&winminheight <= &lines)
1592 set winminheight&
1593 set winheight&
1594endfunc
1595
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001596func Test_opt_winminheight_term()
1597 CheckRunVimInTerminal
1598
1599 " The tabline should be taken into account.
1600 let lines =<< trim END
1601 set wmh=0 stal=2
1602 below sp | wincmd _
1603 below sp | wincmd _
1604 below sp | wincmd _
1605 below sp
1606 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001607 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001608 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1609 call term_sendkeys(buf, ":set wmh=1\n")
1610 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1611
1612 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001613endfunc
1614
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001615func Test_opt_winminheight_term_tabs()
1616 CheckRunVimInTerminal
1617
1618 " The tabline should be taken into account.
1619 let lines =<< trim END
1620 set wmh=0 stal=2
1621 split
1622 split
1623 split
1624 split
1625 tabnew
1626 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001627 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001628 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1629 call term_sendkeys(buf, ":set wmh=1\n")
1630 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1631
1632 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001633endfunc
1634
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001635" Test for the 'winminwidth' option
1636func Test_opt_winminwidth()
1637 only!
1638 let &winwidth = &columns + 4
1639 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1640 call assert_true(&winminwidth <= &columns)
1641 set winminwidth&
1642 set winwidth&
1643endfunc
1644
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001645" Test for setting option value containing spaces with isfname+=32
1646func Test_isfname_with_options()
1647 set isfname+=32
1648 setlocal keywordprg=:term\ help.exe
1649 call assert_equal(':term help.exe', &keywordprg)
1650 set isfname&
1651 setlocal keywordprg&
1652endfunc
1653
Bram Moolenaar74667062020-12-28 15:41:41 +01001654" Test that resetting laststatus does change scroll option
1655func Test_opt_reset_scroll()
1656 CheckRunVimInTerminal
1657 let vimrc =<< trim [CODE]
1658 set scroll=2
1659 set laststatus=2
1660 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001661 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001662 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1663 call term_sendkeys(buf, ":verbose set scroll?\n")
1664 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1665 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001666
1667 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001668 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001669endfunc
1670
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001671" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1672func Test_VIM_POSIX()
1673 let saved_VIM_POSIX = getenv("VIM_POSIX")
1674
1675 call setenv('VIM_POSIX', "1")
1676 let after =<< trim [CODE]
1677 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1678 qall
1679 [CODE]
1680 if RunVim([], after, '')
1681 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1682 \ 'AS'], readfile('X_VIM_POSIX'))
1683 endif
1684
1685 call setenv('VIM_POSIX', v:null)
1686 let after =<< trim [CODE]
1687 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1688 qall
1689 [CODE]
1690 if RunVim([], after, '')
1691 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1692 \ 'S'], readfile('X_VIM_POSIX'))
1693 endif
1694
1695 call delete('X_VIM_POSIX')
1696 call setenv('VIM_POSIX', saved_VIM_POSIX)
1697endfunc
1698
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001699" Test for setting an option to a Vi or Vim default
1700func Test_opt_default()
1701 set formatoptions&vi
1702 call assert_equal('vt', &formatoptions)
1703 set formatoptions&vim
1704 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001705
1706 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1707 set fencs=latin1
1708 set fencs&
1709 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1710 set fencs=latin1
1711 set all&
1712 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001713endfunc
1714
1715" Test for the 'cmdheight' option
1716func Test_cmdheight()
1717 %bw!
1718 let ht = &lines
1719 set cmdheight=9999
1720 call assert_equal(1, winheight(0))
1721 call assert_equal(ht - 1, &cmdheight)
1722 set cmdheight&
1723endfunc
1724
Dominique Pelle923dce22021-11-21 11:36:04 +00001725" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001726func Test_opt_control_char()
1727 set wildchar=^v
1728 call assert_equal("\<C-V>", nr2char(&wildchar))
1729 set wildcharm=^r
1730 call assert_equal("\<C-R>", nr2char(&wildcharm))
1731 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1732 set wildchar& wildcharm&
1733endfunc
1734
1735" Test for the 'errorbells' option
1736func Test_opt_errorbells()
1737 set errorbells
1738 call assert_beeps('s/a1b2/x1y2/')
1739 set noerrorbells
1740endfunc
1741
Dominique Pelle042414f2021-07-12 21:43:19 +02001742func Test_opt_scrolljump()
1743 help
1744 resize 10
1745
1746 " Test with positive 'scrolljump'.
1747 set scrolljump=2
1748 norm! Lj
1749 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1750 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1751 \ winsaveview())
1752
1753 " Test with negative 'scrolljump' (percentage of window height).
1754 set scrolljump=-40
1755 norm! ggLj
1756 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1757 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1758 \ winsaveview())
1759
1760 set scrolljump&
1761 bw
1762endfunc
1763
Bakudankun29f3a452021-12-11 12:28:08 +00001764" Test for the 'cdhome' option
1765func Test_opt_cdhome()
1766 if has('unix') || has('vms')
1767 throw 'Skipped: only works on non-Unix'
1768 endif
1769
1770 set cdhome&
1771 call assert_equal(0, &cdhome)
1772 set cdhome
1773
1774 " This paragraph is copied from Test_cd_no_arg().
1775 let path = getcwd()
1776 cd
1777 call assert_equal($HOME, getcwd())
1778 call assert_notequal(path, getcwd())
1779 exe 'cd ' .. fnameescape(path)
1780 call assert_equal(path, getcwd())
1781
1782 set cdhome&
1783endfunc
1784
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001785func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001786 CheckOption termguicolors
1787
1788 " Test default option completion
1789 set wildoptions=
1790 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1791 call assert_equal('"set termguicolors', @:)
1792
1793 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1794 call assert_equal('"set notermguicolors', @:)
1795
1796 " Test fuzzy option completion
1797 set wildoptions=fuzzy
1798 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1799 call assert_equal('"set termguicolors termencoding', @:)
1800
1801 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1802 call assert_equal('"set notermguicolors', @:)
1803
1804 set wildoptions=
1805endfunc
1806
Sean Dewar39c46b42022-05-12 17:44:29 +01001807func Test_switchbuf_reset()
1808 set switchbuf=useopen
1809 sblast
1810 call assert_equal(1, winnr('$'))
1811 set all&
1812 call assert_equal('', &switchbuf)
1813 sblast
1814 call assert_equal(2, winnr('$'))
1815 only!
1816endfunc
1817
zeertzjqfcba86c2022-09-22 13:57:32 +01001818" :set empty string for global 'keywordprg' falls back to ":help"
1819func Test_keywordprg_empty()
1820 let k = &keywordprg
1821 set keywordprg=man
1822 call assert_equal('man', &keywordprg)
1823 set keywordprg=
1824 call assert_equal(':help', &keywordprg)
1825 set keywordprg=man
1826 call assert_equal('man', &keywordprg)
1827 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1828 let &keywordprg = k
1829endfunc
1830
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001831" check that the very first buffer created does not have 'endoffile' set
1832func Test_endoffile_default()
1833 let after =<< trim [CODE]
1834 call writefile([execute('set eof?')], 'Xtestout')
1835 qall!
1836 [CODE]
1837 if RunVim([], after, '')
1838 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1839 endif
1840 call delete('Xtestout')
1841endfunc
1842
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001843" Test for setting the 'lines' and 'columns' options to a minimum value
1844func Test_set_min_lines_columns()
1845 let save_lines = &lines
1846 let save_columns = &columns
1847
1848 let after =<< trim END
1849 set nomore
1850 let msg = []
1851 let v:errmsg = ''
1852 silent! let &columns=0
1853 call add(msg, v:errmsg)
1854 silent! set columns=0
1855 call add(msg, v:errmsg)
1856 silent! call setbufvar('', '&columns', 0)
1857 call add(msg, v:errmsg)
1858 "call writefile(msg, 'XResultsetminlines')
1859 silent! let &lines=0
1860 call add(msg, v:errmsg)
1861 silent! set lines=0
1862 call add(msg, v:errmsg)
1863 silent! call setbufvar('', '&lines', 0)
1864 call add(msg, v:errmsg)
1865 call writefile(msg, 'XResultsetminlines')
1866 qall!
1867 END
1868 if RunVim([], after, '')
1869 call assert_equal(['E594: Need at least 12 columns',
1870 \ 'E594: Need at least 12 columns: columns=0',
1871 \ 'E594: Need at least 12 columns',
1872 \ 'E593: Need at least 2 lines',
1873 \ 'E593: Need at least 2 lines: lines=0',
1874 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1875 endif
1876
1877 call delete('XResultsetminlines')
1878 let &lines = save_lines
1879 let &columns = save_columns
1880endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001881
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001882" Test for reverting a string option value if the new value is invalid.
1883func Test_string_option_revert_on_failure()
1884 new
1885 let optlist = [
1886 \ ['ambiwidth', 'double', 'a123'],
1887 \ ['background', 'dark', 'a123'],
1888 \ ['backspace', 'eol', 'a123'],
1889 \ ['backupcopy', 'no', 'a123'],
1890 \ ['belloff', 'showmatch', 'a123'],
1891 \ ['breakindentopt', 'min:10', 'list'],
1892 \ ['bufhidden', 'wipe', 'a123'],
1893 \ ['buftype', 'nowrite', 'a123'],
1894 \ ['casemap', 'keepascii', 'a123'],
1895 \ ['cedit', "\<C-Y>", 'z'],
1896 \ ['colorcolumn', '10', 'z'],
1897 \ ['commentstring', '#%s', 'a123'],
1898 \ ['complete', '.,t', 'a'],
1899 \ ['completefunc', 'MyCmplFunc', '1a-'],
1900 \ ['completeopt', 'popup', 'a123'],
1901 \ ['completepopup', 'width:20', 'border'],
1902 \ ['concealcursor', 'v', 'xyz'],
1903 \ ['cpoptions', 'HJ', '~'],
1904 \ ['cryptmethod', 'zip', 'a123'],
1905 \ ['cursorlineopt', 'screenline', 'a123'],
1906 \ ['debug', 'throw', 'a123'],
1907 \ ['diffopt', 'iwhite', 'a123'],
1908 \ ['display', 'uhex', 'a123'],
1909 \ ['eadirection', 'hor', 'a123'],
1910 \ ['encoding', 'utf-8', 'a123'],
1911 \ ['eventignore', 'TextYankPost', 'a123'],
1912 \ ['fileencoding', 'utf-8', 'a123,'],
1913 \ ['fileformat', 'mac', 'a123'],
1914 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001915 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001916 \ ['fillchars', 'diff:~', 'a123'],
1917 \ ['foldclose', 'all', 'a123'],
1918 \ ['foldmarker', '[[[,]]]', '[[['],
1919 \ ['foldmethod', 'marker', 'a123'],
1920 \ ['foldopen', 'percent', 'a123'],
1921 \ ['formatoptions', 'an', '*'],
1922 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1923 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001924 \ ['highlight', '!:CursorColumn', '8:'],
1925 \ ['keymodel', 'stopsel', 'a123'],
1926 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1927 \ ['lispoptions', 'expr:1', 'a123'],
1928 \ ['listchars', 'tab:->', 'tab:'],
1929 \ ['matchpairs', '<:>', '<:'],
1930 \ ['mkspellmem', '100000,1000,100', '100000'],
1931 \ ['mouse', 'nvi', 'z'],
1932 \ ['mousemodel', 'extend', 'a123'],
1933 \ ['nrformats', 'alpha', 'a123'],
1934 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1935 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1936 \ ['previewpopup', 'width:20', 'a123'],
1937 \ ['printoptions', 'paper:A4', 'a123:'],
1938 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1939 \ ['rulerformat', '%l', '%['],
1940 \ ['scrollopt', 'hor,jump', 'a123'],
1941 \ ['selection', 'exclusive', 'a123'],
1942 \ ['selectmode', 'cmd', 'a123'],
1943 \ ['sessionoptions', 'options', 'a123'],
1944 \ ['shortmess', 'w', '2'],
1945 \ ['showbreak', '>>', "\x01"],
1946 \ ['showcmdloc', 'statusline', 'a123'],
1947 \ ['signcolumn', 'no', 'a123'],
1948 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1949 \ ['spellfile', 'MySpell.en.add', "\x01"],
1950 \ ['spelllang', 'en', "#"],
1951 \ ['spelloptions', 'camel', 'a123'],
1952 \ ['spellsuggest', 'double', 'a123'],
1953 \ ['splitkeep', 'topline', 'a123'],
1954 \ ['statusline', '%f', '%['],
1955 \ ['swapsync', 'sync', 'a123'],
1956 \ ['switchbuf', 'usetab', 'a123'],
1957 \ ['syntax', 'abc', 'a^b'],
1958 \ ['tabline', '%f', '%['],
1959 \ ['tagcase', 'ignore', 'a123'],
1960 \ ['tagfunc', 'MyTagFunc', '1a-'],
1961 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1962 \ ['viewoptions', 'options', 'a123'],
1963 \ ['virtualedit', 'onemore', 'a123'],
1964 \ ['whichwrap', '<,>', '{,}'],
1965 \ ['wildmode', 'list', 'a123'],
1966 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001967 \ ]
1968 if has('gui')
1969 call add(optlist, ['browsedir', 'buffer', 'a123'])
1970 endif
1971 if has('clipboard_working')
1972 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1973 endif
1974 if has('win32')
1975 call add(optlist, ['completeslash', 'slash', 'a123'])
1976 endif
1977 if has('cscope')
1978 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1979 endif
1980 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001981 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1982 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1983 endif
1984 if has('keymap')
1985 call add(optlist, ['keymap', 'greek', '[]'])
1986 endif
1987 if has('mouseshape')
1988 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1989 endif
1990 if has('win32') && has('gui')
1991 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1992 endif
1993 if has('rightleft')
1994 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1995 endif
1996 if has('terminal')
1997 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1998 call add(optlist, ['termwinsize', '24x80', '100'])
1999 endif
2000 if has('win32') && has('terminal')
2001 call add(optlist, ['termwintype', 'winpty', 'a123'])
2002 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002003 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002004 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002005 endif
2006 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002007 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2008 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002009 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002010 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2011 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002012 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002013 call add(optlist, ['varsofttabstop', '12', 'a123'])
2014 call add(optlist, ['vartabstop', '4,20', '4,'])
2015 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002016 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002017 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002018 endif
2019 for opt in optlist
2020 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002021 try
2022 exe $"let &{opt[0]} = '{opt[1]}'"
2023 catch
2024 call assert_report($"Caught {v:exception} with {opt->string()}")
2025 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002026 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2027 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2028 exe $"let &{opt[0]} = save_opt"
2029 endfor
2030 bw!
2031endfunc
2032
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002033func Test_set_option_window_global_local()
2034 new Xbuffer1
2035 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2036 setlocal scrolloff=2
2037 setglobal scrolloff=3
2038 setl modified
2039 " A new buffer has its own window-local options
2040 hide enew
2041 call assert_equal(-1, &l:scrolloff)
2042 call assert_equal(3, &g:scrolloff)
2043 " A new window opened with its own buffer-local options
2044 new
2045 call assert_equal(-1, &l:scrolloff)
2046 call assert_equal(3, &g:scrolloff)
2047 " Re-open Xbuffer1 and it should use
2048 " the previous set window-local options
2049 b Xbuffer1
2050 call assert_equal(2, &l:scrolloff)
2051 call assert_equal(3, &g:scrolloff)
2052 bw!
2053 bw!
2054 let &g:scrolloff = _gso
2055endfunc
2056
2057func GetGlobalLocalWindowOptions()
2058 new
2059 sil! r $VIMRUNTIME/doc/options.txt
2060 " Filter for global or local to window
2061 v/^'.*'.*\n.*global or local to window |global-local/d
2062 " get option value and type
2063 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2064 sil %s/empty/""/g
2065 " split the result
2066 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2067 bw!
2068 return result
2069endfunc
2070
2071func Test_set_option_window_global_local_all()
2072 new Xbuffer2
2073
2074 let optionlist = GetGlobalLocalWindowOptions()
2075 for [opt, type, default] in optionlist
2076 let _old = eval('&g:' .. opt)
2077 if type == 'string'
2078 if opt == 'fillchars'
2079 exe 'setl ' .. opt .. '=vert:+'
2080 exe 'setg ' .. opt .. '=vert:+,fold:+'
2081 elseif opt == 'listchars'
2082 exe 'setl ' .. opt .. '=tab:>>'
2083 exe 'setg ' .. opt .. '=tab:++'
2084 elseif opt == 'virtualedit'
2085 exe 'setl ' .. opt .. '=all'
2086 exe 'setg ' .. opt .. '=block'
2087 else
2088 exe 'setl ' .. opt .. '=Local'
2089 exe 'setg ' .. opt .. '=Global'
2090 endif
2091 elseif type == 'number'
2092 exe 'setl ' .. opt .. '=5'
2093 exe 'setg ' .. opt .. '=10'
2094 endif
2095 setl modified
2096 hide enew
2097 if type == 'string'
2098 call assert_equal('', eval('&l:' .. opt))
2099 if opt == 'fillchars'
2100 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2101 elseif opt == 'listchars'
2102 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2103 elseif opt == 'virtualedit'
2104 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2105 else
2106 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2107 endif
2108 elseif type == 'number'
2109 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2110 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2111 endif
2112 bw!
2113 exe 'let &g:' .. opt .. '=' .. default
2114 endfor
2115 bw!
2116endfunc
2117
Christian Brabandt757593c2023-08-22 21:44:10 +02002118func Test_paste_depending_options()
2119 " setting the paste option, resets all dependent options
2120 " and will be reported correctly using :verbose set <option>?
2121 let lines =<< trim [CODE]
2122 " set paste test
2123 set autoindent
2124 set expandtab
2125 " disabled, because depends on compiled feature set
2126 " set hkmap
2127 " set revins
2128 " set varsofttabstop=8,32,8
2129 set ruler
2130 set showmatch
2131 set smarttab
2132 set softtabstop=4
2133 set textwidth=80
2134 set wrapmargin=10
2135
2136 source Xvimrc_paste2
2137
2138 redir > Xoutput_paste
2139 verbose set expandtab?
2140 verbose setg expandtab?
2141 verbose setl expandtab?
2142 redir END
2143
2144 qall!
2145 [CODE]
2146
2147 call writefile(lines, 'Xvimrc_paste', 'D')
2148 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2149 if !RunVim([], lines, '--clean')
2150 return
2151 endif
2152
2153 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2154 call assert_equal('noexpandtab', result[0])
2155 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2156 call assert_equal('noexpandtab', result[2])
2157 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2158 call assert_equal('noexpandtab', result[4])
2159 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2160
2161 call delete('Xoutput_paste')
2162endfunc
2163
2164func Test_binary_depending_options()
2165 " setting the paste option, resets all dependent options
2166 " and will be reported correctly using :verbose set <option>?
2167 let lines =<< trim [CODE]
2168 " set binary test
2169 set expandtab
2170
2171 source Xvimrc_bin2
2172
2173 redir > Xoutput_bin
2174 verbose set expandtab?
2175 verbose setg expandtab?
2176 verbose setl expandtab?
2177 redir END
2178
2179 qall!
2180 [CODE]
2181
2182 call writefile(lines, 'Xvimrc_bin', 'D')
2183 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2184 if !RunVim([], lines, '--clean')
2185 return
2186 endif
2187
2188 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2189 call assert_equal('noexpandtab', result[0])
2190 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2191 call assert_equal('noexpandtab', result[2])
2192 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2193 call assert_equal('noexpandtab', result[4])
2194 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2195
2196 call delete('Xoutput_bin')
2197endfunc
2198
Gregory Anders3695d0e2023-09-29 20:17:20 +02002199func Test_set_keyprotocol()
2200 CheckNotGui
2201
2202 let term = &term
2203 set term=ansi
2204 call assert_equal('', &t_TI)
2205
2206 " Setting 'keyprotocol' should affect terminal codes without needing to
2207 " reset 'term'
2208 set keyprotocol+=ansi:kitty
2209 call assert_equal("\<Esc>[=1;1u", &t_TI)
2210 let &term = term
2211endfunc
2212
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002213func Test_set_wrap()
2214 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2215 " cursor position.
2216 set wrap smoothscroll scrolloff=5
2217
2218 call setline(1, ['', 'aaaa'->repeat(500)])
2219 20 split
2220 20 vsplit
2221 norm 2G$
2222 redraw
2223 set nowrap
2224 call assert_equal(2, winline())
2225
2226 set wrap& smoothscroll& scrolloff&
2227endfunc
2228
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002229" vim: shiftwidth=2 sts=2 expandtab