|
|
@ -66,6 +66,14 @@ ASTPointer<ContractDefinition> parseTextExplainError(std::string const& _source) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void checkFunctionNatspec(ASTPointer<FunctionDefinition> _function, |
|
|
|
std::string const& _expectedDoc) |
|
|
|
{ |
|
|
|
auto doc = _function->getDocumentation(); |
|
|
|
BOOST_CHECK_MESSAGE(doc != nullptr, "Function does not have Natspec Doc as expected"); |
|
|
|
BOOST_CHECK_EQUAL(*doc, _expectedDoc); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -121,14 +129,16 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) |
|
|
|
ASTPointer<ContractDefinition> contract; |
|
|
|
ASTPointer<FunctionDefinition> function; |
|
|
|
char const* text = "contract test {\n" |
|
|
|
" uint256 stateVar;\n" |
|
|
|
" private:\n" |
|
|
|
" uint256 stateVar;\n" |
|
|
|
" public:\n" |
|
|
|
" /// This is a test function\n" |
|
|
|
" function functionName(hash hashin) returns (hash hashout) {}\n" |
|
|
|
"}\n"; |
|
|
|
BOOST_REQUIRE_NO_THROW(contract = parseText(text)); |
|
|
|
auto functions = contract->getDefinedFunctions(); |
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(0)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is a test function"); |
|
|
|
checkFunctionNatspec(function, "This is a test function"); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(function_normal_comments) |
|
|
@ -144,7 +154,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments) |
|
|
|
auto functions = contract->getDefinedFunctions(); |
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(0)); |
|
|
|
BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, |
|
|
|
"Should not have gotten a Natspect comment for this function"); |
|
|
|
"Should not have gotten a Natspecc comment for this function"); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) |
|
|
@ -152,7 +162,9 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) |
|
|
|
ASTPointer<ContractDefinition> contract; |
|
|
|
ASTPointer<FunctionDefinition> function; |
|
|
|
char const* text = "contract test {\n" |
|
|
|
" private:\n" |
|
|
|
" uint256 stateVar;\n" |
|
|
|
" public:\n" |
|
|
|
" /// This is test function 1\n" |
|
|
|
" function functionName1(hash hashin) returns (hash hashout) {}\n" |
|
|
|
" /// This is test function 2\n" |
|
|
@ -166,17 +178,17 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) |
|
|
|
auto functions = contract->getDefinedFunctions(); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(0)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 1"); |
|
|
|
checkFunctionNatspec(function, "This is test function 1"); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(1)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 2"); |
|
|
|
checkFunctionNatspec(function, "This is test function 2"); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(2)); |
|
|
|
BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr, |
|
|
|
"Should not have gotten natspec comment for functionName3()"); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(3)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 4"); |
|
|
|
checkFunctionNatspec(function, "This is test function 4"); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multiline_function_documentation) |
|
|
@ -192,10 +204,9 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation) |
|
|
|
BOOST_REQUIRE_NO_THROW(contract = parseText(text)); |
|
|
|
auto functions = contract->getDefinedFunctions(); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(0)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), |
|
|
|
"This is a test function\n" |
|
|
|
" and it has 2 lines"); |
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(1)); // 1 since, 0 is the index of stateVar accessor
|
|
|
|
checkFunctionNatspec(function, "This is a test function\n" |
|
|
|
" and it has 2 lines"); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) |
|
|
@ -211,7 +222,6 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) |
|
|
|
" mapping(address=>hash) d;\n" |
|
|
|
" string name = \"Solidity\";" |
|
|
|
" }\n" |
|
|
|
" uint256 stateVar;\n" |
|
|
|
" /// This is a test function\n" |
|
|
|
" /// and it has 2 lines\n" |
|
|
|
" function fun(hash hashin) returns (hash hashout) {}\n" |
|
|
@ -220,12 +230,11 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) |
|
|
|
auto functions = contract->getDefinedFunctions(); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(0)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), "fun1 description"); |
|
|
|
checkFunctionNatspec(function, "fun1 description"); |
|
|
|
|
|
|
|
BOOST_REQUIRE_NO_THROW(function = functions.at(1)); |
|
|
|
BOOST_CHECK_EQUAL(*function->getDocumentation(), |
|
|
|
"This is a test function\n" |
|
|
|
" and it has 2 lines"); |
|
|
|
checkFunctionNatspec(function, "This is a test function\n" |
|
|
|
" and it has 2 lines"); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature) |
|
|
|