aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-28 03:37:32 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:17 +0800
commitcc8583ec7d6fd86ca7e129475fde32b76d102e79 (patch)
treea2df35174d6d95734207add361db5d894fe8592f /test
parentc811691861eb51520d9fd51d56770f14990b0320 (diff)
downloaddexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar.gz
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar.bz2
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar.lz
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar.xz
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.tar.zst
dexon-solidity-cc8583ec7d6fd86ca7e129475fde32b76d102e79.zip
Function types.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp18
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp49
-rw-r--r--test/libsolidity/SolidityParser.cpp51
3 files changed, 118 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index d8924250..c9097663 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -7606,6 +7606,24 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call)
BOOST_CHECK(callContractFunction("f(address)", cAddrOpt) == encodeArgs(u256(7)));
}
+BOOST_AUTO_TEST_CASE(pass_function_types_internally)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f(uint x) returns (uint) {
+ return eval(g, x);
+ }
+ function eval(function(uint) returns (uint) x, uint a) returns (uint) {
+ return x(a);
+ }
+ function g(uint x) returns (uint) { return x + 1; }
+ }
+ )";
+
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("f(uint256)", 7) == encodeArgs(u256(8)));
+}
+
BOOST_AUTO_TEST_CASE(shift_constant_left)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index f498a0b9..7f12cd86 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -4132,6 +4132,55 @@ BOOST_AUTO_TEST_CASE(using_directive_for_missing_selftype)
BOOST_CHECK(expectError(text, false) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(function_type)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ function(uint) returns (uint) x;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(function_type_parameter)
+{
+ char const* text = R"(
+ contract C {
+ function f(function(uint) returns (uint) g) returns (function(uint) returns (uint)) {
+ return g;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+BOOST_AUTO_TEST_CASE(private_function_type)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ function(uint) private returns (uint) x;
+ }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(public_function_type)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ function(uint) public returns (uint) x;
+ }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+
BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal)
{
char const* text = R"(
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index ec23d5fd..69b8d0f0 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1241,6 +1241,57 @@ BOOST_AUTO_TEST_CASE(payable_accessor)
BOOST_CHECK(!successParse(text));
}
+BOOST_AUTO_TEST_CASE(function_type_in_expression)
+{
+ char const* text = R"(
+ contract test {
+ function f(uint x, uint y) returns (uint a) {}
+ function g() {
+ function (uint, uint) internal returns (uint) f1 = f;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(function_type_as_storage_variable)
+{
+ // TODO disambiguate from fallback function
+ char const* text = R"(
+ contract test {
+ function f(uint x, uint y) returns (uint a) {}
+ function (uint, uint) internal returns (uint) f1 = f;
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(function_type_in_struct)
+{
+ char const* text = R"(
+ contract test {
+ struct S {
+ function (uint x, uint y) internal returns (uint a) f;
+ function (uint, uint) external returns (uint) g;
+ uint d;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(function_type_as_parameter)
+{
+ char const* text = R"(
+ contract test {
+ function f(function(uint) external returns (uint) g) internal returns (uint a) {
+ return g(1);
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}