bloaty/third_party/re2/re2/testing/tester.h
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 #ifndef RE2_TESTING_TESTER_H_
6 #define RE2_TESTING_TESTER_H_
7 
8 // Comparative tester for regular expression matching.
9 // Checks all implementations against each other.
10 
11 #include <vector>
12 
13 #include "re2/stringpiece.h"
14 #include "re2/prog.h"
15 #include "re2/regexp.h"
16 #include "re2/re2.h"
17 #include "util/pcre.h"
18 
19 namespace re2 {
20 
21 // All the supported regexp engines.
22 enum Engine {
23  kEngineBacktrack = 0, // Prog::UnsafeSearchBacktrack
24  kEngineNFA, // Prog::SearchNFA
25  kEngineDFA, // Prog::SearchDFA, only ask whether it matched
26  kEngineDFA1, // Prog::SearchDFA, ask for match[0]
27  kEngineOnePass, // Prog::SearchOnePass, if applicable
28  kEngineBitState, // Prog::SearchBitState
29  kEngineRE2, // RE2, all submatches
30  kEngineRE2a, // RE2, only ask for match[0]
31  kEngineRE2b, // RE2, only ask whether it matched
32  kEnginePCRE, // PCRE (util/pcre.h)
33 
35 };
36 
37 // Make normal math on the enum preserve the type.
38 // By default, C++ doesn't define ++ on enum, and e+1 has type int.
39 static inline void operator++(Engine& e, int unused) {
40  e = static_cast<Engine>(e+1);
41 }
42 
43 static inline Engine operator+(Engine e, int i) {
44  return static_cast<Engine>(static_cast<int>(e)+i);
45 }
46 
47 // A TestInstance caches per-regexp state for a given
48 // regular expression in a given configuration
49 // (UTF-8 vs Latin1, longest vs first match, etc.).
50 class TestInstance {
51  public:
52  struct Result;
53 
54  TestInstance(const StringPiece& regexp, Prog::MatchKind kind,
56  ~TestInstance();
58  bool error() { return error_; }
59 
60  // Runs a single test case: search in text, which is in context,
61  // using the given anchoring.
62  bool RunCase(const StringPiece& text, const StringPiece& context,
63  Prog::Anchor anchor);
64 
65  private:
66  // Runs a single search using the named engine type.
67  void RunSearch(Engine type,
68  const StringPiece& text, const StringPiece& context,
69  Prog::Anchor anchor,
70  Result *result);
71 
72  void LogMatch(const char* prefix, Engine e, const StringPiece& text,
73  const StringPiece& context, Prog::Anchor anchor);
74 
75  const StringPiece regexp_str_; // regexp being tested
76  Prog::MatchKind kind_; // kind of match
77  Regexp::ParseFlags flags_; // flags for parsing regexp_str_
78  bool error_; // error during constructor?
79 
80  Regexp* regexp_; // parsed regexp
81  int num_captures_; // regexp_->NumCaptures() cached
82  Prog* prog_; // compiled program
83  Prog* rprog_; // compiled reverse program
84  PCRE* re_; // PCRE implementation
85  RE2* re2_; // RE2 implementation
86 
87  TestInstance(const TestInstance&) = delete;
88  TestInstance& operator=(const TestInstance&) = delete;
89 };
90 
91 // A group of TestInstances for all possible configurations.
92 class Tester {
93  public:
94  explicit Tester(const StringPiece& regexp);
95  ~Tester();
96 
97  bool error() { return error_; }
98 
99  // Runs a single test case: search in text, which is in context,
100  // using the given anchoring.
101  bool TestCase(const StringPiece& text, const StringPiece& context,
102  Prog::Anchor anchor);
103 
104  // Run TestCase(text, text, anchor) for all anchoring modes.
105  bool TestInput(const StringPiece& text);
106 
107  // Run TestCase(text, context, anchor) for all anchoring modes.
109 
110  private:
111  bool error_;
112  std::vector<TestInstance*> v_;
113 
114  Tester(const Tester&) = delete;
115  Tester& operator=(const Tester&) = delete;
116 };
117 
118 // Run all possible tests using regexp and text.
119 bool TestRegexpOnText(const StringPiece& regexp, const StringPiece& text);
120 
121 } // namespace re2
122 
123 #endif // RE2_TESTING_TESTER_H_
re2::kEngineDFA
@ kEngineDFA
Definition: bloaty/third_party/re2/re2/testing/tester.h:25
re2::TestInstance::regexp_
Regexp * regexp_
Definition: bloaty/third_party/re2/re2/testing/tester.h:80
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
re2::Tester::operator=
Tester & operator=(const Tester &)=delete
re2::TestInstance::re2_
RE2 * re2_
Definition: bloaty/third_party/re2/re2/testing/tester.h:85
re2::TestInstance::RunSearch
void RunSearch(Engine type, const StringPiece &text, const StringPiece &context, Prog::Anchor anchor, Result *result)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:288
re2::Tester::error_
bool error_
Definition: bloaty/third_party/re2/re2/testing/tester.h:111
re2::kEngineRE2
@ kEngineRE2
Definition: bloaty/third_party/re2/re2/testing/tester.h:29
re2::Prog::Anchor
Anchor
Definition: bloaty/third_party/re2/re2/prog.h:175
re2::TestInstance::error_
bool error_
Definition: bloaty/third_party/re2/re2/testing/tester.h:78
re2::TestRegexpOnText
bool TestRegexpOnText(const StringPiece &regexp, const StringPiece &text)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:663
re2::Regexp
Definition: bloaty/third_party/re2/re2/regexp.h:274
re2::Tester::v_
std::vector< TestInstance * > v_
Definition: bloaty/third_party/re2/re2/testing/tester.h:112
re2::kEngineNFA
@ kEngineNFA
Definition: bloaty/third_party/re2/re2/testing/tester.h:24
re2::TestInstance::TestInstance
TestInstance(const StringPiece &regexp, Prog::MatchKind kind, Regexp::ParseFlags flags)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:169
re2::operator+
static Engine operator+(Engine e, int i)
Definition: bloaty/third_party/re2/re2/testing/tester.h:43
re2
Definition: bloaty/third_party/re2/re2/bitmap256.h:17
re2::TestInstance::re_
PCRE * re_
Definition: bloaty/third_party/re2/re2/testing/tester.h:84
re2::TestInstance::prog_
Prog * prog_
Definition: bloaty/third_party/re2/re2/testing/tester.h:82
re2::Tester::TestInput
bool TestInput(const StringPiece &text)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:641
re2::Prog::MatchKind
MatchKind
Definition: bloaty/third_party/re2/re2/prog.h:192
re2::TestInstance::flags_
Regexp::ParseFlags flags_
Definition: bloaty/third_party/re2/re2/testing/tester.h:77
re2::Tester
Definition: bloaty/third_party/re2/re2/testing/tester.h:92
re2::TestInstance::kind_
Prog::MatchKind kind_
Definition: bloaty/third_party/re2/re2/testing/tester.h:76
re2::TestInstance::error
bool error()
Definition: bloaty/third_party/re2/re2/testing/tester.h:58
gen_server_registered_method_bad_client_test_body.text
def text
Definition: gen_server_registered_method_bad_client_test_body.py:50
re2::kEngineBitState
@ kEngineBitState
Definition: bloaty/third_party/re2/re2/testing/tester.h:28
re2::TestInstance::num_captures_
int num_captures_
Definition: bloaty/third_party/re2/re2/testing/tester.h:81
re2::TestInstance::regexp_str_
const StringPiece regexp_str_
Definition: bloaty/third_party/re2/re2/testing/tester.h:75
re2::TestInstance::Result
Definition: bloaty/third_party/re2/re2/testing/tester.cc:87
re2::RE2
Definition: bloaty/third_party/re2/re2/re2.h:211
re2::Tester::error
bool error()
Definition: bloaty/third_party/re2/re2/testing/tester.h:97
re2::TestInstance
Definition: bloaty/third_party/re2/re2/testing/tester.h:50
re2::Regexp::ParseFlags
ParseFlags
Definition: bloaty/third_party/re2/re2/regexp.h:278
re2::TestInstance::rprog_
Prog * rprog_
Definition: bloaty/third_party/re2/re2/testing/tester.h:83
re2::operator++
static void operator++(Engine &e, int unused)
Definition: bloaty/third_party/re2/re2/testing/tester.h:39
re2::TestInstance::LogMatch
void LogMatch(const char *prefix, Engine e, const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:581
re2::kEngineRE2b
@ kEngineRE2b
Definition: bloaty/third_party/re2/re2/testing/tester.h:31
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
re2::PCRE
Definition: bloaty/third_party/re2/util/pcre.h:186
re2::Tester::~Tester
~Tester()
Definition: bloaty/third_party/re2/re2/testing/tester.cc:623
re2::Prog
Definition: bloaty/third_party/re2/re2/prog.h:56
re2::Tester::TestInputInContext
bool TestInputInContext(const StringPiece &text, const StringPiece &context)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:655
re2::TestInstance::RunCase
bool RunCase(const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:503
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
re2::Engine
Engine
Definition: bloaty/third_party/re2/re2/testing/tester.h:22
re2::kEnginePCRE
@ kEnginePCRE
Definition: bloaty/third_party/re2/re2/testing/tester.h:32
re2::TestInstance::operator=
TestInstance & operator=(const TestInstance &)=delete
re2::Tester::TestCase
bool TestCase(const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:628
re2::TestInstance::flags
Regexp::ParseFlags flags()
Definition: bloaty/third_party/re2/re2/testing/tester.h:57
re2::TestInstance::~TestInstance
~TestInstance()
Definition: bloaty/third_party/re2/re2/testing/tester.cc:276
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
re2::kEngineOnePass
@ kEngineOnePass
Definition: bloaty/third_party/re2/re2/testing/tester.h:27
re2::kEngineMax
@ kEngineMax
Definition: bloaty/third_party/re2/re2/testing/tester.h:34
re2::kEngineDFA1
@ kEngineDFA1
Definition: bloaty/third_party/re2/re2/testing/tester.h:26
re2::StringPiece
Definition: bloaty/third_party/re2/re2/stringpiece.h:39
re2::kEngineBacktrack
@ kEngineBacktrack
Definition: bloaty/third_party/re2/re2/testing/tester.h:23
re2::kEngineRE2a
@ kEngineRE2a
Definition: bloaty/third_party/re2/re2/testing/tester.h:30
re2::Tester::Tester
Tester(const StringPiece &regexp)
Definition: bloaty/third_party/re2/re2/testing/tester.cc:611
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:32