re2 1.19.2 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/linux-alpine-node-16/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-18/Dockerfile +1 -1
- package/.github/actions/linux-alpine-node-20/Dockerfile +1 -1
- package/.gitmodules +5 -2
- package/README.md +1 -0
- package/binding.gyp +82 -25
- package/lib/replace.cc +4 -4
- package/package.json +1 -1
- package/tsconfig.json +2 -1
- package/vendor/re2/.bazelrc +16 -0
- package/vendor/re2/.github/bazel.sh +24 -0
- package/vendor/re2/.github/cmake.sh +12 -0
- package/vendor/re2/.github/workflows/ci-bazel.yml +17 -0
- package/vendor/re2/.github/workflows/ci-cmake.yml +108 -0
- package/vendor/re2/.github/workflows/ci.yml +89 -0
- package/vendor/re2/.github/workflows/pr.yml +26 -0
- package/vendor/re2/.github/workflows/python.yml +185 -0
- package/vendor/re2/AUTHORS +13 -0
- package/vendor/re2/BUILD.bazel +280 -0
- package/vendor/re2/CMakeLists.txt +268 -0
- package/vendor/re2/CONTRIBUTING.md +2 -0
- package/vendor/re2/CONTRIBUTORS +41 -0
- package/vendor/re2/Makefile +400 -0
- package/vendor/{README → re2/README} +5 -0
- package/vendor/re2/SECURITY.md +4 -0
- package/vendor/re2/WORKSPACE.bazel +62 -0
- package/vendor/re2/app/BUILD.bazel +19 -0
- package/vendor/re2/app/_re2.cc +94 -0
- package/vendor/re2/app/_re2.d.ts +23 -0
- package/vendor/re2/app/app.ts +111 -0
- package/vendor/re2/app/build.sh +50 -0
- package/vendor/re2/app/index.html +5 -0
- package/vendor/re2/app/package.json +14 -0
- package/vendor/re2/app/rollup.config.js +28 -0
- package/vendor/re2/app/tsconfig.json +17 -0
- package/vendor/re2/benchlog/benchplot.py +98 -0
- package/vendor/re2/benchlog/mktable +155 -0
- package/vendor/re2/doc/mksyntaxgo +42 -0
- package/vendor/re2/doc/mksyntaxhtml +42 -0
- package/vendor/re2/doc/mksyntaxwiki +36 -0
- package/vendor/re2/doc/syntax.html +477 -0
- package/vendor/re2/doc/syntax.txt +463 -0
- package/vendor/re2/lib/git/commit-msg.hook +104 -0
- package/vendor/re2/libre2.symbols +19 -0
- package/vendor/re2/libre2.symbols.darwin +15 -0
- package/vendor/re2/python/BUILD.bazel +36 -0
- package/vendor/re2/python/README +1 -0
- package/vendor/re2/python/_re2.cc +338 -0
- package/vendor/re2/python/re2.py +582 -0
- package/vendor/re2/python/re2_test.py +482 -0
- package/vendor/re2/python/setup.py +105 -0
- package/vendor/re2/{bitmap256.cc → re2/bitmap256.cc} +4 -4
- package/vendor/re2/{bitstate.cc → re2/bitstate.cc} +21 -25
- package/vendor/re2/{compile.cc → re2/compile.cc} +5 -4
- package/vendor/re2/{dfa.cc → re2/dfa.cc} +120 -101
- package/vendor/re2/{filtered_re2.cc → re2/filtered_re2.cc} +8 -11
- package/vendor/re2/{filtered_re2.h → re2/filtered_re2.h} +5 -4
- package/vendor/re2/{fuzzing → re2/fuzzing}/re2_fuzzer.cc +4 -6
- package/vendor/re2/{mimics_pcre.cc → re2/mimics_pcre.cc} +0 -1
- package/vendor/re2/{nfa.cc → re2/nfa.cc} +34 -37
- package/vendor/re2/{onepass.cc → re2/onepass.cc} +25 -27
- package/vendor/re2/{parse.cc → re2/parse.cc} +118 -121
- package/vendor/re2/{prefilter.cc → re2/prefilter.cc} +2 -3
- package/vendor/re2/{prefilter.h → re2/prefilter.h} +0 -1
- package/vendor/re2/{prefilter_tree.cc → re2/prefilter_tree.cc} +4 -5
- package/vendor/re2/{prefilter_tree.h → re2/prefilter_tree.h} +1 -2
- package/vendor/re2/{prog.cc → re2/prog.cc} +20 -21
- package/vendor/re2/{prog.h → re2/prog.h} +21 -22
- package/vendor/re2/{re2.cc → re2/re2.cc} +51 -62
- package/vendor/re2/{re2.h → re2/re2.h} +78 -40
- package/vendor/re2/{regexp.cc → re2/regexp.cc} +11 -12
- package/vendor/re2/{regexp.h → re2/regexp.h} +9 -10
- package/vendor/re2/{set.cc → re2/set.cc} +3 -5
- package/vendor/re2/{set.h → re2/set.h} +4 -3
- package/vendor/re2/{simplify.cc → re2/simplify.cc} +1 -2
- package/vendor/re2/re2/stringpiece.h +24 -0
- package/vendor/re2/{testing → re2/testing}/backtrack.cc +22 -25
- package/vendor/re2/{testing → re2/testing}/charclass_test.cc +23 -21
- package/vendor/re2/{testing → re2/testing}/compile_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/dfa_test.cc +36 -30
- package/vendor/re2/{testing → re2/testing}/dump.cc +8 -8
- package/vendor/re2/{testing → re2/testing}/exhaustive1_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive2_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive3_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.cc +36 -32
- package/vendor/re2/{testing → re2/testing}/exhaustive_tester.h +0 -1
- package/vendor/re2/{testing → re2/testing}/filtered_re2_test.cc +9 -8
- package/vendor/re2/{testing → re2/testing}/mimics_pcre_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/null_walker.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/parse_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/possible_match_test.cc +15 -14
- package/vendor/re2/{testing → re2/testing}/random_test.cc +13 -12
- package/vendor/re2/{testing → re2/testing}/re2_arg_test.cc +25 -2
- package/vendor/re2/{testing → re2/testing}/re2_test.cc +49 -47
- package/vendor/re2/{testing → re2/testing}/regexp_benchmark.cc +144 -145
- package/vendor/re2/{testing → re2/testing}/regexp_generator.cc +18 -14
- package/vendor/re2/{testing → re2/testing}/regexp_generator.h +3 -4
- package/vendor/re2/{testing → re2/testing}/regexp_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/required_prefix_test.cc +5 -4
- package/vendor/re2/{testing → re2/testing}/search_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/set_test.cc +1 -1
- package/vendor/re2/{testing → re2/testing}/simplify_test.cc +3 -2
- package/vendor/re2/{testing → re2/testing}/string_generator.cc +3 -3
- package/vendor/re2/{testing → re2/testing}/string_generator.h +5 -6
- package/vendor/re2/{testing → re2/testing}/string_generator_test.cc +2 -2
- package/vendor/re2/{testing → re2/testing}/tester.cc +77 -78
- package/vendor/re2/{testing → re2/testing}/tester.h +13 -15
- package/vendor/re2/{tostring.cc → re2/tostring.cc} +7 -8
- package/vendor/re2/{unicode_casefold.h → re2/unicode_casefold.h} +0 -1
- package/vendor/re2/{unicode_groups.h → re2/unicode_groups.h} +0 -1
- package/vendor/re2/{walker-inl.h → re2/walker-inl.h} +2 -1
- package/vendor/re2/re2.pc.in +9 -0
- package/vendor/re2/re2Config.cmake.in +28 -0
- package/vendor/re2/runtests +33 -0
- package/vendor/re2/testinstall.cc +27 -0
- package/vendor/re2/ucs2.diff +567 -0
- package/vendor/{util → re2/util}/logging.h +2 -2
- package/vendor/{util → re2/util}/pcre.cc +47 -116
- package/vendor/{util → re2/util}/pcre.h +53 -63
- package/vendor/re2/util/strutil.cc +26 -0
- package/vendor/{util → re2/util}/strutil.h +0 -5
- package/vendor/re2/stringpiece.cc +0 -65
- package/vendor/re2/stringpiece.h +0 -213
- package/vendor/util/benchmark.cc +0 -131
- package/vendor/util/benchmark.h +0 -156
- package/vendor/util/flags.h +0 -26
- package/vendor/util/mix.h +0 -41
- package/vendor/util/mutex.h +0 -164
- package/vendor/util/strutil.cc +0 -149
- package/vendor/util/test.cc +0 -34
- package/vendor/util/test.h +0 -50
- package/vendor/util/util.h +0 -42
- /package/vendor/{LICENSE → re2/LICENSE} +0 -0
- /package/vendor/re2/{bitmap256.h → re2/bitmap256.h} +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/LICENSE +0 -0
- /package/vendor/re2/{fuzzing → re2/fuzzing}/compiler-rt/include/fuzzer/FuzzedDataProvider.h +0 -0
- /package/vendor/re2/{make_perl_groups.pl → re2/make_perl_groups.pl} +0 -0
- /package/vendor/re2/{make_unicode_casefold.py → re2/make_unicode_casefold.py} +0 -0
- /package/vendor/re2/{make_unicode_groups.py → re2/make_unicode_groups.py} +0 -0
- /package/vendor/re2/{perl_groups.cc → re2/perl_groups.cc} +0 -0
- /package/vendor/re2/{pod_array.h → re2/pod_array.h} +0 -0
- /package/vendor/re2/{sparse_array.h → re2/sparse_array.h} +0 -0
- /package/vendor/re2/{sparse_set.h → re2/sparse_set.h} +0 -0
- /package/vendor/re2/{unicode.py → re2/unicode.py} +0 -0
- /package/vendor/re2/{unicode_casefold.cc → re2/unicode_casefold.cc} +0 -0
- /package/vendor/re2/{unicode_groups.cc → re2/unicode_groups.cc} +0 -0
- /package/vendor/{util → re2/util}/fuzz.cc +0 -0
- /package/vendor/{util → re2/util}/malloc_counter.h +0 -0
- /package/vendor/{util → re2/util}/rune.cc +0 -0
- /package/vendor/{util → re2/util}/utf.h +0 -0
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
#include <stdio.h>
|
|
8
8
|
|
|
9
|
-
#include "
|
|
9
|
+
#include "absl/base/macros.h"
|
|
10
|
+
#include "absl/strings/str_format.h"
|
|
11
|
+
#include "gtest/gtest.h"
|
|
10
12
|
#include "util/utf.h"
|
|
11
13
|
#include "re2/regexp.h"
|
|
12
14
|
|
|
@@ -88,25 +90,25 @@ static CCTest tests[] = {
|
|
|
88
90
|
template <typename CharClass>
|
|
89
91
|
static void Broke(const char *desc, const CCTest* t, CharClass* cc) {
|
|
90
92
|
if (t == NULL) {
|
|
91
|
-
|
|
93
|
+
absl::PrintF("\t%s:", desc);
|
|
92
94
|
} else {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
absl::PrintF("\n");
|
|
96
|
+
absl::PrintF("CharClass added: [%s]", desc);
|
|
95
97
|
for (int k = 0; t->add[k].lo >= 0; k++)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
absl::PrintF(" %d-%d", t->add[k].lo, t->add[k].hi);
|
|
99
|
+
absl::PrintF("\n");
|
|
98
100
|
if (t->remove >= 0)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
absl::PrintF("Removed > %d\n", t->remove);
|
|
102
|
+
absl::PrintF("\twant:");
|
|
101
103
|
for (int k = 0; t->final[k].lo >= 0; k++)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
absl::PrintF(" %d-%d", t->final[k].lo, t->final[k].hi);
|
|
105
|
+
absl::PrintF("\n");
|
|
106
|
+
absl::PrintF("\thave:");
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
for (typename CharClass::iterator it = cc->begin(); it != cc->end(); ++it)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
absl::PrintF(" %d-%d", it->lo, it->hi);
|
|
111
|
+
absl::PrintF("\n");
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
bool ShouldContain(CCTest *t, int x) {
|
|
@@ -155,7 +157,7 @@ bool CorrectCC(CharClass *cc, CCTest *t, const char *desc) {
|
|
|
155
157
|
}
|
|
156
158
|
if (cc->size() != size) {
|
|
157
159
|
Broke(desc, t, cc);
|
|
158
|
-
|
|
160
|
+
absl::PrintF("wrong size: want %d have %d\n", size, cc->size());
|
|
159
161
|
return false;
|
|
160
162
|
}
|
|
161
163
|
|
|
@@ -164,8 +166,8 @@ bool CorrectCC(CharClass *cc, CCTest *t, const char *desc) {
|
|
|
164
166
|
j = Runemax;
|
|
165
167
|
if (ShouldContain(t, j) != cc->Contains(j)) {
|
|
166
168
|
Broke(desc, t, cc);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
absl::PrintF("want contains(%d)=%d, got %d\n",
|
|
170
|
+
j, ShouldContain(t, j), cc->Contains(j));
|
|
169
171
|
return false;
|
|
170
172
|
}
|
|
171
173
|
}
|
|
@@ -177,16 +179,16 @@ bool CorrectCC(CharClass *cc, CCTest *t, const char *desc) {
|
|
|
177
179
|
if (ShouldContain(t, j) == ncc->Contains(j)) {
|
|
178
180
|
Broke(desc, t, cc);
|
|
179
181
|
Broke("ncc", NULL, ncc);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
absl::PrintF("want ncc contains(%d)!=%d, got %d\n",
|
|
183
|
+
j, ShouldContain(t, j), ncc->Contains(j));
|
|
182
184
|
Delete(ncc);
|
|
183
185
|
return false;
|
|
184
186
|
}
|
|
185
187
|
if (ncc->size() != Runemax+1 - cc->size()) {
|
|
186
188
|
Broke(desc, t, cc);
|
|
187
189
|
Broke("ncc", NULL, ncc);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
absl::PrintF("ncc size should be %d is %d\n",
|
|
191
|
+
Runemax+1 - cc->size(), ncc->size());
|
|
190
192
|
Delete(ncc);
|
|
191
193
|
return false;
|
|
192
194
|
}
|
|
@@ -197,7 +199,7 @@ bool CorrectCC(CharClass *cc, CCTest *t, const char *desc) {
|
|
|
197
199
|
|
|
198
200
|
TEST(TestCharClassBuilder, Adds) {
|
|
199
201
|
int nfail = 0;
|
|
200
|
-
for (size_t i = 0; i <
|
|
202
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) {
|
|
201
203
|
CharClassBuilder ccb;
|
|
202
204
|
CCTest* t = &tests[i];
|
|
203
205
|
for (int j = 0; t->add[j].lo >= 0; j++)
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
#include <string>
|
|
8
8
|
|
|
9
|
-
#include "
|
|
9
|
+
#include "absl/base/macros.h"
|
|
10
|
+
#include "gtest/gtest.h"
|
|
10
11
|
#include "util/logging.h"
|
|
11
12
|
#include "re2/regexp.h"
|
|
12
13
|
#include "re2/prog.h"
|
|
@@ -127,7 +128,7 @@ static Test tests[] = {
|
|
|
127
128
|
|
|
128
129
|
TEST(TestRegexpCompileToProg, Simple) {
|
|
129
130
|
int failed = 0;
|
|
130
|
-
for (size_t i = 0; i <
|
|
131
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) {
|
|
131
132
|
const re2::Test& t = tests[i];
|
|
132
133
|
Regexp* re = Regexp::Parse(t.regexp, Regexp::PerlX|Regexp::Latin1, NULL);
|
|
133
134
|
if (re == NULL) {
|
|
@@ -156,7 +157,7 @@ TEST(TestRegexpCompileToProg, Simple) {
|
|
|
156
157
|
EXPECT_EQ(failed, 0);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
static void DumpByteMap(
|
|
160
|
+
static void DumpByteMap(absl::string_view pattern, Regexp::ParseFlags flags,
|
|
160
161
|
std::string* bytemap) {
|
|
161
162
|
Regexp* re = Regexp::Parse(pattern, flags, NULL);
|
|
162
163
|
EXPECT_TRUE(re != NULL);
|
|
@@ -257,7 +258,7 @@ TEST(TestCompile, InsufficientMemory) {
|
|
|
257
258
|
re->Decref();
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
static void Dump(
|
|
261
|
+
static void Dump(absl::string_view pattern, Regexp::ParseFlags flags,
|
|
261
262
|
std::string* forward, std::string* reverse) {
|
|
262
263
|
Regexp* re = Regexp::Parse(pattern, flags, NULL);
|
|
263
264
|
EXPECT_TRUE(re != NULL);
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
#include <thread>
|
|
8
8
|
#include <vector>
|
|
9
9
|
|
|
10
|
-
#include "
|
|
11
|
-
#include "
|
|
10
|
+
#include "absl/base/macros.h"
|
|
11
|
+
#include "absl/flags/flag.h"
|
|
12
|
+
#include "absl/strings/str_format.h"
|
|
13
|
+
#include "gtest/gtest.h"
|
|
12
14
|
#include "util/logging.h"
|
|
13
15
|
#include "util/malloc_counter.h"
|
|
14
|
-
#include "util/strutil.h"
|
|
15
16
|
#include "re2/prog.h"
|
|
16
17
|
#include "re2/re2.h"
|
|
17
18
|
#include "re2/regexp.h"
|
|
@@ -20,9 +21,9 @@
|
|
|
20
21
|
|
|
21
22
|
static const bool UsingMallocCounter = false;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
ABSL_FLAG(int, size, 8, "log2(number of DFA nodes)");
|
|
25
|
+
ABSL_FLAG(int, repeat, 2, "Repetition count.");
|
|
26
|
+
ABSL_FLAG(int, threads, 4, "number of threads");
|
|
26
27
|
|
|
27
28
|
namespace re2 {
|
|
28
29
|
|
|
@@ -50,7 +51,7 @@ static void DoBuild(Prog* prog) {
|
|
|
50
51
|
TEST(Multithreaded, BuildEntireDFA) {
|
|
51
52
|
// Create regexp with 2^FLAGS_size states in DFA.
|
|
52
53
|
std::string s = "a";
|
|
53
|
-
for (int i = 0; i < GetFlag(FLAGS_size); i++)
|
|
54
|
+
for (int i = 0; i < absl::GetFlag(FLAGS_size); i++)
|
|
54
55
|
s += "[ab]";
|
|
55
56
|
s += "b";
|
|
56
57
|
Regexp* re = Regexp::Parse(s, Regexp::LikePerl, NULL);
|
|
@@ -68,14 +69,14 @@ TEST(Multithreaded, BuildEntireDFA) {
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
// Build the DFA simultaneously in a bunch of threads.
|
|
71
|
-
for (int i = 0; i < GetFlag(FLAGS_repeat); i++) {
|
|
72
|
+
for (int i = 0; i < absl::GetFlag(FLAGS_repeat); i++) {
|
|
72
73
|
Prog* prog = re->CompileToProg(0);
|
|
73
74
|
ASSERT_TRUE(prog != NULL);
|
|
74
75
|
|
|
75
76
|
std::vector<std::thread> threads;
|
|
76
|
-
for (int j = 0; j < GetFlag(FLAGS_threads); j++)
|
|
77
|
+
for (int j = 0; j < absl::GetFlag(FLAGS_threads); j++)
|
|
77
78
|
threads.emplace_back(DoBuild, prog);
|
|
78
|
-
for (int j = 0; j < GetFlag(FLAGS_threads); j++)
|
|
79
|
+
for (int j = 0; j < absl::GetFlag(FLAGS_threads); j++)
|
|
79
80
|
threads[j].join();
|
|
80
81
|
|
|
81
82
|
// One more compile, to make sure everything is okay.
|
|
@@ -154,7 +155,7 @@ TEST(SingleThreaded, SearchDFA) {
|
|
|
154
155
|
// Empirically, n = 18 is a good compromise between the two.
|
|
155
156
|
const int n = 18;
|
|
156
157
|
|
|
157
|
-
Regexp* re = Regexp::Parse(
|
|
158
|
+
Regexp* re = Regexp::Parse(absl::StrFormat("0[01]{%d}$", n),
|
|
158
159
|
Regexp::LikePerl, NULL);
|
|
159
160
|
ASSERT_TRUE(re != NULL);
|
|
160
161
|
|
|
@@ -172,12 +173,14 @@ TEST(SingleThreaded, SearchDFA) {
|
|
|
172
173
|
for (int i = 0; i < 10; i++) {
|
|
173
174
|
bool matched = false;
|
|
174
175
|
bool failed = false;
|
|
175
|
-
matched =
|
|
176
|
-
|
|
176
|
+
matched =
|
|
177
|
+
prog->SearchDFA(match, absl::string_view(), Prog::kUnanchored,
|
|
178
|
+
Prog::kFirstMatch, NULL, &failed, NULL);
|
|
177
179
|
ASSERT_FALSE(failed);
|
|
178
180
|
ASSERT_TRUE(matched);
|
|
179
|
-
matched =
|
|
180
|
-
|
|
181
|
+
matched =
|
|
182
|
+
prog->SearchDFA(no_match, absl::string_view(), Prog::kUnanchored,
|
|
183
|
+
Prog::kFirstMatch, NULL, &failed, NULL);
|
|
181
184
|
ASSERT_FALSE(failed);
|
|
182
185
|
ASSERT_FALSE(matched);
|
|
183
186
|
}
|
|
@@ -201,17 +204,19 @@ TEST(SingleThreaded, SearchDFA) {
|
|
|
201
204
|
|
|
202
205
|
// Helper function: searches for match, which should match,
|
|
203
206
|
// and no_match, which should not.
|
|
204
|
-
static void DoSearch(Prog* prog,
|
|
205
|
-
|
|
207
|
+
static void DoSearch(Prog* prog, absl::string_view match,
|
|
208
|
+
absl::string_view no_match) {
|
|
206
209
|
for (int i = 0; i < 2; i++) {
|
|
207
210
|
bool matched = false;
|
|
208
211
|
bool failed = false;
|
|
209
|
-
matched =
|
|
210
|
-
|
|
212
|
+
matched =
|
|
213
|
+
prog->SearchDFA(match, absl::string_view(), Prog::kUnanchored,
|
|
214
|
+
Prog::kFirstMatch, NULL, &failed, NULL);
|
|
211
215
|
ASSERT_FALSE(failed);
|
|
212
216
|
ASSERT_TRUE(matched);
|
|
213
|
-
matched =
|
|
214
|
-
|
|
217
|
+
matched =
|
|
218
|
+
prog->SearchDFA(no_match, absl::string_view(), Prog::kUnanchored,
|
|
219
|
+
Prog::kFirstMatch, NULL, &failed, NULL);
|
|
215
220
|
ASSERT_FALSE(failed);
|
|
216
221
|
ASSERT_FALSE(matched);
|
|
217
222
|
}
|
|
@@ -224,7 +229,7 @@ TEST(Multithreaded, SearchDFA) {
|
|
|
224
229
|
|
|
225
230
|
// Same as single-threaded test above.
|
|
226
231
|
const int n = 18;
|
|
227
|
-
Regexp* re = Regexp::Parse(
|
|
232
|
+
Regexp* re = Regexp::Parse(absl::StrFormat("0[01]{%d}$", n),
|
|
228
233
|
Regexp::LikePerl, NULL);
|
|
229
234
|
ASSERT_TRUE(re != NULL);
|
|
230
235
|
std::string no_match = DeBruijnString(n);
|
|
@@ -243,14 +248,14 @@ TEST(Multithreaded, SearchDFA) {
|
|
|
243
248
|
|
|
244
249
|
// Run the search simultaneously in a bunch of threads.
|
|
245
250
|
// Reuse same flags for Multithreaded.BuildDFA above.
|
|
246
|
-
for (int i = 0; i < GetFlag(FLAGS_repeat); i++) {
|
|
251
|
+
for (int i = 0; i < absl::GetFlag(FLAGS_repeat); i++) {
|
|
247
252
|
Prog* prog = re->CompileToProg(1<<n);
|
|
248
253
|
ASSERT_TRUE(prog != NULL);
|
|
249
254
|
|
|
250
255
|
std::vector<std::thread> threads;
|
|
251
|
-
for (int j = 0; j < GetFlag(FLAGS_threads); j++)
|
|
256
|
+
for (int j = 0; j < absl::GetFlag(FLAGS_threads); j++)
|
|
252
257
|
threads.emplace_back(DoSearch, prog, match, no_match);
|
|
253
|
-
for (int j = 0; j < GetFlag(FLAGS_threads); j++)
|
|
258
|
+
for (int j = 0; j < absl::GetFlag(FLAGS_threads); j++)
|
|
254
259
|
threads[j].join();
|
|
255
260
|
|
|
256
261
|
delete prog;
|
|
@@ -281,15 +286,16 @@ ReverseTest reverse_tests[] = {
|
|
|
281
286
|
|
|
282
287
|
TEST(DFA, ReverseMatch) {
|
|
283
288
|
int nfail = 0;
|
|
284
|
-
for (size_t i = 0; i <
|
|
289
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(reverse_tests); i++) {
|
|
285
290
|
const ReverseTest& t = reverse_tests[i];
|
|
286
291
|
Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL);
|
|
287
292
|
ASSERT_TRUE(re != NULL);
|
|
288
293
|
Prog* prog = re->CompileToReverseProg(0);
|
|
289
294
|
ASSERT_TRUE(prog != NULL);
|
|
290
295
|
bool failed = false;
|
|
291
|
-
bool matched =
|
|
292
|
-
|
|
296
|
+
bool matched =
|
|
297
|
+
prog->SearchDFA(t.text, absl::string_view(), Prog::kUnanchored,
|
|
298
|
+
Prog::kFirstMatch, NULL, &failed, NULL);
|
|
293
299
|
if (matched != t.match) {
|
|
294
300
|
LOG(ERROR) << t.regexp << " on " << t.text << ": want " << t.match;
|
|
295
301
|
nfail++;
|
|
@@ -336,7 +342,7 @@ CallbackTest callback_tests[] = {
|
|
|
336
342
|
|
|
337
343
|
TEST(DFA, Callback) {
|
|
338
344
|
int nfail = 0;
|
|
339
|
-
for (size_t i = 0; i <
|
|
345
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(callback_tests); i++) {
|
|
340
346
|
const CallbackTest& t = callback_tests[i];
|
|
341
347
|
Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL);
|
|
342
348
|
ASSERT_TRUE(re != NULL);
|
|
@@ -349,7 +355,7 @@ TEST(DFA, Callback) {
|
|
|
349
355
|
dump += " ";
|
|
350
356
|
dump += match ? "[[" : "[";
|
|
351
357
|
for (int b = 0; b < prog->bytemap_range() + 1; b++)
|
|
352
|
-
dump +=
|
|
358
|
+
dump += absl::StrFormat("%d,", next[b]);
|
|
353
359
|
dump.pop_back();
|
|
354
360
|
dump += match ? "]]" : "]";
|
|
355
361
|
});
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
#include <string>
|
|
20
20
|
|
|
21
|
-
#include "
|
|
21
|
+
#include "absl/base/macros.h"
|
|
22
|
+
#include "absl/strings/str_format.h"
|
|
23
|
+
#include "gtest/gtest.h"
|
|
22
24
|
#include "util/logging.h"
|
|
23
|
-
#include "util/strutil.h"
|
|
24
25
|
#include "util/utf.h"
|
|
25
|
-
#include "re2/stringpiece.h"
|
|
26
26
|
#include "re2/regexp.h"
|
|
27
27
|
|
|
28
28
|
namespace re2 {
|
|
@@ -55,8 +55,8 @@ static const char* kOpcodeNames[] = {
|
|
|
55
55
|
// Create string representation of regexp with explicit structure.
|
|
56
56
|
// Nothing pretty, just for testing.
|
|
57
57
|
static void DumpRegexpAppending(Regexp* re, std::string* s) {
|
|
58
|
-
if (re->op() < 0 || re->op() >=
|
|
59
|
-
*s +=
|
|
58
|
+
if (re->op() < 0 || re->op() >= ABSL_ARRAYSIZE(kOpcodeNames)) {
|
|
59
|
+
*s += absl::StrFormat("op%d", re->op());
|
|
60
60
|
} else {
|
|
61
61
|
switch (re->op()) {
|
|
62
62
|
default:
|
|
@@ -129,7 +129,7 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) {
|
|
|
129
129
|
DumpRegexpAppending(re->sub()[0], s);
|
|
130
130
|
break;
|
|
131
131
|
case kRegexpRepeat:
|
|
132
|
-
s->append(
|
|
132
|
+
s->append(absl::StrFormat("%d,%d ", re->min(), re->max()));
|
|
133
133
|
DumpRegexpAppending(re->sub()[0], s);
|
|
134
134
|
break;
|
|
135
135
|
case kRegexpCharClass: {
|
|
@@ -139,9 +139,9 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) {
|
|
|
139
139
|
RuneRange rr = *it;
|
|
140
140
|
s->append(sep);
|
|
141
141
|
if (rr.lo == rr.hi)
|
|
142
|
-
s->append(
|
|
142
|
+
s->append(absl::StrFormat("%#x", rr.lo));
|
|
143
143
|
else
|
|
144
|
-
s->append(
|
|
144
|
+
s->append(absl::StrFormat("%#x-%#x", rr.lo, rr.hi));
|
|
145
145
|
sep = " ";
|
|
146
146
|
}
|
|
147
147
|
break;
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
|
|
14
14
|
#include <stdio.h>
|
|
15
15
|
|
|
16
|
-
#include "
|
|
17
|
-
#include "
|
|
16
|
+
#include "absl/base/macros.h"
|
|
17
|
+
#include "absl/flags/flag.h"
|
|
18
|
+
#include "absl/strings/str_format.h"
|
|
19
|
+
#include "gtest/gtest.h"
|
|
18
20
|
#include "util/logging.h"
|
|
19
|
-
#include "util/strutil.h"
|
|
20
21
|
#include "re2/testing/exhaustive_tester.h"
|
|
21
22
|
#include "re2/testing/tester.h"
|
|
22
23
|
|
|
@@ -25,15 +26,15 @@
|
|
|
25
26
|
#define LOGGING 0
|
|
26
27
|
#endif
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
ABSL_FLAG(bool, show_regexps, false, "show regexps during testing");
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
ABSL_FLAG(int, max_bad_regexp_inputs, 1,
|
|
32
|
+
"Stop testing a regular expression after finding this many "
|
|
33
|
+
"strings that break it.");
|
|
33
34
|
|
|
34
35
|
namespace re2 {
|
|
35
36
|
|
|
36
|
-
static char* escape(
|
|
37
|
+
static char* escape(absl::string_view sp) {
|
|
37
38
|
static char buf[512];
|
|
38
39
|
char* p = buf;
|
|
39
40
|
*p++ = '\"';
|
|
@@ -55,20 +56,21 @@ static char* escape(const StringPiece& sp) {
|
|
|
55
56
|
return buf;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
static void PrintResult(const RE2& re,
|
|
59
|
+
static void PrintResult(const RE2& re, absl::string_view input,
|
|
60
|
+
RE2::Anchor anchor, absl::string_view* m, int n) {
|
|
59
61
|
if (!re.Match(input, 0, input.size(), anchor, m, n)) {
|
|
60
|
-
|
|
62
|
+
absl::PrintF("-");
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
65
|
for (int i = 0; i < n; i++) {
|
|
64
66
|
if (i > 0)
|
|
65
|
-
|
|
67
|
+
absl::PrintF(" ");
|
|
66
68
|
if (m[i].data() == NULL)
|
|
67
|
-
|
|
69
|
+
absl::PrintF("-");
|
|
68
70
|
else
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
absl::PrintF("%d-%d",
|
|
72
|
+
BeginPtr(m[i]) - BeginPtr(input),
|
|
73
|
+
EndPtr(m[i]) - BeginPtr(input));
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -79,11 +81,13 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
|
|
|
79
81
|
regexps_++;
|
|
80
82
|
std::string regexp = const_regexp;
|
|
81
83
|
if (!topwrapper_.empty()) {
|
|
82
|
-
|
|
84
|
+
auto fmt = absl::ParsedFormat<'s'>::New(topwrapper_);
|
|
85
|
+
CHECK(fmt != nullptr);
|
|
86
|
+
regexp = absl::StrFormat(*fmt, regexp);
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
if (GetFlag(FLAGS_show_regexps)) {
|
|
86
|
-
|
|
89
|
+
if (absl::GetFlag(FLAGS_show_regexps)) {
|
|
90
|
+
absl::PrintF("\r%s", regexp);
|
|
87
91
|
fflush(stdout);
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -93,32 +97,32 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
|
|
|
93
97
|
if (randomstrings_)
|
|
94
98
|
LOG(ERROR) << "Cannot log with random strings.";
|
|
95
99
|
if (regexps_ == 1) { // first
|
|
96
|
-
|
|
100
|
+
absl::PrintF("strings\n");
|
|
97
101
|
strgen_.Reset();
|
|
98
102
|
while (strgen_.HasNext())
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
absl::PrintF("%s\n", escape(strgen_.Next()));
|
|
104
|
+
absl::PrintF("regexps\n");
|
|
101
105
|
}
|
|
102
|
-
|
|
106
|
+
absl::PrintF("%s\n", escape(regexp));
|
|
103
107
|
|
|
104
108
|
RE2 re(regexp);
|
|
105
109
|
RE2::Options longest;
|
|
106
110
|
longest.set_longest_match(true);
|
|
107
111
|
RE2 relongest(regexp, longest);
|
|
108
112
|
int ngroup = re.NumberOfCapturingGroups()+1;
|
|
109
|
-
|
|
113
|
+
absl::string_view* group = new absl::string_view[ngroup];
|
|
110
114
|
|
|
111
115
|
strgen_.Reset();
|
|
112
116
|
while (strgen_.HasNext()) {
|
|
113
|
-
|
|
117
|
+
absl::string_view input = strgen_.Next();
|
|
114
118
|
PrintResult(re, input, RE2::ANCHOR_BOTH, group, ngroup);
|
|
115
|
-
|
|
119
|
+
absl::PrintF(";");
|
|
116
120
|
PrintResult(re, input, RE2::UNANCHORED, group, ngroup);
|
|
117
|
-
|
|
121
|
+
absl::PrintF(";");
|
|
118
122
|
PrintResult(relongest, input, RE2::ANCHOR_BOTH, group, ngroup);
|
|
119
|
-
|
|
123
|
+
absl::PrintF(";");
|
|
120
124
|
PrintResult(relongest, input, RE2::UNANCHORED, group, ngroup);
|
|
121
|
-
|
|
125
|
+
absl::PrintF("\n");
|
|
122
126
|
}
|
|
123
127
|
delete[] group;
|
|
124
128
|
return;
|
|
@@ -137,7 +141,7 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) {
|
|
|
137
141
|
tests_++;
|
|
138
142
|
if (!tester.TestInput(strgen_.Next())) {
|
|
139
143
|
failures_++;
|
|
140
|
-
if (++bad_inputs >= GetFlag(FLAGS_max_bad_regexp_inputs))
|
|
144
|
+
if (++bad_inputs >= absl::GetFlag(FLAGS_max_bad_regexp_inputs))
|
|
141
145
|
break;
|
|
142
146
|
}
|
|
143
147
|
}
|
|
@@ -164,8 +168,8 @@ void ExhaustiveTest(int maxatoms, int maxops,
|
|
|
164
168
|
topwrapper);
|
|
165
169
|
t.Generate();
|
|
166
170
|
if (!LOGGING) {
|
|
167
|
-
|
|
168
|
-
|
|
171
|
+
absl::PrintF("%d regexps, %d tests, %d failures [%d/%d str]\n",
|
|
172
|
+
t.regexps(), t.tests(), t.failures(), maxstrlen, stralphabet.size());
|
|
169
173
|
}
|
|
170
174
|
EXPECT_EQ(0, t.failures());
|
|
171
175
|
}
|
|
@@ -177,7 +181,7 @@ void EgrepTest(int maxatoms, int maxops, const std::string& alphabet,
|
|
|
177
181
|
const std::string& wrapper) {
|
|
178
182
|
const char* tops[] = { "", "^(?:%s)", "(?:%s)$", "^(?:%s)$" };
|
|
179
183
|
|
|
180
|
-
for (size_t i = 0; i <
|
|
184
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(tops); i++) {
|
|
181
185
|
ExhaustiveTest(maxatoms, maxops,
|
|
182
186
|
Split("", alphabet),
|
|
183
187
|
RegexpGenerator::EgrepOps(),
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
#include <vector>
|
|
10
10
|
#include <utility>
|
|
11
11
|
|
|
12
|
-
#include "
|
|
12
|
+
#include "absl/base/macros.h"
|
|
13
|
+
#include "gtest/gtest.h"
|
|
13
14
|
#include "util/logging.h"
|
|
14
15
|
#include "re2/filtered_re2.h"
|
|
15
16
|
#include "re2/re2.h"
|
|
@@ -185,14 +186,14 @@ bool CheckExpectedAtoms(const char* atoms[],
|
|
|
185
186
|
|
|
186
187
|
TEST(FilteredRE2Test, AtomTests) {
|
|
187
188
|
int nfail = 0;
|
|
188
|
-
for (size_t i = 0; i <
|
|
189
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(atom_tests); i++) {
|
|
189
190
|
FilterTestVars v;
|
|
190
191
|
AtomTest* t = &atom_tests[i];
|
|
191
192
|
size_t nregexp, natom;
|
|
192
|
-
for (nregexp = 0; nregexp <
|
|
193
|
+
for (nregexp = 0; nregexp < ABSL_ARRAYSIZE(t->regexps); nregexp++)
|
|
193
194
|
if (t->regexps[nregexp] == NULL)
|
|
194
195
|
break;
|
|
195
|
-
for (natom = 0; natom <
|
|
196
|
+
for (natom = 0; natom < ABSL_ARRAYSIZE(t->atoms); natom++)
|
|
196
197
|
if (t->atoms[natom] == NULL)
|
|
197
198
|
break;
|
|
198
199
|
AddRegexpsAndCompile(t->regexps, nregexp, &v);
|
|
@@ -224,7 +225,7 @@ TEST(FilteredRE2Test, MatchEmptyPattern) {
|
|
|
224
225
|
// the index we use for the test is for the correct test.
|
|
225
226
|
EXPECT_EQ("CheckEmptyPattern", std::string(t->testname));
|
|
226
227
|
size_t nregexp;
|
|
227
|
-
for (nregexp = 0; nregexp <
|
|
228
|
+
for (nregexp = 0; nregexp < ABSL_ARRAYSIZE(t->regexps); nregexp++)
|
|
228
229
|
if (t->regexps[nregexp] == NULL)
|
|
229
230
|
break;
|
|
230
231
|
AddRegexpsAndCompile(t->regexps, nregexp, &v);
|
|
@@ -241,7 +242,7 @@ TEST(FilteredRE2Test, MatchTests) {
|
|
|
241
242
|
// for this test.
|
|
242
243
|
EXPECT_EQ("SubstrAtomRemovesSuperStrInOr", std::string(t->testname));
|
|
243
244
|
size_t nregexp;
|
|
244
|
-
for (nregexp = 0; nregexp <
|
|
245
|
+
for (nregexp = 0; nregexp < ABSL_ARRAYSIZE(t->regexps); nregexp++)
|
|
245
246
|
if (t->regexps[nregexp] == NULL)
|
|
246
247
|
break;
|
|
247
248
|
AddRegexpsAndCompile(t->regexps, nregexp, &v);
|
|
@@ -288,8 +289,8 @@ TEST(FilteredRE2Test, EmptyStringInStringSetBug) {
|
|
|
288
289
|
FilterTestVars v(0); // override the minimum atom length
|
|
289
290
|
const char* regexps[] = {"-R.+(|ADD=;AA){12}}"};
|
|
290
291
|
const char* atoms[] = {"", "-r", "add=;aa", "}"};
|
|
291
|
-
AddRegexpsAndCompile(regexps,
|
|
292
|
-
EXPECT_TRUE(CheckExpectedAtoms(atoms,
|
|
292
|
+
AddRegexpsAndCompile(regexps, ABSL_ARRAYSIZE(regexps), &v);
|
|
293
|
+
EXPECT_TRUE(CheckExpectedAtoms(atoms, ABSL_ARRAYSIZE(atoms),
|
|
293
294
|
"EmptyStringInStringSetBug", &v));
|
|
294
295
|
}
|
|
295
296
|
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
#include "
|
|
5
|
+
#include "absl/base/macros.h"
|
|
6
|
+
#include "gtest/gtest.h"
|
|
6
7
|
#include "util/logging.h"
|
|
7
8
|
#include "re2/prog.h"
|
|
8
9
|
#include "re2/regexp.h"
|
|
@@ -58,7 +59,7 @@ static PCRETest tests[] = {
|
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
TEST(MimicsPCRE, SimpleTests) {
|
|
61
|
-
for (size_t i = 0; i <
|
|
62
|
+
for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) {
|
|
62
63
|
const PCRETest& t = tests[i];
|
|
63
64
|
for (size_t j = 0; j < 2; j++) {
|
|
64
65
|
Regexp::ParseFlags flags = Regexp::LikePerl;
|