3#include <source_location>
22class ClassDescription :
public Description {
23 using Block = std::function<void(ClassDescription<T>&)>;
34 ClassDescription(Block block, std::source_location location = std::source_location::current())
40 ClassDescription(
const char* description,
42 std::source_location location = std::source_location::current())
43 : Description(location, description), block(block), subject(T()) {}
45 ClassDescription(
const char* description,
48 std::source_location location = std::source_location::current())
49 : Description(location, description), block(block), subject(subject) {}
51 template <Util::not_c_
string U>
52 ClassDescription(U& subject, Block block, std::source_location location = std::source_location::current())
58 ClassDescription(
const char* description,
61 std::source_location location = std::source_location::current())
62 : Description(location, description), block(block), subject(std::move(subject)) {}
64 template <Util::not_c_
string U>
65 ClassDescription(U&& subject, Block block, std::source_location location = std::source_location::current())
69 subject(std::forward<U>(subject)) {}
72 ClassDescription(std::initializer_list<U> init_list,
74 std::source_location location = std::source_location::current())
78 subject(T(init_list)) {}
81 ClassDescription(
const char* description,
82 std::initializer_list<U> init_list,
84 std::source_location location = std::source_location::current())
85 : Description(location, description), block(block), subject(T(init_list)) {}
88 std::function<
void(
ItCD<T>&)> block,
89 std::source_location location = std::source_location::current());
90 ItCD<T>&
it(std::function<
void(
ItCD<T>&)> block, std::source_location location = std::source_location::current());
92 template <
class U = std::
nullptr_t,
class B>
93 ClassDescription<T>& context(
const char* description,
95 std::source_location location = std::source_location::current());
97 template <
class U,
class B>
98 ClassDescription<U>& context(
const char* description,
101 std::source_location location = std::source_location::current());
103 template <
class U,
class B>
104 ClassDescription<U>& context(U& subject, B block, std::source_location location = std::source_location::current()) {
105 return this->context(
"", subject, block, location);
108 template <
class U,
class B>
109 ClassDescription<U>& context(
const char* description,
112 std::source_location location = std::source_location::current());
114 template <
class U,
class B>
115 ClassDescription<U>& context(U&& subject, B block, std::source_location location = std::source_location::current()) {
116 return this->context(
"", std::forward<U>(subject), block, location);
120 [[nodiscard]] std::string get_subject_type()
const noexcept override {
return type; }
123template <Util::not_c_
string U>
126template <Util::not_c_
string U>
133template <
class U,
class B>
134ClassContext<U>& ClassDescription<T>::context(
const char* description,
137 std::source_location location) {
138 auto* context = this->make_child<ClassContext<U>>(description, subject, block, location);
139 context->ClassContext<U>::before_eaches = this->before_eaches;
140 context->ClassContext<U>::after_eaches = this->after_eaches;
141 context->timed_run();
146template <
class U,
class B>
147ClassContext<U>& ClassDescription<T>::context(
const char* description,
150 std::source_location location) {
151 auto* context = this->make_child<ClassContext<U>>(description, std::forward<U>(subject), block, location);
152 context->ClassContext<U>::before_eaches = this->before_eaches;
153 context->ClassContext<U>::after_eaches = this->after_eaches;
154 context->timed_run();
159template <
class U,
class B>
160ClassContext<T>& ClassDescription<T>::context(
const char* description, B block, std::source_location location) {
161 auto* context = this->make_child<ClassContext<T>>(description, this->subject, block, location);
162 context->before_eaches = this->before_eaches;
163 context->after_eaches = this->after_eaches;
164 context->timed_run();
168template <Util::not_c_
string T,
class B>
169ClassContext<T>& Description::context(T& subject, B block, std::source_location location) {
170 auto* context = this->make_child<ClassContext<T>>(subject, block, location);
171 context->before_eaches = this->before_eaches;
172 context->after_eaches = this->after_eaches;
173 context->timed_run();
177template <
class T,
class B>
178ClassContext<T>& Description::context(
const char* description, T& subject, B block, std::source_location location) {
179 auto* context = this->make_child<ClassContext<T>>(description, subject, block, location);
180 context->before_eaches = this->before_eaches;
181 context->after_eaches = this->after_eaches;
182 context->timed_run();
186template <Util::not_c_
string T,
class B>
187ClassContext<T>& Description::context(T&& subject, B block, std::source_location location) {
188 auto* context = this->make_child<ClassContext<T>>(std::forward<T>(subject), block, location);
189 context->before_eaches = this->before_eaches;
190 context->after_eaches = this->after_eaches;
191 context->timed_run();
195template <
class T,
class B>
196ClassContext<T>& Description::context(
const char* description, T&& subject, B block, std::source_location location) {
197 auto* context = this->make_child<ClassContext<T>>(description, std::forward<T>(subject), block, location);
198 context->before_eaches = this->before_eaches;
199 context->after_eaches = this->after_eaches;
200 context->timed_run();
204template <
class T,
typename U>
205ClassContext<T>& Description::context(std::initializer_list<U> init_list,
207 std::source_location location) {
208 auto* context = this->make_child<ClassContext<T>>(T(init_list), block, location);
209 context->before_eaches = this->before_eaches;
210 context->after_eaches = this->after_eaches;
211 context->timed_run();
238 auto*
it = this->make_child<ItCD<T>>(location, this->subject, name, block);
241 exec_before_eaches();
268 auto*
it = this->make_child<ItCD<T>>(location, this->subject, block);
271 exec_before_eaches();
276void ClassDescription<T>::run() {
278 for (
const auto& a : after_alls) {
286 auto* cd = this->get_parent_as<ClassDescription<T>>();
A Description with a defined subject.
Definition class_description.hpp:22
ItCD< T > & it(const char *name, std::function< void(ItCD< T > &)> block, std::source_location location=std::source_location::current())
Definition class_description.hpp:237
An it embedded in a ClassDescription.
Definition it.hpp:89
Defines the Description class and associated functions.
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:122
std::string demangle(const char *name)
Definition util.hpp:38