diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-11-27 22:21:22 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-11-27 22:21:22 +0800 |
commit | ce7bbca1e5bd043252d9708302303326604442ca (patch) | |
tree | 04172ddd724ff2dad13d114b0edcaf9e62cc1366 | |
parent | 0cd1e7655348727560218b6a00725d7231535cdf (diff) | |
download | dexon-solidity-ce7bbca1e5bd043252d9708302303326604442ca.tar.gz dexon-solidity-ce7bbca1e5bd043252d9708302303326604442ca.tar.zst dexon-solidity-ce7bbca1e5bd043252d9708302303326604442ca.zip |
Solidity function AST nodes get documentation attribute
-rw-r--r-- | solidityParser.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/solidityParser.cpp b/solidityParser.cpp index 9319a02c..88a1fd5f 100644 --- a/solidityParser.cpp +++ b/solidityParser.cpp @@ -37,13 +37,14 @@ namespace test namespace { -ASTPointer<ASTNode> parseText(std::string const& _source) +ASTPointer<ContractDefinition> parseText(std::string const& _source) { Parser parser; return parser.parse(std::make_shared<Scanner>(CharStream(_source))); } } + BOOST_AUTO_TEST_SUITE(SolidityParser) BOOST_AUTO_TEST_CASE(smoke_test) @@ -91,6 +92,36 @@ BOOST_AUTO_TEST_CASE(single_function_param) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(function_natspec_documentation) +{ + ASTPointer<ContractDefinition> contract; + ASTPointer<FunctionDefinition> function; + char const* text = "contract test {\n" + " uint256 stateVar;\n" + " /// This is a test function\n" + " function functionName(hash hashin) returns (hash hashout) {}\n" + "}\n"; + BOOST_CHECK_NO_THROW(contract = parseText(text)); + auto functions = contract->getDefinedFunctions(); + BOOST_CHECK_NO_THROW(function = functions.at(0)); + BOOST_CHECK_EQUAL(function->getDocumentation(), " This is a test function"); +} + +BOOST_AUTO_TEST_CASE(function_normal_comments) +{ + ASTPointer<ContractDefinition> contract; + ASTPointer<FunctionDefinition> function; + char const* text = "contract test {\n" + " uint256 stateVar;\n" + " // We won't see this comment\n" + " function functionName(hash hashin) returns (hash hashout) {}\n" + "}\n"; + BOOST_CHECK_NO_THROW(contract = parseText(text)); + auto functions = contract->getDefinedFunctions(); + BOOST_CHECK_NO_THROW(function = functions.at(0)); + BOOST_CHECK_EQUAL(function->getDocumentation(), ""); +} + BOOST_AUTO_TEST_CASE(struct_definition) { char const* text = "contract test {\n" |