Go to the documentation of this file.
12 #include "util/util.h"
13 #include "util/flags.h"
14 #include "util/logging.h"
15 #include "util/strutil.h"
16 #include "re2/testing/tester.h"
19 #include "re2/regexp.h"
21 DEFINE_bool(dump_prog,
false,
"dump regexp program");
22 DEFINE_bool(log_okay,
false,
"log successful runs");
23 DEFINE_bool(dump_rprog,
false,
"dump reversed regexp program");
26 "maximum number of regexp test failures (-1 = unlimited)");
28 DEFINE_string(regexp_engines,
"",
"pattern to select regexp engines to test");
59 static bool did_parse =
false;
63 return cached_engines;
65 if (FLAGS_regexp_engines.empty()) {
69 if (FLAGS_regexp_engines.find(
EngineName(
i)) != std::string::npos)
70 cached_engines |= 1<<
i;
73 if (cached_engines == 0)
74 LOG(
INFO) <<
"Warning: no engines enabled.";
78 if (cached_engines & (1<<
i))
83 return cached_engines;
102 if (s.data() == NULL)
105 s.begin() -
text.begin(), s.end() -
text.begin());
110 for (
size_t i = 0;
i <
text.size();
i++)
122 return "longest match";
124 return "first match";
171 : regexp_str_(regexp_str),
201 if (FLAGS_dump_prog) {
219 if (FLAGS_dump_rprog)
240 options.set_longest_match(
true);
318 result->submatch, nsubmatch);
319 result->have_submatch =
true;
329 result->submatch, nsubmatch);
330 result->have_submatch =
true;
356 &
result->skipped, NULL)) {
357 LOG(
ERROR) <<
"Reverse DFA inconsistency: "
363 result->have_submatch0 =
true;
375 result->submatch, nsubmatch);
376 result->have_submatch =
true;
386 result->submatch, nsubmatch);
387 result->have_submatch =
true;
408 static_cast<size_t>(
text.begin() -
context.begin()),
413 result->have_submatch = nsubmatch > 0;
447 for (
int i = 0;
i < nsubmatch;
i++) {
471 result->have_submatch =
true;
490 if (
r.have_submatch ||
r.have_submatch0) {
495 if (!
r.have_submatch)
523 bool all_okay =
true;
547 LogMatch(
r.untrusted ?
"(Untrusted) Mismatch: " :
"Mismatch: ",
i,
text,
551 LOG(
INFO) <<
" Should not match (but does).";
553 LOG(
INFO) <<
" Should match (but does not).";
574 if (FLAGS_max_regexp_failures > 0 && --FLAGS_max_regexp_failures == 0)
575 LOG(QFATAL) <<
"Too many regexp failures.";
624 for (
size_t i = 0;
i <
v_.size();
i++)
631 for (
size_t i = 0;
i <
v_.size();
i++)
643 if (
text.size() > 0) {
666 return t.TestInput(
text);
DEFINE_string(regexp_engines, "", "pattern to select regexp engines to test")
bool SearchOnePass(const StringPiece &text, const StringPiece &context, Anchor anchor, MatchKind kind, StringPiece *match, int nmatch)
void remove_prefix(size_type n)
return memset(p, 0, total)
void RunSearch(Engine type, const StringPiece &text, const StringPiece &context, Prog::Anchor anchor, Result *result)
void remove_suffix(size_type n)
bool TestRegexpOnText(const StringPiece ®exp, const StringPiece &text)
DEFINE_int32(max_regexp_failures, 100, "maximum number of regexp test failures (-1 = unlimited)")
std::vector< TestInstance * > v_
static const size_type npos
TestInstance(const StringPiece ®exp, Prog::MatchKind kind, Regexp::ParseFlags flags)
const std::string & error() const
const std::string & error() const
static std::string FormatCapture(const StringPiece &text, const StringPiece &s)
Prog * CompileToProg(int64_t max_mem)
Arg(64) -> Arg(128) ->Arg(256) ->Arg(512) ->Arg(1024) ->Arg(1536) ->Arg(2048) ->Arg(3072) ->Arg(4096) ->Arg(5120) ->Arg(6144) ->Arg(7168)
static std::string FormatMode(Regexp::ParseFlags flags)
bool TestInput(const StringPiece &text)
Regexp::ParseFlags flags_
StringPiece submatch[kMaxSubmatch]
TestInstance::Result Result
static const Regexp::ParseFlags multi_line
static bool ResultOkay(const Result &r, const Result &correct)
bool SearchBitState(const StringPiece &text, const StringPiece &context, Anchor anchor, MatchKind kind, StringPiece *match, int nmatch)
static const char * EngineName(Engine e)
std::string StringPrintf(const char *format,...)
static ParseMode parse_modes[]
static Regexp * Parse(const StringPiece &s, ParseFlags flags, RegexpStatus *status)
static Prog::Anchor anchors[]
const StringPiece regexp_str_
size_type find(const StringPiece &s, size_type pos=0) const
static std::string FormatKind(Prog::MatchKind kind)
static const LogLevel ERROR
bool DoMatch(const StringPiece &text, Anchor anchor, size_t *consumed, const Arg *const *args, int n) const
Prog * CompileToReverseProg(int64_t max_mem)
bool SearchDFA(const StringPiece &text, const StringPiece &context, Anchor anchor, MatchKind kind, StringPiece *match0, bool *failed, SparseSet *matches)
bool Match(const StringPiece &text, size_t startpos, size_t endpos, Anchor re_anchor, StringPiece *submatch, int nsubmatch) const
const_pointer data() const
static const int kMaxOnePassCapture
void LogMatch(const char *prefix, Engine e, const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
Regexp::ParseFlags parse_flags
std::string CEscape(const StringPiece &src)
bool TestInputInContext(const StringPiece &text, const StringPiece &context)
static Prog::MatchKind kinds[]
DEFINE_bool(dump_prog, false, "dump regexp program")
bool RunCase(const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
static const char prefix[]
static std::string FormatAnchor(Prog::Anchor anchor)
const char * engine_names[kEngineMax]
bool TestCase(const StringPiece &text, const StringPiece &context, Prog::Anchor anchor)
static bool NonASCII(const StringPiece &text)
bool UnsafeSearchBacktrack(const StringPiece &text, const StringPiece &context, Anchor anchor, MatchKind kind, StringPiece *match, int nmatch)
grpc::ClientContext context
static const Regexp::ParseFlags single_line
static uint32_t Engines()
Tester(const StringPiece ®exp)
bool SearchNFA(const StringPiece &text, const StringPiece &context, Anchor anchor, MatchKind kind, StringPiece *match, int nmatch)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:32