12#include <source_location>
36template <
typename Actual,
typename Expected>
38 std::string custom_failure_message;
48 MatcherBase(MatcherBase<Actual, Expected>
const& copy) =
default;
53 : expectation_(expectation) {}
59 virtual ~MatcherBase() =
default;
66 virtual std::string verb() {
return "match"; }
69 constexpr Actual& actual() {
return expectation_.
get_target(); }
72 Expected& expected() {
return expected_; }
75 Expectation<Actual>& expectation() {
return expectation_; }
80 [[nodiscard]] std::source_location get_location()
const {
return expectation_.get_location(); }
87 virtual bool match() = 0;
88 virtual bool negated_match() {
return !match(); }
91 using expected_t = Expected;
100template <
typename A,
typename E>
102 this->custom_failure_message = std::move(message);
111template <
typename A,
typename E>
113 if (not custom_failure_message.empty()) {
114 return this->custom_failure_message;
124template <
typename A,
typename E>
126 if (not custom_failure_message.empty()) {
127 return this->custom_failure_message;
137template <
typename A,
typename E>
153template <
typename A,
typename E>
162 if (result.is_failure() && result.get_message().empty()) {
164 "Failure message is empty. Does your matcher define the "
165 "appropriate failure_message[_when_negated] method to "
169 if (expectation_.ignored()) {
170 result.set_status(Result::Status::Skipped);
173 ItBase* parent = expectation_.get_it();
174 if (parent !=
nullptr) {
179 (expectation_.positive() ? PositiveExpectationHandler::verb() : NegativeExpectationHandler::verb()) +
" " +
180 this->description());
182 parent->add_result(result);
Wraps the target of an expectation.
Definition expectation.hpp:47
virtual A & get_target() &=0
Get the target of the expectation.
Base class for it expressions.
Definition it_base.hpp:32
bool needs_description() noexcept
Get whether the object needs a description string.
Definition it_base.hpp:58
ItBase & set_description(std::string_view description) noexcept
Set the description string.
Definition it_base.hpp:70
virtual std::string description()
Get the description of the Matcher.
Definition matcher_base.hpp:138
Result run()
Run the Matcher object.
Definition matcher_base.hpp:154
virtual std::string failure_message_when_negated()
Get message to give on match failure when negated.
Definition matcher_base.hpp:125
virtual std::string failure_message()
Get message to give on match failure.
Definition matcher_base.hpp:112
virtual MatcherBase & set_message(std::string message)
Set a custom failure message.
Definition matcher_base.hpp:101
Definition have_error.hpp:9
Contains the primary handlers for running Matchers.
static Result handle_matcher(Matcher &matcher)
runs a negative expectation
Definition handler.hpp:65
static Result handle_matcher(Matcher &matcher)
runs a positive expectation
Definition handler.hpp:42
A helper base class that assists in pretty-printing various objects.
Definition pretty_matchers.hpp:27
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:122
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:106
std::string demangle(const char *name)
Definition util.hpp:38