mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
InlineAssembly: Extracting tests for switch statement
This commit is contained in:
parent
6f872dbebf
commit
cc230ddda3
@ -270,62 +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.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_statement)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ switch 42 default {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} case 2 {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} case 2 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ switch mul(1, 2) case 1 {} case 2 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ function f() -> x {} switch f() case 1 {} case 2 {} default {} }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_no_cases)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 }", ParserError, "Switch statement without any cases.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_duplicate_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 case 1 {} case 1 {} default {} }", DeclarationError, "Duplicate case defined.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_invalid_expression)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch {} case 1 {} default {} }", ParserError, "Literal or identifier expected.");
|
||||
CHECK_PARSE_ERROR(
|
||||
"{ switch mload case 1 {} default {} }",
|
||||
ParserError,
|
||||
"Expected '(' but got reserved keyword 'case'"
|
||||
);
|
||||
CHECK_PARSE_ERROR(
|
||||
"{ switch mstore(1, 1) case 1 {} default {} }",
|
||||
TypeError,
|
||||
"Expected expression to evaluate to one value, but got 0 values instead."
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_default_before_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} case 1 {} }", ParserError, "Case not allowed after default case.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_duplicate_default_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} default {} }", ParserError, "Only one default case allowed.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_invalid_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 case mul(1, 2) {} case 2 {} default {} }", ParserError, "Literal expected.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_invalid_body)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 case 1 mul case 2 {} default {} }", ParserError, "Expected '{' but got identifier");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(for_statement)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ for {} 1 {} {} }"));
|
||||
@ -635,15 +579,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(switch_statement)
|
||||
{
|
||||
BOOST_CHECK(successAssemble("{ switch 1 default {} }"));
|
||||
BOOST_CHECK(successAssemble("{ switch 1 case 1 {} default {} }"));
|
||||
BOOST_CHECK(successAssemble("{ switch 1 case 1 {} }"));
|
||||
BOOST_CHECK(successAssemble("{ let a := 3 switch a case 1 { a := 1 } case 2 { a := 5 } a := 9}"));
|
||||
BOOST_CHECK(successAssemble("{ let a := 2 switch calldataload(0) case 1 { a := 1 } case 2 { a := 5 } }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(for_statement)
|
||||
{
|
||||
BOOST_CHECK(successAssemble("{ for {} 1 {} {} }"));
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
switch 42
|
||||
default {}
|
||||
case 1 {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 4904: (35-39): Case not allowed after default case.
|
7
test/libyul/yulSyntaxTests/switch_duplicate_default.yul
Normal file
7
test/libyul/yulSyntaxTests/switch_duplicate_default.yul
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
switch 42
|
||||
default {}
|
||||
default {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 6931: (35-42): Only one default case allowed.
|
8
test/libyul/yulSyntaxTests/switch_invalid_body.yul
Normal file
8
test/libyul/yulSyntaxTests/switch_invalid_body.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
switch 42
|
||||
case 1 mul
|
||||
case 2 {}
|
||||
default {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (27-30): Expected '{' but got identifier
|
8
test/libyul/yulSyntaxTests/switch_invalid_case.yul
Normal file
8
test/libyul/yulSyntaxTests/switch_invalid_case.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
switch 42
|
||||
case mul(1, 2) {}
|
||||
case 2 {}
|
||||
default {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 4805: (28-29): Literal expected.
|
7
test/libyul/yulSyntaxTests/switch_invalid_expr_1.yul
Normal file
7
test/libyul/yulSyntaxTests/switch_invalid_expr_1.yul
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
switch {}
|
||||
case 1 {}
|
||||
default {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 1856: (13-14): Literal or identifier expected.
|
7
test/libyul/yulSyntaxTests/switch_invalid_expr_2.yul
Normal file
7
test/libyul/yulSyntaxTests/switch_invalid_expr_2.yul
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
switch mload
|
||||
case 1 {}
|
||||
default {}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (23-27): Expected '(' but got reserved keyword 'case'
|
9
test/libyul/yulSyntaxTests/switch_invalid_expr_3.yul
Normal file
9
test/libyul/yulSyntaxTests/switch_invalid_expr_3.yul
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
switch mstore(1, 1)
|
||||
case 1 {}
|
||||
default {}
|
||||
}
|
||||
// ====
|
||||
// dialect: evm
|
||||
// ----
|
||||
// TypeError 3950: (10-22): Expected expression to evaluate to one value, but got 0 values instead.
|
3
test/libyul/yulSyntaxTests/switch_statement_1.yul
Normal file
3
test/libyul/yulSyntaxTests/switch_statement_1.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ switch 42 default {} }
|
||||
// ----
|
||||
// Warning 9592: (2-22): "switch" statement with only a default case.
|
8
test/libyul/yulSyntaxTests/switch_statement_2.yul
Normal file
8
test/libyul/yulSyntaxTests/switch_statement_2.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
{ switch 42 case 1 {} }
|
||||
{ switch 42 case 1 {} case 2 {} }
|
||||
{ switch 42 case 1 {} default {} }
|
||||
{ switch 42 case 1 {} case 2 {} default {} }
|
||||
{ switch mul(1, 2) case 1 {} case 2 {} default {} }
|
||||
{ function f() -> x {} switch f() case 1 {} case 2 {} default {} }
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
switch 42
|
||||
case 1 {}
|
||||
case 1 {}
|
||||
default {}
|
||||
}
|
||||
// ====
|
||||
// dialect: evm
|
||||
// ----
|
||||
// DeclarationError 6792: (25-34): Duplicate case defined.
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
switch 42
|
||||
}
|
||||
// ----
|
||||
// ParserError 2418: (16-17): Switch statement without any cases.
|
Loading…
Reference in New Issue
Block a user