superupon / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

No regular expression matching operators provided #244

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Google Test has a functional RE class in its internals, yet it's used only
for death tests. Semi-portable REs are very useful for general testing,
however, and are so trivial to implement using the RE class that it seems
very strange that Google Test doesn't provide it already. Here's my simple
implementation, which I'd like to see some form of in a future release:

static inline ::testing::AssertionResult _test_assert_REmatch(const char
*str_code, const char *re_code, const char *bool_code, const char *str,
const ::testing::internal::RE &re, const bool full_match)
{
    if ((full_match ? ::testing::internal::RE::FullMatch(str, re) :
::testing::internal::RE::PartialMatch(str, re)))
        return ::testing::AssertionSuccess();
    return ::testing::AssertionFailure(::testing::Message()
                                    << "Value of: " << str_code << "\n"
                                    << "Which is: " << str << "\n"
                                    << "Does not match: " << re.pattern());
}

#define EXPECT_RE_MATCH_FULL(s, r)         
EXPECT_PRED_FORMAT3(_test_assert_REmatch, s, ::testing::internal::RE(r), true)
#define ASSERT_RE_MATCH_FULL(s, r)         
ASSERT_PRED_FORMAT3(_test_assert_REmatch, s, ::testing::internal::RE(r), true)
#define EXPECT_RE_MATCH_PARTIAL(s, r)      
EXPECT_PRED_FORMAT3(_test_assert_REmatch, s, ::testing::internal::RE(r), false)
#define ASSERT_RE_MATCH_PARTIAL(s, r)      
ASSERT_PRED_FORMAT3(_test_assert_REmatch, s, ::testing::internal::RE(r), false)

Original issue reported on code.google.com by ameaijou@gmail.com on 4 Jan 2010 at 3:14

GoogleCodeExporter commented 9 years ago
Addendum: I hereby place the code as written in the issue description above in 
the
public domain for free use by anyone without any restriction whatsoever.

Original comment by ameaijou@gmail.com on 4 Jan 2010 at 3:23

GoogleCodeExporter commented 9 years ago
Please don't use anything from the testing::internal namespace directly, as 
they are
implementation details and thus subject to change without notice.  If you use 
them,
your code could break with new releases of gtest.

We do provide regular expression matching.  Currently you need to download 
Google
Mock (http://code.google.com/p/googlemock/) in order to use it.  The syntax is:

  EXPECT_THAT(my_string, ContainsRegex("a.*b"));

See http://code.google.com/p/googlemock/wiki/CheatSheet#String_Matchers for 
other
checks you can do on strings, once you start to use gmock.

We plan to move this functionality from gmock to gtest
(http://code.google.com/p/googletest/issues/detail?id=191).  Please star issue 
191 to
receive updates on it.

Original comment by w...@google.com on 4 Jan 2010 at 5:12