1357
|
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 = []
|
1465
|
17 :call add(tl, ['ab', 'aab', 'ab'])
|
1357
|
18 :call add(tl, ['b', 'abcdef', 'b'])
|
|
19 :call add(tl, ['bc*', 'abccccdef', 'bcccc'])
|
|
20 :call add(tl, ['bc\{-}', 'abccccdef', 'b'])
|
|
21 :call add(tl, ['bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd'])
|
1465
|
22 :call add(tl, ['bc*', 'abbdef', 'b'])
|
|
23 :call add(tl, ['c*', 'ccc', 'ccc'])
|
|
24 :call add(tl, ['bc*', 'abdef', 'b'])
|
|
25 :call add(tl, ['c*', 'abdef', ''])
|
|
26 :call add(tl, ['bc\+', 'abccccdef', 'bcccc'])
|
|
27 :call add(tl, ['bc\+', 'abdef']) "no match
|
|
28 :"
|
|
29 :"operator \|
|
|
30 :call add(tl, ['a\|ab', 'cabd', 'a']) "alternation is ordered
|
|
31 :"
|
|
32 :call add(tl, ['c\?', 'ccb', 'c'])
|
|
33 :call add(tl, ['bc\?', 'abd', 'b'])
|
|
34 :call add(tl, ['bc\?', 'abccd', 'bc'])
|
|
35 :"
|
|
36 :call add(tl, ['\va{1}', 'ab', 'a'])
|
|
37 :"
|
|
38 :call add(tl, ['\va{2}', 'aa', 'aa'])
|
|
39 :call add(tl, ['\va{2}', 'caad', 'aa'])
|
|
40 :call add(tl, ['\va{2}', 'aba'])
|
|
41 :call add(tl, ['\va{2}', 'ab'])
|
|
42 :call add(tl, ['\va{2}', 'abaa', 'aa'])
|
|
43 :call add(tl, ['\va{2}', 'aaa', 'aa'])
|
|
44 :"
|
|
45 :call add(tl, ['\vb{1}', 'abca', 'b'])
|
|
46 :call add(tl, ['\vba{2}', 'abaa', 'baa'])
|
|
47 :call add(tl, ['\vba{3}', 'aabaac'])
|
|
48 :"
|
|
49 :call add(tl, ['\v(ab){1}', 'ab', 'ab', 'ab'])
|
|
50 :call add(tl, ['\v(ab){1}', 'dabc', 'ab', 'ab'])
|
|
51 :call add(tl, ['\v(ab){1}', 'acb'])
|
|
52 :"
|
|
53 :call add(tl, ['\v(ab){0,2}', 'acb', "", ""])
|
|
54 :call add(tl, ['\v(ab){0,2}', 'ab', 'ab', 'ab'])
|
|
55 :call add(tl, ['\v(ab){1,2}', 'ab', 'ab', 'ab'])
|
|
56 :call add(tl, ['\v(ab){1,2}', 'ababc', 'abab', 'ab'])
|
|
57 :call add(tl, ['\v(ab){2,4}', 'ababcab', 'abab', 'ab'])
|
|
58 :call add(tl, ['\v(ab){2,4}', 'abcababa', 'abab', 'ab'])
|
|
59 :"
|
|
60 :call add(tl, ['\v(ab){2}', 'abab', 'abab', 'ab'])
|
|
61 :call add(tl, ['\v(ab){2}', 'cdababe', 'abab', 'ab'])
|
|
62 :call add(tl, ['\v(ab){2}', 'abac'])
|
|
63 :call add(tl, ['\v(ab){2}', 'abacabab', 'abab', 'ab'])
|
|
64 :call add(tl, ['\v((ab){2}){2}', 'abababab', 'abababab', 'abab', 'ab'])
|
|
65 :call add(tl, ['\v((ab){2}){2}', 'abacabababab', 'abababab', 'abab', 'ab'])
|
|
66 :"
|
|
67 :call add(tl, ['\v(a{1}){1}', 'a', 'a', 'a'])
|
|
68 :call add(tl, ['\v(a{2}){1}', 'aa', 'aa', 'aa'])
|
|
69 :call add(tl, ['\v(a{2}){1}', 'aaac', 'aa', 'aa'])
|
|
70 :call add(tl, ['\v(a{2}){1}', 'daaac', 'aa', 'aa'])
|
|
71 :call add(tl, ['\v(a{1}){2}', 'daaac', 'aa', 'a'])
|
|
72 :call add(tl, ['\v(a{1}){2}', 'aaa', 'aa', 'a'])
|
|
73 :call add(tl, ['\v(a{2})+', 'adaac', 'aa', 'aa'])
|
|
74 :call add(tl, ['\v(a{2})+', 'aa', 'aa', 'aa'])
|
|
75 :call add(tl, ['\v(a{2}){1}', 'aa', 'aa', 'aa'])
|
|
76 :call add(tl, ['\v(a{1}){2}', 'aa', 'aa', 'a'])
|
|
77 :call add(tl, ['\v(a{1}){1}', 'a', 'a', 'a'])
|
|
78 :call add(tl, ['\v(a{2}){2}', 'aaaa', 'aaaa', 'aa'])
|
|
79 :call add(tl, ['\v(a{2}){2}', 'aaabaaaa', 'aaaa', 'aa'])
|
|
80 :"
|
|
81 :call add(tl, ['\v(a+){2}', 'dadaac', 'aa', 'a'])
|
|
82 :call add(tl, ['\v(a{3}){2}', 'aaaaaaa', 'aaaaaa', 'aaa'])
|
|
83 :"
|
|
84 :call add(tl, ['\v(a{1,2}){2}', 'daaac', 'aaa', 'a'])
|
|
85 :call add(tl, ['\v(a{1,3}){2}', 'daaaac', 'aaaa', 'a'])
|
|
86 :call add(tl, ['\v(a{1,3}){2}', 'daaaaac', 'aaaaa', 'aa'])
|
|
87 :call add(tl, ['\v(a{1,3}){3}', 'daac'])
|
|
88 :call add(tl, ['\v(a{1,2}){2}', 'dac'])
|
|
89 :call add(tl, ['\v(a+)+', 'daac', 'aa', 'aa'])
|
|
90 :call add(tl, ['\v(a+)+', 'aaa', 'aaa', 'aaa'])
|
|
91 :call add(tl, ['\v(a+){1,2}', 'aaa', 'aaa', 'aaa'])
|
|
92 :call add(tl, ['\v(a+)(a+)', 'aaa', 'aaa', 'aa', 'a'])
|
|
93 :call add(tl, ['\v(a{3})+', 'daaaac', 'aaa', 'aaa'])
|
|
94 :call add(tl, ['\v(a|b|c)+', 'aacb', 'aacb', 'b'])
|
|
95 :call add(tl, ['\v(a|b|c){2}', 'abcb', 'ab', 'b'])
|
|
96 :call add(tl, ['\v(abc){2}', 'abcabd', ])
|
|
97 :call add(tl, ['\v(abc){2}', 'abdabcabc','abcabc', 'abc'])
|
|
98 :"
|
|
99 :call add(tl, ['a*', 'cc', ''])
|
|
100 :call add(tl, ['\v(a*)+', 'cc', ''])
|
|
101 :call add(tl, ['\v((ab)+)+', 'ab', 'ab', 'ab', 'ab'])
|
|
102 :call add(tl, ['\v(((ab)+)+)+', 'ab', 'ab', 'ab', 'ab', 'ab'])
|
|
103 :call add(tl, ['\v(((ab)+)+)+', 'dababc', 'abab', 'abab', 'abab', 'ab'])
|
|
104 :call add(tl, ['\v(a{0,2})+', 'cc', ''])
|
|
105 :call add(tl, ['\v(a*)+', '', ''])
|
|
106 :call add(tl, ['\v((a*)+)+', '', ''])
|
|
107 :call add(tl, ['\v((ab)*)+', '', ''])
|
|
108 :call add(tl, ['\va{1,3}', 'aab', 'aa'])
|
|
109 :call add(tl, ['\va{2,3}', 'abaa', 'aa'])
|
|
110 :"
|
|
111 :call add(tl, ['\v((ab)+|c*)+', 'abcccaba', 'abcccab', '', 'ab'])
|
|
112 :call add(tl, ['\v(a{2})|(b{3})', 'bbabbbb', 'bbb', '', 'bbb'])
|
|
113 :call add(tl, ['\va{2}|b{2}', 'abab'])
|
|
114 :call add(tl, ['\v(a)+|(c)+', 'bbacbaacbbb', 'a', 'a'])
|
|
115 :call add(tl, ['\vab{2,3}c', 'aabbccccccccccccc', 'abbc'])
|
|
116 :call add(tl, ['\vab{2,3}c', 'aabbbccccccccccccc', 'abbbc'])
|
|
117 :call add(tl, ['\vab{2,3}cd{2,3}e', 'aabbbcddee', 'abbbcdde'])
|
|
118 :call add(tl, ['\va(bc){2}d', 'aabcbfbc' ])
|
|
119 :call add(tl, ['\va*a{2}', 'a', ])
|
|
120 :call add(tl, ['\va*a{2}', 'aa', 'aa' ])
|
|
121 :call add(tl, ['\va*a{2}', 'aaa', 'aaa' ])
|
|
122 :call add(tl, ['\va*a{2}', 'bbbabcc', ])
|
|
123 :call add(tl, ['\va*b*|a*c*', 'a', 'a'])
|
|
124 :call add(tl, ['\va{1}b{1}|a{1}b{1}', ''])
|
|
125 :"
|
|
126 :"submatches
|
|
127 :call add(tl, ['\v(a)', 'ab', 'a', 'a'])
|
|
128 :call add(tl, ['\v(a)(b)', 'ab', 'ab', 'a', 'b'])
|
|
129 :call add(tl, ['\v(ab)(b)(c)', 'abbc', 'abbc', 'ab', 'b', 'c'])
|
|
130 :call add(tl, ['\v((a)(b))', 'ab', 'ab', 'ab', 'a', 'b'])
|
|
131 :call add(tl, ['\v(a)|(b)', 'ab', 'a', 'a'])
|
|
132 :"
|
|
133 :call add(tl, ['\v(a*)+', 'aaaa', 'aaaa', ''])
|
1357
|
134 :call add(tl, ['x', 'abcdef'])
|
|
135 :"
|
|
136 :for t in tl
|
|
137 : let l = matchlist(t[1], t[0])
|
|
138 :" check the match itself
|
|
139 : if len(l) == 0 && len(t) > 2
|
|
140 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", did not match, expected: \"' . t[2] . '\"'
|
|
141 : elseif len(l) > 0 && len(t) == 2
|
|
142 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected no match'
|
|
143 : elseif len(t) > 2 && l[0] != t[2]
|
|
144 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected: \"' . t[2] . '\"'
|
|
145 : else
|
|
146 : $put ='OK'
|
|
147 : endif
|
|
148 : if len(l) > 0
|
|
149 :" check all the nine submatches
|
|
150 : for i in range(1, 9)
|
|
151 : if len(t) <= i + 2
|
|
152 : let e = ''
|
|
153 : else
|
|
154 : let e = t[i + 2]
|
|
155 : endif
|
|
156 : if l[i] != e
|
|
157 : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
|
|
158 : endif
|
|
159 : endfor
|
1405
|
160 : unlet i
|
1357
|
161 : endif
|
|
162 :endfor
|
1405
|
163 :unlet t tl e l
|
1357
|
164 :/^Results/,$wq! test.out
|
|
165 ENDTEST
|
|
166
|
|
167 Results of test64:
|