Browse Source

Merge pull request #828 from LefterisJP/natspec_taglessNotice

Absence of tag in Natspec is now considered @notice
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
3b7a7657f6
  1. 10
      libsolidity/InterfaceHandler.cpp
  2. 28
      test/SolidityNatspecJSON.cpp

10
libsolidity/InterfaceHandler.cpp

@ -351,9 +351,15 @@ void InterfaceHandler::parseDocString(std::string const& _string, CommentOwner _
currPos = appendDocTag(currPos, end, _owner);
else if (currPos != end)
{
if (nlPos == end) //end of text
// if it begins without a tag then consider it as @notice
if (currPos == _string.begin())
{
currPos = parseDocTag(currPos, end, "notice", CommentOwner::FUNCTION);
continue;
}
else if (nlPos == end) //end of text
return;
// else skip the line if a newline was found
// else skip the line if a newline was found and we get here
currPos = nlPos + 1;
}
}

28
test/SolidityNatspecJSON.cpp

@ -506,17 +506,35 @@ BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
BOOST_CHECK_THROW(checkNatspec(sourceCode, natspec, false), DocstringParsingError);
}
// test for bug where having no tags in docstring would cause infinite loop
BOOST_AUTO_TEST_CASE(natspec_no_tags)
BOOST_AUTO_TEST_CASE(natspec_notice_without_tag)
{
char const* sourceCode = "contract test {\n"
" /// I do something awesome\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
" function mul(uint a) returns(uint d) { return a * 7; }\n"
"}\n";
char const* natspec = "{\"methods\": {}}";
char const* natspec = "{"
"\"methods\":{"
" \"mul(uint256)\":{ \"notice\": \"I do something awesome\"}"
"}}";
checkNatspec(sourceCode, natspec, true);
}
checkNatspec(sourceCode, natspec, false);
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\"}"
"}}";
checkNatspec(sourceCode, natspec, true);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save