diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 7b8e56119..d232d5705 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -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; diff --git a/test/libyul/yulSyntaxTests/assign_from_stack.yul b/test/libyul/yulSyntaxTests/assign_from_stack.yul new file mode 100644 index 000000000..44f50ab5e --- /dev/null +++ b/test/libyul/yulSyntaxTests/assign_from_stack.yul @@ -0,0 +1,3 @@ +{ =: x:u256 } +// ---- +// ParserError 1856: (2-3): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/assignment.yul b/test/libyul/yulSyntaxTests/assignment.yul new file mode 100644 index 000000000..263e8e2dc --- /dev/null +++ b/test/libyul/yulSyntaxTests/assignment.yul @@ -0,0 +1,4 @@ +{ + let x:u256 := 2:u256 + let y:u256 := x +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/blocks.yul b/test/libyul/yulSyntaxTests/blocks.yul new file mode 100644 index 000000000..069dc463b --- /dev/null +++ b/test/libyul/yulSyntaxTests/blocks.yul @@ -0,0 +1,9 @@ +{ + let x:u256 := 7:u256 + { + let y:u256 := 3:u256 + } + { + let z:u256 := 2:u256 + } +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/builtin_types.yul b/test/libyul/yulSyntaxTests/builtin_types.yul new file mode 100644 index 000000000..ebf653b50 --- /dev/null +++ b/test/libyul/yulSyntaxTests/builtin_types.yul @@ -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 \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/empty_call.yul b/test/libyul/yulSyntaxTests/empty_call.yul new file mode 100644 index 000000000..30491c114 --- /dev/null +++ b/test/libyul/yulSyntaxTests/empty_call.yul @@ -0,0 +1,3 @@ +{ () } +// ---- +// ParserError 1856: (2-3): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/function_calls.yul b/test/libyul/yulSyntaxTests/function_calls.yul new file mode 100644 index 000000000..50238f798 --- /dev/null +++ b/test/libyul/yulSyntaxTests/function_calls.yul @@ -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() + } +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/function_definitions.yul b/test/libyul/yulSyntaxTests/function_definitions.yul new file mode 100644 index 000000000..ad22684b5 --- /dev/null +++ b/test/libyul/yulSyntaxTests/function_definitions.yul @@ -0,0 +1,4 @@ +{ + function f() { } + function g(a:u256) -> x:u256 { } +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/functions_multiple_args.yul b/test/libyul/yulSyntaxTests/functions_multiple_args.yul new file mode 100644 index 000000000..84468a4a9 --- /dev/null +++ b/test/libyul/yulSyntaxTests/functions_multiple_args.yul @@ -0,0 +1,4 @@ +{ + function f(a:u256, d:u256) { } + function g(a:u256, d:u256) -> x:u256, y:u256 { } +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/instructions.yul b/test/libyul/yulSyntaxTests/instructions.yul new file mode 100644 index 000000000..3d600812f --- /dev/null +++ b/test/libyul/yulSyntaxTests/instructions.yul @@ -0,0 +1,5 @@ +{ pop } +// ==== +// dialect: yul +// ---- +// ParserError 6913: (6-7): Call or assignment expected. diff --git a/test/libyul/yulSyntaxTests/number_literal_1.yul b/test/libyul/yulSyntaxTests/number_literal_1.yul new file mode 100644 index 000000000..456b9b9bd --- /dev/null +++ b/test/libyul/yulSyntaxTests/number_literal_1.yul @@ -0,0 +1 @@ +{ let x:u256 := 1:u256 } \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/number_literal_2.yul b/test/libyul/yulSyntaxTests/number_literal_2.yul new file mode 100644 index 000000000..94c5929b5 --- /dev/null +++ b/test/libyul/yulSyntaxTests/number_literal_2.yul @@ -0,0 +1,3 @@ +{ let x:u256 := .1:u256 } +// ---- +// ParserError 4828: (16-18): Invalid number literal. diff --git a/test/libyul/yulSyntaxTests/number_literal_3.yul b/test/libyul/yulSyntaxTests/number_literal_3.yul new file mode 100644 index 000000000..4dbb6879a --- /dev/null +++ b/test/libyul/yulSyntaxTests/number_literal_3.yul @@ -0,0 +1,3 @@ +{ let x:u256 := 1e5:u256 } +// ---- +// ParserError 4828: (16-19): Invalid number literal. diff --git a/test/libyul/yulSyntaxTests/number_literal_4.yul b/test/libyul/yulSyntaxTests/number_literal_4.yul new file mode 100644 index 000000000..7de784e88 --- /dev/null +++ b/test/libyul/yulSyntaxTests/number_literal_4.yul @@ -0,0 +1,3 @@ +{ let x:u256 := 67.235:u256 } +// ---- +// ParserError 4828: (16-22): Invalid number literal. diff --git a/test/libyul/yulSyntaxTests/number_literal_5.yul b/test/libyul/yulSyntaxTests/number_literal_5.yul new file mode 100644 index 000000000..df41e69ec --- /dev/null +++ b/test/libyul/yulSyntaxTests/number_literal_5.yul @@ -0,0 +1,3 @@ +{ let x:u256 := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:u256 } +// ---- +// TypeError 6708: (16-88): Number literal too large (> 256 bits) diff --git a/test/libyul/yulSyntaxTests/optional_types.yul b/test/libyul/yulSyntaxTests/optional_types.yul new file mode 100644 index 000000000..c3433485b --- /dev/null +++ b/test/libyul/yulSyntaxTests/optional_types.yul @@ -0,0 +1,8 @@ +{ + let x := 1:u256 + let y:u256 := 1 + function f(a) {} + function g(a:u256) -> b {} +} +// ==== +// dialect: yul \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/period_in_identifier.yul b/test/libyul/yulSyntaxTests/period_in_identifier.yul new file mode 100644 index 000000000..1827e6ac2 --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier.yul @@ -0,0 +1 @@ +{ let x.y:u256 := 2:u256 } \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/period_in_identifier_spaced_1.yul b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_1.yul new file mode 100644 index 000000000..dc889a2fb --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_1.yul @@ -0,0 +1,3 @@ +{ let x. y:u256 } +// ---- +// ParserError 6913: (10-11): Call or assignment expected. diff --git a/test/libyul/yulSyntaxTests/period_in_identifier_spaced_2.yul b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_2.yul new file mode 100644 index 000000000..5602cbceb --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_2.yul @@ -0,0 +1,3 @@ +{ let x .y:u256 } +// ---- +// ParserError 1856: (8-9): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/period_in_identifier_spaced_3.yul b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_3.yul new file mode 100644 index 000000000..003341b33 --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier_spaced_3.yul @@ -0,0 +1,3 @@ +{ let x . y:u256 } +// ---- +// ParserError 1856: (8-9): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/period_in_identifier_start.yul b/test/libyul/yulSyntaxTests/period_in_identifier_start.yul new file mode 100644 index 000000000..1c19455d6 --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier_start.yul @@ -0,0 +1,4 @@ +{ + x.y(2:u256) + function x.y(a:u256) {} +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/period_in_identifier_start_with_comment.yul b/test/libyul/yulSyntaxTests/period_in_identifier_start_with_comment.yul new file mode 100644 index 000000000..ed47b09b7 --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_in_identifier_start_with_comment.yul @@ -0,0 +1,2 @@ +/// comment +{ x.y(2:u256) function x.y(a:u256) {} } \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/period_not_as_identifier_start.yul b/test/libyul/yulSyntaxTests/period_not_as_identifier_start.yul new file mode 100644 index 000000000..0002b76fd --- /dev/null +++ b/test/libyul/yulSyntaxTests/period_not_as_identifier_start.yul @@ -0,0 +1,3 @@ +{ let .y:u256 } +// ---- +// ParserError 2314: (6-7): Expected identifier but got '.' diff --git a/test/libyul/yulSyntaxTests/push.yul b/test/libyul/yulSyntaxTests/push.yul new file mode 100644 index 000000000..f3dab144d --- /dev/null +++ b/test/libyul/yulSyntaxTests/push.yul @@ -0,0 +1,3 @@ +{ 0x42:u256 } +// ---- +// ParserError 6913: (12-13): Call or assignment expected. diff --git a/test/libyul/yulSyntaxTests/smoke.yul b/test/libyul/yulSyntaxTests/smoke.yul new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/test/libyul/yulSyntaxTests/smoke.yul @@ -0,0 +1 @@ +{} diff --git a/test/libyul/yulSyntaxTests/token_as_identifier.yul b/test/libyul/yulSyntaxTests/token_as_identifier.yul new file mode 100644 index 000000000..4af1ea213 --- /dev/null +++ b/test/libyul/yulSyntaxTests/token_as_identifier.yul @@ -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 diff --git a/test/libyul/yulSyntaxTests/tuple_assignment.yul b/test/libyul/yulSyntaxTests/tuple_assignment.yul new file mode 100644 index 000000000..dbaccd097 --- /dev/null +++ b/test/libyul/yulSyntaxTests/tuple_assignment.yul @@ -0,0 +1,4 @@ +{ + function f() -> a:u256, b:u256, c:u256 {} + let x:u256, y:u256, z:u256 := f() +} \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/variable_declaration.yul b/test/libyul/yulSyntaxTests/variable_declaration.yul new file mode 100644 index 000000000..5e2ced34a --- /dev/null +++ b/test/libyul/yulSyntaxTests/variable_declaration.yul @@ -0,0 +1,3 @@ +{ let x:u256 := 7:u256 } +// ==== +// dialect: evmTyped diff --git a/test/libyul/yulSyntaxTests/variable_declaration_bool.yul b/test/libyul/yulSyntaxTests/variable_declaration_bool.yul new file mode 100644 index 000000000..8ef371eef --- /dev/null +++ b/test/libyul/yulSyntaxTests/variable_declaration_bool.yul @@ -0,0 +1,6 @@ +{ + let x:bool := true:bool + let y:bool := false:bool +} +// ==== +// dialect: evmTyped diff --git a/test/libyul/yulSyntaxTests/variable_declaration_complex.yul b/test/libyul/yulSyntaxTests/variable_declaration_complex.yul new file mode 100644 index 000000000..a1eab2fd6 --- /dev/null +++ b/test/libyul/yulSyntaxTests/variable_declaration_complex.yul @@ -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 \ No newline at end of file diff --git a/test/libyul/yulSyntaxTests/variable_declaration_empty.yul b/test/libyul/yulSyntaxTests/variable_declaration_empty.yul new file mode 100644 index 000000000..31f51090e --- /dev/null +++ b/test/libyul/yulSyntaxTests/variable_declaration_empty.yul @@ -0,0 +1 @@ +{ let x:u256 } \ No newline at end of file