Require strict parsing for natspec JSON tests

This commit is contained in:
Marenz 2022-01-19 14:30:47 +01:00
parent a07b3ec70f
commit 6d05912d70

View File

@ -56,7 +56,8 @@ public:
else else
generatedDocumentation = m_compilerStack.natspecDev(_contractName); generatedDocumentation = m_compilerStack.natspecDev(_contractName);
Json::Value expectedDocumentation; Json::Value expectedDocumentation;
util::jsonParseStrict(_expectedDocumentationString, expectedDocumentation); std::string parseError;
BOOST_REQUIRE_MESSAGE(util::jsonParseStrict(_expectedDocumentationString, expectedDocumentation, &parseError), parseError);
expectedDocumentation["version"] = Json::Value(Natspec::c_natspecVersion); expectedDocumentation["version"] = Json::Value(Natspec::c_natspecVersion);
expectedDocumentation["kind"] = Json::Value(_userDocumentation ? "user" : "dev"); expectedDocumentation["kind"] = Json::Value(_userDocumentation ? "user" : "dev");
@ -185,18 +186,27 @@ BOOST_AUTO_TEST_CASE(dev_and_user_basic_test)
} }
)"; )";
char const* devNatspec = "{" char const* devNatspec = R"R(
"\"methods\":{" {
" \"mul(uint256)\":{ \n" "methods" :
" \"details\": \"Multiplies a number by 7\"\n" {
" }\n" "mul(uint256)":
" }\n" {
"}}"; "details": "Multiplies a number by 7"
}
}
})R";
char const* userNatspec = "{" char const* userNatspec = R"R(
"\"methods\":{" {
" \"mul(uint256)\":{ \"notice\": \"Multiplies `a` by 7\"}" "methods" :
"}}"; {
"mul(uint256)":
{
"notice": "Multiplies `a` by 7"
}
}
})R";
checkNatspec(sourceCode, "test", devNatspec, false); checkNatspec(sourceCode, "test", devNatspec, false);
checkNatspec(sourceCode, "test", userNatspec, true); checkNatspec(sourceCode, "test", userNatspec, true);
@ -636,7 +646,7 @@ BOOST_AUTO_TEST_CASE(dev_return_no_params)
{ {
"methods": { "methods": {
"mul(uint256,uint256)": { "mul(uint256,uint256)": {
"returns": { "d": "The result of the multiplication" "returns": { "d": "The result of the multiplication" }
} }
} }
})ABCDEF"; })ABCDEF";
@ -866,19 +876,23 @@ BOOST_AUTO_TEST_CASE(dev_multiline_return)
} }
)"; )";
char const* natspec = "{" char const* natspec = R"R({
"\"methods\":{" "methods":
" \"mul(uint256,uint256)\":{ \n" {
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" "mul(uint256,uint256)": {
" \"params\": {\n" "details": "Multiplies a number by 7 and adds second parameter",
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" "params":
" \"second\": \"Documentation for the second parameter\"\n" {
" },\n" "a": "Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines",
" \"returns\": {\n" "second": "Documentation for the second parameter"
" \"d\": \"The result of the multiplication and cookies with nutella\",\n" },
" }\n" "returns":
" }\n" {
"}}"; "d": "The result of the multiplication and cookies with nutella"
}
}
}
})R";
checkNatspec(sourceCode, "test", natspec, false); checkNatspec(sourceCode, "test", natspec, false);
} }
@ -901,19 +915,25 @@ BOOST_AUTO_TEST_CASE(dev_multiline_comment)
} }
)"; )";
char const* natspec = "{" char const* natspec = R"R(
"\"methods\":{" {
" \"mul(uint256,uint256)\":{ \n" "methods":
" \"details\": \"Multiplies a number by 7 and adds second parameter\",\n" {
" \"params\": {\n" "mul(uint256,uint256)":
" \"a\": \"Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines\",\n" {
" \"second\": \"Documentation for the second parameter\"\n" "details": "Multiplies a number by 7 and adds second parameter",
" },\n" "params":
" \"returns\": {\n" {
" \"d\": \"The result of the multiplication and cookies with nutella\",\n" "a": "Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines",
" }\n" "second": "Documentation for the second parameter"
" }\n" },
"}}"; "returns":
{
"d": "The result of the multiplication and cookies with nutella"
}
}
}
})R";
checkNatspec(sourceCode, "test", natspec, false); checkNatspec(sourceCode, "test", natspec, false);
} }
@ -2295,7 +2315,7 @@ BOOST_AUTO_TEST_CASE(dev_return_name_no_description)
{ {
"returns": "returns":
{ {
"a": "a", "a": "a"
} }
} }
} }
@ -2308,7 +2328,7 @@ BOOST_AUTO_TEST_CASE(dev_return_name_no_description)
{ {
"returns": "returns":
{ {
"b": "a", "b": "a"
} }
} }
} }
@ -2465,7 +2485,8 @@ BOOST_AUTO_TEST_CASE(custom_inheritance)
} }
)"; )";
char const* natspecA = R"ABCDEF({ char const* natspecA = R"ABCDEF(
{
"methods": "methods":
{ {
"g(uint256)": "g(uint256)":
@ -2473,8 +2494,9 @@ BOOST_AUTO_TEST_CASE(custom_inheritance)
"custom:since": "2014" "custom:since": "2014"
} }
} }
)ABCDEF"; })ABCDEF";
char const* natspecB = R"ABCDEF({ char const* natspecB = R"ABCDEF(
{
"methods": {} "methods": {}
})ABCDEF"; })ABCDEF";