mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Add support for iterator+sentinel pairs in Contains matcher
This commit is contained in:
parent
4aa88299af
commit
e8ba329b6c
@ -34,12 +34,10 @@ namespace Catch {
|
|||||||
|
|
||||||
template <typename RangeLike>
|
template <typename RangeLike>
|
||||||
bool match( RangeLike&& rng ) const {
|
bool match( RangeLike&& rng ) const {
|
||||||
using std::begin; using std::end;
|
for ( auto&& elem : rng ) {
|
||||||
|
if ( m_eq( elem, m_desired ) ) { return true; }
|
||||||
return end(rng) != std::find_if(begin(rng), end(rng),
|
}
|
||||||
[&](auto const& elem) {
|
return false;
|
||||||
return m_eq(elem, m_desired);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ namespace Catch {
|
|||||||
/**
|
/**
|
||||||
* Creates a matcher that checks whether a range contains a specific element.
|
* Creates a matcher that checks whether a range contains a specific element.
|
||||||
*
|
*
|
||||||
* Uses `eq` to do the comparisons
|
* Uses `eq` to do the comparisons, the element is provided on the rhs
|
||||||
*/
|
*/
|
||||||
template <typename T, typename Equality>
|
template <typename T, typename Equality>
|
||||||
ContainsElementMatcher<T, Equality> Contains(T&& elem, Equality&& eq) {
|
ContainsElementMatcher<T, Equality> Contains(T&& elem, Equality&& eq) {
|
||||||
|
@ -646,6 +646,16 @@ TEST_CASE( "RangeEquals supports ranges with different types returned from begin
|
|||||||
REQUIRE_THAT( diff_types, UnorderedRangeEquals( diff_types ) );
|
REQUIRE_THAT( diff_types, UnorderedRangeEquals( diff_types ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "RangeContains supports ranges with different types returned from "
|
||||||
|
"begin and end",
|
||||||
|
"[matchers][templated][range][approvals]" ) {
|
||||||
|
using Catch::Matchers::Contains;
|
||||||
|
|
||||||
|
has_different_begin_end_types<size_t> diff_types{ 1, 2, 3, 4, 5 };
|
||||||
|
REQUIRE_THAT( diff_types, Contains( size_t( 3 ) ) );
|
||||||
|
REQUIRE_THAT( diff_types, Contains( LessThanMatcher( size_t( 4 ) ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_CASE( "Usage of RangeEquals range matcher", "[matchers][templated][quantifiers]" ) {
|
TEST_CASE( "Usage of RangeEquals range matcher", "[matchers][templated][quantifiers]" ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user