mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Generalised Matchers so objects and comparators can be different types
This commit is contained in:
parent
4e6938d78e
commit
45d4096756
@ -33,14 +33,14 @@ namespace Matchers {
|
|||||||
MatcherUntypedBase& operator = (MatcherUntypedBase const&);
|
MatcherUntypedBase& operator = (MatcherUntypedBase const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ArgT>
|
template<typename ObjectT, typename ComparatorT = ObjectT>
|
||||||
struct MatcherBase : MatcherUntypedBase {
|
struct MatcherBase : MatcherUntypedBase {
|
||||||
|
|
||||||
virtual bool match( ArgT const& arg ) const = 0;
|
virtual bool match( ObjectT const& arg ) const = 0;
|
||||||
|
|
||||||
MatchAllOf<ArgT> operator && ( MatcherBase const& other ) const;
|
MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
|
||||||
MatchAnyOf<ArgT> operator || ( MatcherBase const& other ) const;
|
MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
|
||||||
MatchNotOf<ArgT> operator ! () const;
|
MatchNotOf<ComparatorT> operator ! () const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ArgT>
|
template<typename ArgT>
|
||||||
@ -118,17 +118,17 @@ namespace Matchers {
|
|||||||
MatcherBase<ArgT> const& m_underlyingMatcher;
|
MatcherBase<ArgT> const& m_underlyingMatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ArgT>
|
template<typename ObjectT, typename ComparatorT>
|
||||||
MatchAllOf<ArgT> MatcherBase<ArgT>::operator && ( MatcherBase const& other ) const {
|
MatchAllOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator && ( MatcherBase const& other ) const {
|
||||||
return MatchAllOf<ArgT>() && *this && other;
|
return MatchAllOf<ComparatorT>() && *this && other;
|
||||||
}
|
}
|
||||||
template<typename ArgT>
|
template<typename ObjectT, typename ComparatorT>
|
||||||
MatchAnyOf<ArgT> MatcherBase<ArgT>::operator || ( MatcherBase const& other ) const {
|
MatchAnyOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator || ( MatcherBase const& other ) const {
|
||||||
return MatchAnyOf<ArgT>() || *this || other;
|
return MatchAnyOf<ComparatorT>() || *this || other;
|
||||||
}
|
}
|
||||||
template<typename ArgT>
|
template<typename ObjectT, typename ComparatorT>
|
||||||
MatchNotOf<ArgT> MatcherBase<ArgT>::operator ! () const {
|
MatchNotOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator ! () const {
|
||||||
return MatchNotOf<ArgT>( *this );
|
return MatchNotOf<ComparatorT>( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Impl
|
} // namespace Impl
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_MATCHERS_STRING_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_MATCHERS_STRING_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_matchers.hpp"
|
#include "catch_matchers.hpp"
|
||||||
|
|
||||||
@ -64,4 +64,4 @@ namespace Matchers {
|
|||||||
} // namespace Matchers
|
} // namespace Matchers
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_MATCHERS_STRING_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user