Lines Matching refs:matcher

61 // To implement a matcher Foo for type T, define:
74 // used by a matcher to explain why a value matches or doesn't match.
101 // the match result. A matcher's MatchAndExplain() method can use
116 // matcher.
121 // Describes this matcher to an ostream. The function should print
123 // matcher should have. The subject of the verb phrase is the value
125 // matcher prints "is greater than 7".
128 // Describes the negation of this matcher to an ostream. For
129 // example, if the description of this matcher is "is greater than
132 // MatcherInterface, but it is highly advised so that your matcher
141 // The implementation of a matcher.
145 // Returns true iff the matcher matches x; also explains the match
149 // MatchAndExplain() method of the Pointee(...) matcher should
155 // print-out of x and the matcher's description. Whether the match
158 // when the match succeeds (e.g. when the matcher is used inside
161 // For example, a "has at least 10 elements" matcher should explain
164 // "is empty" matcher probably only needs to explain what the actual
168 // You should override this method when defining a new matcher.
171 // that 'listener' is not NULL. This helps to simplify a matcher's
254 // Returns true iff the matcher matches x; also explains the match
260 // Returns true iff this matcher matches x.
266 // Describes this matcher to an ostream.
269 // Describes the negation of this matcher to an ostream.
274 // Explains why x matches, or doesn't match, the matcher.
280 // Returns the describer for this matcher object; retains ownership
282 // this matcher object is alive.
290 // Constructs a matcher from its implementation.
321 // Constructs a null matcher. Needed for storing Matcher objects in STL
322 // containers. A default-constructed matcher is not yet initialized. You
326 // Constructs a matcher from its implementation.
337 // matcher is expected.
375 // matcher is expected.
418 // polymorphic matcher (i.e. a matcher that can match values of more
421 // To define a polymorphic matcher, a user should provide an Impl
434 // Returns a mutable reference to the underlying matcher
438 // Returns an immutable reference to the underlying matcher
476 // Creates a matcher from its implementation. This is easier to use
488 // Creates a polymorphic matcher from its implementation. This is
511 // polymorphic matcher (i.e. something that can be converted to a
518 // M can be a polymorhic matcher, in which case we want to use
523 // polymorphic matcher because it'll be ambiguous if T has an implicit
540 // matcher. It must be a value then. Use direct initialization to create
541 // a matcher.
548 // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
550 // matcher.
575 // We delegate the matching logic to the source matcher.
596 // a matcher to its own type.
600 static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
605 // In order to be safe and clear, casting between different matcher
607 // matcher m and returns a Matcher<T>. It compiles only when T can be
610 inline Matcher<T> MatcherCast(const M& matcher) {
611 return internal::MatcherCastImpl<T, M>::Cast(matcher);
641 static inline Matcher<T> Cast(const Matcher<U>& matcher) {
660 return MatcherCast<T>(matcher);
669 // A<T>() returns a matcher that matches any value of type T.
695 // Matches the value against the given matcher, prints the value and explains
701 bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
706 return matcher.Matches(value);
710 const bool match = matcher.MatchAndExplain(value, &inner_listener);
751 typename tuple_element<N - 1, MatcherTuple>::type matcher =
756 if (!matcher.MatchAndExplain(value, &listener)) {
765 // matcher's MatchAndExplain() method handles the case when
872 // Implements _, a matcher that matches any value of any
873 // type. This is a polymorphic matcher, so we need a template type
882 // Implements a matcher that compares a given value with a
886 // The matcher defined here is polymorphic (for example, Eq(5) can be
975 // Implements the polymorphic IsNull() matcher, which matches any raw or smart
995 // Implements the polymorphic NotNull() matcher, which matches any raw or smart
1016 // 'variable'. This matcher is polymorphic as it can match any
1040 // compiler to catch using Ref(const_value) as a matcher for a
1048 // this catches using Ref(const_value) as a matcher for a
1183 // Implements the polymorphic HasSubstr(substring) matcher, which
1213 // Describes what this matcher matches.
1230 // Implements the polymorphic StartsWith(substring) matcher, which
1277 // Implements the polymorphic EndsWith(substring) matcher, which
1372 // Implements a matcher that compares the two fields of a 2-tuple
1376 // The matcher defined here is polymorphic (for example, Eq() can be
1439 // Implements the Not(...) matcher for a particular argument type T.
1446 explicit NotMatcherImpl(const Matcher<T>& matcher)
1447 : matcher_(matcher) {}
1467 // Implements the Not(m) matcher, which matches a value that doesn't
1468 // match matcher m.
1472 explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
1487 // Implements the AllOf(m1, m2) matcher for a particular argument type
1552 // a list structure (ListType) and creating a combining matcher from such a
1556 // * Head is the type of the first matcher of the list.
1567 static ListType BuildList(const Head& matcher, const Tail&... tail) {
1568 return ListType(matcher, MatcherListTail::BuildList(tail...));
1635 // Used for implementing the AllOf(m_1, ..., m_n) matcher, which
1659 // Implements the AnyOf(m1, m2) matcher for a particular argument type
1729 // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
1755 // matcher.
1761 // This method template allows Truly(pred) to be used as a matcher
1793 // Used for implementing Matches(matcher), which turns a matcher into
1798 explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
1801 // predicate on type T where m is a matcher on type T.
1804 // some matcher may be interested in its address (e.g. as in
1810 // allows us to write Matches(m) where m is a polymorphic matcher
1832 // argument M must be a type that can be converted to a matcher.
1853 // potentially unsafe downcasting of the matcher argument.
1854 const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
1856 if (MatchPrintAndExplain(x, matcher, &listener))
1862 matcher.DescribeTo(&ss);
1873 // A helper function for converting a matcher to a predicate-formatter
1876 // Implementation detail: 'matcher' is received by-value to force decaying.
1879 MakePredicateFormatterFromMatcher(M matcher) {
1880 return PredicateFormatterFromMatcher<M>(internal::move(matcher));
1883 // Implements the polymorphic floating point equality matcher, which matches
1891 // The matcher's input will be compared with expected. The matcher treats two
1912 // Implements floating point equality matcher as a Matcher<T>.
2040 // Implements the Pointee(m) matcher for matching a pointer whose
2041 // pointee matches matcher m. The pointer can be either raw or smart.
2045 explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
2048 // used as a matcher for any pointer type whose pointee type is
2049 // compatible with the inner matcher, where type Pointer can be
2068 explicit Impl(const InnerMatcher& matcher)
2069 : matcher_(MatcherCast<const Pointee&>(matcher)) {}
2101 // Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
2103 // The result of dynamic_cast<To> is forwarded to the inner matcher.
2104 // If To is a pointer and the cast fails, the inner matcher will receive NULL.
2105 // If To is a reference and the cast fails, this matcher returns false
2110 explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
2111 : matcher_(matcher) {}
2147 explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
2148 : WhenDynamicCastToMatcherBase<To>(matcher) {}
2163 explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
2164 : WhenDynamicCastToMatcherBase<To&>(matcher) {}
2178 // Implements the Field() matcher for matching a field (i.e. member
2184 const Matcher<const FieldType&>& matcher)
2185 : field_(field), matcher_(matcher) {}
2208 // true_type iff the Field() matcher is used to match a pointer.
2233 // Implements the Property() matcher for matching a property
2245 const Matcher<RefToConstProperty>& matcher)
2246 : property_(property), matcher_(matcher) {}
2269 // true_type iff the Property() matcher is used to match a pointer.
2334 // Implements the ResultOf() matcher for matching a return value of a
2341 ResultOfMatcher(Callable callable, const Matcher<ResultType>& matcher)
2342 : callable_(callable), matcher_(matcher) {
2357 Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
2358 : callable_(callable), matcher_(matcher) {}
2397 // Implements a matcher that checks the size of an STL-style container.
2449 // Implements a matcher that checks the begin()..end() distance of an STL-style
2510 // Implements an equality matcher for any STL-style container whose elements
2511 // support ==. This matcher is like Eq(), but its failure explanations provide
2528 // after this matcher is created.
2616 const ContainerMatcher& matcher)
2617 : comparator_(comparator), matcher_(matcher) {}
2636 Impl(const Comparator& comparator, const ContainerMatcher& matcher)
2637 : comparator_(comparator), matcher_(matcher) {}
2700 // it are modified after this matcher is created.
2722 // We pass the LHS value and the RHS value to the inner matcher by
2729 // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
2851 // Describes what this matcher does.
2880 // Describes what this matcher does.
2950 // Returns true iff 'key_value.first' (the key) matches the inner matcher.
2963 // Describes what this matcher does.
2969 // Describes what the negation of this matcher does.
3015 // Describes what this matcher does.
3023 // Describes what the negation of this matcher does.
3116 // Constructs the matcher from a sequence of element values or
3125 // Describes what this matcher does.
3144 // Describes what the negation of this matcher does.
3179 bool match; // Does the current element match the current matcher?
3301 // The matching is represented as a vector of {element, matcher} pairs.
3313 // A vector of matcher describers, one for each element matcher.
3318 // Describes this UnorderedElementsAre matcher.
3321 // Describes the negation of this UnorderedElementsAre matcher.
3356 // Constructs the matcher from a sequence of element values or
3366 // Describes what this matcher does.
3371 // Describes what the negation of this matcher does.
3542 // Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
3544 // second) is a polymorphic matcher that matches a value x iff tm
3607 // Given a 2-tuple matcher tm and a value second,
3608 // MatcherBindSecond(tm, second) returns a matcher that matches a
3617 // Returns the description for a matcher defined using the MATCHER*()
3620 // negation of the matcher. 'param_values' contains a list of strings
3621 // that are the print-out of the matcher's parameters.
3641 // All forms of ElementsAreArray() make a copy of the input matcher sequence.
3720 // _ is a matcher that matches anything of any type.
3730 // Creates a matcher that matches any value of the given type T.
3734 // Creates a matcher that matches any value of the given type T.
3738 // Creates a polymorphic matcher that matches anything equal to x.
3745 // matcher matches any value that's equal to 'value'.
3749 // Creates a monomorphic matcher that matches anything with type Lhs
3764 // Creates a polymorphic matcher that matches anything >= x.
3770 // Creates a polymorphic matcher that matches anything > x.
3776 // Creates a polymorphic matcher that matches anything <= x.
3782 // Creates a polymorphic matcher that matches anything < x.
3788 // Creates a polymorphic matcher that matches anything != x.
3794 // Creates a polymorphic matcher that matches any NULL pointer.
3799 // Creates a polymorphic matcher that matches any non-NULL pointer.
3806 // Creates a polymorphic matcher that matches any argument that
3813 // Creates a matcher that matches any double argument approximately
3819 // Creates a matcher that matches any double argument approximately
3825 // Creates a matcher that matches any double argument approximately equal to
3833 // Creates a matcher that matches any double argument approximately equal to
3841 // Creates a matcher that matches any float argument approximately
3847 // Creates a matcher that matches any float argument approximately
3853 // Creates a matcher that matches any float argument approximately equal to
3861 // Creates a matcher that matches any float argument approximately equal to
3869 // Creates a matcher that matches a pointer (raw or smart) that points
3877 // Creates a matcher that matches a pointer or reference that matches
3879 // The result of dynamic_cast<To> is forwarded to the inner matcher.
3880 // If To is a pointer and the cast fails, the inner matcher will receive NULL.
3881 // If To is a reference and the cast fails, this matcher returns false
3890 // Creates a matcher that matches an object whose given field matches
3891 // 'matcher'. For example,
3897 FieldType Class::*field, const FieldMatcher& matcher) {
3900 field, MatcherCast<const FieldType&>(matcher)));
3904 // to compile where bar is an int32 and m is a matcher for int64.
3907 // Creates a matcher that matches an object whose given property
3908 // matches 'matcher'. For example,
3914 PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
3918 MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
3922 // to compile where bar() returns an int32 and m is a matcher for int64.
3925 // Creates a matcher that matches an object iff the result of applying
3926 // a callable to x matches 'matcher'.
3940 Callable callable, const ResultOfMatcher& matcher) {
3944 matcher));
3948 // to compile where Function() returns an int32 and m is a matcher for int64.
3981 // Creates a matcher that matches any string, std::string, or C string
4004 // The matcher takes ownership of 'regex'.
4015 // The matcher takes ownership of 'regex'.
4056 // Creates a matcher that matches any wstring, std::wstring, or C wide string
4080 // Creates a polymorphic matcher that matches a 2-tuple where the
4084 // Creates a polymorphic matcher that matches a 2-tuple where the
4088 // Creates a polymorphic matcher that matches a 2-tuple where the
4092 // Creates a polymorphic matcher that matches a 2-tuple where the
4096 // Creates a polymorphic matcher that matches a 2-tuple where the
4100 // Creates a polymorphic matcher that matches a 2-tuple where the
4104 // Creates a matcher that matches any value of type T that m doesn't
4111 // Returns a matcher that matches anything that satisfies the given
4120 // Returns a matcher that matches the container size. The container must
4123 // matcher. For instance:
4132 // Returns a matcher that matches the distance between the container's begin()
4133 // iterator and its end() iterator, i.e. the size of the container. This matcher
4143 // Returns a matcher that matches an equal container.
4144 // This matcher behaves like Eq(), but in the event of mismatch lists the
4158 // Returns a matcher that matches a container that, when sorted using
4168 // Returns a matcher that matches a container that, when sorted using
4180 // i-th element (as a pair) satisfy the given pair matcher, for all i.
4211 // pair matcher, for all i. Tuple2Matcher must be able to be safely
4238 // Create a matcher for each element in rhs_container.
4264 // least one element matching the given value or matcher.
4282 inline internal::ContainsMatcher<M> Contains(M matcher) {
4283 return internal::ContainsMatcher<M>(matcher);
4287 // elements matching the given value or matcher.
4314 inline internal::EachMatcher<M> Each(M matcher) {
4315 return internal::EachMatcher<M>(matcher);
4339 // given matcher.
4341 inline internal::MatcherAsPredicate<M> Matches(M matcher) {
4342 return internal::MatcherAsPredicate<M>(matcher);
4345 // Returns true iff the value matches the matcher.
4347 inline bool Value(const T& value, M matcher) {
4348 return testing::Matches(matcher)(value);
4351 // Matches the value against the given matcher and explains the match
4355 M matcher, const T& value, MatchResultListener* listener) {
4356 return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
4360 // Define variadic matcher versions. They are overloaded in
4382 inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
4385 // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
4386 // succeed iff the value matches the matcher. If the assertion fails,
4387 // the value and the description of the matcher will be printed.
4388 #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
4389 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
4390 #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
4391 ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)