diff options
author | Christian <c@ethdev.com> | 2014-10-09 21:57:49 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-10-10 00:35:41 +0800 |
commit | 51f335838c4d882e71fe8e09f744f9ed40391e02 (patch) | |
tree | ef45e5d8dddf592107da53bd741401d0e05a186b | |
parent | 9766467f50a5a34776d80744238687fea3fbbec0 (diff) | |
download | dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar.gz dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar.bz2 dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar.lz dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar.xz dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.tar.zst dexon-solidity-51f335838c4d882e71fe8e09f744f9ed40391e02.zip |
Initial implementation of Solidity parser finished, not yet tested much.
-rw-r--r-- | solidityParser.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/solidityParser.cpp b/solidityParser.cpp index 91247a3b..86d09f17 100644 --- a/solidityParser.cpp +++ b/solidityParser.cpp @@ -130,6 +130,84 @@ BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(variable_definition) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " var b;\n" + " uint256 c;\n" + " mapping(address=>hash) d;\n" + " customtype varname;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " var b = 2;\n" + " uint256 c = 0x87;\n" + " mapping(address=>hash) d;\n" + " string name = \"Solidity\";" + " customtype varname;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(operator_expression) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " uint256 x = (1 + 4) || false && (1 - 12) + -9;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(complex_expression) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " uint256 x = (1 + 4).member(++67)[a/=9] || true;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(while_loop) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " uint256 x = (1 + 4).member(++67) || true;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(if_statement) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) {\n" + " if (a >= 8) return 2; else { var b = 7; }\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(else_if_statement) +{ + char const* text = "contract test {\n" + " function fun(uint256 a) returns (address b) {\n" + " if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;\n" + " }\n" + "}\n"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + + BOOST_AUTO_TEST_SUITE_END() |