diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2018-12-05 10:34:17 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2018-12-05 10:34:19 +0900 |
commit | cdc7d1622945b5442057ec24743c3546fcdec3e7 (patch) | |
tree | 190c6fdcb3263f5fc5524138240aa0b2a80472f4 | |
parent | a019c763979d470e277ab79d1d0797941e5fb0f4 (diff) | |
download | re2-cdc7d1622945b5442057ec24743c3546fcdec3e7.tar.gz re2-cdc7d1622945b5442057ec24743c3546fcdec3e7.tar.bz2 re2-cdc7d1622945b5442057ec24743c3546fcdec3e7.zip |
Imported Upstream version 20180301upstream/20180301
Change-Id: Ifaa605e52a763d5a944d05d1b9acf5a7f05da130
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
-rw-r--r-- | BUILD | 17 | ||||
-rw-r--r-- | kokoro/macos-bazel.cfg | 1 | ||||
-rwxr-xr-x | kokoro/macos-bazel.sh | 26 | ||||
-rwxr-xr-x | kokoro/windows-bazel.bat | 30 | ||||
-rw-r--r-- | kokoro/windows-bazel.cfg | 1 | ||||
-rwxr-xr-x | kokoro/windows-cmake.bat | 21 | ||||
-rw-r--r-- | re2/dfa.cc | 11 | ||||
-rw-r--r-- | re2/fuzzing/re2_fuzzer.cc | 2 | ||||
-rw-r--r-- | re2/nfa.cc | 3 | ||||
-rw-r--r-- | re2/parse.cc | 4 | ||||
-rw-r--r-- | re2/re2.cc | 40 | ||||
-rw-r--r-- | re2/re2.h | 42 | ||||
-rw-r--r-- | re2/set.cc | 2 | ||||
-rw-r--r-- | re2/stringpiece.h | 8 | ||||
-rw-r--r-- | re2/testing/compile_test.cc | 2 | ||||
-rw-r--r-- | re2/testing/dfa_test.cc | 56 | ||||
-rw-r--r-- | re2/testing/mimics_pcre_test.cc | 4 | ||||
-rw-r--r-- | re2/testing/parse_test.cc | 22 | ||||
-rw-r--r-- | re2/testing/possible_match_test.cc | 14 | ||||
-rw-r--r-- | re2/testing/re2_test.cc | 813 | ||||
-rw-r--r-- | re2/testing/regexp_test.cc | 8 | ||||
-rw-r--r-- | re2/testing/required_prefix_test.cc | 10 | ||||
-rw-r--r-- | re2/testing/search_test.cc | 4 | ||||
-rw-r--r-- | re2/testing/set_test.cc | 236 | ||||
-rw-r--r-- | re2/testing/simplify_test.cc | 6 | ||||
-rw-r--r-- | re2/testing/string_generator_test.cc | 2 | ||||
-rw-r--r-- | re2/testing/tester.cc | 2 | ||||
-rw-r--r-- | re2_test.bzl | 2 | ||||
-rw-r--r-- | util/test.cc | 3 | ||||
-rw-r--r-- | util/test.h | 20 |
30 files changed, 738 insertions, 674 deletions
@@ -9,6 +9,11 @@ licenses(["notice"]) exports_files(["LICENSE"]) config_setting( + name = "darwin", + values = {"cpu": "darwin"}, +) + +config_setting( name = "windows", values = {"cpu": "x64_windows"}, ) @@ -73,6 +78,10 @@ cc_library( "//conditions:default": ["-pthread"], }), linkopts = select({ + # Darwin doesn't need `-pthread' when linking and it appears that + # older versions of Clang will warn about the unused command line + # argument, so just don't pass it. + ":darwin": [], ":windows": [], ":windows_msvc": [], "//conditions:default": ["-pthread"], @@ -225,13 +234,5 @@ cc_binary( name = "regexp_benchmark", testonly = 1, srcs = ["re2/testing/regexp_benchmark.cc"], - linkopts = select({ - ":windows": [], - ":windows_msvc": [], - "//conditions:default": [ - "-lm", - "-lrt", - ], - }), deps = [":benchmark"], ) diff --git a/kokoro/macos-bazel.cfg b/kokoro/macos-bazel.cfg new file mode 100644 index 0000000..7901981 --- /dev/null +++ b/kokoro/macos-bazel.cfg @@ -0,0 +1 @@ +build_file: "re2/kokoro/macos-bazel.sh" diff --git a/kokoro/macos-bazel.sh b/kokoro/macos-bazel.sh new file mode 100755 index 0000000..6f25982 --- /dev/null +++ b/kokoro/macos-bazel.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -eux + +cd git/re2 + +bazel clean +bazel build --compilation_mode=dbg -- //... +bazel test --compilation_mode=dbg --test_output=errors -- //... \ + -//:dfa_test \ + -//:exhaustive1_test \ + -//:exhaustive2_test \ + -//:exhaustive3_test \ + -//:exhaustive_test \ + -//:random_test + +bazel clean +bazel build --compilation_mode=opt -- //... +bazel test --compilation_mode=opt --test_output=errors -- //... \ + -//:dfa_test \ + -//:exhaustive1_test \ + -//:exhaustive2_test \ + -//:exhaustive3_test \ + -//:exhaustive_test \ + -//:random_test + +exit 0 diff --git a/kokoro/windows-bazel.bat b/kokoro/windows-bazel.bat new file mode 100755 index 0000000..9ac3d5b --- /dev/null +++ b/kokoro/windows-bazel.bat @@ -0,0 +1,30 @@ +CD git/re2 ^ + || EXIT /B 1 + +bazel clean ^ + || EXIT /B 1 +bazel build --compilation_mode=dbg -- //... ^ + || EXIT /B 1 +bazel test --compilation_mode=dbg --test_output=errors -- //... ^ + -//:dfa_test ^ + -//:exhaustive1_test ^ + -//:exhaustive2_test ^ + -//:exhaustive3_test ^ + -//:exhaustive_test ^ + -//:random_test ^ + || EXIT /B 1 + +bazel clean ^ + || EXIT /B 1 +bazel build --compilation_mode=opt -- //... ^ + || EXIT /B 1 +bazel test --compilation_mode=opt --test_output=errors -- //... ^ + -//:dfa_test ^ + -//:exhaustive1_test ^ + -//:exhaustive2_test ^ + -//:exhaustive3_test ^ + -//:exhaustive_test ^ + -//:random_test ^ + || EXIT /B 1 + +EXIT /B 0 diff --git a/kokoro/windows-bazel.cfg b/kokoro/windows-bazel.cfg new file mode 100644 index 0000000..18b1ed7 --- /dev/null +++ b/kokoro/windows-bazel.cfg @@ -0,0 +1 @@ +build_file: "re2/kokoro/windows-bazel.bat" diff --git a/kokoro/windows-cmake.bat b/kokoro/windows-cmake.bat index 6b04b65..e926d88 100755 --- a/kokoro/windows-cmake.bat +++ b/kokoro/windows-cmake.bat @@ -1,11 +1,18 @@ -CD git/re2 || EXIT /B 1 +CD git/re2 ^ + || EXIT /B 1 -cmake -D CMAKE_BUILD_TYPE=Debug -G "Visual Studio 14 2015" -A x64 . || EXIT /B 1 -cmake --build . --config Debug --clean-first || EXIT /B 1 -ctest -C Debug --output-on-failure -E dfa^|exhaustive^|random || EXIT /B 1 +cmake -D CMAKE_BUILD_TYPE=Debug -G "Visual Studio 14 2015" -A x64 . ^ + || EXIT /B 1 +cmake --build . --config Debug --clean-first ^ + || EXIT /B 1 +ctest -C Debug --output-on-failure -E dfa^|exhaustive^|random ^ + || EXIT /B 1 -cmake -D CMAKE_BUILD_TYPE=Release -G "Visual Studio 14 2015" -A x64 . || EXIT /B 1 -cmake --build . --config Release --clean-first || EXIT /B 1 -ctest -C Release --output-on-failure -E dfa^|exhaustive^|random || EXIT /B 1 +cmake -D CMAKE_BUILD_TYPE=Release -G "Visual Studio 14 2015" -A x64 . ^ + || EXIT /B 1 +cmake --build . --config Release --clean-first ^ + || EXIT /B 1 +ctest -C Release --output-on-failure -E dfa^|exhaustive^|random ^ + || EXIT /B 1 EXIT /B 0 @@ -771,7 +771,7 @@ DFA::State* DFA::CachedState(int* inst, int ninst, uint32_t flag) { mem_budget_ -= mem + kStateCacheOverhead; // Allocate new state along with room for next_ and inst_. - char* space = new char[mem]; + char* space = std::allocator<char>().allocate(mem); State* s = new (space) State; (void) new (s->next_) std::atomic<State*>[nnext]; // Work around a unfortunate bug in older versions of libstdc++. @@ -798,7 +798,12 @@ void DFA::ClearCache() { StateSet::iterator tmp = begin; ++begin; // Deallocate the blob of memory that we allocated in DFA::CachedState(). - delete[] reinterpret_cast<const char*>(*tmp); + // We recompute mem in order to benefit from sized delete where possible. + int ninst = (*tmp)->ninst_; + int nnext = prog_->bytemap_range() + 1; // + 1 for kByteEndText slot + int mem = sizeof(State) + nnext*sizeof(std::atomic<State*>) + + ninst*sizeof(int); + std::allocator<char>().deallocate(reinterpret_cast<char*>(*tmp), mem); } state_cache_.clear(); } @@ -1779,7 +1784,7 @@ bool DFA::Search(const StringPiece& text, if (ExtraDebug) { fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str()); fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n", - text.ToString().c_str(), anchored, want_earliest_match, + string(text).c_str(), anchored, want_earliest_match, run_forward, kind_); } diff --git a/re2/fuzzing/re2_fuzzer.cc b/re2/fuzzing/re2_fuzzer.cc index d3cd145..5d2820b 100644 --- a/re2/fuzzing/re2_fuzzer.cc +++ b/re2/fuzzing/re2_fuzzer.cc @@ -45,7 +45,7 @@ void Test(StringPiece pattern, const RE2::Options& options, StringPiece text) { RE2::Consume(&sp1, re, &i1, &i2, &i3, &i4); RE2::FindAndConsume(&sp2, re, &d1, &d2, &d3, &d4); - s3 = s4 = text.ToString(); + s3 = s4 = string(text); RE2::Replace(&s3, re, ""); RE2::GlobalReplace(&s4, re, ""); @@ -492,8 +492,7 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context, if (ExtraDebug) fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n", - text.ToString().c_str(), context.ToString().c_str(), anchored, - longest); + string(text).c_str(), string(context).c_str(), anchored, longest); // Set up search. Threadq* runq = &q0_; diff --git a/re2/parse.cc b/re2/parse.cc index 3374345..56b4244 100644 --- a/re2/parse.cc +++ b/re2/parse.cc @@ -609,7 +609,7 @@ bool Regexp::ParseState::DoLeftParen(const StringPiece& name) { Regexp* re = new Regexp(kLeftParen, flags_); re->cap_ = ++ncap_; if (name.data() != NULL) - re->name_ = new string(name.ToString()); + re->name_ = new string(name); return PushRegexp(re); } @@ -1790,7 +1790,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags, // Look up the group in the ICU Unicode data. Because ICU provides full // Unicode properties support, this could be more than a lookup by name. ::icu::UnicodeString ustr = ::icu::UnicodeString::fromUTF8( - string("\\p{") + name.ToString() + string("}")); + string("\\p{") + string(name) + string("}")); UErrorCode uerr = U_ZERO_ERROR; ::icu::UnicodeSet uset(ustr, uerr); if (U_FAILURE(uerr)) { @@ -99,8 +99,8 @@ static RE2::ErrorCode RegexpErrorToRE2(re2::RegexpStatusCode code) { static string trunc(const StringPiece& pattern) { if (pattern.size() < 100) - return pattern.ToString(); - return pattern.substr(0, 100).ToString() + "..."; + return string(pattern); + return string(pattern.substr(0, 100)) + "..."; } @@ -172,7 +172,7 @@ void RE2::Init(const StringPiece& pattern, const Options& options) { empty_group_names = new std::map<int, string>; }); - pattern_ = pattern.ToString(); + pattern_ = string(pattern); options_.Copy(options); entire_regexp_ = NULL; suffix_regexp_ = NULL; @@ -196,7 +196,7 @@ void RE2::Init(const StringPiece& pattern, const Options& options) { } error_ = new string(status.Text()); error_code_ = RegexpErrorToRE2(status.code()); - error_arg_ = status.error_arg().ToString(); + error_arg_ = string(status.error_arg()); return; } @@ -345,9 +345,9 @@ bool RE2::FindAndConsumeN(StringPiece* input, const RE2& re, } } -bool RE2::Replace(string *str, - const RE2& re, - const StringPiece& rewrite) { +bool RE2::Replace(string* str, + const RE2& re, + const StringPiece& rewrite) { StringPiece vec[kVecSize]; int nvec = 1 + MaxSubmatch(rewrite); if (nvec > arraysize(vec)) @@ -365,9 +365,9 @@ bool RE2::Replace(string *str, return true; } -int RE2::GlobalReplace(string *str, - const RE2& re, - const StringPiece& rewrite) { +int RE2::GlobalReplace(string* str, + const RE2& re, + const StringPiece& rewrite) { StringPiece vec[kVecSize]; int nvec = 1 + MaxSubmatch(rewrite); if (nvec > arraysize(vec)) @@ -437,10 +437,10 @@ int RE2::GlobalReplace(string *str, return count; } -bool RE2::Extract(const StringPiece &text, - const RE2& re, - const StringPiece &rewrite, - string *out) { +bool RE2::Extract(const StringPiece& text, + const RE2& re, + const StringPiece& rewrite, + string* out) { StringPiece vec[kVecSize]; int nvec = 1 + MaxSubmatch(rewrite); if (nvec > arraysize(vec)) @@ -535,7 +535,7 @@ bool RE2::PossibleMatchRange(string* min, string* max, int maxlen) const { // Avoid possible locale nonsense in standard strcasecmp. // The string a is known to be all lowercase. static int ascii_strcasecmp(const char* a, const char* b, size_t len) { - const char *ae = a + len; + const char* ae = a + len; for (; a < ae; a++, b++) { uint8_t x = *a; @@ -774,7 +774,7 @@ bool RE2::Match(const StringPiece& text, // Internal matcher - like Match() but takes Args not StringPieces. bool RE2::DoMatch(const StringPiece& text, - Anchor anchor, + Anchor re_anchor, size_t* consumed, const Arg* const* args, int n) const { @@ -802,7 +802,7 @@ bool RE2::DoMatch(const StringPiece& text, heapvec = vec; } - if (!Match(text, 0, text.size(), anchor, vec, nvec)) { + if (!Match(text, 0, text.size(), re_anchor, vec, nvec)) { delete[] heapvec; return false; } @@ -896,8 +896,10 @@ int RE2::MaxSubmatch(const StringPiece& rewrite) { // Append the "rewrite" string, with backslash subsitutions from "vec", // to string "out". -bool RE2::Rewrite(string* out, const StringPiece& rewrite, - const StringPiece* vec, int veclen) const { +bool RE2::Rewrite(string* out, + const StringPiece& rewrite, + const StringPiece* vec, + int veclen) const { for (const char *s = rewrite.data(), *end = s + rewrite.size(); s < end; s++) { if (*s != '\\') { @@ -381,7 +381,7 @@ class RE2 { } #endif - // Replace the first match of "pattern" in "str" with "rewrite". + // Replace the first match of "re" in "str" with "rewrite". // Within "rewrite", backslash-escaped digits (\1 to \9) can be // used to insert text matching corresponding parenthesized group // from the pattern. \0 in "rewrite" refers to the entire matching @@ -394,8 +394,8 @@ class RE2 { // // Returns true if the pattern matches and a replacement occurs, // false otherwise. - static bool Replace(string *str, - const RE2& pattern, + static bool Replace(string* str, + const RE2& re, const StringPiece& rewrite); // Like Replace(), except replaces successive non-overlapping occurrences @@ -411,8 +411,8 @@ class RE2 { // replacing "ana" within "banana" makes only one replacement, not two. // // Returns the number of replacements made. - static int GlobalReplace(string *str, - const RE2& pattern, + static int GlobalReplace(string* str, + const RE2& re, const StringPiece& rewrite); // Like Replace, except that if the pattern matches, "rewrite" @@ -423,10 +423,10 @@ class RE2 { // successfully; if no match occurs, the string is left unaffected. // // REQUIRES: "text" must not alias any part of "*out". - static bool Extract(const StringPiece &text, - const RE2& pattern, - const StringPiece &rewrite, - string *out); + static bool Extract(const StringPiece& text, + const RE2& re, + const StringPiece& rewrite, + string* out); // Escapes all potentially meaningful regexp characters in // 'unquoted'. The returned string, used as a regular expression, @@ -481,28 +481,28 @@ class RE2 { // Match against text starting at offset startpos // and stopping the search at offset endpos. // Returns true if match found, false if not. - // On a successful match, fills in match[] (up to nmatch entries) + // On a successful match, fills in submatch[] (up to nsubmatch entries) // with information about submatches. - // I.e. matching RE2("(foo)|(bar)baz") on "barbazbla" will return true, - // setting match[0] = "barbaz", match[1].data() = NULL, match[2] = "bar", - // match[3].data() = NULL, ..., up to match[nmatch-1].data() = NULL. + // I.e. matching RE2("(foo)|(bar)baz") on "barbazbla" will return true, with + // submatch[0] = "barbaz", submatch[1].data() = NULL, submatch[2] = "bar", + // submatch[3].data() = NULL, ..., up to submatch[nsubmatch-1].data() = NULL. // // Don't ask for more match information than you will use: - // runs much faster with nmatch == 1 than nmatch > 1, and - // runs even faster if nmatch == 0. - // Doesn't make sense to use nmatch > 1 + NumberOfCapturingGroups(), + // runs much faster with nsubmatch == 1 than nsubmatch > 1, and + // runs even faster if nsubmatch == 0. + // Doesn't make sense to use nsubmatch > 1 + NumberOfCapturingGroups(), // but will be handled correctly. // // Passing text == StringPiece(NULL, 0) will be handled like any other // empty string, but note that on return, it will not be possible to tell // whether submatch i matched the empty string or did not match: - // either way, match[i].data() == NULL. + // either way, submatch[i].data() == NULL. bool Match(const StringPiece& text, size_t startpos, size_t endpos, - Anchor anchor, - StringPiece *match, - int nmatch) const; + Anchor re_anchor, + StringPiece* submatch, + int nsubmatch) const; // Check that the given rewrite string is suitable for use with this // regular expression. It checks that: @@ -713,7 +713,7 @@ class RE2 { void Init(const StringPiece& pattern, const Options& options); bool DoMatch(const StringPiece& text, - Anchor anchor, + Anchor re_anchor, size_t* consumed, const Arg* const args[], int n) const; @@ -68,7 +68,7 @@ int RE2::Set::Add(const StringPiece& pattern, string* error) { sub[1] = m; re = re2::Regexp::Concat(sub, 2, pf); } - elem_.emplace_back(pattern.ToString(), re); + elem_.emplace_back(string(pattern), re); return n; } diff --git a/re2/stringpiece.h b/re2/stringpiece.h index 133cc82..1db7a2a 100644 --- a/re2/stringpiece.h +++ b/re2/stringpiece.h @@ -30,6 +30,7 @@ namespace re2 { class StringPiece { public: + typedef std::char_traits<char> traits_type; typedef char value_type; typedef char* pointer; typedef const char* const_pointer; @@ -90,6 +91,13 @@ class StringPiece { size_ = len; } + // Converts to `std::basic_string`. + template <typename A> + explicit operator std::basic_string<char, traits_type, A>() const { + if (!data_) return {}; + return std::basic_string<char, traits_type, A>(data_, size_); + } + std::string as_string() const { return std::string(data_, size_); } diff --git a/re2/testing/compile_test.cc b/re2/testing/compile_test.cc index 99c6dba..d89d80f 100644 --- a/re2/testing/compile_test.cc +++ b/re2/testing/compile_test.cc @@ -128,7 +128,7 @@ TEST(TestRegexpCompileToProg, Simple) { failed++; continue; } - CHECK(re->CompileToProg(1) == NULL); + ASSERT_TRUE(re->CompileToProg(1) == NULL); string s = prog->Dump(); if (s != t.code) { LOG(ERROR) << "Incorrect compiled code for: " << t.regexp; diff --git a/re2/testing/dfa_test.cc b/re2/testing/dfa_test.cc index 7f0feea..eb44b4a 100644 --- a/re2/testing/dfa_test.cc +++ b/re2/testing/dfa_test.cc @@ -28,7 +28,7 @@ namespace re2 { // Helper function: builds entire DFA for prog. static void DoBuild(Prog* prog) { - CHECK(prog->BuildEntireDFA(Prog::kFirstMatch, nullptr)); + ASSERT_TRUE(prog->BuildEntireDFA(Prog::kFirstMatch, nullptr)); } TEST(Multithreaded, BuildEntireDFA) { @@ -38,12 +38,12 @@ TEST(Multithreaded, BuildEntireDFA) { s += "[ab]"; s += "b"; Regexp* re = Regexp::Parse(s, Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); // Check that single-threaded code works. { Prog* prog = re->CompileToProg(0); - CHECK(prog); + ASSERT_TRUE(prog != NULL); std::thread t(DoBuild, prog); t.join(); @@ -54,7 +54,7 @@ TEST(Multithreaded, BuildEntireDFA) { // Build the DFA simultaneously in a bunch of threads. for (int i = 0; i < FLAGS_repeat; i++) { Prog* prog = re->CompileToProg(0); - CHECK(prog); + ASSERT_TRUE(prog != NULL); std::vector<std::thread> threads; for (int j = 0; j < FLAGS_threads; j++) @@ -76,7 +76,7 @@ TEST(Multithreaded, BuildEntireDFA) { TEST(SingleThreaded, BuildEntireDFA) { // Create regexp with 2^30 states in DFA. Regexp* re = Regexp::Parse("a[ab]{30}b", Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); for (int i = 17; i < 24; i++) { int64_t limit = int64_t{1}<<i; @@ -85,7 +85,7 @@ TEST(SingleThreaded, BuildEntireDFA) { { testing::MallocCounter m(testing::MallocCounter::THIS_THREAD_ONLY); Prog* prog = re->CompileToProg(limit); - CHECK(prog); + ASSERT_TRUE(prog != NULL); //progusage = m.HeapGrowth(); //dfamem = prog->dfa_mem(); prog->BuildEntireDFA(Prog::kFirstMatch, nullptr); @@ -99,8 +99,8 @@ TEST(SingleThreaded, BuildEntireDFA) { // << "DFA budget " << dfamem << ", " // << "total " << usage; // Tolerate +/- 10%. - CHECK_GT(usage, limit*9/10); - CHECK_LT(usage, limit*11/10); + ASSERT_GT(usage, limit*9/10); + ASSERT_LT(usage, limit*11/10); } } re->Decref(); @@ -176,7 +176,7 @@ TEST(SingleThreaded, SearchDFA) { Regexp* re = Regexp::Parse(StringPrintf("0[01]{%d}$", n), Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); // The De Bruijn string for n ends with a 1 followed by n 0s in a row, // which is not a match for 0[01]{n}$. Adding one more 0 is a match. @@ -188,18 +188,18 @@ TEST(SingleThreaded, SearchDFA) { { testing::MallocCounter m(testing::MallocCounter::THIS_THREAD_ONLY); Prog* prog = re->CompileToProg(1<<n); - CHECK(prog); + ASSERT_TRUE(prog != NULL); for (int i = 0; i < 10; i++) { bool matched = false; bool failed = false; matched = prog->SearchDFA(match, StringPiece(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); - CHECK(!failed); - CHECK(matched); + ASSERT_FALSE(failed); + ASSERT_TRUE(matched); matched = prog->SearchDFA(no_match, StringPiece(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); - CHECK(!failed); - CHECK(!matched); + ASSERT_FALSE(failed); + ASSERT_FALSE(matched); } usage = m.HeapGrowth(); peak_usage = m.PeakHeapGrowth(); @@ -208,8 +208,8 @@ TEST(SingleThreaded, SearchDFA) { if (UsingMallocCounter) { //LOG(INFO) << "usage " << usage << ", " // << "peak usage " << peak_usage; - CHECK_LT(usage, 1<<n); - CHECK_LT(peak_usage, 1<<n); + ASSERT_LT(usage, 1<<n); + ASSERT_LT(peak_usage, 1<<n); } re->Decref(); @@ -226,12 +226,12 @@ static void DoSearch(Prog* prog, const StringPiece& match, bool failed = false; matched = prog->SearchDFA(match, StringPiece(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); - CHECK(!failed); - CHECK(matched); + ASSERT_FALSE(failed); + ASSERT_TRUE(matched); matched = prog->SearchDFA(no_match, StringPiece(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); - CHECK(!failed); - CHECK(!matched); + ASSERT_FALSE(failed); + ASSERT_FALSE(matched); } } @@ -242,14 +242,14 @@ TEST(Multithreaded, SearchDFA) { const int n = 18; Regexp* re = Regexp::Parse(StringPrintf("0[01]{%d}$", n), Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); string no_match = DeBruijnString(n); string match = no_match + "0"; // Check that single-threaded code works. { Prog* prog = re->CompileToProg(1<<n); - CHECK(prog); + ASSERT_TRUE(prog != NULL); std::thread t(DoSearch, prog, match, no_match); t.join(); @@ -261,7 +261,7 @@ TEST(Multithreaded, SearchDFA) { // Reuse same flags for Multithreaded.BuildDFA above. for (int i = 0; i < FLAGS_repeat; i++) { Prog* prog = re->CompileToProg(1<<n); - CHECK(prog); + ASSERT_TRUE(prog != NULL); std::vector<std::thread> threads; for (int j = 0; j < FLAGS_threads; j++) @@ -298,9 +298,9 @@ TEST(DFA, ReverseMatch) { for (int i = 0; i < arraysize(reverse_tests); i++) { const ReverseTest& t = reverse_tests[i]; Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); Prog* prog = re->CompileToReverseProg(0); - CHECK(prog); + ASSERT_TRUE(prog != NULL); bool failed = false; bool matched = prog->SearchDFA(t.text, StringPiece(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); @@ -353,12 +353,12 @@ TEST(DFA, Callback) { for (int i = 0; i < arraysize(callback_tests); i++) { const CallbackTest& t = callback_tests[i]; Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ASSERT_TRUE(prog != NULL); string dump; prog->BuildEntireDFA(Prog::kLongestMatch, [&](const int* next, bool match) { - CHECK(next != NULL); + ASSERT_TRUE(next != NULL); if (!dump.empty()) StringAppendF(&dump, " "); StringAppendF(&dump, match ? "[[" : "["); diff --git a/re2/testing/mimics_pcre_test.cc b/re2/testing/mimics_pcre_test.cc index 541e7d2..2dbbfa1 100644 --- a/re2/testing/mimics_pcre_test.cc +++ b/re2/testing/mimics_pcre_test.cc @@ -65,8 +65,8 @@ TEST(MimicsPCRE, SimpleTests) { if (j == 0) flags = flags | Regexp::Latin1; Regexp* re = Regexp::Parse(t.regexp, flags, NULL); - CHECK(re) << " " << t.regexp; - CHECK_EQ(t.should_match, re->MimicsPCRE()) + ASSERT_TRUE(re != NULL) << " " << t.regexp; + ASSERT_EQ(t.should_match, re->MimicsPCRE()) << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); re->Decref(); diff --git a/re2/testing/parse_test.cc b/re2/testing/parse_test.cc index b039e13..d2b04fc 100644 --- a/re2/testing/parse_test.cc +++ b/re2/testing/parse_test.cc @@ -233,8 +233,8 @@ void TestParse(const Test* tests, int ntests, Regexp::ParseFlags flags, f = tests[i].flags & ~TestZeroFlags; } re[i] = Regexp::Parse(tests[i].regexp, f, &status); - CHECK(re[i] != NULL) << " " << tests[i].regexp << " " - << status.Text(); + ASSERT_TRUE(re[i] != NULL) + << " " << tests[i].regexp << " " << status.Text(); string s = re[i]->Dump(); EXPECT_EQ(string(tests[i].parse), s) << "Regexp: " << tests[i].regexp << "\nparse: " << string(tests[i].parse) << " s: " << s << " flag=" << f; @@ -422,23 +422,23 @@ const char* only_posix[] = { // Test that parser rejects bad regexps. TEST(TestParse, InvalidRegexps) { for (int i = 0; i < arraysize(badtests); i++) { - CHECK(Regexp::Parse(badtests[i], Regexp::PerlX, NULL) == NULL) + ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::PerlX, NULL) == NULL) << " " << badtests[i]; - CHECK(Regexp::Parse(badtests[i], Regexp::NoParseFlags, NULL) == NULL) + ASSERT_TRUE(Regexp::Parse(badtests[i], Regexp::NoParseFlags, NULL) == NULL) << " " << badtests[i]; } for (int i = 0; i < arraysize(only_posix); i++) { - CHECK(Regexp::Parse(only_posix[i], Regexp::PerlX, NULL) == NULL) + ASSERT_TRUE(Regexp::Parse(only_posix[i], Regexp::PerlX, NULL) == NULL) << " " << only_posix[i]; Regexp* re = Regexp::Parse(only_posix[i], Regexp::NoParseFlags, NULL); - CHECK(re) << " " << only_posix[i]; + ASSERT_TRUE(re != NULL) << " " << only_posix[i]; re->Decref(); } for (int i = 0; i < arraysize(only_perl); i++) { - CHECK(Regexp::Parse(only_perl[i], Regexp::NoParseFlags, NULL) == NULL) + ASSERT_TRUE(Regexp::Parse(only_perl[i], Regexp::NoParseFlags, NULL) == NULL) << " " << only_perl[i]; Regexp* re = Regexp::Parse(only_perl[i], Regexp::PerlX, NULL); - CHECK(re) << " " << only_perl[i]; + ASSERT_TRUE(re != NULL) << " " << only_perl[i]; re->Decref(); } } @@ -452,7 +452,7 @@ TEST(TestToString, EquivalentParse) { f = tests[i].flags & ~TestZeroFlags; } Regexp* re = Regexp::Parse(tests[i].regexp, f, &status); - CHECK(re != NULL) << " " << tests[i].regexp << " " << status.Text(); + ASSERT_TRUE(re != NULL) << " " << tests[i].regexp << " " << status.Text(); string s = re->Dump(); EXPECT_EQ(string(tests[i].parse), s) << " " << tests[i].regexp << " " << string(tests[i].parse) << " " << s; string t = re->ToString(); @@ -462,12 +462,12 @@ TEST(TestToString, EquivalentParse) { // Unfortunately we can't check the length here, because // ToString produces "\\{" for a literal brace, // but "{" is a shorter equivalent. - // CHECK_LT(t.size(), strlen(tests[i].regexp)) + // ASSERT_LT(t.size(), strlen(tests[i].regexp)) // << " t=" << t << " regexp=" << tests[i].regexp; // Test that if we parse the new regexp we get the same structure. Regexp* nre = Regexp::Parse(t, Regexp::MatchNL | Regexp::PerlX, &status); - CHECK(nre != NULL) << " reparse " << t << " " << status.Text(); + ASSERT_TRUE(nre != NULL) << " reparse " << t << " " << status.Text(); string ss = nre->Dump(); string tt = nre->ToString(); if (s != ss || t != tt) diff --git a/re2/testing/possible_match_test.cc b/re2/testing/possible_match_test.cc index ca8f5e1..f43a78b 100644 --- a/re2/testing/possible_match_test.cc +++ b/re2/testing/possible_match_test.cc @@ -114,15 +114,15 @@ TEST(PossibleMatchRange, HandWritten) { if (j == 0) { LOG(INFO) << "Checking regexp=" << CEscape(t.regexp); Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL); - CHECK(re); + ASSERT_TRUE(re != NULL); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->PossibleMatchRange(&min, &max, t.maxlen)) + ASSERT_TRUE(prog != NULL); + ASSERT_TRUE(prog->PossibleMatchRange(&min, &max, t.maxlen)) << " " << t.regexp; delete prog; re->Decref(); } else { - CHECK(RE2(t.regexp).PossibleMatchRange(&min, &max, t.maxlen)); + ASSERT_TRUE(RE2(t.regexp).PossibleMatchRange(&min, &max, t.maxlen)); } EXPECT_EQ(t.min, min) << t.regexp; EXPECT_EQ(t.max, max) << t.regexp; @@ -204,7 +204,7 @@ void PossibleMatchTester::HandleRegexp(const string& regexp) { VLOG(3) << CEscape(regexp); RE2 re(regexp, RE2::Latin1); - CHECK_EQ(re.error(), ""); + ASSERT_EQ(re.error(), ""); string min, max; if(!re.PossibleMatchRange(&min, &max, 10)) { @@ -222,8 +222,8 @@ void PossibleMatchTester::HandleRegexp(const string& regexp) { tests_++; if (!RE2::FullMatch(s, re)) continue; - CHECK_GE(s, min) << " regexp: " << regexp << " max: " << max; - CHECK_LE(s, max) << " regexp: " << regexp << " min: " << min; + ASSERT_GE(s, min) << " regexp: " << regexp << " max: " << max; + ASSERT_LE(s, max) << " regexp: " << regexp << " min: " << min; } } diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc index 7fdc836..b847325 100644 --- a/re2/testing/re2_test.cc +++ b/re2/testing/re2_test.cc @@ -26,81 +26,76 @@ namespace re2 { TEST(RE2, HexTests) { - - VLOG(1) << "hex tests"; - -#define CHECK_HEX(type, value) \ - do { \ - type v; \ - CHECK(RE2::FullMatch(#value, "([0-9a-fA-F]+)[uUlL]*", RE2::Hex(&v))); \ - CHECK_EQ(v, 0x ## value); \ - CHECK(RE2::FullMatch("0x" #value, "([0-9a-fA-FxX]+)[uUlL]*", RE2::CRadix(&v))); \ - CHECK_EQ(v, 0x ## value); \ - } while(0) - - CHECK_HEX(short, 2bad); - CHECK_HEX(unsigned short, 2badU); - CHECK_HEX(int, dead); - CHECK_HEX(unsigned int, deadU); - CHECK_HEX(long, 7eadbeefL); - CHECK_HEX(unsigned long, deadbeefUL); - CHECK_HEX(long long, 12345678deadbeefLL); - CHECK_HEX(unsigned long long, cafebabedeadbeefULL); - -#undef CHECK_HEX +#define ASSERT_HEX(type, value) \ + do { \ + type v; \ + ASSERT_TRUE( \ + RE2::FullMatch(#value, "([0-9a-fA-F]+)[uUlL]*", RE2::Hex(&v))); \ + ASSERT_EQ(v, 0x##value); \ + ASSERT_TRUE(RE2::FullMatch("0x" #value, "([0-9a-fA-FxX]+)[uUlL]*", \ + RE2::CRadix(&v))); \ + ASSERT_EQ(v, 0x##value); \ + } while (0) + + ASSERT_HEX(short, 2bad); + ASSERT_HEX(unsigned short, 2badU); + ASSERT_HEX(int, dead); + ASSERT_HEX(unsigned int, deadU); + ASSERT_HEX(long, 7eadbeefL); + ASSERT_HEX(unsigned long, deadbeefUL); + ASSERT_HEX(long long, 12345678deadbeefLL); + ASSERT_HEX(unsigned long long, cafebabedeadbeefULL); + +#undef ASSERT_HEX } TEST(RE2, OctalTests) { - VLOG(1) << "octal tests"; - -#define CHECK_OCTAL(type, value) \ - do { \ - type v; \ - CHECK(RE2::FullMatch(#value, "([0-7]+)[uUlL]*", RE2::Octal(&v))); \ - CHECK_EQ(v, 0 ## value); \ - CHECK(RE2::FullMatch("0" #value, "([0-9a-fA-FxX]+)[uUlL]*", RE2::CRadix(&v))); \ - CHECK_EQ(v, 0 ## value); \ - } while(0) - - CHECK_OCTAL(short, 77777); - CHECK_OCTAL(unsigned short, 177777U); - CHECK_OCTAL(int, 17777777777); - CHECK_OCTAL(unsigned int, 37777777777U); - CHECK_OCTAL(long, 17777777777L); - CHECK_OCTAL(unsigned long, 37777777777UL); - CHECK_OCTAL(long long, 777777777777777777777LL); - CHECK_OCTAL(unsigned long long, 1777777777777777777777ULL); - -#undef CHECK_OCTAL +#define ASSERT_OCTAL(type, value) \ + do { \ + type v; \ + ASSERT_TRUE(RE2::FullMatch(#value, "([0-7]+)[uUlL]*", RE2::Octal(&v))); \ + ASSERT_EQ(v, 0##value); \ + ASSERT_TRUE(RE2::FullMatch("0" #value, "([0-9a-fA-FxX]+)[uUlL]*", \ + RE2::CRadix(&v))); \ + ASSERT_EQ(v, 0##value); \ + } while (0) + + ASSERT_OCTAL(short, 77777); + ASSERT_OCTAL(unsigned short, 177777U); + ASSERT_OCTAL(int, 17777777777); + ASSERT_OCTAL(unsigned int, 37777777777U); + ASSERT_OCTAL(long, 17777777777L); + ASSERT_OCTAL(unsigned long, 37777777777UL); + ASSERT_OCTAL(long long, 777777777777777777777LL); + ASSERT_OCTAL(unsigned long long, 1777777777777777777777ULL); + +#undef ASSERT_OCTAL } TEST(RE2, DecimalTests) { - VLOG(1) << "decimal tests"; - -#define CHECK_DECIMAL(type, value) \ - do { \ - type v; \ - CHECK(RE2::FullMatch(#value, "(-?[0-9]+)[uUlL]*", &v)); \ - CHECK_EQ(v, value); \ - CHECK(RE2::FullMatch(#value, "(-?[0-9a-fA-FxX]+)[uUlL]*", RE2::CRadix(&v))); \ - CHECK_EQ(v, value); \ - } while(0) - - CHECK_DECIMAL(short, -1); - CHECK_DECIMAL(unsigned short, 9999); - CHECK_DECIMAL(int, -1000); - CHECK_DECIMAL(unsigned int, 12345U); - CHECK_DECIMAL(long, -10000000L); - CHECK_DECIMAL(unsigned long, 3083324652U); - CHECK_DECIMAL(long long, -100000000000000LL); - CHECK_DECIMAL(unsigned long long, 1234567890987654321ULL); - -#undef CHECK_DECIMAL +#define ASSERT_DECIMAL(type, value) \ + do { \ + type v; \ + ASSERT_TRUE(RE2::FullMatch(#value, "(-?[0-9]+)[uUlL]*", &v)); \ + ASSERT_EQ(v, value); \ + ASSERT_TRUE( \ + RE2::FullMatch(#value, "(-?[0-9a-fA-FxX]+)[uUlL]*", RE2::CRadix(&v))); \ + ASSERT_EQ(v, value); \ + } while (0) + + ASSERT_DECIMAL(short, -1); + ASSERT_DECIMAL(unsigned short, 9999); + ASSERT_DECIMAL(int, -1000); + ASSERT_DECIMAL(unsigned int, 12345U); + ASSERT_DECIMAL(long, -10000000L); + ASSERT_DECIMAL(unsigned long, 3083324652U); + ASSERT_DECIMAL(long long, -100000000000000LL); + ASSERT_DECIMAL(unsigned long long, 1234567890987654321ULL); + +#undef ASSERT_DECIMAL } TEST(RE2, Replace) { - VLOG(1) << "TestReplace"; - struct ReplaceTest { const char *regexp; const char *rewrite; @@ -181,14 +176,13 @@ TEST(RE2, Replace) { }; for (const ReplaceTest* t = tests; t->original != NULL; t++) { - VLOG(1) << StringPrintf("\"%s\" =~ s/%s/%s/g", t->original, t->regexp, t->rewrite); string one(t->original); - CHECK(RE2::Replace(&one, t->regexp, t->rewrite)); - CHECK_EQ(one, t->single); + ASSERT_TRUE(RE2::Replace(&one, t->regexp, t->rewrite)); + ASSERT_EQ(one, t->single); string all(t->original); - CHECK_EQ(RE2::GlobalReplace(&all, t->regexp, t->rewrite), t->greplace_count) + ASSERT_EQ(RE2::GlobalReplace(&all, t->regexp, t->rewrite), t->greplace_count) << "Got: " << all; - CHECK_EQ(all, t->global); + ASSERT_EQ(all, t->global); } } @@ -217,34 +211,30 @@ TEST(CheckRewriteString, all) { } TEST(RE2, Extract) { - VLOG(1) << "TestExtract"; - string s; - CHECK(RE2::Extract("boris@kremvax.ru", "(.*)@([^.]*)", "\\2!\\1", &s)); - CHECK_EQ(s, "kremvax!boris"); + ASSERT_TRUE(RE2::Extract("boris@kremvax.ru", "(.*)@([^.]*)", "\\2!\\1", &s)); + ASSERT_EQ(s, "kremvax!boris"); - CHECK(RE2::Extract("foo", ".*", "'\\0'", &s)); - CHECK_EQ(s, "'foo'"); + ASSERT_TRUE(RE2::Extract("foo", ".*", "'\\0'", &s)); + ASSERT_EQ(s, "'foo'"); // check that false match doesn't overwrite - CHECK(!RE2::Extract("baz", "bar", "'\\0'", &s)); - CHECK_EQ(s, "'foo'"); + ASSERT_FALSE(RE2::Extract("baz", "bar", "'\\0'", &s)); + ASSERT_EQ(s, "'foo'"); } TEST(RE2, Consume) { - VLOG(1) << "TestConsume"; - RE2 r("\\s*(\\w+)"); // matches a word, possibly proceeded by whitespace string word; string s(" aaa b!@#$@#$cccc"); StringPiece input(s); - CHECK(RE2::Consume(&input, r, &word)); - CHECK_EQ(word, "aaa") << " input: " << input; - CHECK(RE2::Consume(&input, r, &word)); - CHECK_EQ(word, "b") << " input: " << input; - CHECK(! RE2::Consume(&input, r, &word)) << " input: " << input; + ASSERT_TRUE(RE2::Consume(&input, r, &word)); + ASSERT_EQ(word, "aaa") << " input: " << input; + ASSERT_TRUE(RE2::Consume(&input, r, &word)); + ASSERT_EQ(word, "b") << " input: " << input; + ASSERT_FALSE(RE2::Consume(&input, r, &word)) << " input: " << input; } TEST(RE2, ConsumeN) { @@ -272,28 +262,26 @@ TEST(RE2, ConsumeN) { } TEST(RE2, FindAndConsume) { - VLOG(1) << "TestFindAndConsume"; - RE2 r("(\\w+)"); // matches a word string word; string s(" aaa b!@#$@#$cccc"); StringPiece input(s); - CHECK(RE2::FindAndConsume(&input, r, &word)); - CHECK_EQ(word, "aaa"); - CHECK(RE2::FindAndConsume(&input, r, &word)); - CHECK_EQ(word, "b"); - CHECK(RE2::FindAndConsume(&input, r, &word)); - CHECK_EQ(word, "cccc"); - CHECK(! RE2::FindAndConsume(&input, r, &word)); + ASSERT_TRUE(RE2::FindAndConsume(&input, r, &word)); + ASSERT_EQ(word, "aaa"); + ASSERT_TRUE(RE2::FindAndConsume(&input, r, &word)); + ASSERT_EQ(word, "b"); + ASSERT_TRUE(RE2::FindAndConsume(&input, r, &word)); + ASSERT_EQ(word, "cccc"); + ASSERT_FALSE(RE2::FindAndConsume(&input, r, &word)); // Check that FindAndConsume works without any submatches. // Earlier version used uninitialized data for // length to consume. input = "aaa"; - CHECK(RE2::FindAndConsume(&input, "aaa")); - CHECK_EQ(input, ""); + ASSERT_TRUE(RE2::FindAndConsume(&input, "aaa")); + ASSERT_EQ(input, ""); } TEST(RE2, FindAndConsumeN) { @@ -321,30 +309,28 @@ TEST(RE2, FindAndConsumeN) { } TEST(RE2, MatchNumberPeculiarity) { - VLOG(1) << "TestMatchNumberPeculiarity"; - RE2 r("(foo)|(bar)|(baz)"); string word1; string word2; string word3; - CHECK(RE2::PartialMatch("foo", r, &word1, &word2, &word3)); - CHECK_EQ(word1, "foo"); - CHECK_EQ(word2, ""); - CHECK_EQ(word3, ""); - CHECK(RE2::PartialMatch("bar", r, &word1, &word2, &word3)); - CHECK_EQ(word1, ""); - CHECK_EQ(word2, "bar"); - CHECK_EQ(word3, ""); - CHECK(RE2::PartialMatch("baz", r, &word1, &word2, &word3)); - CHECK_EQ(word1, ""); - CHECK_EQ(word2, ""); - CHECK_EQ(word3, "baz"); - CHECK(!RE2::PartialMatch("f", r, &word1, &word2, &word3)); + ASSERT_TRUE(RE2::PartialMatch("foo", r, &word1, &word2, &word3)); + ASSERT_EQ(word1, "foo"); + ASSERT_EQ(word2, ""); + ASSERT_EQ(word3, ""); + ASSERT_TRUE(RE2::PartialMatch("bar", r, &word1, &word2, &word3)); + ASSERT_EQ(word1, ""); + ASSERT_EQ(word2, "bar"); + ASSERT_EQ(word3, ""); + ASSERT_TRUE(RE2::PartialMatch("baz", r, &word1, &word2, &word3)); + ASSERT_EQ(word1, ""); + ASSERT_EQ(word2, ""); + ASSERT_EQ(word3, "baz"); + ASSERT_FALSE(RE2::PartialMatch("f", r, &word1, &word2, &word3)); string a; - CHECK(RE2::FullMatch("hello", "(foo)|hello", &a)); - CHECK_EQ(a, ""); + ASSERT_TRUE(RE2::FullMatch("hello", "(foo)|hello", &a)); + ASSERT_EQ(a, ""); } TEST(RE2, Match) { @@ -353,24 +339,24 @@ TEST(RE2, Match) { // No match. StringPiece s = "zyzzyva"; - CHECK(!re.Match(s, 0, s.size(), RE2::UNANCHORED, - group, arraysize(group))); + ASSERT_FALSE( + re.Match(s, 0, s.size(), RE2::UNANCHORED, group, arraysize(group))); // Matches and extracts. s = "a chrisr:9000 here"; - CHECK(re.Match(s, 0, s.size(), RE2::UNANCHORED, - group, arraysize(group))); - CHECK_EQ(group[0], "chrisr:9000"); - CHECK_EQ(group[1], "chrisr:9000"); - CHECK_EQ(group[2], "chrisr"); - CHECK_EQ(group[3], "9000"); + ASSERT_TRUE( + re.Match(s, 0, s.size(), RE2::UNANCHORED, group, arraysize(group))); + ASSERT_EQ(group[0], "chrisr:9000"); + ASSERT_EQ(group[1], "chrisr:9000"); + ASSERT_EQ(group[2], "chrisr"); + ASSERT_EQ(group[3], "9000"); string all, host; int port; - CHECK(RE2::PartialMatch("a chrisr:9000 here", re, &all, &host, &port)); - CHECK_EQ(all, "chrisr:9000"); - CHECK_EQ(host, "chrisr"); - CHECK_EQ(port, 9000); + ASSERT_TRUE(RE2::PartialMatch("a chrisr:9000 here", re, &all, &host, &port)); + ASSERT_EQ(all, "chrisr:9000"); + ASSERT_EQ(host, "chrisr"); + ASSERT_EQ(port, 9000); } static void TestRecursion(int size, const char* pattern) { @@ -472,9 +458,9 @@ TEST(ProgramSize, BigProgram) { RE2 re_medium("medium.*regexp"); RE2 re_complex("complex.{1,128}regexp"); - CHECK_GT(re_simple.ProgramSize(), 0); - CHECK_GT(re_medium.ProgramSize(), re_simple.ProgramSize()); - CHECK_GT(re_complex.ProgramSize(), re_medium.ProgramSize()); + ASSERT_GT(re_simple.ProgramSize(), 0); + ASSERT_GT(re_medium.ProgramSize(), re_simple.ProgramSize()); + ASSERT_GT(re_complex.ProgramSize(), re_medium.ProgramSize()); } TEST(ProgramFanout, BigProgram) { @@ -486,20 +472,20 @@ TEST(ProgramFanout, BigProgram) { std::map<int, int> histogram; // 3 is the largest non-empty bucket and has 1 element. - CHECK_EQ(3, re1.ProgramFanout(&histogram)); - CHECK_EQ(1, histogram[3]); + ASSERT_EQ(3, re1.ProgramFanout(&histogram)); + ASSERT_EQ(1, histogram[3]); // 7 is the largest non-empty bucket and has 10 elements. - CHECK_EQ(7, re10.ProgramFanout(&histogram)); - CHECK_EQ(10, histogram[7]); + ASSERT_EQ(7, re10.ProgramFanout(&histogram)); + ASSERT_EQ(10, histogram[7]); // 10 is the largest non-empty bucket and has 100 elements. - CHECK_EQ(10, re100.ProgramFanout(&histogram)); - CHECK_EQ(100, histogram[10]); + ASSERT_EQ(10, re100.ProgramFanout(&histogram)); + ASSERT_EQ(100, histogram[10]); // 13 is the largest non-empty bucket and has 1000 elements. - CHECK_EQ(13, re1000.ProgramFanout(&histogram)); - CHECK_EQ(1000, histogram[13]); + ASSERT_EQ(13, re1000.ProgramFanout(&histogram)); + ASSERT_EQ(1000, histogram[13]); } // Issue 956519: handling empty character sets was @@ -513,7 +499,7 @@ TEST(EmptyCharset, Fuzz) { "[^\\D[:digit:]]" }; for (int i = 0; i < arraysize(empties); i++) - CHECK(!RE2(empties[i]).Match("abc", 0, 3, RE2::UNANCHORED, NULL, 0)); + ASSERT_FALSE(RE2(empties[i]).Match("abc", 0, 3, RE2::UNANCHORED, NULL, 0)); } // Bitstate assumes that kInstFail instructions in @@ -528,27 +514,27 @@ TEST(EmptyCharset, BitstateAssumptions) { }; StringPiece group[6]; for (int i = 0; i < arraysize(nop_empties); i++) - CHECK(RE2(nop_empties[i]).Match("", 0, 0, RE2::UNANCHORED, group, 6)); + ASSERT_TRUE(RE2(nop_empties[i]).Match("", 0, 0, RE2::UNANCHORED, group, 6)); } // Test that named groups work correctly. TEST(Capture, NamedGroups) { { RE2 re("(hello world)"); - CHECK_EQ(re.NumberOfCapturingGroups(), 1); + ASSERT_EQ(re.NumberOfCapturingGroups(), 1); const std::map<string, int>& m = re.NamedCapturingGroups(); - CHECK_EQ(m.size(), 0); + ASSERT_EQ(m.size(), 0); } { RE2 re("(?P<A>expr(?P<B>expr)(?P<C>expr))((expr)(?P<D>expr))"); - CHECK_EQ(re.NumberOfCapturingGroups(), 6); + ASSERT_EQ(re.NumberOfCapturingGroups(), 6); const std::map<string, int>& m = re.NamedCapturingGroups(); - CHECK_EQ(m.size(), 4); - CHECK_EQ(m.find("A")->second, 1); - CHECK_EQ(m.find("B")->second, 2); - CHECK_EQ(m.find("C")->second, 3); - CHECK_EQ(m.find("D")->second, 6); // $4 and $5 are anonymous + ASSERT_EQ(m.size(), 4); + ASSERT_EQ(m.find("A")->second, 1); + ASSERT_EQ(m.find("B")->second, 2); + ASSERT_EQ(m.find("C")->second, 3); + ASSERT_EQ(m.find("D")->second, 6); // $4 and $5 are anonymous } } @@ -581,19 +567,19 @@ TEST(RE2, CapturedGroupTest) { } TEST(RE2, FullMatchWithNoArgs) { - CHECK(RE2::FullMatch("h", "h")); - CHECK(RE2::FullMatch("hello", "hello")); - CHECK(RE2::FullMatch("hello", "h.*o")); - CHECK(!RE2::FullMatch("othello", "h.*o")); // Must be anchored at front - CHECK(!RE2::FullMatch("hello!", "h.*o")); // Must be anchored at end + ASSERT_TRUE(RE2::FullMatch("h", "h")); + ASSERT_TRUE(RE2::FullMatch("hello", "hello")); + ASSERT_TRUE(RE2::FullMatch("hello", "h.*o")); + ASSERT_FALSE(RE2::FullMatch("othello", "h.*o")); // Must be anchored at front + ASSERT_FALSE(RE2::FullMatch("hello!", "h.*o")); // Must be anchored at end } TEST(RE2, PartialMatch) { - CHECK(RE2::PartialMatch("x", "x")); - CHECK(RE2::PartialMatch("hello", "h.*o")); - CHECK(RE2::PartialMatch("othello", "h.*o")); - CHECK(RE2::PartialMatch("hello!", "h.*o")); - CHECK(RE2::PartialMatch("x", "((((((((((((((((((((x))))))))))))))))))))")); + ASSERT_TRUE(RE2::PartialMatch("x", "x")); + ASSERT_TRUE(RE2::PartialMatch("hello", "h.*o")); + ASSERT_TRUE(RE2::PartialMatch("othello", "h.*o")); + ASSERT_TRUE(RE2::PartialMatch("hello!", "h.*o")); + ASSERT_TRUE(RE2::PartialMatch("x", "((((((((((((((((((((x))))))))))))))))))))")); } TEST(RE2, PartialMatchN) { @@ -622,62 +608,62 @@ TEST(RE2, PartialMatchN) { TEST(RE2, FullMatchZeroArg) { // Zero-arg - CHECK(RE2::FullMatch("1001", "\\d+")); + ASSERT_TRUE(RE2::FullMatch("1001", "\\d+")); } TEST(RE2, FullMatchOneArg) { int i; // Single-arg - CHECK(RE2::FullMatch("1001", "(\\d+)", &i)); - CHECK_EQ(i, 1001); - CHECK(RE2::FullMatch("-123", "(-?\\d+)", &i)); - CHECK_EQ(i, -123); - CHECK(!RE2::FullMatch("10", "()\\d+", &i)); - CHECK(!RE2::FullMatch("1234567890123456789012345678901234567890", - "(\\d+)", &i)); + ASSERT_TRUE(RE2::FullMatch("1001", "(\\d+)", &i)); + ASSERT_EQ(i, 1001); + ASSERT_TRUE(RE2::FullMatch("-123", "(-?\\d+)", &i)); + ASSERT_EQ(i, -123); + ASSERT_FALSE(RE2::FullMatch("10", "()\\d+", &i)); + ASSERT_FALSE( + RE2::FullMatch("1234567890123456789012345678901234567890", "(\\d+)", &i)); } TEST(RE2, FullMatchIntegerArg) { int i; // Digits surrounding integer-arg - CHECK(RE2::FullMatch("1234", "1(\\d*)4", &i)); - CHECK_EQ(i, 23); - CHECK(RE2::FullMatch("1234", "(\\d)\\d+", &i)); - CHECK_EQ(i, 1); - CHECK(RE2::FullMatch("-1234", "(-\\d)\\d+", &i)); - CHECK_EQ(i, -1); - CHECK(RE2::PartialMatch("1234", "(\\d)", &i)); - CHECK_EQ(i, 1); - CHECK(RE2::PartialMatch("-1234", "(-\\d)", &i)); - CHECK_EQ(i, -1); + ASSERT_TRUE(RE2::FullMatch("1234", "1(\\d*)4", &i)); + ASSERT_EQ(i, 23); + ASSERT_TRUE(RE2::FullMatch("1234", "(\\d)\\d+", &i)); + ASSERT_EQ(i, 1); + ASSERT_TRUE(RE2::FullMatch("-1234", "(-\\d)\\d+", &i)); + ASSERT_EQ(i, -1); + ASSERT_TRUE(RE2::PartialMatch("1234", "(\\d)", &i)); + ASSERT_EQ(i, 1); + ASSERT_TRUE(RE2::PartialMatch("-1234", "(-\\d)", &i)); + ASSERT_EQ(i, -1); } TEST(RE2, FullMatchStringArg) { string s; // String-arg - CHECK(RE2::FullMatch("hello", "h(.*)o", &s)); - CHECK_EQ(s, string("ell")); + ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", &s)); + ASSERT_EQ(s, string("ell")); } TEST(RE2, FullMatchStringPieceArg) { int i; // StringPiece-arg StringPiece sp; - CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &sp, &i)); - CHECK_EQ(sp.size(), 4); - CHECK(memcmp(sp.data(), "ruby", 4) == 0); - CHECK_EQ(i, 1234); + ASSERT_TRUE(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &sp, &i)); + ASSERT_EQ(sp.size(), 4); + ASSERT_TRUE(memcmp(sp.data(), "ruby", 4) == 0); + ASSERT_EQ(i, 1234); } TEST(RE2, FullMatchMultiArg) { int i; string s; // Multi-arg - CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); - CHECK_EQ(s, string("ruby")); - CHECK_EQ(i, 1234); + ASSERT_TRUE(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); + ASSERT_EQ(s, string("ruby")); + ASSERT_EQ(i, 1234); } TEST(RE2, FullMatchN) { @@ -709,34 +695,35 @@ TEST(RE2, FullMatchIgnoredArg) { string s; // Old-school NULL should be ignored. - CHECK(RE2::FullMatch("ruby:1234", "(\\w+)(:)(\\d+)", &s, (void*)NULL, &i)); - CHECK_EQ(s, string("ruby")); - CHECK_EQ(i, 1234); + ASSERT_TRUE( + RE2::FullMatch("ruby:1234", "(\\w+)(:)(\\d+)", &s, (void*)NULL, &i)); + ASSERT_EQ(s, string("ruby")); + ASSERT_EQ(i, 1234); // C++11 nullptr should also be ignored. - CHECK(RE2::FullMatch("rubz:1235", "(\\w+)(:)(\\d+)", &s, nullptr, &i)); - CHECK_EQ(s, string("rubz")); - CHECK_EQ(i, 1235); + ASSERT_TRUE(RE2::FullMatch("rubz:1235", "(\\w+)(:)(\\d+)", &s, nullptr, &i)); + ASSERT_EQ(s, string("rubz")); + ASSERT_EQ(i, 1235); } TEST(RE2, FullMatchTypedNullArg) { string s; // Ignore non-void* NULL arg - CHECK(RE2::FullMatch("hello", "he(.*)lo", (char*)NULL)); - CHECK(RE2::FullMatch("hello", "h(.*)o", (string*)NULL)); - CHECK(RE2::FullMatch("hello", "h(.*)o", (StringPiece*)NULL)); - CHECK(RE2::FullMatch("1234", "(.*)", (int*)NULL)); - CHECK(RE2::FullMatch("1234567890123456", "(.*)", (long long*)NULL)); - CHECK(RE2::FullMatch("123.4567890123456", "(.*)", (double*)NULL)); - CHECK(RE2::FullMatch("123.4567890123456", "(.*)", (float*)NULL)); + ASSERT_TRUE(RE2::FullMatch("hello", "he(.*)lo", (char*)NULL)); + ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", (string*)NULL)); + ASSERT_TRUE(RE2::FullMatch("hello", "h(.*)o", (StringPiece*)NULL)); + ASSERT_TRUE(RE2::FullMatch("1234", "(.*)", (int*)NULL)); + ASSERT_TRUE(RE2::FullMatch("1234567890123456", "(.*)", (long long*)NULL)); + ASSERT_TRUE(RE2::FullMatch("123.4567890123456", "(.*)", (double*)NULL)); + ASSERT_TRUE(RE2::FullMatch("123.4567890123456", "(.*)", (float*)NULL)); // Fail on non-void* NULL arg if the match doesn't parse for the given type. - CHECK(!RE2::FullMatch("hello", "h(.*)lo", &s, (char*)NULL)); - CHECK(!RE2::FullMatch("hello", "(.*)", (int*)NULL)); - CHECK(!RE2::FullMatch("1234567890123456", "(.*)", (int*)NULL)); - CHECK(!RE2::FullMatch("hello", "(.*)", (double*)NULL)); - CHECK(!RE2::FullMatch("hello", "(.*)", (float*)NULL)); + ASSERT_FALSE(RE2::FullMatch("hello", "h(.*)lo", &s, (char*)NULL)); + ASSERT_FALSE(RE2::FullMatch("hello", "(.*)", (int*)NULL)); + ASSERT_FALSE(RE2::FullMatch("1234567890123456", "(.*)", (int*)NULL)); + ASSERT_FALSE(RE2::FullMatch("hello", "(.*)", (double*)NULL)); + ASSERT_FALSE(RE2::FullMatch("hello", "(.*)", (float*)NULL)); } // Check that numeric parsing code does not read past the end of @@ -754,14 +741,14 @@ TEST(RE2, NULTerminated) { #endif v = static_cast<char*>(mmap(NULL, 2*pagesize, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)); - CHECK(v != reinterpret_cast<char*>(-1)); + ASSERT_TRUE(v != reinterpret_cast<char*>(-1)); LOG(INFO) << "Memory at " << (void*)v; - CHECK_EQ(munmap(v + pagesize, pagesize), 0) << " error " << errno; + ASSERT_EQ(munmap(v + pagesize, pagesize), 0) << " error " << errno; v[pagesize - 1] = '1'; x = 0; - CHECK(RE2::FullMatch(StringPiece(v + pagesize - 1, 1), "(.*)", &x)); - CHECK_EQ(x, 1); + ASSERT_TRUE(RE2::FullMatch(StringPiece(v + pagesize - 1, 1), "(.*)", &x)); + ASSERT_EQ(x, 1); #endif } @@ -770,60 +757,60 @@ TEST(RE2, FullMatchTypeTests) { string zeros(1000, '0'); { char c; - CHECK(RE2::FullMatch("Hello", "(H)ello", &c)); - CHECK_EQ(c, 'H'); + ASSERT_TRUE(RE2::FullMatch("Hello", "(H)ello", &c)); + ASSERT_EQ(c, 'H'); } { unsigned char c; - CHECK(RE2::FullMatch("Hello", "(H)ello", &c)); - CHECK_EQ(c, static_cast<unsigned char>('H')); + ASSERT_TRUE(RE2::FullMatch("Hello", "(H)ello", &c)); + ASSERT_EQ(c, static_cast<unsigned char>('H')); } { int16_t v; - CHECK(RE2::FullMatch("100", "(-?\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100", "(-?\\d+)", &v)); CHECK_EQ(v, -100); - CHECK(RE2::FullMatch("32767", "(-?\\d+)", &v)); CHECK_EQ(v, 32767); - CHECK(RE2::FullMatch("-32768", "(-?\\d+)", &v)); CHECK_EQ(v, -32768); - CHECK(!RE2::FullMatch("-32769", "(-?\\d+)", &v)); - CHECK(!RE2::FullMatch("32768", "(-?\\d+)", &v)); + ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100", "(-?\\d+)", &v)); ASSERT_EQ(v, -100); + ASSERT_TRUE(RE2::FullMatch("32767", "(-?\\d+)", &v)); ASSERT_EQ(v, 32767); + ASSERT_TRUE(RE2::FullMatch("-32768", "(-?\\d+)", &v)); ASSERT_EQ(v, -32768); + ASSERT_FALSE(RE2::FullMatch("-32769", "(-?\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch("32768", "(-?\\d+)", &v)); } { uint16_t v; - CHECK(RE2::FullMatch("100", "(\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("32767", "(\\d+)", &v)); CHECK_EQ(v, 32767); - CHECK(RE2::FullMatch("65535", "(\\d+)", &v)); CHECK_EQ(v, 65535); - CHECK(!RE2::FullMatch("65536", "(\\d+)", &v)); + ASSERT_TRUE(RE2::FullMatch("100", "(\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("32767", "(\\d+)", &v)); ASSERT_EQ(v, 32767); + ASSERT_TRUE(RE2::FullMatch("65535", "(\\d+)", &v)); ASSERT_EQ(v, 65535); + ASSERT_FALSE(RE2::FullMatch("65536", "(\\d+)", &v)); } { int32_t v; static const int32_t max = INT32_C(0x7fffffff); static const int32_t min = -max - 1; - CHECK(RE2::FullMatch("100", "(-?\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100", "(-?\\d+)", &v)); CHECK_EQ(v, -100); - CHECK(RE2::FullMatch("2147483647", "(-?\\d+)", &v)); CHECK_EQ(v, max); - CHECK(RE2::FullMatch("-2147483648", "(-?\\d+)", &v)); CHECK_EQ(v, min); - CHECK(!RE2::FullMatch("-2147483649", "(-?\\d+)", &v)); - CHECK(!RE2::FullMatch("2147483648", "(-?\\d+)", &v)); - - CHECK(RE2::FullMatch(zeros + "2147483647", "(-?\\d+)", &v)); - CHECK_EQ(v, max); - CHECK(RE2::FullMatch("-" + zeros + "2147483648", "(-?\\d+)", &v)); - CHECK_EQ(v, min); - - CHECK(!RE2::FullMatch("-" + zeros + "2147483649", "(-?\\d+)", &v)); - CHECK(RE2::FullMatch("0x7fffffff", "(.*)", RE2::CRadix(&v))); - CHECK_EQ(v, max); - CHECK(!RE2::FullMatch("000x7fffffff", "(.*)", RE2::CRadix(&v))); + ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100", "(-?\\d+)", &v)); ASSERT_EQ(v, -100); + ASSERT_TRUE(RE2::FullMatch("2147483647", "(-?\\d+)", &v)); ASSERT_EQ(v, max); + ASSERT_TRUE(RE2::FullMatch("-2147483648", "(-?\\d+)", &v)); ASSERT_EQ(v, min); + ASSERT_FALSE(RE2::FullMatch("-2147483649", "(-?\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch("2147483648", "(-?\\d+)", &v)); + + ASSERT_TRUE(RE2::FullMatch(zeros + "2147483647", "(-?\\d+)", &v)); + ASSERT_EQ(v, max); + ASSERT_TRUE(RE2::FullMatch("-" + zeros + "2147483648", "(-?\\d+)", &v)); + ASSERT_EQ(v, min); + + ASSERT_FALSE(RE2::FullMatch("-" + zeros + "2147483649", "(-?\\d+)", &v)); + ASSERT_TRUE(RE2::FullMatch("0x7fffffff", "(.*)", RE2::CRadix(&v))); + ASSERT_EQ(v, max); + ASSERT_FALSE(RE2::FullMatch("000x7fffffff", "(.*)", RE2::CRadix(&v))); } { uint32_t v; static const uint32_t max = UINT32_C(0xffffffff); - CHECK(RE2::FullMatch("100", "(\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("4294967295", "(\\d+)", &v)); CHECK_EQ(v, max); - CHECK(!RE2::FullMatch("4294967296", "(\\d+)", &v)); - CHECK(!RE2::FullMatch("-1", "(\\d+)", &v)); + ASSERT_TRUE(RE2::FullMatch("100", "(\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("4294967295", "(\\d+)", &v)); ASSERT_EQ(v, max); + ASSERT_FALSE(RE2::FullMatch("4294967296", "(\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch("-1", "(\\d+)", &v)); - CHECK(RE2::FullMatch(zeros + "4294967295", "(\\d+)", &v)); CHECK_EQ(v, max); + ASSERT_TRUE(RE2::FullMatch(zeros + "4294967295", "(\\d+)", &v)); ASSERT_EQ(v, max); } { int64_t v; @@ -831,24 +818,24 @@ TEST(RE2, FullMatchTypeTests) { static const int64_t min = -max - 1; string str; - CHECK(RE2::FullMatch("100", "(-?\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100", "(-?\\d+)", &v)); CHECK_EQ(v, -100); + ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100", "(-?\\d+)", &v)); ASSERT_EQ(v, -100); str = std::to_string(max); - CHECK(RE2::FullMatch(str, "(-?\\d+)", &v)); CHECK_EQ(v, max); + ASSERT_TRUE(RE2::FullMatch(str, "(-?\\d+)", &v)); ASSERT_EQ(v, max); str = std::to_string(min); - CHECK(RE2::FullMatch(str, "(-?\\d+)", &v)); CHECK_EQ(v, min); + ASSERT_TRUE(RE2::FullMatch(str, "(-?\\d+)", &v)); ASSERT_EQ(v, min); str = std::to_string(max); - CHECK_NE(str.back(), '9'); + ASSERT_NE(str.back(), '9'); str.back()++; - CHECK(!RE2::FullMatch(str, "(-?\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch(str, "(-?\\d+)", &v)); str = std::to_string(min); - CHECK_NE(str.back(), '9'); + ASSERT_NE(str.back(), '9'); str.back()++; - CHECK(!RE2::FullMatch(str, "(-?\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch(str, "(-?\\d+)", &v)); } { uint64_t v; @@ -856,15 +843,15 @@ TEST(RE2, FullMatchTypeTests) { static const uint64_t max = UINT64_C(0xffffffffffffffff); string str; - CHECK(RE2::FullMatch("100", "(-?\\d+)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100", "(-?\\d+)", &v2)); CHECK_EQ(v2, -100); + ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100", "(-?\\d+)", &v2)); ASSERT_EQ(v2, -100); str = std::to_string(max); - CHECK(RE2::FullMatch(str, "(-?\\d+)", &v)); CHECK_EQ(v, max); + ASSERT_TRUE(RE2::FullMatch(str, "(-?\\d+)", &v)); ASSERT_EQ(v, max); - CHECK_NE(str.back(), '9'); + ASSERT_NE(str.back(), '9'); str.back()++; - CHECK(!RE2::FullMatch(str, "(-?\\d+)", &v)); + ASSERT_FALSE(RE2::FullMatch(str, "(-?\\d+)", &v)); } } @@ -872,13 +859,13 @@ TEST(RE2, FloatingPointFullMatchTypes) { string zeros(1000, '0'); { float v; - CHECK(RE2::FullMatch("100", "(.*)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100.", "(.*)", &v)); CHECK_EQ(v, -100); - CHECK(RE2::FullMatch("1e23", "(.*)", &v)); CHECK_EQ(v, float(1e23)); - CHECK(RE2::FullMatch(" 100", "(.*)", &v)); CHECK_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("100", "(.*)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100.", "(.*)", &v)); ASSERT_EQ(v, -100); + ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, float(1e23)); + ASSERT_TRUE(RE2::FullMatch(" 100", "(.*)", &v)); ASSERT_EQ(v, 100); - CHECK(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); - CHECK_EQ(v, float(1e23)); + ASSERT_TRUE(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); + ASSERT_EQ(v, float(1e23)); // 6700000000081920.1 is an edge case. // 6700000000081920 is exactly halfway between @@ -896,25 +883,25 @@ TEST(RE2, FloatingPointFullMatchTypes) { // This is known to fail on Cygwin and MinGW due to a broken // implementation of strtof(3). And apparently MSVC too. Sigh. #if !defined(_MSC_VER) && !defined(__CYGWIN__) && !defined(__MINGW32__) - CHECK(RE2::FullMatch("0.1", "(.*)", &v)); - CHECK_EQ(v, 0.1f) << StringPrintf("%.8g != %.8g", v, 0.1f); - CHECK(RE2::FullMatch("6700000000081920.1", "(.*)", &v)); - CHECK_EQ(v, 6700000000081920.1f) + ASSERT_TRUE(RE2::FullMatch("0.1", "(.*)", &v)); + ASSERT_EQ(v, 0.1f) << StringPrintf("%.8g != %.8g", v, 0.1f); + ASSERT_TRUE(RE2::FullMatch("6700000000081920.1", "(.*)", &v)); + ASSERT_EQ(v, 6700000000081920.1f) << StringPrintf("%.8g != %.8g", v, 6700000000081920.1f); #endif } { double v; - CHECK(RE2::FullMatch("100", "(.*)", &v)); CHECK_EQ(v, 100); - CHECK(RE2::FullMatch("-100.", "(.*)", &v)); CHECK_EQ(v, -100); - CHECK(RE2::FullMatch("1e23", "(.*)", &v)); CHECK_EQ(v, 1e23); - CHECK(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); - CHECK_EQ(v, double(1e23)); - - CHECK(RE2::FullMatch("0.1", "(.*)", &v)); - CHECK_EQ(v, 0.1) << StringPrintf("%.17g != %.17g", v, 0.1); - CHECK(RE2::FullMatch("1.00000005960464485", "(.*)", &v)); - CHECK_EQ(v, 1.0000000596046448) + ASSERT_TRUE(RE2::FullMatch("100", "(.*)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("-100.", "(.*)", &v)); ASSERT_EQ(v, -100); + ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, 1e23); + ASSERT_TRUE(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); + ASSERT_EQ(v, double(1e23)); + + ASSERT_TRUE(RE2::FullMatch("0.1", "(.*)", &v)); + ASSERT_EQ(v, 0.1) << StringPrintf("%.17g != %.17g", v, 0.1); + ASSERT_TRUE(RE2::FullMatch("1.00000005960464485", "(.*)", &v)); + ASSERT_EQ(v, 1.0000000596046448) << StringPrintf("%.17g != %.17g", v, 1.0000000596046448); } } @@ -922,141 +909,127 @@ TEST(RE2, FloatingPointFullMatchTypes) { TEST(RE2, FullMatchAnchored) { int i; // Check that matching is fully anchored - CHECK(!RE2::FullMatch("x1001", "(\\d+)", &i)); - CHECK(!RE2::FullMatch("1001x", "(\\d+)", &i)); - CHECK(RE2::FullMatch("x1001", "x(\\d+)", &i)); CHECK_EQ(i, 1001); - CHECK(RE2::FullMatch("1001x", "(\\d+)x", &i)); CHECK_EQ(i, 1001); + ASSERT_FALSE(RE2::FullMatch("x1001", "(\\d+)", &i)); + ASSERT_FALSE(RE2::FullMatch("1001x", "(\\d+)", &i)); + ASSERT_TRUE(RE2::FullMatch("x1001", "x(\\d+)", &i)); ASSERT_EQ(i, 1001); + ASSERT_TRUE(RE2::FullMatch("1001x", "(\\d+)x", &i)); ASSERT_EQ(i, 1001); } TEST(RE2, FullMatchBraces) { // Braces - CHECK(RE2::FullMatch("0abcd", "[0-9a-f+.-]{5,}")); - CHECK(RE2::FullMatch("0abcde", "[0-9a-f+.-]{5,}")); - CHECK(!RE2::FullMatch("0abc", "[0-9a-f+.-]{5,}")); + ASSERT_TRUE(RE2::FullMatch("0abcd", "[0-9a-f+.-]{5,}")); + ASSERT_TRUE(RE2::FullMatch("0abcde", "[0-9a-f+.-]{5,}")); + ASSERT_FALSE(RE2::FullMatch("0abc", "[0-9a-f+.-]{5,}")); } TEST(RE2, Complicated) { // Complicated RE2 - CHECK(RE2::FullMatch("foo", "foo|bar|[A-Z]")); - CHECK(RE2::FullMatch("bar", "foo|bar|[A-Z]")); - CHECK(RE2::FullMatch("X", "foo|bar|[A-Z]")); - CHECK(!RE2::FullMatch("XY", "foo|bar|[A-Z]")); + ASSERT_TRUE(RE2::FullMatch("foo", "foo|bar|[A-Z]")); + ASSERT_TRUE(RE2::FullMatch("bar", "foo|bar|[A-Z]")); + ASSERT_TRUE(RE2::FullMatch("X", "foo|bar|[A-Z]")); + ASSERT_FALSE(RE2::FullMatch("XY", "foo|bar|[A-Z]")); } TEST(RE2, FullMatchEnd) { // Check full-match handling (needs '$' tacked on internally) - CHECK(RE2::FullMatch("fo", "fo|foo")); - CHECK(RE2::FullMatch("foo", "fo|foo")); - CHECK(RE2::FullMatch("fo", "fo|foo$")); - CHECK(RE2::FullMatch("foo", "fo|foo$")); - CHECK(RE2::FullMatch("foo", "foo$")); - CHECK(!RE2::FullMatch("foo$bar", "foo\\$")); - CHECK(!RE2::FullMatch("fox", "fo|bar")); + ASSERT_TRUE(RE2::FullMatch("fo", "fo|foo")); + ASSERT_TRUE(RE2::FullMatch("foo", "fo|foo")); + ASSERT_TRUE(RE2::FullMatch("fo", "fo|foo$")); + ASSERT_TRUE(RE2::FullMatch("foo", "fo|foo$")); + ASSERT_TRUE(RE2::FullMatch("foo", "foo$")); + ASSERT_FALSE(RE2::FullMatch("foo$bar", "foo\\$")); + ASSERT_FALSE(RE2::FullMatch("fox", "fo|bar")); // Uncomment the following if we change the handling of '$' to // prevent it from matching a trailing newline if (false) { // Check that we don't get bitten by pcre's special handling of a // '\n' at the end of the string matching '$' - CHECK(!RE2::PartialMatch("foo\n", "foo$")); + ASSERT_FALSE(RE2::PartialMatch("foo\n", "foo$")); } } TEST(RE2, FullMatchArgCount) { // Number of args int a[16]; - CHECK(RE2::FullMatch("", "")); + ASSERT_TRUE(RE2::FullMatch("", "")); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("1", - "(\\d){1}", - &a[0])); - CHECK_EQ(a[0], 1); + ASSERT_TRUE(RE2::FullMatch("1", "(\\d){1}", &a[0])); + ASSERT_EQ(a[0], 1); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("12", - "(\\d)(\\d)", - &a[0], &a[1])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); + ASSERT_TRUE(RE2::FullMatch("12", "(\\d)(\\d)", &a[0], &a[1])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("123", - "(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); + ASSERT_TRUE(RE2::FullMatch("123", "(\\d)(\\d)(\\d)", &a[0], &a[1], &a[2])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("1234", - "(\\d)(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2], &a[3])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); - CHECK_EQ(a[3], 4); + ASSERT_TRUE(RE2::FullMatch("1234", "(\\d)(\\d)(\\d)(\\d)", &a[0], &a[1], + &a[2], &a[3])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); + ASSERT_EQ(a[3], 4); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("12345", - "(\\d)(\\d)(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2], &a[3], - &a[4])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); - CHECK_EQ(a[3], 4); - CHECK_EQ(a[4], 5); + ASSERT_TRUE(RE2::FullMatch("12345", "(\\d)(\\d)(\\d)(\\d)(\\d)", &a[0], &a[1], + &a[2], &a[3], &a[4])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); + ASSERT_EQ(a[3], 4); + ASSERT_EQ(a[4], 5); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("123456", - "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); - CHECK_EQ(a[3], 4); - CHECK_EQ(a[4], 5); - CHECK_EQ(a[5], 6); + ASSERT_TRUE(RE2::FullMatch("123456", "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", &a[0], + &a[1], &a[2], &a[3], &a[4], &a[5])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); + ASSERT_EQ(a[3], 4); + ASSERT_EQ(a[4], 5); + ASSERT_EQ(a[5], 6); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("1234567", - "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5], &a[6])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); - CHECK_EQ(a[3], 4); - CHECK_EQ(a[4], 5); - CHECK_EQ(a[5], 6); - CHECK_EQ(a[6], 7); + ASSERT_TRUE(RE2::FullMatch("1234567", "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", + &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); + ASSERT_EQ(a[3], 4); + ASSERT_EQ(a[4], 5); + ASSERT_EQ(a[5], 6); + ASSERT_EQ(a[6], 7); memset(a, 0, sizeof(0)); - CHECK(RE2::FullMatch("1234567890123456", - "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)" - "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", - &a[0], &a[1], &a[2], &a[3], - &a[4], &a[5], &a[6], &a[7], - &a[8], &a[9], &a[10], &a[11], - &a[12], &a[13], &a[14], &a[15])); - CHECK_EQ(a[0], 1); - CHECK_EQ(a[1], 2); - CHECK_EQ(a[2], 3); - CHECK_EQ(a[3], 4); - CHECK_EQ(a[4], 5); - CHECK_EQ(a[5], 6); - CHECK_EQ(a[6], 7); - CHECK_EQ(a[7], 8); - CHECK_EQ(a[8], 9); - CHECK_EQ(a[9], 0); - CHECK_EQ(a[10], 1); - CHECK_EQ(a[11], 2); - CHECK_EQ(a[12], 3); - CHECK_EQ(a[13], 4); - CHECK_EQ(a[14], 5); - CHECK_EQ(a[15], 6); + ASSERT_TRUE(RE2::FullMatch("1234567890123456", + "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)" + "(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)", + &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], + &a[7], &a[8], &a[9], &a[10], &a[11], &a[12], + &a[13], &a[14], &a[15])); + ASSERT_EQ(a[0], 1); + ASSERT_EQ(a[1], 2); + ASSERT_EQ(a[2], 3); + ASSERT_EQ(a[3], 4); + ASSERT_EQ(a[4], 5); + ASSERT_EQ(a[5], 6); + ASSERT_EQ(a[6], 7); + ASSERT_EQ(a[7], 8); + ASSERT_EQ(a[8], 9); + ASSERT_EQ(a[9], 0); + ASSERT_EQ(a[10], 1); + ASSERT_EQ(a[11], 2); + ASSERT_EQ(a[12], 3); + ASSERT_EQ(a[13], 4); + ASSERT_EQ(a[14], 5); + ASSERT_EQ(a[15], 6); } TEST(RE2, Accessors) { @@ -1064,15 +1037,15 @@ TEST(RE2, Accessors) { { const string kPattern = "http://([^/]+)/.*"; const RE2 re(kPattern); - CHECK_EQ(kPattern, re.pattern()); + ASSERT_EQ(kPattern, re.pattern()); } // Check RE2 error field. { RE2 re("foo"); - CHECK(re.error().empty()); // Must have no error - CHECK(re.ok()); - CHECK(re.error_code() == RE2::NoError); + ASSERT_TRUE(re.error().empty()); // Must have no error + ASSERT_TRUE(re.ok()); + ASSERT_EQ(re.error_code(), RE2::NoError); } } @@ -1094,31 +1067,31 @@ TEST(RE2, UTF8) { // Both should match in either mode, bytes or UTF-8 RE2 re_test1(".........", RE2::Latin1); - CHECK(RE2::FullMatch(utf8_string, re_test1)); + ASSERT_TRUE(RE2::FullMatch(utf8_string, re_test1)); RE2 re_test2("..."); - CHECK(RE2::FullMatch(utf8_string, re_test2)); + ASSERT_TRUE(RE2::FullMatch(utf8_string, re_test2)); // Check that '.' matches one byte or UTF-8 character // according to the mode. string s; RE2 re_test3("(.)", RE2::Latin1); - CHECK(RE2::PartialMatch(utf8_string, re_test3, &s)); - CHECK_EQ(s, string("\xe6")); + ASSERT_TRUE(RE2::PartialMatch(utf8_string, re_test3, &s)); + ASSERT_EQ(s, string("\xe6")); RE2 re_test4("(.)"); - CHECK(RE2::PartialMatch(utf8_string, re_test4, &s)); - CHECK_EQ(s, string("\xe6\x97\xa5")); + ASSERT_TRUE(RE2::PartialMatch(utf8_string, re_test4, &s)); + ASSERT_EQ(s, string("\xe6\x97\xa5")); // Check that string matches itself in either mode RE2 re_test5(utf8_string, RE2::Latin1); - CHECK(RE2::FullMatch(utf8_string, re_test5)); + ASSERT_TRUE(RE2::FullMatch(utf8_string, re_test5)); RE2 re_test6(utf8_string); - CHECK(RE2::FullMatch(utf8_string, re_test6)); + ASSERT_TRUE(RE2::FullMatch(utf8_string, re_test6)); // Check that pattern matches string only in UTF8 mode RE2 re_test7(utf8_pattern, RE2::Latin1); - CHECK(!RE2::FullMatch(utf8_string, re_test7)); + ASSERT_FALSE(RE2::FullMatch(utf8_string, re_test7)); RE2 re_test8(utf8_pattern); - CHECK(RE2::FullMatch(utf8_string, re_test8)); + ASSERT_TRUE(RE2::FullMatch(utf8_string, re_test8)); } TEST(RE2, UngreedyUTF8) { @@ -1131,42 +1104,44 @@ TEST(RE2, UngreedyUTF8) { RE2 match_sentence(pattern, RE2::Latin1); RE2 match_sentence_re(pattern); - CHECK(!RE2::FullMatch(target, match_sentence)); - CHECK(!RE2::FullMatch(target, match_sentence_re)); + ASSERT_FALSE(RE2::FullMatch(target, match_sentence)); + ASSERT_FALSE(RE2::FullMatch(target, match_sentence_re)); } { const char* pattern = "(?U)\\w+X"; const string target = "a aX"; RE2 match_sentence(pattern, RE2::Latin1); - CHECK_EQ(match_sentence.error(), ""); + ASSERT_EQ(match_sentence.error(), ""); RE2 match_sentence_re(pattern); - CHECK(!RE2::FullMatch(target, match_sentence)); - CHECK(!RE2::FullMatch(target, match_sentence_re)); + ASSERT_FALSE(RE2::FullMatch(target, match_sentence)); + ASSERT_FALSE(RE2::FullMatch(target, match_sentence_re)); } } TEST(RE2, Rejects) { - { RE2 re("a\\1", RE2::Quiet); CHECK(!re.ok()); } + { + RE2 re("a\\1", RE2::Quiet); + ASSERT_FALSE(re.ok()); } { RE2 re("a[x", RE2::Quiet); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } { RE2 re("a[z-a]", RE2::Quiet); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } { RE2 re("a[[:foobar:]]", RE2::Quiet); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } { RE2 re("a(b", RE2::Quiet); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } { RE2 re("a\\", RE2::Quiet); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } } @@ -1174,25 +1149,25 @@ TEST(RE2, NoCrash) { // Test that using a bad regexp doesn't crash. { RE2 re("a\\", RE2::Quiet); - CHECK(!re.ok()); - CHECK(!RE2::PartialMatch("a\\b", re)); + ASSERT_FALSE(re.ok()); + ASSERT_FALSE(RE2::PartialMatch("a\\b", re)); } // Test that using an enormous regexp doesn't crash { RE2 re("(((.{100}){100}){100}){100}", RE2::Quiet); - CHECK(!re.ok()); - CHECK(!RE2::PartialMatch("aaa", re)); + ASSERT_FALSE(re.ok()); + ASSERT_FALSE(RE2::PartialMatch("aaa", re)); } // Test that a crazy regexp still compiles and runs. { RE2 re(".{512}x", RE2::Quiet); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); string s; s.append(515, 'c'); s.append("x"); - CHECK(RE2::PartialMatch(s, re)); + ASSERT_TRUE(RE2::PartialMatch(s, re)); } } @@ -1213,11 +1188,11 @@ TEST(RE2, BigCountedRepetition) { opt.set_max_mem(256<<20); RE2 re(".{512}x", opt); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); string s; s.append(515, 'c'); s.append("x"); - CHECK(RE2::PartialMatch(s, re)); + ASSERT_TRUE(RE2::PartialMatch(s, re)); } TEST(RE2, DeepRecursion) { @@ -1230,7 +1205,7 @@ TEST(RE2, DeepRecursion) { comment += a; comment += "*x"; RE2 re("((?:\\s|xx.*\n|x[*](?:\n|.)*?[*]x)*)"); - CHECK(RE2::FullMatch(comment, re)); + ASSERT_TRUE(RE2::FullMatch(comment, re)); } // Suggested by Josh Hyman. Failed when SearchOnePass was @@ -1550,7 +1525,7 @@ TEST(RE2, Bug18391750) { opt.set_dot_nl(true); opt.set_case_sensitive(false); RE2 re(t, opt); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); RE2::PartialMatch(t, re); } @@ -1564,7 +1539,7 @@ TEST(RE2, Bug18458852) { (char)0x90, (char)0x29, (char)0x5d, (char)0x29, (char)0x29, (char)0x00, }; RE2 re(b); - CHECK(!re.ok()); + ASSERT_FALSE(re.ok()); } TEST(RE2, Bug18523943) { @@ -1585,9 +1560,9 @@ TEST(RE2, Bug18523943) { opt.set_never_nl(true); RE2 re((const char*)b, opt); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); string s1; - CHECK(RE2::PartialMatch((const char*)a, re, &s1)); + ASSERT_TRUE(RE2::PartialMatch((const char*)a, re, &s1)); } TEST(RE2, Bug21371806) { @@ -1598,7 +1573,7 @@ TEST(RE2, Bug21371806) { opt.set_encoding(RE2::Options::EncodingLatin1); RE2 re("g\\p{Zl}]", opt); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); } TEST(RE2, Bug26356109) { @@ -1608,16 +1583,16 @@ TEST(RE2, Bug26356109) { // consume "ab" and then stop (when unanchored) whereas it should consume all // of "abc" as per first-match semantics. RE2 re("a\\C*?c|a\\C*?b"); - CHECK(re.ok()); + ASSERT_TRUE(re.ok()); string s = "abc"; StringPiece m; - CHECK(re.Match(s, 0, s.size(), RE2::UNANCHORED, &m, 1)); - CHECK_EQ(m, s) << " (UNANCHORED) got m='" << m << "', want '" << s << "'"; + ASSERT_TRUE(re.Match(s, 0, s.size(), RE2::UNANCHORED, &m, 1)); + ASSERT_EQ(m, s) << " (UNANCHORED) got m='" << m << "', want '" << s << "'"; - CHECK(re.Match(s, 0, s.size(), RE2::ANCHOR_BOTH, &m, 1)); - CHECK_EQ(m, s) << " (ANCHOR_BOTH) got m='" << m << "', want '" << s << "'"; + ASSERT_TRUE(re.Match(s, 0, s.size(), RE2::ANCHOR_BOTH, &m, 1)); + ASSERT_EQ(m, s) << " (ANCHOR_BOTH) got m='" << m << "', want '" << s << "'"; } TEST(RE2, Issue104) { @@ -1625,16 +1600,16 @@ TEST(RE2, Issue104) { // matched, which would clobber any rune that is longer than one byte. string s = "bc"; - CHECK_EQ(3, RE2::GlobalReplace(&s, "a*", "d")); - CHECK_EQ("dbdcd", s); + ASSERT_EQ(3, RE2::GlobalReplace(&s, "a*", "d")); + ASSERT_EQ("dbdcd", s); s = "ąć"; - CHECK_EQ(3, RE2::GlobalReplace(&s, "Ć*", "Ĉ")); - CHECK_EQ("ĈąĈćĈ", s); + ASSERT_EQ(3, RE2::GlobalReplace(&s, "Ć*", "Ĉ")); + ASSERT_EQ("ĈąĈćĈ", s); s = "人类"; - CHECK_EQ(3, RE2::GlobalReplace(&s, "大*", "小")); - CHECK_EQ("小人小类小", s); + ASSERT_EQ(3, RE2::GlobalReplace(&s, "大*", "小")); + ASSERT_EQ("小人小类小", s); } } // namespace re2 diff --git a/re2/testing/regexp_test.cc b/re2/testing/regexp_test.cc index e612eae..7830322 100644 --- a/re2/testing/regexp_test.cc +++ b/re2/testing/regexp_test.cc @@ -23,7 +23,7 @@ TEST(Regexp, BigRef) { re->Incref(); for (int i = 0; i < 100000; i++) re->Decref(); - CHECK_EQ(re->Ref(), 1); + ASSERT_EQ(re->Ref(), 1); re->Decref(); } @@ -35,12 +35,12 @@ TEST(Regexp, BigConcat) { std::vector<Regexp*> v(90000, x); // ToString bails out at 100000 for (size_t i = 0; i < v.size(); i++) x->Incref(); - CHECK_EQ(x->Ref(), 1 + static_cast<int>(v.size())) << x->Ref(); + ASSERT_EQ(x->Ref(), 1 + static_cast<int>(v.size())) << x->Ref(); Regexp* re = Regexp::Concat(v.data(), static_cast<int>(v.size()), Regexp::NoParseFlags); - CHECK_EQ(re->ToString(), string(v.size(), 'x')); + ASSERT_EQ(re->ToString(), string(v.size(), 'x')); re->Decref(); - CHECK_EQ(x->Ref(), 1) << x->Ref(); + ASSERT_EQ(x->Ref(), 1) << x->Ref(); x->Decref(); } diff --git a/re2/testing/required_prefix_test.cc b/re2/testing/required_prefix_test.cc index 04a1ee4..3f18d9b 100644 --- a/re2/testing/required_prefix_test.cc +++ b/re2/testing/required_prefix_test.cc @@ -47,20 +47,20 @@ TEST(RequiredPrefix, SimpleTests) { if (j == 0) flags = flags | Regexp::Latin1; Regexp* re = Regexp::Parse(t.regexp, flags, NULL); - CHECK(re) << " " << t.regexp; + ASSERT_TRUE(re != NULL) << " " << t.regexp; string p; bool f; Regexp* s; - CHECK_EQ(t.return_value, re->RequiredPrefix(&p, &f, &s)) + ASSERT_EQ(t.return_value, re->RequiredPrefix(&p, &f, &s)) << " " << t.regexp << " " << (j==0 ? "latin1" : "utf") << " " << re->Dump(); if (t.return_value) { - CHECK_EQ(p, string(t.prefix)) + ASSERT_EQ(p, string(t.prefix)) << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); - CHECK_EQ(f, t.foldcase) + ASSERT_EQ(f, t.foldcase) << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); - CHECK_EQ(s->ToString(), string(t.suffix)) + ASSERT_EQ(s->ToString(), string(t.suffix)) << " " << t.regexp << " " << (j==0 ? "latin1" : "utf"); s->Decref(); } diff --git a/re2/testing/search_test.cc b/re2/testing/search_test.cc index 144233e..a67b468 100644 --- a/re2/testing/search_test.cc +++ b/re2/testing/search_test.cc @@ -321,8 +321,8 @@ TEST(Regexp, SearchTests) { // Build a dummy ExhaustiveTest call that will trigger just // this one test, so that we log the test case. std::vector<string> atom, alpha, ops; - atom.push_back(StringPiece(t.regexp).ToString()); - alpha.push_back(StringPiece(t.text).ToString()); + atom.push_back(t.regexp); + alpha.push_back(t.text); ExhaustiveTest(1, 0, atom, ops, 1, alpha, "", ""); } } diff --git a/re2/testing/set_test.cc b/re2/testing/set_test.cc index 25c4f18..5cdc11f 100644 --- a/re2/testing/set_test.cc +++ b/re2/testing/set_test.cc @@ -16,203 +16,203 @@ namespace re2 { TEST(Set, Unanchored) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); - CHECK_EQ(s.Add("foo", NULL), 0); - CHECK_EQ(s.Add("(", NULL), -1); - CHECK_EQ(s.Add("bar", NULL), 1); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("foo", NULL), 0); + ASSERT_EQ(s.Add("(", NULL), -1); + ASSERT_EQ(s.Add("bar", NULL), 1); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("foobar", NULL), true); - CHECK_EQ(s.Match("fooba", NULL), true); - CHECK_EQ(s.Match("oobar", NULL), true); + ASSERT_EQ(s.Match("foobar", NULL), true); + ASSERT_EQ(s.Match("fooba", NULL), true); + ASSERT_EQ(s.Match("oobar", NULL), true); std::vector<int> v; - CHECK_EQ(s.Match("foobar", &v), true); - CHECK_EQ(v.size(), 2); - CHECK_EQ(v[0], 0); - CHECK_EQ(v[1], 1); - - CHECK_EQ(s.Match("fooba", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); - - CHECK_EQ(s.Match("oobar", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 1); + ASSERT_EQ(s.Match("foobar", &v), true); + ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v[0], 0); + ASSERT_EQ(v[1], 1); + + ASSERT_EQ(s.Match("fooba", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); + + ASSERT_EQ(s.Match("oobar", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 1); } TEST(Set, UnanchoredFactored) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); - CHECK_EQ(s.Add("foo", NULL), 0); - CHECK_EQ(s.Add("(", NULL), -1); - CHECK_EQ(s.Add("foobar", NULL), 1); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("foo", NULL), 0); + ASSERT_EQ(s.Add("(", NULL), -1); + ASSERT_EQ(s.Add("foobar", NULL), 1); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("foobar", NULL), true); - CHECK_EQ(s.Match("obarfoobaroo", NULL), true); - CHECK_EQ(s.Match("fooba", NULL), true); - CHECK_EQ(s.Match("oobar", NULL), false); + ASSERT_EQ(s.Match("foobar", NULL), true); + ASSERT_EQ(s.Match("obarfoobaroo", NULL), true); + ASSERT_EQ(s.Match("fooba", NULL), true); + ASSERT_EQ(s.Match("oobar", NULL), false); std::vector<int> v; - CHECK_EQ(s.Match("foobar", &v), true); - CHECK_EQ(v.size(), 2); - CHECK_EQ(v[0], 0); - CHECK_EQ(v[1], 1); - - CHECK_EQ(s.Match("obarfoobaroo", &v), true); - CHECK_EQ(v.size(), 2); - CHECK_EQ(v[0], 0); - CHECK_EQ(v[1], 1); - - CHECK_EQ(s.Match("fooba", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); - - CHECK_EQ(s.Match("oobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), true); + ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v[0], 0); + ASSERT_EQ(v[1], 1); + + ASSERT_EQ(s.Match("obarfoobaroo", &v), true); + ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v[0], 0); + ASSERT_EQ(v[1], 1); + + ASSERT_EQ(s.Match("fooba", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); + + ASSERT_EQ(s.Match("oobar", &v), false); + ASSERT_EQ(v.size(), 0); } TEST(Set, UnanchoredDollar) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); - CHECK_EQ(s.Add("foo$", NULL), 0); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("foo$", NULL), 0); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("foo", NULL), true); - CHECK_EQ(s.Match("foobar", NULL), false); + ASSERT_EQ(s.Match("foo", NULL), true); + ASSERT_EQ(s.Match("foobar", NULL), false); std::vector<int> v; - CHECK_EQ(s.Match("foo", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("foo", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); - CHECK_EQ(s.Match("foobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), false); + ASSERT_EQ(v.size(), 0); } TEST(Set, UnanchoredWordBoundary) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); - CHECK_EQ(s.Add("foo\\b", NULL), 0); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("foo\\b", NULL), 0); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("foo", NULL), true); - CHECK_EQ(s.Match("foobar", NULL), false); - CHECK_EQ(s.Match("foo bar", NULL), true); + ASSERT_EQ(s.Match("foo", NULL), true); + ASSERT_EQ(s.Match("foobar", NULL), false); + ASSERT_EQ(s.Match("foo bar", NULL), true); std::vector<int> v; - CHECK_EQ(s.Match("foo", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("foo", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); - CHECK_EQ(s.Match("foobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("foo bar", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("foo bar", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); } TEST(Set, Anchored) { RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH); - CHECK_EQ(s.Add("foo", NULL), 0); - CHECK_EQ(s.Add("(", NULL), -1); - CHECK_EQ(s.Add("bar", NULL), 1); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("foo", NULL), 0); + ASSERT_EQ(s.Add("(", NULL), -1); + ASSERT_EQ(s.Add("bar", NULL), 1); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("foobar", NULL), false); - CHECK_EQ(s.Match("fooba", NULL), false); - CHECK_EQ(s.Match("oobar", NULL), false); - CHECK_EQ(s.Match("foo", NULL), true); - CHECK_EQ(s.Match("bar", NULL), true); + ASSERT_EQ(s.Match("foobar", NULL), false); + ASSERT_EQ(s.Match("fooba", NULL), false); + ASSERT_EQ(s.Match("oobar", NULL), false); + ASSERT_EQ(s.Match("foo", NULL), true); + ASSERT_EQ(s.Match("bar", NULL), true); std::vector<int> v; - CHECK_EQ(s.Match("foobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("fooba", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("fooba", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("oobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("oobar", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("foo", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("foo", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); - CHECK_EQ(s.Match("bar", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 1); + ASSERT_EQ(s.Match("bar", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 1); } TEST(Set, EmptyUnanchored) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("", NULL), false); - CHECK_EQ(s.Match("foobar", NULL), false); + ASSERT_EQ(s.Match("", NULL), false); + ASSERT_EQ(s.Match("foobar", NULL), false); std::vector<int> v; - CHECK_EQ(s.Match("", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("foobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), false); + ASSERT_EQ(v.size(), 0); } TEST(Set, EmptyAnchored) { RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("", NULL), false); - CHECK_EQ(s.Match("foobar", NULL), false); + ASSERT_EQ(s.Match("", NULL), false); + ASSERT_EQ(s.Match("foobar", NULL), false); std::vector<int> v; - CHECK_EQ(s.Match("", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("foobar", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("foobar", &v), false); + ASSERT_EQ(v.size(), 0); } TEST(Set, Prefix) { RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH); - CHECK_EQ(s.Add("/prefix/\\d*", NULL), 0); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add("/prefix/\\d*", NULL), 0); + ASSERT_EQ(s.Compile(), true); - CHECK_EQ(s.Match("/prefix", NULL), false); - CHECK_EQ(s.Match("/prefix/", NULL), true); - CHECK_EQ(s.Match("/prefix/42", NULL), true); + ASSERT_EQ(s.Match("/prefix", NULL), false); + ASSERT_EQ(s.Match("/prefix/", NULL), true); + ASSERT_EQ(s.Match("/prefix/42", NULL), true); std::vector<int> v; - CHECK_EQ(s.Match("/prefix", &v), false); - CHECK_EQ(v.size(), 0); + ASSERT_EQ(s.Match("/prefix", &v), false); + ASSERT_EQ(v.size(), 0); - CHECK_EQ(s.Match("/prefix/", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("/prefix/", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); - CHECK_EQ(s.Match("/prefix/42", &v), true); - CHECK_EQ(v.size(), 1); - CHECK_EQ(v[0], 0); + ASSERT_EQ(s.Match("/prefix/42", &v), true); + ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v[0], 0); } TEST(Set, OutOfMemory) { RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED); string a(10000, 'a'); - CHECK_EQ(s.Add(a, NULL), 0); - CHECK_EQ(s.Compile(), true); + ASSERT_EQ(s.Add(a, NULL), 0); + ASSERT_EQ(s.Compile(), true); std::vector<int> v; RE2::Set::ErrorInfo ei; - CHECK_EQ(s.Match(a, &v, &ei), false); - CHECK_EQ(v.size(), 0); - CHECK_EQ(ei.kind, RE2::Set::kOutOfMemory); + ASSERT_EQ(s.Match(a, &v, &ei), false); + ASSERT_EQ(v.size(), 0); + ASSERT_EQ(ei.kind, RE2::Set::kOutOfMemory); } } // namespace re2 diff --git a/re2/testing/simplify_test.cc b/re2/testing/simplify_test.cc index 43b9656..ede0f32 100644 --- a/re2/testing/simplify_test.cc +++ b/re2/testing/simplify_test.cc @@ -252,13 +252,13 @@ TEST(TestSimplify, SimpleRegexps) { Regexp::MatchNL | (Regexp::LikePerl & ~Regexp::OneLine), &status); - CHECK(re != NULL) << " " << tests[i].regexp << " " << status.Text(); + ASSERT_TRUE(re != NULL) << " " << tests[i].regexp << " " << status.Text(); Regexp* sre = re->Simplify(); - CHECK(sre != NULL); + ASSERT_TRUE(sre != NULL); // Check that already-simple regexps don't allocate new ones. if (strcmp(tests[i].regexp, tests[i].simplified) == 0) { - CHECK(re == sre) << " " << tests[i].regexp + ASSERT_TRUE(re == sre) << " " << tests[i].regexp << " " << re->ToString() << " " << sre->ToString(); } diff --git a/re2/testing/string_generator_test.cc b/re2/testing/string_generator_test.cc index 1f10a80..2c040a3 100644 --- a/re2/testing/string_generator_test.cc +++ b/re2/testing/string_generator_test.cc @@ -47,7 +47,7 @@ static void RunTest(int len, const string& alphabet, bool donull) { } while (g.HasNext()) { - string s = g.Next().ToString(); + string s = string(g.Next()); n++; // Check that all characters in s appear in alphabet. diff --git a/re2/testing/tester.cc b/re2/testing/tester.cc index 6e4807d..f85f791 100644 --- a/re2/testing/tester.cc +++ b/re2/testing/tester.cc @@ -220,7 +220,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind, } // Create re string that will be used for RE and RE2. - string re = regexp_str.ToString(); + string re = string(regexp_str); // Accomodate flags. // Regexp::Latin1 will be accomodated below. if (!(flags & Regexp::OneLine)) diff --git a/re2_test.bzl b/re2_test.bzl index 94443f6..c0eb654 100644 --- a/re2_test.bzl +++ b/re2_test.bzl @@ -8,5 +8,5 @@ def re2_test(name, deps=[], size="medium"): name=name, srcs=["re2/testing/%s.cc" % (name)], deps=[":test"] + deps, - size = size, + size=size, ) diff --git a/util/test.cc b/util/test.cc index fb31ed8..29c8b41 100644 --- a/util/test.cc +++ b/util/test.cc @@ -3,9 +3,6 @@ // license that can be found in the LICENSE file. #include <stdio.h> -#ifndef _WIN32 -#include <sys/resource.h> -#endif #include "util/test.h" diff --git a/util/test.h b/util/test.h index e075c1e..5242e94 100644 --- a/util/test.h +++ b/util/test.h @@ -23,14 +23,26 @@ class TestRegisterer { } }; -// TODO(rsc): Do a better job. -#define EXPECT_EQ CHECK_EQ +// fatal assertions +#define ASSERT_TRUE CHECK +#define ASSERT_FALSE(x) CHECK(!(x)) +#define ASSERT_EQ CHECK_EQ +#define ASSERT_NE CHECK_NE +#define ASSERT_LT CHECK_LT +#define ASSERT_LE CHECK_LE +#define ASSERT_GT CHECK_GT +#define ASSERT_GE CHECK_GE + +// nonfatal assertions +// TODO(rsc): Do a better job? #define EXPECT_TRUE CHECK +#define EXPECT_FALSE(x) CHECK(!(x)) +#define EXPECT_EQ CHECK_EQ +#define EXPECT_NE CHECK_NE #define EXPECT_LT CHECK_LT -#define EXPECT_GT CHECK_GT #define EXPECT_LE CHECK_LE +#define EXPECT_GT CHECK_GT #define EXPECT_GE CHECK_GE -#define EXPECT_FALSE(x) CHECK(!(x)) namespace testing { class MallocCounter { |