mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
SolidityNatspecJSON: Manual conversion of two test cases that would not be handled correctly by the script
- dev_multiple_params_mixed_whitespace has whitespace that is not completely preserved - dev_explicit_inherit_complex is a multi-file test
This commit is contained in:
parent
1041f071f0
commit
ba019e5a01
@ -1170,29 +1170,6 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params)
|
|||||||
checkNatspec(sourceCode, "test", natspec, false);
|
checkNatspec(sourceCode, "test", natspec, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dev_multiple_params_mixed_whitespace)
|
|
||||||
{
|
|
||||||
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) public returns (uint d) { return a * 7 + second; }\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
char const* natspec = "{"
|
|
||||||
"\"methods\":{"
|
|
||||||
" \"mul(uint256,uint256)\":{ \n"
|
|
||||||
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n"
|
|
||||||
" \"params\": {\n"
|
|
||||||
" \"a\": \"Documentation for the first parameter\",\n"
|
|
||||||
" \"second\": \"Documentation for the second parameter\"\n"
|
|
||||||
" }\n"
|
|
||||||
" }\n"
|
|
||||||
"}}";
|
|
||||||
|
|
||||||
checkNatspec(sourceCode, "test", natspec, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
|
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
@ -2771,77 +2748,6 @@ BOOST_AUTO_TEST_CASE(user_inherit_parameter_mismatch)
|
|||||||
checkNatspec(sourceCode, "Token", natspec2, true);
|
checkNatspec(sourceCode, "Token", natspec2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dev_explicit_inherit_complex)
|
|
||||||
{
|
|
||||||
char const *sourceCode1 = R"(
|
|
||||||
interface ERC20 {
|
|
||||||
/// Transfer ``amount`` from ``msg.sender`` to ``to``.
|
|
||||||
/// @dev test
|
|
||||||
/// @param to address to transfer to
|
|
||||||
/// @param amount amount to transfer
|
|
||||||
function transfer(address to, uint amount) external returns (bool);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ERC21 {
|
|
||||||
/// Transfer ``amount`` from ``msg.sender`` to ``to``.
|
|
||||||
/// @dev test2
|
|
||||||
/// @param to address to transfer to
|
|
||||||
/// @param amount amount to transfer
|
|
||||||
function transfer(address to, uint amount) external returns (bool);
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
char const *sourceCode2 = R"(
|
|
||||||
import "Interfaces.sol" as myInterfaces;
|
|
||||||
|
|
||||||
contract Token is myInterfaces.ERC20, myInterfaces.ERC21 {
|
|
||||||
/// @inheritdoc myInterfaces.ERC20
|
|
||||||
function transfer(address too, uint amount)
|
|
||||||
override(myInterfaces.ERC20, myInterfaces.ERC21) external returns (bool) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
char const *natspec = R"ABCDEF({
|
|
||||||
"methods":
|
|
||||||
{
|
|
||||||
"transfer(address,uint256)":
|
|
||||||
{
|
|
||||||
"details": "test",
|
|
||||||
"params":
|
|
||||||
{
|
|
||||||
"amount": "amount to transfer",
|
|
||||||
"to": "address to transfer to"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})ABCDEF";
|
|
||||||
|
|
||||||
m_compilerStack.reset();
|
|
||||||
m_compilerStack.setSources({
|
|
||||||
{"Interfaces.sol", "pragma solidity >=0.0;\n" + std::string(sourceCode1)},
|
|
||||||
{"Testfile.sol", "pragma solidity >=0.0;\n" + std::string(sourceCode2)}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_compilerStack.setEVMVersion(solidity::test::CommonOptions::get().evmVersion());
|
|
||||||
|
|
||||||
BOOST_REQUIRE_MESSAGE(m_compilerStack.parseAndAnalyze(), "Parsing contract failed");
|
|
||||||
|
|
||||||
Json::Value generatedDocumentation = m_compilerStack.natspecDev("Token");
|
|
||||||
Json::Value expectedDocumentation;
|
|
||||||
util::jsonParseStrict(natspec, expectedDocumentation);
|
|
||||||
|
|
||||||
expectedDocumentation["version"] = Json::Value(Natspec::c_natspecVersion);
|
|
||||||
expectedDocumentation["kind"] = Json::Value("dev");
|
|
||||||
|
|
||||||
BOOST_CHECK_MESSAGE(
|
|
||||||
expectedDocumentation == generatedDocumentation,
|
|
||||||
"Expected:\n" << util::jsonPrettyPrint(expectedDocumentation) <<
|
|
||||||
"\n but got:\n" << util::jsonPrettyPrint(generatedDocumentation)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(dev_different_return_name)
|
BOOST_AUTO_TEST_CASE(dev_different_return_name)
|
||||||
{
|
{
|
||||||
char const *sourceCode = R"(
|
char const *sourceCode = R"(
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
==== Source: Interfaces.sol ====
|
||||||
|
interface ERC20 {
|
||||||
|
/// Transfer ``amount`` from ``msg.sender`` to ``to``.
|
||||||
|
/// @dev test
|
||||||
|
/// @param to address to transfer to
|
||||||
|
/// @param amount amount to transfer
|
||||||
|
function transfer(address to, uint amount) external returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ERC21 {
|
||||||
|
/// Transfer ``amount`` from ``msg.sender`` to ``to``.
|
||||||
|
/// @dev test2
|
||||||
|
/// @param to address to transfer to
|
||||||
|
/// @param amount amount to transfer
|
||||||
|
function transfer(address to, uint amount) external returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
==== Source: Testfile.sol ====
|
||||||
|
import "Interfaces.sol" as myInterfaces;
|
||||||
|
|
||||||
|
contract Token is myInterfaces.ERC20, myInterfaces.ERC21 {
|
||||||
|
/// @inheritdoc myInterfaces.ERC20
|
||||||
|
function transfer(address too, uint amount)
|
||||||
|
override(myInterfaces.ERC20, myInterfaces.ERC21) external returns (bool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// ----
|
||||||
|
// Testfile.sol:Token devdoc
|
||||||
|
// {
|
||||||
|
// "methods":
|
||||||
|
// {
|
||||||
|
// "transfer(address,uint256)":
|
||||||
|
// {
|
||||||
|
// "details": "test",
|
||||||
|
// "params":
|
||||||
|
// {
|
||||||
|
// "amount": "amount to transfer",
|
||||||
|
// "to": "address to transfer to"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
@ -0,0 +1,24 @@
|
|||||||
|
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) public returns (uint d) { return a * 7 + second; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// ----
|
||||||
|
// :test devdoc
|
||||||
|
// {
|
||||||
|
// "methods":
|
||||||
|
// {
|
||||||
|
// "mul(uint256,uint256)":
|
||||||
|
// {
|
||||||
|
// "details": "Multiplies a number by 7 and adds second parameter",
|
||||||
|
// "params":
|
||||||
|
// {
|
||||||
|
// "a": "Documentation for the first parameter",
|
||||||
|
// "second": "Documentation for the second parameter"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user