8namespace CppSpec::Matchers {
16template <
typename A,
typename E>
17class Equal :
public MatcherBase<A, E> {
27 std::string verb()
override {
return "equal"; }
33 bool match()
override;
34 bool expected_is_a_literal();
35 std::string comparison();
36 std::string actual_inspected();
37 std::string simple_failure_message();
41template <
typename A,
typename E>
48 return simple_failure_message();
51template <
typename A,
typename E>
54 ss <<
"expected not " << Pretty::inspect_object(MatcherBase<A, E>::expected()) << std::endl;
55 ss <<
" got " << actual_inspected() << std::endl;
60template <
typename A,
typename E>
61std::string Equal<A, E>::simple_failure_message() {
63 ss <<
"expected " << Pretty::inspect_object(MatcherBase<A, E>::expected()) << std::endl;
64 ss <<
" got " << actual_inspected() << std::endl;
69template <
typename A,
typename E>
70bool Equal<A, E>::diffable() {
71 return !expected_is_a_literal();
75template <
typename A,
typename E>
76bool Equal<A, E>::match() {
77 if constexpr (compares_text) {
78 return string_view_of(this->actual()) == string_view_of(this->expected());
80 return this->
expected() == this->actual();
84template <
typename A,
typename E>
85std::string Equal<A, E>::comparison() {
86 if constexpr (compares_text) {
88 return "A null C string equals only another null C string";
91 return "Compared using `==`";
94template <
typename A,
typename E>
95bool Equal<A, E>::expected_is_a_literal() {
96 return (
typeid(E) ==
typeid(
bool));
106template <
typename A,
typename E>
107std::string Equal<A, E>::actual_inspected() {
108 return Pretty::inspect_object(MatcherBase<A, E>::actual());
Wraps the target of an expectation.
Definition expectation.hpp:48
static constexpr bool compares_text
Whether the two values are compared as text, through string_view_of(), whatever form each is in,...
Definition equal.hpp:25
std::string failure_message_when_negated() override
Get the matcher's own message for a failed negated match; the handler puts any custom message above i...
Definition equal.hpp:52
std::string failure_message() override
Get the matcher's own message for a failed match; the handler puts any custom message above it.
Definition equal.hpp:42
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 base class for all Matchers.
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