C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
it.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <source_location>
5#include <string>
6#include <utility>
7#include <vector>
8
9#include "expectations/expectation.hpp"
10
11namespace CppSpec {
12
27class ItD : public ItBase {
28 public:
29 using Block = std::function<void(ItD&)>;
30
31 private:
33 const Block block;
34
35 public:
52 ItD(std::source_location location, const char* description, Block block)
53 : ItBase(location, description), block(std::move(block)) {}
54
72 ItD(std::source_location location, Block block) : ItBase(location), block(block) {}
73
74 // implemented in description.hpp
75 void run() override;
76};
77
88template <typename T>
89class ItCD : public ItBase {
90 public:
91 using Block = std::function<void(ItCD<T>&)>;
92
93 private:
95 const Block block;
96
97 public:
106
107 // This is only ever instantiated by ClassDescription<T>
108 ItCD(std::source_location location, T& subject, const char* description, Block block)
109 : ItBase(location, description), block(block), subject(subject) {}
110
111 ItCD(std::source_location location, T& subject, Block block) : ItBase(location), block(block), subject(subject) {}
112
113 ExpectationValue<T> is_expected(std::source_location location = std::source_location::current()) {
114 return {*this, subject, location};
115 }
116 void run() override;
117};
118
128template <Util::is_not_functional T>
129ExpectationValue<T> ItBase::expect(T value, std::source_location location) {
130 return {*this, value, location};
131}
132
133template <Util::is_functional T>
134ExpectationFunc<T> ItBase::expect(T block, std::source_location location) {
135 return {*this, block, location};
136}
137
138template <typename T>
139ExpectationValue<T> ItBase::expect(Let<T>& let, std::source_location location) {
140 return {*this, let.value(), location};
141}
142
150template <typename T>
152 std::source_location location) {
153 return {*this, init_list, location};
154}
155
156inline ExpectationValue<std::string> ItBase::expect(const char* str, std::source_location location) {
157 return {*this, std::string(str), location};
158}
159
160} // namespace CppSpec
Definition expectation.hpp:438
Definition expectation.hpp:397
Base class for it expressions.
Definition it_base.hpp:32
ExpectationValue< T > expect(T value, std::source_location location=std::source_location::current())
The expect object generator for objects and LiteralTypes.
Definition it.hpp:129
An it embedded in a ClassDescription.
Definition it.hpp:89
T & subject
A reference to the parent ClassDescription's subject.
Definition it.hpp:105
ItD(std::source_location location, const char *description, Block block)
The primary ItD constructor.
Definition it.hpp:52
ItD(std::source_location location, Block block)
The anonymous ItD constructor.
Definition it.hpp:72
A container that memoizes the result of a block in `it's.
Definition let.hpp:34