Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matcher: Not() #482

Merged
merged 1 commit into from
Aug 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/internal/catch_matchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ namespace Matchers {
};

namespace Generic {
template<typename ExpressionT>
struct Not : public MatcherImpl<Not<ExpressionT>, ExpressionT>
{
Not( Matcher<ExpressionT> const& matcher ) : m_matcher(matcher.clone()) {}
Not( Not const& other ) : m_matcher( other.m_matcher ) {}

virtual bool match( ExpressionT const& expr ) const CATCH_OVERRIDE
{
return !m_matcher->match( expr );
}

virtual std::string toString() const CATCH_OVERRIDE {
return "not " + m_matcher->toString();
}

Ptr< Matcher<ExpressionT> > m_matcher;
};

template<typename ExpressionT>
class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> {
Expand Down Expand Up @@ -204,6 +221,11 @@ namespace Matchers {

// The following functions create the actual matcher objects.
// This allows the types to be inferred
template<typename ExpressionT>
inline Impl::Generic::Not<ExpressionT> Not( Impl::Matcher<ExpressionT> const& m ) {
return Impl::Generic::Not<ExpressionT>( m );
}

template<typename ExpressionT>
inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1,
Impl::Matcher<ExpressionT> const& m2 ) {
Expand Down