diff options
author | Gav Wood <g@ethdev.com> | 2015-02-05 00:48:12 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-02-05 00:48:12 +0800 |
commit | 458e65f3cb74dc112e11616e4860bafa7ad07149 (patch) | |
tree | cb33b547625d6ddacfdebb42cf265bca1432082d | |
parent | d5e876c10630d46900b5170d770503f3a539da12 (diff) | |
parent | bade3d98e91fe3e3a20dafba61a975a5638554b7 (diff) | |
download | dexon-solidity-458e65f3cb74dc112e11616e4860bafa7ad07149.tar.gz dexon-solidity-458e65f3cb74dc112e11616e4860bafa7ad07149.tar.zst dexon-solidity-458e65f3cb74dc112e11616e4860bafa7ad07149.zip |
Merge pull request #948 from guanqun/add-some-tests-for-named-args
Add some tests for named args
-rw-r--r-- | SolidityEndToEndTest.cpp | 10 | ||||
-rw-r--r-- | SolidityParser.cpp | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp index d0d50167..f248a5a0 100644 --- a/SolidityEndToEndTest.cpp +++ b/SolidityEndToEndTest.cpp @@ -102,6 +102,16 @@ BOOST_AUTO_TEST_CASE(named_args) BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); } +BOOST_AUTO_TEST_CASE(disorder_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = "contract test {\n" diff --git a/SolidityParser.cpp b/SolidityParser.cpp index 4ccdcd57..9ba38a4a 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -124,6 +124,24 @@ BOOST_AUTO_TEST_CASE(single_function_param) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({: 1, : 2, : 3}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + +BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({a: , b: , c: }); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_CASE(function_natspec_documentation) { ASTPointer<ContractDefinition> contract; |