diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-05 00:19:47 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-05 00:19:47 +0800 |
commit | e3a1ef66e2ad382a5479619f4764f4a7cfda388a (patch) | |
tree | 67bd4259a6944511c752b44d3bd9d122c027a3da | |
parent | 75d0b8e0b6371d2956308dd2d01aff565f931e0f (diff) | |
download | dexon-solidity-e3a1ef66e2ad382a5479619f4764f4a7cfda388a.tar.gz dexon-solidity-e3a1ef66e2ad382a5479619f4764f4a7cfda388a.tar.zst dexon-solidity-e3a1ef66e2ad382a5479619f4764f4a7cfda388a.zip |
Natspec parsing @param doctags
- Plus additional work on generally parsing doctags.
One important missing feature is to parse a tag midline
- Adding more tests
-rw-r--r-- | solidityNatspecJSON.cpp | 117 |
1 files changed, 101 insertions, 16 deletions
diff --git a/solidityNatspecJSON.cpp b/solidityNatspecJSON.cpp index d74aa8ab..5894f3b0 100644 --- a/solidityNatspecJSON.cpp +++ b/solidityNatspecJSON.cpp @@ -89,21 +89,6 @@ BOOST_AUTO_TEST_CASE(user_basic_test) checkNatspec(sourceCode, natspec, true); } -BOOST_AUTO_TEST_CASE(dev_basic_test) -{ - char const* sourceCode = "contract test {\n" - " /// @dev Multiplies a number by 7\n" - " function mul(uint a) returns(uint d) { return a * 7; }\n" - "}\n"; - - char const* natspec = "{" - "\"methods\":{" - " \"mul\":{ \"details\": \"Multiplies a number by 7\"}" - "}}"; - - checkNatspec(sourceCode, natspec, false); -} - BOOST_AUTO_TEST_CASE(dev_and_user_basic_test) { char const* sourceCode = "contract test {\n" @@ -114,7 +99,11 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test) char const* devNatspec = "{" "\"methods\":{" - " \"mul\":{ \"details\": \"Multiplies a number by 7\"}" + " \"mul\":{ \n" + " \"details\": \"Multiplies a number by 7\",\n" + " \"params\": {}\n" + " }\n" + " }\n" "}}"; char const* userNatspec = "{" @@ -186,6 +175,102 @@ BOOST_AUTO_TEST_CASE(user_empty_contract) checkNatspec(sourceCode, natspec, true); } +BOOST_AUTO_TEST_CASE(dev_multiple_params) +{ + 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 second Documentation for the second parameter\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{" + "\"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" + " \"params\": {\n" + " \"a\": \"Documentation for the first parameter\",\n" + " \"second\": \"Documentation for the second parameter\"\n" + " }\n" + " }\n" + "}}"; + + checkNatspec(sourceCode, natspec, false); +} + +BOOST_AUTO_TEST_CASE(dev_mutiline_param_description) +{ + char const* sourceCode = "contract test {\n" + " /// @dev Multiplies a number by 7 and adds second parameter\n" + " /// @param a Documentation for the first parameter starts here.\n" + " /// Since it's a really complicated parameter we need 2 lines\n" + " /// @param second Documentation for the second parameter\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + "}\n"; + + char const* natspec = "{" + "\"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" + " \"params\": {\n" + " \"a\": \"Documentation for the first parameter starts here.Since it's a really complicated parameter we need 2 lines\",\n" + " \"second\": \"Documentation for the second parameter\"\n" + " }\n" + " }\n" + "}}"; + + checkNatspec(sourceCode, natspec, false); +} + +BOOST_AUTO_TEST_CASE(dev_multiple_functions) +{ + 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 second Documentation for the second parameter\n" + " function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n" + " \n" + " /// @dev Divides 2 numbers\n" + " /// @param input Documentation for the input parameter\n" + " /// @param div Documentation for the div parameter\n" + " function divide(uint input, uint div) returns(uint d)\n" + " {\n" + " return input / div;\n" + " }\n" + " /// @dev Subtracts 3 from `input`\n" + " /// @param input Documentation for the input parameter\n" + " function sub(int input) returns(int d)\n" + " {\n" + " return input - 3;\n" + " }\n" + "}\n"; + + char const* natspec = "{" + "\"methods\":{" + " \"mul\":{ \n" + " \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" + " \"params\": {\n" + " \"a\": \"Documentation for the first parameter\",\n" + " \"second\": \"Documentation for the second parameter\"\n" + " }\n" + " },\n" + " \"divide\":{ \n" + " \"details\": \"Divides 2 numbers\",\n" + " \"params\": {\n" + " \"input\": \"Documentation for the input parameter\",\n" + " \"div\": \"Documentation for the div parameter\"\n" + " }\n" + " },\n" + " \"sub\":{ \n" + " \"details\": \"Subtracts 3 from `input`\",\n" + " \"params\": {\n" + " \"input\": \"Documentation for the input parameter\"\n" + " }\n" + " }\n" + "}}"; + + checkNatspec(sourceCode, natspec, false); +} BOOST_AUTO_TEST_SUITE_END() |