blob: 4435343ac3ffccffbc6bd975e50f497a3067b338 [file] [log] [blame]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +00001Tests for the exists() function. vim: set ft=vim :
2
3STARTTEST
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
11endfunction
12:function! TestExists()
13 augroup myagroup
14 autocmd! BufEnter *.my echo 'myfile edited'
15 augroup END
Bram Moolenaar8fa04452005-12-23 22:13:51 +000016
17 let test_cases = []
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000018
19 " valid autocmd group
Bram Moolenaar8fa04452005-12-23 22:13:51 +000020 let test_cases += [['#myagroup', 1]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000021 " Valid autocmd group and event
Bram Moolenaar8fa04452005-12-23 22:13:51 +000022 let test_cases += [['#myagroup#BufEnter', 1]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000023 " Valid autocmd group, event and pattern
Bram Moolenaar8fa04452005-12-23 22:13:51 +000024 let test_cases += [['#myagroup#BufEnter#*.my', 1]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000025 " Valid autocmd event
Bram Moolenaar8fa04452005-12-23 22:13:51 +000026 let test_cases += [['#BufEnter', 1]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000027 " Valid autocmd event and pattern
Bram Moolenaar8fa04452005-12-23 22:13:51 +000028 let test_cases += [['#BufEnter#*.my', 1]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000029 " Non-existing autocmd group or event
Bram Moolenaar8fa04452005-12-23 22:13:51 +000030 let test_cases += [['#xyzagroup', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000031 " Non-existing autocmd group and valid autocmd event
Bram Moolenaar8fa04452005-12-23 22:13:51 +000032 let test_cases += [['#xyzagroup#BufEnter', 0]]
33 " Valid autocmd group and event with no matching pattern
34 let test_cases += [['#myagroup#CmdwinEnter', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000035 " Valid autocmd group and non-existing autocmd event
Bram Moolenaar8fa04452005-12-23 22:13:51 +000036 let test_cases += [['#myagroup#xyzacmd', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000037 " Valid autocmd group and event and non-matching pattern
Bram Moolenaar8fa04452005-12-23 22:13:51 +000038 let test_cases += [['#myagroup#BufEnter#xyzpat', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000039 " Valid autocmd event and non-matching pattern
Bram Moolenaar8fa04452005-12-23 22:13:51 +000040 let test_cases += [['#BufEnter#xyzpat', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000041 " Empty autocmd group, event and pattern
Bram Moolenaar8fa04452005-12-23 22:13:51 +000042 let test_cases += [['###', 0]]
43 " Empty autocmd group and event or empty event and pattern
44 let test_cases += [['##', 0]]
45 " Valid autocmd event
46 let test_cases += [['##FileReadCmd', 1]]
47 " Non-existing autocmd event
48 let test_cases += [['##MySpecialCmd', 0]]
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000049
Bram Moolenaar8fa04452005-12-23 22:13:51 +000050 redir! > test.out
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000051
Bram Moolenaar8fa04452005-12-23 22:13:51 +000052 for [test_case, result] in test_cases
53 echo test_case . ": " . result
54 call RunTest(test_case, result)
55 endfor
Bram Moolenaarf4cd3e82005-12-22 22:47:02 +000056
57 redir END
58endfunction
59:call TestExists()
60:edit! test.out
61:set ff=unix
62:w
63:qa!
64ENDTEST
65