10namespace CppSpec::Matchers {
16template <
typename A,
typename E,
typename U>
17class ContainBase :
public MatcherBase<A, E> {
21 std::string verb()
override {
return "contain"; }
25 virtual bool diffable() {
return true; }
28 :
MatcherBase<A, std::vector<U>>(expectation, std::vector<U>(
expected)), actual_(this->actual()) {};
30 : MatcherBase<A, U>(expectation, expected), actual_(this->actual()) {};
33 bool actual_collection_includes(U expected_item);
51 bool collection_includes(U expected_item);
54template <
typename A,
typename E,
typename U>
60template <
typename A,
typename E,
typename U>
65template <
typename A,
typename E,
typename U>
70template <
typename A,
typename E,
typename U>
78template <
typename A,
typename E,
typename U>
79bool ContainBase<A, E, U>::actual_collection_includes(U expected_item) {
84 return text && part && text->contains(*part);
86 return text && text->contains(expected_item);
89 return collection_includes(expected_item);
93template <
typename A,
typename E,
typename U>
103template <
typename A,
typename E,
typename U>
106 if constexpr (std::same_as<E, U>) {
118template <
typename A,
typename E,
typename U>
119bool ContainBase<A, E, U>::collection_includes(U expected_item) {
121 "Expected item is not comparable against what is inside container.");
122 auto& actual = this->actual();
123 return std::ranges::find(actual, expected_item) != std::ranges::end(actual);
130template <
typename A,
typename E,
typename U>
132 enum class Predicate { any, all, none };
135 bool match()
override;
136 bool negated_match()
override;
137 using ContainBase<A, E, U>::ContainBase;
140 bool perform_match(Predicate predicate, Predicate hash_subset_predicate);
143template <
typename A,
typename E,
typename U>
144bool Contain<A, E, U>::match() {
145 return !this->actual_is_null_text() && !this->expected_is_null_text() &&
146 perform_match(Predicate::all, Predicate::all);
149template <
typename A,
typename E,
typename U>
150bool Contain<A, E, U>::negated_match() {
151 return !this->actual_is_null_text() && !this->expected_is_null_text() &&
152 perform_match(Predicate::none, Predicate::any);
156template <
typename A,
typename E,
typename U>
157bool Contain<A, E, U>::perform_match(Predicate predicate, Predicate ) {
159 for (U expected_item : this->expected()) {
160 retval = retval && this->actual_collection_includes(expected_item);
170 case Predicate::none:
191template <
typename A,
typename U>
192class Contain<A, U, U> :
public ContainBase<A, U, U> {
196 bool match()
override;
197 bool negated_match()
override;
200template <
typename A,
typename U>
201bool Contain<A, U, U>::match() {
202 return this->actual_collection_includes(this->
expected());
205template <
typename A,
typename U>
206bool Contain<A, U, U>::negated_match() {
207 return !this->actual_is_null_text() && !this->expected_is_null_text() && !match();
Wraps the target of an expectation.
Definition expectation.hpp:48
Definition contain.hpp:17
std::string failure_message() override
Get the matcher's own message for a failed match; the handler puts any custom message above it.
Definition contain.hpp:61
bool expected_is_null_text()
Whether the actual value is text and a piece of text to look for in it is a null C string,...
Definition contain.hpp:104
std::string null_text_notes()
The lines that say why there is no text to search or nothing to look for, or an empty string.
Definition contain.hpp:71
bool actual_is_null_text()
Whether the actual value is a null C string, which is no text, so the matcher fails it negated as wel...
Definition contain.hpp:94
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 contain.hpp:66
std::string description() override
Get the description of the Matcher.
Definition contain.hpp:55
Definition contain.hpp:131
the base class for all Matcher classes and objects
Definition matcher_base.hpp:77
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
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
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.
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
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:255
Helper class for static assertions that has a built-in error string.
Definition util.hpp:86
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