Skip to content

Commit a5f160b

Browse files
committed
ci: increase test coverage for the new XML generator
This adds support for all five admonition types, with corresponding tests, plus tests for type-based friend declarations and pointers to members.
1 parent b1fc43c commit a5f160b

16 files changed

Lines changed: 877 additions & 8 deletions

mrdocs.rnc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ grammar
211211
AnyType?
212212
}
213213

214+
MemberPointerType =
215+
element member-pointer
216+
{
217+
TypeBase,
218+
AnyType?
219+
}
220+
214221
NamedType =
215222
element named
216223
{
@@ -221,7 +228,8 @@ grammar
221228

222229
AnyType =
223230
ArrayType | AutoType | DecltypeType | FunctionType |
224-
LValueReferenceType | RValueReferenceType | PointerType | NamedType
231+
LValueReferenceType | RValueReferenceType | PointerType |
232+
MemberPointerType | NamedType
225233

226234
#---------------------------------------------
227235
# Template parameters (polymorphic)

src/lib/AST/ExtractDocComment.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,24 @@ class DocCommentVisitor
10041004
MRDOCS_UNREACHABLE();
10051005

10061006
default:
1007+
// Check if it's a custom command we registered (e.g. "tip", "important").
1008+
// These don't have KCI_ constants, since they are registered at runtime via
1009+
// initCustomCommentCommands().
1010+
llvm::StringRef name = cmd->Name;
1011+
if (name == "tip" || name == "important" || name == "caution")
1012+
{
1013+
doc::ParagraphBlock p = parseBlock(std::in_place_type<doc::ParagraphBlock>);
1014+
doc::AdmonitionKind k = name == "tip"
1015+
? doc::AdmonitionKind::tip
1016+
: name == "important"
1017+
? doc::AdmonitionKind::important
1018+
: doc::AdmonitionKind::caution;
1019+
doc::AdmonitionBlock adm(k);
1020+
adm.blocks.emplace_back(std::move(p));
1021+
jd_.Document.emplace_back(std::move(adm));
1022+
return;
1023+
}
1024+
10071025
// unsupported → ignore
10081026
return;
10091027
}
@@ -1157,8 +1175,10 @@ class DocCommentVisitor
11571175
void
11581176
initCustomCommentCommands(clang::ASTContext& context)
11591177
{
1160-
(void) context;
1161-
// Reserved for future custom commands registration.
1178+
clang::comments::CommandTraits& traits = context.getCommentCommandTraits();
1179+
traits.registerBlockCommand("tip");
1180+
traits.registerBlockCommand("important");
1181+
traits.registerBlockCommand("caution");
11621182
}
11631183

11641184
void

src/lib/Gen/xml/XMLWriter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ XMLWriter::write(T const& value)
113113
// Primitives: write as text content
114114
if constexpr (std::is_same_v<Type, bool>)
115115
{
116-
if (value) os_ << '1';
116+
os_ << '1';
117117
}
118118
else if constexpr (std::is_same_v<Type, std::string> ||
119119
std::is_same_v<Type, dom::String> ||
@@ -127,7 +127,7 @@ XMLWriter::write(T const& value)
127127
}
128128
else if constexpr (std::is_same_v<Type, SymbolID>)
129129
{
130-
if (value) os_ << toBase64Str(value);
130+
os_ << toBase64Str(value);
131131
}
132132
else if constexpr (boost::describe::has_describe_enumerators<Type>::value)
133133
{
@@ -178,8 +178,6 @@ XMLWriter::writeElement(std::string_view tag, T const& value)
178178
{ if (!value) return; }
179179
else if constexpr (is_optional<Type>::value)
180180
{ if (!value) return; }
181-
else if constexpr (is_polymorphic<Type>::value)
182-
{ if (value.valueless_after_move()) return; }
183181
else if constexpr (is_vector<Type>::value)
184182
{ if (value.empty()) return; }
185183

@@ -201,7 +199,10 @@ XMLWriter::writeElement(std::string_view tag, T const& value)
201199
}
202200
else if constexpr (is_polymorphic<Type>::value)
203201
{
204-
writePolymorphic(*value);
202+
if (!value.valueless_after_move())
203+
{
204+
writePolymorphic(*value);
205+
}
205206
}
206207
else if constexpr (is_vector<Type>::value)
207208
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Functions
8+
9+
[cols="1,4"]
10+
|===
11+
| Name| Description
12+
| link:#allAdmonitions[`allAdmonitions`]
13+
| Function with all admonition types
14+
|===
15+
16+
[#allAdmonitions]
17+
== allAdmonitions
18+
19+
Function with all admonition types
20+
21+
=== Synopsis
22+
23+
Declared in `&lt;admonitions&period;cpp&gt;`
24+
25+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
26+
----
27+
void
28+
allAdmonitions();
29+
----
30+
31+
=== Description
32+
33+
General description&period;
34+
35+
[CAUTION]
36+
====
37+
Be careful&period;
38+
39+
====
40+
41+
[IMPORTANT]
42+
====
43+
This is important&period;
44+
45+
====
46+
47+
[NOTE]
48+
====
49+
This is a note&period;
50+
51+
====
52+
53+
[TIP]
54+
====
55+
This is a tip&period;
56+
57+
====
58+
59+
[WARNING]
60+
====
61+
This is a warning&period;
62+
63+
====
64+
65+
66+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** Function with all admonition types
2+
3+
General description.
4+
5+
@caution Be careful.
6+
@important This is important.
7+
@note This is a note.
8+
@tip This is a tip.
9+
@warning This is a warning.
10+
*/
11+
void allAdmonitions();
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
<meta charset="utf-8">
5+
</head>
6+
<body>
7+
<div>
8+
<h1>Reference</h1>
9+
<div>
10+
<div>
11+
<h2 id="index">
12+
Global Namespace</h2>
13+
</div>
14+
<h2>
15+
Functions</h2>
16+
<table style="table-layout: fixed; width: 100%;">
17+
<thead>
18+
<tr>
19+
<th>Name</th><th>Description</th>
20+
</tr>
21+
</thead>
22+
<tbody>
23+
<tr>
24+
<td><a href="#allAdmonitions"><code>allAdmonitions</code></a> </td><td>Function with all admonition types</td></tr>
25+
</tbody>
26+
</table>
27+
28+
</div>
29+
<div>
30+
<div>
31+
<h2 id="allAdmonitions">
32+
allAdmonitions</h2>
33+
<div>
34+
<p>Function with all admonition types</p>
35+
</div>
36+
</div>
37+
<div>
38+
<h3>
39+
Synopsis</h3>
40+
<div>
41+
Declared in <code>&lt;admonitions.cpp&gt;</code></div>
42+
<pre><code class="source-code cpp">void
43+
allAdmonitions();</code></pre>
44+
</div>
45+
<div>
46+
<h3>
47+
Description</h3>
48+
<p>General description.</p>
49+
<div class="admonition">
50+
<h4>CAUTION</h4>
51+
<div>
52+
<p>Be careful.</p>
53+
</div>
54+
</div><div class="admonition">
55+
<h4>IMPORTANT</h4>
56+
<div>
57+
<p>This is important.</p>
58+
</div>
59+
</div><div class="admonition">
60+
<h4>NOTE</h4>
61+
<div>
62+
<p>This is a note.</p>
63+
</div>
64+
</div><div class="admonition">
65+
<h4>TIP</h4>
66+
<div>
67+
<p>This is a tip.</p>
68+
</div>
69+
</div><div class="admonition">
70+
<h4>WARNING</h4>
71+
<div>
72+
<p>This is a warning.</p>
73+
</div>
74+
</div></div>
75+
</div>
76+
77+
</div>
78+
<footer class="mrdocs-footer">
79+
<span>Created with <a href="https://www.mrdocs.com">MrDocs</a></span>
80+
</footer>
81+
</body>
82+
</html>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace>
5+
<source>
6+
</source>
7+
<id>//////////////////////////8=</id>
8+
<extraction>regular</extraction>
9+
<namespace-tranche>
10+
<functions>NeMs9Qpqlt/baij2ijbXagnblE8=</functions>
11+
</namespace-tranche>
12+
</namespace>
13+
<function>
14+
<name>allAdmonitions</name>
15+
<source>
16+
<location>
17+
<short-path>admonitions.cpp</short-path>
18+
<source-path>admonitions.cpp</source-path>
19+
<line-number>11</line-number>
20+
<column-number>1</column-number>
21+
<documented>1</documented>
22+
</location>
23+
</source>
24+
<id>NeMs9Qpqlt/baij2ijbXagnblE8=</id>
25+
<extraction>regular</extraction>
26+
<parent>//////////////////////////8=</parent>
27+
<doc-comment>
28+
<paragraph>
29+
<kind>paragraph</kind>
30+
<text>
31+
<kind>text</kind>
32+
<literal>General description.</literal>
33+
</text>
34+
</paragraph>
35+
<admonition>
36+
<kind>admonition</kind>
37+
<paragraph>
38+
<kind>paragraph</kind>
39+
<text>
40+
<kind>text</kind>
41+
<literal>Be careful.</literal>
42+
</text>
43+
</paragraph>
44+
<admonish>caution</admonish>
45+
</admonition>
46+
<admonition>
47+
<kind>admonition</kind>
48+
<paragraph>
49+
<kind>paragraph</kind>
50+
<text>
51+
<kind>text</kind>
52+
<literal>This is important.</literal>
53+
</text>
54+
</paragraph>
55+
<admonish>important</admonish>
56+
</admonition>
57+
<admonition>
58+
<kind>admonition</kind>
59+
<paragraph>
60+
<kind>paragraph</kind>
61+
<text>
62+
<kind>text</kind>
63+
<literal>This is a note.</literal>
64+
</text>
65+
</paragraph>
66+
<admonish>note</admonish>
67+
</admonition>
68+
<admonition>
69+
<kind>admonition</kind>
70+
<paragraph>
71+
<kind>paragraph</kind>
72+
<text>
73+
<kind>text</kind>
74+
<literal>This is a tip.</literal>
75+
</text>
76+
</paragraph>
77+
<admonish>tip</admonish>
78+
</admonition>
79+
<admonition>
80+
<kind>admonition</kind>
81+
<paragraph>
82+
<kind>paragraph</kind>
83+
<text>
84+
<kind>text</kind>
85+
<literal>This is a warning.</literal>
86+
</text>
87+
</paragraph>
88+
<admonish>warning</admonish>
89+
</admonition>
90+
<brief>
91+
<kind>brief</kind>
92+
<text>
93+
<kind>text</kind>
94+
<literal>Function with all admonition types</literal>
95+
</text>
96+
</brief>
97+
</doc-comment>
98+
<named>
99+
<name>
100+
<identifier>void</identifier>
101+
</name>
102+
</named>
103+
<func-class>normal</func-class>
104+
</function>
105+
</mrdocs>

test-files/golden-tests/snippets/terminate.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<literal>This function does not return.</literal>
4242
</text>
4343
</paragraph>
44+
<admonish>note</admonish>
4445
</admonition>
4546
<brief>
4647
<kind>brief</kind>

0 commit comments

Comments
 (0)