Adds natspec to AST for enum definition.

This commit is contained in:
Christian Parpart
2023-04-05 14:58:32 +02:00
committed by Nikola Matic
parent 7b634152bd
commit be8752b5d3
12 changed files with 180 additions and 10 deletions
@@ -0,0 +1,48 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"Color":
[
4
]
},
"id": 5,
"nodeType": "SourceUnit",
"nodes":
[
{
"canonicalName": "Color",
"documentation":
{
"id": 1,
"nodeType": "StructuredDocumentation",
"src": "0:112:1",
"text": "@title example of title\n @author example of author\n @notice example of notice\n @dev example of dev"
},
"id": 4,
"members":
[
{
"id": 2,
"name": "Red",
"nameLocation": "129:3:1",
"nodeType": "EnumValue",
"src": "129:3:1"
},
{
"id": 3,
"name": "Green",
"nameLocation": "138:5:1",
"nodeType": "EnumValue",
"src": "138:5:1"
}
],
"name": "Color",
"nameLocation": "117:5:1",
"nodeType": "EnumDefinition",
"src": "112:33:1"
}
],
"src": "112:34:1"
}
+10
View File
@@ -0,0 +1,10 @@
/// @title example of title
/// @author example of author
/// @notice example of notice
/// @dev example of dev
enum Color {
Red,
Green
}
// ----
@@ -0,0 +1,40 @@
{
"absolutePath": "a",
"id": 5,
"nodeType": "SourceUnit",
"nodes":
[
{
"documentation":
{
"id": 1,
"nodeType": "StructuredDocumentation",
"src": "0:112:1",
"text": "@title example of title\n @author example of author\n @notice example of notice\n @dev example of dev"
},
"id": 4,
"members":
[
{
"id": 2,
"name": "Red",
"nameLocation": "129:3:1",
"nodeType": "EnumValue",
"src": "129:3:1"
},
{
"id": 3,
"name": "Green",
"nameLocation": "138:5:1",
"nodeType": "EnumValue",
"src": "138:5:1"
}
],
"name": "Color",
"nameLocation": "117:5:1",
"nodeType": "EnumDefinition",
"src": "112:33:1"
}
],
"src": "112:34:1"
}
+34
View File
@@ -1076,6 +1076,40 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function)
expectNatspecError(sourceCode);
}
BOOST_AUTO_TEST_CASE(enum_no_docs)
{
char const* sourceCode = R"(
contract C {
/// @title example of title
/// @author example of author
/// @notice example of notice
/// @dev example of dev
enum Color {
Red,
Green
}
}
)";
char const* devDoc = R"ABCDEF(
{
"kind": "dev",
"methods": {},
"version": 1
})ABCDEF";
checkNatspec(sourceCode, "C", devDoc, false);
char const* userDoc = R"ABCDEF(
{
"kind": "user",
"methods": {},
"version": 1
})ABCDEF";
checkNatspec(sourceCode, "C", userDoc, true);
}
BOOST_AUTO_TEST_CASE(natspec_notice_without_tag)
{
char const* sourceCode = R"(
+1 -1
View File
@@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers)
s.annotation().recursive = false;
BOOST_CHECK_EQUAL(s.type()->identifier(), "t_type$_t_struct$_Struct_$3_storage_ptr_$");
EnumDefinition e(++id, {}, make_shared<string>("Enum"), {}, {});
EnumDefinition e(++id, {}, make_shared<string>("Enum"), {}, {}, {});
BOOST_CHECK_EQUAL(e.type()->identifier(), "t_type$_t_enum$_Enum_$4_$");
TupleType t({e.type(), s.type(), stringArray, nullptr});
+22 -4
View File
@@ -48,9 +48,18 @@ contract User
// <- {
// "contents": {
// "kind": "markdown",
// "value": "```solidity\ntype(enum User.SomeEnum)\n```\n\n"
// "value": "```solidity\ntype(enum User.SomeEnum)\n```\n\nSome enum value.\n\n"
// },
// "range": @Cursor1Range
// "range": {
// "end": {
// "character": 12,
// "line": 17
// },
// "start": {
// "character": 4,
// "line": 17
// }
// }
// }
// -> textDocument/hover {
// "position": @Cursor2
@@ -58,9 +67,18 @@ contract User
// <- {
// "contents": {
// "kind": "markdown",
// "value": "```solidity\ntype(enum User.SomeEnum)\n```\n\n"
// "value": "```solidity\ntype(enum User.SomeEnum)\n```\n\nSome enum value.\n\n"
// },
// "range": @Cursor2Range
// "range": {
// "end": {
// "character": 32,
// "line": 22
// },
// "start": {
// "character": 24,
// "line": 22
// }
// }
// }
// -> textDocument/hover {
// "position": @Cursor3
@@ -0,0 +1,11 @@
contract C {
/// @title example of title
/// @author example of author
/// @notice example of notice
/// @dev example of dev
enum Color {
Red,
Green
}
}
// ----