From 7fb43fe8542679fe91fef460d1a5d15fb8f83cca Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 May 2018 03:06:47 +0200 Subject: Move couple of parser tests to syntax tests. --- test/libsolidity/SolidityParser.cpp | 132 --------------------- .../parsing/comment_end_with_double_star.sol | 5 + .../syntaxTests/parsing/empty_comment.sol | 3 + .../syntaxTests/parsing/function_no_body.sol | 5 + .../parsing/function_type_state_variable.sol | 4 + .../syntaxTests/parsing/interface_basic.sol | 6 + .../parsing/multi_variable_declarations.sol | 29 +++++ .../multiple_function_param_trailing_comma.sol | 5 + .../syntaxTests/parsing/overloaded_functions.sol | 9 ++ .../parsing/single_event_arg_trailing_comma.sol | 6 + .../parsing/single_modifier_arg_trailing_comma.sol | 6 + test/libsolidity/syntaxTests/parsing/tuples.sol | 24 ++++ 12 files changed, 102 insertions(+), 132 deletions(-) create mode 100644 test/libsolidity/syntaxTests/parsing/comment_end_with_double_star.sol create mode 100644 test/libsolidity/syntaxTests/parsing/empty_comment.sol create mode 100644 test/libsolidity/syntaxTests/parsing/function_no_body.sol create mode 100644 test/libsolidity/syntaxTests/parsing/function_type_state_variable.sol create mode 100644 test/libsolidity/syntaxTests/parsing/interface_basic.sol create mode 100644 test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol create mode 100644 test/libsolidity/syntaxTests/parsing/multiple_function_param_trailing_comma.sol create mode 100644 test/libsolidity/syntaxTests/parsing/overloaded_functions.sol create mode 100644 test/libsolidity/syntaxTests/parsing/single_event_arg_trailing_comma.sol create mode 100644 test/libsolidity/syntaxTests/parsing/single_modifier_arg_trailing_comma.sol create mode 100644 test/libsolidity/syntaxTests/parsing/tuples.sol (limited to 'test') diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index cbea8694..0c801cf6 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -112,38 +112,6 @@ while(0) BOOST_AUTO_TEST_SUITE(SolidityParser) -BOOST_AUTO_TEST_CASE(single_modifier_arg_trailing_comma) -{ - char const* text = R"( - contract test { - modifier modTest(uint a,) { _; } - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(single_event_arg_trailing_comma) -{ - char const* text = R"( - contract test { - event Test(uint a,); - function(uint a) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - -BOOST_AUTO_TEST_CASE(multiple_function_param_trailing_comma) -{ - char const* text = R"( - contract test { - function(uint a, uint b,) {} - } - )"; - CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); -} - BOOST_AUTO_TEST_CASE(multiple_return_param_trailing_comma) { char const* text = R"( @@ -176,16 +144,6 @@ BOOST_AUTO_TEST_CASE(multiple_event_arg_trailing_comma) CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list."); } -BOOST_AUTO_TEST_CASE(function_no_body) -{ - char const* text = R"( - contract test { - function functionName(bytes32 input) returns (bytes32 out); - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(two_exact_functions) { char const* text = R"( @@ -200,17 +158,6 @@ BOOST_AUTO_TEST_CASE(two_exact_functions) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(overloaded_functions) -{ - char const* text = R"( - contract test { - function fun(uint a) returns(uint r) { return a; } - function fun(uint a, uint b) returns(uint r) { return a + b; } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(function_natspec_documentation) { char const* text = R"( @@ -985,28 +932,6 @@ BOOST_AUTO_TEST_CASE(location_specifiers_for_locals) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(empty_comment) -{ - char const* text = R"( - // - contract test - {} - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(comment_end_with_double_star) -{ - char const* text = R"( - contract C1 { - /** - **/ - } - contract C2 {} - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(library_simple) { char const* text = R"( @@ -1017,42 +942,6 @@ BOOST_AUTO_TEST_CASE(library_simple) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(multi_variable_declaration) -{ - char const* text = R"( - contract C { - function f() { - var (a,b,c) = g(); - var (d) = 2; - var (,e) = 3; - var (f,) = 4; - var (x,,) = g(); - var (,y,) = g(); - var () = g(); - var (,,) = g(); - } - function g() returns (uint, uint, uint) {} - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(tuples) -{ - char const* text = R"( - contract C { - function f() { - uint a = (1); - var (b,) = (1,); - var (c,d) = (1, 2 + a); - var (e,) = (1, 2, b); - (a) = 3; - } - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( @@ -1335,27 +1224,6 @@ BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions) BOOST_CHECK(successParse(text)); } -BOOST_AUTO_TEST_CASE(function_type_state_variable) -{ - char const* text = R"( - contract test { - function() x; - function() y = x; - } - )"; - BOOST_CHECK(successParse(text)); -} - -BOOST_AUTO_TEST_CASE(interface) -{ - char const* text = R"( - interface Interface { - function f(); - } - )"; - BOOST_CHECK(successParse(text)); -} - BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/syntaxTests/parsing/comment_end_with_double_star.sol b/test/libsolidity/syntaxTests/parsing/comment_end_with_double_star.sol new file mode 100644 index 00000000..d3fcae9b --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/comment_end_with_double_star.sol @@ -0,0 +1,5 @@ +contract C1 { +/** + **/ +} +contract C2 {} diff --git a/test/libsolidity/syntaxTests/parsing/empty_comment.sol b/test/libsolidity/syntaxTests/parsing/empty_comment.sol new file mode 100644 index 00000000..b39c8483 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/empty_comment.sol @@ -0,0 +1,3 @@ +// +contract test +{} diff --git a/test/libsolidity/syntaxTests/parsing/function_no_body.sol b/test/libsolidity/syntaxTests/parsing/function_no_body.sol new file mode 100644 index 00000000..0424ebd8 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_no_body.sol @@ -0,0 +1,5 @@ +contract test { + function functionName(bytes32 input) returns (bytes32 out); +} +// ---- +// Warning: (17-76): No visibility specified. Defaulting to "public". diff --git a/test/libsolidity/syntaxTests/parsing/function_type_state_variable.sol b/test/libsolidity/syntaxTests/parsing/function_type_state_variable.sol new file mode 100644 index 00000000..eff52c7c --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/function_type_state_variable.sol @@ -0,0 +1,4 @@ +contract test { + function() x; + function() y = x; +} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/parsing/interface_basic.sol b/test/libsolidity/syntaxTests/parsing/interface_basic.sol new file mode 100644 index 00000000..c25b48ba --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/interface_basic.sol @@ -0,0 +1,6 @@ +interface Interface { + function f(); +} +// ---- +// Warning: (23-36): Functions in interfaces should be declared external. +// Warning: (23-36): No visibility specified. Defaulting to "public". In interfaces it defaults to external. diff --git a/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol new file mode 100644 index 00000000..818999df --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multi_variable_declarations.sol @@ -0,0 +1,29 @@ +contract C { + function f() { + var (a,b,c) = g(); + var (d) = 2; + var (,e) = 3; + var (f,) = 4; + var (x,,) = g(); + var (,y,) = g(); + var () = g(); + var (,,) = g(); + } + function g() returns (uint, uint, uint) {} +} +// ---- +// Warning: (36-37): Use of the "var" keyword is deprecated. +// Warning: (38-39): Use of the "var" keyword is deprecated. +// Warning: (40-41): Use of the "var" keyword is deprecated. +// Warning: (57-58): Use of the "var" keyword is deprecated. +// Warning: (73-74): Use of the "var" keyword is deprecated. +// Warning: (88-89): Use of the "var" keyword is deprecated. +// Warning: (104-105): Use of the "var" keyword is deprecated. +// Warning: (124-125): Use of the "var" keyword is deprecated. +// Warning: (88-89): This declaration shadows an existing declaration. +// Warning: (52-63): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (67-79): Different number of components on the left hand side (2) than on the right hand side (1). +// Warning: (67-79): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (83-95): Different number of components on the left hand side (2) than on the right hand side (1). +// Warning: (83-95): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// TypeError: (137-149): Too many components (3) in value for variable assignment (0) needed diff --git a/test/libsolidity/syntaxTests/parsing/multiple_function_param_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/multiple_function_param_trailing_comma.sol new file mode 100644 index 00000000..ae65b33c --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/multiple_function_param_trailing_comma.sol @@ -0,0 +1,5 @@ +contract test { + function(uint a, uint b,) {} +} +// ---- +// ParserError: (40-41): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol b/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol new file mode 100644 index 00000000..1a78d155 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/overloaded_functions.sol @@ -0,0 +1,9 @@ +contract test { + function fun(uint a) returns(uint r) { return a; } + function fun(uint a, uint b) returns(uint r) { return a + b; } +} +// ---- +// Warning: (17-67): No visibility specified. Defaulting to "public". +// Warning: (69-131): No visibility specified. Defaulting to "public". +// Warning: (17-67): Function state mutability can be restricted to pure +// Warning: (69-131): Function state mutability can be restricted to pure diff --git a/test/libsolidity/syntaxTests/parsing/single_event_arg_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/single_event_arg_trailing_comma.sol new file mode 100644 index 00000000..50638dc7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/single_event_arg_trailing_comma.sol @@ -0,0 +1,6 @@ +contract test { + event Test(uint a,); + function(uint a) {} +} +// ---- +// ParserError: (34-35): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/single_modifier_arg_trailing_comma.sol b/test/libsolidity/syntaxTests/parsing/single_modifier_arg_trailing_comma.sol new file mode 100644 index 00000000..2f60405f --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/single_modifier_arg_trailing_comma.sol @@ -0,0 +1,6 @@ +contract test { + modifier modTest(uint a,) { _; } + function(uint a) {} +} +// ---- +// ParserError: (40-41): Unexpected trailing comma in parameter list. diff --git a/test/libsolidity/syntaxTests/parsing/tuples.sol b/test/libsolidity/syntaxTests/parsing/tuples.sol new file mode 100644 index 00000000..6f739740 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/tuples.sol @@ -0,0 +1,24 @@ +contract C { + function f() { + uint a = (1); + var (b,) = (1,); + var (c,d) = (1, 2 + a); + var (e,) = (1, 2, b); + (a) = 3; + } +} +// ---- +// Warning: (52-53): Use of the "var" keyword is deprecated. +// Warning: (71-72): Use of the "var" keyword is deprecated. +// Warning: (73-74): Use of the "var" keyword is deprecated. +// Warning: (97-98): Use of the "var" keyword is deprecated. +// Warning: (47-62): Different number of components on the left hand side (2) than on the right hand side (1). +// Warning: (47-62): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (66-88): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (92-112): Different number of components on the left hand side (2) than on the right hand side (3). +// Warning: (92-112): The type of this variable was inferred as uint8, which can hold values between 0 and 255. This is probably not desired. Use an explicit type to silence this warning. +// Warning: (14-127): No visibility specified. Defaulting to "public". +// Warning: (71-72): Unused local variable. +// Warning: (73-74): Unused local variable. +// Warning: (97-98): Unused local variable. +// Warning: (14-127): Function state mutability can be restricted to pure -- cgit