Tests for multi variable declaration.

This commit is contained in:
chriseth 2015-10-09 16:26:27 +02:00
parent b9a166061b
commit c54a033bf0
3 changed files with 50 additions and 0 deletions

View File

@ -5613,6 +5613,30 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
BOOST_CHECK_EQUAL(m_state.balance(libraryAddress), 0); BOOST_CHECK_EQUAL(m_state.balance(libraryAddress), 0);
} }
BOOST_AUTO_TEST_CASE(multi_variable_declaration)
{
char const* sourceCode = R"(
contract C {
function g() returns (uint a, uint b, uint c) {
a = 1; b = 2; c = 3;
}
function f() returns (bool) {
var (x, y, z) = g();
if (x != 1 || y != 2 || z != 3) return false;
var (, a,) = g();
if (a != 2) return false;
var (b,) = g();
if (b != 1) return false;
var (,c) = g();
if (c != 3) return false;
return true;
}
}
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f()", encodeArgs()) == encodeArgs(true));
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

View File

@ -2397,6 +2397,14 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance)
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError); SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
} }
BOOST_AUTO_TEST_CASE(multi_variable_declaration_fail)
{
char const* text = R"(
contract C { function f() { var (x,y); } }
)";
SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

View File

@ -934,6 +934,24 @@ BOOST_AUTO_TEST_CASE(library_simple)
BOOST_CHECK_NO_THROW(parseText(text)); BOOST_CHECK_NO_THROW(parseText(text));
} }
BOOST_AUTO_TEST_CASE(multi_variable_declaration)
{
char const* text = R"(
library Lib {
function f() {
var (a,b,c) = g();
var (d) = 2;
var (,e) = 3;
var (f,) = 4;
var (x,,) = g();
var (,y,) = g();
}
function g() returns (uint, uint, uint) {}
}
)";
BOOST_CHECK_NO_THROW(parseText(text));
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }