C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
have_value.hpp
1#pragma once
2
3#include "matchers/equal.hpp"
5
6namespace CppSpec::Matchers {
7
8template <typename T>
9concept optional = requires(T t) {
10 { t.has_value() } -> std::same_as<bool>;
11};
12
13template <optional T>
14class HaveValue : public MatcherBase<T, void*> {
15 public:
16 HaveValue(Expectation<T>& expectation) : MatcherBase<T, void*>(expectation) {}
17
18 std::string verb() override { return "have"; }
19 std::string description() override { return "have a value"; }
20
21 bool match() override { return (this->actual().has_value()); }
22};
23
24template <optional T, typename E>
25class HaveValueEqualTo : public Equal<T, E> {
26 public:
27 static_assert(std::is_same_v<typename T::value_type, E>, "the contained value_type must match the expected type");
28 HaveValueEqualTo(Expectation<T>& expectation, E expected) : Equal<T, E>(expectation, expected) {}
29
30 bool match() { return (this->actual().value() == this->expected()); }
31};
32
33} // namespace CppSpec::Matchers
Wraps the target of an expectation.
Definition expectation.hpp:47
std::string description() override
Get the description of the Matcher.
Definition have_value.hpp:19
Definition have_error.hpp:9
Definition have_value.hpp:9
Contains the base class for all Matchers.