|
|
@ -21,6 +21,7 @@ |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "../TestHelper.h" |
|
|
|
#include <string> |
|
|
|
#include <json/json.h> |
|
|
|
#include <libsolidity/CompilerStack.h> |
|
|
|
#include <libsolidity/Exceptions.h> |
|
|
@ -38,9 +39,11 @@ class DocumentationChecker |
|
|
|
public: |
|
|
|
DocumentationChecker(): m_compilerStack(false) {} |
|
|
|
|
|
|
|
void checkNatspec(std::string const& _code, |
|
|
|
std::string const& _expectedDocumentationString, |
|
|
|
bool _userDocumentation) |
|
|
|
void checkNatspec( |
|
|
|
std::string const& _code, |
|
|
|
std::string const& _expectedDocumentationString, |
|
|
|
bool _userDocumentation |
|
|
|
) |
|
|
|
{ |
|
|
|
std::string generatedDocumentationString; |
|
|
|
ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed"); |
|
|
@ -53,9 +56,11 @@ public: |
|
|
|
m_reader.parse(generatedDocumentationString, generatedDocumentation); |
|
|
|
Json::Value expectedDocumentation; |
|
|
|
m_reader.parse(_expectedDocumentationString, expectedDocumentation); |
|
|
|
BOOST_CHECK_MESSAGE(expectedDocumentation == generatedDocumentation, |
|
|
|
"Expected " << _expectedDocumentationString << |
|
|
|
"\n but got:\n" << generatedDocumentationString); |
|
|
|
BOOST_CHECK_MESSAGE( |
|
|
|
expectedDocumentation == generatedDocumentation, |
|
|
|
"Expected " << _expectedDocumentationString << |
|
|
|
"\n but got:\n" << generatedDocumentationString |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
@ -229,18 +234,6 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params) |
|
|
|
checkNatspec(sourceCode, natspec, false); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(dev_documenting_nonexistant_param) |
|
|
|
{ |
|
|
|
char const* sourceCode = "contract test {\n" |
|
|
|
" /// @dev Multiplies a number by 7 and adds second parameter\n" |
|
|
|
" /// @param a Documentation for the first parameter\n" |
|
|
|
" /// @param not_existing Documentation for the second parameter\n" |
|
|
|
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" |
|
|
|
"}\n"; |
|
|
|
|
|
|
|
BOOST_CHECK_THROW(checkNatspec(sourceCode, "", false), DocstringParsingError); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description) |
|
|
|
{ |
|
|
|
char const* sourceCode = "contract test {\n" |
|
|
@ -488,46 +481,48 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function) |
|
|
|
checkNatspec(sourceCode, natspec, false); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(dev_title_at_function_error) |
|
|
|
{ |
|
|
|
char const* sourceCode = " /// @author Lefteris\n" |
|
|
|
" /// @title Just a test contract\n" |
|
|
|
"contract test {\n" |
|
|
|
" /// @dev Mul function\n" |
|
|
|
" /// @title I really should not be here\n" |
|
|
|
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" |
|
|
|
"}\n"; |
|
|
|
|
|
|
|
BOOST_CHECK_THROW(checkNatspec(sourceCode, "", false), DocstringParsingError); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(natspec_notice_without_tag) |
|
|
|
{ |
|
|
|
char const* sourceCode = "contract test {\n" |
|
|
|
" /// I do something awesome\n" |
|
|
|
" function mul(uint a) returns(uint d) { return a * 7; }\n" |
|
|
|
"}\n"; |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
/// I do something awesome
|
|
|
|
function mul(uint a) returns(uint d) { return a * 7; } |
|
|
|
} |
|
|
|
)"; |
|
|
|
|
|
|
|
char const* natspec = "{" |
|
|
|
"\"methods\":{" |
|
|
|
" \"mul(uint256)\":{ \"notice\": \"I do something awesome\"}" |
|
|
|
"}}"; |
|
|
|
|
|
|
|
char const* natspec = R"ABCDEF( |
|
|
|
{ |
|
|
|
"methods" : { |
|
|
|
"mul(uint256)" : { |
|
|
|
"notice" : "I do something awesome" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)ABCDEF"; |
|
|
|
|
|
|
|
checkNatspec(sourceCode, natspec, true); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(natspec_multiline_notice_without_tag) |
|
|
|
{ |
|
|
|
char const* sourceCode = "contract test {\n" |
|
|
|
" /// I do something awesome\n" |
|
|
|
" /// which requires two lines to explain\n" |
|
|
|
" function mul(uint a) returns(uint d) { return a * 7; }\n" |
|
|
|
"}\n"; |
|
|
|
|
|
|
|
char const* natspec = "{" |
|
|
|
"\"methods\":{" |
|
|
|
" \"mul(uint256)\":{ \"notice\": \"I do something awesome which requires two lines to explain\"}" |
|
|
|
"}}"; |
|
|
|
char const* sourceCode = R"( |
|
|
|
contract test { |
|
|
|
/// I do something awesome
|
|
|
|
/// which requires two lines to explain
|
|
|
|
function mul(uint a) returns(uint d) { return a * 7; } |
|
|
|
} |
|
|
|
)"; |
|
|
|
|
|
|
|
char const* natspec = R"ABCDEF( |
|
|
|
{ |
|
|
|
"methods" : { |
|
|
|
"mul(uint256)" : { |
|
|
|
"notice" : "I do something awesome which requires two lines to explain" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
)ABCDEF"; |
|
|
|
|
|
|
|
checkNatspec(sourceCode, natspec, true); |
|
|
|
} |
|
|
|