5namespace CppSpec::Matchers {
11template <
typename A,
typename E,
typename U>
12class ContainBase :
public MatcherBase<A, E> {
16 std::string verb()
override {
return "contain"; }
20 virtual bool diffable() {
return true; }
23 :
MatcherBase<A, std::vector<U>>(expectation, std::vector<U>(
expected)), actual_(this->actual()) {};
25 : MatcherBase<A, U>(expectation, expected), actual_(this->actual()) {};
28 bool actual_collection_includes(U expected_item);
31template <
typename A,
typename E,
typename U>
37template <
typename A,
typename E,
typename U>
42template <
typename A,
typename E,
typename U>
47template <
typename A,
typename E,
typename U>
48bool ContainBase<A, E, U>::actual_collection_includes(U expected_item) {
49 auto actual = this->actual();
50 auto last = *(actual.begin());
52 "Expected item is not comparable against what is inside container.");
53 return std::ranges::find(actual, expected_item) != actual.end();
60template <
typename A,
typename E,
typename U>
61class Contain :
public ContainBase<A, E, U> {
62 enum class Predicate { any, all, none };
65 bool match()
override;
66 bool negated_match()
override;
67 using ContainBase<A, E, U>::ContainBase;
70 bool perform_match(Predicate predicate, Predicate hash_subset_predicate);
73template <
typename A,
typename E,
typename U>
74bool Contain<A, E, U>::match() {
75 return perform_match(Predicate::all, Predicate::all);
78template <
typename A,
typename E,
typename U>
79bool Contain<A, E, U>::negated_match() {
80 return perform_match(Predicate::none, Predicate::any);
84template <
typename A,
typename E,
typename U>
85bool Contain<A, E, U>::perform_match(Predicate predicate, Predicate ) {
87 for (U expected_item : this->expected()) {
88 retval = retval && this->actual_collection_includes(expected_item);
119template <
typename A,
typename U>
120class Contain<A, U, U> :
public ContainBase<A, U, U> {
124 bool match()
override;
127template <
typename A,
typename U>
128bool Contain<A, U, U>::match() {
129 return this->actual_collection_includes(this->
expected());
Wraps the target of an expectation.
Definition expectation.hpp:47
Definition contain.hpp:12
std::string failure_message() override
Get message to give on match failure.
Definition contain.hpp:38
std::string failure_message_when_negated() override
Get message to give on match failure when negated.
Definition contain.hpp:43
std::string description() override
Get the description of the Matcher.
Definition contain.hpp:32
Definition contain.hpp:61
the base class for all Matcher classes and objects
Definition matcher_base.hpp:37
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
Definition have_error.hpp:9
Contains the base class for all Matchers.
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:106
Helper class for static assertions that has a built-in error string.
Definition util.hpp:47