mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add exponent operator
https://www.pivotaltracker.com/n/projects/1189488/stories/83746404
This commit is contained in:
parent
7dc5e2a1a0
commit
3ce223c6cb
@ -56,6 +56,36 @@ BOOST_AUTO_TEST_CASE(empty_contract)
|
|||||||
BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()).empty());
|
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)
|
BOOST_AUTO_TEST_CASE(recursive_calls)
|
||||||
{
|
{
|
||||||
char const* sourceCode = "contract test {\n"
|
char const* sourceCode = "contract test {\n"
|
||||||
|
@ -387,6 +387,17 @@ BOOST_AUTO_TEST_CASE(complex_expression)
|
|||||||
BOOST_CHECK_NO_THROW(parseText(text));
|
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)
|
BOOST_AUTO_TEST_CASE(while_loop)
|
||||||
{
|
{
|
||||||
char const* text = "contract test {\n"
|
char const* text = "contract test {\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user