diff options
author | chriseth <c@ethdev.com> | 2015-10-09 22:26:27 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-10-09 22:26:27 +0800 |
commit | c54a033bf036d16651fb992689adfcffb2f3a951 (patch) | |
tree | c202cdab8002d74d9032116b0e1cd2b1515b30a1 | |
parent | b9a166061bc94cd06458c945d66bf52e76e84b70 (diff) | |
download | dexon-solidity-c54a033bf036d16651fb992689adfcffb2f3a951.tar.gz dexon-solidity-c54a033bf036d16651fb992689adfcffb2f3a951.tar.zst dexon-solidity-c54a033bf036d16651fb992689adfcffb2f3a951.zip |
Tests for multi variable declaration.
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 24 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 18 |
3 files changed, 50 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3126c1cc..08f62963 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -5613,6 +5613,30 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) 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() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index b55c92f0..c6d69f42 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2397,6 +2397,14 @@ BOOST_AUTO_TEST_CASE(cyclic_binary_dependency_via_inheritance) 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() } diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 1e034863..569530b9 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -934,6 +934,24 @@ BOOST_AUTO_TEST_CASE(library_simple) 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() } |