OLD | NEW |
| (Empty) |
1 // Copyright 2008 The RE2 Authors. All Rights Reserved. | |
2 // Use of this source code is governed by a BSD-style | |
3 // license that can be found in the LICENSE file. | |
4 | |
5 // Exhaustive testing of regular expression matching. | |
6 | |
7 #include "util/test.h" | |
8 #include "re2/testing/exhaustive_tester.h" | |
9 | |
10 DECLARE_string(regexp_engines); | |
11 | |
12 namespace re2 { | |
13 | |
14 // Test simple repetition operators | |
15 TEST(Repetition, Simple) { | |
16 vector<string> ops = Split(" ", | |
17 "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} " | |
18 "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} " | |
19 "%s* %s+ %s? %s*? %s+? %s??"); | |
20 ExhaustiveTest(3, 2, Explode("abc."), ops, | |
21 6, Explode("ab"), "(?:%s)", ""); | |
22 ExhaustiveTest(3, 2, Explode("abc."), ops, | |
23 40, Explode("a"), "(?:%s)", ""); | |
24 } | |
25 | |
26 // Test capturing parens -- (a) -- inside repetition operators | |
27 TEST(Repetition, Capturing) { | |
28 vector<string> ops = Split(" ", | |
29 "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} " | |
30 "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} " | |
31 "%s* %s+ %s? %s*? %s+? %s??"); | |
32 ExhaustiveTest(3, 2, Split(" ", "a (a) b"), ops, | |
33 7, Explode("ab"), "(?:%s)", ""); | |
34 | |
35 // This would be a great test, but it runs forever when PCRE is enabled. | |
36 if (strstr("PCRE", FLAGS_regexp_engines.c_str()) == NULL) | |
37 ExhaustiveTest(4, 3, Split(" ", "a (a)"), ops, | |
38 100, Explode("a"), "(?:%s)", ""); | |
39 } | |
40 | |
41 } // namespace re2 | |
42 | |
OLD | NEW |