@@ -43,19 +43,27 @@ class ClassDescription : public Description {
43
43
std::source_location location = std::source_location::current())
44
44
: Description(location, description), block(block), subject(T()) {}
45
45
46
- ClassDescription (T subject, Block block, std::source_location location = std::source_location::current())
46
+ ClassDescription (const char * description,
47
+ T& subject,
48
+ Block block,
49
+ std::source_location location = std::source_location::current())
50
+ : Description(location, description), block(block), subject(subject) {}
51
+
52
+ template <Util::not_c_string U>
53
+ ClassDescription (U& subject, Block block, std::source_location location = std::source_location::current())
47
54
: Description(location, Pretty::to_word(subject)),
48
55
block (block),
49
56
type(" : " + Util::demangle(typeid (T).name())),
50
57
subject(subject) {}
51
58
52
59
ClassDescription (const char * description,
53
- T subject,
60
+ T&& subject,
54
61
Block block,
55
62
std::source_location location = std::source_location::current())
56
- : Description(location, description), block(block), subject(subject) {}
63
+ : Description(location, description), block(block), subject(std::move( subject) ) {}
57
64
58
- ClassDescription (T&& subject, Block block, std::source_location location = std::source_location::current())
65
+ template <Util::not_c_string U>
66
+ ClassDescription (U&& subject, Block block, std::source_location location = std::source_location::current())
59
67
: Description(location, Pretty::to_word(subject)),
60
68
block(block),
61
69
type(" : " + Util::demangle(typeid (T).name())),
@@ -89,53 +97,59 @@ class ClassDescription : public Description {
89
97
90
98
template <class U , class B >
91
99
ClassDescription<U>& context (const char * description,
92
- U subject,
100
+ U& subject,
93
101
B block,
94
102
std::source_location location = std::source_location::current());
103
+
104
+ template <class U , class B >
105
+ ClassDescription<U>& context (U& subject, B block, std::source_location location = std::source_location::current()) {
106
+ return this ->context (" " , subject, block, location);
107
+ }
108
+
95
109
template <class U , class B >
96
110
ClassDescription<U>& context (const char * description,
97
- U& subject,
111
+ U&& subject,
98
112
B block,
99
113
std::source_location location = std::source_location::current());
100
- template <class U , class B >
101
- ClassDescription<U>& context (U subject, B block, std::source_location location = std::source_location::current());
102
114
115
+ template <class U , class B >
116
+ ClassDescription<U>& context (U&& subject, B block, std::source_location location = std::source_location::current()) {
117
+ return this ->context (" " , subject, block, location);
118
+ }
103
119
void run () override ;
104
120
105
121
[[nodiscard]] std::string get_subject_type () const noexcept override { return type; }
106
122
};
107
123
124
+ template <Util::not_c_string U>
125
+ ClassDescription (U&, std::function<void (ClassDescription<U>&)>, std::source_location) -> ClassDescription<U>;
126
+
127
+ template <Util::not_c_string U>
128
+ ClassDescription (U&&, std::function<void (ClassDescription<U>&)>, std::source_location) -> ClassDescription<U>;
129
+
108
130
template <class T >
109
131
using ClassContext = ClassDescription<T>;
110
132
111
133
template <class T >
112
134
template <class U , class B >
113
135
ClassContext<U>& ClassDescription<T>::context(const char * description,
114
- U subject,
136
+ U& subject,
115
137
B block,
116
138
std::source_location location) {
117
- auto * context = new ClassContext<U>(description, subject, block, location);
118
- context->set_parent (this );
139
+ auto * context = this ->make_child <ClassContext<U>>(description, subject, block, location);
119
140
context->ClassContext <U>::before_eaches = this ->before_eaches ;
120
141
context->ClassContext <U>::after_eaches = this ->after_eaches ;
121
142
context->timed_run ();
122
143
return *context;
123
144
}
124
145
125
- template <class T >
126
- template <class U , class B >
127
- ClassContext<U>& ClassDescription<T>::context(U subject, B block, std::source_location location) {
128
- return this ->context (" " , std::forward<U>(subject), block, location);
129
- }
130
-
131
146
template <class T >
132
147
template <class U , class B >
133
148
ClassContext<U>& ClassDescription<T>::context(const char * description,
134
- U& subject,
149
+ U&& subject,
135
150
B block,
136
151
std::source_location location) {
137
- auto * context = new ClassContext<U>(description, subject, block, location);
138
- context->set_parent (this );
152
+ auto * context = this ->make_child <ClassContext<U>>(description, subject, block, location);
139
153
context->ClassContext <U>::before_eaches = this ->before_eaches ;
140
154
context->ClassContext <U>::after_eaches = this ->after_eaches ;
141
155
context->timed_run ();
@@ -145,31 +159,43 @@ ClassContext<U>& ClassDescription<T>::context(const char* description,
145
159
template <class T >
146
160
template <class U , class B >
147
161
ClassContext<T>& ClassDescription<T>::context(const char * description, B block, std::source_location location) {
148
- auto * context = new ClassContext<T>(description, this ->subject , block, location);
149
- context->set_parent (this );
162
+ auto * context = this ->make_child <ClassContext<T>>(description, this ->subject , block, location);
163
+ context->before_eaches = this ->before_eaches ;
164
+ context->after_eaches = this ->after_eaches ;
165
+ context->timed_run ();
166
+ return *context;
167
+ }
168
+
169
+ template <Util::not_c_string T, class B >
170
+ ClassContext<T>& Description::context (T& subject, B block, std::source_location location) {
171
+ auto * context = this ->make_child <ClassContext<T>>(subject, block, location);
150
172
context->before_eaches = this ->before_eaches ;
151
173
context->after_eaches = this ->after_eaches ;
152
174
context->timed_run ();
153
175
return *context;
154
176
}
155
177
156
178
template <class T , class B >
157
- requires (!std::is_same_v<T, const char *>)
158
- ClassContext<T>& Description::context (T subject, B block, std::source_location location) {
159
- auto * context = new ClassContext<T>(subject, block, location);
160
- context->set_parent (this );
161
- context->set_location (location);
179
+ ClassContext<T>& Description::context (const char * description, T& subject, B block, std::source_location location) {
180
+ auto * context = this ->make_child <ClassContext<T>>(description, subject, block, location);
181
+ context->before_eaches = this ->before_eaches ;
182
+ context->after_eaches = this ->after_eaches ;
183
+ context->timed_run ();
184
+ return *context;
185
+ }
186
+
187
+ template <Util::not_c_string T, class B >
188
+ ClassContext<T>& Description::context (T&& subject, B block, std::source_location location) {
189
+ auto * context = this ->make_child <ClassContext<T>>(subject, block, location);
162
190
context->before_eaches = this ->before_eaches ;
163
191
context->after_eaches = this ->after_eaches ;
164
192
context->timed_run ();
165
193
return *context;
166
194
}
167
195
168
196
template <class T , class B >
169
- ClassContext<T>& Description::context (const char * description, T subject, B block, std::source_location location) {
170
- auto * context = new ClassContext<T>(description, subject, block, location);
171
- context->set_parent (this );
172
- context->set_location (location);
197
+ ClassContext<T>& Description::context (const char * description, T&& subject, B block, std::source_location location) {
198
+ auto * context = this ->make_child <ClassContext<T>>(description, subject, block, location);
173
199
context->before_eaches = this ->before_eaches ;
174
200
context->after_eaches = this ->after_eaches ;
175
201
context->timed_run ();
@@ -180,8 +206,7 @@ template <class T, typename U>
180
206
ClassContext<T>& Description::context (std::initializer_list<U> init_list,
181
207
std::function<void (ClassDescription<T>&)> block,
182
208
std::source_location location) {
183
- auto * context = new ClassContext<T>(T (init_list), block, location);
184
- context->set_parent (this );
209
+ auto * context = this ->make_child <ClassContext<T>>(T (init_list), block, location);
185
210
context->before_eaches = this ->before_eaches ;
186
211
context->after_eaches = this ->after_eaches ;
187
212
context->timed_run ();
@@ -211,7 +236,7 @@ ClassContext<T>& Description::context(std::initializer_list<U> init_list,
211
236
*/
212
237
template <class T >
213
238
ItCD<T>& ClassDescription<T>::it(const char * name, std::function<void (ItCD<T>&)> block, std::source_location location) {
214
- auto * it = new ItCD<T>(* this , location, this ->subject , name, block);
239
+ auto * it = this -> make_child < ItCD<T>>( location, this ->subject , name, block);
215
240
it->timed_run ();
216
241
exec_after_eaches ();
217
242
exec_before_eaches ();
@@ -241,7 +266,7 @@ ItCD<T>& ClassDescription<T>::it(const char* name, std::function<void(ItCD<T>&)>
241
266
*/
242
267
template <class T >
243
268
ItCD<T>& ClassDescription<T>::it(std::function<void (ItCD<T>&)> block, std::source_location location) {
244
- auto * it = new ItCD<T>(* this , location, this ->subject , block);
269
+ auto * it = this -> make_child < ItCD<T>>( location, this ->subject , block);
245
270
it->timed_run ();
246
271
exec_after_eaches ();
247
272
exec_before_eaches ();
@@ -256,17 +281,10 @@ void ClassDescription<T>::run() {
256
281
}
257
282
}
258
283
259
- template <class T >
260
- ExpectationValue<T> ItCD<T>::is_expected() {
261
- auto cd = this ->get_parent_as <ClassDescription<T>>();
262
- ExpectationValue<T> expectation (*this , cd->subject , std::source_location::current ());
263
- return expectation;
264
- }
265
-
266
284
template <class T >
267
285
void ItCD<T>::run() {
268
286
this ->block (*this );
269
- auto cd = this ->get_parent_as <ClassDescription<T>>();
287
+ auto * cd = this ->get_parent_as <ClassDescription<T>>();
270
288
cd->reset_lets ();
271
289
}
272
290
0 commit comments