Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 1 | Tests for the exists() function. vim: set ft=vim : |
| 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 |
| 14 | autocmd! BufEnter *.my echo 'myfile edited' |
| 15 | augroup END |
| 16 | redir! > test.out |
| 17 | |
| 18 | " valid autocmd group |
| 19 | call RunTest('#myagroup', 1) |
| 20 | |
| 21 | " Valid autocmd group and event |
| 22 | call RunTest('#myagroup#BufEnter', 1) |
| 23 | |
| 24 | " Valid autocmd group, event and pattern |
| 25 | call RunTest('#myagroup#BufEnter#*.my', 1) |
| 26 | |
| 27 | " Valid autocmd event |
| 28 | call RunTest('#BufEnter', 1) |
| 29 | |
| 30 | " Valid autocmd event and pattern |
| 31 | call RunTest('#BufEnter#*.my', 1) |
| 32 | |
| 33 | " Non-existing autocmd group or event |
| 34 | call RunTest('#xyzagroup', 0) |
| 35 | |
| 36 | " Non-existing autocmd group and valid autocmd event |
| 37 | call RunTest('#xyzagroup#BufEnter', 0) |
| 38 | |
| 39 | " Valid autocmd group and autocmd event with no matching pattern |
| 40 | call RunTest('#myagroup#CmdwinEnter', 0) |
| 41 | |
| 42 | " Valid autocmd group and non-existing autocmd event |
| 43 | call RunTest('#myagroup#xyzacmd', 0) |
| 44 | |
| 45 | " Valid autocmd group and event and non-matching pattern |
| 46 | call RunTest('#myagroup#BufEnter#xyzpat', 0) |
| 47 | |
| 48 | " Valid autocmd event and non-matching pattern |
| 49 | call RunTest('#BufEnter#xyzpat', 0) |
| 50 | |
| 51 | " Empty autocmd group, event and pattern |
| 52 | call RunTest('###', 0) |
| 53 | |
| 54 | " Empty autocmd group and event or event and pattern |
| 55 | call RunTest('##', 0) |
| 56 | |
| 57 | " Testing support for event name that exists. |
| 58 | call RunTest('##SwapExists', 1) |
| 59 | |
| 60 | " Testing support for event name that doesn't exist. |
| 61 | call RunTest('##SwapNotExists', 0) |
| 62 | |
| 63 | redir END |
| 64 | endfunction |
| 65 | :call TestExists() |
| 66 | :edit! test.out |
| 67 | :set ff=unix |
| 68 | :w |
| 69 | :qa! |
| 70 | ENDTEST |
| 71 | |