diff --git a/solidityNatspecJSON.cpp b/solidityNatspecJSON.cpp index f1795fe1c..641bb82ab 100644 --- a/solidityNatspecJSON.cpp +++ b/solidityNatspecJSON.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -393,6 +394,93 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return) checkNatspec(sourceCode, natspec, false); } +BOOST_AUTO_TEST_CASE(dev_contract_no_doc) +{ + char const* sourceCode = "contract test {\n" + " /// @dev Mul function\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{" + " \"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Mul function\"\n" + " }\n" + " }\n" + "}"; + + checkNatspec(sourceCode, natspec, false); +} + +BOOST_AUTO_TEST_CASE(dev_contract_doc) +{ + char const* sourceCode = " /// @author Lefteris\n" + " /// @title Just a test contract\n" + "contract test {\n" + " /// @dev Mul function\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{" + " \"author\": \"Lefteris\"," + " \"title\": \"Just a test contract\"," + " \"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Mul function\"\n" + " }\n" + " }\n" + "}"; + + checkNatspec(sourceCode, natspec, false); +} + +BOOST_AUTO_TEST_CASE(dev_author_at_function) +{ + char const* sourceCode = " /// @author Lefteris\n" + " /// @title Just a test contract\n" + "contract test {\n" + " /// @dev Mul function\n" + " /// @author John Doe\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{" + " \"author\": \"Lefteris\"," + " \"title\": \"Just a test contract\"," + " \"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Mul function\",\n" + " \"author\": \"John Doe\",\n" + " }\n" + " }\n" + "}"; + + 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"; + + char const* natspec = "{" + " \"author\": \"Lefteris\"," + " \"title\": \"Just a test contract\"," + " \"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Mul function\"\n" + " }\n" + " }\n" + "}"; + + BOOST_CHECK_THROW(checkNatspec(sourceCode, natspec, false), DocstringParsingError); +} + BOOST_AUTO_TEST_SUITE_END() }