Go to the documentation of this file.
10 #include "util/logging.h"
11 #include "re2/regexp.h"
34 {
"a.",
"cat{lit{a}dot{}}" },
35 {
"a.b",
"cat{lit{a}dot{}lit{b}}" },
37 {
"a.b.c",
"cat{lit{a}dot{}lit{b}dot{}lit{c}}" },
38 {
"abc",
"str{abc}" },
39 {
"a|^",
"alt{lit{a}bol{}}" },
40 {
"a|b",
"cc{0x61-0x62}" },
41 {
"(a)",
"cap{lit{a}}" },
42 {
"(a)|b",
"alt{cap{lit{a}}lit{b}}" },
43 {
"a*",
"star{lit{a}}" },
44 {
"a+",
"plus{lit{a}}" },
45 {
"a?",
"que{lit{a}}" },
46 {
"a{2}",
"rep{2,2 lit{a}}" },
47 {
"a{2,3}",
"rep{2,3 lit{a}}" },
48 {
"a{2,}",
"rep{2,-1 lit{a}}" },
49 {
"a*?",
"nstar{lit{a}}" },
50 {
"a+?",
"nplus{lit{a}}" },
51 {
"a??",
"nque{lit{a}}" },
52 {
"a{2}?",
"nrep{2,2 lit{a}}" },
53 {
"a{2,3}?",
"nrep{2,3 lit{a}}" },
54 {
"a{2,}?",
"nrep{2,-1 lit{a}}" },
56 {
"|",
"alt{emp{}emp{}}" },
57 {
"|x|",
"alt{emp{}lit{x}emp{}}" },
72 {
"\\\\",
"lit{\\}" },
73 {
"[ace]",
"cc{0x61 0x63 0x65}" },
74 {
"[abc]",
"cc{0x61-0x63}" },
75 {
"[a-z]",
"cc{0x61-0x7a}" },
82 {
"[[:lower:]]",
"cc{0x61-0x7a}" },
83 {
"[a-z]",
"cc{0x61-0x7a}" },
84 {
"[^[:lower:]]",
"cc{0-0x60 0x7b-0x10ffff}" },
85 {
"[[:^lower:]]",
"cc{0-0x60 0x7b-0x10ffff}" },
86 {
"(?i)[[:lower:]]",
"cc{0x41-0x5a 0x61-0x7a 0x17f 0x212a}" },
87 {
"(?i)[a-z]",
"cc{0x41-0x5a 0x61-0x7a 0x17f 0x212a}" },
88 {
"(?i)[^[:lower:]]",
"cc{0-0x40 0x5b-0x60 0x7b-0x17e 0x180-0x2129 0x212b-0x10ffff}" },
89 {
"(?i)[[:^lower:]]",
"cc{0-0x40 0x5b-0x60 0x7b-0x17e 0x180-0x2129 0x212b-0x10ffff}" },
90 {
"\\d",
"cc{0x30-0x39}" },
91 {
"\\D",
"cc{0-0x2f 0x3a-0x10ffff}" },
92 {
"\\s",
"cc{0x9-0xa 0xc-0xd 0x20}" },
93 {
"\\S",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}" },
94 {
"\\w",
"cc{0x30-0x39 0x41-0x5a 0x5f 0x61-0x7a}" },
95 {
"\\W",
"cc{0-0x2f 0x3a-0x40 0x5b-0x5e 0x60 0x7b-0x10ffff}" },
96 {
"(?i)\\w",
"cc{0x30-0x39 0x41-0x5a 0x5f 0x61-0x7a 0x17f 0x212a}" },
97 {
"(?i)\\W",
"cc{0-0x2f 0x3a-0x40 0x5b-0x5e 0x60 0x7b-0x17e 0x180-0x2129 0x212b-0x10ffff}" },
98 {
"[^\\\\]",
"cc{0-0x5b 0x5d-0x10ffff}" },
102 {
"\\p{Braille}",
"cc{0x2800-0x28ff}" },
103 {
"\\P{Braille}",
"cc{0-0x27ff 0x2900-0x10ffff}" },
104 {
"\\p{^Braille}",
"cc{0-0x27ff 0x2900-0x10ffff}" },
105 {
"\\P{^Braille}",
"cc{0x2800-0x28ff}" },
108 {
"a{,2}",
"str{a{,2}}" },
109 {
"\\.\\^\\$\\\\",
"str{.^$\\}" },
110 {
"[a-zABC]",
"cc{0x41-0x43 0x61-0x7a}" },
111 {
"[^a]",
"cc{0-0x60 0x62-0x10ffff}" },
112 {
"[\xce\xb1-\xce\xb5\xe2\x98\xba]",
"cc{0x3b1-0x3b5 0x263a}" },
113 {
"a*{",
"cat{star{lit{a}}lit{{}}" },
116 {
"(?:ab)*",
"star{str{ab}}" },
117 {
"(ab)*",
"star{cap{str{ab}}}" },
118 {
"ab|cd",
"alt{str{ab}str{cd}}" },
119 {
"a(b|c)d",
"cat{lit{a}cap{cc{0x62-0x63}}lit{d}}" },
122 {
"(?:(?:a)*)*",
"star{lit{a}}" },
123 {
"(?:(?:a)+)+",
"plus{lit{a}}" },
124 {
"(?:(?:a)?)?",
"que{lit{a}}" },
125 {
"(?:(?:a)*)+",
"star{lit{a}}" },
126 {
"(?:(?:a)*)?",
"star{lit{a}}" },
127 {
"(?:(?:a)+)*",
"star{lit{a}}" },
128 {
"(?:(?:a)+)?",
"star{lit{a}}" },
129 {
"(?:(?:a)?)*",
"star{lit{a}}" },
130 {
"(?:(?:a)?)+",
"star{lit{a}}" },
133 {
"(?:a)",
"lit{a}" },
134 {
"(?:ab)(?:cd)",
"str{abcd}" },
135 {
"(?:a|b)|(?:c|d)",
"cc{0x61-0x64}" },
136 {
"a|c",
"cc{0x61 0x63}" },
137 {
"a|[cd]",
"cc{0x61 0x63-0x64}" },
139 {
"[ab]|c",
"cc{0x61-0x63}" },
140 {
"[ab]|[cd]",
"cc{0x61-0x64}" },
141 {
"[ab]|.",
"dot{}" },
143 {
".|[cd]",
"dot{}" },
147 {
"\\Q+|*?{[\\E",
"str{+|*?{[}" },
148 {
"\\Q+\\E+",
"plus{lit{+}}" },
149 {
"\\Q\\\\E",
"lit{\\}" },
150 {
"\\Q\\\\\\E",
"str{\\\\}" },
151 {
"\\Qa\\E*",
"star{lit{a}}" },
152 {
"\\Qab\\E*",
"cat{lit{a}star{lit{b}}}" },
153 {
"\\Qabc\\E*",
"cat{str{ab}star{lit{c}}}" },
156 {
"(?m)^",
"bol{}" },
157 {
"(?m)$",
"eol{}" },
158 {
"(?-m)^",
"bot{}" },
159 {
"(?-m)$",
"eot{}" },
160 {
"(?m)\\A",
"bot{}" },
161 {
"(?m)\\z",
"eot{\\z}" },
162 {
"(?-m)\\A",
"bot{}" },
163 {
"(?-m)\\z",
"eot{\\z}" },
166 {
"(?P<name>a)",
"cap{name:lit{a}}" },
169 {
"[Aa]",
"litfold{a}" },
172 {
"abcde",
"str{abcde}" },
173 {
"[Aa][Bb]cd",
"cat{strfold{ab}str{cd}}" },
176 {
"[^ ]",
"cc{0-0x9 0xb-0x1f 0x21-0x10ffff}",
TestZeroFlags },
180 {
"[^ \f]",
"cc{0-0x9 0xb 0xd-0x1f 0x21-0x10ffff}",
TestZeroFlags },
184 {
"[^ \r]",
"cc{0-0x9 0xb-0xc 0xe-0x1f 0x21-0x10ffff}",
TestZeroFlags },
186 {
"[^ \r]",
"cc{0-0x9 0xb-0xc 0xe-0x1f 0x21-0x10ffff}",
Regexp::NeverNL },
188 {
"[^ \v]",
"cc{0-0x9 0xc-0x1f 0x21-0x10ffff}",
TestZeroFlags },
192 {
"[^ \t]",
"cc{0-0x8 0xb-0x1f 0x21-0x10ffff}",
TestZeroFlags },
198 {
"[^ \r\f\t\v]",
"cc{0-0x8 0xe-0x1f 0x21-0x10ffff}",
Regexp::NeverNL },
200 {
"[^ \r\n\f\t\v]",
"cc{0-0x8 0xe-0x1f 0x21-0x10ffff}",
Regexp::NeverNL },
202 {
"[^ \r\n\f\t]",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
Regexp::NeverNL },
204 {
"[^\t-\n\f-\r ]",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
206 {
"[^\t-\n\f-\r ]",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
208 {
"[^\t-\n\f-\r ]",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
210 {
"[^\t-\n\f-\r ]",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
212 {
"\\S",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
214 {
"\\S",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
216 {
"\\S",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
218 {
"\\S",
"cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
223 {
"[\\s\\S]",
"cc{0-0x10ffff}" },
244 <<
"Regexp: " <<
tests[
i].regexp
246 <<
" s: " << s <<
" flag=" << f;
250 for (
int j = 0; j <
ntests; j++) {
253 <<
"Regexp: " <<
tests[
i].regexp <<
" " <<
tests[j].regexp;
268 {
"AbCdE",
"strfold{abcde}" },
269 {
"[Aa]",
"litfold{a}" },
270 {
"a",
"litfold{a}" },
274 {
"A[F-g]",
"cat{litfold{a}cc{0x41-0x7a 0x17f 0x212a}}" },
275 {
"[[:upper:]]",
"cc{0x41-0x5a 0x61-0x7a 0x17f 0x212a}" },
276 {
"[[:lower:]]",
"cc{0x41-0x5a 0x61-0x7a 0x17f 0x212a}" },
285 {
"(|)^$.[*+?]{5,10},\\",
"str{(|)^$.[*+?]{5,10},\\}" },
296 {
"[^a]",
"cc{0-0x60 0x62-0x10ffff}" },
297 {
"[a\\n]",
"cc{0xa 0x61}" },
307 {
".",
"cc{0-0x9 0xb-0x10ffff}" },
309 {
"[^a]",
"cc{0-0x9 0xb-0x60 0x62-0x10ffff}" },
310 {
"[a\\n]",
"cc{0xa 0x61}" },
319 {
"abc|abd",
"cat{str{ab}cc{0x63-0x64}}" },
320 {
"a(?:b)c|abd",
"cat{str{ab}cc{0x63-0x64}}" },
321 {
"abc|abd|aef|bcx|bcy",
322 "alt{cat{lit{a}alt{cat{lit{b}cc{0x63-0x64}}str{ef}}}"
323 "cat{str{bc}cc{0x78-0x79}}}" },
324 {
"abc|x|abd",
"alt{str{abc}lit{x}str{abd}}" },
325 {
"(?i)abc|ABD",
"cat{strfold{ab}cc{0x43-0x44 0x63-0x64}}" },
326 {
"[ab]c|[ab]d",
"cat{cc{0x61-0x62}cc{0x63-0x64}}" },
327 {
".c|.d",
"cat{cc{0-0x9 0xb-0x10ffff}cc{0x63-0x64}}" },
328 {
"\\Cc|\\Cd",
"cat{byte{}cc{0x63-0x64}}" },
330 "cat{rep{2,2 lit{x}}alt{emp{}cc{0x30-0x39}}}" },
331 {
"x{2}y|x{2}[0-9]y",
332 "cat{rep{2,2 lit{x}}alt{lit{y}cat{cc{0x30-0x39}lit{y}}}}" },
334 "alt{lit{n}cat{lit{r}alt{emp{}lit{s}}}}" },
336 "alt{lit{n}cat{lit{r}alt{lit{s}emp{}}}}" },
338 "alt{cat{lit{r}alt{emp{}lit{s}}}lit{n}}" },
340 "alt{cat{lit{r}alt{lit{s}emp{}}}lit{n}}" },
342 "cat{lit{a}alt{cat{nstar{byte{}}lit{c}}cat{nstar{byte{}}lit{b}}}}" },
344 "cat{bol{}cat{str{/a/}alt{str{bc}str{de}}}}" },
346 {
"a|aa|aaa|aaaa|aaaaa|aaaaaa|aaaaaaa|aaaaaaaa|aaaaaaaaa|aaaaaaaaaa",
347 "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}"
348 "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}"
349 "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}" "cat{lit{a}alt{emp{}"
350 "lit{a}}}}}}}}}}}}}}}}}}}" },
351 {
"a|aardvark|aardvarks|abaci|aback|abacus|abacuses|abaft|abalone|abalones",
352 "cat{lit{a}alt{emp{}cat{str{ardvark}alt{emp{}lit{s}}}"
353 "cat{str{ba}alt{cat{lit{c}alt{cc{0x69 0x6b}cat{str{us}alt{emp{}str{es}}}}}"
354 "str{ft}cat{str{lone}alt{emp{}lit{s}}}}}}}" },
363 {
"((((((((((x{2}){2}){2}){2}){2}){2}){2}){2}){2}))",
364 "cap{cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 lit{x}}}}}}}}}}}}}}}}}}}}" },
365 {
"((((((((((x{1}){2}){2}){2}){2}){2}){2}){2}){2}){2})",
366 "cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{1,1 lit{x}}}}}}}}}}}}}}}}}}}}}" },
367 {
"((((((((((x{0}){2}){2}){2}){2}){2}){2}){2}){2}){2})",
368 "cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 cap{rep{0,0 lit{x}}}}}}}}}}}}}}}}}}}}}" },
369 {
"((((((x{2}){2}){2}){5}){5}){5})",
370 "cap{rep{5,5 cap{rep{5,5 cap{rep{5,5 cap{rep{2,2 cap{rep{2,2 cap{rep{2,2 lit{x}}}}}}}}}}}}}" },
401 "((((((((((x{2}){2}){2}){2}){2}){2}){2}){2}){2}){2})",
402 "(((x{7}){11}){13})",
453 TEST(TestToString, EquivalentParse) {
464 <<
"Regexp: " <<
tests[
i].regexp
466 <<
" s: " << s <<
" flag=" << f;
468 if (t !=
tests[
i].regexp) {
482 if (s != ss || t != tt)
493 TEST(NamedCaptures, ErrorArgs) {
static Regexp::ParseFlags kTestFlags
static Regexp * Parse(const StringPiece &s, ParseFlags flags, RegexpStatus *status)
static bool Equal(Regexp *a, Regexp *b)
#define ASSERT_TRUE(condition)
static void parse(const char *s)
const char * only_posix[]
#define EXPECT_TRUE(condition)
static const Regexp::ParseFlags TestZeroFlags
TEST(TestCharClassBuilder, Adds)
bool RegexpEqualTestingOnly(Regexp *a, Regexp *b)
absl::StatusCode code() const
void TestParse(const Test *tests, int ntests, Regexp::ParseFlags flags, const std::string &title)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:39