C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
satisfy.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <string>
5
6#include "matcher_base.hpp"
7
8namespace CppSpec::Matchers {
9//
10// template <class D>
11// class BeHelpers {
12// protected:
13// std::string parenthesize(std::string string) { return "(" + string + ")"; }
14// std::string expected_to_sentence() {
15// return this->split_words(this->expected());
16// }
17//};
18
19template <typename A>
20class Satisfy : public MatcherBase<A, bool> //, BeHelpers<Satisfy<A>>
21{
22 std::function<bool(A)> test;
23
24 public:
25 Satisfy(Expectation<A>& expectation, std::function<bool(A)> test) : MatcherBase<A, bool>(expectation), test(test) {}
26
27 std::string failure_message() override;
28 std::string failure_message_when_negated() override;
29 std::string verb() override { return "be"; }
30
31 bool match() override;
32};
33
34template <typename A>
36 return std::format("expected {} to evaluate to true", MatcherBase<A, bool>::actual());
37}
38
39template <typename A>
41 return std::format("expected {} to evaluate to false", MatcherBase<A, bool>::actual());
42}
43
44template <typename A>
45bool Satisfy<A>::match() {
46 return test(this->actual());
47}
48
49} // namespace CppSpec::Matchers
Wraps the target of an expectation.
Definition expectation.hpp:47
std::string failure_message() override
Get message to give on match failure.
Definition satisfy.hpp:35
std::string failure_message_when_negated() override
Get message to give on match failure when negated.
Definition satisfy.hpp:40
Contains the base class for all Matchers.