mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33:29 +01:00
Added AnyMatch, AllMatch and NoneMatch
This commit is contained in:
parent
ce54ec185f
commit
552af8920d
@ -88,6 +88,7 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/matchers/catch_matchers_exception.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_floating_point.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_predicate.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_quantifiers.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_string.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_templated.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_vector.hpp
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <catch2/matchers/catch_matchers_exception.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <catch2/matchers/catch_matchers_predicate.hpp>
|
||||
#include <catch2/matchers/catch_matchers_quantifiers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
#include <catch2/matchers/catch_matchers_templated.hpp>
|
||||
#include <catch2/matchers/catch_matchers_vector.hpp>
|
||||
|
109
src/catch2/matchers/catch_matchers_quantifiers.hpp
Normal file
109
src/catch2/matchers/catch_matchers_quantifiers.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#ifndef CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
|
||||
#define CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
|
||||
|
||||
#include <catch2/matchers/catch_matchers_templated.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace Catch {
|
||||
namespace Matchers {
|
||||
// Matcher for checking that all elements in range matches a given matcher.
|
||||
template <typename Matcher>
|
||||
class AllMatchMatcher final : public MatcherGenericBase {
|
||||
Matcher m_matcher;
|
||||
public:
|
||||
AllMatchMatcher(Matcher matcher):
|
||||
m_matcher(std::move(matcher))
|
||||
{}
|
||||
|
||||
std::string describe() const override {
|
||||
return "all match " + m_matcher.describe();
|
||||
}
|
||||
|
||||
template <typename RangeLike>
|
||||
bool match(RangeLike&& rng) const {
|
||||
for (auto&& elem : rng) {
|
||||
if (!m_matcher.match(elem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Matcher for checking that no element in range matches a given matcher.
|
||||
template <typename Matcher>
|
||||
class NoneMatchMatcher final : public MatcherGenericBase {
|
||||
Matcher m_matcher;
|
||||
public:
|
||||
NoneMatchMatcher(Matcher matcher):
|
||||
m_matcher(std::move(matcher))
|
||||
{}
|
||||
|
||||
std::string describe() const override {
|
||||
return "none match " + m_matcher.describe();
|
||||
}
|
||||
|
||||
template <typename RangeLike>
|
||||
bool match(RangeLike&& rng) const {
|
||||
for (auto&& elem : rng) {
|
||||
if (m_matcher.match(elem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Matcher for checking that at least one element in range matches a given matcher.
|
||||
template <typename Matcher>
|
||||
class AnyMatchMatcher final : public MatcherGenericBase {
|
||||
Matcher m_matcher;
|
||||
public:
|
||||
AnyMatchMatcher(Matcher matcher):
|
||||
m_matcher(std::move(matcher))
|
||||
{}
|
||||
|
||||
std::string describe() const override {
|
||||
return "any match " + m_matcher.describe();
|
||||
}
|
||||
|
||||
template <typename RangeLike>
|
||||
bool match(RangeLike&& rng) const {
|
||||
for (auto&& elem : rng) {
|
||||
if (m_matcher.match(elem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Creates a matcher that checks whether a range contains element matching a matcher
|
||||
template <typename Matcher>
|
||||
AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
|
||||
return { std::forward<Matcher>(matcher) };
|
||||
}
|
||||
|
||||
// Creates a matcher that checks whether no element in a range matches a matcher.
|
||||
template <typename Matcher>
|
||||
NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
|
||||
return { std::forward<Matcher>(matcher) };
|
||||
}
|
||||
|
||||
// Creates a matcher that checks whether any element in a range matches a matcher.
|
||||
template <typename Matcher>
|
||||
AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
|
||||
return { std::forward<Matcher>(matcher) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
|
@ -238,6 +238,7 @@ Message from section two
|
||||
:test-result: FAIL Unexpected exceptions can be translated
|
||||
:test-result: PASS Upcasting special member functions
|
||||
:test-result: PASS Usage of the SizeIs range matcher
|
||||
:test-result: PASS Usage of the quantifiers matchers
|
||||
:test-result: PASS Use a custom approx
|
||||
:test-result: PASS Variadic macros
|
||||
:test-result: PASS Vector Approx matcher
|
||||
|
@ -1668,6 +1668,24 @@ MatchersRanges.tests.cpp:<line number>: passed: arr, !SizeIs(!Lt(3)) for: { 0, 0
|
||||
MatchersRanges.tests.cpp:<line number>: passed: map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3
|
||||
MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12
|
||||
MatchersRanges.tests.cpp:<line number>: passed: has_size{}, SizeIs(13) for: {?} has size == 13
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AllMatch(Contains(0)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, AllMatch(StartsWith("C")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, AllMatch(EndsWith("+")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AllMatch(!IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AllMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AnyMatch(Contains(-2)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AnyMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, AnyMatch(StartsWith("CMak")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, AnyMatch(EndsWith("++")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AnyMatch(Contains(4)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AnyMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, NoneMatch(Contains(-6)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, NoneMatch(SizeIs(42)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, NoneMatch(StartsWith("abd")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: string_vector, NoneMatch(EndsWith("#!--")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--"
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, NoneMatch(IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty
|
||||
MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, NoneMatch(SizeIs(3)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3
|
||||
Approx.tests.cpp:<line number>: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 )
|
||||
Approx.tests.cpp:<line number>: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 )
|
||||
Approx.tests.cpp:<line number>: passed: d == approx( 1.24 ) for: 1.23 == Approx( 1.24 )
|
||||
|
@ -1380,6 +1380,6 @@ due to unexpected exception with message:
|
||||
Why would you throw a std::string?
|
||||
|
||||
===============================================================================
|
||||
test cases: 351 | 277 passed | 70 failed | 4 failed as expected
|
||||
assertions: 1992 | 1840 passed | 131 failed | 21 failed as expected
|
||||
test cases: 352 | 278 passed | 70 failed | 4 failed as expected
|
||||
assertions: 2010 | 1858 passed | 131 failed | 21 failed as expected
|
||||
|
||||
|
@ -12286,6 +12286,129 @@ MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
{?} has size == 13
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Usage of the quantifiers matchers
|
||||
Usage of the AllMatch range matcher
|
||||
-------------------------------------------------------------------------------
|
||||
MatchersRanges.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, AllMatch(Contains(0)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } all match contains element 0
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, AllMatch(SizeIs(5)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } all match has size == 5
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, AllMatch(StartsWith("C")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with:
|
||||
"C"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, AllMatch(EndsWith("+")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with:
|
||||
"+"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, AllMatch(!IsEmpty()) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, AllMatch(SizeIs(2)) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Usage of the quantifiers matchers
|
||||
Usage of the AnyMatch range matcher
|
||||
-------------------------------------------------------------------------------
|
||||
MatchersRanges.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, AnyMatch(Contains(-2)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } any match contains element -2
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, AnyMatch(SizeIs(5)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } any match has size == 5
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, AnyMatch(StartsWith("CMak")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with:
|
||||
"CMak"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, AnyMatch(EndsWith("++")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with:
|
||||
"++"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, AnyMatch(Contains(4)) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, AnyMatch(SizeIs(2)) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Usage of the quantifiers matchers
|
||||
Usage of the NoneMatch range matcher
|
||||
-------------------------------------------------------------------------------
|
||||
MatchersRanges.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, NoneMatch(Contains(-6)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } none match contains element -6
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_arr_arr, NoneMatch(SizeIs(42)) )
|
||||
with expansion:
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0
|
||||
}, { 1, 0, 0, -1, 5 } } none match has size == 42
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, NoneMatch(StartsWith("abd")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts
|
||||
with: "abd"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( string_vector, NoneMatch(EndsWith("#!--")) )
|
||||
with expansion:
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with:
|
||||
"#!--"
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, NoneMatch(IsEmpty()) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty
|
||||
|
||||
MatchersRanges.tests.cpp:<line number>: PASSED:
|
||||
REQUIRE_THAT( int_vectors_list, NoneMatch(SizeIs(3)) )
|
||||
with expansion:
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Use a custom approx
|
||||
-------------------------------------------------------------------------------
|
||||
@ -15681,6 +15804,6 @@ Misc.tests.cpp:<line number>
|
||||
Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 351 | 261 passed | 86 failed | 4 failed as expected
|
||||
assertions: 2009 | 1840 passed | 148 failed | 21 failed as expected
|
||||
test cases: 352 | 262 passed | 86 failed | 4 failed as expected
|
||||
assertions: 2027 | 1858 passed | 148 failed | 21 failed as expected
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="2010" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="2028" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -1283,6 +1283,9 @@ Exception.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Some with stdlib containers" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type requires ADL found size free function" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type has size member" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the AllMatch range matcher" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the AnyMatch range matcher" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the NoneMatch range matcher" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Use a custom approx" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Variadic macros/Section with one argument" time="{duration}" status="run"/>
|
||||
<testcase classname="<exe-name>.global" name="Vector Approx matcher/Empty vector is roughly equal to an empty vector" time="{duration}" status="run"/>
|
||||
|
@ -1268,6 +1268,9 @@ Matchers.tests.cpp:<line number>
|
||||
<testCase name="Usage of the SizeIs range matcher/Some with stdlib containers" duration="{duration}"/>
|
||||
<testCase name="Usage of the SizeIs range matcher/Type requires ADL found size free function" duration="{duration}"/>
|
||||
<testCase name="Usage of the SizeIs range matcher/Type has size member" duration="{duration}"/>
|
||||
<testCase name="Usage of the quantifiers matchers/Usage of the AllMatch range matcher" duration="{duration}"/>
|
||||
<testCase name="Usage of the quantifiers matchers/Usage of the AnyMatch range matcher" duration="{duration}"/>
|
||||
<testCase name="Usage of the quantifiers matchers/Usage of the NoneMatch range matcher" duration="{duration}"/>
|
||||
</file>
|
||||
<file path="tests/<exe-name>/UsageTests/Message.tests.cpp">
|
||||
<testCase name="#1455 - INFO and WARN can start with a linebreak" duration="{duration}"/>
|
||||
|
@ -3179,6 +3179,42 @@ ok {test-number} - map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3
|
||||
ok {test-number} - unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12
|
||||
# Usage of the SizeIs range matcher
|
||||
ok {test-number} - has_size{}, SizeIs(13) for: {?} has size == 13
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, AllMatch(Contains(0)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, AllMatch(StartsWith("C")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, AllMatch(EndsWith("+")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, AllMatch(!IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, AllMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, AnyMatch(Contains(-2)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, AnyMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, AnyMatch(StartsWith("CMak")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, AnyMatch(EndsWith("++")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, AnyMatch(Contains(4)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, AnyMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, NoneMatch(Contains(-6)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_arr_arr, NoneMatch(SizeIs(42)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, NoneMatch(StartsWith("abd")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - string_vector, NoneMatch(EndsWith("#!--")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--"
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, NoneMatch(IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty
|
||||
# Usage of the quantifiers matchers
|
||||
ok {test-number} - int_vectors_list, NoneMatch(SizeIs(3)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3
|
||||
# Use a custom approx
|
||||
ok {test-number} - d == approx( 1.23 ) for: 1.23 == Approx( 1.23 )
|
||||
# Use a custom approx
|
||||
@ -4010,5 +4046,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2009
|
||||
1..2027
|
||||
|
||||
|
@ -579,6 +579,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "3.14"'
|
||||
##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"]
|
||||
##teamcity[testStarted name='Usage of the SizeIs range matcher']
|
||||
##teamcity[testFinished name='Usage of the SizeIs range matcher' duration="{duration}"]
|
||||
##teamcity[testStarted name='Usage of the quantifiers matchers']
|
||||
##teamcity[testFinished name='Usage of the quantifiers matchers' duration="{duration}"]
|
||||
##teamcity[testStarted name='Use a custom approx']
|
||||
##teamcity[testFinished name='Use a custom approx' duration="{duration}"]
|
||||
##teamcity[testStarted name='Variadic macros']
|
||||
|
@ -14620,6 +14620,162 @@ There is no extra whitespace here
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Usage of the quantifiers matchers" tags="[matchers][quantifiers][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Section name="Usage of the AllMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, AllMatch(Contains(0))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, AllMatch(SizeIs(5))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, AllMatch(StartsWith("C"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, AllMatch(EndsWith("+"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, AllMatch(!IsEmpty())
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, AllMatch(SizeIs(2))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="6" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="Usage of the AnyMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, AnyMatch(Contains(-2))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, AnyMatch(SizeIs(5))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, AnyMatch(StartsWith("CMak"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, AnyMatch(EndsWith("++"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, AnyMatch(Contains(4))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, AnyMatch(SizeIs(2))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="6" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="Usage of the NoneMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, NoneMatch(Contains(-6))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_arr_arr, NoneMatch(SizeIs(42))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, NoneMatch(StartsWith("abd"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
string_vector, NoneMatch(EndsWith("#!--"))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, NoneMatch(IsEmpty())
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
|
||||
<Original>
|
||||
int_vectors_list, NoneMatch(SizeIs(3))
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="6" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Use a custom approx" tags="[Approx][custom]" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
|
||||
<Original>
|
||||
@ -18598,9 +18754,9 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1840" failures="149" expectedFailures="21"/>
|
||||
<OverallResultsCases successes="261" failures="86" expectedFailures="4"/>
|
||||
<OverallResults successes="1858" failures="149" expectedFailures="21"/>
|
||||
<OverallResultsCases successes="262" failures="86" expectedFailures="4"/>
|
||||
</Group>
|
||||
<OverallResults successes="1840" failures="148" expectedFailures="21"/>
|
||||
<OverallResultsCases successes="261" failures="86" expectedFailures="4"/>
|
||||
<OverallResults successes="1858" failures="148" expectedFailures="21"/>
|
||||
<OverallResultsCases successes="262" failures="86" expectedFailures="4"/>
|
||||
</Catch>
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <catch2/matchers/catch_matchers_container_properties.hpp>
|
||||
#include <catch2/matchers/catch_matchers_contains.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
#include <catch2/matchers/catch_matchers_quantifiers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
@ -217,3 +219,56 @@ TEST_CASE("Usage of the SizeIs range matcher", "[matchers][templated][size]") {
|
||||
REQUIRE_THAT(has_size{}, SizeIs(13));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Usage of the quantifiers matchers", "[matchers][templated][quantifiers]") {
|
||||
using Catch::Matchers::AllMatch;
|
||||
using Catch::Matchers::AnyMatch;
|
||||
using Catch::Matchers::Contains;
|
||||
using Catch::Matchers::EndsWith;
|
||||
using Catch::Matchers::IsEmpty;
|
||||
using Catch::Matchers::NoneMatch;
|
||||
using Catch::Matchers::SizeIs;
|
||||
using Catch::Matchers::StartsWith;
|
||||
std::array<std::array<int, 5>, 5> int_arr_arr{{
|
||||
{{ 0, 1, 2, 3, 5 }},
|
||||
{{ 4,-3,-2, 5, 0 }},
|
||||
{{ 0, 0, 0, 5, 0 }},
|
||||
{{ 0,-5, 0, 5, 0 }},
|
||||
{{ 1, 0, 0,-1, 5 }}
|
||||
}};
|
||||
std::vector<std::string> string_vector{ "Command+", "Catch2+", "CMake+", "C++", "Console+" };
|
||||
std::list<std::vector<int>> int_vectors_list{ { 1, 2 }, { 3, 4 }, { 5, 6 } };
|
||||
|
||||
SECTION("Usage of the AllMatch range matcher") {
|
||||
REQUIRE_THAT(int_arr_arr, AllMatch(Contains(0)));
|
||||
REQUIRE_THAT(int_arr_arr, AllMatch(SizeIs(5)));
|
||||
|
||||
REQUIRE_THAT(string_vector, AllMatch(StartsWith("C")));
|
||||
REQUIRE_THAT(string_vector, AllMatch(EndsWith("+")));
|
||||
|
||||
REQUIRE_THAT(int_vectors_list, AllMatch(!IsEmpty()));
|
||||
REQUIRE_THAT(int_vectors_list, AllMatch(SizeIs(2)));
|
||||
}
|
||||
|
||||
SECTION("Usage of the AnyMatch range matcher") {
|
||||
REQUIRE_THAT(int_arr_arr, AnyMatch(Contains(-2)));
|
||||
REQUIRE_THAT(int_arr_arr, AnyMatch(SizeIs(5)));
|
||||
|
||||
REQUIRE_THAT(string_vector, AnyMatch(StartsWith("CMak")));
|
||||
REQUIRE_THAT(string_vector, AnyMatch(EndsWith("++")));
|
||||
|
||||
REQUIRE_THAT(int_vectors_list, AnyMatch(Contains(4)));
|
||||
REQUIRE_THAT(int_vectors_list, AnyMatch(SizeIs(2)));
|
||||
}
|
||||
|
||||
SECTION("Usage of the NoneMatch range matcher") {
|
||||
REQUIRE_THAT(int_arr_arr, NoneMatch(Contains(-6)));
|
||||
REQUIRE_THAT(int_arr_arr, NoneMatch(SizeIs(42)));
|
||||
|
||||
REQUIRE_THAT(string_vector, NoneMatch(StartsWith("abd")));
|
||||
REQUIRE_THAT(string_vector, NoneMatch(EndsWith("#!--")));
|
||||
|
||||
REQUIRE_THAT(int_vectors_list, NoneMatch(IsEmpty()));
|
||||
REQUIRE_THAT(int_vectors_list, NoneMatch(SizeIs(3)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user