diff options
author | Simon Warta <[email protected]> | 2015-08-08 18:04:57 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-08-11 10:50:14 +0200 |
commit | a35294066c8d24f685bc84a93f3bf1e2931e6db3 (patch) | |
tree | 6681b6b5a496fdb2f8843a0194d2119b1c54b600 /src | |
parent | e1c927afcee6c7ae95b0ccaa0169a05776aa63db (diff) |
Add Not matcher for Catch
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/catchy/catchy_tests.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tests/catchy/catchy_tests.h b/src/tests/catchy/catchy_tests.h index c60a790d9..99ad03f31 100644 --- a/src/tests/catchy/catchy_tests.h +++ b/src/tests/catchy/catchy_tests.h @@ -19,6 +19,25 @@ namespace Catch { namespace Matchers { namespace Impl { + 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 + { + return !m_matcher->match( expr ); + } + virtual std::string toString() const { + return "not " + m_matcher->toString(); + } + + Ptr<Matcher<ExpressionT>> m_matcher; + }; + } // namespace Generic + namespace StdVector { template<typename T, typename Alloc> struct Equals : MatcherImpl<Equals<T, Alloc>, std::vector<T, Alloc> > @@ -82,6 +101,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 T, typename Alloc> inline Impl::StdVector::Equals<T, Alloc> Equals( std::vector<T, Alloc> const& vec ) { return Impl::StdVector::Equals<T, Alloc>( vec ); |