Bram Moolenaar | 4d2fffc | 2007-08-14 15:29:16 +0000 | [diff] [blame^] | 1 | Test for regexp patterns. |
| 2 | |
| 3 | A pattern that gives the expected result produces OK, so that we know it was |
| 4 | actually tried. |
| 5 | |
| 6 | STARTTEST |
| 7 | :so small.vim |
| 8 | :" tl is a List of Lists with: |
| 9 | :" regexp pattern |
| 10 | :" text to test the pattern on |
| 11 | :" expected match (optional) |
| 12 | :" expected submatch 1 (optional) |
| 13 | :" expected submatch 2 (optional) |
| 14 | :" etc. |
| 15 | :" When there is no match use only the first two items. |
| 16 | :let tl = [] |
| 17 | :call add(tl, ['b', 'abcdef', 'b']) |
| 18 | :call add(tl, ['bc*', 'abccccdef', 'bcccc']) |
| 19 | :call add(tl, ['bc\{-}', 'abccccdef', 'b']) |
| 20 | :call add(tl, ['bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd']) |
| 21 | :call add(tl, ['x', 'abcdef']) |
| 22 | :" |
| 23 | :for t in tl |
| 24 | : let l = matchlist(t[1], t[0]) |
| 25 | :" check the match itself |
| 26 | : if len(l) == 0 && len(t) > 2 |
| 27 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", did not match, expected: \"' . t[2] . '\"' |
| 28 | : elseif len(l) > 0 && len(t) == 2 |
| 29 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected no match' |
| 30 | : elseif len(t) > 2 && l[0] != t[2] |
| 31 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected: \"' . t[2] . '\"' |
| 32 | : else |
| 33 | : $put ='OK' |
| 34 | : endif |
| 35 | : if len(l) > 0 |
| 36 | :" check all the nine submatches |
| 37 | : for i in range(1, 9) |
| 38 | : if len(t) <= i + 2 |
| 39 | : let e = '' |
| 40 | : else |
| 41 | : let e = t[i + 2] |
| 42 | : endif |
| 43 | : if l[i] != e |
| 44 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' |
| 45 | : endif |
| 46 | : endfor |
| 47 | : endif |
| 48 | :endfor |
| 49 | :/^Results/,$wq! test.out |
| 50 | ENDTEST |
| 51 | |
| 52 | Results of test64: |