aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-22 02:07:03 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-29 04:46:16 +0800
commit98cde6b4dd920538d460d401cf6273ef87a16a9b (patch)
treec602bba7c3007af9255249c8d36e842fbee97008
parent8c8def6b3c3af33c1faf5fc04e6341c9419ac188 (diff)
downloaddexon-solidity-98cde6b4dd920538d460d401cf6273ef87a16a9b.tar.gz
dexon-solidity-98cde6b4dd920538d460d401cf6273ef87a16a9b.tar.zst
dexon-solidity-98cde6b4dd920538d460d401cf6273ef87a16a9b.zip
Fix in addStateVariableAccessor and adjustment of parser tests
-rw-r--r--SolidityParser.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/SolidityParser.cpp b/SolidityParser.cpp
index e331b9c6..db7806f4 100644
--- a/SolidityParser.cpp
+++ b/SolidityParser.cpp
@@ -66,6 +66,14 @@ ASTPointer<ContractDefinition> parseTextExplainError(std::string const& _source)
}
}
+static void checkFunctionNatspec(ASTPointer<FunctionDefinition> _function,
+ std::string const& _expectedDoc)
+{
+ auto doc = _function->getDocumentation();
+ BOOST_CHECK_MESSAGE(doc != nullptr, "Function does not have Natspec Doc as expected");
+ BOOST_CHECK_EQUAL(*doc, _expectedDoc);
+}
+
}
@@ -121,14 +129,16 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation)
ASTPointer<ContractDefinition> contract;
ASTPointer<FunctionDefinition> function;
char const* text = "contract test {\n"
- " uint256 stateVar;\n"
+ " private:\n"
+ " uint256 stateVar;\n"
+ " public:\n"
" /// This is a test function\n"
" function functionName(hash hashin) returns (hash hashout) {}\n"
"}\n";
BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is a test function");
+ checkFunctionNatspec(function, "This is a test function");
}
BOOST_AUTO_TEST_CASE(function_normal_comments)
@@ -144,7 +154,7 @@ BOOST_AUTO_TEST_CASE(function_normal_comments)
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
- "Should not have gotten a Natspect comment for this function");
+ "Should not have gotten a Natspecc comment for this function");
}
BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
@@ -152,7 +162,9 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
ASTPointer<ContractDefinition> contract;
ASTPointer<FunctionDefinition> function;
char const* text = "contract test {\n"
+ " private:\n"
" uint256 stateVar;\n"
+ " public:\n"
" /// This is test function 1\n"
" function functionName1(hash hashin) returns (hash hashout) {}\n"
" /// This is test function 2\n"
@@ -166,17 +178,17 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 1");
+ checkFunctionNatspec(function, "This is test function 1");
BOOST_REQUIRE_NO_THROW(function = functions.at(1));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 2");
+ checkFunctionNatspec(function, "This is test function 2");
BOOST_REQUIRE_NO_THROW(function = functions.at(2));
BOOST_CHECK_MESSAGE(function->getDocumentation() == nullptr,
"Should not have gotten natspec comment for functionName3()");
BOOST_REQUIRE_NO_THROW(function = functions.at(3));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), "This is test function 4");
+ checkFunctionNatspec(function, "This is test function 4");
}
BOOST_AUTO_TEST_CASE(multiline_function_documentation)
@@ -192,10 +204,9 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation)
BOOST_REQUIRE_NO_THROW(contract = parseText(text));
auto functions = contract->getDefinedFunctions();
- BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(),
- "This is a test function\n"
- " and it has 2 lines");
+ BOOST_REQUIRE_NO_THROW(function = functions.at(1)); // 1 since, 0 is the index of stateVar accessor
+ checkFunctionNatspec(function, "This is a test function\n"
+ " and it has 2 lines");
}
BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
@@ -211,7 +222,6 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
" mapping(address=>hash) d;\n"
" string name = \"Solidity\";"
" }\n"
- " uint256 stateVar;\n"
" /// This is a test function\n"
" /// and it has 2 lines\n"
" function fun(hash hashin) returns (hash hashout) {}\n"
@@ -220,12 +230,11 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
auto functions = contract->getDefinedFunctions();
BOOST_REQUIRE_NO_THROW(function = functions.at(0));
- BOOST_CHECK_EQUAL(*function->getDocumentation(), "fun1 description");
+ checkFunctionNatspec(function, "fun1 description");
BOOST_REQUIRE_NO_THROW(function = functions.at(1));
- BOOST_CHECK_EQUAL(*function->getDocumentation(),
- "This is a test function\n"
- " and it has 2 lines");
+ checkFunctionNatspec(function, "This is a test function\n"
+ " and it has 2 lines");
}
BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)