diff options
author | chriseth <chris@ethereum.org> | 2016-11-18 00:32:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-18 00:32:21 +0800 |
commit | b46a14f4a8e128c08336763abf8bbf7c111f464d (patch) | |
tree | ee20fa35cbc19eddcddd1013e745b387e7371be3 /test/libsolidity/SolidityParser.cpp | |
parent | c811691861eb51520d9fd51d56770f14990b0320 (diff) | |
parent | 2c14a96820233809db4360b39f5f02039be5730a (diff) | |
download | dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar.gz dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar.bz2 dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar.lz dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar.xz dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.tar.zst dexon-solidity-b46a14f4a8e128c08336763abf8bbf7c111f464d.zip |
Merge pull request #1122 from ethereum/firstClassFunctions
Functions as first-class types.
Diffstat (limited to 'test/libsolidity/SolidityParser.cpp')
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index ec23d5fd..914dbc30 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1241,6 +1241,115 @@ 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) +{ + char const* text = R"( + contract test { + function (uint, uint) internal returns (uint) f1; + } + )"; + BOOST_CHECK(successParse(text)); +} + +BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_modifiers) +{ + char const* text = R"( + contract test { + function (uint, uint) modifier1() returns (uint) f1; + } + )"; + BOOST_CHECK(!successParse(text)); +} + +BOOST_AUTO_TEST_CASE(function_type_as_storage_variable_with_assignment) +{ + 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_CASE(calling_function) +{ + char const* text = R"( + contract test { + function f() { + function() returns(function() returns(function() returns(function() returns(uint)))) x; + uint y; + y = x()()()(); + } + } + )"; + BOOST_CHECK(successParse(text)); +} + +BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions) +{ + char const* text = R"( + contract test { + mapping (address => function() internal returns (uint)) a; + mapping (address => function() external) b; + mapping (address => function() external[]) c; + function() external[] d; + } + )"; + BOOST_CHECK(successParse(text)); +} + +BOOST_AUTO_TEST_CASE(function_type_state_variable) +{ + char const* text = R"( + contract test { + function() x; + function() y = x; + } + )"; + BOOST_CHECK(successParse(text)); +} + + BOOST_AUTO_TEST_SUITE_END() } |