From 93b3237c6ae526d3ff5aa0d23d48319cf705baee Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 25 Nov 2015 14:23:35 +0100 Subject: Add bound functions to types. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'test/libsolidity') 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"( -- cgit