mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Make concrete matchers final
Outside of `MatcherBase` and `GenericMatcherBase`, matchers are not designed to be overriden. This means that doing so can easily lead to errors, and matchers are generally fairly simple functionality-wise. so there is not much code reuse to be gained anyway. Thus, Catch2-provided concrete matchers are now final.
This commit is contained in:
parent
007efc173a
commit
f52a58e857
@ -13,7 +13,7 @@ namespace Catch {
|
|||||||
namespace Matchers {
|
namespace Matchers {
|
||||||
namespace Exception {
|
namespace Exception {
|
||||||
|
|
||||||
class ExceptionMessageMatcher : public MatcherBase<std::exception> {
|
class ExceptionMessageMatcher final : public MatcherBase<std::exception> {
|
||||||
std::string m_message;
|
std::string m_message;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace Matchers {
|
|||||||
|
|
||||||
enum class FloatingPointKind : uint8_t;
|
enum class FloatingPointKind : uint8_t;
|
||||||
|
|
||||||
struct WithinAbsMatcher : MatcherBase<double> {
|
struct WithinAbsMatcher final : MatcherBase<double> {
|
||||||
WithinAbsMatcher(double target, double margin);
|
WithinAbsMatcher(double target, double margin);
|
||||||
bool match(double const& matchee) const override;
|
bool match(double const& matchee) const override;
|
||||||
std::string describe() const override;
|
std::string describe() const override;
|
||||||
@ -25,7 +25,7 @@ namespace Matchers {
|
|||||||
double m_margin;
|
double m_margin;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WithinUlpsMatcher : MatcherBase<double> {
|
struct WithinUlpsMatcher final : MatcherBase<double> {
|
||||||
WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType);
|
WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType);
|
||||||
bool match(double const& matchee) const override;
|
bool match(double const& matchee) const override;
|
||||||
std::string describe() const override;
|
std::string describe() const override;
|
||||||
@ -41,7 +41,7 @@ namespace Matchers {
|
|||||||
// |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
|
// |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
|
||||||
// the same result if we do this for floats, as if we do this for
|
// the same result if we do this for floats, as if we do this for
|
||||||
// doubles that were promoted from floats.
|
// doubles that were promoted from floats.
|
||||||
struct WithinRelMatcher : MatcherBase<double> {
|
struct WithinRelMatcher final : MatcherBase<double> {
|
||||||
WithinRelMatcher(double target, double epsilon);
|
WithinRelMatcher(double target, double epsilon);
|
||||||
bool match(double const& matchee) const override;
|
bool match(double const& matchee) const override;
|
||||||
std::string describe() const override;
|
std::string describe() const override;
|
||||||
|
@ -23,7 +23,7 @@ namespace Detail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename Predicate>
|
template <typename T, typename Predicate>
|
||||||
class PredicateMatcher : public MatcherBase<T> {
|
class PredicateMatcher final : public MatcherBase<T> {
|
||||||
Predicate m_predicate;
|
Predicate m_predicate;
|
||||||
std::string m_description;
|
std::string m_description;
|
||||||
public:
|
public:
|
||||||
|
@ -35,24 +35,24 @@ namespace Matchers {
|
|||||||
std::string m_operation;
|
std::string m_operation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EqualsMatcher : StringMatcherBase {
|
struct EqualsMatcher final : StringMatcherBase {
|
||||||
EqualsMatcher( CasedString const& comparator );
|
EqualsMatcher( CasedString const& comparator );
|
||||||
bool match( std::string const& source ) const override;
|
bool match( std::string const& source ) const override;
|
||||||
};
|
};
|
||||||
struct ContainsMatcher : StringMatcherBase {
|
struct ContainsMatcher final : StringMatcherBase {
|
||||||
ContainsMatcher( CasedString const& comparator );
|
ContainsMatcher( CasedString const& comparator );
|
||||||
bool match( std::string const& source ) const override;
|
bool match( std::string const& source ) const override;
|
||||||
};
|
};
|
||||||
struct StartsWithMatcher : StringMatcherBase {
|
struct StartsWithMatcher final : StringMatcherBase {
|
||||||
StartsWithMatcher( CasedString const& comparator );
|
StartsWithMatcher( CasedString const& comparator );
|
||||||
bool match( std::string const& source ) const override;
|
bool match( std::string const& source ) const override;
|
||||||
};
|
};
|
||||||
struct EndsWithMatcher : StringMatcherBase {
|
struct EndsWithMatcher final : StringMatcherBase {
|
||||||
EndsWithMatcher( CasedString const& comparator );
|
EndsWithMatcher( CasedString const& comparator );
|
||||||
bool match( std::string const& source ) const override;
|
bool match( std::string const& source ) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RegexMatcher : MatcherBase<std::string> {
|
struct RegexMatcher final : MatcherBase<std::string> {
|
||||||
RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
|
RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
|
||||||
bool match( std::string const& matchee ) const override;
|
bool match( std::string const& matchee ) const override;
|
||||||
std::string describe() const override;
|
std::string describe() const override;
|
||||||
|
@ -18,7 +18,7 @@ namespace Matchers {
|
|||||||
|
|
||||||
namespace Vector {
|
namespace Vector {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
|
struct ContainsElementMatcher final : MatcherBase<std::vector<T>> {
|
||||||
|
|
||||||
ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
|
ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace Matchers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ContainsMatcher : MatcherBase<std::vector<T>> {
|
struct ContainsMatcher final : MatcherBase<std::vector<T>> {
|
||||||
|
|
||||||
ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
|
ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ namespace Matchers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct EqualsMatcher : MatcherBase<std::vector<T>> {
|
struct EqualsMatcher final : MatcherBase<std::vector<T>> {
|
||||||
|
|
||||||
EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
|
EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ namespace Matchers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ApproxMatcher : MatcherBase<std::vector<T>> {
|
struct ApproxMatcher final : MatcherBase<std::vector<T>> {
|
||||||
|
|
||||||
ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {}
|
ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ namespace Matchers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> {
|
struct UnorderedEqualsMatcher final : MatcherBase<std::vector<T>> {
|
||||||
UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
|
UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
|
||||||
bool match(std::vector<T> const& vec) const override {
|
bool match(std::vector<T> const& vec) const override {
|
||||||
// Note: This is a reimplementation of std::is_permutation,
|
// Note: This is a reimplementation of std::is_permutation,
|
||||||
|
Loading…
Reference in New Issue
Block a user