5784
|
1 Tests for the exists() and has() functions. vim: set ft=vim ts=8 sw=2 :
|
615
|
2
|
|
3 STARTTEST
|
|
4 :so small.vim
|
|
5 :function! RunTest(str, result)
|
|
6 if exists(a:str) == a:result
|
|
7 echo "OK"
|
|
8 else
|
|
9 echo "FAILED: Checking for " . a:str
|
|
10 endif
|
|
11 endfunction
|
|
12 :function! TestExists()
|
|
13 augroup myagroup
|
5604
|
14 autocmd! BufEnter *.my echo "myfile edited"
|
|
15 autocmd! FuncUndefined UndefFun exec "fu UndefFun()\nendfu"
|
615
|
16 augroup END
|
5604
|
17 set rtp+=./sautest
|
617
|
18
|
|
19 let test_cases = []
|
615
|
20
|
|
21 " valid autocmd group
|
617
|
22 let test_cases += [['#myagroup', 1]]
|
867
|
23 " valid autocmd group with garbage
|
|
24 let test_cases += [['#myagroup+b', 0]]
|
615
|
25 " Valid autocmd group and event
|
617
|
26 let test_cases += [['#myagroup#BufEnter', 1]]
|
615
|
27 " Valid autocmd group, event and pattern
|
617
|
28 let test_cases += [['#myagroup#BufEnter#*.my', 1]]
|
615
|
29 " Valid autocmd event
|
617
|
30 let test_cases += [['#BufEnter', 1]]
|
615
|
31 " Valid autocmd event and pattern
|
617
|
32 let test_cases += [['#BufEnter#*.my', 1]]
|
615
|
33 " Non-existing autocmd group or event
|
617
|
34 let test_cases += [['#xyzagroup', 0]]
|
615
|
35 " Non-existing autocmd group and valid autocmd event
|
617
|
36 let test_cases += [['#xyzagroup#BufEnter', 0]]
|
|
37 " Valid autocmd group and event with no matching pattern
|
|
38 let test_cases += [['#myagroup#CmdwinEnter', 0]]
|
|
39 " Valid autocmd group and non-existing autocmd event
|
|
40 let test_cases += [['#myagroup#xyzacmd', 0]]
|
|
41 " Valid autocmd group and event and non-matching pattern
|
|
42 let test_cases += [['#myagroup#BufEnter#xyzpat', 0]]
|
|
43 " Valid autocmd event and non-matching pattern
|
|
44 let test_cases += [['#BufEnter#xyzpat', 0]]
|
|
45 " Empty autocmd group, event and pattern
|
|
46 let test_cases += [['###', 0]]
|
|
47 " Empty autocmd group and event or empty event and pattern
|
|
48 let test_cases += [['##', 0]]
|
|
49 " Valid autocmd event
|
|
50 let test_cases += [['##FileReadCmd', 1]]
|
|
51 " Non-existing autocmd event
|
|
52 let test_cases += [['##MySpecialCmd', 0]]
|
615
|
53
|
620
|
54 " Existing and working option (long form)
|
|
55 let test_cases += [['&textwidth', 1]]
|
|
56 " Existing and working option (short form)
|
|
57 let test_cases += [['&tw', 1]]
|
867
|
58 " Existing and working option with garbage
|
|
59 let test_cases += [['&tw-', 0]]
|
625
|
60 " Global option
|
|
61 let test_cases += [['&g:errorformat', 1]]
|
|
62 " Local option
|
|
63 let test_cases += [['&l:errorformat', 1]]
|
620
|
64 " Negative form of existing and working option (long form)
|
|
65 let test_cases += [['&nojoinspaces', 0]]
|
|
66 " Negative form of existing and working option (short form)
|
|
67 let test_cases += [['&nojs', 0]]
|
|
68 " Non-existing option
|
|
69 let test_cases += [['&myxyzoption', 0]]
|
|
70
|
|
71 " Existing and working option (long form)
|
|
72 let test_cases += [['+incsearch', 1]]
|
867
|
73 " Existing and working option with garbage
|
|
74 let test_cases += [['+incsearch!1', 0]]
|
620
|
75 " Existing and working option (short form)
|
|
76 let test_cases += [['+is', 1]]
|
|
77 " Existing option that is hidden.
|
|
78 let test_cases += [['+autoprint', 0]]
|
|
79
|
|
80 " Existing environment variable
|
|
81 let $EDITOR_NAME = 'Vim Editor'
|
|
82 let test_cases += [['$EDITOR_NAME', 1]]
|
|
83 " Non-existing environment variable
|
|
84 let test_cases += [['$NON_ENV_VAR', 0]]
|
|
85
|
|
86 " Valid internal function
|
|
87 let test_cases += [['*bufnr', 1]]
|
867
|
88 " Valid internal function with ()
|
|
89 let test_cases += [['*bufnr()', 1]]
|
620
|
90 " Non-existing internal function
|
|
91 let test_cases += [['*myxyzfunc', 0]]
|
867
|
92 " Valid internal function with garbage
|
|
93 let test_cases += [['*bufnr&6', 0]]
|
620
|
94
|
|
95 " Valid user defined function
|
|
96 let test_cases += [['*TestExists', 1]]
|
|
97 " Non-existing user defined function
|
|
98 let test_cases += [['*MyxyzFunc', 0]]
|
|
99
|
5604
|
100 " Function that may be created by FuncUndefined event
|
|
101 let test_cases += [['*UndefFun', 0]]
|
|
102 " Function that may be created by script autoloading
|
|
103 let test_cases += [['*footest#F', 0]]
|
|
104
|
617
|
105 redir! > test.out
|
615
|
106
|
617
|
107 for [test_case, result] in test_cases
|
5604
|
108 echo test_case . ": " . result
|
617
|
109 call RunTest(test_case, result)
|
|
110 endfor
|
615
|
111
|
620
|
112 " Valid internal command (full match)
|
|
113 echo ':edit: 2'
|
|
114 if exists(':edit') == 2
|
|
115 echo "OK"
|
|
116 else
|
|
117 echo "FAILED"
|
|
118 endif
|
|
119
|
867
|
120 " Valid internal command (full match) with garbage
|
|
121 echo ':edit/a: 0'
|
|
122 if exists(':edit/a') == 0
|
|
123 echo "OK"
|
|
124 else
|
|
125 echo "FAILED"
|
|
126 endif
|
|
127
|
620
|
128 " Valid internal command (partial match)
|
|
129 echo ':q: 1'
|
|
130 if exists(':q') == 1
|
|
131 echo "OK"
|
|
132 else
|
|
133 echo "FAILED"
|
|
134 endif
|
|
135
|
|
136 " Non-existing internal command
|
|
137 echo ':invalidcmd: 0'
|
|
138 if !exists(':invalidcmd')
|
|
139 echo "OK"
|
|
140 else
|
|
141 echo "FAILED"
|
|
142 endif
|
|
143
|
|
144 " User defined command (full match)
|
|
145 command! MyCmd :echo 'My command'
|
|
146 echo ':MyCmd: 2'
|
|
147 if exists(':MyCmd') == 2
|
|
148 echo "OK"
|
|
149 else
|
|
150 echo "FAILED"
|
|
151 endif
|
|
152
|
|
153 " User defined command (partial match)
|
|
154 command! MyOtherCmd :echo 'Another command'
|
|
155 echo ':My: 3'
|
|
156 if exists(':My') == 3
|
|
157 echo "OK"
|
|
158 else
|
|
159 echo "FAILED"
|
|
160 endif
|
|
161
|
|
162 " Command modifier
|
|
163 echo ':rightbelow: 2'
|
|
164 if exists(':rightbelow') == 2
|
|
165 echo "OK"
|
|
166 else
|
|
167 echo "FAILED"
|
|
168 endif
|
|
169
|
|
170 " Non-existing user defined command (full match)
|
|
171 delcommand MyCmd
|
|
172
|
|
173 echo ':MyCmd: 0'
|
|
174 if !exists(':MyCmd')
|
|
175 echo "OK"
|
|
176 else
|
|
177 echo "FAILED"
|
|
178 endif
|
|
179
|
|
180 " Non-existing user defined command (partial match)
|
|
181 delcommand MyOtherCmd
|
|
182
|
|
183 echo ':My: 0'
|
|
184 if !exists(':My')
|
|
185 echo "OK"
|
|
186 else
|
|
187 echo "FAILED"
|
|
188 endif
|
|
189
|
|
190 " Valid local variable
|
|
191 let local_var = 1
|
|
192 echo 'local_var: 1'
|
|
193 if exists('local_var')
|
|
194 echo "OK"
|
|
195 else
|
|
196 echo "FAILED"
|
|
197 endif
|
|
198
|
867
|
199 " Valid local variable with garbage
|
|
200 let local_var = 1
|
|
201 echo 'local_var%n: 0'
|
|
202 if !exists('local_var%n')
|
|
203 echo "OK"
|
|
204 else
|
|
205 echo "FAILED"
|
|
206 endif
|
|
207
|
620
|
208 " Non-existing local variable
|
|
209 unlet local_var
|
|
210 echo 'local_var: 0'
|
|
211 if !exists('local_var')
|
|
212 echo "OK"
|
|
213 else
|
|
214 echo "FAILED"
|
|
215 endif
|
|
216
|
5604
|
217 " Non-existing autoload variable that may be autoloaded
|
|
218 echo 'footest#x: 0'
|
|
219 if !exists('footest#x')
|
|
220 echo "OK"
|
|
221 else
|
|
222 echo "FAILED"
|
|
223 endif
|
|
224
|
620
|
225 " Valid local list
|
|
226 let local_list = ["blue", "orange"]
|
|
227 echo 'local_list: 1'
|
|
228 if exists('local_list')
|
|
229 echo "OK"
|
|
230 else
|
|
231 echo "FAILED"
|
|
232 endif
|
|
233
|
867
|
234 " Valid local list item
|
|
235 echo 'local_list[1]: 1'
|
|
236 if exists('local_list[1]')
|
|
237 echo "OK"
|
|
238 else
|
|
239 echo "FAILED"
|
|
240 endif
|
|
241
|
|
242 " Valid local list item with garbage
|
|
243 echo 'local_list[1]+5: 0'
|
|
244 if !exists('local_list[1]+5')
|
|
245 echo "OK"
|
|
246 else
|
|
247 echo "FAILED"
|
|
248 endif
|
|
249
|
|
250 " Invalid local list item
|
|
251 echo 'local_list[2]: 0'
|
|
252 if !exists('local_list[2]')
|
|
253 echo "OK"
|
|
254 else
|
|
255 echo "FAILED"
|
|
256 endif
|
|
257
|
620
|
258 " Non-existing local list
|
|
259 unlet local_list
|
|
260 echo 'local_list: 0'
|
|
261 if !exists('local_list')
|
|
262 echo "OK"
|
|
263 else
|
|
264 echo "FAILED"
|
|
265 endif
|
|
266
|
|
267 " Valid local dictionary
|
|
268 let local_dict = {"xcord":100, "ycord":2}
|
|
269 echo 'local_dict: 1'
|
|
270 if exists('local_dict')
|
|
271 echo "OK"
|
|
272 else
|
|
273 echo "FAILED"
|
|
274 endif
|
|
275
|
|
276 " Non-existing local dictionary
|
|
277 unlet local_dict
|
|
278 echo 'local_dict: 0'
|
|
279 if !exists('local_dict')
|
|
280 echo "OK"
|
|
281 else
|
|
282 echo "FAILED"
|
|
283 endif
|
|
284
|
625
|
285 " Existing local curly-brace variable
|
|
286 let str = "local"
|
|
287 let curly_{str}_var = 1
|
|
288 echo 'curly_' . str . '_var: 1'
|
|
289 if exists('curly_{str}_var')
|
|
290 echo "OK"
|
|
291 else
|
|
292 echo "FAILED"
|
|
293 endif
|
|
294
|
|
295 " Non-existing local curly-brace variable
|
|
296 unlet curly_{str}_var
|
|
297 echo 'curly_' . str . '_var: 0'
|
|
298 if !exists('curly_{str}_var')
|
|
299 echo "OK"
|
|
300 else
|
|
301 echo "FAILED"
|
|
302 endif
|
|
303
|
|
304
|
620
|
305 " Existing global variable
|
|
306 let g:global_var = 1
|
|
307 echo 'g:global_var: 1'
|
|
308 if exists('g:global_var')
|
|
309 echo "OK"
|
|
310 else
|
|
311 echo "FAILED"
|
|
312 endif
|
|
313
|
867
|
314 " Existing global variable with garbage
|
|
315 echo 'g:global_var-n: 1'
|
|
316 if !exists('g:global_var-n')
|
|
317 echo "OK"
|
|
318 else
|
|
319 echo "FAILED"
|
|
320 endif
|
|
321
|
620
|
322 " Non-existing global variable
|
|
323 unlet g:global_var
|
|
324 echo 'g:global_var: 0'
|
|
325 if !exists('g:global_var')
|
|
326 echo "OK"
|
|
327 else
|
|
328 echo "FAILED"
|
|
329 endif
|
|
330
|
625
|
331 " Existing global list
|
|
332 let g:global_list = ["blue", "orange"]
|
|
333 echo 'g:global_list: 1'
|
|
334 if exists('g:global_list')
|
620
|
335 echo "OK"
|
|
336 else
|
|
337 echo "FAILED"
|
|
338 endif
|
|
339
|
625
|
340 " Non-existing global list
|
|
341 unlet g:global_list
|
|
342 echo 'g:global_list: 0'
|
|
343 if !exists('g:global_list')
|
|
344 echo "OK"
|
|
345 else
|
|
346 echo "FAILED"
|
|
347 endif
|
|
348
|
|
349 " Existing global dictionary
|
|
350 let g:global_dict = {"xcord":100, "ycord":2}
|
|
351 echo 'g:global_dict: 1'
|
|
352 if exists('g:global_dict')
|
|
353 echo "OK"
|
|
354 else
|
|
355 echo "FAILED"
|
|
356 endif
|
|
357
|
|
358 " Non-existing global dictionary
|
|
359 unlet g:global_dict
|
|
360 echo 'g:global_dict: 0'
|
|
361 if !exists('g:global_dict')
|
620
|
362 echo "OK"
|
|
363 else
|
|
364 echo "FAILED"
|
|
365 endif
|
|
366
|
|
367 " Existing global curly-brace variable
|
|
368 let str = "global"
|
625
|
369 let g:curly_{str}_var = 1
|
|
370 echo 'g:curly_' . str . '_var: 1'
|
620
|
371 if exists('g:curly_{str}_var')
|
|
372 echo "OK"
|
|
373 else
|
|
374 echo "FAILED"
|
|
375 endif
|
|
376
|
|
377 " Non-existing global curly-brace variable
|
625
|
378 unlet g:curly_{str}_var
|
|
379 echo 'g:curly_' . str . '_var: 0'
|
620
|
380 if !exists('g:curly_{str}_var')
|
|
381 echo "OK"
|
|
382 else
|
|
383 echo "FAILED"
|
|
384 endif
|
|
385
|
625
|
386 " Existing window variable
|
|
387 echo 'w:window_var: 1'
|
|
388 let w:window_var = 1
|
|
389 if exists('w:window_var')
|
|
390 echo "OK"
|
|
391 else
|
|
392 echo "FAILED"
|
|
393 endif
|
|
394
|
|
395 " Non-existing window variable
|
|
396 unlet w:window_var
|
|
397 echo 'w:window_var: 0'
|
|
398 if !exists('w:window_var')
|
|
399 echo "OK"
|
|
400 else
|
|
401 echo "FAILED"
|
|
402 endif
|
|
403
|
|
404 " Existing window list
|
|
405 let w:window_list = ["blue", "orange"]
|
|
406 echo 'w:window_list: 1'
|
|
407 if exists('w:window_list')
|
|
408 echo "OK"
|
|
409 else
|
|
410 echo "FAILED"
|
|
411 endif
|
|
412
|
|
413 " Non-existing window list
|
|
414 unlet w:window_list
|
|
415 echo 'w:window_list: 0'
|
|
416 if !exists('w:window_list')
|
|
417 echo "OK"
|
|
418 else
|
|
419 echo "FAILED"
|
|
420 endif
|
|
421
|
|
422 " Existing window dictionary
|
|
423 let w:window_dict = {"xcord":100, "ycord":2}
|
|
424 echo 'w:window_dict: 1'
|
|
425 if exists('w:window_dict')
|
|
426 echo "OK"
|
|
427 else
|
|
428 echo "FAILED"
|
|
429 endif
|
|
430
|
|
431 " Non-existing window dictionary
|
|
432 unlet w:window_dict
|
|
433 echo 'w:window_dict: 0'
|
|
434 if !exists('w:window_dict')
|
|
435 echo "OK"
|
|
436 else
|
|
437 echo "FAILED"
|
|
438 endif
|
|
439
|
|
440 " Existing window curly-brace variable
|
|
441 let str = "window"
|
|
442 let w:curly_{str}_var = 1
|
|
443 echo 'w:curly_' . str . '_var: 1'
|
|
444 if exists('w:curly_{str}_var')
|
|
445 echo "OK"
|
|
446 else
|
|
447 echo "FAILED"
|
|
448 endif
|
|
449
|
|
450 " Non-existing window curly-brace variable
|
|
451 unlet w:curly_{str}_var
|
|
452 echo 'w:curly_' . str . '_var: 0'
|
|
453 if !exists('w:curly_{str}_var')
|
|
454 echo "OK"
|
|
455 else
|
|
456 echo "FAILED"
|
|
457 endif
|
|
458
|
|
459 " Existing buffer variable
|
|
460 echo 'b:buffer_var: 1'
|
|
461 let b:buffer_var = 1
|
|
462 if exists('b:buffer_var')
|
|
463 echo "OK"
|
|
464 else
|
|
465 echo "FAILED"
|
|
466 endif
|
|
467
|
|
468 " Non-existing buffer variable
|
|
469 unlet b:buffer_var
|
|
470 echo 'b:buffer_var: 0'
|
|
471 if !exists('b:buffer_var')
|
|
472 echo "OK"
|
|
473 else
|
|
474 echo "FAILED"
|
|
475 endif
|
|
476
|
|
477 " Existing buffer list
|
|
478 let b:buffer_list = ["blue", "orange"]
|
|
479 echo 'b:buffer_list: 1'
|
|
480 if exists('b:buffer_list')
|
|
481 echo "OK"
|
|
482 else
|
|
483 echo "FAILED"
|
|
484 endif
|
|
485
|
|
486 " Non-existing buffer list
|
|
487 unlet b:buffer_list
|
|
488 echo 'b:buffer_list: 0'
|
|
489 if !exists('b:buffer_list')
|
|
490 echo "OK"
|
|
491 else
|
|
492 echo "FAILED"
|
|
493 endif
|
|
494
|
|
495 " Existing buffer dictionary
|
|
496 let b:buffer_dict = {"xcord":100, "ycord":2}
|
|
497 echo 'b:buffer_dict: 1'
|
|
498 if exists('b:buffer_dict')
|
|
499 echo "OK"
|
|
500 else
|
|
501 echo "FAILED"
|
|
502 endif
|
|
503
|
|
504 " Non-existing buffer dictionary
|
|
505 unlet b:buffer_dict
|
|
506 echo 'b:buffer_dict: 0'
|
|
507 if !exists('b:buffer_dict')
|
|
508 echo "OK"
|
|
509 else
|
|
510 echo "FAILED"
|
|
511 endif
|
|
512
|
|
513 " Existing buffer curly-brace variable
|
|
514 let str = "buffer"
|
|
515 let b:curly_{str}_var = 1
|
|
516 echo 'b:curly_' . str . '_var: 1'
|
|
517 if exists('b:curly_{str}_var')
|
|
518 echo "OK"
|
|
519 else
|
|
520 echo "FAILED"
|
|
521 endif
|
|
522
|
|
523 " Non-existing buffer curly-brace variable
|
|
524 unlet b:curly_{str}_var
|
|
525 echo 'b:curly_' . str . '_var: 0'
|
|
526 if !exists('b:curly_{str}_var')
|
|
527 echo "OK"
|
|
528 else
|
|
529 echo "FAILED"
|
|
530 endif
|
|
531
|
620
|
532 " Script-local tests
|
|
533 source test60.vim
|
|
534
|
625
|
535 " Existing Vim internal variable
|
|
536 echo 'v:version: 1'
|
|
537 if exists('v:version')
|
|
538 echo "OK"
|
|
539 else
|
|
540 echo "FAILED"
|
|
541 endif
|
|
542
|
|
543 " Non-existing Vim internal variable
|
|
544 echo 'v:non_exists_var: 0'
|
|
545 if !exists('v:non_exists_var')
|
|
546 echo "OK"
|
|
547 else
|
|
548 echo "FAILED"
|
|
549 endif
|
|
550
|
|
551 " Function arguments
|
|
552 function TestFuncArg(func_arg, ...)
|
|
553 echo 'a:func_arg: 1'
|
|
554 if exists('a:func_arg')
|
|
555 echo "OK"
|
|
556 else
|
|
557 echo "FAILED"
|
|
558 endif
|
|
559
|
|
560 echo 'a:non_exists_arg: 0'
|
|
561 if !exists('a:non_exists_arg')
|
|
562 echo "OK"
|
|
563 else
|
|
564 echo "FAILED"
|
|
565 endif
|
|
566
|
|
567 echo 'a:1: 1'
|
|
568 if exists('a:1')
|
|
569 echo "OK"
|
|
570 else
|
|
571 echo "FAILED"
|
|
572 endif
|
|
573
|
|
574 echo 'a:2: 0'
|
|
575 if !exists('a:2')
|
|
576 echo "OK"
|
|
577 else
|
|
578 echo "FAILED"
|
|
579 endif
|
|
580 endfunction
|
|
581
|
|
582 call TestFuncArg("arg1", "arg2")
|
|
583
|
5604
|
584 echo ' g:footest#x =' g:footest#x
|
|
585 echo ' footest#F()' footest#F()
|
|
586 echo 'UndefFun()' UndefFun()
|
|
587
|
615
|
588 redir END
|
|
589 endfunction
|
|
590 :call TestExists()
|
5784
|
591 :"
|
|
592 :function TestHas()
|
|
593 redir >> test.out
|
|
594 for pl in ['6.9.999', '7.1.999', '7.4.123', '9.1.0', '9.9.1']
|
|
595 echo 'has patch ' . pl . ': ' . has('patch-' . pl)
|
|
596 endfor
|
|
597 redir END
|
|
598 endfunc
|
|
599 :call TestHas()
|
|
600 :"
|
1405
|
601 :delfunc TestExists
|
|
602 :delfunc RunTest
|
|
603 :delfunc TestFuncArg
|
615
|
604 :edit! test.out
|
|
605 :set ff=unix
|
|
606 :w
|
|
607 :qa!
|
5604
|
608 :while getchar(1) | call getchar() | endwhile
|
615
|
609 ENDTEST
|
|
610
|