aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-10-16 16:01:34 +0800
committerchriseth <c@ethdev.com>2015-10-16 16:01:34 +0800
commit52eaa477d4bd9ad2f591148727d1ac9fd500d283 (patch)
treeaa45f8f99f9b9d7bc530edeb682727449aacb78e /test/libsolidity/SolidityEndToEndTest.cpp
parent2ea5b2431fc360904f193f61d974acf24fff1326 (diff)
parent2920a32ae81539a10af54e275da72111b792568e (diff)
downloaddexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar.gz
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar.bz2
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar.lz
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar.xz
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.tar.zst
dexon-solidity-52eaa477d4bd9ad2f591148727d1ac9fd500d283.zip
Merge pull request #132 from chriseth/tupleExpression
Tuple expressions and destructuring assignments
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index bee19010..75e43b73 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5677,6 +5677,101 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
BOOST_CHECK(callContractFunction("f()", encodeArgs()) == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(tuples)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint[] data;
+ function g() internal returns (uint a, uint b, uint[] storage c) {
+ return (1, 2, data);
+ }
+ function h() external returns (uint a, uint b) {
+ return (5, 6);
+ }
+ function f() returns (uint) {
+ data.length = 1;
+ data[0] = 3;
+ uint a; uint b;
+ (a, b) = this.h();
+ if (a != 5 || b != 6) return 1;
+ uint[] storage c;
+ (a, b, c) = g();
+ if (a != 1 || b != 2 || c[0] != 3) return 2;
+ (a, b) = (b, a);
+ if (a != 2 || b != 1) return 3;
+ (a, , b, ) = (8, 9, 10, 11, 12);
+ if (a != 8 || b != 10) return 4;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
+}
+
+BOOST_AUTO_TEST_CASE(destructuring_assignment)
+{
+ char const* sourceCode = R"(
+ contract C {
+ uint x = 7;
+ bytes data;
+ uint[] y;
+ uint[] arrayData;
+ function returnsArray() returns (uint[]) {
+ arrayData.length = 9;
+ arrayData[2] = 5;
+ arrayData[7] = 4;
+ return arrayData;
+ }
+ function f(bytes s) returns (uint) {
+ uint loc;
+ uint[] memory memArray;
+ (loc, x, y, data, arrayData[3]) = (8, 4, returnsArray(), s, 2);
+ if (loc != 8) return 1;
+ if (x != 4) return 2;
+ if (y.length != 9) return 3;
+ if (y[2] != 5) return 4;
+ if (y[7] != 4) return 5;
+ if (data.length != s.length) return 6;
+ if (data[3] != s[3]) return 7;
+ if (arrayData[3] != 2) return 8;
+ (memArray, loc) = (arrayData, 3);
+ if (loc != 3) return 9;
+ if (memArray.length != arrayData.length) return 10;
+ bytes memory memBytes;
+ (x, memBytes, y[2], ) = (456, s, 789, 101112, 131415);
+ if (x != 456 || memBytes.length != s.length || y[2] != 789) return 11;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(bytes)", u256(0x20), u256(5), string("abcde")) == encodeArgs(u256(0)));
+}
+
+BOOST_AUTO_TEST_CASE(destructuring_assignment_wildcard)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (uint) {
+ uint a;
+ uint b;
+ uint c;
+ (a,) = (1,);
+ if (a != 1) return 1;
+ (,b) = (2,3,4);
+ if (b != 4) return 2;
+ (, c,) = (5,6,7);
+ if (c != 6) return 3;
+ (a, b,) = (11, 12, 13);
+ if (a != 11 || b != 12) return 4;
+ (, a, b) = (11, 12, 13);
+ if (a != 12 || b != 13) return 5;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}