blob: fc1fd571b57320a035a6047a402f1692d07241f3 [file] [log] [blame]
Guido van Rossum8e0ce301997-07-11 19:34:44 +00001# Re test suite and benchmark suite v1.5a2
2
3# The 3 possible outcomes for each pattern
4[SUCCEED, FAIL, SYNTAX_ERROR] = range(3)
5
6# Benchmark suite (needs expansion)
7#
8# The benchmark suite does not test correctness, just speed. The
9# first element of each tuple is the regex pattern; the second is a
10# string to match it against. The benchmarking code will embed the
11# second string inside several sizes of padding, to test how regex
12# matching performs on large strings.
13
14benchmarks = [
15 ('Python', 'Python'), # Simple text literal
16 ('.*Python', 'Python'), # Bad text literal
17 ('.*Python.*', 'Python'), # Worse text literal
18 ('.*(Python)', 'Python'), # Bad text literal with grouping
19
20 ('(Python|Perl|Tcl', 'Perl'), # Alternation
21 ('(Python|Perl|Tcl)', 'Perl'), # Grouped alternation
22 ('(Python)\\1', 'PythonPython'), # Backreference
23 ('([0a-z][a-z]*,)+', 'a5,b7,c9,'), # Disable the fastmap optimization
24 ('([a-z][a-z0-9]*,)+', 'a5,b7,c9,') # A few sets
25]
26
27# Test suite (for verifying correctness)
28#
29# The test suite is a list of 5- or 3-tuples. The 5 parts of a
30# complete tuple are:
31# element 0: a string containing the pattern
32# 1: the string to match against the pattern
33# 2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR)
34# 3: a string that will be eval()'ed to produce a test string.
35# This is an arbitrary Python expression; the available
36# variables are "found" (the whole match), and "g1", "g2", ...
37# up to "g10" contain the contents of each group, or the
38# string 'None' if the group wasn't given a value.
39# 4: The expected result of evaluating the expression.
40# If the two don't match, an error is reported.
41#
42# If the regex isn't expected to work, the latter two elements can be omitted.
43
44tests = [
45('abc', 'abc', SUCCEED,
46 'found', 'abc'),
47('abc', 'xbc', FAIL),
48('abc', 'axc', FAIL),
49('abc', 'abx', FAIL),
50('abc', 'xabcy', SUCCEED,
51 'found', 'abc'),
52('abc', 'ababc', SUCCEED,
53 'found', 'abc'),
54('ab*c', 'abc', SUCCEED,
55 'found', 'abc'),
56('ab*bc', 'abc', SUCCEED,
57 'found', 'abc'),
58('ab*bc', 'abbc', SUCCEED,
59 'found', 'abbc'),
60('ab*bc', 'abbbbc', SUCCEED,
61 'found', 'abbbbc'),
62('ab+bc', 'abbc', SUCCEED,
63 'found', 'abbc'),
64('ab+bc', 'abc', FAIL),
65('ab+bc', 'abq', FAIL),
66('ab+bc', 'abbbbc', SUCCEED,
67 'found', 'abbbbc'),
68('ab?bc', 'abbc', SUCCEED,
69 'found', 'abbc'),
70('ab?bc', 'abc', SUCCEED,
71 'found', 'abc'),
72('ab?bc', 'abbbbc', FAIL),
73('ab?c', 'abc', SUCCEED,
74 'found', 'abc'),
75('^abc$', 'abc', SUCCEED,
76 'found', 'abc'),
77('^abc$', 'abcc', FAIL),
78('^abc', 'abcc', SUCCEED,
79 'found', 'abc'),
80('^abc$', 'aabc', FAIL),
81('abc$', 'aabc', SUCCEED,
82 'found', 'abc'),
83('^', 'abc', SUCCEED,
84 'found+"-"', '-'),
85('$', 'abc', SUCCEED,
86 'found+"-"', '-'),
87('a.c', 'abc', SUCCEED,
88 'found', 'abc'),
89('a.c', 'axc', SUCCEED,
90 'found', 'axc'),
91('a.*c', 'axyzc', SUCCEED,
92 'found', 'axyzc'),
93('a.*c', 'axyzd', FAIL),
94('a[bc]d', 'abc', FAIL),
95('a[bc]d', 'abd', SUCCEED,
96 'found', 'abd'),
97('a[b-d]e', 'abd', FAIL),
98('a[b-d]e', 'ace', SUCCEED,
99 'found', 'ace'),
100('a[b-d]', 'aac', SUCCEED,
101 'found', 'ac'),
102('a[-b]', 'a-', SUCCEED,
103 'found', 'a-'),
104('a[b-]', 'a-', SYNTAX_ERROR),
105('a[]b', '-', SYNTAX_ERROR),
106('a[', '-', SYNTAX_ERROR),
107('a\\', '-', SYNTAX_ERROR),
108('abc)', '-', SYNTAX_ERROR),
109('(abc', '-', SYNTAX_ERROR),
110('a]', 'a]', SUCCEED,
111 'found', 'a]'),
112('a[]]b', 'a]b', SUCCEED,
113 'found', 'a]b'),
114('a[^bc]d', 'aed', SUCCEED,
115 'found', 'aed'),
116('a[^bc]d', 'abd', FAIL),
117('a[^-b]c', 'adc', SUCCEED,
118 'found', 'adc'),
119('a[^-b]c', 'a-c', FAIL),
120('a[^]b]c', 'a]c', FAIL),
121('a[^]b]c', 'adc', SUCCEED,
122 'found', 'adc'),
123('\\ba\\b', 'a-', SUCCEED,
124 '"-"', '-'),
125('\\ba\\b', '-a', SUCCEED,
126 '"-"', '-'),
127('\\ba\\b', '-a-', SUCCEED,
128 '"-"', '-'),
129('\\by\\b', 'xy', FAIL),
130('\\by\\b', 'yz', FAIL),
131('\\by\\b', 'xyz', FAIL),
132('ab|cd', 'abc', SUCCEED,
133 'found', 'ab'),
134('ab|cd', 'abcd', SUCCEED,
135 'found', 'ab'),
136('()ef', 'def', SUCCEED,
137 'found+"-"+g1', 'ef-'),
138('$b', 'b', FAIL),
139('a(b', 'a(b', SUCCEED,
140 'found+"-"+g1', 'a(b-None'),
141('a\\(*b', 'ab', SUCCEED,
142 'found', 'ab'),
143('a\\(*b', 'a((b', SUCCEED,
144 'found', 'a((b'),
145('a\\\\b', 'a\\b', SUCCEED,
146 'found', 'a\\b'),
147('((a))', 'abc', SUCCEED,
148 'found+"-"+g1+"-"+g2', 'a-a-a'),
149('(a)b(c)', 'abc', SUCCEED,
150 'found+"-"+g1+"-"+g2', 'abc-a-c'),
151('a+b+c', 'aabbabc', SUCCEED,
152 'found', 'abc'),
153('(a+|b)*', 'ab', SUCCEED,
154 'found+"-"+g1', 'ab-b'),
155('(a+|b)+', 'ab', SUCCEED,
156 'found+"-"+g1', 'ab-b'),
157('(a+|b)?', 'ab', SUCCEED,
158 'found+"-"+g1', 'a-a'),
159(')(', '-', SYNTAX_ERROR),
160('[^ab]*', 'cde', SUCCEED,
161 'found', 'cde'),
162('abc', '', FAIL),
163('a*', '', SUCCEED,
164 'found', ''),
165('a|b|c|d|e', 'e', SUCCEED,
166 'found', 'e'),
167('(a|b|c|d|e)f', 'ef', SUCCEED,
168 'found+"-"+g1', 'ef-e'),
169('abcd*efg', 'abcdefg', SUCCEED,
170 'found', 'abcdefg'),
171('ab*', 'xabyabbbz', SUCCEED,
172 'found', 'ab'),
173('ab*', 'xayabbbz', SUCCEED,
174 'found', 'a'),
175('(ab|cd)e', 'abcde', SUCCEED,
176 'found+"-"+g1', 'cde-cd'),
177('[abhgefdc]ij', 'hij', SUCCEED,
178 'found', 'hij'),
179('^(ab|cd)e', 'abcde', FAIL,
180 'xg1y', 'xy'),
181('(abc|)ef', 'abcdef', SUCCEED,
182 'found+"-"+g1', 'ef-'),
183('(a|b)c*d', 'abcd', SUCCEED,
184 'found+"-"+g1', 'bcd-b'),
185('(ab|ab*)bc', 'abc', SUCCEED,
186 'found+"-"+g1', 'abc-a'),
187('a([bc]*)c*', 'abc', SUCCEED,
188 'found+"-"+g1', 'abc-bc'),
189('a([bc]*)(c*d)', 'abcd', SUCCEED,
190 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
191('a([bc]+)(c*d)', 'abcd', SUCCEED,
192 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
193('a([bc]*)(c+d)', 'abcd', SUCCEED,
194 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),
195('a[bcd]*dcdcde', 'adcdcde', SUCCEED,
196 'found', 'adcdcde'),
197('a[bcd]+dcdcde', 'adcdcde', FAIL),
198('(ab|a)b*c', 'abc', SUCCEED,
199 'found+"-"+g1', 'abc-ab'),
200('((a)(b)c)(d)', 'abcd', SUCCEED,
201 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),
202('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED,
203 'found', 'alpha'),
204('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED,
205 'found+"-"+g1', 'bh-None'),
206('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED,
207 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
208('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED,
209 'found+"-"+g1+"-"+g2', 'ij-ij-j'),
210('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL),
211('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL),
212('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED,
213 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
214('(((((((((a)))))))))', 'a', SUCCEED,
215 'found', 'a'),
216('multiple words of text', 'uh-uh', FAIL),
217('multiple words', 'multiple words, yeah', SUCCEED,
218 'found', 'multiple words'),
219('(.*)c(.*)', 'abcde', SUCCEED,
220 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),
221('((.*), (.*))', '(a, b)', SUCCEED,
222 'g2+"-"+g1', 'b-a'),
223('[k]', 'ab', FAIL),
224('a[-]?c', 'ac', SUCCEED,
225 'found', 'ac'),
226('(abc)\\1', 'abcabc', SUCCEED,
227 'g1', 'abc'),
228('([a-c]*)\\1', 'abcabc', SUCCEED,
229 'g1', 'abc'),
230('^(.+)?B', 'AB', SUCCEED,
231 'g1', 'A'),
232('(a+).\\1$', 'aaaaa', SUCCEED,
233 'found+"-"+g1', 'aaaaa-aa'),
234('^(a+).\\1$', 'aaaa', FAIL),
235('(abc)\\1', 'abcabc', SUCCEED,
236 'found+"-"+g1', 'abcabc-abc'),
237('([a-c]+)\\1', 'abcabc', SUCCEED,
238 'found+"-"+g1', 'abcabc-abc'),
239('(a)\\1', 'aa', SUCCEED,
240 'found+"-"+g1', 'aa-a'),
241('(a+)\\1', 'aa', SUCCEED,
242 'found+"-"+g1', 'aa-a'),
243('(a+)+\\1', 'aa', SUCCEED,
244 'found+"-"+g1', 'aa-a'),
245('(a).+\\1', 'aba', SUCCEED,
246 'found+"-"+g1', 'aba-a'),
247('(a)ba*\\1', 'aba', SUCCEED,
248 'found+"-"+g1', 'aba-a'),
249('(aa|a)a\\1$', 'aaa', SUCCEED,
250 'found+"-"+g1', 'aaa-a'),
251('(a|aa)a\\1$', 'aaa', SUCCEED,
252 'found+"-"+g1', 'aaa-a'),
253('(a+)a\\1$', 'aaa', SUCCEED,
254 'found+"-"+g1', 'aaa-a'),
255('([abc]*)\\1', 'abcabc', SUCCEED,
256 'found+"-"+g1', 'abcabc-abc'),
257('(a)(b)c|ab', 'ab', SUCCEED,
258 'found+"-"+g1+"-"+g2', 'ab-None-None'),
259('(a)+x', 'aaax', SUCCEED,
260 'found+"-"+g1', 'aaax-a'),
261('([ac])+x', 'aacx', SUCCEED,
262 'found+"-"+g1', 'aacx-c'),
263('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED,
264 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'),
265('([^.]*)\\.([^:]*):[T ]+(.*)', 'track1.title:TBlah blah blah', SUCCEED,
266 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'),
267('([^N]*N)+', 'abNNxyzN', SUCCEED,
268 'found+"-"+g1', 'abNNxyzN-xyzN'),
269('([^N]*N)+', 'abNNxyz', SUCCEED,
270 'found+"-"+g1', 'abNN-N'),
271('([abc]*)x', 'abcx', SUCCEED,
272 'found+"-"+g1', 'abcx-abc'),
273('([abc]*)x', 'abc', FAIL),
274('([xyz]*)x', 'abcx', SUCCEED,
275 'found+"-"+g1', 'x-'),
276('(a)+b|aac', 'aac', SUCCEED,
277 'found+"-"+g1', 'aac-None'),
278]