aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-11-28 18:17:18 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-11-28 18:17:18 +0800
commit9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2 (patch)
tree38c0019528deba420a52b1f2de15366dc5cb8131
parent263e1be34e08c720fccbc2532a7adda728ecee6e (diff)
downloaddexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar.gz
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar.bz2
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar.lz
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar.xz
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.tar.zst
dexon-solidity-9e80ec9e7a790ba06ee2f8f1c1fdfe963b0a28c2.zip
Solidity natspec docstring test improvements
- Adding a test for docstring being between function signature and function body - Properly checking for exceptions in parsing - Small parser fix
-rw-r--r--solidityParser.cpp70
1 files changed, 47 insertions, 23 deletions
diff --git a/solidityParser.cpp b/solidityParser.cpp
index 89ef0ac0..e4db2ece 100644
--- a/solidityParser.cpp
+++ b/solidityParser.cpp
@@ -101,10 +101,10 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation)
" /// This is a test function\n"
" function functionName(hash hashin) returns (hash hashout) {}\n"
"}\n";
- BOOST_CHECK_NO_THROW(contract = parseText(text));
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(), " This is a test function");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is a test function");
}
BOOST_AUTO_TEST_CASE(function_normal_comments)
@@ -116,10 +116,10 @@ BOOST_AUTO_TEST_CASE(function_normal_comments)
" // We won't see this comment\n"
" function functionName(hash hashin) returns (hash hashout) {}\n"
"}\n";
- BOOST_CHECK_NO_THROW(contract = parseText(text));
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_NO_THROW(function = functions.at(0));
- BOOST_CHECK_MESSAGE(function->getDocumentation().get() == nullptr,
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
"Should not have gotten a Natspect comment for this function");
}
@@ -138,21 +138,21 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
" /// This is test function 4\n"
" function functionName4(hash hashin) returns (hash hashout) {}\n"
"}\n";
- BOOST_CHECK_NO_THROW(contract = parseText(text));
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(), " This is test function 1");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 1");
- BOOST_CHECK_NO_THROW(function = functions.at(1));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(), " This is test function 2");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(1));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 2");
- BOOST_CHECK_NO_THROW(function = functions.at(2));
- BOOST_CHECK_MESSAGE(function->getDocumentation().get() == nullptr,
+ BOOST_REQUIRE_NO_THROW(function = functions.at(2));
+ BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
"Should not have gotten natspec comment for functionName3()");
- BOOST_CHECK_NO_THROW(function = functions.at(3));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(), " This is test function 4");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(3));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), " This is test function 4");
}
BOOST_AUTO_TEST_CASE(multiline_function_documentation)
@@ -165,11 +165,11 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation)
" /// and it has 2 lines\n"
" function functionName1(hash hashin) returns (hash hashout) {}\n"
"}\n";
- BOOST_CHECK_NO_THROW(contract = parseText(text));
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(),
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(),
" This is a test function\n"
" and it has 2 lines");
}
@@ -192,18 +192,42 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
" /// and it has 2 lines\n"
" function fun(hash hashin) returns (hash hashout) {}\n"
"}\n";
- BOOST_CHECK_NO_THROW(contract = parseText(text));
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_CHECK_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(), " fun1 description");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(), " fun1 description");
- BOOST_CHECK_NO_THROW(function = functions.at(1));
- BOOST_CHECK_EQUAL(*function->getDocumentation().get(),
+ BOOST_REQUIRE_NO_THROW(function = functions.at(1));
+ BOOST_CHECK_EQUAL(*function->getDocumentation(),
" This is a test function\n"
" and it has 2 lines");
}
+BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature)
+{
+ ASTPointer<ContractDefinition> contract;
+ ASTPointer<FunctionDefinition> function;
+ char const* text = "contract test {\n"
+ " uint256 stateVar;\n"
+ " function fun1(uint256 a) {\n"
+ " /// I should have been above the function signature"
+ " {\n"
+ " var b;\n"
+ " /// I should not interfere with actual natspec comments\n"
+ " uint256 c;\n"
+ " mapping(address=>hash) d;\n"
+ " string name = \"Solidity\";"
+ " }\n"
+ "}\n";
+ BOOST_REQUIRE_NO_THROW(contract = parseText(text));
+ auto functions = contract->getDefinedFunctions();
+
+ BOOST_REQUIRE_NO_THROW(function = functions.at(0));
+ BOOST_CHECK_MESSAGE(!function->getDocumentation(),
+ "Shouldn't get natspec docstring for this function");
+}
+
BOOST_AUTO_TEST_CASE(struct_definition)
{
char const* text = "contract test {\n"