|
|
@ -61,8 +61,10 @@ bool SkipPrefix(const char* prefix, const char** pstr); |
|
|
|
|
|
|
|
|
|
|
|
namespace gmock_matchers_test { |
|
|
|
namespace gmock_matchers_test { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using std::make_pair; |
|
|
|
using std::map; |
|
|
|
using std::map; |
|
|
|
using std::multimap; |
|
|
|
using std::multimap; |
|
|
|
|
|
|
|
using std::pair; |
|
|
|
using std::stringstream; |
|
|
|
using std::stringstream; |
|
|
|
using std::tr1::make_tuple; |
|
|
|
using std::tr1::make_tuple; |
|
|
|
using testing::A; |
|
|
|
using testing::A; |
|
|
@ -71,9 +73,11 @@ using testing::AllOf; |
|
|
|
using testing::An; |
|
|
|
using testing::An; |
|
|
|
using testing::AnyOf; |
|
|
|
using testing::AnyOf; |
|
|
|
using testing::ByRef; |
|
|
|
using testing::ByRef; |
|
|
|
|
|
|
|
using testing::ContainsRegex; |
|
|
|
using testing::DoubleEq; |
|
|
|
using testing::DoubleEq; |
|
|
|
using testing::EndsWith; |
|
|
|
using testing::EndsWith; |
|
|
|
using testing::Eq; |
|
|
|
using testing::Eq; |
|
|
|
|
|
|
|
using testing::ExplainMatchResult; |
|
|
|
using testing::Field; |
|
|
|
using testing::Field; |
|
|
|
using testing::FloatEq; |
|
|
|
using testing::FloatEq; |
|
|
|
using testing::Ge; |
|
|
|
using testing::Ge; |
|
|
@ -85,12 +89,12 @@ using testing::Le; |
|
|
|
using testing::Lt; |
|
|
|
using testing::Lt; |
|
|
|
using testing::MakeMatcher; |
|
|
|
using testing::MakeMatcher; |
|
|
|
using testing::MakePolymorphicMatcher; |
|
|
|
using testing::MakePolymorphicMatcher; |
|
|
|
|
|
|
|
using testing::MatchResultListener; |
|
|
|
using testing::Matcher; |
|
|
|
using testing::Matcher; |
|
|
|
using testing::MatcherCast; |
|
|
|
using testing::MatcherCast; |
|
|
|
using testing::MatcherInterface; |
|
|
|
using testing::MatcherInterface; |
|
|
|
using testing::Matches; |
|
|
|
using testing::Matches; |
|
|
|
using testing::ExplainMatchResult; |
|
|
|
using testing::MatchesRegex; |
|
|
|
using testing::MatchResultListener; |
|
|
|
|
|
|
|
using testing::NanSensitiveDoubleEq; |
|
|
|
using testing::NanSensitiveDoubleEq; |
|
|
|
using testing::NanSensitiveFloatEq; |
|
|
|
using testing::NanSensitiveFloatEq; |
|
|
|
using testing::Ne; |
|
|
|
using testing::Ne; |
|
|
@ -112,17 +116,19 @@ using testing::TypedEq; |
|
|
|
using testing::Value; |
|
|
|
using testing::Value; |
|
|
|
using testing::_; |
|
|
|
using testing::_; |
|
|
|
using testing::internal::DummyMatchResultListener; |
|
|
|
using testing::internal::DummyMatchResultListener; |
|
|
|
|
|
|
|
using testing::internal::ExplainMatchFailureTupleTo; |
|
|
|
using testing::internal::FloatingEqMatcher; |
|
|
|
using testing::internal::FloatingEqMatcher; |
|
|
|
using testing::internal::FormatMatcherDescriptionSyntaxError; |
|
|
|
using testing::internal::FormatMatcherDescriptionSyntaxError; |
|
|
|
using testing::internal::GetParamIndex; |
|
|
|
using testing::internal::GetParamIndex; |
|
|
|
using testing::internal::Interpolation; |
|
|
|
using testing::internal::Interpolation; |
|
|
|
using testing::internal::Interpolations; |
|
|
|
using testing::internal::Interpolations; |
|
|
|
using testing::internal::JoinAsTuple; |
|
|
|
using testing::internal::JoinAsTuple; |
|
|
|
|
|
|
|
using testing::internal::RE; |
|
|
|
using testing::internal::SkipPrefix; |
|
|
|
using testing::internal::SkipPrefix; |
|
|
|
using testing::internal::StreamMatchResultListener; |
|
|
|
using testing::internal::StreamMatchResultListener; |
|
|
|
using testing::internal::String; |
|
|
|
using testing::internal::String; |
|
|
|
using testing::internal::Strings; |
|
|
|
|
|
|
|
using testing::internal::StringMatchResultListener; |
|
|
|
using testing::internal::StringMatchResultListener; |
|
|
|
|
|
|
|
using testing::internal::Strings; |
|
|
|
using testing::internal::ValidateMatcherDescription; |
|
|
|
using testing::internal::ValidateMatcherDescription; |
|
|
|
using testing::internal::kInvalidInterpolation; |
|
|
|
using testing::internal::kInvalidInterpolation; |
|
|
|
using testing::internal::kPercentInterpolation; |
|
|
|
using testing::internal::kPercentInterpolation; |
|
|
@ -131,17 +137,13 @@ using testing::internal::linked_ptr; |
|
|
|
using testing::internal::scoped_ptr; |
|
|
|
using testing::internal::scoped_ptr; |
|
|
|
using testing::internal::string; |
|
|
|
using testing::internal::string; |
|
|
|
|
|
|
|
|
|
|
|
using testing::ContainsRegex; |
|
|
|
|
|
|
|
using testing::MatchesRegex; |
|
|
|
|
|
|
|
using testing::internal::RE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For testing ExplainMatchResultTo().
|
|
|
|
// For testing ExplainMatchResultTo().
|
|
|
|
class GreaterThanMatcher : public MatcherInterface<int> { |
|
|
|
class GreaterThanMatcher : public MatcherInterface<int> { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {} |
|
|
|
explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {} |
|
|
|
|
|
|
|
|
|
|
|
virtual void DescribeTo(::std::ostream* os) const { |
|
|
|
virtual void DescribeTo(::std::ostream* os) const { |
|
|
|
*os << "is greater than " << rhs_; |
|
|
|
*os << "is > " << rhs_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual bool MatchAndExplain(int lhs, |
|
|
|
virtual bool MatchAndExplain(int lhs, |
|
|
@ -757,7 +759,7 @@ TEST(GeTest, ImplementsGreaterThanOrEqual) { |
|
|
|
// Tests that Ge(v) describes itself properly.
|
|
|
|
// Tests that Ge(v) describes itself properly.
|
|
|
|
TEST(GeTest, CanDescribeSelf) { |
|
|
|
TEST(GeTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Ge(5); |
|
|
|
Matcher<int> m = Ge(5); |
|
|
|
EXPECT_EQ("is greater than or equal to 5", Describe(m)); |
|
|
|
EXPECT_EQ("is >= 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Gt(v) matches anything > v.
|
|
|
|
// Tests that Gt(v) matches anything > v.
|
|
|
@ -771,7 +773,7 @@ TEST(GtTest, ImplementsGreaterThan) { |
|
|
|
// Tests that Gt(v) describes itself properly.
|
|
|
|
// Tests that Gt(v) describes itself properly.
|
|
|
|
TEST(GtTest, CanDescribeSelf) { |
|
|
|
TEST(GtTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Gt(5); |
|
|
|
Matcher<int> m = Gt(5); |
|
|
|
EXPECT_EQ("is greater than 5", Describe(m)); |
|
|
|
EXPECT_EQ("is > 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Le(v) matches anything <= v.
|
|
|
|
// Tests that Le(v) matches anything <= v.
|
|
|
@ -785,7 +787,7 @@ TEST(LeTest, ImplementsLessThanOrEqual) { |
|
|
|
// Tests that Le(v) describes itself properly.
|
|
|
|
// Tests that Le(v) describes itself properly.
|
|
|
|
TEST(LeTest, CanDescribeSelf) { |
|
|
|
TEST(LeTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Le(5); |
|
|
|
Matcher<int> m = Le(5); |
|
|
|
EXPECT_EQ("is less than or equal to 5", Describe(m)); |
|
|
|
EXPECT_EQ("is <= 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Lt(v) matches anything < v.
|
|
|
|
// Tests that Lt(v) matches anything < v.
|
|
|
@ -799,7 +801,7 @@ TEST(LtTest, ImplementsLessThan) { |
|
|
|
// Tests that Lt(v) describes itself properly.
|
|
|
|
// Tests that Lt(v) describes itself properly.
|
|
|
|
TEST(LtTest, CanDescribeSelf) { |
|
|
|
TEST(LtTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Lt(5); |
|
|
|
Matcher<int> m = Lt(5); |
|
|
|
EXPECT_EQ("is less than 5", Describe(m)); |
|
|
|
EXPECT_EQ("is < 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Ne(v) matches anything != v.
|
|
|
|
// Tests that Ne(v) matches anything != v.
|
|
|
@ -813,7 +815,7 @@ TEST(NeTest, ImplementsNotEqual) { |
|
|
|
// Tests that Ne(v) describes itself properly.
|
|
|
|
// Tests that Ne(v) describes itself properly.
|
|
|
|
TEST(NeTest, CanDescribeSelf) { |
|
|
|
TEST(NeTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Ne(5); |
|
|
|
Matcher<int> m = Ne(5); |
|
|
|
EXPECT_EQ("is not equal to 5", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that IsNull() matches any NULL pointer of any type.
|
|
|
|
// Tests that IsNull() matches any NULL pointer of any type.
|
|
|
@ -876,7 +878,7 @@ TEST(IsNullTest, ReferenceToConstScopedPtr) { |
|
|
|
TEST(IsNullTest, CanDescribeSelf) { |
|
|
|
TEST(IsNullTest, CanDescribeSelf) { |
|
|
|
Matcher<int*> m = IsNull(); |
|
|
|
Matcher<int*> m = IsNull(); |
|
|
|
EXPECT_EQ("is NULL", Describe(m)); |
|
|
|
EXPECT_EQ("is NULL", Describe(m)); |
|
|
|
EXPECT_EQ("is not NULL", DescribeNegation(m)); |
|
|
|
EXPECT_EQ("isn't NULL", DescribeNegation(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that NotNull() matches any non-NULL pointer of any type.
|
|
|
|
// Tests that NotNull() matches any non-NULL pointer of any type.
|
|
|
@ -923,7 +925,7 @@ TEST(NotNullTest, ReferenceToConstScopedPtr) { |
|
|
|
// Tests that NotNull() describes itself properly.
|
|
|
|
// Tests that NotNull() describes itself properly.
|
|
|
|
TEST(NotNullTest, CanDescribeSelf) { |
|
|
|
TEST(NotNullTest, CanDescribeSelf) { |
|
|
|
Matcher<int*> m = NotNull(); |
|
|
|
Matcher<int*> m = NotNull(); |
|
|
|
EXPECT_EQ("is not NULL", Describe(m)); |
|
|
|
EXPECT_EQ("isn't NULL", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Ref(variable) matches an argument that references
|
|
|
|
// Tests that Ref(variable) matches an argument that references
|
|
|
@ -973,6 +975,16 @@ TEST(RefTest, IsCovariant) { |
|
|
|
EXPECT_FALSE(m1.Matches(base2)); |
|
|
|
EXPECT_FALSE(m1.Matches(base2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RefTest, ExplainsResult) { |
|
|
|
|
|
|
|
int n = 0; |
|
|
|
|
|
|
|
EXPECT_THAT(Explain(Matcher<const int&>(Ref(n)), n), |
|
|
|
|
|
|
|
StartsWith("which is located @")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int m = 0; |
|
|
|
|
|
|
|
EXPECT_THAT(Explain(Matcher<const int&>(Ref(n)), m), |
|
|
|
|
|
|
|
StartsWith("which is located @")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests string comparison matchers.
|
|
|
|
// Tests string comparison matchers.
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StrEqTest, MatchesEqualString) { |
|
|
|
TEST(StrEqTest, MatchesEqualString) { |
|
|
@ -1013,7 +1025,7 @@ TEST(StrNeTest, MatchesUnequalString) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(StrNeTest, CanDescribeSelf) { |
|
|
|
TEST(StrNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const char*> m = StrNe("Hi"); |
|
|
|
Matcher<const char*> m = StrNe("Hi"); |
|
|
|
EXPECT_EQ("is not equal to \"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to \"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
|
TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
@ -1072,7 +1084,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(StrCaseNeTest, CanDescribeSelf) { |
|
|
|
TEST(StrCaseNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const char*> m = StrCaseNe("Hi"); |
|
|
|
Matcher<const char*> m = StrCaseNe("Hi"); |
|
|
|
EXPECT_EQ("is not equal to (ignoring case) \"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to (ignoring case) \"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that HasSubstr() works for matching string-typed values.
|
|
|
|
// Tests that HasSubstr() works for matching string-typed values.
|
|
|
@ -1106,12 +1118,21 @@ TEST(HasSubstrTest, CanDescribeSelf) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(KeyTest, CanDescribeSelf) { |
|
|
|
TEST(KeyTest, CanDescribeSelf) { |
|
|
|
Matcher<const std::pair<std::string, int>&> m = Key("foo"); |
|
|
|
Matcher<const pair<std::string, int>&> m = Key("foo"); |
|
|
|
EXPECT_EQ("has a key that is equal to \"foo\"", Describe(m)); |
|
|
|
EXPECT_EQ("has a key that is equal to \"foo\"", Describe(m)); |
|
|
|
|
|
|
|
EXPECT_EQ("doesn't have a key that is equal to \"foo\"", DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(KeyTest, ExplainsResult) { |
|
|
|
|
|
|
|
Matcher<pair<int, bool> > m = Key(GreaterThan(10)); |
|
|
|
|
|
|
|
EXPECT_EQ("whose first field is a value which is 5 less than 10", |
|
|
|
|
|
|
|
Explain(m, make_pair(5, true))); |
|
|
|
|
|
|
|
EXPECT_EQ("whose first field is a value which is 5 more than 10", |
|
|
|
|
|
|
|
Explain(m, make_pair(15, true))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(KeyTest, MatchesCorrectly) { |
|
|
|
TEST(KeyTest, MatchesCorrectly) { |
|
|
|
std::pair<int, std::string> p(25, "foo"); |
|
|
|
pair<int, std::string> p(25, "foo"); |
|
|
|
EXPECT_THAT(p, Key(25)); |
|
|
|
EXPECT_THAT(p, Key(25)); |
|
|
|
EXPECT_THAT(p, Not(Key(42))); |
|
|
|
EXPECT_THAT(p, Not(Key(42))); |
|
|
|
EXPECT_THAT(p, Key(Ge(20))); |
|
|
|
EXPECT_THAT(p, Key(Ge(20))); |
|
|
@ -1121,30 +1142,30 @@ TEST(KeyTest, MatchesCorrectly) { |
|
|
|
TEST(KeyTest, SafelyCastsInnerMatcher) { |
|
|
|
TEST(KeyTest, SafelyCastsInnerMatcher) { |
|
|
|
Matcher<int> is_positive = Gt(0); |
|
|
|
Matcher<int> is_positive = Gt(0); |
|
|
|
Matcher<int> is_negative = Lt(0); |
|
|
|
Matcher<int> is_negative = Lt(0); |
|
|
|
std::pair<char, bool> p('a', true); |
|
|
|
pair<char, bool> p('a', true); |
|
|
|
EXPECT_THAT(p, Key(is_positive)); |
|
|
|
EXPECT_THAT(p, Key(is_positive)); |
|
|
|
EXPECT_THAT(p, Not(Key(is_negative))); |
|
|
|
EXPECT_THAT(p, Not(Key(is_negative))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(KeyTest, InsideContainsUsingMap) { |
|
|
|
TEST(KeyTest, InsideContainsUsingMap) { |
|
|
|
std::map<int, char> container; |
|
|
|
std::map<int, char> container; |
|
|
|
container.insert(std::make_pair(1, 'a')); |
|
|
|
container.insert(make_pair(1, 'a')); |
|
|
|
container.insert(std::make_pair(2, 'b')); |
|
|
|
container.insert(make_pair(2, 'b')); |
|
|
|
container.insert(std::make_pair(4, 'c')); |
|
|
|
container.insert(make_pair(4, 'c')); |
|
|
|
EXPECT_THAT(container, Contains(Key(1))); |
|
|
|
EXPECT_THAT(container, Contains(Key(1))); |
|
|
|
EXPECT_THAT(container, Not(Contains(Key(3)))); |
|
|
|
EXPECT_THAT(container, Not(Contains(Key(3)))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(KeyTest, InsideContainsUsingMultimap) { |
|
|
|
TEST(KeyTest, InsideContainsUsingMultimap) { |
|
|
|
std::multimap<int, char> container; |
|
|
|
std::multimap<int, char> container; |
|
|
|
container.insert(std::make_pair(1, 'a')); |
|
|
|
container.insert(make_pair(1, 'a')); |
|
|
|
container.insert(std::make_pair(2, 'b')); |
|
|
|
container.insert(make_pair(2, 'b')); |
|
|
|
container.insert(std::make_pair(4, 'c')); |
|
|
|
container.insert(make_pair(4, 'c')); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_THAT(container, Not(Contains(Key(25)))); |
|
|
|
EXPECT_THAT(container, Not(Contains(Key(25)))); |
|
|
|
container.insert(std::make_pair(25, 'd')); |
|
|
|
container.insert(make_pair(25, 'd')); |
|
|
|
EXPECT_THAT(container, Contains(Key(25))); |
|
|
|
EXPECT_THAT(container, Contains(Key(25))); |
|
|
|
container.insert(std::make_pair(25, 'e')); |
|
|
|
container.insert(make_pair(25, 'e')); |
|
|
|
EXPECT_THAT(container, Contains(Key(25))); |
|
|
|
EXPECT_THAT(container, Contains(Key(25))); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_THAT(container, Contains(Key(1))); |
|
|
|
EXPECT_THAT(container, Contains(Key(1))); |
|
|
@ -1153,25 +1174,25 @@ TEST(KeyTest, InsideContainsUsingMultimap) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(PairTest, Typing) { |
|
|
|
TEST(PairTest, Typing) { |
|
|
|
// Test verifies the following type conversions can be compiled.
|
|
|
|
// Test verifies the following type conversions can be compiled.
|
|
|
|
Matcher<const std::pair<const char*, int>&> m1 = Pair("foo", 42); |
|
|
|
Matcher<const pair<const char*, int>&> m1 = Pair("foo", 42); |
|
|
|
Matcher<const std::pair<const char*, int> > m2 = Pair("foo", 42); |
|
|
|
Matcher<const pair<const char*, int> > m2 = Pair("foo", 42); |
|
|
|
Matcher<std::pair<const char*, int> > m3 = Pair("foo", 42); |
|
|
|
Matcher<pair<const char*, int> > m3 = Pair("foo", 42); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<std::pair<int, const std::string> > m4 = Pair(25, "42"); |
|
|
|
Matcher<pair<int, const std::string> > m4 = Pair(25, "42"); |
|
|
|
Matcher<std::pair<const std::string, int> > m5 = Pair("25", 42); |
|
|
|
Matcher<pair<const std::string, int> > m5 = Pair("25", 42); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(PairTest, CanDescribeSelf) { |
|
|
|
TEST(PairTest, CanDescribeSelf) { |
|
|
|
Matcher<const std::pair<std::string, int>&> m1 = Pair("foo", 42); |
|
|
|
Matcher<const pair<std::string, int>&> m1 = Pair("foo", 42); |
|
|
|
EXPECT_EQ("has a first field that is equal to \"foo\"" |
|
|
|
EXPECT_EQ("has a first field that is equal to \"foo\"" |
|
|
|
", and has a second field that is equal to 42", |
|
|
|
", and has a second field that is equal to 42", |
|
|
|
Describe(m1)); |
|
|
|
Describe(m1)); |
|
|
|
EXPECT_EQ("has a first field that is not equal to \"foo\"" |
|
|
|
EXPECT_EQ("has a first field that isn't equal to \"foo\"" |
|
|
|
", or has a second field that is not equal to 42", |
|
|
|
", or has a second field that isn't equal to 42", |
|
|
|
DescribeNegation(m1)); |
|
|
|
DescribeNegation(m1)); |
|
|
|
// Double and triple negation (1 or 2 times not and description of negation).
|
|
|
|
// Double and triple negation (1 or 2 times not and description of negation).
|
|
|
|
Matcher<const std::pair<int, int>&> m2 = Not(Pair(Not(13), 42)); |
|
|
|
Matcher<const pair<int, int>&> m2 = Not(Pair(Not(13), 42)); |
|
|
|
EXPECT_EQ("has a first field that is not equal to 13" |
|
|
|
EXPECT_EQ("has a first field that isn't equal to 13" |
|
|
|
", and has a second field that is equal to 42", |
|
|
|
", and has a second field that is equal to 42", |
|
|
|
DescribeNegation(m2)); |
|
|
|
DescribeNegation(m2)); |
|
|
|
} |
|
|
|
} |
|
|
@ -1179,43 +1200,43 @@ TEST(PairTest, CanDescribeSelf) { |
|
|
|
TEST(PairTest, CanExplainMatchResultTo) { |
|
|
|
TEST(PairTest, CanExplainMatchResultTo) { |
|
|
|
// If neither field matches, Pair() should explain about the first
|
|
|
|
// If neither field matches, Pair() should explain about the first
|
|
|
|
// field.
|
|
|
|
// field.
|
|
|
|
const Matcher<std::pair<int, int> > m = Pair(GreaterThan(0), GreaterThan(0)); |
|
|
|
const Matcher<pair<int, int> > m = Pair(GreaterThan(0), GreaterThan(0)); |
|
|
|
EXPECT_EQ("whose first field does not match, which is 1 less than 0", |
|
|
|
EXPECT_EQ("whose first field does not match, which is 1 less than 0", |
|
|
|
Explain(m, std::make_pair(-1, -2))); |
|
|
|
Explain(m, make_pair(-1, -2))); |
|
|
|
|
|
|
|
|
|
|
|
// If the first field matches but the second doesn't, Pair() should
|
|
|
|
// If the first field matches but the second doesn't, Pair() should
|
|
|
|
// explain about the second field.
|
|
|
|
// explain about the second field.
|
|
|
|
EXPECT_EQ("whose second field does not match, which is 2 less than 0", |
|
|
|
EXPECT_EQ("whose second field does not match, which is 2 less than 0", |
|
|
|
Explain(m, std::make_pair(1, -2))); |
|
|
|
Explain(m, make_pair(1, -2))); |
|
|
|
|
|
|
|
|
|
|
|
// If the first field doesn't match but the second does, Pair()
|
|
|
|
// If the first field doesn't match but the second does, Pair()
|
|
|
|
// should explain about the first field.
|
|
|
|
// should explain about the first field.
|
|
|
|
EXPECT_EQ("whose first field does not match, which is 1 less than 0", |
|
|
|
EXPECT_EQ("whose first field does not match, which is 1 less than 0", |
|
|
|
Explain(m, std::make_pair(-1, 2))); |
|
|
|
Explain(m, make_pair(-1, 2))); |
|
|
|
|
|
|
|
|
|
|
|
// If both fields match, Pair() should explain about them both.
|
|
|
|
// If both fields match, Pair() should explain about them both.
|
|
|
|
EXPECT_EQ("whose both fields match, where the first field is a value " |
|
|
|
EXPECT_EQ("whose both fields match, where the first field is a value " |
|
|
|
"which is 1 more than 0, and the second field is a value " |
|
|
|
"which is 1 more than 0, and the second field is a value " |
|
|
|
"which is 2 more than 0", |
|
|
|
"which is 2 more than 0", |
|
|
|
Explain(m, std::make_pair(1, 2))); |
|
|
|
Explain(m, make_pair(1, 2))); |
|
|
|
|
|
|
|
|
|
|
|
// If only the first match has an explanation, only this explanation should
|
|
|
|
// If only the first match has an explanation, only this explanation should
|
|
|
|
// be printed.
|
|
|
|
// be printed.
|
|
|
|
const Matcher<std::pair<int, int> > explain_first = Pair(GreaterThan(0), 0); |
|
|
|
const Matcher<pair<int, int> > explain_first = Pair(GreaterThan(0), 0); |
|
|
|
EXPECT_EQ("whose both fields match, where the first field is a value " |
|
|
|
EXPECT_EQ("whose both fields match, where the first field is a value " |
|
|
|
"which is 1 more than 0", |
|
|
|
"which is 1 more than 0", |
|
|
|
Explain(explain_first, std::make_pair(1, 0))); |
|
|
|
Explain(explain_first, make_pair(1, 0))); |
|
|
|
|
|
|
|
|
|
|
|
// If only the second match has an explanation, only this explanation should
|
|
|
|
// If only the second match has an explanation, only this explanation should
|
|
|
|
// be printed.
|
|
|
|
// be printed.
|
|
|
|
const Matcher<std::pair<int, int> > explain_second = Pair(0, GreaterThan(0)); |
|
|
|
const Matcher<pair<int, int> > explain_second = Pair(0, GreaterThan(0)); |
|
|
|
EXPECT_EQ("whose both fields match, where the second field is a value " |
|
|
|
EXPECT_EQ("whose both fields match, where the second field is a value " |
|
|
|
"which is 1 more than 0", |
|
|
|
"which is 1 more than 0", |
|
|
|
Explain(explain_second, std::make_pair(0, 1))); |
|
|
|
Explain(explain_second, make_pair(0, 1))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(PairTest, MatchesCorrectly) { |
|
|
|
TEST(PairTest, MatchesCorrectly) { |
|
|
|
std::pair<int, std::string> p(25, "foo"); |
|
|
|
pair<int, std::string> p(25, "foo"); |
|
|
|
|
|
|
|
|
|
|
|
// Both fields match.
|
|
|
|
// Both fields match.
|
|
|
|
EXPECT_THAT(p, Pair(25, "foo")); |
|
|
|
EXPECT_THAT(p, Pair(25, "foo")); |
|
|
@ -1237,7 +1258,7 @@ TEST(PairTest, MatchesCorrectly) { |
|
|
|
TEST(PairTest, SafelyCastsInnerMatchers) { |
|
|
|
TEST(PairTest, SafelyCastsInnerMatchers) { |
|
|
|
Matcher<int> is_positive = Gt(0); |
|
|
|
Matcher<int> is_positive = Gt(0); |
|
|
|
Matcher<int> is_negative = Lt(0); |
|
|
|
Matcher<int> is_negative = Lt(0); |
|
|
|
std::pair<char, bool> p('a', true); |
|
|
|
pair<char, bool> p('a', true); |
|
|
|
EXPECT_THAT(p, Pair(is_positive, _)); |
|
|
|
EXPECT_THAT(p, Pair(is_positive, _)); |
|
|
|
EXPECT_THAT(p, Not(Pair(is_negative, _))); |
|
|
|
EXPECT_THAT(p, Not(Pair(is_negative, _))); |
|
|
|
EXPECT_THAT(p, Pair(_, is_positive)); |
|
|
|
EXPECT_THAT(p, Pair(_, is_positive)); |
|
|
@ -1246,9 +1267,9 @@ TEST(PairTest, SafelyCastsInnerMatchers) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(PairTest, InsideContainsUsingMap) { |
|
|
|
TEST(PairTest, InsideContainsUsingMap) { |
|
|
|
std::map<int, char> container; |
|
|
|
std::map<int, char> container; |
|
|
|
container.insert(std::make_pair(1, 'a')); |
|
|
|
container.insert(make_pair(1, 'a')); |
|
|
|
container.insert(std::make_pair(2, 'b')); |
|
|
|
container.insert(make_pair(2, 'b')); |
|
|
|
container.insert(std::make_pair(4, 'c')); |
|
|
|
container.insert(make_pair(4, 'c')); |
|
|
|
EXPECT_THAT(container, Contains(Pair(1, 'a'))); |
|
|
|
EXPECT_THAT(container, Contains(Pair(1, 'a'))); |
|
|
|
EXPECT_THAT(container, Contains(Pair(1, _))); |
|
|
|
EXPECT_THAT(container, Contains(Pair(1, _))); |
|
|
|
EXPECT_THAT(container, Contains(Pair(_, 'a'))); |
|
|
|
EXPECT_THAT(container, Contains(Pair(_, 'a'))); |
|
|
@ -1397,7 +1418,7 @@ TEST(StdWideStrNeTest, MatchesUnequalString) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(StdWideStrNeTest, CanDescribeSelf) { |
|
|
|
TEST(StdWideStrNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const wchar_t*> m = StrNe(L"Hi"); |
|
|
|
Matcher<const wchar_t*> m = StrNe(L"Hi"); |
|
|
|
EXPECT_EQ("is not equal to L\"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to L\"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
|
TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
@ -1456,7 +1477,7 @@ TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(StdWideStrCaseNeTest, CanDescribeSelf) { |
|
|
|
TEST(StdWideStrCaseNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const wchar_t*> m = StrCaseNe(L"Hi"); |
|
|
|
Matcher<const wchar_t*> m = StrCaseNe(L"Hi"); |
|
|
|
EXPECT_EQ("is not equal to (ignoring case) L\"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to (ignoring case) L\"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that HasSubstr() works for matching wstring-typed values.
|
|
|
|
// Tests that HasSubstr() works for matching wstring-typed values.
|
|
|
@ -1588,7 +1609,7 @@ TEST(GlobalWideStrNeTest, MatchesUnequalString) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalWideStrNeTest, CanDescribeSelf) { |
|
|
|
TEST(GlobalWideStrNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const wchar_t*> m = StrNe(L"Hi"); |
|
|
|
Matcher<const wchar_t*> m = StrNe(L"Hi"); |
|
|
|
EXPECT_EQ("is not equal to L\"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to L\"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
|
TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { |
|
|
@ -1647,7 +1668,7 @@ TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalWideStrCaseNeTest, CanDescribeSelf) { |
|
|
|
TEST(GlobalWideStrCaseNeTest, CanDescribeSelf) { |
|
|
|
Matcher<const wchar_t*> m = StrCaseNe(L"Hi"); |
|
|
|
Matcher<const wchar_t*> m = StrCaseNe(L"Hi"); |
|
|
|
EXPECT_EQ("is not equal to (ignoring case) L\"Hi\"", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to (ignoring case) L\"Hi\"", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that HasSubstr() works for matching wstring-typed values.
|
|
|
|
// Tests that HasSubstr() works for matching wstring-typed values.
|
|
|
@ -1827,7 +1848,7 @@ TEST(NotTest, NegatesMatcher) { |
|
|
|
// Tests that Not(m) describes itself properly.
|
|
|
|
// Tests that Not(m) describes itself properly.
|
|
|
|
TEST(NotTest, CanDescribeSelf) { |
|
|
|
TEST(NotTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m = Not(Eq(5)); |
|
|
|
Matcher<int> m = Not(Eq(5)); |
|
|
|
EXPECT_EQ("is not equal to 5", Describe(m)); |
|
|
|
EXPECT_EQ("isn't equal to 5", Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that monomorphic matchers are safely cast by the Not matcher.
|
|
|
|
// Tests that monomorphic matchers are safely cast by the Not matcher.
|
|
|
@ -1873,31 +1894,62 @@ TEST(AllOfTest, MatchesWhenAllMatch) { |
|
|
|
TEST(AllOfTest, CanDescribeSelf) { |
|
|
|
TEST(AllOfTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m; |
|
|
|
Matcher<int> m; |
|
|
|
m = AllOf(Le(2), Ge(1)); |
|
|
|
m = AllOf(Le(2), Ge(1)); |
|
|
|
EXPECT_EQ("(is less than or equal to 2) and " |
|
|
|
EXPECT_EQ("(is <= 2) and (is >= 1)", Describe(m)); |
|
|
|
"(is greater than or equal to 1)", |
|
|
|
|
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2)); |
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2)); |
|
|
|
EXPECT_EQ("(is greater than 0) and " |
|
|
|
EXPECT_EQ("(is > 0) and " |
|
|
|
"((is not equal to 1) and " |
|
|
|
"((isn't equal to 1) and " |
|
|
|
"(is not equal to 2))", |
|
|
|
"(isn't equal to 2))", |
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); |
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); |
|
|
|
EXPECT_EQ("(is greater than 0) and " |
|
|
|
EXPECT_EQ("(is > 0) and " |
|
|
|
"((is not equal to 1) and " |
|
|
|
"((isn't equal to 1) and " |
|
|
|
"((is not equal to 2) and " |
|
|
|
"((isn't equal to 2) and " |
|
|
|
"(is not equal to 3)))", |
|
|
|
"(isn't equal to 3)))", |
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); |
|
|
|
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); |
|
|
|
EXPECT_EQ("(is greater than or equal to 0) and " |
|
|
|
EXPECT_EQ("(is >= 0) and " |
|
|
|
"((is less than 10) and " |
|
|
|
"((is < 10) and " |
|
|
|
"((is not equal to 3) and " |
|
|
|
"((isn't equal to 3) and " |
|
|
|
"((is not equal to 5) and " |
|
|
|
"((isn't equal to 5) and " |
|
|
|
"(is not equal to 7))))", Describe(m)); |
|
|
|
"(isn't equal to 7))))", |
|
|
|
|
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests that AllOf(m1, ..., mn) describes its negation properly.
|
|
|
|
|
|
|
|
TEST(AllOfTest, CanDescribeNegation) { |
|
|
|
|
|
|
|
Matcher<int> m; |
|
|
|
|
|
|
|
m = AllOf(Le(2), Ge(1)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't <= 2) or " |
|
|
|
|
|
|
|
"(isn't >= 1)", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't > 0) or " |
|
|
|
|
|
|
|
"((is equal to 1) or " |
|
|
|
|
|
|
|
"(is equal to 2))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't > 0) or " |
|
|
|
|
|
|
|
"((is equal to 1) or " |
|
|
|
|
|
|
|
"((is equal to 2) or " |
|
|
|
|
|
|
|
"(is equal to 3)))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't >= 0) or " |
|
|
|
|
|
|
|
"((isn't < 10) or " |
|
|
|
|
|
|
|
"((is equal to 3) or " |
|
|
|
|
|
|
|
"((is equal to 5) or " |
|
|
|
|
|
|
|
"(is equal to 7))))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that monomorphic matchers are safely cast by the AllOf matcher.
|
|
|
|
// Tests that monomorphic matchers are safely cast by the AllOf matcher.
|
|
|
@ -1915,6 +1967,49 @@ TEST(AllOfTest, AllOfMatcherSafelyCastsMonomorphicMatchers) { |
|
|
|
Matcher<int&> m5 = AllOf(greater_than_5, less_than_10, less_than_10); |
|
|
|
Matcher<int&> m5 = AllOf(greater_than_5, less_than_10, less_than_10); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(AllOfTest, ExplainsResult) { |
|
|
|
|
|
|
|
Matcher<int> m; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. Both matchers need to explain. The second
|
|
|
|
|
|
|
|
// matcher doesn't give an explanation, so only the first matcher's
|
|
|
|
|
|
|
|
// explanation is printed.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), Lt(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 15 more than 10", Explain(m, 25)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. Both matchers need to explain.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 20 more than 10, and which is 10 more than 20", |
|
|
|
|
|
|
|
Explain(m, 30)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. All matchers need to explain. The second
|
|
|
|
|
|
|
|
// matcher doesn't given an explanation.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), Lt(30), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 15 more than 10, and which is 5 more than 20", |
|
|
|
|
|
|
|
Explain(m, 25)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. All matchers need to explain.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), GreaterThan(20), GreaterThan(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 30 more than 10, and which is 20 more than 20, " |
|
|
|
|
|
|
|
"and which is 10 more than 30", |
|
|
|
|
|
|
|
Explain(m, 40)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. The first matcher, which failed, needs to
|
|
|
|
|
|
|
|
// explain.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 10", Explain(m, 5)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. The second matcher, which failed, needs to
|
|
|
|
|
|
|
|
// explain. Since it doesn't given an explanation, nothing is
|
|
|
|
|
|
|
|
// printed.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), Lt(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("", Explain(m, 40)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. The second matcher, which failed, needs to
|
|
|
|
|
|
|
|
// explain.
|
|
|
|
|
|
|
|
m = AllOf(GreaterThan(10), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 20", Explain(m, 15)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
|
|
|
|
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
|
|
|
|
// least one of the given matchers.
|
|
|
|
// least one of the given matchers.
|
|
|
|
TEST(AnyOfTest, MatchesWhenAnyMatches) { |
|
|
|
TEST(AnyOfTest, MatchesWhenAnyMatches) { |
|
|
@ -1948,31 +2043,58 @@ TEST(AnyOfTest, MatchesWhenAnyMatches) { |
|
|
|
TEST(AnyOfTest, CanDescribeSelf) { |
|
|
|
TEST(AnyOfTest, CanDescribeSelf) { |
|
|
|
Matcher<int> m; |
|
|
|
Matcher<int> m; |
|
|
|
m = AnyOf(Le(1), Ge(3)); |
|
|
|
m = AnyOf(Le(1), Ge(3)); |
|
|
|
EXPECT_EQ("(is less than or equal to 1) or " |
|
|
|
EXPECT_EQ("(is <= 1) or (is >= 3)", |
|
|
|
"(is greater than or equal to 3)", |
|
|
|
|
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2)); |
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2)); |
|
|
|
EXPECT_EQ("(is less than 0) or " |
|
|
|
EXPECT_EQ("(is < 0) or " |
|
|
|
"((is equal to 1) or (is equal to 2))", |
|
|
|
"((is equal to 1) or (is equal to 2))", |
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3)); |
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3)); |
|
|
|
EXPECT_EQ("(is less than 0) or " |
|
|
|
EXPECT_EQ("(is < 0) or " |
|
|
|
"((is equal to 1) or " |
|
|
|
"((is equal to 1) or " |
|
|
|
"((is equal to 2) or " |
|
|
|
"((is equal to 2) or " |
|
|
|
"(is equal to 3)))", |
|
|
|
"(is equal to 3)))", |
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Le(0), Gt(10), 3, 5, 7); |
|
|
|
m = AnyOf(Le(0), Gt(10), 3, 5, 7); |
|
|
|
EXPECT_EQ("(is less than or equal to 0) or " |
|
|
|
EXPECT_EQ("(is <= 0) or " |
|
|
|
"((is greater than 10) or " |
|
|
|
"((is > 10) or " |
|
|
|
"((is equal to 3) or " |
|
|
|
"((is equal to 3) or " |
|
|
|
"((is equal to 5) or " |
|
|
|
"((is equal to 5) or " |
|
|
|
"(is equal to 7))))", |
|
|
|
"(is equal to 7))))", |
|
|
|
Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests that AnyOf(m1, ..., mn) describes its negation properly.
|
|
|
|
|
|
|
|
TEST(AnyOfTest, CanDescribeNegation) { |
|
|
|
|
|
|
|
Matcher<int> m; |
|
|
|
|
|
|
|
m = AnyOf(Le(1), Ge(3)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't <= 1) and (isn't >= 3)", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't < 0) and " |
|
|
|
|
|
|
|
"((isn't equal to 1) and (isn't equal to 2))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3)); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't < 0) and " |
|
|
|
|
|
|
|
"((isn't equal to 1) and " |
|
|
|
|
|
|
|
"((isn't equal to 2) and " |
|
|
|
|
|
|
|
"(isn't equal to 3)))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = AnyOf(Le(0), Gt(10), 3, 5, 7); |
|
|
|
|
|
|
|
EXPECT_EQ("(isn't <= 0) and " |
|
|
|
|
|
|
|
"((isn't > 10) and " |
|
|
|
|
|
|
|
"((isn't equal to 3) and " |
|
|
|
|
|
|
|
"((isn't equal to 5) and " |
|
|
|
|
|
|
|
"(isn't equal to 7))))", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that monomorphic matchers are safely cast by the AnyOf matcher.
|
|
|
|
// Tests that monomorphic matchers are safely cast by the AnyOf matcher.
|
|
|
|
TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) { |
|
|
|
TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) { |
|
|
|
// greater_than_5 and less_than_10 are monomorphic matchers.
|
|
|
|
// greater_than_5 and less_than_10 are monomorphic matchers.
|
|
|
@ -1988,6 +2110,49 @@ TEST(AnyOfTest, AnyOfMatcherSafelyCastsMonomorphicMatchers) { |
|
|
|
Matcher<int&> m5 = AnyOf(greater_than_5, less_than_10, less_than_10); |
|
|
|
Matcher<int&> m5 = AnyOf(greater_than_5, less_than_10, less_than_10); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(AnyOfTest, ExplainsResult) { |
|
|
|
|
|
|
|
Matcher<int> m; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. Both matchers need to explain. The second
|
|
|
|
|
|
|
|
// matcher doesn't give an explanation, so only the first matcher's
|
|
|
|
|
|
|
|
// explanation is printed.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), Lt(0)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 10", Explain(m, 5)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. Both matchers need to explain.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 10, and which is 15 less than 20", |
|
|
|
|
|
|
|
Explain(m, 5)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. All matchers need to explain. The second
|
|
|
|
|
|
|
|
// matcher doesn't given an explanation.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), Gt(20), GreaterThan(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 10, and which is 25 less than 30", |
|
|
|
|
|
|
|
Explain(m, 5)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Failed match. All matchers need to explain.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), GreaterThan(20), GreaterThan(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 less than 10, and which is 15 less than 20, " |
|
|
|
|
|
|
|
"and which is 25 less than 30", |
|
|
|
|
|
|
|
Explain(m, 5)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. The first matcher, which succeeded, needs to
|
|
|
|
|
|
|
|
// explain.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 more than 10", Explain(m, 15)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. The second matcher, which succeeded, needs to
|
|
|
|
|
|
|
|
// explain. Since it doesn't given an explanation, nothing is
|
|
|
|
|
|
|
|
// printed.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(10), Lt(30)); |
|
|
|
|
|
|
|
EXPECT_EQ("", Explain(m, 0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Successful match. The second matcher, which succeeded, needs to
|
|
|
|
|
|
|
|
// explain.
|
|
|
|
|
|
|
|
m = AnyOf(GreaterThan(30), GreaterThan(20)); |
|
|
|
|
|
|
|
EXPECT_EQ("which is 5 more than 20", Explain(m, 25)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// The following predicate function and predicate functor are for
|
|
|
|
// The following predicate function and predicate functor are for
|
|
|
|
// testing the Truly(predicate) matcher.
|
|
|
|
// testing the Truly(predicate) matcher.
|
|
|
|
|
|
|
|
|
|
|
@ -2181,14 +2346,13 @@ TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) { |
|
|
|
// resolved.
|
|
|
|
// resolved.
|
|
|
|
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Gt(10)), |
|
|
|
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Gt(10)), |
|
|
|
"Value of: n\n" |
|
|
|
"Value of: n\n" |
|
|
|
"Expected: is greater than 10\n" |
|
|
|
"Expected: is > 10\n" |
|
|
|
" Actual: 5"); |
|
|
|
" Actual: 5"); |
|
|
|
n = 0; |
|
|
|
n = 0; |
|
|
|
EXPECT_NONFATAL_FAILURE( |
|
|
|
EXPECT_NONFATAL_FAILURE( |
|
|
|
EXPECT_THAT(n, ::testing::AllOf(::testing::Le(7), ::testing::Ge(5))), |
|
|
|
EXPECT_THAT(n, ::testing::AllOf(::testing::Le(7), ::testing::Ge(5))), |
|
|
|
"Value of: n\n" |
|
|
|
"Value of: n\n" |
|
|
|
"Expected: (is less than or equal to 7) and " |
|
|
|
"Expected: (is <= 7) and (is >= 5)\n" |
|
|
|
"(is greater than or equal to 5)\n" |
|
|
|
|
|
|
|
" Actual: 0"); |
|
|
|
" Actual: 0"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2205,7 +2369,7 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) { |
|
|
|
"Expected: does not reference the variable @"); |
|
|
|
"Expected: does not reference the variable @"); |
|
|
|
// Tests the "Actual" part.
|
|
|
|
// Tests the "Actual" part.
|
|
|
|
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))), |
|
|
|
EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))), |
|
|
|
"Actual: 0 (is located @"); |
|
|
|
"Actual: 0, which is located @"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if !GTEST_OS_SYMBIAN |
|
|
|
#if !GTEST_OS_SYMBIAN |
|
|
@ -2232,7 +2396,7 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) { |
|
|
|
Matcher<int> is_greater_than_5 = Gt(5); |
|
|
|
Matcher<int> is_greater_than_5 = Gt(5); |
|
|
|
EXPECT_NONFATAL_FAILURE(EXPECT_THAT(5, is_greater_than_5), |
|
|
|
EXPECT_NONFATAL_FAILURE(EXPECT_THAT(5, is_greater_than_5), |
|
|
|
"Value of: 5\n" |
|
|
|
"Value of: 5\n" |
|
|
|
"Expected: is greater than 5\n" |
|
|
|
"Expected: is > 5\n" |
|
|
|
" Actual: 5"); |
|
|
|
" Actual: 5"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif // !GTEST_OS_SYMBIAN
|
|
|
|
#endif // !GTEST_OS_SYMBIAN
|
|
|
@ -2407,11 +2571,11 @@ TEST_F(FloatTest, NanSensitiveFloatEqCanMatchNaN) { |
|
|
|
TEST_F(FloatTest, FloatEqCanDescribeSelf) { |
|
|
|
TEST_F(FloatTest, FloatEqCanDescribeSelf) { |
|
|
|
Matcher<float> m1 = FloatEq(2.0f); |
|
|
|
Matcher<float> m1 = FloatEq(2.0f); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is not approximately 2", DescribeNegation(m1)); |
|
|
|
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<float> m2 = FloatEq(0.5f); |
|
|
|
Matcher<float> m2 = FloatEq(0.5f); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2)); |
|
|
|
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<float> m3 = FloatEq(nan1_); |
|
|
|
Matcher<float> m3 = FloatEq(nan1_); |
|
|
|
EXPECT_EQ("never matches", Describe(m3)); |
|
|
|
EXPECT_EQ("never matches", Describe(m3)); |
|
|
@ -2421,15 +2585,15 @@ TEST_F(FloatTest, FloatEqCanDescribeSelf) { |
|
|
|
TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) { |
|
|
|
TEST_F(FloatTest, NanSensitiveFloatEqCanDescribeSelf) { |
|
|
|
Matcher<float> m1 = NanSensitiveFloatEq(2.0f); |
|
|
|
Matcher<float> m1 = NanSensitiveFloatEq(2.0f); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is not approximately 2", DescribeNegation(m1)); |
|
|
|
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<float> m2 = NanSensitiveFloatEq(0.5f); |
|
|
|
Matcher<float> m2 = NanSensitiveFloatEq(0.5f); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2)); |
|
|
|
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<float> m3 = NanSensitiveFloatEq(nan1_); |
|
|
|
Matcher<float> m3 = NanSensitiveFloatEq(nan1_); |
|
|
|
EXPECT_EQ("is NaN", Describe(m3)); |
|
|
|
EXPECT_EQ("is NaN", Describe(m3)); |
|
|
|
EXPECT_EQ("is not NaN", DescribeNegation(m3)); |
|
|
|
EXPECT_EQ("isn't NaN", DescribeNegation(m3)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Instantiate FloatingPointTest for testing doubles.
|
|
|
|
// Instantiate FloatingPointTest for testing doubles.
|
|
|
@ -2462,11 +2626,11 @@ TEST_F(DoubleTest, NanSensitiveDoubleEqCanMatchNaN) { |
|
|
|
TEST_F(DoubleTest, DoubleEqCanDescribeSelf) { |
|
|
|
TEST_F(DoubleTest, DoubleEqCanDescribeSelf) { |
|
|
|
Matcher<double> m1 = DoubleEq(2.0); |
|
|
|
Matcher<double> m1 = DoubleEq(2.0); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is not approximately 2", DescribeNegation(m1)); |
|
|
|
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<double> m2 = DoubleEq(0.5); |
|
|
|
Matcher<double> m2 = DoubleEq(0.5); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2)); |
|
|
|
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<double> m3 = DoubleEq(nan1_); |
|
|
|
Matcher<double> m3 = DoubleEq(nan1_); |
|
|
|
EXPECT_EQ("never matches", Describe(m3)); |
|
|
|
EXPECT_EQ("never matches", Describe(m3)); |
|
|
@ -2476,15 +2640,15 @@ TEST_F(DoubleTest, DoubleEqCanDescribeSelf) { |
|
|
|
TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) { |
|
|
|
TEST_F(DoubleTest, NanSensitiveDoubleEqCanDescribeSelf) { |
|
|
|
Matcher<double> m1 = NanSensitiveDoubleEq(2.0); |
|
|
|
Matcher<double> m1 = NanSensitiveDoubleEq(2.0); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is approximately 2", Describe(m1)); |
|
|
|
EXPECT_EQ("is not approximately 2", DescribeNegation(m1)); |
|
|
|
EXPECT_EQ("isn't approximately 2", DescribeNegation(m1)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<double> m2 = NanSensitiveDoubleEq(0.5); |
|
|
|
Matcher<double> m2 = NanSensitiveDoubleEq(0.5); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is approximately 0.5", Describe(m2)); |
|
|
|
EXPECT_EQ("is not approximately 0.5", DescribeNegation(m2)); |
|
|
|
EXPECT_EQ("isn't approximately 0.5", DescribeNegation(m2)); |
|
|
|
|
|
|
|
|
|
|
|
Matcher<double> m3 = NanSensitiveDoubleEq(nan1_); |
|
|
|
Matcher<double> m3 = NanSensitiveDoubleEq(nan1_); |
|
|
|
EXPECT_EQ("is NaN", Describe(m3)); |
|
|
|
EXPECT_EQ("is NaN", Describe(m3)); |
|
|
|
EXPECT_EQ("is not NaN", DescribeNegation(m3)); |
|
|
|
EXPECT_EQ("isn't NaN", DescribeNegation(m3)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(PointeeTest, RawPointer) { |
|
|
|
TEST(PointeeTest, RawPointer) { |
|
|
@ -2547,8 +2711,8 @@ TEST(PointeeTest, MatchesAgainstAValue) { |
|
|
|
|
|
|
|
|
|
|
|
TEST(PointeeTest, CanDescribeSelf) { |
|
|
|
TEST(PointeeTest, CanDescribeSelf) { |
|
|
|
const Matcher<int*> m = Pointee(Gt(3)); |
|
|
|
const Matcher<int*> m = Pointee(Gt(3)); |
|
|
|
EXPECT_EQ("points to a value that is greater than 3", Describe(m)); |
|
|
|
EXPECT_EQ("points to a value that is > 3", Describe(m)); |
|
|
|
EXPECT_EQ("does not point to a value that is greater than 3", |
|
|
|
EXPECT_EQ("does not point to a value that is > 3", |
|
|
|
DescribeNegation(m)); |
|
|
|
DescribeNegation(m)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2693,10 +2857,8 @@ TEST(FieldTest, WorksForCompatibleMatcherType) { |
|
|
|
TEST(FieldTest, CanDescribeSelf) { |
|
|
|
TEST(FieldTest, CanDescribeSelf) { |
|
|
|
Matcher<const AStruct&> m = Field(&AStruct::x, Ge(0)); |
|
|
|
Matcher<const AStruct&> m = Field(&AStruct::x, Ge(0)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ("is an object whose given field is greater than or equal to 0", |
|
|
|
EXPECT_EQ("is an object whose given field is >= 0", Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); |
|
|
|
EXPECT_EQ("is an object whose given field is not greater than or equal to 0", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Field() can explain the match result.
|
|
|
|
// Tests that Field() can explain the match result.
|
|
|
@ -2764,10 +2926,8 @@ TEST(FieldForPointerTest, WorksForArgumentOfSubType) { |
|
|
|
TEST(FieldForPointerTest, CanDescribeSelf) { |
|
|
|
TEST(FieldForPointerTest, CanDescribeSelf) { |
|
|
|
Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0)); |
|
|
|
Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ("is an object whose given field is greater than or equal to 0", |
|
|
|
EXPECT_EQ("is an object whose given field is >= 0", Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); |
|
|
|
EXPECT_EQ("is an object whose given field is not greater than or equal to 0", |
|
|
|
|
|
|
|
DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Field() can explain the result of matching a pointer.
|
|
|
|
// Tests that Field() can explain the result of matching a pointer.
|
|
|
@ -2900,10 +3060,9 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) { |
|
|
|
TEST(PropertyTest, CanDescribeSelf) { |
|
|
|
TEST(PropertyTest, CanDescribeSelf) { |
|
|
|
Matcher<const AClass&> m = Property(&AClass::n, Ge(0)); |
|
|
|
Matcher<const AClass&> m = Property(&AClass::n, Ge(0)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ("is an object whose given property is greater than or equal to 0", |
|
|
|
EXPECT_EQ("is an object whose given property is >= 0", Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
EXPECT_EQ("is an object whose given property isn't >= 0", |
|
|
|
EXPECT_EQ("is an object whose given property " |
|
|
|
DescribeNegation(m)); |
|
|
|
"is not greater than or equal to 0", DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Property() can explain the match result.
|
|
|
|
// Tests that Property() can explain the match result.
|
|
|
@ -2980,10 +3139,9 @@ TEST(PropertyForPointerTest, WorksForArgumentOfSubType) { |
|
|
|
TEST(PropertyForPointerTest, CanDescribeSelf) { |
|
|
|
TEST(PropertyForPointerTest, CanDescribeSelf) { |
|
|
|
Matcher<const AClass*> m = Property(&AClass::n, Ge(0)); |
|
|
|
Matcher<const AClass*> m = Property(&AClass::n, Ge(0)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ("is an object whose given property is greater than or equal to 0", |
|
|
|
EXPECT_EQ("is an object whose given property is >= 0", Describe(m)); |
|
|
|
Describe(m)); |
|
|
|
EXPECT_EQ("is an object whose given property isn't >= 0", |
|
|
|
EXPECT_EQ("is an object whose given property " |
|
|
|
DescribeNegation(m)); |
|
|
|
"is not greater than or equal to 0", DescribeNegation(m)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that Property() can explain the result of matching a pointer.
|
|
|
|
// Tests that Property() can explain the result of matching a pointer.
|
|
|
@ -3021,7 +3179,7 @@ TEST(ResultOfTest, CanDescribeItself) { |
|
|
|
EXPECT_EQ("is mapped by the given callable to a value that " |
|
|
|
EXPECT_EQ("is mapped by the given callable to a value that " |
|
|
|
"is equal to \"foo\"", Describe(matcher)); |
|
|
|
"is equal to \"foo\"", Describe(matcher)); |
|
|
|
EXPECT_EQ("is mapped by the given callable to a value that " |
|
|
|
EXPECT_EQ("is mapped by the given callable to a value that " |
|
|
|
"is not equal to \"foo\"", DescribeNegation(matcher)); |
|
|
|
"isn't equal to \"foo\"", DescribeNegation(matcher)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that ResultOf() can explain the match result.
|
|
|
|
// Tests that ResultOf() can explain the match result.
|
|
|
@ -3173,7 +3331,7 @@ class DivisibleByImpl { |
|
|
|
// For testing using ExplainMatchResultTo() with polymorphic matchers.
|
|
|
|
// For testing using ExplainMatchResultTo() with polymorphic matchers.
|
|
|
|
template <typename T> |
|
|
|
template <typename T> |
|
|
|
bool MatchAndExplain(const T& n, MatchResultListener* listener) const { |
|
|
|
bool MatchAndExplain(const T& n, MatchResultListener* listener) const { |
|
|
|
*listener << "is " << (n % divider_) << " modulo " |
|
|
|
*listener << "which is " << (n % divider_) << " modulo " |
|
|
|
<< divider_; |
|
|
|
<< divider_; |
|
|
|
return (n % divider_) == 0; |
|
|
|
return (n % divider_) == 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -3201,28 +3359,28 @@ PolymorphicMatcher<DivisibleByImpl> DivisibleBy(int n) { |
|
|
|
// asked to explain why.
|
|
|
|
// asked to explain why.
|
|
|
|
TEST(ExplainMatchResultTest, AllOf_False_False) { |
|
|
|
TEST(ExplainMatchResultTest, AllOf_False_False) { |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3)); |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3)); |
|
|
|
EXPECT_EQ("is 1 modulo 4", Explain(m, 5)); |
|
|
|
EXPECT_EQ("which is 1 modulo 4", Explain(m, 5)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that when AllOf() fails, only the first failing matcher is
|
|
|
|
// Tests that when AllOf() fails, only the first failing matcher is
|
|
|
|
// asked to explain why.
|
|
|
|
// asked to explain why.
|
|
|
|
TEST(ExplainMatchResultTest, AllOf_False_True) { |
|
|
|
TEST(ExplainMatchResultTest, AllOf_False_True) { |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3)); |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(4), DivisibleBy(3)); |
|
|
|
EXPECT_EQ("is 2 modulo 4", Explain(m, 6)); |
|
|
|
EXPECT_EQ("which is 2 modulo 4", Explain(m, 6)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that when AllOf() fails, only the first failing matcher is
|
|
|
|
// Tests that when AllOf() fails, only the first failing matcher is
|
|
|
|
// asked to explain why.
|
|
|
|
// asked to explain why.
|
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_False) { |
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_False) { |
|
|
|
const Matcher<int> m = AllOf(Ge(1), DivisibleBy(3)); |
|
|
|
const Matcher<int> m = AllOf(Ge(1), DivisibleBy(3)); |
|
|
|
EXPECT_EQ("is 2 modulo 3", Explain(m, 5)); |
|
|
|
EXPECT_EQ("which is 2 modulo 3", Explain(m, 5)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that when AllOf() succeeds, all matchers are asked to explain
|
|
|
|
// Tests that when AllOf() succeeds, all matchers are asked to explain
|
|
|
|
// why.
|
|
|
|
// why.
|
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_True) { |
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_True) { |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(2), DivisibleBy(3)); |
|
|
|
const Matcher<int> m = AllOf(DivisibleBy(2), DivisibleBy(3)); |
|
|
|
EXPECT_EQ("is 0 modulo 2; is 0 modulo 3", Explain(m, 6)); |
|
|
|
EXPECT_EQ("which is 0 modulo 2, and which is 0 modulo 3", Explain(m, 6)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_True_2) { |
|
|
|
TEST(ExplainMatchResultTest, AllOf_True_True_2) { |
|
|
@ -3309,7 +3467,8 @@ TYPED_TEST(ContainerEqTest, ValueMissing) { |
|
|
|
TypeParam test_set(test_vals, test_vals + 4); |
|
|
|
TypeParam test_set(test_vals, test_vals + 4); |
|
|
|
const Matcher<TypeParam> m = ContainerEq(my_set); |
|
|
|
const Matcher<TypeParam> m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Not in actual: 3", Explain(m, test_set)); |
|
|
|
EXPECT_EQ("which doesn't have these expected elements: 3", |
|
|
|
|
|
|
|
Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that added values are reported.
|
|
|
|
// Tests that added values are reported.
|
|
|
@ -3320,7 +3479,7 @@ TYPED_TEST(ContainerEqTest, ValueAdded) { |
|
|
|
TypeParam test_set(test_vals, test_vals + 6); |
|
|
|
TypeParam test_set(test_vals, test_vals + 6); |
|
|
|
const Matcher<const TypeParam&> m = ContainerEq(my_set); |
|
|
|
const Matcher<const TypeParam&> m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Only in actual: 46", Explain(m, test_set)); |
|
|
|
EXPECT_EQ("which has these unexpected elements: 46", Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that added and missing values are reported together.
|
|
|
|
// Tests that added and missing values are reported together.
|
|
|
@ -3331,7 +3490,9 @@ TYPED_TEST(ContainerEqTest, ValueAddedAndRemoved) { |
|
|
|
TypeParam test_set(test_vals, test_vals + 5); |
|
|
|
TypeParam test_set(test_vals, test_vals + 5); |
|
|
|
const Matcher<TypeParam> m = ContainerEq(my_set); |
|
|
|
const Matcher<TypeParam> m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Only in actual: 46; not in actual: 5", Explain(m, test_set)); |
|
|
|
EXPECT_EQ("which has these unexpected elements: 46,\n" |
|
|
|
|
|
|
|
"and doesn't have these expected elements: 5", |
|
|
|
|
|
|
|
Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests duplicated value -- expect no explanation.
|
|
|
|
// Tests duplicated value -- expect no explanation.
|
|
|
@ -3356,7 +3517,8 @@ TEST(ContainerEqExtraTest, MultipleValuesMissing) { |
|
|
|
std::vector<int> test_set(test_vals, test_vals + 3); |
|
|
|
std::vector<int> test_set(test_vals, test_vals + 3); |
|
|
|
const Matcher<std::vector<int> > m = ContainerEq(my_set); |
|
|
|
const Matcher<std::vector<int> > m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Not in actual: 3, 8", Explain(m, test_set)); |
|
|
|
EXPECT_EQ("which doesn't have these expected elements: 3, 8", |
|
|
|
|
|
|
|
Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that added values are reported.
|
|
|
|
// Tests that added values are reported.
|
|
|
@ -3368,7 +3530,8 @@ TEST(ContainerEqExtraTest, MultipleValuesAdded) { |
|
|
|
std::list<size_t> test_set(test_vals, test_vals + 7); |
|
|
|
std::list<size_t> test_set(test_vals, test_vals + 7); |
|
|
|
const Matcher<const std::list<size_t>&> m = ContainerEq(my_set); |
|
|
|
const Matcher<const std::list<size_t>&> m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Only in actual: 92, 46", Explain(m, test_set)); |
|
|
|
EXPECT_EQ("which has these unexpected elements: 92, 46", |
|
|
|
|
|
|
|
Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests that added and missing values are reported together.
|
|
|
|
// Tests that added and missing values are reported together.
|
|
|
@ -3379,7 +3542,8 @@ TEST(ContainerEqExtraTest, MultipleValuesAddedAndRemoved) { |
|
|
|
std::list<size_t> test_set(test_vals, test_vals + 5); |
|
|
|
std::list<size_t> test_set(test_vals, test_vals + 5); |
|
|
|
const Matcher<const std::list<size_t> > m = ContainerEq(my_set); |
|
|
|
const Matcher<const std::list<size_t> > m = ContainerEq(my_set); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_FALSE(m.Matches(test_set)); |
|
|
|
EXPECT_EQ("Only in actual: 92, 46; not in actual: 5, 8", |
|
|
|
EXPECT_EQ("which has these unexpected elements: 92, 46,\n" |
|
|
|
|
|
|
|
"and doesn't have these expected elements: 5, 8", |
|
|
|
Explain(m, test_set)); |
|
|
|
Explain(m, test_set)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3412,7 +3576,8 @@ TEST(ContainerEqExtraTest, WorksForMaps) { |
|
|
|
EXPECT_TRUE(m.Matches(my_map)); |
|
|
|
EXPECT_TRUE(m.Matches(my_map)); |
|
|
|
EXPECT_FALSE(m.Matches(test_map)); |
|
|
|
EXPECT_FALSE(m.Matches(test_map)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ("Only in actual: (0, \"aa\"); not in actual: (0, \"a\")", |
|
|
|
EXPECT_EQ("which has these unexpected elements: (0, \"aa\"),\n" |
|
|
|
|
|
|
|
"and doesn't have these expected elements: (0, \"a\")", |
|
|
|
Explain(m, test_map)); |
|
|
|
Explain(m, test_map)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3795,5 +3960,29 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) { |
|
|
|
EXPECT_EQ(42, impl.divider()); |
|
|
|
EXPECT_EQ(42, impl.divider()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MatcherTupleTest, ExplainsMatchFailure) { |
|
|
|
|
|
|
|
stringstream ss1; |
|
|
|
|
|
|
|
ExplainMatchFailureTupleTo(make_tuple(Matcher<char>(Eq('a')), GreaterThan(5)), |
|
|
|
|
|
|
|
make_tuple('a', 10), &ss1); |
|
|
|
|
|
|
|
EXPECT_EQ("", ss1.str()); // Successful match.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringstream ss2; |
|
|
|
|
|
|
|
ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher<char>(Eq('a'))), |
|
|
|
|
|
|
|
make_tuple(2, 'b'), &ss2); |
|
|
|
|
|
|
|
EXPECT_EQ(" Expected arg #0: is > 5\n" |
|
|
|
|
|
|
|
" Actual: 2, which is 3 less than 5\n" |
|
|
|
|
|
|
|
" Expected arg #1: is equal to 'a' (97)\n" |
|
|
|
|
|
|
|
" Actual: 'b' (98)\n", |
|
|
|
|
|
|
|
ss2.str()); // Failed match where both arguments need explanation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringstream ss3; |
|
|
|
|
|
|
|
ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher<char>(Eq('a'))), |
|
|
|
|
|
|
|
make_tuple(2, 'a'), &ss3); |
|
|
|
|
|
|
|
EXPECT_EQ(" Expected arg #0: is > 5\n" |
|
|
|
|
|
|
|
" Actual: 2, which is 3 less than 5\n", |
|
|
|
|
|
|
|
ss3.str()); // Failed match where only one argument needs
|
|
|
|
|
|
|
|
// explanation.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace gmock_matchers_test
|
|
|
|
} // namespace gmock_matchers_test
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|