Go to the documentation of this file.
10 #include "util/logging.h"
11 #include "util/strutil.h"
14 #include "re2/regexp.h"
15 #include "re2/testing/exhaustive_tester.h"
16 #include "re2/testing/regexp_generator.h"
17 #include "re2/testing/string_generator.h"
23 TEST(CplusplusStrings, EightBit) {
38 {
"Abcdef", 10,
"Abcdef",
"Abcdef" },
39 {
"abc(def|ghi)", 10,
"abcdef",
"abcghi" },
40 {
"a+hello", 10,
"aa",
"ahello" },
41 {
"a*hello", 10,
"a",
"hello" },
42 {
"def|abc", 10,
"abc",
"def" },
43 {
"a(b)(c)[d]", 10,
"abcd",
"abcd" },
44 {
"ab(cab|cat)", 10,
"abcab",
"abcat" },
45 {
"ab(cab|ca)x", 10,
"abcabx",
"abcax" },
46 {
"(ab|x)(c|de)", 10,
"abc",
"xde" },
47 {
"(ab|x)?(c|z)?", 10,
"",
"z" },
48 {
"[^\\s\\S]", 10,
"",
"" },
49 {
"(abc)+", 5,
"abc",
"abcac" },
50 {
"(abc)+", 2,
"ab",
"ac" },
51 {
"(abc)+", 1,
"a",
"b" },
52 {
"[a\xC3\xA1]", 4,
"a",
"\xC3\xA1" },
53 {
"a*", 10,
"",
"ab" },
55 {
"(?i)Abcdef", 10,
"ABCDEF",
"abcdef" },
56 {
"(?i)abc(def|ghi)", 10,
"ABCDEF",
"abcghi" },
57 {
"(?i)a+hello", 10,
"AA",
"ahello" },
58 {
"(?i)a*hello", 10,
"A",
"hello" },
59 {
"(?i)def|abc", 10,
"ABC",
"def" },
60 {
"(?i)a(b)(c)[d]", 10,
"ABCD",
"abcd" },
61 {
"(?i)ab(cab|cat)", 10,
"ABCAB",
"abcat" },
62 {
"(?i)ab(cab|ca)x", 10,
"ABCABX",
"abcax" },
63 {
"(?i)(ab|x)(c|de)", 10,
"ABC",
"xde" },
64 {
"(?i)(ab|x)?(c|z)?", 10,
"",
"z" },
65 {
"(?i)[^\\s\\S]", 10,
"",
"" },
66 {
"(?i)(abc)+", 5,
"ABC",
"abcac" },
67 {
"(?i)(abc)+", 2,
"AB",
"ac" },
68 {
"(?i)(abc)+", 1,
"A",
"b" },
69 {
"(?i)[a\xC3\xA1]", 4,
"A",
"\xC3\xA1" },
70 {
"(?i)a*", 10,
"",
"ab" },
71 {
"(?i)A*", 10,
"",
"ab" },
73 {
"\\AAbcdef", 10,
"Abcdef",
"Abcdef" },
74 {
"\\Aabc(def|ghi)", 10,
"abcdef",
"abcghi" },
75 {
"\\Aa+hello", 10,
"aa",
"ahello" },
76 {
"\\Aa*hello", 10,
"a",
"hello" },
77 {
"\\Adef|abc", 10,
"abc",
"def" },
78 {
"\\Aa(b)(c)[d]", 10,
"abcd",
"abcd" },
79 {
"\\Aab(cab|cat)", 10,
"abcab",
"abcat" },
80 {
"\\Aab(cab|ca)x", 10,
"abcabx",
"abcax" },
81 {
"\\A(ab|x)(c|de)", 10,
"abc",
"xde" },
82 {
"\\A(ab|x)?(c|z)?", 10,
"",
"z" },
83 {
"\\A[^\\s\\S]", 10,
"",
"" },
84 {
"\\A(abc)+", 5,
"abc",
"abcac" },
85 {
"\\A(abc)+", 2,
"ab",
"ac" },
86 {
"\\A(abc)+", 1,
"a",
"b" },
87 {
"\\A[a\xC3\xA1]", 4,
"a",
"\xC3\xA1" },
88 {
"\\Aa*", 10,
"",
"ab" },
90 {
"(?i)\\AAbcdef", 10,
"ABCDEF",
"abcdef" },
91 {
"(?i)\\Aabc(def|ghi)", 10,
"ABCDEF",
"abcghi" },
92 {
"(?i)\\Aa+hello", 10,
"AA",
"ahello" },
93 {
"(?i)\\Aa*hello", 10,
"A",
"hello" },
94 {
"(?i)\\Adef|abc", 10,
"ABC",
"def" },
95 {
"(?i)\\Aa(b)(c)[d]", 10,
"ABCD",
"abcd" },
96 {
"(?i)\\Aab(cab|cat)", 10,
"ABCAB",
"abcat" },
97 {
"(?i)\\Aab(cab|ca)x", 10,
"ABCABX",
"abcax" },
98 {
"(?i)\\A(ab|x)(c|de)", 10,
"ABC",
"xde" },
99 {
"(?i)\\A(ab|x)?(c|z)?", 10,
"",
"z" },
100 {
"(?i)\\A[^\\s\\S]", 10,
"",
"" },
101 {
"(?i)\\A(abc)+", 5,
"ABC",
"abcac" },
102 {
"(?i)\\A(abc)+", 2,
"AB",
"ac" },
103 {
"(?i)\\A(abc)+", 1,
"A",
"b" },
104 {
"(?i)\\A[a\xC3\xA1]", 4,
"A",
"\xC3\xA1" },
105 {
"(?i)\\Aa*", 10,
"",
"ab" },
106 {
"(?i)\\AA*", 10,
"",
"ab" },
109 TEST(PossibleMatchRange, HandWritten) {
111 for (
size_t j = 0; j < 2; j++) {
112 const PrefixTest& t =
tests[
i];
118 Prog*
prog = re->CompileToProg(0);
134 TEST(PossibleMatchRange, Failures) {
144 PossibleMatchRange(&
min, &
max, 10))
147 PossibleMatchRange(&
min, &
max, 10))
150 PossibleMatchRange(&
min, &
max, 10))
153 PossibleMatchRange(&
min, &
max, 10))
156 PossibleMatchRange(&
min, &
max, 10))
159 PossibleMatchRange(&
min, &
max, 10))
171 class PossibleMatchTester :
public RegexpGenerator {
175 const std::vector<std::string>&
alphabet,
176 const std::vector<std::string>&
ops,
178 const std::vector<std::string>& stralphabet)
180 strgen_(maxstrlen, stralphabet),
210 if(!re.PossibleMatchRange(&
min, &
max, 10)) {
214 if(strstr(regexp.c_str(),
"\\C*"))
216 LOG(QFATAL) <<
"PossibleMatchRange failed on: " <<
CEscape(regexp);
230 TEST(PossibleMatchRange, Exhaustive) {
239 PossibleMatchTester
t(natom, noperator,
Split(
" ",
"a b [0-9]"),
243 LOG(
INFO) <<
t.regexps() <<
" regexps, "
244 <<
t.tests() <<
" tests";
#define EXPECT_FALSE(condition)
static bool FullMatch(const StringPiece &text, const RE2 &re, A &&... a)
std::vector< std::string > Split(const StringPiece &sep, const StringPiece &s)
#define ASSERT_GE(val1, val2)
#define ASSERT_LE(val1, val2)
static const char alphabet[]
PossibleMatchTester(int maxatoms, int maxops, const std::vector< std::string > &alphabet, const std::vector< std::string > &ops, int maxstrlen, const std::vector< std::string > &stralphabet)
PossibleMatchTester & operator=(const PossibleMatchTester &)=delete
static Regexp * Parse(const StringPiece &s, ParseFlags flags, RegexpStatus *status)
static const std::vector< std::string > & EgrepOps()
std::vector< std::string > Explode(const StringPiece &s)
const bool RE2_DEBUG_MODE
std::string CEscape(const StringPiece &src)
#define EXPECT_LT(val1, val2)
#define ASSERT_TRUE(condition)
void HandleRegexp(const std::string ®exp)
const StringPiece & Next()
TEST(TestCharClassBuilder, Adds)
#define ASSERT_EQ(val1, val2)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:44