1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
//===-- SymbolDocumentationTests.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "SymbolDocumentation.h"
#include "support/Markup.h"
#include "clang/Basic/CommentOptions.h"
#include "llvm/ADT/StringRef.h"
#include "gtest/gtest.h"
namespace clang {
namespace clangd {
TEST(SymbolDocumentation, UnhandledDocs) {
CommentOptions CommentOpts;
struct Case {
llvm::StringRef Documentation;
llvm::StringRef ExpectedRenderEscapedMarkdown;
llvm::StringRef ExpectedRenderMarkdown;
llvm::StringRef ExpectedRenderPlainText;
} Cases[] = {
{
"foo bar",
"foo bar",
"foo bar",
"foo bar",
},
{
"foo\nbar\n",
"foo\nbar",
"foo\nbar",
"foo bar",
},
{
"foo\n\nbar\n",
"foo\n\nbar",
"foo\n\nbar",
"foo\n\nbar",
},
{
"foo \\p bar baz",
"foo `bar` baz",
"foo `bar` baz",
"foo bar baz",
},
{
"foo \\e bar baz",
"foo \\*bar\\* baz",
"foo *bar* baz",
"foo *bar* baz",
},
{
"foo \\b bar baz",
"foo \\*\\*bar\\*\\* baz",
"foo **bar** baz",
"foo **bar** baz",
},
{
"foo \\ref bar baz",
"foo \\*\\*\\\\ref\\*\\* \\*bar\\* baz",
"foo **\\ref** *bar* baz",
"foo **\\ref** *bar* baz",
},
{
"foo @ref bar baz",
"foo \\*\\*@ref\\*\\* \\*bar\\* baz",
"foo **@ref** *bar* baz",
"foo **@ref** *bar* baz",
},
{
"\\brief this is a \\n\nbrief description",
"",
"",
"",
},
{
"\\throw exception foo",
"\\*\\*\\\\throw\\*\\* \\*exception\\* foo",
"**\\throw** *exception* foo",
"**\\throw** *exception* foo",
},
{
R"(\brief this is a brief description
\li item 1
\li item 2
\arg item 3)",
R"(- item 1
- item 2
- item 3)",
R"(- item 1
- item 2
- item 3)",
R"(- item 1
- item 2
- item 3)",
},
{
"\\defgroup mygroup this is a group\nthis is not a group description",
"\\*\\*@defgroup\\*\\* `mygroup this is a group`\n\nthis is not a "
"group "
"description",
"**@defgroup** `mygroup this is a group`\n\nthis is not a group "
"description",
"**@defgroup** `mygroup this is a group`\n\nthis is not a group "
"description",
},
{
R"(\verbatim
this is a
verbatim block containing
some verbatim text
\endverbatim)",
R"(\*\*@verbatim\*\*
```
this is a
verbatim block containing
some verbatim text
```
\*\*@endverbatim\*\*)",
R"(**@verbatim**
```
this is a
verbatim block containing
some verbatim text
```
**@endverbatim**)",
R"(**@verbatim**
this is a
verbatim block containing
some verbatim text
**@endverbatim**)",
},
{
"@param foo this is a parameter\n@param bar this is another "
"parameter",
"",
"",
"",
},
{
R"(@brief brief docs
@param foo this is a parameter
\brief another brief?
\details these are details
More description
documentation)",
R"(\*\*\\brief\*\* another brief?
\*\*\\details\*\* these are details
More description
documentation)",
R"(**\brief** another brief?
**\details** these are details
More description
documentation)",
R"(**\brief** another brief?
**\details** these are details
More description documentation)",
},
{
R"(<b>this is a bold text</b>
normal text<i>this is an italic text</i>
<code>this is a code block</code>)",
R"(\<b>this is a bold text\</b>
normal text\<i>this is an italic text\</i>
\<code>this is a code block\</code>)",
R"(\<b>this is a bold text\</b>
normal text\<i>this is an italic text\</i>
\<code>this is a code block\</code>)",
"<b>this is a bold text</b> normal text<i>this is an italic text</i> "
"<code>this is a code block</code>",
},
};
for (const auto &C : Cases) {
markup::Document Doc;
SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts);
SymbolDoc.docToMarkup(Doc);
EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText);
EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown);
EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown);
}
}
} // namespace clangd
} // namespace clang
|