Fix EXPECT_THAT() to support literal strings as a second argument.

This commit is contained in:
kosak 2015-04-28 23:06:58 +00:00
parent 6305ff5a92
commit 9b1a944ec4
2 changed files with 19 additions and 3 deletions

View File

@ -1833,7 +1833,7 @@ class MatcherAsPredicate {
template <typename M>
class PredicateFormatterFromMatcher {
public:
explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {}
explicit PredicateFormatterFromMatcher(M m) : matcher_(internal::move(m)) {}
// This template () operator allows a PredicateFormatterFromMatcher
// object to act as a predicate-formatter suitable for using with
@ -1873,10 +1873,11 @@ class PredicateFormatterFromMatcher {
// A helper function for converting a matcher to a predicate-formatter
// without the user needing to explicitly write the type. This is
// used for implementing ASSERT_THAT() and EXPECT_THAT().
// Implementation detail: 'matcher' is received by-value to force decaying.
template <typename M>
inline PredicateFormatterFromMatcher<M>
MakePredicateFormatterFromMatcher(const M& matcher) {
return PredicateFormatterFromMatcher<M>(matcher);
MakePredicateFormatterFromMatcher(M matcher) {
return PredicateFormatterFromMatcher<M>(internal::move(matcher));
}
// Implements the polymorphic floating point equality matcher, which matches

View File

@ -762,6 +762,21 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) {
EXPECT_TRUE(m.Matches(n));
}
TEST(ExpectThat, TakesLiterals) {
EXPECT_THAT(1, 1);
EXPECT_THAT(1.0, 1.0);
EXPECT_THAT(string(), "");
}
TEST(ExpectThat, TakesFunctions) {
struct Helper {
static void Func() {}
};
void (*func)() = Helper::Func;
EXPECT_THAT(func, Helper::Func);
EXPECT_THAT(func, &Helper::Func);
}
// Tests that A<T>() matches any value of type T.
TEST(ATest, MatchesAnyValue) {
// Tests a matcher for a value type.