aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2015-02-08 19:23:17 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2015-02-10 23:39:13 +0800
commit3ce223c6cb30f8e9f1035b6740d8c90f95a91185 (patch)
tree7574972adee85d1622757549497944678a90777e
parent7dc5e2a1a0ef2c0212d852c053fc52e25c16acd9 (diff)
downloaddexon-solidity-3ce223c6cb30f8e9f1035b6740d8c90f95a91185.tar.gz
dexon-solidity-3ce223c6cb30f8e9f1035b6740d8c90f95a91185.tar.zst
dexon-solidity-3ce223c6cb30f8e9f1035b6740d8c90f95a91185.zip
add exponent operator
https://www.pivotaltracker.com/n/projects/1189488/stories/83746404
-rw-r--r--SolidityEndToEndTest.cpp30
-rw-r--r--SolidityParser.cpp11
2 files changed, 41 insertions, 0 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 31b80894..74811014 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -56,6 +56,36 @@ BOOST_AUTO_TEST_CASE(empty_contract)
BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()).empty());
}
+BOOST_AUTO_TEST_CASE(exp_operator)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(uint a) returns(uint d) { return 2 ** a; }
+ })";
+ compileAndRun(sourceCode);
+ testSolidityAgainstCppOnRange("f(uint256)", [](u256 const& a) -> u256 { return u256(1 << a.convert_to<int>()); }, 0, 16);
+}
+
+BOOST_AUTO_TEST_CASE(exp_operator_const)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f() returns(uint d) { return 2 ** 3; }
+ })";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(8)));
+}
+
+BOOST_AUTO_TEST_CASE(exp_operator_const_signed)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f() returns(int d) { return -2 ** 3; }
+ })";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f()", bytes()) == toBigEndian(u256(-8)));
+}
+
BOOST_AUTO_TEST_CASE(recursive_calls)
{
char const* sourceCode = "contract test {\n"
diff --git a/SolidityParser.cpp b/SolidityParser.cpp
index 7af99567..84f36170 100644
--- a/SolidityParser.cpp
+++ b/SolidityParser.cpp
@@ -387,6 +387,17 @@ BOOST_AUTO_TEST_CASE(complex_expression)
BOOST_CHECK_NO_THROW(parseText(text));
}
+BOOST_AUTO_TEST_CASE(exp_expression)
+{
+ char const* text = R"(
+ contract test {
+ function fun(uint256 a) {
+ uint256 x = 3 ** a;
+ }
+ })";
+ BOOST_CHECK_NO_THROW(parseText(text));
+}
+
BOOST_AUTO_TEST_CASE(while_loop)
{
char const* text = "contract test {\n"