1 Test for regexp patterns.
3 A pattern that gives the expected result produces OK, so that we know it was
8 :" tl is a List of Lists with:
10 :" text to test the pattern on
11 :" expected match (optional)
12 :" expected submatch 1 (optional)
13 :" expected submatch 2 (optional)
15 :" When there is no match use only the first two items.
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'])
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] . '\"'
36 :" check all the nine submatches
37 : for i in range(1, 9)
44 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
51 :/^Results/,$wq! test.out