12#include <source_location>
38 return "\nnullptr is not text, so there is nothing to search";
48inline constexpr std::string_view
nothing_to_look_for =
"\nnullptr is not text, so there is nothing to look for";
76template <
typename Actual,
typename Expected>
78 std::string custom_failure_message;
82 [[nodiscard]] std::string with_custom_message(std::string own)
const {
86 return custom_failure_message.empty() ? own : custom_failure_message +
"\n" + own;
97 MatcherBase(MatcherBase<Actual, Expected>
const& copy) =
default;
102 : expectation_(expectation) {}
108 virtual ~MatcherBase() =
default;
115 virtual std::string verb() {
return "match"; }
118 constexpr Actual& actual() {
return expectation_.
get_target(); }
121 Expected& expected() {
return expected_; }
124 Expectation<Actual>& expectation() {
return expectation_; }
145 "Failure message is empty. Does your matcher define the appropriate failure_message[_when_negated] method to "
148 [[nodiscard]] std::source_location get_location()
const {
return expectation_.get_location(); }
155 virtual bool match() = 0;
156 virtual bool negated_match() {
return !match(); }
159 using expected_t = Expected;
168template <
typename A,
typename E>
170 this->custom_failure_message = std::move(message);
179template <
typename A,
typename E>
189template <
typename A,
typename E>
199template <
typename A,
typename E>
216template <
typename A,
typename E>
226 if (result.is_failure() && result.get_message().empty()) {
230 if (expectation_.ignored()) {
231 result.set_status(Result::Status::Skipped);
234 ItBase* parent = expectation_.get_it();
235 if (parent !=
nullptr) {
240 (expectation_.positive() ? PositiveExpectationHandler::verb() : NegativeExpectationHandler::verb()) +
" " +
241 this->description());
243 parent->add_result(result);
Wraps the target of an expectation.
Definition expectation.hpp:48
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
std::string full_failure_message()
What a failed match reports: the custom message, when one was set, on the line above the matcher's ow...
Definition matcher_base.hpp:133
virtual std::string description()
Get the description of the Matcher.
Definition matcher_base.hpp:200
Result run()
Run the Matcher object.
Definition matcher_base.hpp:217
virtual std::string failure_message_when_negated()
Get the matcher's own message for a failed negated match; the handler puts any custom message above i...
Definition matcher_base.hpp:190
static constexpr std::string_view empty_failure_message
What a failure reports in place of a matcher's own message that is empty.
Definition matcher_base.hpp:144
virtual std::string failure_message()
Get the matcher's own message for a failed match; the handler puts any custom message above it.
Definition matcher_base.hpp:180
std::string full_failure_message_when_negated()
What a failed negated match reports: the custom message, when one was set, on the line above the matc...
Definition matcher_base.hpp:139
virtual MatcherBase & set_message(std::string message)
Set a custom failure message.
Definition matcher_base.hpp:169
Definition have_error.hpp:9
Checks whether T is text that CppSpec::string_view_of() can view: a C string, or a type that converts...
Definition util.hpp:201
Contains the primary handlers for running Matchers.
std::string no_text_to_search(const A &actual)
The line a matcher that searches text puts below its own message when the actual value is a null C st...
Definition matcher_base.hpp:35
constexpr std::string_view nothing_to_look_for
The line a matcher that searches text puts below its own message when the text or pattern it looks fo...
Definition matcher_base.hpp:48
std::string no_text_to_look_for(const E &expected)
The line nothing_to_look_for when the expected value is a null C string.
Definition matcher_base.hpp:57
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:144
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:273
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:255
std::string demangle(const char *name)
Definition util.hpp:77
constexpr std::optional< std::string_view > string_view_of(const T &text)
View text as a std::string_view, the one form the string matchers and the printer compare and print.
Definition util.hpp:337