2020 * Unit tests for the solidity parser.
2121 */
2222
23- #include < string>
24- #include < memory>
25- #include < liblangutil/Scanner.h>
23+ #include < libsolidity/ast/ASTVisitor.h>
2624#include < libsolidity/parsing/Parser.h>
25+ #include < liblangutil/Scanner.h>
2726#include < liblangutil/ErrorReporter.h>
2827#include < test/Common.h>
2928#include < test/libsolidity/ErrorCheck.h>
30- #include < libsolidity/ast/ASTVisitor.h>
3129
3230#include < boost/test/unit_test.hpp>
3331
32+ #include < range/v3/range/conversion.hpp>
33+
34+ #include < string>
35+ #include < memory>
36+
3437using namespace std ;
3538using namespace solidity ::langutil;
3639
@@ -141,7 +144,7 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation)
141144 FunctionDefinition const * function = nullptr ;
142145 auto functions = contract->definedFunctions ();
143146
144- BOOST_REQUIRE_MESSAGE (function = functions.at ( 0 ), " Failed to retrieve function" );
147+ BOOST_REQUIRE_MESSAGE (function = * functions.begin ( ), " Failed to retrieve function" );
145148 checkFunctionNatspec (function, " This is a test function" );
146149}
147150
@@ -159,9 +162,11 @@ BOOST_AUTO_TEST_CASE(function_normal_comments)
159162 ErrorList errors;
160163 ASTPointer<ContractDefinition> contract = parseText (text, errors);
161164 auto functions = contract->definedFunctions ();
162- BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
163- BOOST_CHECK_MESSAGE (function->documentation () == nullptr ,
164- " Should not have gotten a Natspecc comment for this function" );
165+ BOOST_REQUIRE_MESSAGE (function = *functions.begin (), " Failed to retrieve function" );
166+ BOOST_CHECK_MESSAGE (
167+ function->documentation () == nullptr ,
168+ " Should not have gotten a Natspecc comment for this function"
169+ );
165170}
166171
167172BOOST_AUTO_TEST_CASE (multiple_functions_natspec_documentation)
@@ -183,7 +188,7 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
183188 BOOST_CHECK (successParse (text));
184189 ErrorList errors;
185190 ASTPointer<ContractDefinition> contract = parseText (text, errors);
186- auto functions = contract->definedFunctions ();
191+ auto functions = contract->definedFunctions () | ranges::to<vector<FunctionDefinition const *>>() ;
187192
188193 BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
189194 checkFunctionNatspec (function, " This is test function 1" );
@@ -214,9 +219,12 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation)
214219 ErrorList errors;
215220 ASTPointer<ContractDefinition> contract = parseText (text, errors);
216221 auto functions = contract->definedFunctions ();
217- BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
218- checkFunctionNatspec (function, " This is a test function\n "
219- " and it has 2 lines" );
222+ BOOST_REQUIRE_MESSAGE (function = *functions.begin (), " Failed to retrieve function" );
223+ checkFunctionNatspec (
224+ function,
225+ " This is a test function\n "
226+ " and it has 2 lines"
227+ );
220228}
221229
222230BOOST_AUTO_TEST_CASE (natspec_comment_in_function_body)
@@ -240,7 +248,7 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
240248 BOOST_CHECK (successParse (text));
241249 ErrorList errors;
242250 ASTPointer<ContractDefinition> contract = parseText (text, errors);
243- auto functions = contract->definedFunctions ();
251+ auto functions = contract->definedFunctions () | ranges::to<vector<FunctionDefinition const *>>() ;
244252
245253 BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
246254 checkFunctionNatspec (function, " fun1 description" );
@@ -269,7 +277,7 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)
269277 BOOST_CHECK (successParse (text));
270278 ErrorList errors;
271279 ASTPointer<ContractDefinition> contract = parseText (text, errors);
272- auto functions = contract->definedFunctions ();
280+ auto functions = contract->definedFunctions () | ranges::to<vector<FunctionDefinition const *>>() ;
273281
274282 BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
275283 BOOST_CHECK_MESSAGE (!function->documentation (),
@@ -295,7 +303,7 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature)
295303 BOOST_CHECK (successParse (text));
296304 ErrorList errors;
297305 ASTPointer<ContractDefinition> contract = parseText (text, errors);
298- auto functions = contract->definedFunctions ();
306+ auto functions = contract->definedFunctions () | ranges::to<vector<FunctionDefinition const *>>() ;
299307
300308 BOOST_REQUIRE_MESSAGE (function = functions.at (0 ), " Failed to retrieve function" );
301309 BOOST_CHECK_MESSAGE (!function->documentation (),
0 commit comments