blob: 3dce60ab731f555cc1d0e142857187c51807d1a9 [file] [log] [blame]
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001//===- unittests/AST/CommentParser.cpp ------ Comment parser tests --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chandler Carruth1050e8b2012-12-04 09:45:34 +000010#include "clang/AST/CommentParser.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000011#include "clang/AST/Comment.h"
12#include "clang/AST/CommentCommandTraits.h"
13#include "clang/AST/CommentLexer.h"
14#include "clang/AST/CommentSema.h"
Dmitri Gribenko6ebf0912013-02-22 14:21:27 +000015#include "clang/Basic/CommentOptions.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000016#include "clang/Basic/Diagnostic.h"
Douglas Gregor3aeb34f2012-10-23 22:38:58 +000017#include "clang/Basic/DiagnosticOptions.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000018#include "clang/Basic/FileManager.h"
Chandler Carruth7cc315c2012-12-04 09:53:37 +000019#include "clang/Basic/SourceManager.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000020#include "llvm/ADT/STLExtras.h"
21#include "llvm/Support/Allocator.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000022#include "gtest/gtest.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000023#include <vector>
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000024
25using namespace llvm;
26using namespace clang;
27
28namespace clang {
29namespace comments {
30
31namespace {
32
33const bool DEBUG = true;
34
35class CommentParserTest : public ::testing::Test {
36protected:
37 CommentParserTest()
38 : FileMgr(FileMgrOpts),
39 DiagID(new DiagnosticIDs()),
Douglas Gregor8e023612012-10-23 22:31:51 +000040 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000041 SourceMgr(Diags, FileMgr),
Dmitri Gribenko6ebf0912013-02-22 14:21:27 +000042 Traits(Allocator, CommentOptions()) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000043 }
44
45 FileSystemOptions FileMgrOpts;
46 FileManager FileMgr;
47 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
48 DiagnosticsEngine Diags;
49 SourceManager SourceMgr;
50 llvm::BumpPtrAllocator Allocator;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000051 CommandTraits Traits;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000052
53 FullComment *parseString(const char *Source);
54};
55
56FullComment *CommentParserTest::parseString(const char *Source) {
57 MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
58 FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
59 SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
60
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000061 Lexer L(Allocator, Traits, Begin, Source, Source + strlen(Source));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000062
Dmitri Gribenko19523542012-09-29 11:40:46 +000063 Sema S(Allocator, SourceMgr, Diags, Traits, /*PP=*/ NULL);
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000064 Parser P(L, S, Allocator, SourceMgr, Diags, Traits);
65 FullComment *FC = P.parseFullComment();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000066
67 if (DEBUG) {
68 llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000069 FC->dump(llvm::errs(), &Traits, &SourceMgr);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000070 }
71
72 Token Tok;
73 L.lex(Tok);
74 if (Tok.is(tok::eof))
75 return FC;
76 else
77 return NULL;
78}
79
80::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) {
81 if (!C)
82 return ::testing::AssertionFailure() << "Comment is NULL";
83
84 if (Count != C->child_count())
85 return ::testing::AssertionFailure()
86 << "Count = " << Count
87 << ", child_count = " << C->child_count();
88
89 return ::testing::AssertionSuccess();
90}
91
92template <typename T>
93::testing::AssertionResult GetChildAt(const Comment *C,
94 size_t Idx,
95 T *&Child) {
96 if (!C)
97 return ::testing::AssertionFailure() << "Comment is NULL";
98
99 if (Idx >= C->child_count())
100 return ::testing::AssertionFailure()
101 << "Idx out of range. Idx = " << Idx
102 << ", child_count = " << C->child_count();
103
104 Comment::child_iterator I = C->child_begin() + Idx;
105 Comment *CommentChild = *I;
106 if (!CommentChild)
107 return ::testing::AssertionFailure() << "Child is NULL";
108
109 Child = dyn_cast<T>(CommentChild);
110 if (!Child)
111 return ::testing::AssertionFailure()
112 << "Child is not of requested type, but a "
113 << CommentChild->getCommentKindName();
114
115 return ::testing::AssertionSuccess();
116}
117
118::testing::AssertionResult HasTextAt(const Comment *C,
119 size_t Idx,
120 StringRef Text) {
121 TextComment *TC;
122 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
123 if (!AR)
124 return AR;
125
126 StringRef ActualText = TC->getText();
127 if (ActualText != Text)
128 return ::testing::AssertionFailure()
129 << "TextComment has text \"" << ActualText.str() << "\", "
130 "expected \"" << Text.str() << "\"";
131
132 if (TC->hasTrailingNewline())
133 return ::testing::AssertionFailure()
134 << "TextComment has a trailing newline";
135
136 return ::testing::AssertionSuccess();
137}
138
139::testing::AssertionResult HasTextWithNewlineAt(const Comment *C,
140 size_t Idx,
141 StringRef Text) {
142 TextComment *TC;
143 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
144 if (!AR)
145 return AR;
146
147 StringRef ActualText = TC->getText();
148 if (ActualText != Text)
149 return ::testing::AssertionFailure()
150 << "TextComment has text \"" << ActualText.str() << "\", "
151 "expected \"" << Text.str() << "\"";
152
153 if (!TC->hasTrailingNewline())
154 return ::testing::AssertionFailure()
155 << "TextComment has no trailing newline";
156
157 return ::testing::AssertionSuccess();
158}
159
160::testing::AssertionResult HasBlockCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000161 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000162 size_t Idx,
163 BlockCommandComment *&BCC,
164 StringRef Name,
165 ParagraphComment *&Paragraph) {
166 ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC);
167 if (!AR)
168 return AR;
169
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000170 StringRef ActualName = BCC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000171 if (ActualName != Name)
172 return ::testing::AssertionFailure()
173 << "BlockCommandComment has name \"" << ActualName.str() << "\", "
174 "expected \"" << Name.str() << "\"";
175
176 Paragraph = BCC->getParagraph();
177
178 return ::testing::AssertionSuccess();
179}
180
181::testing::AssertionResult HasParamCommandAt(
182 const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000183 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000184 size_t Idx,
185 ParamCommandComment *&PCC,
186 StringRef CommandName,
187 ParamCommandComment::PassDirection Direction,
188 bool IsDirectionExplicit,
189 StringRef ParamName,
190 ParagraphComment *&Paragraph) {
191 ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC);
192 if (!AR)
193 return AR;
194
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000195 StringRef ActualCommandName = PCC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000196 if (ActualCommandName != CommandName)
197 return ::testing::AssertionFailure()
198 << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", "
199 "expected \"" << CommandName.str() << "\"";
200
201 if (PCC->getDirection() != Direction)
202 return ::testing::AssertionFailure()
203 << "ParamCommandComment has direction " << PCC->getDirection() << ", "
204 "expected " << Direction;
205
206 if (PCC->isDirectionExplicit() != IsDirectionExplicit)
207 return ::testing::AssertionFailure()
208 << "ParamCommandComment has "
209 << (PCC->isDirectionExplicit() ? "explicit" : "implicit")
210 << " direction, "
211 "expected " << (IsDirectionExplicit ? "explicit" : "implicit");
212
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000213 if (!ParamName.empty() && !PCC->hasParamName())
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000214 return ::testing::AssertionFailure()
215 << "ParamCommandComment has no parameter name";
216
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000217 StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamNameAsWritten() : "";
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000218 if (ActualParamName != ParamName)
219 return ::testing::AssertionFailure()
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000220 << "ParamCommandComment has parameter name \"" << ActualParamName.str()
221 << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000222 "expected \"" << ParamName.str() << "\"";
223
224 Paragraph = PCC->getParagraph();
225
226 return ::testing::AssertionSuccess();
227}
228
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000229::testing::AssertionResult HasTParamCommandAt(
230 const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000231 const CommandTraits &Traits,
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000232 size_t Idx,
233 TParamCommandComment *&TPCC,
234 StringRef CommandName,
235 StringRef ParamName,
236 ParagraphComment *&Paragraph) {
237 ::testing::AssertionResult AR = GetChildAt(C, Idx, TPCC);
238 if (!AR)
239 return AR;
240
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000241 StringRef ActualCommandName = TPCC->getCommandName(Traits);
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000242 if (ActualCommandName != CommandName)
243 return ::testing::AssertionFailure()
244 << "TParamCommandComment has name \"" << ActualCommandName.str() << "\", "
245 "expected \"" << CommandName.str() << "\"";
246
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000247 if (!ParamName.empty() && !TPCC->hasParamName())
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000248 return ::testing::AssertionFailure()
249 << "TParamCommandComment has no parameter name";
250
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000251 StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamNameAsWritten() : "";
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000252 if (ActualParamName != ParamName)
253 return ::testing::AssertionFailure()
254 << "TParamCommandComment has parameter name \"" << ActualParamName.str()
255 << "\", "
256 "expected \"" << ParamName.str() << "\"";
257
258 Paragraph = TPCC->getParagraph();
259
260 return ::testing::AssertionSuccess();
261}
262
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000263::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000264 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000265 size_t Idx,
266 InlineCommandComment *&ICC,
267 StringRef Name) {
268 ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
269 if (!AR)
270 return AR;
271
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000272 StringRef ActualName = ICC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000273 if (ActualName != Name)
274 return ::testing::AssertionFailure()
275 << "InlineCommandComment has name \"" << ActualName.str() << "\", "
276 "expected \"" << Name.str() << "\"";
277
278 return ::testing::AssertionSuccess();
279}
280
281struct NoArgs {};
282
283::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000284 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000285 size_t Idx,
286 InlineCommandComment *&ICC,
287 StringRef Name,
288 NoArgs) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000289 ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000290 if (!AR)
291 return AR;
292
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000293 if (ICC->getNumArgs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000294 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000295 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000296 "expected 0";
297
298 return ::testing::AssertionSuccess();
299}
300
301::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000302 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000303 size_t Idx,
304 InlineCommandComment *&ICC,
305 StringRef Name,
306 StringRef Arg) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000307 ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000308 if (!AR)
309 return AR;
310
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000311 if (ICC->getNumArgs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000312 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000313 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000314 "expected 1";
315
316 StringRef ActualArg = ICC->getArgText(0);
317 if (ActualArg != Arg)
318 return ::testing::AssertionFailure()
319 << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
320 "expected \"" << Arg.str() << "\"";
321
322 return ::testing::AssertionSuccess();
323}
324
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000325::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
326 size_t Idx,
327 HTMLStartTagComment *&HST,
328 StringRef TagName) {
329 ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000330 if (!AR)
331 return AR;
332
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000333 StringRef ActualTagName = HST->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000334 if (ActualTagName != TagName)
335 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000336 << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000337 "expected \"" << TagName.str() << "\"";
338
339 return ::testing::AssertionSuccess();
340}
341
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000342struct SelfClosing {};
343
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000344::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
345 size_t Idx,
346 HTMLStartTagComment *&HST,
347 StringRef TagName,
348 SelfClosing) {
349 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000350 if (!AR)
351 return AR;
352
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000353 if (!HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000354 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000355 << "HTMLStartTagComment is not self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000356
357 return ::testing::AssertionSuccess();
358}
359
360
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000361struct NoAttrs {};
362
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000363::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
364 size_t Idx,
365 HTMLStartTagComment *&HST,
366 StringRef TagName,
367 NoAttrs) {
368 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000369 if (!AR)
370 return AR;
371
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000372 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000373 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000374 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000375
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000376 if (HST->getNumAttrs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000377 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000378 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000379 "expected 0";
380
381 return ::testing::AssertionSuccess();
382}
383
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000384::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
385 size_t Idx,
386 HTMLStartTagComment *&HST,
387 StringRef TagName,
388 StringRef AttrName,
389 StringRef AttrValue) {
390 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000391 if (!AR)
392 return AR;
393
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000394 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000395 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000396 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000397
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000398 if (HST->getNumAttrs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000399 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000400 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000401 "expected 1";
402
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000403 StringRef ActualName = HST->getAttr(0).Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000404 if (ActualName != AttrName)
405 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000406 << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000407 "expected \"" << AttrName.str() << "\"";
408
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000409 StringRef ActualValue = HST->getAttr(0).Value;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000410 if (ActualValue != AttrValue)
411 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000412 << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000413 "expected \"" << AttrValue.str() << "\"";
414
415 return ::testing::AssertionSuccess();
416}
417
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000418::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
419 size_t Idx,
420 HTMLEndTagComment *&HET,
421 StringRef TagName) {
422 ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000423 if (!AR)
424 return AR;
425
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000426 StringRef ActualTagName = HET->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000427 if (ActualTagName != TagName)
428 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000429 << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000430 "expected \"" << TagName.str() << "\"";
431
432 return ::testing::AssertionSuccess();
433}
434
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000435::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
436 size_t Idx,
437 StringRef Text) {
438 ParagraphComment *PC;
439
440 {
441 ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
442 if (!AR)
443 return AR;
444 }
445
446 {
447 ::testing::AssertionResult AR = HasChildCount(PC, 1);
448 if (!AR)
449 return AR;
450 }
451
452 {
453 ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
454 if (!AR)
455 return AR;
456 }
457
458 return ::testing::AssertionSuccess();
459}
460
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000461::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000462 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000463 size_t Idx,
464 VerbatimBlockComment *&VBC,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000465 StringRef Name,
466 StringRef CloseName) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000467 ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
468 if (!AR)
469 return AR;
470
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000471 StringRef ActualName = VBC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000472 if (ActualName != Name)
473 return ::testing::AssertionFailure()
474 << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
475 "expected \"" << Name.str() << "\"";
476
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000477 StringRef ActualCloseName = VBC->getCloseName();
478 if (ActualCloseName != CloseName)
479 return ::testing::AssertionFailure()
480 << "VerbatimBlockComment has closing command name \""
481 << ActualCloseName.str() << "\", "
482 "expected \"" << CloseName.str() << "\"";
483
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000484 return ::testing::AssertionSuccess();
485}
486
487struct NoLines {};
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000488struct Lines {};
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000489
490::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000491 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000492 size_t Idx,
493 VerbatimBlockComment *&VBC,
494 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000495 StringRef CloseName,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000496 NoLines) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000497 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000498 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000499 if (!AR)
500 return AR;
501
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000502 if (VBC->getNumLines() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000503 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000504 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000505 "expected 0";
506
507 return ::testing::AssertionSuccess();
508}
509
510::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000511 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000512 size_t Idx,
513 VerbatimBlockComment *&VBC,
514 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000515 StringRef CloseName,
516 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000517 StringRef Line0) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000518 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000519 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000520 if (!AR)
521 return AR;
522
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000523 if (VBC->getNumLines() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000524 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000525 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000526 "expected 1";
527
528 StringRef ActualLine0 = VBC->getText(0);
529 if (ActualLine0 != Line0)
530 return ::testing::AssertionFailure()
531 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
532 "expected \"" << Line0.str() << "\"";
533
534 return ::testing::AssertionSuccess();
535}
536
537::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000538 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000539 size_t Idx,
540 VerbatimBlockComment *&VBC,
541 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000542 StringRef CloseName,
543 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000544 StringRef Line0,
545 StringRef Line1) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000546 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000547 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000548 if (!AR)
549 return AR;
550
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000551 if (VBC->getNumLines() != 2)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000552 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000553 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000554 "expected 2";
555
556 StringRef ActualLine0 = VBC->getText(0);
557 if (ActualLine0 != Line0)
558 return ::testing::AssertionFailure()
559 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
560 "expected \"" << Line0.str() << "\"";
561
562 StringRef ActualLine1 = VBC->getText(1);
563 if (ActualLine1 != Line1)
564 return ::testing::AssertionFailure()
565 << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
566 "expected \"" << Line1.str() << "\"";
567
568 return ::testing::AssertionSuccess();
569}
570
571::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000572 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000573 size_t Idx,
574 VerbatimLineComment *&VLC,
575 StringRef Name,
576 StringRef Text) {
577 ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
578 if (!AR)
579 return AR;
580
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000581 StringRef ActualName = VLC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000582 if (ActualName != Name)
583 return ::testing::AssertionFailure()
584 << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
585 "expected \"" << Name.str() << "\"";
586
587 StringRef ActualText = VLC->getText();
588 if (ActualText != Text)
589 return ::testing::AssertionFailure()
590 << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
591 "expected \"" << Text.str() << "\"";
592
593 return ::testing::AssertionSuccess();
594}
595
596
597TEST_F(CommentParserTest, Basic1) {
598 const char *Source = "//";
599
600 FullComment *FC = parseString(Source);
601 ASSERT_TRUE(HasChildCount(FC, 0));
602}
603
604TEST_F(CommentParserTest, Basic2) {
605 const char *Source = "// Meow";
606
607 FullComment *FC = parseString(Source);
608 ASSERT_TRUE(HasChildCount(FC, 1));
609
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000610 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000611}
612
613TEST_F(CommentParserTest, Basic3) {
614 const char *Source =
615 "// Aaa\n"
616 "// Bbb";
617
618 FullComment *FC = parseString(Source);
619 ASSERT_TRUE(HasChildCount(FC, 1));
620
621 {
622 ParagraphComment *PC;
623 ASSERT_TRUE(GetChildAt(FC, 0, PC));
624
625 ASSERT_TRUE(HasChildCount(PC, 2));
626 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
627 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
628 }
629}
630
631TEST_F(CommentParserTest, Paragraph1) {
632 const char *Sources[] = {
633 "// Aaa\n"
634 "//\n"
635 "// Bbb",
636
637 "// Aaa\n"
638 "//\n"
639 "//\n"
640 "// Bbb",
641 };
642
643
644 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
645 FullComment *FC = parseString(Sources[i]);
646 ASSERT_TRUE(HasChildCount(FC, 2));
647
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000648 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
649 ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000650 }
651}
652
653TEST_F(CommentParserTest, Paragraph2) {
654 const char *Source =
655 "// \\brief Aaa\n"
656 "//\n"
657 "// Bbb";
658
659 FullComment *FC = parseString(Source);
660 ASSERT_TRUE(HasChildCount(FC, 3));
661
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000662 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000663 {
664 BlockCommandComment *BCC;
665 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000666 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000667
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000668 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000669 }
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000670 ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000671}
672
673TEST_F(CommentParserTest, Paragraph3) {
674 const char *Source = "// \\brief \\author";
675
676 FullComment *FC = parseString(Source);
677 ASSERT_TRUE(HasChildCount(FC, 3));
678
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000679 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000680 {
681 BlockCommandComment *BCC;
682 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000683 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000684
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000685 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000686 }
687 {
688 BlockCommandComment *BCC;
689 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000690 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000691
692 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
693 ASSERT_TRUE(HasChildCount(PC, 0));
694 }
695}
696
697TEST_F(CommentParserTest, Paragraph4) {
698 const char *Source =
699 "// \\brief Aaa\n"
700 "// Bbb \\author\n"
701 "// Ccc";
702
703 FullComment *FC = parseString(Source);
704 ASSERT_TRUE(HasChildCount(FC, 3));
705
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000706 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000707 {
708 BlockCommandComment *BCC;
709 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000710 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000711
712 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
713 ASSERT_TRUE(HasChildCount(PC, 2));
714 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
715 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
716 }
717 {
718 BlockCommandComment *BCC;
719 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000720 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000721
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000722 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000723 }
724}
725
726TEST_F(CommentParserTest, ParamCommand1) {
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000727 const char *Source = "// \\param aaa";
728
729 FullComment *FC = parseString(Source);
730 ASSERT_TRUE(HasChildCount(FC, 2));
731
732 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
733 {
734 ParamCommandComment *PCC;
735 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000736 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000737 ParamCommandComment::In,
738 /* IsDirectionExplicit = */ false,
739 "aaa", PC));
740 ASSERT_TRUE(HasChildCount(PCC, 1));
741 ASSERT_TRUE(HasChildCount(PC, 0));
742 }
743}
744
745TEST_F(CommentParserTest, ParamCommand2) {
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000746 const char *Source = "// \\param\\brief";
747
748 FullComment *FC = parseString(Source);
749 ASSERT_TRUE(HasChildCount(FC, 3));
750
751 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
752 {
753 ParamCommandComment *PCC;
754 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000755 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000756 ParamCommandComment::In,
757 /* IsDirectionExplicit = */ false,
758 "", PC));
759 ASSERT_TRUE(HasChildCount(PCC, 1));
760 ASSERT_TRUE(HasChildCount(PC, 0));
761 }
762 {
763 BlockCommandComment *BCC;
764 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000765 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000766 ASSERT_TRUE(HasChildCount(PC, 0));
767 }
768}
769
770TEST_F(CommentParserTest, ParamCommand3) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000771 const char *Sources[] = {
772 "// \\param aaa Bbb\n",
773 "// \\param\n"
774 "// aaa Bbb\n",
775 "// \\param \n"
776 "// aaa Bbb\n",
777 "// \\param aaa\n"
778 "// Bbb\n"
779 };
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000780
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000781 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
782 FullComment *FC = parseString(Sources[i]);
783 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000784
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000785 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
786 {
787 ParamCommandComment *PCC;
788 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000789 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000790 ParamCommandComment::In,
791 /* IsDirectionExplicit = */ false,
792 "aaa", PC));
793 ASSERT_TRUE(HasChildCount(PCC, 1));
794 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
795 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000796 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000797}
798
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000799TEST_F(CommentParserTest, ParamCommand4) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000800 const char *Sources[] = {
801 "// \\param [in] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000802 "// \\param[in] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000803 "// \\param\n"
804 "// [in] aaa Bbb\n",
805 "// \\param [in]\n"
806 "// aaa Bbb\n",
807 "// \\param [in] aaa\n"
808 "// Bbb\n",
809 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000810
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000811 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
812 FullComment *FC = parseString(Sources[i]);
813 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000814
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000815 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
816 {
817 ParamCommandComment *PCC;
818 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000819 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000820 ParamCommandComment::In,
821 /* IsDirectionExplicit = */ true,
822 "aaa", PC));
823 ASSERT_TRUE(HasChildCount(PCC, 1));
824 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
825 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000826 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000827}
828
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000829TEST_F(CommentParserTest, ParamCommand5) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000830 const char *Sources[] = {
831 "// \\param [out] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000832 "// \\param[out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000833 "// \\param\n"
834 "// [out] aaa Bbb\n",
835 "// \\param [out]\n"
836 "// aaa Bbb\n",
837 "// \\param [out] aaa\n"
838 "// Bbb\n",
839 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000840
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000841 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
842 FullComment *FC = parseString(Sources[i]);
843 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000844
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000845 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
846 {
847 ParamCommandComment *PCC;
848 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000849 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000850 ParamCommandComment::Out,
851 /* IsDirectionExplicit = */ true,
852 "aaa", PC));
853 ASSERT_TRUE(HasChildCount(PCC, 1));
854 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
855 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000856 }
857}
858
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000859TEST_F(CommentParserTest, ParamCommand6) {
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000860 const char *Sources[] = {
861 "// \\param [in,out] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000862 "// \\param[in,out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000863 "// \\param [in, out] aaa Bbb\n",
864 "// \\param [in,\n"
865 "// out] aaa Bbb\n",
866 "// \\param [in,out]\n"
867 "// aaa Bbb\n",
868 "// \\param [in,out] aaa\n"
869 "// Bbb\n"
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000870 };
871
872 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
873 FullComment *FC = parseString(Sources[i]);
874 ASSERT_TRUE(HasChildCount(FC, 2));
875
876 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
877 {
878 ParamCommandComment *PCC;
879 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000880 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000881 ParamCommandComment::InOut,
882 /* IsDirectionExplicit = */ true,
883 "aaa", PC));
884 ASSERT_TRUE(HasChildCount(PCC, 1));
885 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
886 }
887 }
888}
889
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000890TEST_F(CommentParserTest, ParamCommand7) {
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000891 const char *Source =
892 "// \\param aaa \\% Bbb \\$ ccc\n";
893
894 FullComment *FC = parseString(Source);
895 ASSERT_TRUE(HasChildCount(FC, 2));
896
897 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
898 {
899 ParamCommandComment *PCC;
900 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000901 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000902 ParamCommandComment::In,
903 /* IsDirectionExplicit = */ false,
904 "aaa", PC));
905 ASSERT_TRUE(HasChildCount(PCC, 1));
906
907 ASSERT_TRUE(HasChildCount(PC, 5));
908 ASSERT_TRUE(HasTextAt(PC, 0, " "));
909 ASSERT_TRUE(HasTextAt(PC, 1, "%"));
910 ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
911 ASSERT_TRUE(HasTextAt(PC, 3, "$"));
912 ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
913 }
914}
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000915
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000916TEST_F(CommentParserTest, TParamCommand1) {
917 const char *Sources[] = {
918 "// \\tparam aaa Bbb\n",
919 "// \\tparam\n"
920 "// aaa Bbb\n",
921 "// \\tparam \n"
922 "// aaa Bbb\n",
923 "// \\tparam aaa\n"
924 "// Bbb\n"
925 };
926
927 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
928 FullComment *FC = parseString(Sources[i]);
929 ASSERT_TRUE(HasChildCount(FC, 2));
930
931 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
932 {
933 TParamCommandComment *TPCC;
934 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000935 ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam",
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000936 "aaa", PC));
937 ASSERT_TRUE(HasChildCount(TPCC, 1));
938 ASSERT_TRUE(HasParagraphCommentAt(TPCC, 0, " Bbb"));
939 }
940 }
941}
942
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000943TEST_F(CommentParserTest, TParamCommand2) {
944 const char *Source = "// \\tparam\\brief";
945
946 FullComment *FC = parseString(Source);
947 ASSERT_TRUE(HasChildCount(FC, 3));
948
949 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
950 {
951 TParamCommandComment *TPCC;
952 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000953 ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam", "", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000954 ASSERT_TRUE(HasChildCount(TPCC, 1));
955 ASSERT_TRUE(HasChildCount(PC, 0));
956 }
957 {
958 BlockCommandComment *BCC;
959 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000960 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000961 ASSERT_TRUE(HasChildCount(PC, 0));
962 }
963}
964
965
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000966TEST_F(CommentParserTest, InlineCommand1) {
967 const char *Source = "// \\c";
968
969 FullComment *FC = parseString(Source);
970 ASSERT_TRUE(HasChildCount(FC, 1));
971
972 {
973 ParagraphComment *PC;
974 InlineCommandComment *ICC;
975 ASSERT_TRUE(GetChildAt(FC, 0, PC));
976
977 ASSERT_TRUE(HasChildCount(PC, 2));
978 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000979 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000980 }
981}
982
983TEST_F(CommentParserTest, InlineCommand2) {
984 const char *Source = "// \\c ";
985
986 FullComment *FC = parseString(Source);
987 ASSERT_TRUE(HasChildCount(FC, 1));
988
989 {
990 ParagraphComment *PC;
991 InlineCommandComment *ICC;
992 ASSERT_TRUE(GetChildAt(FC, 0, PC));
993
994 ASSERT_TRUE(HasChildCount(PC, 3));
995 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000996 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000997 ASSERT_TRUE(HasTextAt(PC, 2, " "));
998 }
999}
1000
1001TEST_F(CommentParserTest, InlineCommand3) {
1002 const char *Source = "// \\c aaa\n";
1003
1004 FullComment *FC = parseString(Source);
1005 ASSERT_TRUE(HasChildCount(FC, 1));
1006
1007 {
1008 ParagraphComment *PC;
1009 InlineCommandComment *ICC;
1010 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1011
1012 ASSERT_TRUE(HasChildCount(PC, 2));
1013 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001014 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001015 }
1016}
1017
1018TEST_F(CommentParserTest, InlineCommand4) {
1019 const char *Source = "// \\c aaa bbb";
1020
1021 FullComment *FC = parseString(Source);
1022 ASSERT_TRUE(HasChildCount(FC, 1));
1023
1024 {
1025 ParagraphComment *PC;
1026 InlineCommandComment *ICC;
1027 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1028
1029 ASSERT_TRUE(HasChildCount(PC, 3));
1030 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001031 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001032 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
1033 }
1034}
1035
1036TEST_F(CommentParserTest, InlineCommand5) {
1037 const char *Source = "// \\unknown aaa\n";
1038
1039 FullComment *FC = parseString(Source);
1040 ASSERT_TRUE(HasChildCount(FC, 1));
1041
1042 {
1043 ParagraphComment *PC;
1044 InlineCommandComment *ICC;
1045 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1046
1047 ASSERT_TRUE(HasChildCount(PC, 3));
1048 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001049 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "unknown", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001050 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
1051 }
1052}
1053
1054TEST_F(CommentParserTest, HTML1) {
1055 const char *Sources[] = {
1056 "// <a",
1057 "// <a>",
1058 "// <a >"
1059 };
1060
1061 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1062 FullComment *FC = parseString(Sources[i]);
1063 ASSERT_TRUE(HasChildCount(FC, 1));
1064
1065 {
1066 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001067 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001068 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1069
1070 ASSERT_TRUE(HasChildCount(PC, 2));
1071 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001072 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001073 }
1074 }
1075}
1076
1077TEST_F(CommentParserTest, HTML2) {
1078 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001079 "// <br/>",
1080 "// <br />"
1081 };
1082
1083 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1084 FullComment *FC = parseString(Sources[i]);
1085 ASSERT_TRUE(HasChildCount(FC, 1));
1086
1087 {
1088 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001089 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001090 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1091
1092 ASSERT_TRUE(HasChildCount(PC, 2));
1093 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001094 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001095 }
1096 }
1097}
1098
1099TEST_F(CommentParserTest, HTML3) {
1100 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001101 "// <a href",
1102 "// <a href ",
1103 "// <a href>",
1104 "// <a href >",
1105 };
1106
1107 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1108 FullComment *FC = parseString(Sources[i]);
1109 ASSERT_TRUE(HasChildCount(FC, 1));
1110
1111 {
1112 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001113 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001114 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1115
1116 ASSERT_TRUE(HasChildCount(PC, 2));
1117 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001118 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001119 }
1120 }
1121}
1122
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001123TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001124 const char *Sources[] = {
1125 "// <a href=\"bbb\"",
1126 "// <a href=\"bbb\">",
1127 };
1128
1129 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1130 FullComment *FC = parseString(Sources[i]);
1131 ASSERT_TRUE(HasChildCount(FC, 1));
1132
1133 {
1134 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001135 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001136 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1137
1138 ASSERT_TRUE(HasChildCount(PC, 2));
1139 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001140 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001141 }
1142 }
1143}
1144
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001145TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001146 const char *Sources[] = {
1147 "// </a",
1148 "// </a>",
1149 "// </a >"
1150 };
1151
1152 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1153 FullComment *FC = parseString(Sources[i]);
1154 ASSERT_TRUE(HasChildCount(FC, 1));
1155
1156 {
1157 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001158 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001159 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1160
1161 ASSERT_TRUE(HasChildCount(PC, 2));
1162 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001163 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001164 }
1165 }
1166}
1167
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001168TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001169 const char *Source =
1170 "// <pre>\n"
1171 "// Aaa\n"
1172 "// Bbb\n"
1173 "// </pre>\n";
1174
1175 FullComment *FC = parseString(Source);
1176 ASSERT_TRUE(HasChildCount(FC, 1));
1177
1178 {
1179 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001180 HTMLStartTagComment *HST;
1181 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001182 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1183
1184 ASSERT_TRUE(HasChildCount(PC, 6));
1185 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001186 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001187 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1188 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1189 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001190 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001191 }
1192}
1193
1194TEST_F(CommentParserTest, VerbatimBlock1) {
1195 const char *Source = "// \\verbatim\\endverbatim\n";
1196
1197 FullComment *FC = parseString(Source);
1198 ASSERT_TRUE(HasChildCount(FC, 2));
1199
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001200 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001201 {
1202 VerbatimBlockComment *VCC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001203 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VCC,
1204 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001205 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001206 }
1207}
1208
1209TEST_F(CommentParserTest, VerbatimBlock2) {
1210 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1211
1212 FullComment *FC = parseString(Source);
1213 ASSERT_TRUE(HasChildCount(FC, 2));
1214
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001215 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001216 {
1217 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001218 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1219 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001220 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001221 }
1222}
1223
1224TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001225 const char *Source = "// \\verbatim Aaa\n";
1226
1227 FullComment *FC = parseString(Source);
1228 ASSERT_TRUE(HasChildCount(FC, 2));
1229
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001230 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001231 {
1232 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001233 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC, "verbatim", "",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001234 Lines(), " Aaa"));
1235 }
1236}
1237
1238TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001239 const char *Source =
1240 "//\\verbatim\n"
1241 "//\\endverbatim\n";
1242
1243 FullComment *FC = parseString(Source);
1244 ASSERT_TRUE(HasChildCount(FC, 1));
1245
1246 {
1247 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001248 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1249 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001250 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001251 }
1252}
1253
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001254TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001255 const char *Sources[] = {
1256 "//\\verbatim\n"
1257 "// Aaa\n"
1258 "//\\endverbatim\n",
1259
1260 "/*\\verbatim\n"
1261 " * Aaa\n"
1262 " *\\endverbatim*/"
1263 };
1264
1265 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1266 FullComment *FC = parseString(Sources[i]);
1267 ASSERT_TRUE(HasChildCount(FC, 1));
1268
1269 {
1270 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001271 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1272 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001273 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001274 }
1275 }
1276}
1277
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001278TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001279 const char *Sources[] = {
1280 "// \\verbatim\n"
1281 "// Aaa\n"
1282 "// \\endverbatim\n",
1283
1284 "/* \\verbatim\n"
1285 " * Aaa\n"
1286 " * \\endverbatim*/"
1287 };
1288
1289 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1290 FullComment *FC = parseString(Sources[i]);
1291 ASSERT_TRUE(HasChildCount(FC, 2));
1292
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001293 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001294 {
1295 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001296 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1297 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001298 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001299 }
1300 }
1301}
1302
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001303TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001304 const char *Sources[] = {
1305 "// \\verbatim\n"
1306 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001307 "// Bbb\n"
1308 "// \\endverbatim\n",
1309
1310 "/* \\verbatim\n"
1311 " * Aaa\n"
1312 " * Bbb\n"
1313 " * \\endverbatim*/"
1314 };
1315
1316 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1317 FullComment *FC = parseString(Sources[i]);
1318 ASSERT_TRUE(HasChildCount(FC, 2));
1319
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001320 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001321 {
1322 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001323 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1324 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001325 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001326 }
1327 }
1328}
1329
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001330TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001331 const char *Sources[] = {
1332 "// \\verbatim\n"
1333 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001334 "//\n"
1335 "// Bbb\n"
1336 "// \\endverbatim\n",
1337
1338 "/* \\verbatim\n"
1339 " * Aaa\n"
1340 " *\n"
1341 " * Bbb\n"
1342 " * \\endverbatim*/"
1343 };
1344 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001345 FullComment *FC = parseString(Sources[i]);
1346 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001347
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001348 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001349 {
1350 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001351 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1352 "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001353 ASSERT_EQ(3U, VBC->getNumLines());
1354 ASSERT_EQ(" Aaa", VBC->getText(0));
1355 ASSERT_EQ("", VBC->getText(1));
1356 ASSERT_EQ(" Bbb", VBC->getText(2));
1357 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001358 }
1359}
1360
1361TEST_F(CommentParserTest, VerbatimLine1) {
1362 const char *Sources[] = {
1363 "// \\fn",
1364 "// \\fn\n"
1365 };
1366
1367 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1368 FullComment *FC = parseString(Sources[i]);
1369 ASSERT_TRUE(HasChildCount(FC, 2));
1370
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001371 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001372 {
1373 VerbatimLineComment *VLC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001374 ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001375 }
1376 }
1377}
1378
1379TEST_F(CommentParserTest, VerbatimLine2) {
1380 const char *Sources[] = {
1381 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1382 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1383 };
1384
1385 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1386 FullComment *FC = parseString(Sources[i]);
1387 ASSERT_TRUE(HasChildCount(FC, 2));
1388
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001389 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001390 {
1391 VerbatimLineComment *VLC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001392 ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn",
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001393 " void *foo(const char *zzz = \"\\$\");"));
1394 }
1395 }
1396}
1397
1398} // unnamed namespace
1399
1400} // end namespace comments
1401} // end namespace clang
1402