OLD | NEW |
1 // Copyright 2009 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2009 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 #include "util/test.h" | 5 #include "util/test.h" |
6 #include "re2/regexp.h" | 6 #include "re2/regexp.h" |
7 | 7 |
8 namespace re2 { | 8 namespace re2 { |
9 | 9 |
10 struct PrefixTest { | 10 struct PrefixTest { |
(...skipping 10 matching lines...) Expand all Loading... |
21 { "", false }, | 21 { "", false }, |
22 { "(?m)^", false }, | 22 { "(?m)^", false }, |
23 | 23 |
24 // If the regexp immediately goes into | 24 // If the regexp immediately goes into |
25 // something not a literal match, there's no required prefix. | 25 // something not a literal match, there's no required prefix. |
26 { "^(abc)", false }, | 26 { "^(abc)", false }, |
27 { "^a*", false }, | 27 { "^a*", false }, |
28 | 28 |
29 // Otherwise, it should work. | 29 // Otherwise, it should work. |
30 { "^abc$", true, "abc", false, "(?-m:$)" }, | 30 { "^abc$", true, "abc", false, "(?-m:$)" }, |
31 { "^abc", "true", "abc", false, "" }, | 31 { "^abc", true, "abc", false, "" }, |
32 { "^(?i)abc", true, "abc", true, "" }, | 32 { "^(?i)abc", true, "abc", true, "" }, |
33 { "^abcd*", true, "abc", false, "d*" }, | 33 { "^abcd*", true, "abc", false, "d*" }, |
34 { "^[Aa][Bb]cd*", true, "ab", true, "cd*" }, | 34 { "^[Aa][Bb]cd*", true, "ab", true, "cd*" }, |
35 { "^ab[Cc]d*", true, "ab", false, "[Cc]d*" }, | 35 { "^ab[Cc]d*", true, "ab", false, "[Cc]d*" }, |
36 { "^☺abc", true, "☺abc", false, "" }, | 36 { "^☺abc", true, "☺abc", false, "" }, |
37 }; | 37 }; |
38 | 38 |
39 TEST(RequiredPrefix, SimpleTests) { | 39 TEST(RequiredPrefix, SimpleTests) { |
40 for (int i = 0; i < arraysize(tests); i++) { | 40 for (int i = 0; i < arraysize(tests); i++) { |
41 const PrefixTest& t = tests[i]; | 41 const PrefixTest& t = tests[i]; |
(...skipping 16 matching lines...) Expand all Loading... |
58 CHECK_EQ(s->ToString(), string(t.suffix)) | 58 CHECK_EQ(s->ToString(), string(t.suffix)) |
59 << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); | 59 << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); |
60 s->Decref(); | 60 s->Decref(); |
61 } | 61 } |
62 re->Decref(); | 62 re->Decref(); |
63 } | 63 } |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 } // namespace re2 | 67 } // namespace re2 |
OLD | NEW |