Merge pull request #9804 from ethereum/extractYulSyntaxTests

Extract (some) yul syntax tests.
This commit is contained in:
chriseth 2020-09-15 13:50:45 +02:00 committed by GitHub
commit ff93d8ac6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 128 additions and 143 deletions

View File

@ -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;

View File

@ -0,0 +1,3 @@
{ =: x:u256 }
// ----
// ParserError 1856: (2-3): Literal or identifier expected.

View File

@ -0,0 +1,4 @@
{
let x:u256 := 2:u256
let y:u256 := x
}

View File

@ -0,0 +1,9 @@
{
let x:u256 := 7:u256
{
let y:u256 := 3:u256
}
{
let z:u256 := 2:u256
}
}

View 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

View File

@ -0,0 +1,3 @@
{ () }
// ----
// ParserError 1856: (2-3): Literal or identifier expected.

View 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()
}
}

View File

@ -0,0 +1,4 @@
{
function f() { }
function g(a:u256) -> x:u256 { }
}

View File

@ -0,0 +1,4 @@
{
function f(a:u256, d:u256) { }
function g(a:u256, d:u256) -> x:u256, y:u256 { }
}

View File

@ -0,0 +1,5 @@
{ pop }
// ====
// dialect: yul
// ----
// ParserError 6913: (6-7): Call or assignment expected.

View File

@ -0,0 +1 @@
{ let x:u256 := 1:u256 }

View File

@ -0,0 +1,3 @@
{ let x:u256 := .1:u256 }
// ----
// ParserError 4828: (16-18): Invalid number literal.

View File

@ -0,0 +1,3 @@
{ let x:u256 := 1e5:u256 }
// ----
// ParserError 4828: (16-19): Invalid number literal.

View File

@ -0,0 +1,3 @@
{ let x:u256 := 67.235:u256 }
// ----
// ParserError 4828: (16-22): Invalid number literal.

View File

@ -0,0 +1,3 @@
{ let x:u256 := 0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:u256 }
// ----
// TypeError 6708: (16-88): Number literal too large (> 256 bits)

View File

@ -0,0 +1,8 @@
{
let x := 1:u256
let y:u256 := 1
function f(a) {}
function g(a:u256) -> b {}
}
// ====
// dialect: yul

View File

@ -0,0 +1 @@
{ let x.y:u256 := 2:u256 }

View File

@ -0,0 +1,3 @@
{ let x. y:u256 }
// ----
// ParserError 6913: (10-11): Call or assignment expected.

View File

@ -0,0 +1,3 @@
{ let x .y:u256 }
// ----
// ParserError 1856: (8-9): Literal or identifier expected.

View File

@ -0,0 +1,3 @@
{ let x . y:u256 }
// ----
// ParserError 1856: (8-9): Literal or identifier expected.

View File

@ -0,0 +1,4 @@
{
x.y(2:u256)
function x.y(a:u256) {}
}

View File

@ -0,0 +1,2 @@
/// comment
{ x.y(2:u256) function x.y(a:u256) {} }

View File

@ -0,0 +1,3 @@
{ let .y:u256 }
// ----
// ParserError 2314: (6-7): Expected identifier but got '.'

View File

@ -0,0 +1,3 @@
{ 0x42:u256 }
// ----
// ParserError 6913: (12-13): Call or assignment expected.

View File

@ -0,0 +1 @@
{}

View 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

View File

@ -0,0 +1,4 @@
{
function f() -> a:u256, b:u256, c:u256 {}
let x:u256, y:u256, z:u256 := f()
}

View File

@ -0,0 +1,3 @@
{ let x:u256 := 7:u256 }
// ====
// dialect: evmTyped

View File

@ -0,0 +1,6 @@
{
let x:bool := true:bool
let y:bool := false:bool
}
// ====
// dialect: evmTyped

View File

@ -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

View File

@ -0,0 +1 @@
{ let x:u256 }