OLD | NEW |
1 // Copyright 2008 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2008 The RE2 Authors. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Exhaustive testing of regular expression matching. | 5 // Exhaustive testing of regular expression matching. |
6 | 6 |
7 #include "util/test.h" | 7 #include "util/test.h" |
8 #include "re2/re2.h" | 8 #include "re2/re2.h" |
9 #include "re2/testing/exhaustive_tester.h" | 9 #include "re2/testing/exhaustive_tester.h" |
10 | 10 |
11 DECLARE_string(regexp_engines); | 11 DECLARE_string(regexp_engines); |
12 | 12 |
13 namespace re2 { | 13 namespace re2 { |
14 | 14 |
15 // Test empty string matches (aka "(?:)") | 15 // Test empty string matches (aka "(?:)") |
16 TEST(EmptyString, Exhaustive) { | 16 TEST(EmptyString, Exhaustive) { |
17 ExhaustiveTest(2, 2, Split(" ", "(?:) a"), | 17 ExhaustiveTest(2, 2, Split(" ", "(?:) a"), |
18 RegexpGenerator::EgrepOps(), | 18 RegexpGenerator::EgrepOps(), |
19 5, Split("", "ab"), "", ""); | 19 5, Split("", "ab"), "", ""); |
20 } | 20 } |
21 | 21 |
22 // Test escaped versions of regexp syntax. | 22 // Test escaped versions of regexp syntax. |
23 TEST(Punctuation, Literals) { | 23 TEST(Punctuation, Literals) { |
24 vector<string> alphabet = Explode("()*+?{}[]\\^$."); | 24 vector<string> alphabet = Explode("()*+?{}[]\\^$."); |
25 vector<string> escaped = alphabet; | 25 vector<string> escaped = alphabet; |
26 for (int i = 0; i < escaped.size(); i++) | 26 for (size_t i = 0; i < escaped.size(); i++) |
27 escaped[i] = "\\" + escaped[i]; | 27 escaped[i] = "\\" + escaped[i]; |
28 ExhaustiveTest(1, 1, escaped, RegexpGenerator::EgrepOps(), | 28 ExhaustiveTest(1, 1, escaped, RegexpGenerator::EgrepOps(), |
29 2, alphabet, "", ""); | 29 2, alphabet, "", ""); |
30 } | 30 } |
31 | 31 |
32 // Test ^ $ . \A \z in presence of line endings. | 32 // Test ^ $ . \A \z in presence of line endings. |
33 // Have to wrap the empty-width ones in (?:) so that | 33 // Have to wrap the empty-width ones in (?:) so that |
34 // they can be repeated -- PCRE rejects ^* but allows (?:^)* | 34 // they can be repeated -- PCRE rejects ^* but allows (?:^)* |
35 TEST(LineEnds, Exhaustive) { | 35 TEST(LineEnds, Exhaustive) { |
36 ExhaustiveTest(2, 2, Split(" ", "(?:^) (?:$) . a \\n (?:\\A) (?:\\z)"), | 36 ExhaustiveTest(2, 2, Split(" ", "(?:^) (?:$) . a \\n (?:\\A) (?:\\z)"), |
(...skipping 24 matching lines...) Expand all Loading... |
61 // | 61 // |
62 // TEST(Newlines, Exhaustive) { | 62 // TEST(Newlines, Exhaustive) { |
63 // vector<string> empty_vector; | 63 // vector<string> empty_vector; |
64 // ExhaustiveTest(1, 1, Split(" ", "\\n . a [^a]"), | 64 // ExhaustiveTest(1, 1, Split(" ", "\\n . a [^a]"), |
65 // RegexpGenerator::EgrepOps(), | 65 // RegexpGenerator::EgrepOps(), |
66 // 4, Explode("a\n"), ""); | 66 // 4, Explode("a\n"), ""); |
67 // } | 67 // } |
68 | 68 |
69 } // namespace re2 | 69 } // namespace re2 |
70 | 70 |
OLD | NEW |