@@ -19,9 +19,9 @@ namespace CppSpec {
1919 */
2020template <class T >
2121class 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 ;
2525 std::string type = " " ;
2626
2727 public:
@@ -30,80 +30,80 @@ class ClassDescription : public Description {
3030 // Constructor
3131 // if there's no explicit subject given, then use
3232 // the default constructor of the given type as the implicit subject.
33- ClassDescription<T>(block_t body )
33+ ClassDescription<T>(Block block )
3434 : Description(),
35- body (body ),
35+ block (block ),
3636 type(" : " + Util::demangle(typeid (T).name())),
3737 subject(T()) {
38- this ->descr = Pretty::to_word (subject);
38+ this ->description = Pretty::to_word (subject);
3939 }
4040
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()) {}
4343
44- ClassDescription (T subject, block_t body )
44+ ClassDescription (T subject, Block block )
4545 : Description(Pretty::to_word(subject)),
46- body (body ),
46+ block (block ),
4747 type(" : " + Util::demangle(typeid (T).name())),
4848 subject(subject) {}
4949
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) {}
5252
53- ClassDescription (T &subject, block_t body )
53+ ClassDescription (T &subject, Block block )
5454 : Description(Pretty::to_word(subject)),
55- body(body ),
55+ block(block ),
5656 type(" : " + Util::demangle(typeid (T).name())),
5757 subject(subject) {}
5858
59- // ClassDescription(std::string descr, T &subject, block_t body)
60- // : Description(descr), body(body), subject(subject) {}
61-
6259 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 ),
6562 type(" : " + Util::demangle(typeid (T).name())),
6663 subject(T(init_list)) {
67- this ->descr = Pretty::to_word (subject);
64+ this ->description = Pretty::to_word (subject);
6865 }
6966
7067 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)) {}
7471
7572 ClassDescription<T>(Description &d) : Description(d) {}
7673
7774 const bool has_subject = true ;
7875
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 );
8178 /* * @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);
8482 }
8583 /* * @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 ); }
8785
8886 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 );
9189 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 );
9492 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 );
9694 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 );
9896
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);
10099
101100 Result run (Formatters::BaseFormatter &printer) override ;
102101
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; }
107107};
108108
109109template <class T >
@@ -112,9 +112,9 @@ using ClassContext = ClassDescription<T>;
112112template <class T >
113113template <class U >
114114Result 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 );
118118 context.set_parent (this );
119119 context.ClassContext <U>::before_eaches = this ->before_eaches ;
120120 context.ClassContext <U>::after_eaches = this ->after_eaches ;
@@ -124,16 +124,16 @@ Result ClassDescription<T>::context(
124124template <class T >
125125template <class U >
126126Result 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 );
129129}
130130
131131template <class T >
132132template <class U >
133133Result 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 );
137137 context.set_parent (this );
138138 context.ClassContext <U>::before_eaches = this ->before_eaches ;
139139 context.ClassContext <U>::after_eaches = this ->after_eaches ;
@@ -143,14 +143,14 @@ Result ClassDescription<T>::context(
143143template <class T >
144144template <class U >
145145Result 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 );
148148}
149149
150150template <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 );
154154 context.set_parent (this );
155155 context.before_eaches = this ->before_eaches ;
156156 context.after_eaches = this ->after_eaches ;
@@ -159,31 +159,24 @@ Result ClassDescription<T>::context(std::string descr,
159159
160160template <class T >
161161Result 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 );
164164}
165165
166166template <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 );
170170 context.set_parent (this );
171171 context.before_eaches = this ->before_eaches ;
172172 context.after_eaches = this ->after_eaches ;
173173 return context.run (this ->get_formatter ());
174174}
175175
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-
183176template <class T , typename U>
184177Result 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 );
187180 context.set_parent (this );
188181 context.before_eaches = this ->before_eaches ;
189182 context.after_eaches = this ->after_eaches ;
@@ -194,7 +187,7 @@ Result Description::context(std::initializer_list<U> init_list,
194187 * Jasmine-style `it` declaration, with an explicit docstring
195188 * provided for verbose printing.
196189 *
197- * As this is an ItCd , it passes along associated type information
190+ * As this is an ItCD , it passes along associated type information
198191 * about the implicit subject from the containing
199192 * ClassDescription / ClassContext.
200193 *
@@ -207,14 +200,14 @@ Result Description::context(std::initializer_list<U> init_list,
207200 * @endcode
208201 *
209202 * @param name the name of the test
210- * @param body the contents of test
203+ * @param block the contents of test
211204 *
212205 * @return the result of the test
213206 */
214207template <class T >
215208Result 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 );
218211 Result result = it.run (this ->get_formatter ());
219212 exec_after_eaches ();
220213 exec_before_eaches ();
@@ -228,7 +221,7 @@ Result ClassDescription<T>::it(std::string name,
228221 * is a desire to be verbose, as each expectation prints its
229222 * own docstring.
230223 *
231- * As this is an ItCd , it passes along associated type information
224+ * As this is an ItCD , it passes along associated type information
232225 * about the implicit subject from the containing
233226 * ClassDescription / ClassContext.
234227 *
@@ -238,13 +231,13 @@ Result ClassDescription<T>::it(std::string name,
238231 * });
239232 * @endcode
240233 *
241- * @param body the contents of the test
234+ * @param block the contents of the test
242235 *
243236 * @return the result of the test
244237 */
245238template <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 );
248241 Result result = it.run (this ->get_formatter ());
249242 exec_after_eaches ();
250243 exec_before_eaches ();
@@ -255,29 +248,23 @@ template <class T>
255248Result ClassDescription<T>::run(Formatters::BaseFormatter &printer) {
256249 if (not this ->has_formatter ()) this ->set_printer (printer);
257250 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 ();
260253 if (this ->get_parent () == nullptr ) printer.flush ();
261254 return this ->get_status () ? Result::success () : Result::failure ();
262255}
263256
264257template <class T >
265- Expectations::ExpectationValue <T> ItCd <T>::is_expected() {
258+ Expectations::ExpectationValue<T> ItCD <T>::is_expected() {
266259 auto cd = static_cast <ClassDescription<T> *>(this ->get_parent ());
267260 Expectations::ExpectationValue<T> expectation (*this , cd->subject );
268261 return expectation;
269262}
270263
271264template <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 );
279267 printer.format (*this );
280-
281268 auto cd = static_cast <ClassDescription<T> *>(this ->get_parent ());
282269 cd->reset_lets ();
283270 return this ->get_status () ? Result::success () : Result::failure ();
0 commit comments