diff options
author | chriseth <c@ethdev.com> | 2015-11-25 21:23:35 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-11-29 07:16:07 +0800 |
commit | 93b3237c6ae526d3ff5aa0d23d48319cf705baee (patch) | |
tree | e86eae7793dabe6ea9d680fd4f74fedd83ace115 /test | |
parent | d71cd3aa2b235f877b7928b57c94159e2c16865c (diff) | |
download | dexon-solidity-93b3237c6ae526d3ff5aa0d23d48319cf705baee.tar.gz dexon-solidity-93b3237c6ae526d3ff5aa0d23d48319cf705baee.tar.zst dexon-solidity-93b3237c6ae526d3ff5aa0d23d48319cf705baee.zip |
Add bound functions to types.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f96f7046..19ee9440 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2551,6 +2551,99 @@ BOOST_AUTO_TEST_CASE(using_for_not_library) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(using_for_function_exists) +{ + char const* text = R"( + library D { function double(uint self) returns (uint) { return 2*self; } } + contract C { + using D for uint; + function f(uint a) { + a.double; + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(using_for_function_on_int) +{ + char const* text = R"( + library D { function double(uint self) returns (uint) { return 2*self; } } + contract C { + using D for uint; + function f(uint a) returns (uint) { + return a.double(); + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(using_for_function_on_struct) +{ + char const* text = R"( + library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + contract C { + using D for D.s; + D.s x; + function f(uint a) returns (uint) { + return x.mul(a); + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(using_for_overload) +{ + char const* text = R"( + library D { + struct s { uint a; } + function mul(s storage self, uint x) returns (uint) { return self.a *= x; } + function mul(s storage self, bytes32 x) returns (bytes32) { } + } + contract C { + using D for D.s; + D.s x; + function f(uint a) returns (uint) { + return x.mul(a); + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(using_for_by_name) +{ + char const* text = R"( + library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + contract C { + using D for D.s; + D.s x; + function f(uint a) returns (uint) { + return x.mul({x: a}); + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(bound_function_in_var) +{ + char const* text = R"( + library D { struct s { uint a; } function mul(s storage self, uint x) returns (uint) { return self.a *= x; } } + contract C { + using D for D.s; + D.s x; + function f(uint a) returns (uint) { + var g = x.mul; + return g({x: a}); + } + } + )"; + BOOST_CHECK(success(text)); +} + BOOST_AUTO_TEST_CASE(create_memory_arrays) { char const* text = R"( |