Test for the Canonical Signature of a function

This commit is contained in:
Lefteris Karapetsas 2015-01-07 02:07:34 +01:00
parent e50d4095a7
commit 36e5b5102a

View File

@ -38,7 +38,7 @@ namespace test
namespace namespace
{ {
void parseTextAndResolveNames(std::string const& _source) ASTPointer<SourceUnit> parseTextAndResolveNames(std::string const& _source)
{ {
Parser parser; Parser parser;
ASTPointer<SourceUnit> sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source))); ASTPointer<SourceUnit> sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source)));
@ -50,6 +50,8 @@ void parseTextAndResolveNames(std::string const& _source)
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes()) for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
resolver.checkTypeRequirements(*contract); resolver.checkTypeRequirements(*contract);
return sourceUnit;
} }
} }
@ -321,6 +323,23 @@ BOOST_AUTO_TEST_CASE(comparison_bitop_precedence)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
} }
BOOST_AUTO_TEST_CASE(function_canonical_signature)
{
ASTPointer<SourceUnit> sourceUnit;
char const* text = "contract Test {\n"
" function foo(uint256 arg1, uint64 arg2, bool arg3) returns (uint256 ret) {\n"
" ret = arg1 + arg2;\n"
" }\n"
"}\n";
BOOST_CHECK_NO_THROW(sourceUnit = parseTextAndResolveNames(text));
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
auto functions = contract->getDefinedFunctions();
BOOST_ASSERT("foo(uint256,uint64,bool)" == functions[0]->getCanonicalSignature());
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }