Solidity work for documentation strings

- Still a work in progress

- Parser now properly gets each function's doc comment

- Small changes in the scanner

- Multiline comments are considered
This commit is contained in:
Lefteris Karapetsas 2014-11-27 18:57:50 +01:00
parent ce7bbca1e5
commit de5ca561f8

View File

@ -122,6 +122,58 @@ BOOST_AUTO_TEST_CASE(function_normal_comments)
BOOST_CHECK_EQUAL(function->getDocumentation(), ""); BOOST_CHECK_EQUAL(function->getDocumentation(), "");
} }
BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
{
ASTPointer<ContractDefinition> contract;
ASTPointer<FunctionDefinition> function;
char const* text = "contract test {\n"
" uint256 stateVar;\n"
" /// This is test function 1\n"
" function functionName1(hash hashin) returns (hash hashout) {}\n"
" /// This is test function 2\n"
" function functionName2(hash hashin) returns (hash hashout) {}\n"
" // nothing to see here\n"
" function functionName3(hash hashin) returns (hash hashout) {}\n"
" /// This is test function 4\n"
" function functionName4(hash hashin) returns (hash hashout) {}\n"
"}\n";
BOOST_CHECK_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
BOOST_CHECK_NO_THROW(function = functions.at(0));
BOOST_CHECK_EQUAL(function->getDocumentation(), " This is test function 1");
BOOST_CHECK_NO_THROW(function = functions.at(1));
BOOST_CHECK_EQUAL(function->getDocumentation(), " This is test function 2");
BOOST_CHECK_NO_THROW(function = functions.at(2));
BOOST_CHECK_EQUAL(function->getDocumentation(), "");
BOOST_CHECK_NO_THROW(function = functions.at(3));
BOOST_CHECK_EQUAL(function->getDocumentation(), " This is test function 4");
}
#if 0 /* Work in progress - currently fails*/
BOOST_AUTO_TEST_CASE(multiline_function_documentation)
{
ASTPointer<ContractDefinition> contract;
ASTPointer<FunctionDefinition> function;
char const* text = "contract test {\n"
" uint256 stateVar;\n"
" /// This is a test function\n"
" /// and it has 2 lines\n"
" function functionName1(hash hashin) returns (hash hashout) {}\n"
"}\n";
BOOST_CHECK_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
BOOST_CHECK_NO_THROW(function = functions.at(0));
BOOST_CHECK_EQUAL(function->getDocumentation(),
" This is a test function\n"
" and it has 2 lines");
}
#endif
BOOST_AUTO_TEST_CASE(struct_definition) BOOST_AUTO_TEST_CASE(struct_definition)
{ {
char const* text = "contract test {\n" char const* text = "contract test {\n"