InlineAssembly: Extracting tests for if statement

This commit is contained in:
Christian Parpart 2020-10-19 13:47:15 +02:00
parent 8270af8560
commit 6f872dbebf
8 changed files with 46 additions and 27 deletions

View File

@ -270,27 +270,6 @@ BOOST_AUTO_TEST_CASE(variable_use_before_decl)
CHECK_PARSE_ERROR("{ let x := mul(2, x) }", DeclarationError, "Variable x used before it was declared."); CHECK_PARSE_ERROR("{ let x := mul(2, x) }", DeclarationError, "Variable x used before it was declared.");
} }
BOOST_AUTO_TEST_CASE(if_statement)
{
BOOST_CHECK(successParse("{ if 42 {} }"));
BOOST_CHECK(successParse("{ if 42 { let x := 3 } }"));
BOOST_CHECK(successParse("{ function f() -> x {} if f() { pop(f()) } }"));
}
BOOST_AUTO_TEST_CASE(if_statement_scope)
{
BOOST_CHECK(successParse("{ let x := 2 if 42 { x := 3 } }"));
CHECK_PARSE_ERROR("{ if 32 { let x := 3 } x := 2 }", DeclarationError, "Variable not found or variable not lvalue.");
}
BOOST_AUTO_TEST_CASE(if_statement_invalid)
{
CHECK_PARSE_ERROR("{ if mload {} }", ParserError, "Expected '(' but got '{'");
BOOST_CHECK("{ if calldatasize() {}");
CHECK_PARSE_ERROR("{ if mstore(1, 1) {} }", TypeError, "Expected expression to evaluate to one value, but got 0 values instead.");
CHECK_PARSE_ERROR("{ if 32 let x := 3 }", ParserError, "Expected '{' but got reserved keyword 'let'");
}
BOOST_AUTO_TEST_CASE(switch_statement) BOOST_AUTO_TEST_CASE(switch_statement)
{ {
BOOST_CHECK(successParse("{ switch 42 default {} }")); BOOST_CHECK(successParse("{ switch 42 default {} }"));
@ -671,12 +650,6 @@ BOOST_AUTO_TEST_CASE(for_statement)
BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }")); BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }"));
} }
BOOST_AUTO_TEST_CASE(if_statement)
{
BOOST_CHECK(successAssemble("{ if 1 {} }"));
BOOST_CHECK(successAssemble("{ let x := 0 if eq(calldatasize(), 0) { x := 1 } mstore(0, x) }"));
}
BOOST_AUTO_TEST_CASE(large_constant) BOOST_AUTO_TEST_CASE(large_constant)
{ {
auto source = R"({ auto source = R"({

View File

@ -0,0 +1,8 @@
{
{ if 42 {} }
{ if 42 { let x := 3 } }
{ function f() -> x {} if f() { pop(f()) } }
{ let x := 0 if eq(calldatasize(), 0) { x := 1 } mstore(0, x) }
}
// ====
// dialect: evm

View File

@ -0,0 +1,5 @@
{
if mload {}
}
// ----
// ParserError 2314: (15-16): Expected '(' but got '{'

View File

@ -0,0 +1,7 @@
{
if mstore(1, 1) {}
}
// ====
// dialect: evm
// ----
// TypeError 3950: (6-18): Expected expression to evaluate to one value, but got 0 values instead.

View File

@ -0,0 +1,7 @@
{
if 32 let x := 3
}
// ====
// dialect: yul
// ----
// ParserError 2314: (12-15): Expected '{' but got reserved keyword 'let'

View File

@ -0,0 +1,5 @@
{
if calldatasize {}
}
// ----
// ParserError 2314: (22-23): Expected '(' but got '{'

View File

@ -0,0 +1,6 @@
{
let x := 2
if 42 { x := 3 }
}
// ====
// dialect: evm

View File

@ -0,0 +1,8 @@
{
if 32 { let x := 3 }
x := 2
}
// ====
// dialect: evm
// ----
// DeclarationError 4634: (25-26): Variable not found or variable not lvalue.