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