aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-10-13 05:02:35 +0800
committerchriseth <c@ethdev.com>2015-10-15 23:38:42 +0800
commit7ebd536e79215f06f5ce7e14591aa494d06032b6 (patch)
treecca1f7597e4c6ddd674db92337424b0fd412b501 /test/libsolidity
parent7ba42f470753f9af25531017f319cf94eb26d3f2 (diff)
downloaddexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.tar.gz
dexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.tar.zst
dexon-solidity-7ebd536e79215f06f5ce7e14591aa494d06032b6.zip
Tuple expressions.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp55
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp27
-rw-r--r--test/libsolidity/SolidityParser.cpp17
3 files changed, 98 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index bee19010..1d9a403a 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5677,6 +5677,61 @@ 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 != 1 || b != 2) return 1;
+ uint[] storage c;
+ (a, b, c) = g();
+ if (a != 5 || b != 6 || c[0] != 3) return 2;
+ (a, b) = (b, a);
+ if (a != 6 || b != 5) return 3;
+ (a, , b, ) = (8, 9, 10, 11, 12);
+ if (a != 8 || b != 10) return 3;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()") == 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()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2558ba97..0b5a86d7 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2460,6 +2460,33 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_4)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(tuples)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ uint a = (1);
+ var (b,) = (1,);
+ var (c,d) = (1, 2 + a);
+ var (e,) = (1, 2, b);
+ }
+ }
+ )";
+ BOOST_CHECK_NO_THROW(parseAndAnalyse(text));
+}
+
+BOOST_AUTO_TEST_CASE(tuples_empty_components)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ (1,,2);
+ }
+ }
+ )";
+ SOLIDITY_CHECK_ERROR_TYPE(parseAndAnalyseReturnError(text), TypeError);
+}
+
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_5)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 35393811..9aa4a8ef 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -983,7 +983,7 @@ BOOST_AUTO_TEST_CASE(local_const_variable)
BOOST_AUTO_TEST_CASE(multi_variable_declaration)
{
char const* text = R"(
- library Lib {
+ contract C {
function f() {
var (a,b,c) = g();
var (d) = 2;
@@ -1000,6 +1000,21 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
BOOST_CHECK(successParse(text));
}
+BOOST_AUTO_TEST_CASE(tuples)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ uint a = (1);
+ var (b,) = (1,);
+ var (c,d) = (1, 2 + a);
+ var (e,) = (1, 2, b);
+ }
+ }
+ )";
+ BOOST_CHECK_NO_THROW(parseText(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}