mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9804 from ethereum/extractYulSyntaxTests
Extract (some) yul syntax tests.
This commit is contained in:
commit
ff93d8ac6c
@ -126,149 +126,6 @@ do \
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(YulParser)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(smoke_test)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 7:u256 }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl_bool)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:bool := true:bool }"));
|
||||
BOOST_CHECK(successParse("{ let x:bool := false:bool }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl_empty)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assignment)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 2:u256 let y:u256 := x }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(period_in_identifier)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x.y:u256 := 2:u256 }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(period_not_as_identifier_start)
|
||||
{
|
||||
CHECK_ERROR("{ let .y:u256 }", ParserError, "Expected identifier but got '.'");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(period_in_identifier_spaced)
|
||||
{
|
||||
CHECK_ERROR("{ let x. y:u256 }", ParserError, "Call or assignment expected");
|
||||
CHECK_ERROR("{ let x .y:u256 }", ParserError, "Literal or identifier expected");
|
||||
CHECK_ERROR("{ let x . y:u256 }", ParserError, "Literal or identifier expected");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(period_in_identifier_start)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ x.y(2:u256) function x.y(a:u256) {} }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(period_in_identifier_start_with_comment)
|
||||
{
|
||||
BOOST_CHECK(successParse("/// comment\n{ x.y(2:u256) function x.y(a:u256) {} }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vardecl_complex)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ function add(a:u256, b:u256) -> c:u256 {} let y:u256 := 2:u256 let x:u256 := add(7:u256, add(6:u256, y)) }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(blocks)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 7:u256 { let y:u256 := 3:u256 } { let z:u256 := 2:u256 } }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_definitions)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ function f() { } function g(a:u256) -> x:u256 { } }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_definitions_multiple_args)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ function f(a:u256, d:u256) { } function g(a:u256, d:u256) -> x:u256, y:u256 { } }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_calls)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ function f(a:u256) -> b:u256 {} function g(a:u256, b:u256, c:u256) {} function x() { g(1:u256, 2:u256, f(3:u256)) x() } }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tuple_assignment)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ function f() -> a:u256, b:u256, c:u256 {} let x:u256, y:u256, z:u256 := f() }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(instructions)
|
||||
{
|
||||
CHECK_ERROR("{ pop }", ParserError, "Call or assignment expected.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(push)
|
||||
{
|
||||
CHECK_ERROR("{ 0x42:u256 }", ParserError, "Call or assignment expected.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(assign_from_stack)
|
||||
{
|
||||
CHECK_ERROR("{ =: x:u256 }", ParserError, "Literal or identifier expected.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_call)
|
||||
{
|
||||
CHECK_ERROR("{ () }", ParserError, "Literal or identifier expected.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(tokens_as_identifers)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let return:u256 := 1:u256 }"));
|
||||
BOOST_CHECK(successParse("{ let byte:u256 := 1:u256 }"));
|
||||
BOOST_CHECK(successParse("{ let address:u256 := 1:u256 }"));
|
||||
BOOST_CHECK(successParse("{ let bool:u256 := 1:u256 }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(optional_types)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x := 1:u256 }"));
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 1 }"));
|
||||
BOOST_CHECK(successParse("{ function f(a) {} }"));
|
||||
BOOST_CHECK(successParse("{ function f(a:u256) -> b {} }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(number_literals)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 1:u256 }"));
|
||||
CHECK_ERROR("{ let x:u256 := .1:u256 }", ParserError, "Invalid number literal.");
|
||||
CHECK_ERROR("{ let x:u256 := 1e5:u256 }", ParserError, "Invalid number literal.");
|
||||
CHECK_ERROR("{ let x:u256 := 67.235:u256 }", ParserError, "Invalid number literal.");
|
||||
CHECK_ERROR("{ let x:u256 := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:u256 }", TypeError, "Number literal too large (> 256 bits)");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(builtin_types)
|
||||
{
|
||||
BOOST_CHECK(successParse("{ let x:bool := true:bool }"));
|
||||
BOOST_CHECK(successParse("{ let x:u8 := 1:u8 }"));
|
||||
BOOST_CHECK(successParse("{ let x:s8 := 1:s8 }"));
|
||||
BOOST_CHECK(successParse("{ let x:u32 := 1:u32 }"));
|
||||
BOOST_CHECK(successParse("{ let x:s32 := 1:s32 }"));
|
||||
BOOST_CHECK(successParse("{ let x:u64 := 1:u64 }"));
|
||||
BOOST_CHECK(successParse("{ let x:s64 := 1:s64 }"));
|
||||
BOOST_CHECK(successParse("{ let x:u128 := 1:u128 }"));
|
||||
BOOST_CHECK(successParse("{ let x:s128 := 1:s128 }"));
|
||||
BOOST_CHECK(successParse("{ let x:u256 := 1:u256 }"));
|
||||
BOOST_CHECK(successParse("{ let x:s256 := 1:s256 }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(recursion_depth)
|
||||
{
|
||||
string input;
|
||||
|
3
test/libyul/yulSyntaxTests/assign_from_stack.yul
Normal file
3
test/libyul/yulSyntaxTests/assign_from_stack.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ =: x:u256 }
|
||||
// ----
|
||||
// ParserError 1856: (2-3): Literal or identifier expected.
|
4
test/libyul/yulSyntaxTests/assignment.yul
Normal file
4
test/libyul/yulSyntaxTests/assignment.yul
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
let x:u256 := 2:u256
|
||||
let y:u256 := x
|
||||
}
|
9
test/libyul/yulSyntaxTests/blocks.yul
Normal file
9
test/libyul/yulSyntaxTests/blocks.yul
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
let x:u256 := 7:u256
|
||||
{
|
||||
let y:u256 := 3:u256
|
||||
}
|
||||
{
|
||||
let z:u256 := 2:u256
|
||||
}
|
||||
}
|
15
test/libyul/yulSyntaxTests/builtin_types.yul
Normal file
15
test/libyul/yulSyntaxTests/builtin_types.yul
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
let x1:bool := true:bool
|
||||
let x2:u8 := 1:u8
|
||||
let x3:s8 := 1:s8
|
||||
let x4:u32 := 1:u32
|
||||
let x5:s32 := 1:s32
|
||||
let x6:u64 := 1:u64
|
||||
let x7:s64 := 1:s64
|
||||
let x8:u128 := 1:u128
|
||||
let x9:s128 := 1:s128
|
||||
let x10:u256 := 1:u256
|
||||
let x11:s256 := 1:s256
|
||||
}
|
||||
// ====
|
||||
// dialect: yul
|
3
test/libyul/yulSyntaxTests/empty_call.yul
Normal file
3
test/libyul/yulSyntaxTests/empty_call.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ () }
|
||||
// ----
|
||||
// ParserError 1856: (2-3): Literal or identifier expected.
|
8
test/libyul/yulSyntaxTests/function_calls.yul
Normal file
8
test/libyul/yulSyntaxTests/function_calls.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
function f(a:u256) -> b:u256 {}
|
||||
function g(a:u256, b:u256, c:u256) {}
|
||||
function x() {
|
||||
g(1:u256, 2:u256, f(3:u256))
|
||||
x()
|
||||
}
|
||||
}
|
4
test/libyul/yulSyntaxTests/function_definitions.yul
Normal file
4
test/libyul/yulSyntaxTests/function_definitions.yul
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
function f() { }
|
||||
function g(a:u256) -> x:u256 { }
|
||||
}
|
4
test/libyul/yulSyntaxTests/functions_multiple_args.yul
Normal file
4
test/libyul/yulSyntaxTests/functions_multiple_args.yul
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
function f(a:u256, d:u256) { }
|
||||
function g(a:u256, d:u256) -> x:u256, y:u256 { }
|
||||
}
|
5
test/libyul/yulSyntaxTests/instructions.yul
Normal file
5
test/libyul/yulSyntaxTests/instructions.yul
Normal file
@ -0,0 +1,5 @@
|
||||
{ pop }
|
||||
// ====
|
||||
// dialect: yul
|
||||
// ----
|
||||
// ParserError 6913: (6-7): Call or assignment expected.
|
1
test/libyul/yulSyntaxTests/number_literal_1.yul
Normal file
1
test/libyul/yulSyntaxTests/number_literal_1.yul
Normal file
@ -0,0 +1 @@
|
||||
{ let x:u256 := 1:u256 }
|
3
test/libyul/yulSyntaxTests/number_literal_2.yul
Normal file
3
test/libyul/yulSyntaxTests/number_literal_2.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ let x:u256 := .1:u256 }
|
||||
// ----
|
||||
// ParserError 4828: (16-18): Invalid number literal.
|
3
test/libyul/yulSyntaxTests/number_literal_3.yul
Normal file
3
test/libyul/yulSyntaxTests/number_literal_3.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ let x:u256 := 1e5:u256 }
|
||||
// ----
|
||||
// ParserError 4828: (16-19): Invalid number literal.
|
3
test/libyul/yulSyntaxTests/number_literal_4.yul
Normal file
3
test/libyul/yulSyntaxTests/number_literal_4.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ let x:u256 := 67.235:u256 }
|
||||
// ----
|
||||
// ParserError 4828: (16-22): Invalid number literal.
|
3
test/libyul/yulSyntaxTests/number_literal_5.yul
Normal file
3
test/libyul/yulSyntaxTests/number_literal_5.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ let x:u256 := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:u256 }
|
||||
// ----
|
||||
// TypeError 6708: (16-88): Number literal too large (> 256 bits)
|
8
test/libyul/yulSyntaxTests/optional_types.yul
Normal file
8
test/libyul/yulSyntaxTests/optional_types.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
let x := 1:u256
|
||||
let y:u256 := 1
|
||||
function f(a) {}
|
||||
function g(a:u256) -> b {}
|
||||
}
|
||||
// ====
|
||||
// dialect: yul
|
1
test/libyul/yulSyntaxTests/period_in_identifier.yul
Normal file
1
test/libyul/yulSyntaxTests/period_in_identifier.yul
Normal file
@ -0,0 +1 @@
|
||||
{ let x.y:u256 := 2:u256 }
|
@ -0,0 +1,3 @@
|
||||
{ let x. y:u256 }
|
||||
// ----
|
||||
// ParserError 6913: (10-11): Call or assignment expected.
|
@ -0,0 +1,3 @@
|
||||
{ let x .y:u256 }
|
||||
// ----
|
||||
// ParserError 1856: (8-9): Literal or identifier expected.
|
@ -0,0 +1,3 @@
|
||||
{ let x . y:u256 }
|
||||
// ----
|
||||
// ParserError 1856: (8-9): Literal or identifier expected.
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
x.y(2:u256)
|
||||
function x.y(a:u256) {}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
/// comment
|
||||
{ x.y(2:u256) function x.y(a:u256) {} }
|
@ -0,0 +1,3 @@
|
||||
{ let .y:u256 }
|
||||
// ----
|
||||
// ParserError 2314: (6-7): Expected identifier but got '.'
|
3
test/libyul/yulSyntaxTests/push.yul
Normal file
3
test/libyul/yulSyntaxTests/push.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ 0x42:u256 }
|
||||
// ----
|
||||
// ParserError 6913: (12-13): Call or assignment expected.
|
1
test/libyul/yulSyntaxTests/smoke.yul
Normal file
1
test/libyul/yulSyntaxTests/smoke.yul
Normal file
@ -0,0 +1 @@
|
||||
{}
|
8
test/libyul/yulSyntaxTests/token_as_identifier.yul
Normal file
8
test/libyul/yulSyntaxTests/token_as_identifier.yul
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
let return:u256 := 1:u256
|
||||
let byte:u256 := 1:u256
|
||||
let address:u256 := 1:u256
|
||||
let bool:u256 := 1:u256
|
||||
}
|
||||
// ====
|
||||
// dialect: yul
|
4
test/libyul/yulSyntaxTests/tuple_assignment.yul
Normal file
4
test/libyul/yulSyntaxTests/tuple_assignment.yul
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
function f() -> a:u256, b:u256, c:u256 {}
|
||||
let x:u256, y:u256, z:u256 := f()
|
||||
}
|
3
test/libyul/yulSyntaxTests/variable_declaration.yul
Normal file
3
test/libyul/yulSyntaxTests/variable_declaration.yul
Normal file
@ -0,0 +1,3 @@
|
||||
{ let x:u256 := 7:u256 }
|
||||
// ====
|
||||
// dialect: evmTyped
|
6
test/libyul/yulSyntaxTests/variable_declaration_bool.yul
Normal file
6
test/libyul/yulSyntaxTests/variable_declaration_bool.yul
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
let x:bool := true:bool
|
||||
let y:bool := false:bool
|
||||
}
|
||||
// ====
|
||||
// dialect: evmTyped
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
function add(a:u256, b:u256) -> c:u256 {}
|
||||
let y:u256 := 2:u256
|
||||
let x:u256 := add(7:u256, add(6:u256, y))
|
||||
}
|
||||
// ====
|
||||
// dialect: yul
|
@ -0,0 +1 @@
|
||||
{ let x:u256 }
|
Loading…
Reference in New Issue
Block a user