mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adjust tests.
This commit is contained in:
parent
e6d48bb72a
commit
69f5f2eb65
@ -466,7 +466,8 @@ BOOST_AUTO_TEST_CASE(for_loop)
|
|||||||
text = R"(
|
text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint x) public pure {
|
function f(uint x) public pure {
|
||||||
for (uint y = 2; x < 10; ) {
|
uint y;
|
||||||
|
for (y = 2; x < 10; ) {
|
||||||
y = 3;
|
y = 3;
|
||||||
}
|
}
|
||||||
assert(y == 3);
|
assert(y == 3);
|
||||||
@ -477,7 +478,8 @@ BOOST_AUTO_TEST_CASE(for_loop)
|
|||||||
text = R"(
|
text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint x) public pure {
|
function f(uint x) public pure {
|
||||||
for (uint y = 2; x < 10; ) {
|
uint y;
|
||||||
|
for (y = 2; x < 10; ) {
|
||||||
y = 3;
|
y = 3;
|
||||||
}
|
}
|
||||||
assert(y == 2);
|
assert(y == 2);
|
||||||
|
@ -322,10 +322,10 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
|||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract test {
|
contract test {
|
||||||
function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }
|
function f(uint y) { ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}});
|
||||||
bytes expectation({byte(Instruction::PUSH1), 0x1,
|
bytes expectation({byte(Instruction::PUSH1), 0x1,
|
||||||
byte(Instruction::PUSH1), 0x2,
|
byte(Instruction::PUSH1), 0x2,
|
||||||
byte(Instruction::PUSH1), 0x3,
|
byte(Instruction::PUSH1), 0x3,
|
||||||
@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(arithmetics)
|
|||||||
byte(Instruction::PUSH1), 0x6,
|
byte(Instruction::PUSH1), 0x6,
|
||||||
byte(Instruction::PUSH1), 0x7,
|
byte(Instruction::PUSH1), 0x7,
|
||||||
byte(Instruction::PUSH1), 0x8,
|
byte(Instruction::PUSH1), 0x8,
|
||||||
byte(Instruction::DUP10),
|
byte(Instruction::DUP9),
|
||||||
byte(Instruction::XOR),
|
byte(Instruction::XOR),
|
||||||
byte(Instruction::AND),
|
byte(Instruction::AND),
|
||||||
byte(Instruction::OR),
|
byte(Instruction::OR),
|
||||||
@ -364,13 +364,13 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
|||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract test {
|
contract test {
|
||||||
function f(int y) { var x = !(~+- y == 2); }
|
function f(int y) { !(~+- y == 2); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}});
|
||||||
|
|
||||||
bytes expectation({byte(Instruction::PUSH1), 0x2,
|
bytes expectation({byte(Instruction::PUSH1), 0x2,
|
||||||
byte(Instruction::DUP3),
|
byte(Instruction::DUP2),
|
||||||
byte(Instruction::PUSH1), 0x0,
|
byte(Instruction::PUSH1), 0x0,
|
||||||
byte(Instruction::SUB),
|
byte(Instruction::SUB),
|
||||||
byte(Instruction::NOT),
|
byte(Instruction::NOT),
|
||||||
@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(unary_inc_dec)
|
|||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract test {
|
contract test {
|
||||||
function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }
|
function f(uint a) returns (uint x) { x = --a ^ (a-- ^ (++a ^ a++)); }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
|
||||||
@ -426,7 +426,10 @@ BOOST_AUTO_TEST_CASE(unary_inc_dec)
|
|||||||
byte(Instruction::POP), // second ++
|
byte(Instruction::POP), // second ++
|
||||||
// Stack here: a x a^(a+2)^(a+2)
|
// Stack here: a x a^(a+2)^(a+2)
|
||||||
byte(Instruction::DUP3), // will change
|
byte(Instruction::DUP3), // will change
|
||||||
byte(Instruction::XOR)});
|
byte(Instruction::XOR),
|
||||||
|
byte(Instruction::SWAP1),
|
||||||
|
byte(Instruction::POP),
|
||||||
|
byte(Instruction::DUP1)});
|
||||||
// Stack here: a x a^(a+2)^(a+2)^a
|
// Stack here: a x a^(a+2)^(a+2)^a
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
@ -76,15 +76,19 @@ BOOST_AUTO_TEST_CASE(double_function_declaration)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(double_variable_declaration)
|
BOOST_AUTO_TEST_CASE(double_variable_declaration)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
string text = R"(
|
||||||
contract test {
|
contract test {
|
||||||
function f() public {
|
function f() pure public {
|
||||||
uint256 x;
|
uint256 x;
|
||||||
if (true) { uint256 x; }
|
if (true) { uint256 x; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, DeclarationError, "Identifier already declared.");
|
CHECK_WARNING_ALLOW_MULTI(text, (vector<string>{
|
||||||
|
"This declaration shadows an existing declaration.",
|
||||||
|
"Unused local variable",
|
||||||
|
"Unused local variable"
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_shadowing)
|
BOOST_AUTO_TEST_CASE(name_shadowing)
|
||||||
@ -1043,7 +1047,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables)
|
|||||||
modifier mod(uint a) { if (a > 0) _; }
|
modifier mod(uint a) { if (a > 0) _; }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_SUCCESS(text);
|
CHECK_ERROR(text, DeclarationError, "Undeclared identifier.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_modifier_double_invocation)
|
BOOST_AUTO_TEST_CASE(function_modifier_double_invocation)
|
||||||
|
Loading…
Reference in New Issue
Block a user