blob: f9a424ff1fe09e0e8b850a984e1f3a8e50e419ce [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 Moolenaar6b915c02020-01-18 15:53:19 +010063func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020064 let caught = 'ok'
65 try
66 options
67 catch
68 let caught = v:throwpoint . "\n" . v:exception
69 endtry
70 call assert_equal('ok', caught)
71
Bram Moolenaare0b59492019-05-21 20:54:45 +020072 " Check if the option-window is opened horizontally.
73 wincmd j
74 call assert_notequal('option-window', bufname(''))
75 wincmd k
76 call assert_equal('option-window', bufname(''))
77 " close option-window
78 close
79
80 " Open the option-window vertically.
81 vert options
82 " Check if the option-window is opened vertically.
83 wincmd l
84 call assert_notequal('option-window', bufname(''))
85 wincmd h
86 call assert_equal('option-window', bufname(''))
87 " close option-window
88 close
89
90 " Open the option-window in a new tab.
91 tab options
92 " Check if the option-window is opened in a tab.
93 normal gT
94 call assert_notequal('option-window', bufname(''))
95 normal gt
96 call assert_equal('option-window', bufname(''))
97
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020098 " close option-window
99 close
Bram Moolenaar004a6782020-04-11 17:09:31 +0200100
101 " Open the options window browse
102 if has('browse')
103 browse set
104 call assert_equal('option-window', bufname(''))
105 close
106 endif
Bram Moolenaar1e115362019-01-09 23:01:02 +0100107endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200108
Bram Moolenaar1e115362019-01-09 23:01:02 +0100109func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +0200110 " Test that changing 'path' keeps two commas.
111 set path=foo,,bar
112 set path-=bar
113 set path+=bar
114 call assert_equal('foo,,bar', &path)
115
116 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +0100117endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200118
119func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +0200120 if has('signs')
121 call assert_equal("auto", &signcolumn)
122 set signcolumn=yes
123 set signcolumn=no
124 call assert_fails('set signcolumn=nope')
125 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200126endfunc
127
Bram Moolenaard0b51382016-11-04 15:23:45 +0100128func Test_filetype_valid()
129 set ft=valid_name
130 call assert_equal("valid_name", &filetype)
131 set ft=valid-name
132 call assert_equal("valid-name", &filetype)
133
134 call assert_fails(":set ft=wrong;name", "E474:")
135 call assert_fails(":set ft=wrong\\\\name", "E474:")
136 call assert_fails(":set ft=wrong\\|name", "E474:")
137 call assert_fails(":set ft=wrong/name", "E474:")
138 call assert_fails(":set ft=wrong\\\nname", "E474:")
139 call assert_equal("valid-name", &filetype)
140
141 exe "set ft=trunc\x00name"
142 call assert_equal("trunc", &filetype)
143endfunc
144
145func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100146 if !has('syntax')
147 return
148 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100149 set syn=valid_name
150 call assert_equal("valid_name", &syntax)
151 set syn=valid-name
152 call assert_equal("valid-name", &syntax)
153
154 call assert_fails(":set syn=wrong;name", "E474:")
155 call assert_fails(":set syn=wrong\\\\name", "E474:")
156 call assert_fails(":set syn=wrong\\|name", "E474:")
157 call assert_fails(":set syn=wrong/name", "E474:")
158 call assert_fails(":set syn=wrong\\\nname", "E474:")
159 call assert_equal("valid-name", &syntax)
160
161 exe "set syn=trunc\x00name"
162 call assert_equal("trunc", &syntax)
163endfunc
164
165func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100166 if !has('keymap')
167 return
168 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100169 call assert_fails(":set kmp=valid_name", "E544:")
170 call assert_fails(":set kmp=valid_name", "valid_name")
171 call assert_fails(":set kmp=valid-name", "E544:")
172 call assert_fails(":set kmp=valid-name", "valid-name")
173
174 call assert_fails(":set kmp=wrong;name", "E474:")
175 call assert_fails(":set kmp=wrong\\\\name", "E474:")
176 call assert_fails(":set kmp=wrong\\|name", "E474:")
177 call assert_fails(":set kmp=wrong/name", "E474:")
178 call assert_fails(":set kmp=wrong\\\nname", "E474:")
179
180 call assert_fails(":set kmp=trunc\x00name", "E544:")
181 call assert_fails(":set kmp=trunc\x00name", "trunc")
182endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100183
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100184func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100185 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100186 exe 'set ' . a:name . '=/usr/share/dict/words'
187 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
188 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
189 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
190 exe 'set ' . a:name . '=/usr/share/dict\ words'
191 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100192
193 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100194 call assert_fails("set " . a:name . "=/not&there", "E474:")
195 call assert_fails("set " . a:name . "=/not>there", "E474:")
196 call assert_fails("set " . a:name . "=/not.*there", "E474:")
197endfunc
198
Bram Moolenaar60629d62017-02-23 18:08:56 +0100199func Test_cinkeys()
200 " This used to cause invalid memory access
201 set cindent cinkeys=0
202 norm a
203 set cindent& cinkeys&
204endfunc
205
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100206func Test_dictionary()
207 call Check_dir_option('dictionary')
208endfunc
209
210func Test_thesaurus()
211 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100212endfun
213
Bram Moolenaar226c5342017-02-17 14:53:15 +0100214func Test_complete()
215 " Trailing single backslash used to cause invalid memory access.
216 set complete=s\
217 new
218 call feedkeys("i\<C-N>\<Esc>", 'xt')
219 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200220 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100221 set complete&
222endfun
223
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100224func Test_set_completion()
225 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
226 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
227
Bram Moolenaar297610b2019-12-27 17:20:55 +0100228 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
229 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
230
231 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
232 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
233
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100234 " Expand boolan options. When doing :set no<Tab>
235 " vim displays the options names without "no" but completion uses "no...".
236 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
237 call assert_equal('"set nodiff digraph', @:)
238
239 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
240 call assert_equal('"set invdiff digraph', @:)
241
242 " Expand abbreviation of options.
243 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
244 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
245
246 " Expand current value
247 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
248 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
249
250 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
251 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
252
253 " Expand key codes.
254 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
255 call assert_equal('"set <Help> <Home>', @:)
256
257 " Expand terminal options.
258 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
259 call assert_equal('"set t_AB t_AF t_AL', @:)
260
261 " Expand directories.
262 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
263 call assert_match(' ./samples/ ', @:)
264 call assert_notmatch(' ./small.vim ', @:)
265
266 " Expand files and directories.
267 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
268 call assert_match(' ./samples/.* ./small.vim', @:)
269
270 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
271 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200272 set tags&
Bram Moolenaar1363a302020-04-12 13:50:26 +0200273
274 " Expanding the option names
275 call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
276 call assert_equal('"set all', @:)
277
278 " Expanding a second set of option names
279 call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
280 call assert_equal('"set wrapscan all', @:)
281
282 " Expanding a special keycode
283 call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
284 call assert_equal('"set <Home>', @:)
285
286 " Expanding an invalid special keycode
287 call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
288 call assert_equal("\"set <abcd>\<Tab>", @:)
289
290 " Expanding a terminal keycode
291 call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
292 call assert_equal("\"set t_AB", @:)
293
294 " Expanding an invalid option name
295 call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
296 call assert_equal("\"set abcde=\<Tab>", @:)
297
298 " Expanding after a = for a boolean option
299 call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
300 call assert_equal("\"set wrapscan=\<Tab>", @:)
301
302 " Expanding a numeric option
303 call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
304 call assert_equal("\"set tabstop+=" .. &tabstop, @:)
305
306 " Expanding a non-boolean option
307 call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
308 call assert_equal("\"set invtabstop=", @:)
309
310 " Expand options for 'spellsuggest'
311 call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
312 call assert_equal("\"set spellsuggest=best,file:xyz", @:)
313
314 " Expand value for 'key'
315 set key=abcd
316 call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
317 call assert_equal('"set key=*****', @:)
318 set key=
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100319endfunc
320
321func Test_set_errors()
322 call assert_fails('set scroll=-1', 'E49:')
323 call assert_fails('set backupcopy=', 'E474:')
324 call assert_fails('set regexpengine=3', 'E474:')
325 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200326 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100327 call assert_fails('set colorcolumn=-a', 'E474:')
328 call assert_fails('set colorcolumn=a', 'E474:')
329 call assert_fails('set colorcolumn=1,', 'E474:')
330 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100331 call assert_fails('set cmdheight=-1', 'E487:')
332 call assert_fails('set cmdwinheight=-1', 'E487:')
333 if has('conceal')
334 call assert_fails('set conceallevel=-1', 'E487:')
335 call assert_fails('set conceallevel=4', 'E474:')
336 endif
337 call assert_fails('set helpheight=-1', 'E487:')
338 call assert_fails('set history=-1', 'E487:')
339 call assert_fails('set report=-1', 'E487:')
340 call assert_fails('set shiftwidth=-1', 'E487:')
341 call assert_fails('set sidescroll=-1', 'E487:')
342 call assert_fails('set tabstop=-1', 'E487:')
343 call assert_fails('set textwidth=-1', 'E487:')
344 call assert_fails('set timeoutlen=-1', 'E487:')
345 call assert_fails('set updatecount=-1', 'E487:')
346 call assert_fails('set updatetime=-1', 'E487:')
347 call assert_fails('set winheight=-1', 'E487:')
348 call assert_fails('set tabstop!', 'E488:')
349 call assert_fails('set xxx', 'E518:')
350 call assert_fails('set beautify?', 'E519:')
351 call assert_fails('set undolevels=x', 'E521:')
352 call assert_fails('set tabstop=', 'E521:')
353 call assert_fails('set comments=-', 'E524:')
354 call assert_fails('set comments=a', 'E525:')
355 call assert_fails('set foldmarker=x', 'E536:')
356 call assert_fails('set commentstring=x', 'E537:')
357 call assert_fails('set complete=x', 'E539:')
358 call assert_fails('set statusline=%{', 'E540:')
359 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
360 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100361 if has('cursorshape')
362 " This invalid value for 'guicursor' used to cause Vim to crash.
363 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
364 call assert_fails('set guicursor=i-ci', 'E545:')
365 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100366 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100367 call assert_fails('set guicursor=r-cr:horx', 'E548:')
368 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
369 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100370 if has('mouseshape')
371 call assert_fails('se mouseshape=i-r:x', 'E547:')
372 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100373 call assert_fails('set backupext=~ patchmode=~', 'E589:')
374 call assert_fails('set winminheight=10 winheight=9', 'E591:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200375 set winminheight& winheight&
376 set winheight=10 winminheight=10
377 call assert_fails('set winheight=9', 'E591:')
378 set winminheight& winheight&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100379 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200380 set winminwidth& winwidth&
381 call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
382 set winwidth& winminwidth&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100383 call assert_fails("set showbreak=\x01", 'E595:')
384 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200385 call assert_fails('set tabstop??', 'E488:')
386 call assert_fails('set wrapscan!!', 'E488:')
387 call assert_fails('set tabstop&&', 'E488:')
388 call assert_fails('set wrapscan<<', 'E488:')
389 call assert_fails('set wrapscan=1', 'E474:')
390 call assert_fails('set autoindent@', 'E488:')
391 call assert_fails('set wildchar=<abc>', 'E474:')
392 call assert_fails('set cmdheight=1a', 'E521:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200393 call assert_fails('set invcmdheight', 'E474:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200394 if has('python') && has('python3')
395 call assert_fails('set pyxversion=6', 'E474:')
396 endif
Bram Moolenaar1363a302020-04-12 13:50:26 +0200397 call assert_fails("let &tabstop='ab'", 'E521:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100398endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100399
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200400func CheckWasSet(name)
401 let verb_cm = execute('verbose set ' .. a:name .. '?')
402 call assert_match('Last set from.*test_options.vim', verb_cm)
403endfunc
404func CheckWasNotSet(name)
405 let verb_cm = execute('verbose set ' .. a:name .. '?')
406 call assert_notmatch('Last set from', verb_cm)
407endfunc
408
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200409" Must be executed before other tests that set 'term'.
410func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200411 CheckNotGui
412
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200413 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200414
415 let term_save = &term
416 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200417 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200418 let &term = term_save
419endfunc
420
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200421func Test_copy_context()
422 setlocal list
423 call CheckWasSet('list')
424 split
425 call CheckWasSet('list')
426 quit
427 setlocal nolist
428
429 set ai
430 call CheckWasSet('ai')
431 set filetype=perl
432 call CheckWasSet('filetype')
433 set fo=tcroq
434 call CheckWasSet('fo')
435
436 split Xsomebuf
437 call CheckWasSet('ai')
438 call CheckWasNotSet('filetype')
439 call CheckWasSet('fo')
440endfunc
441
Bram Moolenaar67391142017-02-19 21:07:04 +0100442func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200443 CheckUnix
444 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200445
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200446 " Setting 'ttytype' used to cause a double-free when exiting vim and
447 " when vim is compiled with -DEXITFREE.
448 set ttytype=ansi
449 call assert_equal('ansi', &ttytype)
450 call assert_equal(&ttytype, &term)
451 set ttytype=xterm
452 call assert_equal('xterm', &ttytype)
453 call assert_equal(&ttytype, &term)
454 " "set ttytype=" gives E522 instead of E529
455 " in travis on some builds. Why? Catch both for now
456 try
457 set ttytype=
458 call assert_report('set ttytype= did not fail')
459 catch /E529\|E522/
460 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200461
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200462 " Some systems accept any terminal name and return dumb settings,
463 " check for failure of finding the entry and for missing 'cm' entry.
464 try
465 set ttytype=xxx
466 call assert_report('set ttytype=xxx did not fail')
467 catch /E522\|E437/
468 endtry
469
470 set ttytype&
471 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200472
473 if has('gui') && !has('gui_running')
474 call assert_fails('set term=gui', 'E531:')
475 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100476endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100477
478func Test_set_all()
479 set tw=75
480 set iskeyword=a-z,A-Z
481 set nosplitbelow
482 let out = execute('set all')
483 call assert_match('textwidth=75', out)
484 call assert_match('iskeyword=a-z,A-Z', out)
485 call assert_match('nosplitbelow', out)
486 set tw& iskeyword& splitbelow&
487endfunc
488
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100489func Test_set_one_column()
490 let out_mult = execute('set all')->split("\n")
491 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100492 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100493endfunc
494
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100495func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100496 if filereadable('opt_test.vim')
497 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100498 else
499 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100500 endif
501endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200502
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100503func Test_renderoptions()
504 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
505 " Doesn't hurt to do this on a non-Windows system.
506 if windowsversion() !~ '^[345]\.'
507 set renderoptions=type:directx
508 set rop=type:directx
509 endif
510endfunc
511
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200512func ResetIndentexpr()
513 set indentexpr=
514endfunc
515
516func Test_set_indentexpr()
517 " this was causing usage of freed memory
518 set indentexpr=ResetIndentexpr()
519 new
520 call feedkeys("i\<c-f>", 'x')
521 call assert_equal('', &indentexpr)
522 bwipe!
523endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200524
525func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100526 " Option 'backupskip' may contain several comma-separated path
527 " specifications if one or more of the environment variables TMPDIR, TMP,
528 " or TEMP is defined. To simplify testing, convert the string value into a
529 " list.
530 let bsklist = split(&bsk, ',')
531
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200532 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100533 let found = (index(bsklist, '/private/tmp/*') >= 0)
534 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200535 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100536 let found = (index(bsklist, '/tmp/*') >= 0)
537 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200538 endif
539
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100540 " If our test platform is Windows, the path(s) in option bsk will use
541 " backslash for the path separator and the components could be in short
542 " (8.3) format. As such, we need to replace the backslashes with forward
543 " slashes and convert the path components to long format. The expand()
544 " function will do this but it cannot handle comma-separated paths. This is
545 " why bsk was converted from a string into a list of strings above.
546 "
547 " One final complication is that the wildcard "/*" is at the end of each
548 " path and so expand() might return a list of matching files. To prevent
549 " this, we need to remove the wildcard before calling expand() and then
550 " append it afterwards.
551 if has('win32')
552 let item_nbr = 0
553 while item_nbr < len(bsklist)
554 let path_spec = bsklist[item_nbr]
555 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
556 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
557 let bsklist[item_nbr] = path_spec . '/*'
558 let item_nbr += 1
559 endwhile
560 endif
561
562 " Option bsk will also include these environment variables if defined.
563 " If they're defined, verify they appear in the option value.
564 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200565 if exists(var)
566 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100567 let varvalue = substitute(varvalue, '/$', '', '')
568 let varvalue .= '/*'
569 let found = (index(bsklist, varvalue) >= 0)
570 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200571 endif
572 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200573
574 " Duplicates should be filtered out (option has P_NODUP)
575 let backupskip = &backupskip
576 set backupskip=
577 set backupskip+=/test/dir
578 set backupskip+=/other/dir
579 set backupskip+=/test/dir
580 call assert_equal('/test/dir,/other/dir', &backupskip)
581 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200582endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200583
584func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200585 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200586
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200587 " Test copy option from current buffer in window
588 split
589 enew
590 setlocal numberwidth=5
591 wincmd w
592 call assert_equal(4,&numberwidth)
593 bnext
594 call assert_equal(5,&numberwidth)
595 bw!
596 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200597
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200598 " Test copy value from window that used to be display the buffer
599 split
600 enew
601 setlocal numberwidth=6
602 bnext
603 wincmd w
604 call assert_equal(4,&numberwidth)
605 bnext
606 call assert_equal(6,&numberwidth)
607 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200608
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200609 " Test that if buffer is current, don't use the stale cached value
610 " from the last time the buffer was displayed.
611 split
612 enew
613 setlocal numberwidth=7
614 bnext
615 bnext
616 setlocal numberwidth=8
617 wincmd w
618 call assert_equal(4,&numberwidth)
619 bnext
620 call assert_equal(8,&numberwidth)
621 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200622
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200623 " Test value is not copied if window already has seen the buffer
624 enew
625 split
626 setlocal numberwidth=9
627 bnext
628 setlocal numberwidth=10
629 wincmd w
630 call assert_equal(4,&numberwidth)
631 bnext
632 call assert_equal(4,&numberwidth)
633 bw!
634
635 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200636endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200637
638func Test_shortmess_F()
639 new
640 call assert_match('\[No Name\]', execute('file'))
641 set shortmess+=F
642 call assert_match('\[No Name\]', execute('file'))
643 call assert_match('^\s*$', execute('file foo'))
644 call assert_match('foo', execute('file'))
645 set shortmess-=F
646 call assert_match('bar', execute('file bar'))
647 call assert_match('bar', execute('file'))
648 set shortmess&
649 bwipe
650endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200651
652func Test_shortmess_F2()
653 e file1
654 e file2
655 call assert_match('file1', execute('bn', ''))
656 call assert_match('file2', execute('bn', ''))
657 set shortmess+=F
658 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200659 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200660 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200661 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200662 set hidden
663 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200664 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200665 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200666 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200667 set nohidden
668 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200669 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200670 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200671 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200672 set shortmess&
673 call assert_match('file1', execute('bn', ''))
674 call assert_match('file2', execute('bn', ''))
675 bwipe
676 bwipe
677endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100678
679func Test_local_scrolloff()
680 set so=5
681 set siso=7
682 split
683 call assert_equal(5, &so)
684 setlocal so=3
685 call assert_equal(3, &so)
686 wincmd w
687 call assert_equal(5, &so)
688 wincmd w
689 setlocal so<
690 call assert_equal(5, &so)
691 setlocal so=0
692 call assert_equal(0, &so)
693 setlocal so=-1
694 call assert_equal(5, &so)
695
696 call assert_equal(7, &siso)
697 setlocal siso=3
698 call assert_equal(3, &siso)
699 wincmd w
700 call assert_equal(7, &siso)
701 wincmd w
702 setlocal siso<
703 call assert_equal(7, &siso)
704 setlocal siso=0
705 call assert_equal(0, &siso)
706 setlocal siso=-1
707 call assert_equal(7, &siso)
708
709 close
710 set so&
711 set siso&
712endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200713
714func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100715 CheckFunction reltimefloat
716
Bram Moolenaar449ac472019-04-03 21:42:35 +0200717 new
718 call setline(1, 'empty')
719 redraw
720 set writedelay=10
721 let start = reltime()
722 call setline(1, repeat('x', 70))
723 redraw
724 let elapsed = reltimefloat(reltime(start))
725 set writedelay=0
726 " With 'writedelay' set should take at least 30 * 10 msec
727 call assert_inrange(30 * 0.01, 999.0, elapsed)
728
729 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200730endfunc
731
732func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200733 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200734 set visualbell
735 call assert_beeps('normal 0h')
736 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200737 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200738endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100739
740" Test for the 'write' option
741func Test_write()
742 new
743 call setline(1, ['L1'])
744 set nowrite
745 call assert_fails('write Xfile', 'E142:')
746 set write
747 close!
748endfunc
749
750" Test for 'buftype' option
751func Test_buftype()
752 new
753 call setline(1, ['L1'])
754 set buftype=nowrite
755 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100756
757 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
758 exe 'set buftype=' .. val
759 call writefile(['something'], 'XBuftype')
760 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
761 endfor
762
763 call delete('XBuftype')
764 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100765endfunc
766
Bram Moolenaar4d23c522020-04-09 18:42:11 +0200767" Test for the 'shell' option
768func Test_shell()
769 CheckUnix
770 let save_shell = &shell
771 set shell=
772 call assert_fails('shell', 'E91:')
773 let &shell = save_shell
774endfunc
775
Bram Moolenaarea3db912020-02-02 15:32:13 +0100776" Test for the 'shellquote' option
777func Test_shellquote()
778 CheckUnix
779 set shellquote=#
780 set verbose=20
781 redir => v
782 silent! !echo Hello
783 redir END
784 set verbose&
785 set shellquote&
786 call assert_match(': "#echo Hello#"', v)
787endfunc
788
Bram Moolenaar578fe942020-02-27 21:32:51 +0100789" Test for the 'rightleftcmd' option
790func Test_rightleftcmd()
791 CheckFeature rightleft
792 set rightleft
793 set rightleftcmd
794
795 let g:l = []
796 func AddPos()
797 call add(g:l, screencol())
798 return ''
799 endfunc
800 cmap <expr> <F2> AddPos()
801
802 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
803 \ "\<Left>\<F2>\<Esc>", 'xt')
804 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
805
806 cunmap <F2>
807 unlet g:l
808 set rightleftcmd&
809 set rightleft&
810endfunc
811
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200812" Test for the "debug" option
813func Test_debug_option()
814 set debug=beep
815 exe "normal \<C-c>"
816 call assert_equal('Beep!', Screenline(&lines))
817 set debug&
818endfunc
819
Bram Moolenaar004a6782020-04-11 17:09:31 +0200820" Test for the default CDPATH option
821func Test_opt_default_cdpath()
822 CheckFeature file_in_path
823 let after =<< trim [CODE]
824 call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
825 call writefile(v:errors, 'Xtestout')
826 qall
827 [CODE]
828 if has('unix')
829 let $CDPATH='/path/to/dir1:/path/to/dir2'
830 else
831 let $CDPATH='/path/to/dir1;/path/to/dir2'
832 endif
833 if RunVim([], after, '')
834 call assert_equal([], readfile('Xtestout'))
835 call delete('Xtestout')
836 endif
837endfunc
838
839" Test for setting keycodes using set
840func Test_opt_set_keycode()
841 call assert_fails('set <t_k1=l', 'E474:')
842 call assert_fails('set <Home=l', 'E474:')
843 set <t_k9>=abcd
844 call assert_equal('abcd', &t_k9)
845 set <t_k9>&
846 set <F9>=xyz
847 call assert_equal('xyz', &t_k9)
848 set <t_k9>&
849endfunc
850
851" Test for changing options in a sandbox
852func Test_opt_sandbox()
853 for opt in ['backupdir', 'cdpath', 'exrc']
854 call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
Bram Moolenaar1363a302020-04-12 13:50:26 +0200855 call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200856 endfor
Bram Moolenaar1363a302020-04-12 13:50:26 +0200857 call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
Bram Moolenaar004a6782020-04-11 17:09:31 +0200858endfunc
859
860" Test for setting an option with local value to global value
861func Test_opt_local_to_global()
862 setglobal equalprg=gprg
863 setlocal equalprg=lprg
864 call assert_equal('gprg', &g:equalprg)
865 call assert_equal('lprg', &l:equalprg)
866 call assert_equal('lprg', &equalprg)
867 set equalprg<
868 call assert_equal('', &l:equalprg)
869 call assert_equal('gprg', &equalprg)
870 setglobal equalprg=gnewprg
871 setlocal equalprg=lnewprg
872 setlocal equalprg<
873 call assert_equal('gnewprg', &l:equalprg)
874 call assert_equal('gnewprg', &equalprg)
875 set equalprg&
876endfunc
877
878" Test for incrementing, decrementing and multiplying a number option value
879func Test_opt_num_op()
880 set shiftwidth=4
881 set sw+=2
882 call assert_equal(6, &sw)
883 set sw-=2
884 call assert_equal(4, &sw)
885 set sw^=2
886 call assert_equal(8, &sw)
887 set shiftwidth&
888endfunc
889
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100890" vim: shiftwidth=2 sts=2 expandtab