Skip to content

Commit

Permalink
Merge pull request ethereum#1483 from federicobond/r-literals
Browse files Browse the repository at this point in the history
Migrate remaining source code in tests to R literals
  • Loading branch information
RJ authored Dec 3, 2016
2 parents 9be2fb1 + 70d246c commit 29edf2f
Show file tree
Hide file tree
Showing 4 changed files with 810 additions and 592 deletions.
114 changes: 66 additions & 48 deletions test/libsolidity/SolidityABIJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ BOOST_FIXTURE_TEST_SUITE(SolidityABIJSON, JSONInterfaceChecker)

BOOST_AUTO_TEST_CASE(basic_test)
{
char const* sourceCode = "contract test {\n"
" function f(uint a) returns(uint d) { return a * 7; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a) returns(uint d) { return a * 7; }
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -93,19 +95,22 @@ BOOST_AUTO_TEST_CASE(basic_test)

BOOST_AUTO_TEST_CASE(empty_contract)
{
char const* sourceCode = "contract test {\n"
"}\n";
char const* sourceCode = R"(
contract test { }
)";
char const* interface = "[]";

checkInterface(sourceCode, interface);
}

BOOST_AUTO_TEST_CASE(multiple_methods)
{
char const* sourceCode = "contract test {\n"
" function f(uint a) returns(uint d) { return a * 7; }\n"
" function g(uint b) returns(uint e) { return b * 8; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a) returns(uint d) { return a * 7; }
function g(uint b) returns(uint e) { return b * 8; }
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -151,9 +156,11 @@ BOOST_AUTO_TEST_CASE(multiple_methods)

BOOST_AUTO_TEST_CASE(multiple_params)
{
char const* sourceCode = "contract test {\n"
" function f(uint a, uint b) returns(uint d) { return a + b; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a, uint b) returns(uint d) { return a + b; }
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -186,10 +193,12 @@ BOOST_AUTO_TEST_CASE(multiple_params)
BOOST_AUTO_TEST_CASE(multiple_methods_order)
{
// methods are expected to be in alpabetical order
char const* sourceCode = "contract test {\n"
" function f(uint a) returns(uint d) { return a * 7; }\n"
" function c(uint b) returns(uint e) { return b * 8; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a) returns(uint d) { return a * 7; }
function c(uint b) returns(uint e) { return b * 8; }
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -235,10 +244,12 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)

BOOST_AUTO_TEST_CASE(const_function)
{
char const* sourceCode = "contract test {\n"
" function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
" function boo(uint32 a) constant returns(uint b) { return a * 4; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function foo(uint a, uint b) returns(uint d) { return a + b; }
function boo(uint32 a) constant returns(uint b) { return a * 4; }
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -286,11 +297,13 @@ BOOST_AUTO_TEST_CASE(const_function)

BOOST_AUTO_TEST_CASE(events)
{
char const* sourceCode = "contract test {\n"
" function f(uint a) returns(uint d) { return a * 7; }\n"
" event e1(uint b, address indexed c); \n"
" event e2(); \n"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a) returns(uint d) { return a * 7; }
event e1(uint b, address indexed c);
event e2();
}
)";
char const* interface = R"([
{
"name": "f",
Expand Down Expand Up @@ -341,9 +354,11 @@ BOOST_AUTO_TEST_CASE(events)

BOOST_AUTO_TEST_CASE(events_anonymous)
{
char const* sourceCode = "contract test {\n"
" event e() anonymous; \n"
"}\n";
char const* sourceCode = R"(
contract test {
event e() anonymous;
}
)";
char const* interface = R"([
{
"name": "e",
Expand All @@ -359,15 +374,16 @@ BOOST_AUTO_TEST_CASE(events_anonymous)

BOOST_AUTO_TEST_CASE(inherited)
{
char const* sourceCode =
" contract Base { \n"
" function baseFunction(uint p) returns (uint i) { return p; } \n"
" event baseEvent(bytes32 indexed evtArgBase); \n"
" } \n"
" contract Derived is Base { \n"
" function derivedFunction(bytes32 p) returns (bytes32 i) { return p; } \n"
" event derivedEvent(uint indexed evtArgDerived); \n"
" }";
char const* sourceCode = R"(
contract Base {
function baseFunction(uint p) returns (uint i) { return p; }
event baseEvent(bytes32 indexed evtArgBase);
}
contract Derived is Base {
function derivedFunction(bytes32 p) returns (bytes32 i) { return p; }
event derivedEvent(uint indexed evtArgDerived);
}
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -431,13 +447,14 @@ BOOST_AUTO_TEST_CASE(inherited)
BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
{
char const* sourceCode = R"(
contract test {
function f(uint, uint k) returns(uint ret_k, uint ret_g){
uint g = 8;
ret_k = k;
ret_g = g;
contract test {
function f(uint, uint k) returns(uint ret_k, uint ret_g) {
uint g = 8;
ret_k = k;
ret_g = g;
}
}
})";
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -475,10 +492,11 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
{
char const* sourceCode = R"(
contract test {
function f(uint k) returns(uint){
return k;
function f(uint k) returns(uint) {
return k;
}
}
})";
)";

char const* interface = R"([
{
Expand Down Expand Up @@ -542,7 +560,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi)
contract test {
enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
function test(ActionChoices param) {}
function ret() returns(ActionChoices){
function ret() returns(ActionChoices) {
ActionChoices action = ActionChoices.GoLeft;
return action;
}
Expand Down Expand Up @@ -612,7 +630,7 @@ BOOST_AUTO_TEST_CASE(library_function)
char const* sourceCode = R"(
library test {
struct StructType { uint a; }
function f(StructType storage b, uint[] storage c, test d) returns (uint[] e, StructType storage f){}
function f(StructType storage b, uint[] storage c, test d) returns (uint[] e, StructType storage f) {}
}
)";

Expand Down
Loading

0 comments on commit 29edf2f

Please sign in to comment.