From 1252ed3b881030a6e98222a526cb5be383dd34d4 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:58:20 +0800 Subject: [PATCH] add several type error test cases --- test/SolidityNameAndTypeResolution.cpp | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index 1a087592c..ae6c374b4 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -868,6 +868,42 @@ BOOST_AUTO_TEST_CASE(access_to_protected_state_variable) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(error_count_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(empty_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(duplicate_parameter_names_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1, a: 2}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + +BOOST_AUTO_TEST_CASE(invalid_parameter_names_in_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b) returns (uint r) { r = a + b; }\n" + " function b() returns (uint r) { r = a({a: 1, c: 2}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() }