mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Small cleanup for PredicateMatcher
Removed the `generic` nested namespace, so PredicateMatcher now lives in `Catch::Matchers` namespace, just like other matchers. Also cleaned up and doxygenized comments on the `Predicate` factory function for `PredicateMatcher`.
This commit is contained in:
parent
ab0ca2f566
commit
5c9367d4f1
@ -1,6 +1,6 @@
|
|||||||
#include <catch2/matchers/catch_matchers_predicate.hpp>
|
#include <catch2/matchers/catch_matchers_predicate.hpp>
|
||||||
|
|
||||||
std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) {
|
std::string Catch::Matchers::Detail::finalizeDescription(const std::string& desc) {
|
||||||
if (desc.empty()) {
|
if (desc.empty()) {
|
||||||
return "matches undescribed predicate";
|
return "matches undescribed predicate";
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Matchers {
|
namespace Matchers {
|
||||||
namespace Generic {
|
|
||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
std::string finalizeDescription(const std::string& desc);
|
std::string finalizeDescription(const std::string& desc);
|
||||||
}
|
} // namespace Detail
|
||||||
|
|
||||||
template <typename T, typename Predicate>
|
template <typename T, typename Predicate>
|
||||||
class PredicateMatcher final : public MatcherBase<T> {
|
class PredicateMatcher final : public MatcherBase<T> {
|
||||||
@ -42,17 +41,16 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Generic
|
/**
|
||||||
|
* Creates a matcher that calls delegates `match` to the provided predicate.
|
||||||
// The following functions create the actual matcher objects.
|
*
|
||||||
// The user has to explicitly specify type to the function, because
|
* The user has to explicitly specify the argument type to the matcher
|
||||||
// inferring std::function<bool(T const&)> is hard (but possible) and
|
*/
|
||||||
// requires a lot of TMP.
|
|
||||||
template<typename T, typename Pred>
|
template<typename T, typename Pred>
|
||||||
Generic::PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") {
|
PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") {
|
||||||
static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T");
|
static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T");
|
||||||
static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool");
|
static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool");
|
||||||
return Generic::PredicateMatcher<T, Pred>(std::forward<Pred>(predicate), description);
|
return PredicateMatcher<T, Pred>(std::forward<Pred>(predicate), description);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Matchers
|
} // namespace Matchers
|
||||||
|
Loading…
Reference in New Issue
Block a user