mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2331 from ethereum/ASTDocumentationEntry
documentation field added to ContractDefinition-Node
This commit is contained in:
commit
21aafaa704
@ -252,6 +252,7 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
|
|||||||
{
|
{
|
||||||
setJsonNode(_node, "ContractDefinition", {
|
setJsonNode(_node, "ContractDefinition", {
|
||||||
make_pair("name", _node.name()),
|
make_pair("name", _node.name()),
|
||||||
|
make_pair("documentation", _node.documentation() ? Json::Value(*_node.documentation()) : Json::nullValue),
|
||||||
make_pair("contractKind", contractKind(_node.contractKind())),
|
make_pair("contractKind", contractKind(_node.contractKind())),
|
||||||
make_pair("fullyImplemented", _node.annotation().isFullyImplemented),
|
make_pair("fullyImplemented", _node.annotation().isFullyImplemented),
|
||||||
make_pair("linearizedBaseContracts", getContainerIds(_node.annotation().linearizedBaseContracts)),
|
make_pair("linearizedBaseContracts", getContainerIds(_node.annotation().linearizedBaseContracts)),
|
||||||
|
@ -228,6 +228,36 @@ BOOST_AUTO_TEST_CASE(function_type)
|
|||||||
BOOST_CHECK_EQUAL(funType["attributes"]["visibility"], "external");
|
BOOST_CHECK_EQUAL(funType["attributes"]["visibility"], "external");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(documentation)
|
||||||
|
{
|
||||||
|
CompilerStack c;
|
||||||
|
c.addSource("a", "/**This contract is empty*/ contract C {}");
|
||||||
|
c.addSource("b",
|
||||||
|
"/**This contract is empty"
|
||||||
|
" and has a line-breaking comment.*/"
|
||||||
|
"contract C {}"
|
||||||
|
);
|
||||||
|
c.parseAndAnalyze();
|
||||||
|
map<string, unsigned> sourceIndices;
|
||||||
|
sourceIndices["a"] = 0;
|
||||||
|
sourceIndices["b"] = 1;
|
||||||
|
Json::Value astJsonA = ASTJsonConverter(true, sourceIndices).toJson(c.ast("a"));
|
||||||
|
Json::Value documentationA = astJsonA["children"][0]["attributes"]["documentation"];
|
||||||
|
BOOST_CHECK_EQUAL(documentationA, "This contract is empty");
|
||||||
|
Json::Value astJsonB = ASTJsonConverter(true, sourceIndices).toJson(c.ast("b"));
|
||||||
|
Json::Value documentationB = astJsonB["children"][0]["attributes"]["documentation"];
|
||||||
|
BOOST_CHECK_EQUAL(documentationB, "This contract is empty and has a line-breaking comment.");
|
||||||
|
//same tests for non-legacy mode
|
||||||
|
astJsonA = ASTJsonConverter(false, sourceIndices).toJson(c.ast("a"));
|
||||||
|
documentationA = astJsonA["nodes"][0]["documentation"];
|
||||||
|
BOOST_CHECK_EQUAL(documentationA, "This contract is empty");
|
||||||
|
astJsonB = ASTJsonConverter(false, sourceIndices).toJson(c.ast("b"));
|
||||||
|
documentationB = astJsonB["nodes"][0]["documentation"];
|
||||||
|
BOOST_CHECK_EQUAL(documentationB, "This contract is empty and has a line-breaking comment.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -90,11 +90,11 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
|
|||||||
BOOST_CHECK(result["sources"]["fileA"].isObject());
|
BOOST_CHECK(result["sources"]["fileA"].isObject());
|
||||||
BOOST_CHECK(result["sources"]["fileA"]["AST"].isObject());
|
BOOST_CHECK(result["sources"]["fileA"]["AST"].isObject());
|
||||||
BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["AST"]) ==
|
BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["AST"]) ==
|
||||||
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},"
|
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},"
|
||||||
"\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null],"
|
"\"children\":[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null],"
|
||||||
"\"contractKind\":\"contract\",\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],"
|
"\"contractKind\":\"contract\",\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],"
|
||||||
"\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\","
|
"\"name\":\"A\",\"nodes\":[null],\"scope\":2},\"id\":1,\"name\":\"ContractDefinition\","
|
||||||
"\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}");
|
"\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}");
|
||||||
}
|
}
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
|
|||||||
BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["legacyAST"]) ==
|
BOOST_CHECK(dev::jsonCompactPrint(result["sources"]["fileA"]["legacyAST"]) ==
|
||||||
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},\"children\":"
|
"{\"attributes\":{\"absolutePath\":\"fileA\",\"exportedSymbols\":{\"A\":[1]}},\"children\":"
|
||||||
"[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null],\"contractKind\":\"contract\","
|
"[{\"attributes\":{\"baseContracts\":[null],\"contractDependencies\":[null],\"contractKind\":\"contract\","
|
||||||
"\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],\"name\":\"A\",\"nodes\":[null],\"scope\":2},"
|
"\"documentation\":null,\"fullyImplemented\":true,\"linearizedBaseContracts\":[1],\"name\":\"A\",\"nodes\":[null],\"scope\":2},"
|
||||||
"\"id\":1,\"name\":\"ContractDefinition\",\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}");
|
"\"id\":1,\"name\":\"ContractDefinition\",\"src\":\"0:14:0\"}],\"id\":2,\"name\":\"SourceUnit\",\"src\":\"0:14:0\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user