@@ -19,9 +19,9 @@ namespace CppSpec {
19
19
*/
20
20
template <class T >
21
21
class ClassDescription : public Description {
22
- typedef std::function<void (ClassDescription<T> &)> block_t ;
23
- block_t body;
24
- bool first ;
22
+ using Block = std::function<void (ClassDescription<T> &)>;
23
+
24
+ Block block ;
25
25
std::string type = " " ;
26
26
27
27
public:
@@ -30,80 +30,80 @@ class ClassDescription : public Description {
30
30
// Constructor
31
31
// if there's no explicit subject given, then use
32
32
// the default constructor of the given type as the implicit subject.
33
- ClassDescription<T>(block_t body )
33
+ ClassDescription<T>(Block block )
34
34
: Description(),
35
- body (body ),
35
+ block (block ),
36
36
type(" : " + Util::demangle(typeid (T).name())),
37
37
subject(T()) {
38
- this ->descr = Pretty::to_word (subject);
38
+ this ->description = Pretty::to_word (subject);
39
39
}
40
40
41
- ClassDescription<T>(std::string descr, block_t body )
42
- : Description(descr ), body(body ), subject(T()) {}
41
+ ClassDescription<T>(std::string description, Block block )
42
+ : Description(description ), block(block ), subject(T()) {}
43
43
44
- ClassDescription (T subject, block_t body )
44
+ ClassDescription (T subject, Block block )
45
45
: Description(Pretty::to_word(subject)),
46
- body (body ),
46
+ block (block ),
47
47
type(" : " + Util::demangle(typeid (T).name())),
48
48
subject(subject) {}
49
49
50
- ClassDescription (std::string descr , T subject, block_t body )
51
- : Description(descr ), body(body ), subject(subject) {}
50
+ ClassDescription (std::string description , T subject, Block block )
51
+ : Description(description ), block(block ), subject(subject) {}
52
52
53
- ClassDescription (T &subject, block_t body )
53
+ ClassDescription (T &subject, Block block )
54
54
: Description(Pretty::to_word(subject)),
55
- body(body ),
55
+ block(block ),
56
56
type(" : " + Util::demangle(typeid (T).name())),
57
57
subject(subject) {}
58
58
59
- // ClassDescription(std::string descr, T &subject, block_t body)
60
- // : Description(descr), body(body), subject(subject) {}
61
-
62
59
template <typename U>
63
- ClassDescription (std::initializer_list<U> init_list, block_t body )
64
- : body(body ),
60
+ ClassDescription (std::initializer_list<U> init_list, Block block )
61
+ : block(block ),
65
62
type(" : " + Util::demangle(typeid (T).name())),
66
63
subject(T(init_list)) {
67
- this ->descr = Pretty::to_word (subject);
64
+ this ->description = Pretty::to_word (subject);
68
65
}
69
66
70
67
template <typename U>
71
- ClassDescription (std::string descr , std::initializer_list<U> init_list,
72
- block_t body )
73
- : Description(descr ), body(body ), subject(T(init_list)) {}
68
+ ClassDescription (std::string description , std::initializer_list<U> init_list,
69
+ Block block )
70
+ : Description(description ), block(block ), subject(T(init_list)) {}
74
71
75
72
ClassDescription<T>(Description &d) : Description(d) {}
76
73
77
74
const bool has_subject = true ;
78
75
79
- Result it (std::string descr , std::function<void (ItCd <T> &)> body );
80
- Result it (std::function<void (ItCd <T> &)> body );
76
+ Result it (std::string description , std::function<void (ItCD <T> &)> block );
77
+ Result it (std::function<void (ItCD <T> &)> block );
81
78
/* * @brief an alias for it */
82
- Result specify (std::string descr, std::function<void (ItCd<T> &)> body) {
83
- return it (descr, body);
79
+ Result specify (std::string description,
80
+ std::function<void (ItCD<T> &)> block) {
81
+ return it (description, block);
84
82
}
85
83
/* * @brief an alias for it */
86
- Result specify (std::function<void (ItCd <T> &)> body ) { return it (body ); }
84
+ Result specify (std::function<void (ItCD <T> &)> block ) { return it (block ); }
87
85
88
86
template <class U >
89
- Result context (std::string descr , U subject,
90
- std::function<void (ClassDescription<U> &)> body );
87
+ Result context (std::string description , U subject,
88
+ std::function<void (ClassDescription<U> &)> block );
91
89
template <class U >
92
- Result context (std::string descr , U &subject,
93
- std::function<void (ClassDescription<U> &)> body );
90
+ Result context (std::string description , U &subject,
91
+ std::function<void (ClassDescription<U> &)> block );
94
92
template <class U >
95
- Result context (U subject, std::function<void (ClassDescription<U> &)> body );
93
+ Result context (U subject, std::function<void (ClassDescription<U> &)> block );
96
94
template <class U >
97
- Result context (U &subject, std::function<void (ClassDescription<U> &)> body );
95
+ Result context (U &subject, std::function<void (ClassDescription<U> &)> block );
98
96
99
- Result context (std::string descr, std::function<void (ClassDescription<T> &)> body);
97
+ Result context (std::string description,
98
+ std::function<void (ClassDescription<T> &)> block);
100
99
101
100
Result run (Formatters::BaseFormatter &printer) override ;
102
101
103
- std::string get_descr () override { return descr; }
104
- const std::string get_descr () const override { return descr; }
105
- std::string get_subject_type () override { return type; }
106
- const std::string get_subject_type () const override { return type; }
102
+ // std::string get_descr() noexcept override { return description; }
103
+ // const std::string get_descr() const noexcept override { return
104
+ // description; }
105
+ std::string get_subject_type () noexcept override { return type; }
106
+ const std::string get_subject_type () const noexcept override { return type; }
107
107
};
108
108
109
109
template <class T >
@@ -112,9 +112,9 @@ using ClassContext = ClassDescription<T>;
112
112
template <class T >
113
113
template <class U >
114
114
Result ClassDescription<T>::context(
115
- std::string descr , U subject,
116
- std::function<void (ClassDescription<U> &)> body ) {
117
- ClassContext<U> context (descr , subject, body );
115
+ std::string description , U subject,
116
+ std::function<void (ClassDescription<U> &)> block ) {
117
+ ClassContext<U> context (description , subject, block );
118
118
context.set_parent (this );
119
119
context.ClassContext <U>::before_eaches = this ->before_eaches ;
120
120
context.ClassContext <U>::after_eaches = this ->after_eaches ;
@@ -124,16 +124,16 @@ Result ClassDescription<T>::context(
124
124
template <class T >
125
125
template <class U >
126
126
Result ClassDescription<T>::context(
127
- U subject, std::function<void (ClassDescription<U> &)> body ) {
128
- return context (" " , std::forward<U>(subject), body );
127
+ U subject, std::function<void (ClassDescription<U> &)> block ) {
128
+ return this -> context (" " , std::forward<U>(subject), block );
129
129
}
130
130
131
131
template <class T >
132
132
template <class U >
133
133
Result ClassDescription<T>::context(
134
- std::string descr , U &subject,
135
- std::function<void (ClassDescription<U> &)> body ) {
136
- ClassContext<U> context (descr , subject, body );
134
+ std::string description , U &subject,
135
+ std::function<void (ClassDescription<U> &)> block ) {
136
+ ClassContext<U> context (description , subject, block );
137
137
context.set_parent (this );
138
138
context.ClassContext <U>::before_eaches = this ->before_eaches ;
139
139
context.ClassContext <U>::after_eaches = this ->after_eaches ;
@@ -143,14 +143,14 @@ Result ClassDescription<T>::context(
143
143
template <class T >
144
144
template <class U >
145
145
Result ClassDescription<T>::context(
146
- U &subject, std::function<void (ClassDescription<U> &)> body ) {
147
- return context (" " , std::forward<U>(subject), body );
146
+ U &subject, std::function<void (ClassDescription<U> &)> block ) {
147
+ return this -> context (" " , std::forward<U>(subject), block );
148
148
}
149
149
150
150
template <class T >
151
- Result ClassDescription<T>::context(std::string descr,
152
- std::function<void (ClassDescription<T> &)> body ) {
153
- ClassContext<T> context (descr , this ->subject , body );
151
+ Result ClassDescription<T>::context(
152
+ std::string description, std:: function<void (ClassDescription<T> &)> block ) {
153
+ ClassContext<T> context (description , this ->subject , block );
154
154
context.set_parent (this );
155
155
context.before_eaches = this ->before_eaches ;
156
156
context.after_eaches = this ->after_eaches ;
@@ -159,31 +159,24 @@ Result ClassDescription<T>::context(std::string descr,
159
159
160
160
template <class T >
161
161
Result Description::context (T subject,
162
- std::function<void (ClassDescription<T> &)> body ) {
163
- return this ->context (" " , subject, body );
162
+ std::function<void (ClassDescription<T> &)> block ) {
163
+ return this ->context (" " , subject, block );
164
164
}
165
165
166
166
template <class T >
167
- Result Description::context (std::string descr , T subject,
168
- std::function<void (ClassDescription<T> &)> body ) {
169
- ClassContext<T> context (descr , subject, body );
167
+ Result Description::context (std::string description , T subject,
168
+ std::function<void (ClassDescription<T> &)> block ) {
169
+ ClassContext<T> context (description , subject, block );
170
170
context.set_parent (this );
171
171
context.before_eaches = this ->before_eaches ;
172
172
context.after_eaches = this ->after_eaches ;
173
173
return context.run (this ->get_formatter ());
174
174
}
175
175
176
-
177
- // template <class T>
178
- // ClassContext<T>& Description::context(
179
- // T& subject, std::function<void(ClassDescription<T>&)> body) {
180
- // return context(subject, body);
181
- // }
182
-
183
176
template <class T , typename U>
184
177
Result Description::context (std::initializer_list<U> init_list,
185
- std::function<void (ClassDescription<T> &)> body ) {
186
- ClassContext<T> context (T (init_list), body );
178
+ std::function<void (ClassDescription<T> &)> block ) {
179
+ ClassContext<T> context (T (init_list), block );
187
180
context.set_parent (this );
188
181
context.before_eaches = this ->before_eaches ;
189
182
context.after_eaches = this ->after_eaches ;
@@ -194,7 +187,7 @@ Result Description::context(std::initializer_list<U> init_list,
194
187
* Jasmine-style `it` declaration, with an explicit docstring
195
188
* provided for verbose printing.
196
189
*
197
- * As this is an ItCd , it passes along associated type information
190
+ * As this is an ItCD , it passes along associated type information
198
191
* about the implicit subject from the containing
199
192
* ClassDescription / ClassContext.
200
193
*
@@ -207,14 +200,14 @@ Result Description::context(std::initializer_list<U> init_list,
207
200
* @endcode
208
201
*
209
202
* @param name the name of the test
210
- * @param body the contents of test
203
+ * @param block the contents of test
211
204
*
212
205
* @return the result of the test
213
206
*/
214
207
template <class T >
215
208
Result ClassDescription<T>::it(std::string name,
216
- std::function<void (ItCd <T> &)> body ) {
217
- ItCd <T> it (*this , this ->subject , name, body );
209
+ std::function<void (ItCD <T> &)> block ) {
210
+ ItCD <T> it (*this , this ->subject , name, block );
218
211
Result result = it.run (this ->get_formatter ());
219
212
exec_after_eaches ();
220
213
exec_before_eaches ();
@@ -228,7 +221,7 @@ Result ClassDescription<T>::it(std::string name,
228
221
* is a desire to be verbose, as each expectation prints its
229
222
* own docstring.
230
223
*
231
- * As this is an ItCd , it passes along associated type information
224
+ * As this is an ItCD , it passes along associated type information
232
225
* about the implicit subject from the containing
233
226
* ClassDescription / ClassContext.
234
227
*
@@ -238,13 +231,13 @@ Result ClassDescription<T>::it(std::string name,
238
231
* });
239
232
* @endcode
240
233
*
241
- * @param body the contents of the test
234
+ * @param block the contents of the test
242
235
*
243
236
* @return the result of the test
244
237
*/
245
238
template <class T >
246
- Result ClassDescription<T>::it(std::function<void (ItCd <T> &)> body ) {
247
- ItCd <T> it (*this , this ->subject , body );
239
+ Result ClassDescription<T>::it(std::function<void (ItCD <T> &)> block ) {
240
+ ItCD <T> it (*this , this ->subject , block );
248
241
Result result = it.run (this ->get_formatter ());
249
242
exec_after_eaches ();
250
243
exec_before_eaches ();
@@ -255,29 +248,23 @@ template <class T>
255
248
Result ClassDescription<T>::run(Formatters::BaseFormatter &printer) {
256
249
if (not this ->has_formatter ()) this ->set_printer (printer);
257
250
printer.format (*this );
258
- body (*this );
259
- for (auto a : after_alls) a ();
251
+ this -> block (*this );
252
+ for (const auto & a : after_alls) a ();
260
253
if (this ->get_parent () == nullptr ) printer.flush ();
261
254
return this ->get_status () ? Result::success () : Result::failure ();
262
255
}
263
256
264
257
template <class T >
265
- Expectations::ExpectationValue <T> ItCd <T>::is_expected() {
258
+ Expectations::ExpectationValue<T> ItCD <T>::is_expected() {
266
259
auto cd = static_cast <ClassDescription<T> *>(this ->get_parent ());
267
260
Expectations::ExpectationValue<T> expectation (*this , cd->subject );
268
261
return expectation;
269
262
}
270
263
271
264
template <class T >
272
- Result ItCd<T>::run(Formatters::BaseFormatter &printer) {
273
- // if (!this->needs_descr() && printer.mode == BaseFormatter::Mode::verbose)
274
- // {
275
- // printer.format(*this);
276
- // }
277
-
278
- body (*this );
265
+ Result ItCD<T>::run(Formatters::BaseFormatter &printer) {
266
+ this ->block (*this );
279
267
printer.format (*this );
280
-
281
268
auto cd = static_cast <ClassDescription<T> *>(this ->get_parent ());
282
269
cd->reset_lets ();
283
270
return this ->get_status () ? Result::success () : Result::failure ();
0 commit comments