blob: f65654dc5c1cdbf51dcbc30417969cc3165f6607 [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))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100967endfunc
968
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100969func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200970 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100971 if filereadable('opt_test.vim')
972 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100973 else
974 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100975 endif
976endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200977
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100978func Test_renderoptions()
979 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
980 " Doesn't hurt to do this on a non-Windows system.
981 if windowsversion() !~ '^[345]\.'
982 set renderoptions=type:directx
983 set rop=type:directx
984 endif
985endfunc
986
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200987func ResetIndentexpr()
988 set indentexpr=
989endfunc
990
991func Test_set_indentexpr()
992 " this was causing usage of freed memory
993 set indentexpr=ResetIndentexpr()
994 new
995 call feedkeys("i\<c-f>", 'x')
996 call assert_equal('', &indentexpr)
997 bwipe!
998endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200999
1000func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001001 " Option 'backupskip' may contain several comma-separated path
1002 " specifications if one or more of the environment variables TMPDIR, TMP,
1003 " or TEMP is defined. To simplify testing, convert the string value into a
1004 " list.
1005 let bsklist = split(&bsk, ',')
1006
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001007 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001008 let found = (index(bsklist, '/private/tmp/*') >= 0)
1009 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001010 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001011 let found = (index(bsklist, '/tmp/*') >= 0)
1012 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001013 endif
1014
Bram Moolenaar98ad1e12019-01-30 21:51:27 +01001015 " If our test platform is Windows, the path(s) in option bsk will use
1016 " backslash for the path separator and the components could be in short
1017 " (8.3) format. As such, we need to replace the backslashes with forward
1018 " slashes and convert the path components to long format. The expand()
1019 " function will do this but it cannot handle comma-separated paths. This is
1020 " why bsk was converted from a string into a list of strings above.
1021 "
1022 " One final complication is that the wildcard "/*" is at the end of each
1023 " path and so expand() might return a list of matching files. To prevent
1024 " this, we need to remove the wildcard before calling expand() and then
1025 " append it afterwards.
1026 if has('win32')
1027 let item_nbr = 0
1028 while item_nbr < len(bsklist)
1029 let path_spec = bsklist[item_nbr]
1030 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
1031 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
1032 let bsklist[item_nbr] = path_spec . '/*'
1033 let item_nbr += 1
1034 endwhile
1035 endif
1036
1037 " Option bsk will also include these environment variables if defined.
1038 " If they're defined, verify they appear in the option value.
1039 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001040 if exists(var)
1041 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +01001042 let varvalue = substitute(varvalue, '/$', '', '')
1043 let varvalue .= '/*'
1044 let found = (index(bsklist, varvalue) >= 0)
1045 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001046 endif
1047 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001048
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001049 " Duplicates from environment variables should be filtered out (option has
1050 " P_NODUP). Run this in a separate instance and write v:errors in a file,
1051 " so that we see what happens on startup.
1052 let after =<< trim [CODE]
1053 let bsklist = split(&backupskip, ',')
1054 call assert_equal(uniq(copy(bsklist)), bsklist)
1055 call writefile(['errors:'] + v:errors, 'Xtestout')
1056 qall
1057 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001058 call writefile(after, 'Xafter', 'D')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001059 let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
1060
1061 let saveenv = {}
1062 for var in ['TMPDIR', 'TMP', 'TEMP']
1063 let saveenv[var] = getenv(var)
1064 call setenv(var, '/duplicate/path')
1065 endfor
1066
1067 exe 'silent !' . cmd
1068 call assert_equal(['errors:'], readfile('Xtestout'))
1069
1070 " restore environment variables
1071 for var in ['TMPDIR', 'TMP', 'TEMP']
1072 call setenv(var, saveenv[var])
1073 endfor
1074
1075 call delete('Xtestout')
Bram Moolenaarb00ef052020-09-12 14:53:53 +02001076
Bram Moolenaar06e2c812019-06-12 19:05:48 +02001077 " Duplicates should be filtered out (option has P_NODUP)
1078 let backupskip = &backupskip
1079 set backupskip=
1080 set backupskip+=/test/dir
1081 set backupskip+=/other/dir
1082 set backupskip+=/test/dir
1083 call assert_equal('/test/dir,/other/dir', &backupskip)
1084 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02001085endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +02001086
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001087func Test_buf_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001088 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +02001089
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001090 " Test copy option from current buffer in window
1091 split
1092 enew
1093 setlocal numberwidth=5
1094 wincmd w
1095 call assert_equal(4,&numberwidth)
1096 bnext
1097 call assert_equal(5,&numberwidth)
1098 bw!
1099 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +02001100
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001101 " Test copy value from window that used to be display the buffer
1102 split
1103 enew
1104 setlocal numberwidth=6
1105 bnext
1106 wincmd w
1107 call assert_equal(4,&numberwidth)
1108 bnext
1109 call assert_equal(6,&numberwidth)
1110 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001111
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001112 " Test that if buffer is current, don't use the stale cached value
1113 " from the last time the buffer was displayed.
1114 split
1115 enew
1116 setlocal numberwidth=7
1117 bnext
1118 bnext
1119 setlocal numberwidth=8
1120 wincmd w
1121 call assert_equal(4,&numberwidth)
1122 bnext
1123 call assert_equal(8,&numberwidth)
1124 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +02001125
Bram Moolenaar7cb33a12018-08-23 22:20:35 +02001126 " Test value is not copied if window already has seen the buffer
1127 enew
1128 split
1129 setlocal numberwidth=9
1130 bnext
1131 setlocal numberwidth=10
1132 wincmd w
1133 call assert_equal(4,&numberwidth)
1134 bnext
1135 call assert_equal(4,&numberwidth)
1136 bw!
1137
1138 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +02001139endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +02001140
Bram Moolenaarb1fd26d2022-10-03 11:23:02 +01001141def Test_split_copy_options()
1142 var values = [
1143 ['cursorbind', true, false],
1144 ['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
1145 ['list', true, 0],
1146 ['listchars', '"space:-"', '"' .. &listchars .. '"'],
1147 ['number', true, 0],
1148 ['relativenumber', true, false],
1149 ['scrollbind', true, false],
1150 ['smoothscroll', true, false],
1151 ['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
1152 ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
1153 ['wrap', false, true],
1154 ]
1155 if has('linebreak')
1156 values += [
1157 ['breakindent', true, false],
1158 ['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
1159 ['linebreak', true, false],
1160 ['numberwidth', 7, 4],
1161 ['showbreak', '"++"', '"' .. &showbreak .. '"'],
1162 ]
1163 endif
1164 if has('rightleft')
1165 values += [
1166 ['rightleft', true, false],
1167 ['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
1168 ]
1169 endif
1170 if has('statusline')
1171 values += [
1172 ['statusline', '"---%f---"', '"' .. &statusline .. '"'],
1173 ]
1174 endif
1175 if has('spell')
1176 values += [
1177 ['spell', true, false],
1178 ]
1179 endif
1180 if has('syntax')
1181 values += [
1182 ['cursorcolumn', true, false],
1183 ['cursorline', true, false],
1184 ['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
1185 ['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
1186 ]
1187 endif
1188 if has('diff')
1189 values += [
1190 ['diff', true, false],
1191 ]
1192 endif
1193 if has('conceal')
1194 values += [
1195 ['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
1196 ['conceallevel', '3', &conceallevel],
1197 ]
1198 endif
1199 if has('terminal')
1200 values += [
1201 ['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
1202 ['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
1203 ]
1204 endif
1205 if has('folding')
1206 values += [
1207 ['foldcolumn', 5, &foldcolumn],
1208 ['foldenable', false, true],
1209 ['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
1210 ['foldignore', '"+="', '"' .. &foldignore .. '"'],
1211 ['foldlevel', 4, &foldlevel],
1212 ['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
1213 ['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
1214 ['foldminlines', 3, &foldminlines],
1215 ['foldnestmax', 17, &foldnestmax],
1216 ['foldtext', '"closed"', '"' .. &foldtext .. '"'],
1217 ]
1218 endif
1219 if has('signs')
1220 values += [
1221 ['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
1222 ]
1223 endif
1224
1225 # set options to non-default value
1226 for item in values
1227 exe $'&l:{item[0]} = {item[1]}'
1228 endfor
1229
1230 # check values are set in new window
1231 split
1232 for item in values
1233 exe $'assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
1234 endfor
1235
1236 # restore
1237 close
1238 for item in values
1239 exe $'&l:{item[0]} = {item[2]}'
1240 endfor
1241enddef
1242
Bram Moolenaarfc089602018-06-24 16:53:35 +02001243func Test_shortmess_F()
1244 new
1245 call assert_match('\[No Name\]', execute('file'))
1246 set shortmess+=F
1247 call assert_match('\[No Name\]', execute('file'))
1248 call assert_match('^\s*$', execute('file foo'))
1249 call assert_match('foo', execute('file'))
1250 set shortmess-=F
1251 call assert_match('bar', execute('file bar'))
1252 call assert_match('bar', execute('file'))
1253 set shortmess&
1254 bwipe
1255endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001256
1257func Test_shortmess_F2()
1258 e file1
1259 e file2
1260 call assert_match('file1', execute('bn', ''))
1261 call assert_match('file2', execute('bn', ''))
1262 set shortmess+=F
1263 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001264 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001265 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +02001266 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001267 set hidden
1268 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001269 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001270 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001271 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001272 set nohidden
1273 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 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +02001276 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001277 set shortmess&
1278 call assert_match('file1', execute('bn', ''))
1279 call assert_match('file2', execute('bn', ''))
1280 bwipe
1281 bwipe
Yegappan Lakshmanane24b5e02022-09-22 13:44:00 +01001282 call assert_fails('call test_getvalue("abc")', 'E475:')
Bram Moolenaar2f0f8712018-08-21 18:50:18 +02001283endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +01001284
1285func Test_local_scrolloff()
1286 set so=5
1287 set siso=7
1288 split
1289 call assert_equal(5, &so)
1290 setlocal so=3
1291 call assert_equal(3, &so)
1292 wincmd w
1293 call assert_equal(5, &so)
1294 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001295 call assert_equal(3, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001296 setlocal so<
1297 call assert_equal(5, &so)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001298 setglob so=8
1299 call assert_equal(8, &so)
1300 call assert_equal(-1, &l:so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001301 setlocal so=0
1302 call assert_equal(0, &so)
1303 setlocal so=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001304 call assert_equal(8, &so)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001305
1306 call assert_equal(7, &siso)
1307 setlocal siso=3
1308 call assert_equal(3, &siso)
1309 wincmd w
1310 call assert_equal(7, &siso)
1311 wincmd w
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001312 call assert_equal(3, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001313 setlocal siso<
1314 call assert_equal(7, &siso)
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001315 setglob siso=4
1316 call assert_equal(4, &siso)
1317 call assert_equal(-1, &l:siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001318 setlocal siso=0
1319 call assert_equal(0, &siso)
1320 setlocal siso=-1
Bram Moolenaarbf5f1892023-06-27 21:51:07 +01001321 call assert_equal(4, &siso)
Bram Moolenaar375e3392019-01-31 18:26:10 +01001322
1323 close
1324 set so&
1325 set siso&
1326endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +02001327
1328func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +01001329 CheckFunction reltimefloat
1330
Bram Moolenaar449ac472019-04-03 21:42:35 +02001331 new
1332 call setline(1, 'empty')
1333 redraw
1334 set writedelay=10
1335 let start = reltime()
1336 call setline(1, repeat('x', 70))
1337 redraw
1338 let elapsed = reltimefloat(reltime(start))
1339 set writedelay=0
1340 " With 'writedelay' set should take at least 30 * 10 msec
1341 call assert_inrange(30 * 0.01, 999.0, elapsed)
1342
1343 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001344endfunc
1345
1346func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +02001347 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +02001348 set visualbell
1349 call assert_beeps('normal 0h')
1350 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +02001351 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +02001352endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001353
1354" Test for the 'write' option
1355func Test_write()
1356 new
1357 call setline(1, ['L1'])
1358 set nowrite
Bram Moolenaarb18b4962022-09-02 21:55:50 +01001359 call assert_fails('write Xwrfile', 'E142:')
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001360 set write
1361 close!
1362endfunc
1363
1364" Test for 'buftype' option
1365func Test_buftype()
1366 new
1367 call setline(1, ['L1'])
1368 set buftype=nowrite
1369 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001370
1371 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
1372 exe 'set buftype=' .. val
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001373 call writefile(['something'], 'XBuftype', 'D')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001374 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
1375 endfor
1376
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +01001377 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01001378endfunc
1379
Bram Moolenaar578fe942020-02-27 21:32:51 +01001380" Test for the 'rightleftcmd' option
1381func Test_rightleftcmd()
1382 CheckFeature rightleft
1383 set rightleft
Bram Moolenaar578fe942020-02-27 21:32:51 +01001384
1385 let g:l = []
1386 func AddPos()
1387 call add(g:l, screencol())
1388 return ''
1389 endfunc
1390 cmap <expr> <F2> AddPos()
1391
zeertzjqbb404f52022-07-23 06:25:29 +01001392 set rightleftcmd=
1393 call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
1394 \ "\<Right>\<F2>\<Esc>", 'xt')
1395 call assert_equal([2, 5, 3, 4], g:l)
1396
1397 let g:l = []
1398 set rightleftcmd=search
Bram Moolenaar578fe942020-02-27 21:32:51 +01001399 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
1400 \ "\<Left>\<F2>\<Esc>", 'xt')
1401 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
1402
1403 cunmap <F2>
1404 unlet g:l
1405 set rightleftcmd&
1406 set rightleft&
1407endfunc
1408
zeertzjq28c162f2022-08-14 14:49:50 +01001409" Test for the 'debug' option
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001410func Test_debug_option()
zeertzjq28c162f2022-08-14 14:49:50 +01001411 " redraw to avoid matching previous messages
1412 redraw
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001413 set debug=beep
1414 exe "normal \<C-c>"
1415 call assert_equal('Beep!', Screenline(&lines))
zeertzjq28c162f2022-08-14 14:49:50 +01001416 call assert_equal('line 4:', Screenline(&lines - 1))
zeertzjq30585e02023-03-06 08:10:04 +00001417 " also check a line above, with a certain window width the colon is there
1418 call assert_match('Test_debug_option:$',
1419 \ Screenline(&lines - 3) .. Screenline(&lines - 2))
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02001420 set debug&
1421endfunc
1422
Bram Moolenaar004a6782020-04-11 17:09:31 +02001423" Test for the default CDPATH option
1424func Test_opt_default_cdpath()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001425 let after =<< trim [CODE]
1426 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
1427 call writefile(v:errors, 'Xtestout')
1428 qall
1429 [CODE]
1430 if has('unix')
1431 let $CDPATH='/path/to/dir1:/path/to/dir2'
1432 else
1433 let $CDPATH='/path/to/dir1;/path/to/dir2'
1434 endif
1435 if RunVim([], after, '')
1436 call assert_equal([], readfile('Xtestout'))
1437 call delete('Xtestout')
1438 endif
1439endfunc
1440
1441" Test for setting keycodes using set
1442func Test_opt_set_keycode()
1443 call assert_fails('set <t_k1=l', 'E474:')
1444 call assert_fails('set <Home=l', 'E474:')
1445 set <t_k9>=abcd
1446 call assert_equal('abcd', &t_k9)
1447 set <t_k9>&
1448 set <F9>=xyz
1449 call assert_equal('xyz', &t_k9)
1450 set <t_k9>&
Bram Moolenaar84f54632022-06-29 18:39:11 +01001451
1452 " should we test all of them?
1453 set t_Ce=testCe
1454 set t_Cs=testCs
1455 set t_Us=testUs
1456 set t_ds=testds
1457 set t_Ds=testDs
1458 call assert_equal('testCe', &t_Ce)
1459 call assert_equal('testCs', &t_Cs)
1460 call assert_equal('testUs', &t_Us)
1461 call assert_equal('testds', &t_ds)
1462 call assert_equal('testDs', &t_Ds)
Bram Moolenaar004a6782020-04-11 17:09:31 +02001463endfunc
1464
1465" Test for changing options in a sandbox
1466func Test_opt_sandbox()
1467 for opt in ['backupdir', 'cdpath', 'exrc']
1468 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +02001469 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001470 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +02001471 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +02001472endfunc
1473
1474" Test for setting an option with local value to global value
1475func Test_opt_local_to_global()
1476 setglobal equalprg=gprg
1477 setlocal equalprg=lprg
1478 call assert_equal('gprg', &g:equalprg)
1479 call assert_equal('lprg', &l:equalprg)
1480 call assert_equal('lprg', &equalprg)
1481 set equalprg<
1482 call assert_equal('', &l:equalprg)
1483 call assert_equal('gprg', &equalprg)
1484 setglobal equalprg=gnewprg
1485 setlocal equalprg=lnewprg
1486 setlocal equalprg<
1487 call assert_equal('gnewprg', &l:equalprg)
1488 call assert_equal('gnewprg', &equalprg)
1489 set equalprg&
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001490
1491 " Test for setting the global/local value of a boolean option
1492 setglobal autoread
1493 setlocal noautoread
1494 call assert_false(&autoread)
1495 set autoread<
1496 call assert_true(&autoread)
1497 setglobal noautoread
1498 setlocal autoread
1499 setlocal autoread<
1500 call assert_false(&autoread)
1501 set autoread&
Bram Moolenaar004a6782020-04-11 17:09:31 +02001502endfunc
1503
Dominique Pelle042414f2021-07-12 21:43:19 +02001504func Test_set_in_sandbox()
1505 " Some boolean options cannot be set in sandbox, some can.
1506 call assert_fails('sandbox set modelineexpr', 'E48:')
1507 sandbox set number
1508 call assert_true(&number)
1509 set number&
1510
1511 " Some boolean options cannot be set in sandbox, some can.
1512 if has('python') || has('python3')
1513 call assert_fails('sandbox set pyxversion=3', 'E48:')
1514 endif
1515 sandbox set tabstop=4
1516 call assert_equal(4, &tabstop)
1517 set tabstop&
1518
1519 " Some string options cannot be set in sandbox, some can.
1520 call assert_fails('sandbox set backupdir=/tmp', 'E48:')
1521 sandbox set filetype=perl
1522 call assert_equal('perl', &filetype)
1523 set filetype&
1524endfunc
1525
Bram Moolenaar004a6782020-04-11 17:09:31 +02001526" Test for incrementing, decrementing and multiplying a number option value
1527func Test_opt_num_op()
1528 set shiftwidth=4
1529 set sw+=2
1530 call assert_equal(6, &sw)
1531 set sw-=2
1532 call assert_equal(4, &sw)
1533 set sw^=2
1534 call assert_equal(8, &sw)
1535 set shiftwidth&
1536endfunc
1537
Bram Moolenaar65d032c2020-04-24 20:57:01 +02001538" Test for setting option values using v:false and v:true
1539func Test_opt_boolean()
1540 set number&
1541 set number
1542 call assert_equal(1, &nu)
1543 set nonu
1544 call assert_equal(0, &nu)
1545 let &nu = v:true
1546 call assert_equal(1, &nu)
1547 let &nu = v:false
1548 call assert_equal(0, &nu)
1549 set number&
1550endfunc
1551
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02001552" Test for the 'window' option
1553func Test_window_opt()
1554 " Needs only one open widow
1555 %bw!
1556 call setline(1, range(1, 8))
1557 set window=5
1558 exe "normal \<C-F>"
1559 call assert_equal(4, line('w0'))
1560 exe "normal \<C-F>"
1561 call assert_equal(7, line('w0'))
1562 exe "normal \<C-F>"
1563 call assert_equal(8, line('w0'))
1564 exe "normal \<C-B>"
1565 call assert_equal(5, line('w0'))
1566 exe "normal \<C-B>"
1567 call assert_equal(2, line('w0'))
1568 exe "normal \<C-B>"
1569 call assert_equal(1, line('w0'))
1570 set window=1
1571 exe "normal gg\<C-F>"
1572 call assert_equal(2, line('w0'))
1573 exe "normal \<C-F>"
1574 call assert_equal(3, line('w0'))
1575 exe "normal \<C-B>"
1576 call assert_equal(2, line('w0'))
1577 exe "normal \<C-B>"
1578 call assert_equal(1, line('w0'))
1579 enew!
1580 set window&
1581endfunc
1582
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001583" Test for the 'winminheight' option
1584func Test_opt_winminheight()
1585 only!
1586 let &winheight = &lines + 4
1587 call assert_fails('let &winminheight = &lines + 2', 'E36:')
1588 call assert_true(&winminheight <= &lines)
1589 set winminheight&
1590 set winheight&
1591endfunc
1592
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001593func Test_opt_winminheight_term()
1594 CheckRunVimInTerminal
1595
1596 " The tabline should be taken into account.
1597 let lines =<< trim END
1598 set wmh=0 stal=2
1599 below sp | wincmd _
1600 below sp | wincmd _
1601 below sp | wincmd _
1602 below sp
1603 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001604 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001605 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1606 call term_sendkeys(buf, ":set wmh=1\n")
1607 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1608
1609 call StopVimInTerminal(buf)
Bram Moolenaar39d4cab2021-03-01 21:02:46 +01001610endfunc
1611
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001612func Test_opt_winminheight_term_tabs()
1613 CheckRunVimInTerminal
1614
1615 " The tabline should be taken into account.
1616 let lines =<< trim END
1617 set wmh=0 stal=2
1618 split
1619 split
1620 split
1621 split
1622 tabnew
1623 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001624 call writefile(lines, 'Xwinminheight', 'D')
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001625 let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
1626 call term_sendkeys(buf, ":set wmh=1\n")
1627 call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
1628
1629 call StopVimInTerminal(buf)
Bram Moolenaar9e813b32021-03-13 14:29:05 +01001630endfunc
1631
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +02001632" Test for the 'winminwidth' option
1633func Test_opt_winminwidth()
1634 only!
1635 let &winwidth = &columns + 4
1636 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
1637 call assert_true(&winminwidth <= &columns)
1638 set winminwidth&
1639 set winwidth&
1640endfunc
1641
Bram Moolenaar994b89d2020-08-07 19:12:41 +02001642" Test for setting option value containing spaces with isfname+=32
1643func Test_isfname_with_options()
1644 set isfname+=32
1645 setlocal keywordprg=:term\ help.exe
1646 call assert_equal(':term help.exe', &keywordprg)
1647 set isfname&
1648 setlocal keywordprg&
1649endfunc
1650
Bram Moolenaar74667062020-12-28 15:41:41 +01001651" Test that resetting laststatus does change scroll option
1652func Test_opt_reset_scroll()
1653 CheckRunVimInTerminal
1654 let vimrc =<< trim [CODE]
1655 set scroll=2
1656 set laststatus=2
1657 [CODE]
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001658 call writefile(vimrc, 'Xscroll', 'D')
Bram Moolenaar74667062020-12-28 15:41:41 +01001659 let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
1660 call term_sendkeys(buf, ":verbose set scroll?\n")
1661 call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
1662 call assert_match('^\s*scroll=7$', term_getline(buf, 14))
Bram Moolenaar74667062020-12-28 15:41:41 +01001663
1664 " clean up
Bram Moolenaar145d1fd2022-09-30 21:57:11 +01001665 call StopVimInTerminal(buf)
Bram Moolenaar74667062020-12-28 15:41:41 +01001666endfunc
1667
Dominique Pelle6d37e8e2021-05-06 17:36:55 +02001668" Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
1669func Test_VIM_POSIX()
1670 let saved_VIM_POSIX = getenv("VIM_POSIX")
1671
1672 call setenv('VIM_POSIX', "1")
1673 let after =<< trim [CODE]
1674 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1675 qall
1676 [CODE]
1677 if RunVim([], after, '')
1678 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
1679 \ 'AS'], readfile('X_VIM_POSIX'))
1680 endif
1681
1682 call setenv('VIM_POSIX', v:null)
1683 let after =<< trim [CODE]
1684 call writefile([&cpo, &shm], 'X_VIM_POSIX')
1685 qall
1686 [CODE]
1687 if RunVim([], after, '')
1688 call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
1689 \ 'S'], readfile('X_VIM_POSIX'))
1690 endif
1691
1692 call delete('X_VIM_POSIX')
1693 call setenv('VIM_POSIX', saved_VIM_POSIX)
1694endfunc
1695
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001696" Test for setting an option to a Vi or Vim default
1697func Test_opt_default()
1698 set formatoptions&vi
1699 call assert_equal('vt', &formatoptions)
1700 set formatoptions&vim
1701 call assert_equal('tcq', &formatoptions)
Bram Moolenaar5ffefbb2021-06-13 20:27:36 +02001702
1703 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1704 set fencs=latin1
1705 set fencs&
1706 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1707 set fencs=latin1
1708 set all&
1709 call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
Yegappan Lakshmanan59585492021-06-12 13:46:41 +02001710endfunc
1711
1712" Test for the 'cmdheight' option
1713func Test_cmdheight()
1714 %bw!
1715 let ht = &lines
1716 set cmdheight=9999
1717 call assert_equal(1, winheight(0))
1718 call assert_equal(ht - 1, &cmdheight)
1719 set cmdheight&
1720endfunc
1721
Dominique Pelle923dce22021-11-21 11:36:04 +00001722" To specify a control character as an option value, '^' can be used
Yegappan Lakshmanan2d6d7182021-06-13 21:52:48 +02001723func Test_opt_control_char()
1724 set wildchar=^v
1725 call assert_equal("\<C-V>", nr2char(&wildchar))
1726 set wildcharm=^r
1727 call assert_equal("\<C-R>", nr2char(&wildcharm))
1728 " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
1729 set wildchar& wildcharm&
1730endfunc
1731
1732" Test for the 'errorbells' option
1733func Test_opt_errorbells()
1734 set errorbells
1735 call assert_beeps('s/a1b2/x1y2/')
1736 set noerrorbells
1737endfunc
1738
Dominique Pelle042414f2021-07-12 21:43:19 +02001739func Test_opt_scrolljump()
1740 help
1741 resize 10
1742
1743 " Test with positive 'scrolljump'.
1744 set scrolljump=2
1745 norm! Lj
1746 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1747 \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
1748 \ winsaveview())
1749
1750 " Test with negative 'scrolljump' (percentage of window height).
1751 set scrolljump=-40
1752 norm! ggLj
1753 call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
1754 \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
1755 \ winsaveview())
1756
1757 set scrolljump&
1758 bw
1759endfunc
1760
Bakudankun29f3a452021-12-11 12:28:08 +00001761" Test for the 'cdhome' option
1762func Test_opt_cdhome()
1763 if has('unix') || has('vms')
1764 throw 'Skipped: only works on non-Unix'
1765 endif
1766
1767 set cdhome&
1768 call assert_equal(0, &cdhome)
1769 set cdhome
1770
1771 " This paragraph is copied from Test_cd_no_arg().
1772 let path = getcwd()
1773 cd
1774 call assert_equal($HOME, getcwd())
1775 call assert_notequal(path, getcwd())
1776 exe 'cd ' .. fnameescape(path)
1777 call assert_equal(path, getcwd())
1778
1779 set cdhome&
1780endfunc
1781
Yee Cheng Chin900894b2023-09-29 20:42:32 +02001782func Test_set_completion_fuzzy()
Christian Brabandtcb747892022-05-08 21:10:56 +01001783 CheckOption termguicolors
1784
1785 " Test default option completion
1786 set wildoptions=
1787 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1788 call assert_equal('"set termguicolors', @:)
1789
1790 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1791 call assert_equal('"set notermguicolors', @:)
1792
1793 " Test fuzzy option completion
1794 set wildoptions=fuzzy
1795 call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
1796 call assert_equal('"set termguicolors termencoding', @:)
1797
1798 call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
1799 call assert_equal('"set notermguicolors', @:)
1800
1801 set wildoptions=
1802endfunc
1803
Sean Dewar39c46b42022-05-12 17:44:29 +01001804func Test_switchbuf_reset()
1805 set switchbuf=useopen
1806 sblast
1807 call assert_equal(1, winnr('$'))
1808 set all&
1809 call assert_equal('', &switchbuf)
1810 sblast
1811 call assert_equal(2, winnr('$'))
1812 only!
1813endfunc
1814
zeertzjqfcba86c2022-09-22 13:57:32 +01001815" :set empty string for global 'keywordprg' falls back to ":help"
1816func Test_keywordprg_empty()
1817 let k = &keywordprg
1818 set keywordprg=man
1819 call assert_equal('man', &keywordprg)
1820 set keywordprg=
1821 call assert_equal(':help', &keywordprg)
1822 set keywordprg=man
1823 call assert_equal('man', &keywordprg)
1824 call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
1825 let &keywordprg = k
1826endfunc
1827
Bram Moolenaar0aad88f2022-11-12 11:54:26 +00001828" check that the very first buffer created does not have 'endoffile' set
1829func Test_endoffile_default()
1830 let after =<< trim [CODE]
1831 call writefile([execute('set eof?')], 'Xtestout')
1832 qall!
1833 [CODE]
1834 if RunVim([], after, '')
1835 call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
1836 endif
1837 call delete('Xtestout')
1838endfunc
1839
Yegappan Lakshmanan32ff96e2023-02-13 16:10:04 +00001840" Test for setting the 'lines' and 'columns' options to a minimum value
1841func Test_set_min_lines_columns()
1842 let save_lines = &lines
1843 let save_columns = &columns
1844
1845 let after =<< trim END
1846 set nomore
1847 let msg = []
1848 let v:errmsg = ''
1849 silent! let &columns=0
1850 call add(msg, v:errmsg)
1851 silent! set columns=0
1852 call add(msg, v:errmsg)
1853 silent! call setbufvar('', '&columns', 0)
1854 call add(msg, v:errmsg)
1855 "call writefile(msg, 'XResultsetminlines')
1856 silent! let &lines=0
1857 call add(msg, v:errmsg)
1858 silent! set lines=0
1859 call add(msg, v:errmsg)
1860 silent! call setbufvar('', '&lines', 0)
1861 call add(msg, v:errmsg)
1862 call writefile(msg, 'XResultsetminlines')
1863 qall!
1864 END
1865 if RunVim([], after, '')
1866 call assert_equal(['E594: Need at least 12 columns',
1867 \ 'E594: Need at least 12 columns: columns=0',
1868 \ 'E594: Need at least 12 columns',
1869 \ 'E593: Need at least 2 lines',
1870 \ 'E593: Need at least 2 lines: lines=0',
1871 \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
1872 endif
1873
1874 call delete('XResultsetminlines')
1875 let &lines = save_lines
1876 let &columns = save_columns
1877endfunc
zeertzjqfcba86c2022-09-22 13:57:32 +01001878
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001879" Test for reverting a string option value if the new value is invalid.
1880func Test_string_option_revert_on_failure()
1881 new
1882 let optlist = [
1883 \ ['ambiwidth', 'double', 'a123'],
1884 \ ['background', 'dark', 'a123'],
1885 \ ['backspace', 'eol', 'a123'],
1886 \ ['backupcopy', 'no', 'a123'],
1887 \ ['belloff', 'showmatch', 'a123'],
1888 \ ['breakindentopt', 'min:10', 'list'],
1889 \ ['bufhidden', 'wipe', 'a123'],
1890 \ ['buftype', 'nowrite', 'a123'],
1891 \ ['casemap', 'keepascii', 'a123'],
1892 \ ['cedit', "\<C-Y>", 'z'],
1893 \ ['colorcolumn', '10', 'z'],
1894 \ ['commentstring', '#%s', 'a123'],
1895 \ ['complete', '.,t', 'a'],
1896 \ ['completefunc', 'MyCmplFunc', '1a-'],
1897 \ ['completeopt', 'popup', 'a123'],
1898 \ ['completepopup', 'width:20', 'border'],
1899 \ ['concealcursor', 'v', 'xyz'],
1900 \ ['cpoptions', 'HJ', '~'],
1901 \ ['cryptmethod', 'zip', 'a123'],
1902 \ ['cursorlineopt', 'screenline', 'a123'],
1903 \ ['debug', 'throw', 'a123'],
1904 \ ['diffopt', 'iwhite', 'a123'],
1905 \ ['display', 'uhex', 'a123'],
1906 \ ['eadirection', 'hor', 'a123'],
1907 \ ['encoding', 'utf-8', 'a123'],
1908 \ ['eventignore', 'TextYankPost', 'a123'],
1909 \ ['fileencoding', 'utf-8', 'a123,'],
1910 \ ['fileformat', 'mac', 'a123'],
1911 \ ['fileformats', 'mac', 'a123'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001912 \ ['filetype', 'abc', 'a^b'],
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001913 \ ['fillchars', 'diff:~', 'a123'],
1914 \ ['foldclose', 'all', 'a123'],
1915 \ ['foldmarker', '[[[,]]]', '[[['],
1916 \ ['foldmethod', 'marker', 'a123'],
1917 \ ['foldopen', 'percent', 'a123'],
1918 \ ['formatoptions', 'an', '*'],
1919 \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
1920 \ ['helplang', 'en', 'a'],
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001921 \ ['highlight', '!:CursorColumn', '8:'],
1922 \ ['keymodel', 'stopsel', 'a123'],
1923 \ ['keyprotocol', 'kitty:kitty', 'kitty:'],
1924 \ ['lispoptions', 'expr:1', 'a123'],
1925 \ ['listchars', 'tab:->', 'tab:'],
1926 \ ['matchpairs', '<:>', '<:'],
1927 \ ['mkspellmem', '100000,1000,100', '100000'],
1928 \ ['mouse', 'nvi', 'z'],
1929 \ ['mousemodel', 'extend', 'a123'],
1930 \ ['nrformats', 'alpha', 'a123'],
1931 \ ['omnifunc', 'MyOmniFunc', '1a-'],
1932 \ ['operatorfunc', 'MyOpFunc', '1a-'],
1933 \ ['previewpopup', 'width:20', 'a123'],
1934 \ ['printoptions', 'paper:A4', 'a123:'],
1935 \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
1936 \ ['rulerformat', '%l', '%['],
1937 \ ['scrollopt', 'hor,jump', 'a123'],
1938 \ ['selection', 'exclusive', 'a123'],
1939 \ ['selectmode', 'cmd', 'a123'],
1940 \ ['sessionoptions', 'options', 'a123'],
1941 \ ['shortmess', 'w', '2'],
1942 \ ['showbreak', '>>', "\x01"],
1943 \ ['showcmdloc', 'statusline', 'a123'],
1944 \ ['signcolumn', 'no', 'a123'],
1945 \ ['spellcapcheck', '[.?!]\+', '%\{'],
1946 \ ['spellfile', 'MySpell.en.add', "\x01"],
1947 \ ['spelllang', 'en', "#"],
1948 \ ['spelloptions', 'camel', 'a123'],
1949 \ ['spellsuggest', 'double', 'a123'],
1950 \ ['splitkeep', 'topline', 'a123'],
1951 \ ['statusline', '%f', '%['],
1952 \ ['swapsync', 'sync', 'a123'],
1953 \ ['switchbuf', 'usetab', 'a123'],
1954 \ ['syntax', 'abc', 'a^b'],
1955 \ ['tabline', '%f', '%['],
1956 \ ['tagcase', 'ignore', 'a123'],
1957 \ ['tagfunc', 'MyTagFunc', '1a-'],
1958 \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
1959 \ ['viewoptions', 'options', 'a123'],
1960 \ ['virtualedit', 'onemore', 'a123'],
1961 \ ['whichwrap', '<,>', '{,}'],
1962 \ ['wildmode', 'list', 'a123'],
1963 \ ['wildoptions', 'pum', 'a123']
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00001964 \ ]
1965 if has('gui')
1966 call add(optlist, ['browsedir', 'buffer', 'a123'])
1967 endif
1968 if has('clipboard_working')
1969 call add(optlist, ['clipboard', 'unnamed', 'a123'])
1970 endif
1971 if has('win32')
1972 call add(optlist, ['completeslash', 'slash', 'a123'])
1973 endif
1974 if has('cscope')
1975 call add(optlist, ['cscopequickfix', 't-', 'z-'])
1976 endif
1977 if !has('win32')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00001978 call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
1979 call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
1980 endif
1981 if has('keymap')
1982 call add(optlist, ['keymap', 'greek', '[]'])
1983 endif
1984 if has('mouseshape')
1985 call add(optlist, ['mouseshape', 'm:no', 'a123:'])
1986 endif
1987 if has('win32') && has('gui')
1988 call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
1989 endif
1990 if has('rightleft')
1991 call add(optlist, ['rightleftcmd', 'search', 'a123'])
1992 endif
1993 if has('terminal')
1994 call add(optlist, ['termwinkey', '<C-L>', '<C'])
1995 call add(optlist, ['termwinsize', '24x80', '100'])
1996 endif
1997 if has('win32') && has('terminal')
1998 call add(optlist, ['termwintype', 'winpty', 'a123'])
1999 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002000 if exists('+toolbar')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002001 call add(optlist, ['toolbar', 'text', 'a123'])
James McCoydb1887c2023-03-02 18:36:33 +00002002 endif
2003 if exists('+toolbariconsize')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002004 call add(optlist, ['toolbariconsize', 'medium', 'a123'])
2005 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002006 if exists('+ttymouse') && !has('gui')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002007 call add(optlist, ['ttymouse', 'xterm', 'a123'])
2008 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002009 if exists('+vartabs')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002010 call add(optlist, ['varsofttabstop', '12', 'a123'])
2011 call add(optlist, ['vartabstop', '4,20', '4,'])
2012 endif
Yegappan Lakshmananc6ff21e2023-03-02 14:46:48 +00002013 if exists('+winaltkeys')
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002014 call add(optlist, ['winaltkeys', 'no', 'a123'])
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002015 endif
2016 for opt in optlist
2017 exe $"let save_opt = &{opt[0]}"
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00002018 try
2019 exe $"let &{opt[0]} = '{opt[1]}'"
2020 catch
2021 call assert_report($"Caught {v:exception} with {opt->string()}")
2022 endtry
Yegappan Lakshmanan8ad862a2023-02-23 15:05:22 +00002023 call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
2024 call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
2025 exe $"let &{opt[0]} = save_opt"
2026 endfor
2027 bw!
2028endfunc
2029
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +02002030func Test_set_option_window_global_local()
2031 new Xbuffer1
2032 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
2033 setlocal scrolloff=2
2034 setglobal scrolloff=3
2035 setl modified
2036 " A new buffer has its own window-local options
2037 hide enew
2038 call assert_equal(-1, &l:scrolloff)
2039 call assert_equal(3, &g:scrolloff)
2040 " A new window opened with its own buffer-local options
2041 new
2042 call assert_equal(-1, &l:scrolloff)
2043 call assert_equal(3, &g:scrolloff)
2044 " Re-open Xbuffer1 and it should use
2045 " the previous set window-local options
2046 b Xbuffer1
2047 call assert_equal(2, &l:scrolloff)
2048 call assert_equal(3, &g:scrolloff)
2049 bw!
2050 bw!
2051 let &g:scrolloff = _gso
2052endfunc
2053
2054func GetGlobalLocalWindowOptions()
2055 new
2056 sil! r $VIMRUNTIME/doc/options.txt
2057 " Filter for global or local to window
2058 v/^'.*'.*\n.*global or local to window |global-local/d
2059 " get option value and type
2060 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
2061 sil %s/empty/""/g
2062 " split the result
2063 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
2064 bw!
2065 return result
2066endfunc
2067
2068func Test_set_option_window_global_local_all()
2069 new Xbuffer2
2070
2071 let optionlist = GetGlobalLocalWindowOptions()
2072 for [opt, type, default] in optionlist
2073 let _old = eval('&g:' .. opt)
2074 if type == 'string'
2075 if opt == 'fillchars'
2076 exe 'setl ' .. opt .. '=vert:+'
2077 exe 'setg ' .. opt .. '=vert:+,fold:+'
2078 elseif opt == 'listchars'
2079 exe 'setl ' .. opt .. '=tab:>>'
2080 exe 'setg ' .. opt .. '=tab:++'
2081 elseif opt == 'virtualedit'
2082 exe 'setl ' .. opt .. '=all'
2083 exe 'setg ' .. opt .. '=block'
2084 else
2085 exe 'setl ' .. opt .. '=Local'
2086 exe 'setg ' .. opt .. '=Global'
2087 endif
2088 elseif type == 'number'
2089 exe 'setl ' .. opt .. '=5'
2090 exe 'setg ' .. opt .. '=10'
2091 endif
2092 setl modified
2093 hide enew
2094 if type == 'string'
2095 call assert_equal('', eval('&l:' .. opt))
2096 if opt == 'fillchars'
2097 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
2098 elseif opt == 'listchars'
2099 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
2100 elseif opt == 'virtualedit'
2101 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
2102 else
2103 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
2104 endif
2105 elseif type == 'number'
2106 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
2107 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
2108 endif
2109 bw!
2110 exe 'let &g:' .. opt .. '=' .. default
2111 endfor
2112 bw!
2113endfunc
2114
Christian Brabandt757593c2023-08-22 21:44:10 +02002115func Test_paste_depending_options()
2116 " setting the paste option, resets all dependent options
2117 " and will be reported correctly using :verbose set <option>?
2118 let lines =<< trim [CODE]
2119 " set paste test
2120 set autoindent
2121 set expandtab
2122 " disabled, because depends on compiled feature set
2123 " set hkmap
2124 " set revins
2125 " set varsofttabstop=8,32,8
2126 set ruler
2127 set showmatch
2128 set smarttab
2129 set softtabstop=4
2130 set textwidth=80
2131 set wrapmargin=10
2132
2133 source Xvimrc_paste2
2134
2135 redir > Xoutput_paste
2136 verbose set expandtab?
2137 verbose setg expandtab?
2138 verbose setl expandtab?
2139 redir END
2140
2141 qall!
2142 [CODE]
2143
2144 call writefile(lines, 'Xvimrc_paste', 'D')
2145 call writefile(['set paste'], 'Xvimrc_paste2', 'D')
2146 if !RunVim([], lines, '--clean')
2147 return
2148 endif
2149
2150 let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
2151 call assert_equal('noexpandtab', result[0])
2152 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
2153 call assert_equal('noexpandtab', result[2])
2154 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
2155 call assert_equal('noexpandtab', result[4])
2156 call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
2157
2158 call delete('Xoutput_paste')
2159endfunc
2160
2161func Test_binary_depending_options()
2162 " setting the paste option, resets all dependent options
2163 " and will be reported correctly using :verbose set <option>?
2164 let lines =<< trim [CODE]
2165 " set binary test
2166 set expandtab
2167
2168 source Xvimrc_bin2
2169
2170 redir > Xoutput_bin
2171 verbose set expandtab?
2172 verbose setg expandtab?
2173 verbose setl expandtab?
2174 redir END
2175
2176 qall!
2177 [CODE]
2178
2179 call writefile(lines, 'Xvimrc_bin', 'D')
2180 call writefile(['set binary'], 'Xvimrc_bin2', 'D')
2181 if !RunVim([], lines, '--clean')
2182 return
2183 endif
2184
2185 let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
2186 call assert_equal('noexpandtab', result[0])
2187 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
2188 call assert_equal('noexpandtab', result[2])
2189 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
2190 call assert_equal('noexpandtab', result[4])
2191 call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
2192
2193 call delete('Xoutput_bin')
2194endfunc
2195
Gregory Anders3695d0e2023-09-29 20:17:20 +02002196func Test_set_keyprotocol()
2197 CheckNotGui
2198
2199 let term = &term
2200 set term=ansi
2201 call assert_equal('', &t_TI)
2202
2203 " Setting 'keyprotocol' should affect terminal codes without needing to
2204 " reset 'term'
2205 set keyprotocol+=ansi:kitty
2206 call assert_equal("\<Esc>[=1;1u", &t_TI)
2207 let &term = term
2208endfunc
2209
Luuk van Baal1bf1bf52023-10-28 21:43:31 +02002210func Test_set_wrap()
2211 " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
2212 " cursor position.
2213 set wrap smoothscroll scrolloff=5
2214
2215 call setline(1, ['', 'aaaa'->repeat(500)])
2216 20 split
2217 20 vsplit
2218 norm 2G$
2219 redraw
2220 set nowrap
2221 call assert_equal(2, winline())
2222
2223 set wrap& smoothscroll& scrolloff&
2224endfunc
2225
Bram Moolenaar5d98dc22020-01-29 21:57:34 +01002226" vim: shiftwidth=2 sts=2 expandtab