blob: 8f27d9c4acdae9bc90ce511a81604cbc18641f76 [file] [log] [blame]
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02001" Test for options
2
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
Bram Moolenaarcde0ff32020-04-04 14:00:39 +02004source view_util.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02005
Bram Moolenaar1e115362019-01-09 23:01:02 +01006func Test_whichwrap()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02007 set whichwrap=b,s
8 call assert_equal('b,s', &whichwrap)
9
10 set whichwrap+=h,l
11 call assert_equal('b,s,h,l', &whichwrap)
12
13 set whichwrap+=h,l
14 call assert_equal('b,s,h,l', &whichwrap)
15
16 set whichwrap+=h,l
17 call assert_equal('b,s,h,l', &whichwrap)
18
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +010019 set whichwrap=h,h
20 call assert_equal('h', &whichwrap)
21
22 set whichwrap=h,h,h
23 call assert_equal('h', &whichwrap)
24
Bram Moolenaar004a6782020-04-11 17:09:31 +020025 " For compatibility with Vim 3.0 and before, number values are also
26 " supported for 'whichwrap'
27 set whichwrap=1
28 call assert_equal('b', &whichwrap)
29 set whichwrap=2
30 call assert_equal('s', &whichwrap)
31 set whichwrap=4
32 call assert_equal('h,l', &whichwrap)
33 set whichwrap=8
34 call assert_equal('<,>', &whichwrap)
35 set whichwrap=16
36 call assert_equal('[,]', &whichwrap)
37 set whichwrap=31
38 call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
39
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020040 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010041endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020042
Bram Moolenaar1e115362019-01-09 23:01:02 +010043func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010044 " This used to cause Vim to access uninitialized memory.
45 set isfname=
46 call assert_equal("~X", expand("~X"))
47 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010048endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010049
Bram Moolenaar1e115362019-01-09 23:01:02 +010050func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010051 " Empty 'wildchar' used to access invalid memory.
52 call assert_fails('set wildchar=', 'E521:')
53 call assert_fails('set wildchar=abc', 'E521:')
54 set wildchar=<Esc>
55 let a=execute('set wildchar?')
56 call assert_equal("\n wildchar=<Esc>", a)
57 set wildchar=27
58 let a=execute('set wildchar?')
59 call assert_equal("\n wildchar=<Esc>", a)
60 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010062
Bram Moolenaar2e61e2d2020-05-22 14:10:36 +020063func Test_wildoptions()
64 set wildoptions=
65 set wildoptions+=tagfile
66 set wildoptions+=tagfile
67 call assert_equal('tagfile', &wildoptions)
68endfunc
69
Bram Moolenaar6b915c02020-01-18 15:53:19 +010070func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020071 let caught = 'ok'
72 try
73 options
74 catch
75 let caught = v:throwpoint . "\n" . v:exception
76 endtry
77 call assert_equal('ok', caught)
78
Bram Moolenaare0b59492019-05-21 20:54:45 +020079 " Check if the option-window is opened horizontally.
80 wincmd j
81 call assert_notequal('option-window', bufname(''))
82 wincmd k
83 call assert_equal('option-window', bufname(''))
84 " close option-window
85 close
86
87 " Open the option-window vertically.
88 vert options
89 " Check if the option-window is opened vertically.
90 wincmd l
91 call assert_notequal('option-window', bufname(''))
92 wincmd h
93 call assert_equal('option-window', bufname(''))
94 " close option-window
95 close
96
Bram Moolenaar7a1637f2020-04-13 21:16:21 +020097 " Open the option-window at the top.
98 set splitbelow
99 topleft options
100 call assert_equal(1, winnr())
101 close
102
103 " Open the option-window at the bottom.
104 set nosplitbelow
105 botright options
106 call assert_equal(winnr('$'), winnr())
107 close
108 set splitbelow&
109
Bram Moolenaare0b59492019-05-21 20:54:45 +0200110 " Open the option-window in a new tab.
111 tab options
112 " Check if the option-window is opened in a tab.
113 normal gT
114 call assert_notequal('option-window', bufname(''))
115 normal gt
116 call assert_equal('option-window', bufname(''))
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200117 " close option-window
118 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200119
120 " Open the options window browse
121 if has('browse')
122 browse set
123 call assert_equal('option-window', bufname(''))
124 close
125 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100126endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200127
Bram Moolenaar1e115362019-01-09 23:01:02 +0100128func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200129 " Test that changing 'path' keeps two commas.
130 set path=foo,,bar
131 set path-=bar
132 set path+=bar
133 call assert_equal('foo,,bar', &path)
134
135 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100136endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200137
138func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +0200139 if has('signs')
140 call assert_equal("auto", &signcolumn)
141 set signcolumn=yes
142 set signcolumn=no
143 call assert_fails('set signcolumn=nope')
144 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200145endfunc
146
Bram Moolenaard0b51382016-11-04 15:23:45 +0100147func Test_filetype_valid()
148 set ft=valid_name
149 call assert_equal("valid_name", &filetype)
150 set ft=valid-name
151 call assert_equal("valid-name", &filetype)
152
153 call assert_fails(":set ft=wrong;name", "E474:")
154 call assert_fails(":set ft=wrong\\\\name", "E474:")
155 call assert_fails(":set ft=wrong\\|name", "E474:")
156 call assert_fails(":set ft=wrong/name", "E474:")
157 call assert_fails(":set ft=wrong\\\nname", "E474:")
158 call assert_equal("valid-name", &filetype)
159
160 exe "set ft=trunc\x00name"
161 call assert_equal("trunc", &filetype)
162endfunc
163
164func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100165 if !has('syntax')
166 return
167 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100168 set syn=valid_name
169 call assert_equal("valid_name", &syntax)
170 set syn=valid-name
171 call assert_equal("valid-name", &syntax)
172
173 call assert_fails(":set syn=wrong;name", "E474:")
174 call assert_fails(":set syn=wrong\\\\name", "E474:")
175 call assert_fails(":set syn=wrong\\|name", "E474:")
176 call assert_fails(":set syn=wrong/name", "E474:")
177 call assert_fails(":set syn=wrong\\\nname", "E474:")
178 call assert_equal("valid-name", &syntax)
179
180 exe "set syn=trunc\x00name"
181 call assert_equal("trunc", &syntax)
182endfunc
183
184func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100185 if !has('keymap')
186 return
187 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100188 call assert_fails(":set kmp=valid_name", "E544:")
189 call assert_fails(":set kmp=valid_name", "valid_name")
190 call assert_fails(":set kmp=valid-name", "E544:")
191 call assert_fails(":set kmp=valid-name", "valid-name")
192
193 call assert_fails(":set kmp=wrong;name", "E474:")
194 call assert_fails(":set kmp=wrong\\\\name", "E474:")
195 call assert_fails(":set kmp=wrong\\|name", "E474:")
196 call assert_fails(":set kmp=wrong/name", "E474:")
197 call assert_fails(":set kmp=wrong\\\nname", "E474:")
198
199 call assert_fails(":set kmp=trunc\x00name", "E544:")
200 call assert_fails(":set kmp=trunc\x00name", "trunc")
201endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100202
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100203func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100204 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100205 exe 'set ' . a:name . '=/usr/share/dict/words'
206 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
207 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
208 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
209 exe 'set ' . a:name . '=/usr/share/dict\ words'
210 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100211
212 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100213 call assert_fails("set " . a:name . "=/not&there", "E474:")
214 call assert_fails("set " . a:name . "=/not>there", "E474:")
215 call assert_fails("set " . a:name . "=/not.*there", "E474:")
216endfunc
217
Bram Moolenaar60629d62017-02-23 18:08:56 +0100218func Test_cinkeys()
219 " This used to cause invalid memory access
220 set cindent cinkeys=0
221 norm a
222 set cindent& cinkeys&
223endfunc
224
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100225func Test_dictionary()
226 call Check_dir_option('dictionary')
227endfunc
228
229func Test_thesaurus()
230 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100231endfun
232
Bram Moolenaar226c5342017-02-17 14:53:15 +0100233func Test_complete()
234 " Trailing single backslash used to cause invalid memory access.
235 set complete=s\
236 new
237 call feedkeys("i\<C-N>\<Esc>", 'xt')
238 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200239 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100240 set complete&
241endfun
242
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100243func Test_set_completion()
244 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
245 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
246
Bram Moolenaar297610b2019-12-27 17:20:55 +0100247 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
248 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
249
250 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
251 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
252
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100253 " Expand boolan options. When doing :set no<Tab>
254 " vim displays the options names without "no" but completion uses "no...".
255 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
256 call assert_equal('"set nodiff digraph', @:)
257
258 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
259 call assert_equal('"set invdiff digraph', @:)
260
261 " Expand abbreviation of options.
262 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
263 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
264
265 " Expand current value
266 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
267 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
268
269 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
270 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
271
272 " Expand key codes.
273 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
274 call assert_equal('"set <Help> <Home>', @:)
275
276 " Expand terminal options.
277 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaare023e882020-05-31 16:42:30 +0200278 call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
Bram Moolenaar0ff5ded2020-05-07 18:43:44 +0200279 call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100280
281 " Expand directories.
282 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
283 call assert_match(' ./samples/ ', @:)
284 call assert_notmatch(' ./small.vim ', @:)
285
286 " Expand files and directories.
287 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
288 call assert_match(' ./samples/.* ./small.vim', @:)
289
290 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
291 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200292 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200293
294 " Expanding the option names
295 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
296 call assert_equal('"set all', @:)
297
298 " Expanding a second set of option names
299 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
300 call assert_equal('"set wrapscan all', @:)
301
302 " Expanding a special keycode
303 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
304 call assert_equal('"set <Home>', @:)
305
306 " Expanding an invalid special keycode
307 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
308 call assert_equal("\"set <abcd>\<Tab>", @:)
309
310 " Expanding a terminal keycode
311 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
312 call assert_equal("\"set t_AB", @:)
313
314 " Expanding an invalid option name
315 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
316 call assert_equal("\"set abcde=\<Tab>", @:)
317
318 " Expanding after a = for a boolean option
319 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
320 call assert_equal("\"set wrapscan=\<Tab>", @:)
321
322 " Expanding a numeric option
323 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
324 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
325
326 " Expanding a non-boolean option
327 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
328 call assert_equal("\"set invtabstop=", @:)
329
330 " Expand options for 'spellsuggest'
331 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
332 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
333
334 " Expand value for 'key'
335 set key=abcd
336 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
337 call assert_equal('"set key=*****', @:)
338 set key=
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100339endfunc
340
341func Test_set_errors()
342 call assert_fails('set scroll=-1', 'E49:')
343 call assert_fails('set backupcopy=', 'E474:')
344 call assert_fails('set regexpengine=3', 'E474:')
345 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200346 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100347 call assert_fails('set colorcolumn=-a', 'E474:')
348 call assert_fails('set colorcolumn=a', 'E474:')
349 call assert_fails('set colorcolumn=1,', 'E474:')
350 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100351 call assert_fails('set cmdheight=-1', 'E487:')
352 call assert_fails('set cmdwinheight=-1', 'E487:')
353 if has('conceal')
354 call assert_fails('set conceallevel=-1', 'E487:')
355 call assert_fails('set conceallevel=4', 'E474:')
356 endif
357 call assert_fails('set helpheight=-1', 'E487:')
358 call assert_fails('set history=-1', 'E487:')
359 call assert_fails('set report=-1', 'E487:')
360 call assert_fails('set shiftwidth=-1', 'E487:')
361 call assert_fails('set sidescroll=-1', 'E487:')
362 call assert_fails('set tabstop=-1', 'E487:')
363 call assert_fails('set textwidth=-1', 'E487:')
364 call assert_fails('set timeoutlen=-1', 'E487:')
365 call assert_fails('set updatecount=-1', 'E487:')
366 call assert_fails('set updatetime=-1', 'E487:')
367 call assert_fails('set winheight=-1', 'E487:')
368 call assert_fails('set tabstop!', 'E488:')
369 call assert_fails('set xxx', 'E518:')
370 call assert_fails('set beautify?', 'E519:')
371 call assert_fails('set undolevels=x', 'E521:')
372 call assert_fails('set tabstop=', 'E521:')
373 call assert_fails('set comments=-', 'E524:')
374 call assert_fails('set comments=a', 'E525:')
375 call assert_fails('set foldmarker=x', 'E536:')
376 call assert_fails('set commentstring=x', 'E537:')
377 call assert_fails('set complete=x', 'E539:')
378 call assert_fails('set statusline=%{', 'E540:')
379 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
380 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100381 if has('cursorshape')
382 " This invalid value for 'guicursor' used to cause Vim to crash.
383 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
384 call assert_fails('set guicursor=i-ci', 'E545:')
385 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100386 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100387 call assert_fails('set guicursor=r-cr:horx', 'E548:')
388 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
389 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100390 if has('mouseshape')
391 call assert_fails('se mouseshape=i-r:x', 'E547:')
392 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100393 call assert_fails('set backupext=~ patchmode=~', 'E589:')
394 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200395 set winminheight& winheight&
396 set winheight=10 winminheight=10
397 call assert_fails('set winheight=9', 'E591:')
398 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100399 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200400 set winminwidth& winwidth&
401 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
402 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100403 call assert_fails("set showbreak=\x01", 'E595:')
404 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200405 call assert_fails('set tabstop??', 'E488:')
406 call assert_fails('set wrapscan!!', 'E488:')
407 call assert_fails('set tabstop&&', 'E488:')
408 call assert_fails('set wrapscan<<', 'E488:')
409 call assert_fails('set wrapscan=1', 'E474:')
410 call assert_fails('set autoindent@', 'E488:')
411 call assert_fails('set wildchar=<abc>', 'E474:')
412 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200413 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200414 if has('python') && has('python3')
415 call assert_fails('set pyxversion=6', 'E474:')
416 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200417 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100418endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100419
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200420func CheckWasSet(name)
421 let verb_cm = execute('verbose set ' .. a:name .. '?')
422 call assert_match('Last set from.*test_options.vim', verb_cm)
423endfunc
424func CheckWasNotSet(name)
425 let verb_cm = execute('verbose set ' .. a:name .. '?')
426 call assert_notmatch('Last set from', verb_cm)
427endfunc
428
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200429" Must be executed before other tests that set 'term'.
430func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200431 CheckNotGui
432
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200433 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200434
435 let term_save = &term
436 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200437 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200438 let &term = term_save
439endfunc
440
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200441func Test_copy_context()
442 setlocal list
443 call CheckWasSet('list')
444 split
445 call CheckWasSet('list')
446 quit
447 setlocal nolist
448
449 set ai
450 call CheckWasSet('ai')
451 set filetype=perl
452 call CheckWasSet('filetype')
453 set fo=tcroq
454 call CheckWasSet('fo')
455
456 split Xsomebuf
457 call CheckWasSet('ai')
458 call CheckWasNotSet('filetype')
459 call CheckWasSet('fo')
460endfunc
461
Bram Moolenaar67391142017-02-19 21:07:04 +0100462func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200463 CheckUnix
464 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200465
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200466 " Setting 'ttytype' used to cause a double-free when exiting vim and
467 " when vim is compiled with -DEXITFREE.
468 set ttytype=ansi
469 call assert_equal('ansi', &ttytype)
470 call assert_equal(&ttytype, &term)
471 set ttytype=xterm
472 call assert_equal('xterm', &ttytype)
473 call assert_equal(&ttytype, &term)
474 " "set ttytype=" gives E522 instead of E529
475 " in travis on some builds. Why? Catch both for now
476 try
477 set ttytype=
478 call assert_report('set ttytype= did not fail')
479 catch /E529\|E522/
480 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200481
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200482 " Some systems accept any terminal name and return dumb settings,
483 " check for failure of finding the entry and for missing 'cm' entry.
484 try
485 set ttytype=xxx
486 call assert_report('set ttytype=xxx did not fail')
487 catch /E522\|E437/
488 endtry
489
490 set ttytype&
491 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200492
493 if has('gui') && !has('gui_running')
494 call assert_fails('set term=gui', 'E531:')
495 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100496endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100497
498func Test_set_all()
499 set tw=75
500 set iskeyword=a-z,A-Z
501 set nosplitbelow
502 let out = execute('set all')
503 call assert_match('textwidth=75', out)
504 call assert_match('iskeyword=a-z,A-Z', out)
505 call assert_match('nosplitbelow', out)
506 set tw& iskeyword& splitbelow&
507endfunc
508
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100509func Test_set_one_column()
510 let out_mult = execute('set all')->split("\n")
511 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100512 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100513endfunc
514
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100515func Test_set_values()
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200516 " opt_test.vim is generated from ../optiondefs.h using gen_opt_test.vim
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100517 if filereadable('opt_test.vim')
518 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100519 else
520 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100521 endif
522endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200523
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100524func Test_renderoptions()
525 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
526 " Doesn't hurt to do this on a non-Windows system.
527 if windowsversion() !~ '^[345]\.'
528 set renderoptions=type:directx
529 set rop=type:directx
530 endif
531endfunc
532
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200533func ResetIndentexpr()
534 set indentexpr=
535endfunc
536
537func Test_set_indentexpr()
538 " this was causing usage of freed memory
539 set indentexpr=ResetIndentexpr()
540 new
541 call feedkeys("i\<c-f>", 'x')
542 call assert_equal('', &indentexpr)
543 bwipe!
544endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200545
546func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100547 " Option 'backupskip' may contain several comma-separated path
548 " specifications if one or more of the environment variables TMPDIR, TMP,
549 " or TEMP is defined. To simplify testing, convert the string value into a
550 " list.
551 let bsklist = split(&bsk, ',')
552
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200553 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100554 let found = (index(bsklist, '/private/tmp/*') >= 0)
555 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200556 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100557 let found = (index(bsklist, '/tmp/*') >= 0)
558 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200559 endif
560
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100561 " If our test platform is Windows, the path(s) in option bsk will use
562 " backslash for the path separator and the components could be in short
563 " (8.3) format. As such, we need to replace the backslashes with forward
564 " slashes and convert the path components to long format. The expand()
565 " function will do this but it cannot handle comma-separated paths. This is
566 " why bsk was converted from a string into a list of strings above.
567 "
568 " One final complication is that the wildcard "/*" is at the end of each
569 " path and so expand() might return a list of matching files. To prevent
570 " this, we need to remove the wildcard before calling expand() and then
571 " append it afterwards.
572 if has('win32')
573 let item_nbr = 0
574 while item_nbr < len(bsklist)
575 let path_spec = bsklist[item_nbr]
576 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
577 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
578 let bsklist[item_nbr] = path_spec . '/*'
579 let item_nbr += 1
580 endwhile
581 endif
582
583 " Option bsk will also include these environment variables if defined.
584 " If they're defined, verify they appear in the option value.
585 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200586 if exists(var)
587 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100588 let varvalue = substitute(varvalue, '/$', '', '')
589 let varvalue .= '/*'
590 let found = (index(bsklist, varvalue) >= 0)
591 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200592 endif
593 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200594
595 " Duplicates should be filtered out (option has P_NODUP)
596 let backupskip = &backupskip
597 set backupskip=
598 set backupskip+=/test/dir
599 set backupskip+=/other/dir
600 set backupskip+=/test/dir
601 call assert_equal('/test/dir,/other/dir', &backupskip)
602 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200603endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200604
605func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200606 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200607
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200608 " Test copy option from current buffer in window
609 split
610 enew
611 setlocal numberwidth=5
612 wincmd w
613 call assert_equal(4,&numberwidth)
614 bnext
615 call assert_equal(5,&numberwidth)
616 bw!
617 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200618
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200619 " Test copy value from window that used to be display the buffer
620 split
621 enew
622 setlocal numberwidth=6
623 bnext
624 wincmd w
625 call assert_equal(4,&numberwidth)
626 bnext
627 call assert_equal(6,&numberwidth)
628 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200629
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200630 " Test that if buffer is current, don't use the stale cached value
631 " from the last time the buffer was displayed.
632 split
633 enew
634 setlocal numberwidth=7
635 bnext
636 bnext
637 setlocal numberwidth=8
638 wincmd w
639 call assert_equal(4,&numberwidth)
640 bnext
641 call assert_equal(8,&numberwidth)
642 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200643
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200644 " Test value is not copied if window already has seen the buffer
645 enew
646 split
647 setlocal numberwidth=9
648 bnext
649 setlocal numberwidth=10
650 wincmd w
651 call assert_equal(4,&numberwidth)
652 bnext
653 call assert_equal(4,&numberwidth)
654 bw!
655
656 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200657endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200658
659func Test_shortmess_F()
660 new
661 call assert_match('\[No Name\]', execute('file'))
662 set shortmess+=F
663 call assert_match('\[No Name\]', execute('file'))
664 call assert_match('^\s*$', execute('file foo'))
665 call assert_match('foo', execute('file'))
666 set shortmess-=F
667 call assert_match('bar', execute('file bar'))
668 call assert_match('bar', execute('file'))
669 set shortmess&
670 bwipe
671endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200672
673func Test_shortmess_F2()
674 e file1
675 e file2
676 call assert_match('file1', execute('bn', ''))
677 call assert_match('file2', execute('bn', ''))
678 set shortmess+=F
679 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200680 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200681 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200682 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200683 set hidden
684 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200685 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200686 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200687 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200688 set nohidden
689 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200690 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200691 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200692 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200693 set shortmess&
694 call assert_match('file1', execute('bn', ''))
695 call assert_match('file2', execute('bn', ''))
696 bwipe
697 bwipe
698endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100699
700func Test_local_scrolloff()
701 set so=5
702 set siso=7
703 split
704 call assert_equal(5, &so)
705 setlocal so=3
706 call assert_equal(3, &so)
707 wincmd w
708 call assert_equal(5, &so)
709 wincmd w
710 setlocal so<
711 call assert_equal(5, &so)
712 setlocal so=0
713 call assert_equal(0, &so)
714 setlocal so=-1
715 call assert_equal(5, &so)
716
717 call assert_equal(7, &siso)
718 setlocal siso=3
719 call assert_equal(3, &siso)
720 wincmd w
721 call assert_equal(7, &siso)
722 wincmd w
723 setlocal siso<
724 call assert_equal(7, &siso)
725 setlocal siso=0
726 call assert_equal(0, &siso)
727 setlocal siso=-1
728 call assert_equal(7, &siso)
729
730 close
731 set so&
732 set siso&
733endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200734
735func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100736 CheckFunction reltimefloat
737
Bram Moolenaar449ac472019-04-03 21:42:35 +0200738 new
739 call setline(1, 'empty')
740 redraw
741 set writedelay=10
742 let start = reltime()
743 call setline(1, repeat('x', 70))
744 redraw
745 let elapsed = reltimefloat(reltime(start))
746 set writedelay=0
747 " With 'writedelay' set should take at least 30 * 10 msec
748 call assert_inrange(30 * 0.01, 999.0, elapsed)
749
750 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200751endfunc
752
753func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200754 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200755 set visualbell
756 call assert_beeps('normal 0h')
757 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200758 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200759endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100760
761" Test for the 'write' option
762func Test_write()
763 new
764 call setline(1, ['L1'])
765 set nowrite
766 call assert_fails('write Xfile', 'E142:')
767 set write
768 close!
769endfunc
770
771" Test for 'buftype' option
772func Test_buftype()
773 new
774 call setline(1, ['L1'])
775 set buftype=nowrite
776 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100777
778 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
779 exe 'set buftype=' .. val
780 call writefile(['something'], 'XBuftype')
781 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
782 endfor
783
784 call delete('XBuftype')
785 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100786endfunc
787
Bram Moolenaar4d23c522020-04-09 18:42:11 +0200788" Test for the 'shell' option
789func Test_shell()
790 CheckUnix
791 let save_shell = &shell
792 set shell=
793 call assert_fails('shell', 'E91:')
794 let &shell = save_shell
795endfunc
796
Bram Moolenaarea3db912020-02-02 15:32:13 +0100797" Test for the 'shellquote' option
798func Test_shellquote()
799 CheckUnix
800 set shellquote=#
801 set verbose=20
802 redir => v
803 silent! !echo Hello
804 redir END
805 set verbose&
806 set shellquote&
807 call assert_match(': "#echo Hello#"', v)
808endfunc
809
Bram Moolenaar578fe942020-02-27 21:32:51 +0100810" Test for the 'rightleftcmd' option
811func Test_rightleftcmd()
812 CheckFeature rightleft
813 set rightleft
814 set rightleftcmd
815
816 let g:l = []
817 func AddPos()
818 call add(g:l, screencol())
819 return ''
820 endfunc
821 cmap <expr> <F2> AddPos()
822
823 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
824 \ "\<Left>\<F2>\<Esc>", 'xt')
825 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
826
827 cunmap <F2>
828 unlet g:l
829 set rightleftcmd&
830 set rightleft&
831endfunc
832
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200833" Test for the "debug" option
834func Test_debug_option()
835 set debug=beep
836 exe "normal \<C-c>"
837 call assert_equal('Beep!', Screenline(&lines))
838 set debug&
839endfunc
840
Bram Moolenaar004a6782020-04-11 17:09:31 +0200841" Test for the default CDPATH option
842func Test_opt_default_cdpath()
843 CheckFeature file_in_path
844 let after =<< trim [CODE]
845 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
846 call writefile(v:errors, 'Xtestout')
847 qall
848 [CODE]
849 if has('unix')
850 let $CDPATH='/path/to/dir1:/path/to/dir2'
851 else
852 let $CDPATH='/path/to/dir1;/path/to/dir2'
853 endif
854 if RunVim([], after, '')
855 call assert_equal([], readfile('Xtestout'))
856 call delete('Xtestout')
857 endif
858endfunc
859
860" Test for setting keycodes using set
861func Test_opt_set_keycode()
862 call assert_fails('set <t_k1=l', 'E474:')
863 call assert_fails('set <Home=l', 'E474:')
864 set <t_k9>=abcd
865 call assert_equal('abcd', &t_k9)
866 set <t_k9>&
867 set <F9>=xyz
868 call assert_equal('xyz', &t_k9)
869 set <t_k9>&
870endfunc
871
872" Test for changing options in a sandbox
873func Test_opt_sandbox()
874 for opt in ['backupdir', 'cdpath', 'exrc']
875 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200876 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200877 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200878 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200879endfunc
880
881" Test for setting an option with local value to global value
882func Test_opt_local_to_global()
883 setglobal equalprg=gprg
884 setlocal equalprg=lprg
885 call assert_equal('gprg', &g:equalprg)
886 call assert_equal('lprg', &l:equalprg)
887 call assert_equal('lprg', &equalprg)
888 set equalprg<
889 call assert_equal('', &l:equalprg)
890 call assert_equal('gprg', &equalprg)
891 setglobal equalprg=gnewprg
892 setlocal equalprg=lnewprg
893 setlocal equalprg<
894 call assert_equal('gnewprg', &l:equalprg)
895 call assert_equal('gnewprg', &equalprg)
896 set equalprg&
897endfunc
898
899" Test for incrementing, decrementing and multiplying a number option value
900func Test_opt_num_op()
901 set shiftwidth=4
902 set sw+=2
903 call assert_equal(6, &sw)
904 set sw-=2
905 call assert_equal(4, &sw)
906 set sw^=2
907 call assert_equal(8, &sw)
908 set shiftwidth&
909endfunc
910
Bram Moolenaar65d032c2020-04-24 20:57:01 +0200911" Test for setting option values using v:false and v:true
912func Test_opt_boolean()
913 set number&
914 set number
915 call assert_equal(1, &nu)
916 set nonu
917 call assert_equal(0, &nu)
918 let &nu = v:true
919 call assert_equal(1, &nu)
920 let &nu = v:false
921 call assert_equal(0, &nu)
922 set number&
923endfunc
924
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200925" Test for the 'window' option
926func Test_window_opt()
927 " Needs only one open widow
928 %bw!
929 call setline(1, range(1, 8))
930 set window=5
931 exe "normal \<C-F>"
932 call assert_equal(4, line('w0'))
933 exe "normal \<C-F>"
934 call assert_equal(7, line('w0'))
935 exe "normal \<C-F>"
936 call assert_equal(8, line('w0'))
937 exe "normal \<C-B>"
938 call assert_equal(5, line('w0'))
939 exe "normal \<C-B>"
940 call assert_equal(2, line('w0'))
941 exe "normal \<C-B>"
942 call assert_equal(1, line('w0'))
943 set window=1
944 exe "normal gg\<C-F>"
945 call assert_equal(2, line('w0'))
946 exe "normal \<C-F>"
947 call assert_equal(3, line('w0'))
948 exe "normal \<C-B>"
949 call assert_equal(2, line('w0'))
950 exe "normal \<C-B>"
951 call assert_equal(1, line('w0'))
952 enew!
953 set window&
954endfunc
955
Bram Moolenaar5d3c9f82020-06-26 20:41:39 +0200956" Test for the 'winminheight' option
957func Test_opt_winminheight()
958 only!
959 let &winheight = &lines + 4
960 call assert_fails('let &winminheight = &lines + 2', 'E36:')
961 call assert_true(&winminheight <= &lines)
962 set winminheight&
963 set winheight&
964endfunc
965
966" Test for the 'winminwidth' option
967func Test_opt_winminwidth()
968 only!
969 let &winwidth = &columns + 4
970 call assert_fails('let &winminwidth = &columns + 2', 'E36:')
971 call assert_true(&winminwidth <= &columns)
972 set winminwidth&
973 set winwidth&
974endfunc
975
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100976" vim: shiftwidth=2 sts=2 expandtab