InlineAssembly: Extracting tests for for-statements.

This commit is contained in:
Christian Parpart 2020-10-19 15:05:21 +02:00
parent 671b1c950e
commit f2117b87f7
22 changed files with 131 additions and 41 deletions

View File

@ -203,41 +203,6 @@ BOOST_AUTO_TEST_CASE(constants)
BOOST_CHECK(successParse("{ pop(mul(7, 8)) }"));
}
BOOST_AUTO_TEST_CASE(for_statement)
{
BOOST_CHECK(successParse("{ for {} 1 {} {} }"));
BOOST_CHECK(successParse("{ for { let i := 1 } lt(i, 5) { i := add(i, 1) } {} }"));
}
BOOST_AUTO_TEST_CASE(for_invalid_expression)
{
CHECK_PARSE_ERROR("{ for {} {} {} {} }", ParserError, "Literal or identifier expected.");
CHECK_PARSE_ERROR("{ for 1 1 {} {} }", ParserError, "Expected '{' but got 'Number'");
CHECK_PARSE_ERROR("{ for {} 1 1 {} }", ParserError, "Expected '{' but got 'Number'");
CHECK_PARSE_ERROR("{ for {} 1 {} 1 }", ParserError, "Expected '{' but got 'Number'");
CHECK_PARSE_ERROR("{ for {} mload {} {} }", ParserError, "Expected '(' but got '{'");
CHECK_PARSE_ERROR("{ for {} mstore(1, 1) {} {} }", TypeError, "Expected expression to evaluate to one value, but got 0 values instead.");
}
BOOST_AUTO_TEST_CASE(for_visibility)
{
BOOST_CHECK(successParse("{ for { let i := 1 } i { pop(i) } { pop(i) } }"));
CHECK_PARSE_ERROR("{ for {} i { let i := 1 } {} }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for {} 1 { let i := 1 } { pop(i) } }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for {} 1 { pop(i) } { let i := 1 } }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for { pop(i) } 1 { let i := 1 } {} }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for { pop(i) } 1 { } { let i := 1 } }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for {} i {} { let i := 1 } }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for {} 1 { pop(i) } { let i := 1 } }", DeclarationError, "Identifier not found");
CHECK_PARSE_ERROR("{ for { let x := 1 } 1 { let x := 1 } {} }", DeclarationError, "Variable name x already taken in this scope");
CHECK_PARSE_ERROR("{ for { let x := 1 } 1 {} { let x := 1 } }", DeclarationError, "Variable name x already taken in this scope");
CHECK_PARSE_ERROR("{ let x := 1 for { let x := 1 } 1 {} {} }", DeclarationError, "Variable name x already taken in this scope");
CHECK_PARSE_ERROR("{ let x := 1 for {} 1 { let x := 1 } {} }", DeclarationError, "Variable name x already taken in this scope");
CHECK_PARSE_ERROR("{ let x := 1 for {} 1 {} { let x := 1 } }", DeclarationError, "Variable name x already taken in this scope");
// Check that body and post are not sub-scopes of each other.
BOOST_CHECK(successParse("{ for {} 1 { let x := 1 } { let x := 1 } }"));
}
BOOST_AUTO_TEST_CASE(blocks)
{
BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }"));
@ -512,12 +477,6 @@ BOOST_AUTO_TEST_CASE(embedded_functions)
BOOST_CHECK(successAssemble("{ function f(r, s) -> x { function g(a) -> b { } x := g(2) } let x := f(2, 3) }"));
}
BOOST_AUTO_TEST_CASE(for_statement)
{
BOOST_CHECK(successAssemble("{ for {} 1 {} {} }"));
BOOST_CHECK(successAssemble("{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }"));
}
BOOST_AUTO_TEST_CASE(large_constant)
{
auto source = R"({

View File

@ -0,0 +1,5 @@
{
for {} {} {} {}
}
// ----
// ParserError 1856: (10-11): Literal or identifier expected.

View File

@ -0,0 +1,5 @@
{
for 1 1 {} {}
}
// ----
// ParserError 2314: (7-8): Expected '{' but got 'Number'

View File

@ -0,0 +1,5 @@
{
for {} 1 1 {}
}
// ----
// ParserError 2314: (12-13): Expected '{' but got 'Number'

View File

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

View File

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

View File

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

View File

@ -0,0 +1,10 @@
{
{ for {} 1 {} {} }
{ for { let i := 1 } lt(i, 5) { i := add(i, 1) } {} }
{ for {} 1 {} {} }
{ let x := calldatasize() for { let i := 0} lt(i, x) { i := add(i, 1) } { mstore(i, 2) } }
}
// ====
// dialect: evm
// ----

View File

@ -0,0 +1,5 @@
{
for { let i := 1 } i { pop(i) } { pop(i) }
}
// ====
// dialect: evm

View File

@ -0,0 +1,7 @@
{
for {} i { let i := 1 } {}
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (10-11): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for {} 1 { let i := 1 } { pop(i) }
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (33-34): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for {} 1 { pop(i) } { let i := 1 }
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (18-19): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for { pop(i) } 1 { let i := 1 } {}
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (13-14): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for { pop(i) } 1 { } { let i := 1 }
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (13-14): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for {} i {} { let i := 1 }
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (10-11): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for {} 1 { pop(i) } { let i := 1 }
}
// ====
// dialect: evm
// ----
// DeclarationError 8198: (18-19): Identifier not found.

View File

@ -0,0 +1,7 @@
{
for { let x := 1 } 1 { let x := 1 } {}
}
// ====
// dialect: yul
// ----
// DeclarationError 1395: (26-36): Variable name x already taken in this scope.

View File

@ -0,0 +1,7 @@
{
for { let x := 1 } 1 {} { let x := 1 }
}
// ====
// dialect: yul
// ----
// DeclarationError 1395: (29-39): Variable name x already taken in this scope.

View File

@ -0,0 +1,5 @@
{
let x := 1 for { let x := 1 } 1 {} {}
}
// ----
// DeclarationError 1395: (20-30): Variable name x already taken in this scope.

View File

@ -0,0 +1,5 @@
{
let x := 1 for {} 1 { let x := 1 } {}
}
// ----
// DeclarationError 1395: (25-35): Variable name x already taken in this scope.

View File

@ -0,0 +1,5 @@
{
let x := 1 for {} 1 {} { let x := 1 }
}
// ----
// DeclarationError 1395: (28-38): Variable name x already taken in this scope.

View File

@ -0,0 +1,6 @@
{
// Check that body and post are not sub-scopes of each other.
for {} 1 { let x := 1 } { let x := 1 }
}
// ====
// dialect: evm