re2/re2/testing/mimics_pcre_test.cc
Go to the documentation of this file.
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 #include "util/test.h"
6 #include "util/logging.h"
7 #include "re2/prog.h"
8 #include "re2/regexp.h"
9 
10 namespace re2 {
11 
12 struct PCRETest {
13  const char* regexp;
14  bool should_match;
15 };
16 
17 static PCRETest tests[] = {
18  // Most things should behave exactly.
19  { "abc", true },
20  { "(a|b)c", true },
21  { "(a*|b)c", true },
22  { "(a|b*)c", true },
23  { "a(b|c)d", true },
24  { "a(()|())c", true },
25  { "ab*c", true },
26  { "ab+c", true },
27  { "a(b*|c*)d", true },
28  { "\\W", true },
29  { "\\W{1,2}", true },
30  { "\\d", true },
31 
32  // Check that repeated empty strings do not.
33  { "(a*)*", false },
34  { "x(a*)*y", false },
35  { "(a*)+", false },
36  { "(a+)*", true },
37  { "(a+)+", true },
38  { "(a+)+", true },
39 
40  // \v is the only character class that shouldn't.
41  { "\\b", true },
42  { "\\v", false },
43  { "\\d", true },
44 
45  // The handling of ^ in multi-line mode is different, as is
46  // the handling of $ in single-line mode. (Both involve
47  // boundary cases if the string ends with \n.)
48  { "\\A", true },
49  { "\\z", true },
50  { "(?m)^", false },
51  { "(?m)$", true },
52  { "(?-m)^", true },
53  { "(?-m)$", false }, // In PCRE, == \Z
54  { "(?m)\\A", true },
55  { "(?m)\\z", true },
56  { "(?-m)\\A", true },
57  { "(?-m)\\z", true },
58 };
59 
60 TEST(MimicsPCRE, SimpleTests) {
61  for (size_t i = 0; i < arraysize(tests); i++) {
62  const PCRETest& t = tests[i];
63  for (size_t j = 0; j < 2; j++) {
65  if (j == 0)
67  Regexp* re = Regexp::Parse(t.regexp, flags, NULL);
68  ASSERT_TRUE(re != NULL) << " " << t.regexp;
69  ASSERT_EQ(t.should_match, re->MimicsPCRE())
70  << " " << t.regexp << " "
71  << (j == 0 ? "latin1" : "utf");
72  re->Decref();
73  }
74  }
75 }
76 
77 } // namespace re2
re2::PCRETest
Definition: bloaty/third_party/re2/re2/testing/mimics_pcre_test.cc:12
re2
Definition: bloaty/third_party/re2/re2/bitmap256.h:17
re2::Regexp::Latin1
@ Latin1
Definition: bloaty/third_party/re2/re2/regexp.h:289
re2::Regexp::Parse
static Regexp * Parse(const StringPiece &s, ParseFlags flags, RegexpStatus *status)
Definition: bloaty/third_party/re2/re2/parse.cc:2200
re2::Regexp::ParseFlags
ParseFlags
Definition: bloaty/third_party/re2/re2/regexp.h:278
arraysize
#define arraysize(array)
Definition: benchmark/src/arraysize.h:28
tests
Definition: src/python/grpcio_tests/tests/__init__.py:1
re2::PCRETest::should_match
bool should_match
Definition: bloaty/third_party/re2/re2/testing/mimics_pcre_test.cc:14
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
re2::PCRETest::regexp
const char * regexp
Definition: bloaty/third_party/re2/re2/testing/mimics_pcre_test.cc:13
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
re2::TEST
TEST(TestCharClassBuilder, Adds)
Definition: bloaty/third_party/re2/re2/testing/charclass_test.cc:198
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
re2::Regexp::LikePerl
@ LikePerl
Definition: bloaty/third_party/re2/re2/regexp.h:312
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2056


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:29