blob: ef3ae1ad4176984c4a6ff61987175ef48993807c [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 Moolenaarc8ce6152016-08-07 13:48:20 +020025 set whichwrap&
Bram Moolenaar1e115362019-01-09 23:01:02 +010026endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020027
Bram Moolenaar1e115362019-01-09 23:01:02 +010028func Test_isfname()
Bram Moolenaar187a4f22017-02-23 17:07:14 +010029 " This used to cause Vim to access uninitialized memory.
30 set isfname=
31 call assert_equal("~X", expand("~X"))
32 set isfname&
Bram Moolenaar1e115362019-01-09 23:01:02 +010033endfunc
Bram Moolenaar187a4f22017-02-23 17:07:14 +010034
Bram Moolenaar1e115362019-01-09 23:01:02 +010035func Test_wildchar()
Bram Moolenaara12e4032017-02-25 21:37:57 +010036 " Empty 'wildchar' used to access invalid memory.
37 call assert_fails('set wildchar=', 'E521:')
38 call assert_fails('set wildchar=abc', 'E521:')
39 set wildchar=<Esc>
40 let a=execute('set wildchar?')
41 call assert_equal("\n wildchar=<Esc>", a)
42 set wildchar=27
43 let a=execute('set wildchar?')
44 call assert_equal("\n wildchar=<Esc>", a)
45 set wildchar&
Bram Moolenaar1e115362019-01-09 23:01:02 +010046endfunc
Bram Moolenaara12e4032017-02-25 21:37:57 +010047
Bram Moolenaar6b915c02020-01-18 15:53:19 +010048func Test_options_command()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020049 let caught = 'ok'
50 try
51 options
52 catch
53 let caught = v:throwpoint . "\n" . v:exception
54 endtry
55 call assert_equal('ok', caught)
56
Bram Moolenaare0b59492019-05-21 20:54:45 +020057 " Check if the option-window is opened horizontally.
58 wincmd j
59 call assert_notequal('option-window', bufname(''))
60 wincmd k
61 call assert_equal('option-window', bufname(''))
62 " close option-window
63 close
64
65 " Open the option-window vertically.
66 vert options
67 " Check if the option-window is opened vertically.
68 wincmd l
69 call assert_notequal('option-window', bufname(''))
70 wincmd h
71 call assert_equal('option-window', bufname(''))
72 " close option-window
73 close
74
75 " Open the option-window in a new tab.
76 tab options
77 " Check if the option-window is opened in a tab.
78 normal gT
79 call assert_notequal('option-window', bufname(''))
80 normal gt
81 call assert_equal('option-window', bufname(''))
82
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020083 " close option-window
84 close
Bram Moolenaar1e115362019-01-09 23:01:02 +010085endfunc
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020086
Bram Moolenaar1e115362019-01-09 23:01:02 +010087func Test_path_keep_commas()
Bram Moolenaarc8ce6152016-08-07 13:48:20 +020088 " Test that changing 'path' keeps two commas.
89 set path=foo,,bar
90 set path-=bar
91 set path+=bar
92 call assert_equal('foo,,bar', &path)
93
94 set path&
Bram Moolenaar1e115362019-01-09 23:01:02 +010095endfunc
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020096
97func Test_signcolumn()
Bram Moolenaarebcccad2016-08-12 19:17:13 +020098 if has('signs')
99 call assert_equal("auto", &signcolumn)
100 set signcolumn=yes
101 set signcolumn=no
102 call assert_fails('set signcolumn=nope')
103 endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200104endfunc
105
Bram Moolenaard0b51382016-11-04 15:23:45 +0100106func Test_filetype_valid()
107 set ft=valid_name
108 call assert_equal("valid_name", &filetype)
109 set ft=valid-name
110 call assert_equal("valid-name", &filetype)
111
112 call assert_fails(":set ft=wrong;name", "E474:")
113 call assert_fails(":set ft=wrong\\\\name", "E474:")
114 call assert_fails(":set ft=wrong\\|name", "E474:")
115 call assert_fails(":set ft=wrong/name", "E474:")
116 call assert_fails(":set ft=wrong\\\nname", "E474:")
117 call assert_equal("valid-name", &filetype)
118
119 exe "set ft=trunc\x00name"
120 call assert_equal("trunc", &filetype)
121endfunc
122
123func Test_syntax_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100124 if !has('syntax')
125 return
126 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100127 set syn=valid_name
128 call assert_equal("valid_name", &syntax)
129 set syn=valid-name
130 call assert_equal("valid-name", &syntax)
131
132 call assert_fails(":set syn=wrong;name", "E474:")
133 call assert_fails(":set syn=wrong\\\\name", "E474:")
134 call assert_fails(":set syn=wrong\\|name", "E474:")
135 call assert_fails(":set syn=wrong/name", "E474:")
136 call assert_fails(":set syn=wrong\\\nname", "E474:")
137 call assert_equal("valid-name", &syntax)
138
139 exe "set syn=trunc\x00name"
140 call assert_equal("trunc", &syntax)
141endfunc
142
143func Test_keymap_valid()
Bram Moolenaar9376f5f2016-11-04 16:41:20 +0100144 if !has('keymap')
145 return
146 endif
Bram Moolenaard0b51382016-11-04 15:23:45 +0100147 call assert_fails(":set kmp=valid_name", "E544:")
148 call assert_fails(":set kmp=valid_name", "valid_name")
149 call assert_fails(":set kmp=valid-name", "E544:")
150 call assert_fails(":set kmp=valid-name", "valid-name")
151
152 call assert_fails(":set kmp=wrong;name", "E474:")
153 call assert_fails(":set kmp=wrong\\\\name", "E474:")
154 call assert_fails(":set kmp=wrong\\|name", "E474:")
155 call assert_fails(":set kmp=wrong/name", "E474:")
156 call assert_fails(":set kmp=wrong\\\nname", "E474:")
157
158 call assert_fails(":set kmp=trunc\x00name", "E544:")
159 call assert_fails(":set kmp=trunc\x00name", "trunc")
160endfunc
Bram Moolenaar7554da42016-11-25 22:04:13 +0100161
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100162func Check_dir_option(name)
Bram Moolenaar7554da42016-11-25 22:04:13 +0100163 " Check that it's possible to set the option.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100164 exe 'set ' . a:name . '=/usr/share/dict/words'
165 call assert_equal('/usr/share/dict/words', eval('&' . a:name))
166 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
167 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
168 exe 'set ' . a:name . '=/usr/share/dict\ words'
169 call assert_equal('/usr/share/dict words', eval('&' . a:name))
Bram Moolenaar7554da42016-11-25 22:04:13 +0100170
171 " Check rejecting weird characters.
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100172 call assert_fails("set " . a:name . "=/not&there", "E474:")
173 call assert_fails("set " . a:name . "=/not>there", "E474:")
174 call assert_fails("set " . a:name . "=/not.*there", "E474:")
175endfunc
176
Bram Moolenaar60629d62017-02-23 18:08:56 +0100177func Test_cinkeys()
178 " This used to cause invalid memory access
179 set cindent cinkeys=0
180 norm a
181 set cindent& cinkeys&
182endfunc
183
Bram Moolenaarf422bcc2016-11-26 17:45:53 +0100184func Test_dictionary()
185 call Check_dir_option('dictionary')
186endfunc
187
188func Test_thesaurus()
189 call Check_dir_option('thesaurus')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100190endfun
191
Bram Moolenaar226c5342017-02-17 14:53:15 +0100192func Test_complete()
193 " Trailing single backslash used to cause invalid memory access.
194 set complete=s\
195 new
196 call feedkeys("i\<C-N>\<Esc>", 'xt')
197 bwipe!
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200198 call assert_fails('set complete=ix', 'E535:')
Bram Moolenaar226c5342017-02-17 14:53:15 +0100199 set complete&
200endfun
201
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100202func Test_set_completion()
203 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
204 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
205
Bram Moolenaar297610b2019-12-27 17:20:55 +0100206 call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
207 call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
208
209 call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
210 call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
211
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100212 " Expand boolan options. When doing :set no<Tab>
213 " vim displays the options names without "no" but completion uses "no...".
214 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
215 call assert_equal('"set nodiff digraph', @:)
216
217 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
218 call assert_equal('"set invdiff digraph', @:)
219
220 " Expand abbreviation of options.
221 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
222 call assert_equal('"set tabstop thesaurus ttyscroll', @:)
223
224 " Expand current value
225 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
226 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
227
228 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
229 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
230
231 " Expand key codes.
232 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
233 call assert_equal('"set <Help> <Home>', @:)
234
235 " Expand terminal options.
236 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
237 call assert_equal('"set t_AB t_AF t_AL', @:)
238
239 " Expand directories.
240 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
241 call assert_match(' ./samples/ ', @:)
242 call assert_notmatch(' ./small.vim ', @:)
243
244 " Expand files and directories.
245 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
246 call assert_match(' ./samples/.* ./small.vim', @:)
247
248 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
249 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
Bram Moolenaar297610b2019-12-27 17:20:55 +0100250
Bram Moolenaar0331faf2019-06-15 18:40:37 +0200251 set tags&
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100252endfunc
253
254func Test_set_errors()
255 call assert_fails('set scroll=-1', 'E49:')
256 call assert_fails('set backupcopy=', 'E474:')
257 call assert_fails('set regexpengine=3', 'E474:')
258 call assert_fails('set history=10001', 'E474:')
Bram Moolenaarf8a07122019-07-01 22:06:07 +0200259 call assert_fails('set numberwidth=21', 'E474:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100260 call assert_fails('set colorcolumn=-a', 'E474:')
261 call assert_fails('set colorcolumn=a', 'E474:')
262 call assert_fails('set colorcolumn=1,', 'E474:')
263 call assert_fails('set colorcolumn=1;', 'E474:')
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100264 call assert_fails('set cmdheight=-1', 'E487:')
265 call assert_fails('set cmdwinheight=-1', 'E487:')
266 if has('conceal')
267 call assert_fails('set conceallevel=-1', 'E487:')
268 call assert_fails('set conceallevel=4', 'E474:')
269 endif
270 call assert_fails('set helpheight=-1', 'E487:')
271 call assert_fails('set history=-1', 'E487:')
272 call assert_fails('set report=-1', 'E487:')
273 call assert_fails('set shiftwidth=-1', 'E487:')
274 call assert_fails('set sidescroll=-1', 'E487:')
275 call assert_fails('set tabstop=-1', 'E487:')
276 call assert_fails('set textwidth=-1', 'E487:')
277 call assert_fails('set timeoutlen=-1', 'E487:')
278 call assert_fails('set updatecount=-1', 'E487:')
279 call assert_fails('set updatetime=-1', 'E487:')
280 call assert_fails('set winheight=-1', 'E487:')
281 call assert_fails('set tabstop!', 'E488:')
282 call assert_fails('set xxx', 'E518:')
283 call assert_fails('set beautify?', 'E519:')
284 call assert_fails('set undolevels=x', 'E521:')
285 call assert_fails('set tabstop=', 'E521:')
286 call assert_fails('set comments=-', 'E524:')
287 call assert_fails('set comments=a', 'E525:')
288 call assert_fails('set foldmarker=x', 'E536:')
289 call assert_fails('set commentstring=x', 'E537:')
290 call assert_fails('set complete=x', 'E539:')
291 call assert_fails('set statusline=%{', 'E540:')
292 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:')
293 call assert_fails('set statusline=%(', 'E542:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100294 if has('cursorshape')
295 " This invalid value for 'guicursor' used to cause Vim to crash.
296 call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
297 call assert_fails('set guicursor=i-ci', 'E545:')
298 call assert_fails('set guicursor=x', 'E545:')
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100299 call assert_fails('set guicursor=x:', 'E546:')
Bram Moolenaar24922ec2017-02-23 17:59:22 +0100300 call assert_fails('set guicursor=r-cr:horx', 'E548:')
301 call assert_fails('set guicursor=r-cr:hor0', 'E549:')
302 endif
Bram Moolenaar9b9be002020-03-22 14:41:22 +0100303 if has('mouseshape')
304 call assert_fails('se mouseshape=i-r:x', 'E547:')
305 endif
Bram Moolenaar698f8b22017-02-04 15:53:32 +0100306 call assert_fails('set backupext=~ patchmode=~', 'E589:')
307 call assert_fails('set winminheight=10 winheight=9', 'E591:')
308 call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
309 call assert_fails("set showbreak=\x01", 'E595:')
310 call assert_fails('set t_foo=', 'E846:')
Bram Moolenaar7554da42016-11-25 22:04:13 +0100311endfunc
Bram Moolenaar67391142017-02-19 21:07:04 +0100312
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200313func CheckWasSet(name)
314 let verb_cm = execute('verbose set ' .. a:name .. '?')
315 call assert_match('Last set from.*test_options.vim', verb_cm)
316endfunc
317func CheckWasNotSet(name)
318 let verb_cm = execute('verbose set ' .. a:name .. '?')
319 call assert_notmatch('Last set from', verb_cm)
320endfunc
321
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200322" Must be executed before other tests that set 'term'.
323func Test_000_term_option_verbose()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200324 CheckNotGui
325
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200326 call CheckWasNotSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200327
328 let term_save = &term
329 set term=ansi
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200330 call CheckWasSet('t_cm')
Bram Moolenaar35bc7d62018-10-02 14:45:10 +0200331 let &term = term_save
332endfunc
333
Bram Moolenaarcfb38142019-10-19 20:18:47 +0200334func Test_copy_context()
335 setlocal list
336 call CheckWasSet('list')
337 split
338 call CheckWasSet('list')
339 quit
340 setlocal nolist
341
342 set ai
343 call CheckWasSet('ai')
344 set filetype=perl
345 call CheckWasSet('filetype')
346 set fo=tcroq
347 call CheckWasSet('fo')
348
349 split Xsomebuf
350 call CheckWasSet('ai')
351 call CheckWasNotSet('filetype')
352 call CheckWasSet('fo')
353endfunc
354
Bram Moolenaar67391142017-02-19 21:07:04 +0100355func Test_set_ttytype()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200356 CheckUnix
357 CheckNotGui
Bram Moolenaarf803a762017-04-09 22:54:13 +0200358
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200359 " Setting 'ttytype' used to cause a double-free when exiting vim and
360 " when vim is compiled with -DEXITFREE.
361 set ttytype=ansi
362 call assert_equal('ansi', &ttytype)
363 call assert_equal(&ttytype, &term)
364 set ttytype=xterm
365 call assert_equal('xterm', &ttytype)
366 call assert_equal(&ttytype, &term)
367 " "set ttytype=" gives E522 instead of E529
368 " in travis on some builds. Why? Catch both for now
369 try
370 set ttytype=
371 call assert_report('set ttytype= did not fail')
372 catch /E529\|E522/
373 endtry
Bram Moolenaarf803a762017-04-09 22:54:13 +0200374
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200375 " Some systems accept any terminal name and return dumb settings,
376 " check for failure of finding the entry and for missing 'cm' entry.
377 try
378 set ttytype=xxx
379 call assert_report('set ttytype=xxx did not fail')
380 catch /E522\|E437/
381 endtry
382
383 set ttytype&
384 call assert_equal(&ttytype, &term)
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200385
386 if has('gui') && !has('gui_running')
387 call assert_fails('set term=gui', 'E531:')
388 endif
Bram Moolenaar67391142017-02-19 21:07:04 +0100389endfunc
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100390
391func Test_set_all()
392 set tw=75
393 set iskeyword=a-z,A-Z
394 set nosplitbelow
395 let out = execute('set all')
396 call assert_match('textwidth=75', out)
397 call assert_match('iskeyword=a-z,A-Z', out)
398 call assert_match('nosplitbelow', out)
399 set tw& iskeyword& splitbelow&
400endfunc
401
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100402func Test_set_one_column()
403 let out_mult = execute('set all')->split("\n")
404 let out_one = execute('set! all')->split("\n")
Bram Moolenaarab505b12020-03-23 19:28:44 +0100405 call assert_true(len(out_mult) < len(out_one))
Bram Moolenaar6b915c02020-01-18 15:53:19 +0100406endfunc
407
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100408func Test_set_values()
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100409 if filereadable('opt_test.vim')
410 source opt_test.vim
Bram Moolenaare8512d72017-03-07 22:33:32 +0100411 else
412 throw 'Skipped: opt_test.vim does not exist'
Bram Moolenaar2f5463d2017-02-25 20:40:46 +0100413 endif
414endfunc
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200415
Bram Moolenaar0c1e3742019-12-27 13:49:24 +0100416func Test_renderoptions()
417 " Only do this for Windows Vista and later, fails on Windows XP and earlier.
418 " Doesn't hurt to do this on a non-Windows system.
419 if windowsversion() !~ '^[345]\.'
420 set renderoptions=type:directx
421 set rop=type:directx
422 endif
423endfunc
424
Bram Moolenaara701b3b2017-04-20 22:57:27 +0200425func ResetIndentexpr()
426 set indentexpr=
427endfunc
428
429func Test_set_indentexpr()
430 " this was causing usage of freed memory
431 set indentexpr=ResetIndentexpr()
432 new
433 call feedkeys("i\<c-f>", 'x')
434 call assert_equal('', &indentexpr)
435 bwipe!
436endfunc
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200437
438func Test_backupskip()
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100439 " Option 'backupskip' may contain several comma-separated path
440 " specifications if one or more of the environment variables TMPDIR, TMP,
441 " or TEMP is defined. To simplify testing, convert the string value into a
442 " list.
443 let bsklist = split(&bsk, ',')
444
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200445 if has("mac")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100446 let found = (index(bsklist, '/private/tmp/*') >= 0)
447 call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200448 elseif has("unix")
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100449 let found = (index(bsklist, '/tmp/*') >= 0)
450 call assert_true(found, '/tmp not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200451 endif
452
Bram Moolenaar98ad1e12019-01-30 21:51:27 +0100453 " If our test platform is Windows, the path(s) in option bsk will use
454 " backslash for the path separator and the components could be in short
455 " (8.3) format. As such, we need to replace the backslashes with forward
456 " slashes and convert the path components to long format. The expand()
457 " function will do this but it cannot handle comma-separated paths. This is
458 " why bsk was converted from a string into a list of strings above.
459 "
460 " One final complication is that the wildcard "/*" is at the end of each
461 " path and so expand() might return a list of matching files. To prevent
462 " this, we need to remove the wildcard before calling expand() and then
463 " append it afterwards.
464 if has('win32')
465 let item_nbr = 0
466 while item_nbr < len(bsklist)
467 let path_spec = bsklist[item_nbr]
468 let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
469 let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
470 let bsklist[item_nbr] = path_spec . '/*'
471 let item_nbr += 1
472 endwhile
473 endif
474
475 " Option bsk will also include these environment variables if defined.
476 " If they're defined, verify they appear in the option value.
477 for var in ['$TMPDIR', '$TMP', '$TEMP']
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200478 if exists(var)
479 let varvalue = substitute(expand(var), '\\', '/', 'g')
Bram Moolenaarcbbd0f62019-01-30 22:36:18 +0100480 let varvalue = substitute(varvalue, '/$', '', '')
481 let varvalue .= '/*'
482 let found = (index(bsklist, varvalue) >= 0)
483 call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200484 endif
485 endfor
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200486
487 " Duplicates should be filtered out (option has P_NODUP)
488 let backupskip = &backupskip
489 set backupskip=
490 set backupskip+=/test/dir
491 set backupskip+=/other/dir
492 set backupskip+=/test/dir
493 call assert_equal('/test/dir,/other/dir', &backupskip)
494 let &backupskip = backupskip
Bram Moolenaarb8e22a02018-04-12 21:37:34 +0200495endfunc
Bram Moolenaar25782a72018-05-13 18:05:33 +0200496
497func Test_copy_winopt()
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200498 set hidden
Bram Moolenaar25782a72018-05-13 18:05:33 +0200499
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200500 " Test copy option from current buffer in window
501 split
502 enew
503 setlocal numberwidth=5
504 wincmd w
505 call assert_equal(4,&numberwidth)
506 bnext
507 call assert_equal(5,&numberwidth)
508 bw!
509 call assert_equal(4,&numberwidth)
Bram Moolenaar25782a72018-05-13 18:05:33 +0200510
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200511 " Test copy value from window that used to be display the buffer
512 split
513 enew
514 setlocal numberwidth=6
515 bnext
516 wincmd w
517 call assert_equal(4,&numberwidth)
518 bnext
519 call assert_equal(6,&numberwidth)
520 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200521
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200522 " Test that if buffer is current, don't use the stale cached value
523 " from the last time the buffer was displayed.
524 split
525 enew
526 setlocal numberwidth=7
527 bnext
528 bnext
529 setlocal numberwidth=8
530 wincmd w
531 call assert_equal(4,&numberwidth)
532 bnext
533 call assert_equal(8,&numberwidth)
534 bw!
Bram Moolenaar25782a72018-05-13 18:05:33 +0200535
Bram Moolenaar7cb33a12018-08-23 22:20:35 +0200536 " Test value is not copied if window already has seen the buffer
537 enew
538 split
539 setlocal numberwidth=9
540 bnext
541 setlocal numberwidth=10
542 wincmd w
543 call assert_equal(4,&numberwidth)
544 bnext
545 call assert_equal(4,&numberwidth)
546 bw!
547
548 set hidden&
Bram Moolenaar25782a72018-05-13 18:05:33 +0200549endfunc
Bram Moolenaarfc089602018-06-24 16:53:35 +0200550
551func Test_shortmess_F()
552 new
553 call assert_match('\[No Name\]', execute('file'))
554 set shortmess+=F
555 call assert_match('\[No Name\]', execute('file'))
556 call assert_match('^\s*$', execute('file foo'))
557 call assert_match('foo', execute('file'))
558 set shortmess-=F
559 call assert_match('bar', execute('file bar'))
560 call assert_match('bar', execute('file'))
561 set shortmess&
562 bwipe
563endfunc
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200564
565func Test_shortmess_F2()
566 e file1
567 e file2
568 call assert_match('file1', execute('bn', ''))
569 call assert_match('file2', execute('bn', ''))
570 set shortmess+=F
571 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200572 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200573 call assert_true(empty(execute('bn', '')))
Bram Moolenaarce90e362019-09-08 18:58:44 +0200574 call assert_false('need_fileinfo'->test_getvalue())
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200575 set hidden
576 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200577 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200578 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200579 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200580 set nohidden
581 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200582 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200583 call assert_true(empty(execute('bn', '')))
Bram Moolenaareda65222019-05-16 20:29:44 +0200584 call assert_false(test_getvalue('need_fileinfo'))
Bram Moolenaar2f0f8712018-08-21 18:50:18 +0200585 set shortmess&
586 call assert_match('file1', execute('bn', ''))
587 call assert_match('file2', execute('bn', ''))
588 bwipe
589 bwipe
590endfunc
Bram Moolenaar375e3392019-01-31 18:26:10 +0100591
592func Test_local_scrolloff()
593 set so=5
594 set siso=7
595 split
596 call assert_equal(5, &so)
597 setlocal so=3
598 call assert_equal(3, &so)
599 wincmd w
600 call assert_equal(5, &so)
601 wincmd w
602 setlocal so<
603 call assert_equal(5, &so)
604 setlocal so=0
605 call assert_equal(0, &so)
606 setlocal so=-1
607 call assert_equal(5, &so)
608
609 call assert_equal(7, &siso)
610 setlocal siso=3
611 call assert_equal(3, &siso)
612 wincmd w
613 call assert_equal(7, &siso)
614 wincmd w
615 setlocal siso<
616 call assert_equal(7, &siso)
617 setlocal siso=0
618 call assert_equal(0, &siso)
619 setlocal siso=-1
620 call assert_equal(7, &siso)
621
622 close
623 set so&
624 set siso&
625endfunc
Bram Moolenaar449ac472019-04-03 21:42:35 +0200626
627func Test_writedelay()
Bram Moolenaar5feabe02020-01-30 18:24:53 +0100628 CheckFunction reltimefloat
629
Bram Moolenaar449ac472019-04-03 21:42:35 +0200630 new
631 call setline(1, 'empty')
632 redraw
633 set writedelay=10
634 let start = reltime()
635 call setline(1, repeat('x', 70))
636 redraw
637 let elapsed = reltimefloat(reltime(start))
638 set writedelay=0
639 " With 'writedelay' set should take at least 30 * 10 msec
640 call assert_inrange(30 * 0.01, 999.0, elapsed)
641
642 bwipe!
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200643endfunc
644
645func Test_visualbell()
Bram Moolenaar7a666272019-04-03 22:52:34 +0200646 set belloff=
Bram Moolenaarb4e6a2d2019-04-03 21:53:33 +0200647 set visualbell
648 call assert_beeps('normal 0h')
649 set novisualbell
Bram Moolenaar7a666272019-04-03 22:52:34 +0200650 set belloff=all
Bram Moolenaar449ac472019-04-03 21:42:35 +0200651endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100652
653" Test for the 'write' option
654func Test_write()
655 new
656 call setline(1, ['L1'])
657 set nowrite
658 call assert_fails('write Xfile', 'E142:')
659 set write
660 close!
661endfunc
662
663" Test for 'buftype' option
664func Test_buftype()
665 new
666 call setline(1, ['L1'])
667 set buftype=nowrite
668 call assert_fails('write', 'E382:')
Bram Moolenaara3a9c8e2020-03-19 12:38:34 +0100669
670 for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
671 exe 'set buftype=' .. val
672 call writefile(['something'], 'XBuftype')
673 call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
674 endfor
675
676 call delete('XBuftype')
677 bwipe!
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100678endfunc
679
Bram Moolenaarea3db912020-02-02 15:32:13 +0100680" Test for the 'shellquote' option
681func Test_shellquote()
682 CheckUnix
683 set shellquote=#
684 set verbose=20
685 redir => v
686 silent! !echo Hello
687 redir END
688 set verbose&
689 set shellquote&
690 call assert_match(': "#echo Hello#"', v)
691endfunc
692
Bram Moolenaar578fe942020-02-27 21:32:51 +0100693" Test for the 'rightleftcmd' option
694func Test_rightleftcmd()
695 CheckFeature rightleft
696 set rightleft
697 set rightleftcmd
698
699 let g:l = []
700 func AddPos()
701 call add(g:l, screencol())
702 return ''
703 endfunc
704 cmap <expr> <F2> AddPos()
705
706 call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
707 \ "\<Left>\<F2>\<Esc>", 'xt')
708 call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
709
710 cunmap <F2>
711 unlet g:l
712 set rightleftcmd&
713 set rightleft&
714endfunc
715
Bram Moolenaarcde0ff32020-04-04 14:00:39 +0200716" Test for the "debug" option
717func Test_debug_option()
718 set debug=beep
719 exe "normal \<C-c>"
720 call assert_equal('Beep!', Screenline(&lines))
721 set debug&
722endfunc
723
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100724" vim: shiftwidth=2 sts=2 expandtab