diff options
Diffstat (limited to 'test/libsolidity')
-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"( |