Merge pull request #1458 from federicobond/r-literals

Use more R string literals in tests
This commit is contained in:
chriseth 2016-12-01 15:03:27 +01:00 committed by GitHub
commit 9db14ce673
2 changed files with 934 additions and 717 deletions

File diff suppressed because it is too large Load Diff

View File

@ -88,72 +88,88 @@ BOOST_AUTO_TEST_SUITE(SolidityParser)
BOOST_AUTO_TEST_CASE(smoke_test) BOOST_AUTO_TEST_CASE(smoke_test)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVariable1;\n" contract test {
"}\n"; uint256 stateVariable1;
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(missing_variable_name_in_declaration) BOOST_AUTO_TEST_CASE(missing_variable_name_in_declaration)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 ;\n" contract test {
"}\n"; uint256 ;
}
)";
BOOST_CHECK(!successParse(text)); BOOST_CHECK(!successParse(text));
} }
BOOST_AUTO_TEST_CASE(empty_function) BOOST_AUTO_TEST_CASE(empty_function)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" function functionName(bytes20 arg1, address addr) constant\n" uint256 stateVar;
" returns (int id)\n" function functionName(bytes20 arg1, address addr) constant
" { }\n" returns (int id)
"}\n"; { }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(no_function_params) BOOST_AUTO_TEST_CASE(no_function_params)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" function functionName() {}\n" uint256 stateVar;
"}\n"; function functionName() {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(single_function_param) BOOST_AUTO_TEST_CASE(single_function_param)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" function functionName(bytes32 input) returns (bytes32 out) {}\n" uint256 stateVar;
"}\n"; function functionName(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(function_no_body) BOOST_AUTO_TEST_CASE(function_no_body)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function functionName(bytes32 input) returns (bytes32 out);\n" contract test {
"}\n"; function functionName(bytes32 input) returns (bytes32 out);
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" contract test {
" function b() returns (uint r) { r = a({: 1, : 2, : 3}); }\n" function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }
"}\n"; function b() returns (uint r) { r = a({: 1, : 2, : 3}); }
}
)";
BOOST_CHECK(!successParse(text)); BOOST_CHECK(!successParse(text));
} }
BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) BOOST_AUTO_TEST_CASE(missing_argument_in_named_args)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" contract test {
" function b() returns (uint r) { r = a({a: , b: , c: }); }\n" function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }
"}\n"; function b() returns (uint r) { r = a({a: , b: , c: }); }
}
)";
BOOST_CHECK(!successParse(text)); BOOST_CHECK(!successParse(text));
} }
@ -184,11 +200,13 @@ BOOST_AUTO_TEST_CASE(overloaded_functions)
BOOST_AUTO_TEST_CASE(function_natspec_documentation) BOOST_AUTO_TEST_CASE(function_natspec_documentation)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" /// This is a test function\n" uint256 stateVar;
" function functionName(bytes32 input) returns (bytes32 out) {}\n" /// This is a test function
"}\n"; function functionName(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -202,11 +220,13 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation)
BOOST_AUTO_TEST_CASE(function_normal_comments) BOOST_AUTO_TEST_CASE(function_normal_comments)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" // We won't see this comment\n" uint256 stateVar;
" function functionName(bytes32 input) returns (bytes32 out) {}\n" // We won't see this comment
"}\n"; function functionName(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -219,17 +239,19 @@ BOOST_AUTO_TEST_CASE(function_normal_comments)
BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" /// This is test function 1\n" uint256 stateVar;
" function functionName1(bytes32 input) returns (bytes32 out) {}\n" /// This is test function 1
" /// This is test function 2\n" function functionName1(bytes32 input) returns (bytes32 out) {}
" function functionName2(bytes32 input) returns (bytes32 out) {}\n" /// This is test function 2
" // nothing to see here\n" function functionName2(bytes32 input) returns (bytes32 out) {}
" function functionName3(bytes32 input) returns (bytes32 out) {}\n" // nothing to see here
" /// This is test function 4\n" function functionName3(bytes32 input) returns (bytes32 out) {}
" function functionName4(bytes32 input) returns (bytes32 out) {}\n" /// This is test function 4
"}\n"; function functionName4(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -252,12 +274,14 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation)
BOOST_AUTO_TEST_CASE(multiline_function_documentation) BOOST_AUTO_TEST_CASE(multiline_function_documentation)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" /// This is a test function\n" uint256 stateVar;
" /// and it has 2 lines\n" /// This is a test function
" function functionName1(bytes32 input) returns (bytes32 out) {}\n" /// and it has 2 lines
"}\n"; function functionName1(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -270,19 +294,21 @@ BOOST_AUTO_TEST_CASE(multiline_function_documentation)
BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body) BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" /// fun1 description\n" contract test {
" function fun1(uint256 a) {\n" /// fun1 description
" var b;\n" function fun1(uint256 a) {
" /// I should not interfere with actual natspec comments\n" var b;
" uint256 c;\n" /// I should not interfere with actual natspec comments
" mapping(address=>bytes32) d;\n" uint256 c;
" bytes7 name = \"Solidity\";" mapping(address=>bytes32) d;
" }\n" bytes7 name = "Solidity";
" /// This is a test function\n" }
" /// and it has 2 lines\n" /// This is a test function
" function fun(bytes32 input) returns (bytes32 out) {}\n" /// and it has 2 lines
"}\n"; function fun(bytes32 input) returns (bytes32 out) {}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -299,17 +325,19 @@ BOOST_AUTO_TEST_CASE(natspec_comment_in_function_body)
BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature) BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" function ///I am in the wrong place \n" uint256 stateVar;
" fun1(uint256 a) {\n" function ///I am in the wrong place
" var b;\n" fun1(uint256 a) {
" /// I should not interfere with actual natspec comments\n" var b;
" uint256 c;\n" /// I should not interfere with actual natspec comments
" mapping(address=>bytes32) d;\n" uint256 c;
" bytes7 name = \"Solidity\";" mapping(address=>bytes32) d;
" }\n" bytes7 name = "Solidity";
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -323,17 +351,19 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_between_keyword_and_signature)
BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature) BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature)
{ {
FunctionDefinition const* function = nullptr; FunctionDefinition const* function = nullptr;
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" function fun1(uint256 a) {\n" uint256 stateVar;
" /// I should have been above the function signature\n" function fun1(uint256 a) {
" var b;\n" /// I should have been above the function signature
" /// I should not interfere with actual natspec comments\n" var b;
" uint256 c;\n" /// I should not interfere with actual natspec comments
" mapping(address=>bytes32) d;\n" uint256 c;
" bytes7 name = \"Solidity\";" mapping(address=>bytes32) d;
" }\n" bytes7 name = "Solidity";
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
ErrorList errors; ErrorList errors;
ASTPointer<ContractDefinition> contract = parseText(text, errors); ASTPointer<ContractDefinition> contract = parseText(text, errors);
@ -346,71 +376,83 @@ BOOST_AUTO_TEST_CASE(natspec_docstring_after_signature)
BOOST_AUTO_TEST_CASE(struct_definition) BOOST_AUTO_TEST_CASE(struct_definition)
{ {
char const* text = "contract test {\n" char const* text = R"(
" uint256 stateVar;\n" contract test {
" struct MyStructName {\n" uint256 stateVar;
" address addr;\n" struct MyStructName {
" uint256 count;\n" address addr;
" }\n" uint256 count;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(mapping) BOOST_AUTO_TEST_CASE(mapping)
{ {
char const* text = "contract test {\n" char const* text = R"(
" mapping(address => bytes32) names;\n" contract test {
"}\n"; mapping(address => bytes32) names;
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(mapping_in_struct) BOOST_AUTO_TEST_CASE(mapping_in_struct)
{ {
char const* text = "contract test {\n" char const* text = R"(
" struct test_struct {\n" contract test {
" address addr;\n" struct test_struct {
" uint256 count;\n" address addr;
" mapping(bytes32 => test_struct) self_reference;\n" uint256 count;
" }\n" mapping(bytes32 => test_struct) self_reference;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct) BOOST_AUTO_TEST_CASE(mapping_to_mapping_in_struct)
{ {
char const* text = "contract test {\n" char const* text = R"(
" struct test_struct {\n" contract test {
" address addr;\n" struct test_struct {
" mapping (uint64 => mapping (bytes32 => uint)) complex_mapping;\n" address addr;
" }\n" mapping (uint64 => mapping (bytes32 => uint)) complex_mapping;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(variable_definition) BOOST_AUTO_TEST_CASE(variable_definition)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" var b;\n" function fun(uint256 a) {
" uint256 c;\n" var b;
" mapping(address=>bytes32) d;\n" uint256 c;
" customtype varname;\n" mapping(address=>bytes32) d;
" }\n" customtype varname;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(variable_definition_with_initialization) BOOST_AUTO_TEST_CASE(variable_definition_with_initialization)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" var b = 2;\n" function fun(uint256 a) {
" uint256 c = 0x87;\n" var b = 2;
" mapping(address=>bytes32) d;\n" uint256 c = 0x87;
" bytes7 name = \"Solidity\";" mapping(address=>bytes32) d;
" customtype varname;\n" bytes7 name = "Solidity";
" }\n" customtype varname;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
@ -450,21 +492,25 @@ BOOST_AUTO_TEST_CASE(variable_definition_in_function_return)
BOOST_AUTO_TEST_CASE(operator_expression) BOOST_AUTO_TEST_CASE(operator_expression)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" uint256 x = (1 + 4) || false && (1 - 12) + -9;\n" function fun(uint256 a) {
" }\n" uint256 x = (1 + 4) || false && (1 - 12) + -9;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(complex_expression) BOOST_AUTO_TEST_CASE(complex_expression)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" uint256 x = (1 + 4).member(++67)[a/=9] || true;\n" function fun(uint256 a) {
" }\n" uint256 x = (1 + 4).member(++67)[a/=9] || true;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
@ -475,248 +521,294 @@ BOOST_AUTO_TEST_CASE(exp_expression)
function fun(uint256 a) { function fun(uint256 a) {
uint256 x = 3 ** a; uint256 x = 3 ** a;
} }
})"; }
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(while_loop) BOOST_AUTO_TEST_CASE(while_loop)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" while (true) { uint256 x = 1; break; continue; } x = 9;\n" function fun(uint256 a) {
" }\n" while (true) { uint256 x = 1; break; continue; } x = 9;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr) BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" for (uint256 i = 0; i < 10; i++)\n" function fun(uint256 a) {
" { uint256 x = i; break; continue; }\n" for (uint256 i = 0; i < 10; i++) {
" }\n" uint256 x = i; break; continue;
"}\n"; }
}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr) BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" uint256 i =0;\n" function fun(uint256 a) {
" for (i = 0; i < 10; i++)\n" uint256 i =0;
" { uint256 x = i; break; continue; }\n" for (i = 0; i < 10; i++) {
" }\n" uint256 x = i; break; continue;
"}\n"; }
}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr) BOOST_AUTO_TEST_CASE(for_loop_simple_noexpr)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" uint256 i =0;\n" function fun(uint256 a) {
" for (;;)\n" uint256 i =0;
" { uint256 x = i; break; continue; }\n" for (;;) {
" }\n" uint256 x = i; break; continue;
"}\n"; }
}
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body) BOOST_AUTO_TEST_CASE(for_loop_single_stmt_body)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" uint256 i =0;\n" function fun(uint256 a) {
" for (i = 0; i < 10; i++)\n" uint256 i = 0;
" continue;\n" for (i = 0; i < 10; i++)
" }\n" continue;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(if_statement) BOOST_AUTO_TEST_CASE(if_statement)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) {\n" contract test {
" if (a >= 8) { return 2; } else { var b = 7; }\n" function fun(uint256 a) {
" }\n" if (a >= 8) { return 2; } else { var b = 7; }
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(else_if_statement) BOOST_AUTO_TEST_CASE(else_if_statement)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun(uint256 a) returns (address b) {\n" contract test {
" if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;\n" function fun(uint256 a) returns (address b) {
" }\n" if (a < 0) b = 0x67; else if (a == 0) b = 0x12; else b = 0x78;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion) BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun() {\n" contract test {
" uint64(2);\n" function fun() {
" uint64[7](3);\n" uint64(2);
" uint64[](3);\n" uint64[7](3);
" }\n" uint64[](3);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(type_conversion_to_dynamic_array) BOOST_AUTO_TEST_CASE(type_conversion_to_dynamic_array)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun() {\n" contract test {
" var x = uint64[](3);\n" function fun() {
" }\n" var x = uint64[](3);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(import_directive) BOOST_AUTO_TEST_CASE(import_directive)
{ {
char const* text = "import \"abc\";\n" char const* text = R"(
"contract test {\n" import "abc";
" function fun() {\n" contract test {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(multiple_contracts) BOOST_AUTO_TEST_CASE(multiple_contracts)
{ {
char const* text = "contract test {\n" char const* text = R"(
" function fun() {\n" contract test {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"contract test2 {\n" }
" function fun() {\n" contract test2 {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports) BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports)
{ {
char const* text = "import \"abc\";\n" char const* text = R"(
"contract test {\n" import "abc";
" function fun() {\n" contract test {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"import \"def\";\n" }
"contract test2 {\n" import "def";
" function fun() {\n" contract test2 {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"import \"ghi\";\n"; }
import "ghi";
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(contract_inheritance) BOOST_AUTO_TEST_CASE(contract_inheritance)
{ {
char const* text = "contract base {\n" char const* text = R"(
" function fun() {\n" contract base {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"contract derived is base {\n" }
" function fun() {\n" contract derived is base {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(contract_multiple_inheritance) BOOST_AUTO_TEST_CASE(contract_multiple_inheritance)
{ {
char const* text = "contract base {\n" char const* text = R"(
" function fun() {\n" contract base {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"contract derived is base, nonExisting {\n" }
" function fun() {\n" contract derived is base, nonExisting {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments) BOOST_AUTO_TEST_CASE(contract_multiple_inheritance_with_arguments)
{ {
char const* text = "contract base {\n" char const* text = R"(
" function fun() {\n" contract base {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n" }
"contract derived is base(2), nonExisting(\"abc\", \"def\", base.fun()) {\n" }
" function fun() {\n" contract derived is base(2), nonExisting("abc", "def", base.fun()) {
" uint64(2);\n" function fun() {
" }\n" uint64(2);
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(placeholder_in_function_context) BOOST_AUTO_TEST_CASE(placeholder_in_function_context)
{ {
char const* text = "contract c {\n" char const* text = R"(
" function fun() returns (uint r) {\n" contract c {
" var _ = 8;\n" function fun() returns (uint r) {
" return _ + 1;" var _ = 8;
" }\n" return _ + 1;
"}\n"; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(modifier) BOOST_AUTO_TEST_CASE(modifier)
{ {
char const* text = "contract c {\n" char const* text = R"(
" modifier mod { if (msg.sender == 0) _; }\n" contract c {
"}\n"; modifier mod { if (msg.sender == 0) _; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(modifier_without_semicolon) BOOST_AUTO_TEST_CASE(modifier_without_semicolon)
{ {
char const* text = "contract c {\n" char const* text = R"(
" modifier mod { if (msg.sender == 0) _ }\n" contract c {
"}\n"; modifier mod { if (msg.sender == 0) _ }
}
)";
BOOST_CHECK(!successParse(text)); BOOST_CHECK(!successParse(text));
} }
BOOST_AUTO_TEST_CASE(modifier_arguments) BOOST_AUTO_TEST_CASE(modifier_arguments)
{ {
char const* text = "contract c {\n" char const* text = R"(
" modifier mod(uint a) { if (msg.sender == a) _; }\n" contract c {
"}\n"; modifier mod(uint a) { if (msg.sender == a) _; }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(modifier_invocation) BOOST_AUTO_TEST_CASE(modifier_invocation)
{ {
char const* text = "contract c {\n" char const* text = R"(
" modifier mod1(uint a) { if (msg.sender == a) _; }\n" contract c {
" modifier mod2 { if (msg.sender == 2) _; }\n" modifier mod1(uint a) { if (msg.sender == a) _; }
" function f() mod1(7) mod2 { }\n" modifier mod2 { if (msg.sender == 2) _; }
"}\n"; function f() mod1(7) mod2 { }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }
BOOST_AUTO_TEST_CASE(fallback_function) BOOST_AUTO_TEST_CASE(fallback_function)
{ {
char const* text = "contract c {\n" char const* text = R"(
" function() { }\n" contract c {
"}\n"; function() { }
}
)";
BOOST_CHECK(successParse(text)); BOOST_CHECK(successParse(text));
} }