Merge pull request #1483 from federicobond/r-literals

Migrate remaining source code in tests to R literals
This commit is contained in:
RJ 2016-12-03 16:02:52 -06:00 committed by GitHub
commit 29edf2f4c9
4 changed files with 810 additions and 592 deletions

View File

@ -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"([
{
@ -93,8 +95,9 @@ 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);
@ -102,10 +105,12 @@ BOOST_AUTO_TEST_CASE(empty_contract)
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"([
{
@ -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"([
{
@ -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"([
{
@ -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"([
{
@ -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",
@ -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",
@ -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"([
{
@ -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"([
{
@ -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"([
{
@ -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;
}
@ -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) {}
}
)";

View File

@ -168,9 +168,11 @@ BOOST_AUTO_TEST_SUITE(SolidityExpressionCompiler)
BOOST_AUTO_TEST_CASE(literal_true)
{
char const* sourceCode = "contract test {\n"
" function f() { var x = true; }"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = true; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH1), 0x1});
@ -179,9 +181,11 @@ BOOST_AUTO_TEST_CASE(literal_true)
BOOST_AUTO_TEST_CASE(literal_false)
{
char const* sourceCode = "contract test {\n"
" function f() { var x = false; }"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = false; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH1), 0x0});
@ -190,9 +194,11 @@ BOOST_AUTO_TEST_CASE(literal_false)
BOOST_AUTO_TEST_CASE(int_literal)
{
char const* sourceCode = "contract test {\n"
" function f() { var x = 0x12345678901234567890; }"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = 0x12345678901234567890; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH10), 0x12, 0x34, 0x56, 0x78, 0x90,
@ -204,11 +210,11 @@ BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination)
{
char const* sourceCode = R"(
contract test {
function test ()
{
function test () {
var x = 1 wei;
}
})";
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH1), 0x1});
@ -219,11 +225,11 @@ BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination)
{
char const* sourceCode = R"(
contract test {
function test ()
{
function test () {
var x = 1 szabo;
}
})";
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH5), 0xe8, 0xd4, 0xa5, 0x10, 0x00});
@ -249,11 +255,11 @@ BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination)
{
char const* sourceCode = R"(
contract test {
function test ()
{
function test () {
var x = 1 ether;
}
})";
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH8), 0xd, 0xe0, 0xb6, 0xb3, 0xa7, 0x64, 0x00, 0x00});
@ -262,9 +268,11 @@ BOOST_AUTO_TEST_CASE(int_with_ether_ether_subdenomination)
BOOST_AUTO_TEST_CASE(comparison)
{
char const* sourceCode = "contract test {\n"
" function f() { var x = (0x10aa < 0x11aa) != true; }"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = (0x10aa < 0x11aa) != true; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH1), 0x1, byte(Instruction::ISZERO), byte(Instruction::ISZERO),
@ -278,9 +286,11 @@ BOOST_AUTO_TEST_CASE(comparison)
BOOST_AUTO_TEST_CASE(short_circuiting)
{
char const* sourceCode = "contract test {\n"
" function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation({byte(Instruction::PUSH1), 0x12, // 8 + 10
@ -305,9 +315,11 @@ BOOST_AUTO_TEST_CASE(short_circuiting)
BOOST_AUTO_TEST_CASE(arithmetics)
{
char const* sourceCode = "contract test {\n"
" function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint y) { var x = ((((((((y ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }
}
)";
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
bytes expectation({byte(Instruction::PUSH1), 0x1,
byte(Instruction::PUSH1), 0x2,
@ -339,9 +351,11 @@ BOOST_AUTO_TEST_CASE(arithmetics)
BOOST_AUTO_TEST_CASE(unary_operators)
{
char const* sourceCode = "contract test {\n"
" function f(int y) { var x = !(~+- y == 2); }"
"}\n";
char const* sourceCode = R"(
contract test {
function f(int y) { var x = !(~+- y == 2); }
}
)";
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}, {"test", "f", "x"}});
bytes expectation({byte(Instruction::PUSH1), 0x2,
@ -356,9 +370,11 @@ BOOST_AUTO_TEST_CASE(unary_operators)
BOOST_AUTO_TEST_CASE(unary_inc_dec)
{
char const* sourceCode = "contract test {\n"
" function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }
}
)";
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}});
// Stack: a, x
@ -406,9 +422,11 @@ BOOST_AUTO_TEST_CASE(unary_inc_dec)
BOOST_AUTO_TEST_CASE(assignment)
{
char const* sourceCode = "contract test {\n"
" function f(uint a, uint b) { (a += b) * 2; }"
"}\n";
char const* sourceCode = R"(
contract test {
function f(uint a, uint b) { (a += b) * 2; }
}
)";
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}});
// Stack: a, b
@ -427,9 +445,11 @@ BOOST_AUTO_TEST_CASE(assignment)
BOOST_AUTO_TEST_CASE(negative_literals_8bits)
{
char const* sourceCode = "contract test {\n"
" function f() { int8 x = -0x80; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { int8 x = -0x80; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation(bytes({byte(Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80));
@ -438,9 +458,11 @@ BOOST_AUTO_TEST_CASE(negative_literals_8bits)
BOOST_AUTO_TEST_CASE(negative_literals_16bits)
{
char const* sourceCode = "contract test {\n"
" function f() { int64 x = ~0xabc; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { int64 x = ~0xabc; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation(bytes({byte(Instruction::PUSH32)}) + bytes(30, 0xff) + bytes{0xf5, 0x43});
@ -451,9 +473,11 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
{
// first literal itself is too large for 256 bits but it fits after all constant operations
// have been applied
char const* sourceCode = "contract test {\n"
" function f() { var x = (0xffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f() { var x = (0xffffffffffffffffffffffffffffffffffffffff * 0xffffffffffffffffffffffffff01) & 0xbf; }
}
)";
bytes code = compileFirstExpression(sourceCode);
bytes expectation(bytes({byte(Instruction::PUSH1), 0xbf}));
@ -462,11 +486,13 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
BOOST_AUTO_TEST_CASE(blockhash)
{
char const* sourceCode = "contract test {\n"
" function f() {\n"
" block.blockhash(3);\n"
" }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function f() {
block.blockhash(3);
}
}
)";
bytes code = compileFirstExpression(sourceCode, {}, {},
{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block))});

File diff suppressed because it is too large Load Diff

View File

@ -76,10 +76,12 @@ BOOST_FIXTURE_TEST_SUITE(SolidityNatspecJSON, DocumentationChecker)
BOOST_AUTO_TEST_CASE(user_basic_test)
{
char const* sourceCode = "contract test {\n"
" /// @notice Multiplies `a` by 7\n"
" function mul(uint a) returns(uint d) { return a * 7; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @notice Multiplies `a` by 7
function mul(uint a) returns(uint d) { return a * 7; }
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -91,11 +93,13 @@ BOOST_AUTO_TEST_CASE(user_basic_test)
BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
{
char const* sourceCode = "contract test {\n"
" /// @notice Multiplies `a` by 7\n"
" /// @dev Multiplies a number by 7\n"
" function mul(uint a) returns(uint d) { return a * 7; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @notice Multiplies `a` by 7
/// @dev Multiplies a number by 7
function mul(uint a) returns(uint d) { return a * 7; }
}
)";
char const* devNatspec = "{"
"\"methods\":{"
@ -116,14 +120,15 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
BOOST_AUTO_TEST_CASE(user_multiline_comment)
{
char const* sourceCode = "contract test {\n"
" /// @notice Multiplies `a` by 7\n"
" /// and then adds `b`\n"
" function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
" {\n"
" return (a * 7) + b;\n"
" }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @notice Multiplies `a` by 7
/// and then adds `b`
function mul_and_add(uint a, uint256 b) returns(uint256 d) {
return (a * 7) + b;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -135,24 +140,24 @@ BOOST_AUTO_TEST_CASE(user_multiline_comment)
BOOST_AUTO_TEST_CASE(user_multiple_functions)
{
char const* sourceCode = "contract test {\n"
" /// @notice Multiplies `a` by 7 and then adds `b`\n"
" function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
" {\n"
" return (a * 7) + b;\n"
" }\n"
"\n"
" /// @notice Divides `input` by `div`\n"
" function divide(uint input, uint div) returns(uint d)\n"
" {\n"
" return input / div;\n"
" }\n"
" /// @notice Subtracts 3 from `input`\n"
" function sub(int input) returns(int d)\n"
" {\n"
" return input - 3;\n"
" }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @notice Multiplies `a` by 7 and then adds `b`
function mul_and_add(uint a, uint256 b) returns(uint256 d) {
return (a * 7) + b;
}
/// @notice Divides `input` by `div`
function divide(uint input, uint div) returns(uint d) {
return input / div;
}
/// @notice Subtracts 3 from `input`
function sub(int input) returns(int d) {
return input - 3;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -166,8 +171,9 @@ BOOST_AUTO_TEST_CASE(user_multiple_functions)
BOOST_AUTO_TEST_CASE(user_empty_contract)
{
char const* sourceCode = "contract test {\n"
"}\n";
char const* sourceCode = R"(
contract test { }
)";
char const* natspec = "{\"methods\":{} }";
@ -176,13 +182,16 @@ BOOST_AUTO_TEST_CASE(user_empty_contract)
BOOST_AUTO_TEST_CASE(dev_and_user_no_doc)
{
char const* sourceCode = "contract test {\n"
" function mul(uint a) returns(uint d) { return a * 7; }\n"
" function sub(int input) returns(int d)\n"
" {\n"
" return input - 3;\n"
" }\n"
"}\n";
char const* sourceCode = R"(
contract test {
function mul(uint a) returns(uint d) {
return a * 7;
}
function sub(int input) returns(int d) {
return input - 3;
}
}
)";
char const* devNatspec = "{\"methods\":{}}";
char const* userNatspec = "{\"methods\":{}}";
@ -193,13 +202,15 @@ BOOST_AUTO_TEST_CASE(dev_and_user_no_doc)
BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
{
char const* sourceCode = "contract test {\n"
" /// @dev\n"
" /// Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param second Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev
/// Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter
/// @param second Documentation for the second parameter
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -217,12 +228,14 @@ BOOST_AUTO_TEST_CASE(dev_desc_after_nl)
BOOST_AUTO_TEST_CASE(dev_multiple_params)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param second Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter
/// @param second Documentation for the second parameter
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -240,13 +253,15 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params)
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter starts here.\n"
" /// Since it's a really complicated parameter we need 2 lines\n"
" /// @param second Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter starts here.
/// Since it's a really complicated parameter we need 2 lines
/// @param second Documentation for the second parameter
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -264,26 +279,27 @@ BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
BOOST_AUTO_TEST_CASE(dev_multiple_functions)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param second Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
" \n"
" /// @dev Divides 2 numbers\n"
" /// @param input Documentation for the input parameter\n"
" /// @param div Documentation for the div parameter\n"
" function divide(uint input, uint div) returns(uint d)\n"
" {\n"
" return input / div;\n"
" }\n"
" /// @dev Subtracts 3 from `input`\n"
" /// @param input Documentation for the input parameter\n"
" function sub(int input) returns(int d)\n"
" {\n"
" return input - 3;\n"
" }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter
/// @param second Documentation for the second parameter
function mul(uint a, uint second) returns(uint d) {
return a * 7 + second;
}
/// @dev Divides 2 numbers
/// @param input Documentation for the input parameter
/// @param div Documentation for the div parameter
function divide(uint input, uint div) returns(uint d) {
return input / div;
}
/// @dev Subtracts 3 from `input`
/// @param input Documentation for the input parameter
function sub(int input) returns(int d) {
return input - 3;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -314,14 +330,16 @@ BOOST_AUTO_TEST_CASE(dev_multiple_functions)
BOOST_AUTO_TEST_CASE(dev_return)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter starts here.\n"
" /// Since it's a really complicated parameter we need 2 lines\n"
" /// @param second Documentation for the second parameter\n"
" /// @return The result of the multiplication\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter starts here.
/// Since it's a really complicated parameter we need 2 lines
/// @param second Documentation for the second parameter
/// @return The result of the multiplication
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -339,15 +357,19 @@ BOOST_AUTO_TEST_CASE(dev_return)
}
BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter starts here.\n"
" /// Since it's a really complicated parameter we need 2 lines\n"
" /// @param second Documentation for the second parameter\n"
" /// @return\n"
" /// The result of the multiplication\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter starts here.
/// Since it's a really complicated parameter we need 2 lines
/// @param second Documentation for the second parameter
/// @return
/// The result of the multiplication
function mul(uint a, uint second) returns(uint d) {
return a * 7 + second;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -367,15 +389,19 @@ BOOST_AUTO_TEST_CASE(dev_return_desc_after_nl)
BOOST_AUTO_TEST_CASE(dev_multiline_return)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter starts here.\n"
" /// Since it's a really complicated parameter we need 2 lines\n"
" /// @param second Documentation for the second parameter\n"
" /// @return The result of the multiplication\n"
" /// and cookies with nutella\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter starts here.
/// Since it's a really complicated parameter we need 2 lines
/// @param second Documentation for the second parameter
/// @return The result of the multiplication
/// and cookies with nutella
function mul(uint a, uint second) returns(uint d) {
return a * 7 + second;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -394,17 +420,21 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return)
BOOST_AUTO_TEST_CASE(dev_multiline_comment)
{
char const* sourceCode = "contract test {\n"
" /**\n"
" * @dev Multiplies a number by 7 and adds second parameter\n"
" * @param a Documentation for the first parameter starts here.\n"
" * Since it's a really complicated parameter we need 2 lines\n"
" * @param second Documentation for the second parameter\n"
" * @return The result of the multiplication\n"
" * and cookies with nutella\n"
" */"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/**
* @dev Multiplies a number by 7 and adds second parameter
* @param a Documentation for the first parameter starts here.
* Since it's a really complicated parameter we need 2 lines
* @param second Documentation for the second parameter
* @return The result of the multiplication
* and cookies with nutella
*/
function mul(uint a, uint second) returns(uint d) {
return a * 7 + second;
}
}
)";
char const* natspec = "{"
"\"methods\":{"
@ -423,10 +453,12 @@ BOOST_AUTO_TEST_CASE(dev_multiline_comment)
BOOST_AUTO_TEST_CASE(dev_contract_no_doc)
{
char const* sourceCode = "contract test {\n"
" /// @dev Mul function\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Mul function
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
" \"methods\":{"
@ -441,12 +473,14 @@ BOOST_AUTO_TEST_CASE(dev_contract_no_doc)
BOOST_AUTO_TEST_CASE(dev_contract_doc)
{
char const* sourceCode = " /// @author Lefteris\n"
" /// @title Just a test contract\n"
"contract test {\n"
" /// @dev Mul function\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
/// @author Lefteris
/// @title Just a test contract
contract test {
/// @dev Mul function
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
" \"author\": \"Lefteris\","
@ -463,13 +497,15 @@ BOOST_AUTO_TEST_CASE(dev_contract_doc)
BOOST_AUTO_TEST_CASE(dev_author_at_function)
{
char const* sourceCode = " /// @author Lefteris\n"
" /// @title Just a test contract\n"
"contract test {\n"
" /// @dev Mul function\n"
" /// @author John Doe\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
/// @author Lefteris
/// @title Just a test contract
contract test {
/// @dev Mul function
/// @author John Doe
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
char const* natspec = "{"
" \"author\": \"Lefteris\","
@ -549,25 +585,29 @@ BOOST_AUTO_TEST_CASE(empty_comment)
BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
{
char const* sourceCode = " /// @author Lefteris\n"
" /// @title Just a test contract\n"
"contract test {\n"
" /// @dev Mul function\n"
" /// @title I really should not be here\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
/// @author Lefteris
/// @title Just a test contract
contract test {
/// @dev Mul function
/// @title I really should not be here
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
expectNatspecError(sourceCode);
}
BOOST_AUTO_TEST_CASE(dev_documenting_nonexistent_param)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param not_existing Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
char const* sourceCode = R"(
contract test {
/// @dev Multiplies a number by 7 and adds second parameter
/// @param a Documentation for the first parameter
/// @param not_existing Documentation for the second parameter
function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }
}
)";
expectNatspecError(sourceCode);
}