blob: 87e10cebc06bb94d2bb1d87e8106052a0cbff460 [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
10#include "clang/Basic/SourceManager.h"
11#include "clang/Basic/FileManager.h"
12#include "clang/Basic/Diagnostic.h"
13#include "clang/AST/Comment.h"
14#include "clang/AST/CommentLexer.h"
15#include "clang/AST/CommentParser.h"
16#include "clang/AST/CommentSema.h"
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/Support/Allocator.h"
19#include <vector>
20
21#include "gtest/gtest.h"
22
23using namespace llvm;
24using namespace clang;
25
26namespace clang {
27namespace comments {
28
29namespace {
30
31const bool DEBUG = true;
32
33class CommentParserTest : public ::testing::Test {
34protected:
35 CommentParserTest()
36 : FileMgr(FileMgrOpts),
37 DiagID(new DiagnosticIDs()),
38 Diags(DiagID, new IgnoringDiagConsumer()),
39 SourceMgr(Diags, FileMgr) {
40 }
41
42 FileSystemOptions FileMgrOpts;
43 FileManager FileMgr;
44 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
45 DiagnosticsEngine Diags;
46 SourceManager SourceMgr;
47 llvm::BumpPtrAllocator Allocator;
48
49 FullComment *parseString(const char *Source);
50};
51
52FullComment *CommentParserTest::parseString(const char *Source) {
53 MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
54 FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
55 SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
56
57 comments::Lexer L(Begin, CommentOptions(),
58 Source, Source + strlen(Source));
59
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000060 comments::Sema S(Allocator, SourceMgr, Diags);
61 comments::Parser P(L, S, Allocator, SourceMgr, Diags);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000062 comments::FullComment *FC = P.parseFullComment();
63
64 if (DEBUG) {
65 llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
66 FC->dump(SourceMgr);
67 }
68
69 Token Tok;
70 L.lex(Tok);
71 if (Tok.is(tok::eof))
72 return FC;
73 else
74 return NULL;
75}
76
77::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) {
78 if (!C)
79 return ::testing::AssertionFailure() << "Comment is NULL";
80
81 if (Count != C->child_count())
82 return ::testing::AssertionFailure()
83 << "Count = " << Count
84 << ", child_count = " << C->child_count();
85
86 return ::testing::AssertionSuccess();
87}
88
89template <typename T>
90::testing::AssertionResult GetChildAt(const Comment *C,
91 size_t Idx,
92 T *&Child) {
93 if (!C)
94 return ::testing::AssertionFailure() << "Comment is NULL";
95
96 if (Idx >= C->child_count())
97 return ::testing::AssertionFailure()
98 << "Idx out of range. Idx = " << Idx
99 << ", child_count = " << C->child_count();
100
101 Comment::child_iterator I = C->child_begin() + Idx;
102 Comment *CommentChild = *I;
103 if (!CommentChild)
104 return ::testing::AssertionFailure() << "Child is NULL";
105
106 Child = dyn_cast<T>(CommentChild);
107 if (!Child)
108 return ::testing::AssertionFailure()
109 << "Child is not of requested type, but a "
110 << CommentChild->getCommentKindName();
111
112 return ::testing::AssertionSuccess();
113}
114
115::testing::AssertionResult HasTextAt(const Comment *C,
116 size_t Idx,
117 StringRef Text) {
118 TextComment *TC;
119 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
120 if (!AR)
121 return AR;
122
123 StringRef ActualText = TC->getText();
124 if (ActualText != Text)
125 return ::testing::AssertionFailure()
126 << "TextComment has text \"" << ActualText.str() << "\", "
127 "expected \"" << Text.str() << "\"";
128
129 if (TC->hasTrailingNewline())
130 return ::testing::AssertionFailure()
131 << "TextComment has a trailing newline";
132
133 return ::testing::AssertionSuccess();
134}
135
136::testing::AssertionResult HasTextWithNewlineAt(const Comment *C,
137 size_t Idx,
138 StringRef Text) {
139 TextComment *TC;
140 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
141 if (!AR)
142 return AR;
143
144 StringRef ActualText = TC->getText();
145 if (ActualText != Text)
146 return ::testing::AssertionFailure()
147 << "TextComment has text \"" << ActualText.str() << "\", "
148 "expected \"" << Text.str() << "\"";
149
150 if (!TC->hasTrailingNewline())
151 return ::testing::AssertionFailure()
152 << "TextComment has no trailing newline";
153
154 return ::testing::AssertionSuccess();
155}
156
157::testing::AssertionResult HasBlockCommandAt(const Comment *C,
158 size_t Idx,
159 BlockCommandComment *&BCC,
160 StringRef Name,
161 ParagraphComment *&Paragraph) {
162 ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC);
163 if (!AR)
164 return AR;
165
166 StringRef ActualName = BCC->getCommandName();
167 if (ActualName != Name)
168 return ::testing::AssertionFailure()
169 << "BlockCommandComment has name \"" << ActualName.str() << "\", "
170 "expected \"" << Name.str() << "\"";
171
172 Paragraph = BCC->getParagraph();
173
174 return ::testing::AssertionSuccess();
175}
176
177::testing::AssertionResult HasParamCommandAt(
178 const Comment *C,
179 size_t Idx,
180 ParamCommandComment *&PCC,
181 StringRef CommandName,
182 ParamCommandComment::PassDirection Direction,
183 bool IsDirectionExplicit,
184 StringRef ParamName,
185 ParagraphComment *&Paragraph) {
186 ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC);
187 if (!AR)
188 return AR;
189
190 StringRef ActualCommandName = PCC->getCommandName();
191 if (ActualCommandName != CommandName)
192 return ::testing::AssertionFailure()
193 << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", "
194 "expected \"" << CommandName.str() << "\"";
195
196 if (PCC->getDirection() != Direction)
197 return ::testing::AssertionFailure()
198 << "ParamCommandComment has direction " << PCC->getDirection() << ", "
199 "expected " << Direction;
200
201 if (PCC->isDirectionExplicit() != IsDirectionExplicit)
202 return ::testing::AssertionFailure()
203 << "ParamCommandComment has "
204 << (PCC->isDirectionExplicit() ? "explicit" : "implicit")
205 << " direction, "
206 "expected " << (IsDirectionExplicit ? "explicit" : "implicit");
207
208 StringRef ActualParamName = PCC->getParamName();
209 if (ActualParamName != ParamName)
210 return ::testing::AssertionFailure()
211 << "ParamCommandComment has name \"" << ActualParamName.str() << "\", "
212 "expected \"" << ParamName.str() << "\"";
213
214 Paragraph = PCC->getParagraph();
215
216 return ::testing::AssertionSuccess();
217}
218
219::testing::AssertionResult HasInlineCommandAt(const Comment *C,
220 size_t Idx,
221 InlineCommandComment *&ICC,
222 StringRef Name) {
223 ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
224 if (!AR)
225 return AR;
226
227 StringRef ActualName = ICC->getCommandName();
228 if (ActualName != Name)
229 return ::testing::AssertionFailure()
230 << "InlineCommandComment has name \"" << ActualName.str() << "\", "
231 "expected \"" << Name.str() << "\"";
232
233 return ::testing::AssertionSuccess();
234}
235
236struct NoArgs {};
237
238::testing::AssertionResult HasInlineCommandAt(const Comment *C,
239 size_t Idx,
240 InlineCommandComment *&ICC,
241 StringRef Name,
242 NoArgs) {
243 ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name);
244 if (!AR)
245 return AR;
246
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000247 if (ICC->getNumArgs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000248 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000249 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000250 "expected 0";
251
252 return ::testing::AssertionSuccess();
253}
254
255::testing::AssertionResult HasInlineCommandAt(const Comment *C,
256 size_t Idx,
257 InlineCommandComment *&ICC,
258 StringRef Name,
259 StringRef Arg) {
260 ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name);
261 if (!AR)
262 return AR;
263
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000264 if (ICC->getNumArgs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000265 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000266 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000267 "expected 1";
268
269 StringRef ActualArg = ICC->getArgText(0);
270 if (ActualArg != Arg)
271 return ::testing::AssertionFailure()
272 << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
273 "expected \"" << Arg.str() << "\"";
274
275 return ::testing::AssertionSuccess();
276}
277
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000278::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
279 size_t Idx,
280 HTMLStartTagComment *&HST,
281 StringRef TagName) {
282 ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000283 if (!AR)
284 return AR;
285
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000286 StringRef ActualTagName = HST->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000287 if (ActualTagName != TagName)
288 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000289 << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000290 "expected \"" << TagName.str() << "\"";
291
292 return ::testing::AssertionSuccess();
293}
294
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000295struct SelfClosing {};
296
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000297::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
298 size_t Idx,
299 HTMLStartTagComment *&HST,
300 StringRef TagName,
301 SelfClosing) {
302 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000303 if (!AR)
304 return AR;
305
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000306 if (!HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000307 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000308 << "HTMLStartTagComment is not self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000309
310 return ::testing::AssertionSuccess();
311}
312
313
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000314struct NoAttrs {};
315
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000316::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
317 size_t Idx,
318 HTMLStartTagComment *&HST,
319 StringRef TagName,
320 NoAttrs) {
321 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000322 if (!AR)
323 return AR;
324
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000325 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000326 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000327 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000328
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000329 if (HST->getNumAttrs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000330 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000331 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000332 "expected 0";
333
334 return ::testing::AssertionSuccess();
335}
336
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000337::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
338 size_t Idx,
339 HTMLStartTagComment *&HST,
340 StringRef TagName,
341 StringRef AttrName,
342 StringRef AttrValue) {
343 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000344 if (!AR)
345 return AR;
346
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000347 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000348 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000349 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000350
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000351 if (HST->getNumAttrs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000352 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000353 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000354 "expected 1";
355
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000356 StringRef ActualName = HST->getAttr(0).Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000357 if (ActualName != AttrName)
358 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000359 << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000360 "expected \"" << AttrName.str() << "\"";
361
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000362 StringRef ActualValue = HST->getAttr(0).Value;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000363 if (ActualValue != AttrValue)
364 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000365 << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000366 "expected \"" << AttrValue.str() << "\"";
367
368 return ::testing::AssertionSuccess();
369}
370
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000371::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
372 size_t Idx,
373 HTMLEndTagComment *&HET,
374 StringRef TagName) {
375 ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000376 if (!AR)
377 return AR;
378
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000379 StringRef ActualTagName = HET->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000380 if (ActualTagName != TagName)
381 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000382 << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000383 "expected \"" << TagName.str() << "\"";
384
385 return ::testing::AssertionSuccess();
386}
387
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000388::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
389 size_t Idx,
390 StringRef Text) {
391 ParagraphComment *PC;
392
393 {
394 ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
395 if (!AR)
396 return AR;
397 }
398
399 {
400 ::testing::AssertionResult AR = HasChildCount(PC, 1);
401 if (!AR)
402 return AR;
403 }
404
405 {
406 ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
407 if (!AR)
408 return AR;
409 }
410
411 return ::testing::AssertionSuccess();
412}
413
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000414::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
415 size_t Idx,
416 VerbatimBlockComment *&VBC,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000417 StringRef Name,
418 StringRef CloseName) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000419 ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
420 if (!AR)
421 return AR;
422
423 StringRef ActualName = VBC->getCommandName();
424 if (ActualName != Name)
425 return ::testing::AssertionFailure()
426 << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
427 "expected \"" << Name.str() << "\"";
428
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000429 StringRef ActualCloseName = VBC->getCloseName();
430 if (ActualCloseName != CloseName)
431 return ::testing::AssertionFailure()
432 << "VerbatimBlockComment has closing command name \""
433 << ActualCloseName.str() << "\", "
434 "expected \"" << CloseName.str() << "\"";
435
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000436 return ::testing::AssertionSuccess();
437}
438
439struct NoLines {};
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000440struct Lines {};
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000441
442::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
443 size_t Idx,
444 VerbatimBlockComment *&VBC,
445 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000446 StringRef CloseName,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000447 NoLines) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000448 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
449 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000450 if (!AR)
451 return AR;
452
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000453 if (VBC->getNumLines() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000454 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000455 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000456 "expected 0";
457
458 return ::testing::AssertionSuccess();
459}
460
461::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
462 size_t Idx,
463 VerbatimBlockComment *&VBC,
464 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000465 StringRef CloseName,
466 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000467 StringRef Line0) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000468 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
469 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000470 if (!AR)
471 return AR;
472
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000473 if (VBC->getNumLines() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000474 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000475 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000476 "expected 1";
477
478 StringRef ActualLine0 = VBC->getText(0);
479 if (ActualLine0 != Line0)
480 return ::testing::AssertionFailure()
481 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
482 "expected \"" << Line0.str() << "\"";
483
484 return ::testing::AssertionSuccess();
485}
486
487::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
488 size_t Idx,
489 VerbatimBlockComment *&VBC,
490 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000491 StringRef CloseName,
492 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000493 StringRef Line0,
494 StringRef Line1) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000495 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
496 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000497 if (!AR)
498 return AR;
499
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000500 if (VBC->getNumLines() != 2)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000501 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000502 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000503 "expected 2";
504
505 StringRef ActualLine0 = VBC->getText(0);
506 if (ActualLine0 != Line0)
507 return ::testing::AssertionFailure()
508 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
509 "expected \"" << Line0.str() << "\"";
510
511 StringRef ActualLine1 = VBC->getText(1);
512 if (ActualLine1 != Line1)
513 return ::testing::AssertionFailure()
514 << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
515 "expected \"" << Line1.str() << "\"";
516
517 return ::testing::AssertionSuccess();
518}
519
520::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
521 size_t Idx,
522 VerbatimLineComment *&VLC,
523 StringRef Name,
524 StringRef Text) {
525 ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
526 if (!AR)
527 return AR;
528
529 StringRef ActualName = VLC->getCommandName();
530 if (ActualName != Name)
531 return ::testing::AssertionFailure()
532 << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
533 "expected \"" << Name.str() << "\"";
534
535 StringRef ActualText = VLC->getText();
536 if (ActualText != Text)
537 return ::testing::AssertionFailure()
538 << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
539 "expected \"" << Text.str() << "\"";
540
541 return ::testing::AssertionSuccess();
542}
543
544
545TEST_F(CommentParserTest, Basic1) {
546 const char *Source = "//";
547
548 FullComment *FC = parseString(Source);
549 ASSERT_TRUE(HasChildCount(FC, 0));
550}
551
552TEST_F(CommentParserTest, Basic2) {
553 const char *Source = "// Meow";
554
555 FullComment *FC = parseString(Source);
556 ASSERT_TRUE(HasChildCount(FC, 1));
557
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000558 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000559}
560
561TEST_F(CommentParserTest, Basic3) {
562 const char *Source =
563 "// Aaa\n"
564 "// Bbb";
565
566 FullComment *FC = parseString(Source);
567 ASSERT_TRUE(HasChildCount(FC, 1));
568
569 {
570 ParagraphComment *PC;
571 ASSERT_TRUE(GetChildAt(FC, 0, PC));
572
573 ASSERT_TRUE(HasChildCount(PC, 2));
574 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
575 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
576 }
577}
578
579TEST_F(CommentParserTest, Paragraph1) {
580 const char *Sources[] = {
581 "// Aaa\n"
582 "//\n"
583 "// Bbb",
584
585 "// Aaa\n"
586 "//\n"
587 "//\n"
588 "// Bbb",
589 };
590
591
592 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
593 FullComment *FC = parseString(Sources[i]);
594 ASSERT_TRUE(HasChildCount(FC, 2));
595
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000596 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
597 ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000598 }
599}
600
601TEST_F(CommentParserTest, Paragraph2) {
602 const char *Source =
603 "// \\brief Aaa\n"
604 "//\n"
605 "// Bbb";
606
607 FullComment *FC = parseString(Source);
608 ASSERT_TRUE(HasChildCount(FC, 3));
609
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000610 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000611 {
612 BlockCommandComment *BCC;
613 ParagraphComment *PC;
614 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
615
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000616 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000617 }
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000618 ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000619}
620
621TEST_F(CommentParserTest, Paragraph3) {
622 const char *Source = "// \\brief \\author";
623
624 FullComment *FC = parseString(Source);
625 ASSERT_TRUE(HasChildCount(FC, 3));
626
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000627 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000628 {
629 BlockCommandComment *BCC;
630 ParagraphComment *PC;
631 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
632
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000633 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000634 }
635 {
636 BlockCommandComment *BCC;
637 ParagraphComment *PC;
638 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
639
640 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
641 ASSERT_TRUE(HasChildCount(PC, 0));
642 }
643}
644
645TEST_F(CommentParserTest, Paragraph4) {
646 const char *Source =
647 "// \\brief Aaa\n"
648 "// Bbb \\author\n"
649 "// Ccc";
650
651 FullComment *FC = parseString(Source);
652 ASSERT_TRUE(HasChildCount(FC, 3));
653
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000654 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000655 {
656 BlockCommandComment *BCC;
657 ParagraphComment *PC;
658 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
659
660 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
661 ASSERT_TRUE(HasChildCount(PC, 2));
662 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
663 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
664 }
665 {
666 BlockCommandComment *BCC;
667 ParagraphComment *PC;
668 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
669
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000670 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000671 }
672}
673
674TEST_F(CommentParserTest, ParamCommand1) {
675 const char *Source =
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000676 "// \\param aaa Bbb\n";
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000677
678 FullComment *FC = parseString(Source);
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000679 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000680
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000681 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000682 {
683 ParamCommandComment *PCC;
684 ParagraphComment *PC;
685 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
686 ParamCommandComment::In,
687 /* IsDirectionExplicit = */ false,
688 "aaa", PC));
689 ASSERT_TRUE(HasChildCount(PCC, 1));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000690 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000691 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000692}
693
694TEST_F(CommentParserTest, ParamCommand2) {
695 const char *Source =
696 "// \\param [in] aaa Bbb\n";
697
698 FullComment *FC = parseString(Source);
699 ASSERT_TRUE(HasChildCount(FC, 2));
700
701 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000702 {
703 ParamCommandComment *PCC;
704 ParagraphComment *PC;
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000705 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000706 ParamCommandComment::In,
707 /* IsDirectionExplicit = */ true,
708 "aaa", PC));
709 ASSERT_TRUE(HasChildCount(PCC, 1));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000710 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000711 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000712}
713
714TEST_F(CommentParserTest, ParamCommand3) {
715 const char *Source =
716 "// \\param [out] aaa Bbb\n";
717
718 FullComment *FC = parseString(Source);
719 ASSERT_TRUE(HasChildCount(FC, 2));
720
721 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000722 {
723 ParamCommandComment *PCC;
724 ParagraphComment *PC;
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000725 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000726 ParamCommandComment::Out,
727 /* IsDirectionExplicit = */ true,
728 "aaa", PC));
729 ASSERT_TRUE(HasChildCount(PCC, 1));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000730 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000731 }
732}
733
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000734TEST_F(CommentParserTest, ParamCommand4) {
735 const char *Sources[] = {
736 "// \\param [in,out] aaa Bbb\n",
737 "// \\param [in, out] aaa Bbb\n"
738 };
739
740 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
741 FullComment *FC = parseString(Sources[i]);
742 ASSERT_TRUE(HasChildCount(FC, 2));
743
744 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
745 {
746 ParamCommandComment *PCC;
747 ParagraphComment *PC;
748 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
749 ParamCommandComment::InOut,
750 /* IsDirectionExplicit = */ true,
751 "aaa", PC));
752 ASSERT_TRUE(HasChildCount(PCC, 1));
753 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
754 }
755 }
756}
757
758
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000759TEST_F(CommentParserTest, InlineCommand1) {
760 const char *Source = "// \\c";
761
762 FullComment *FC = parseString(Source);
763 ASSERT_TRUE(HasChildCount(FC, 1));
764
765 {
766 ParagraphComment *PC;
767 InlineCommandComment *ICC;
768 ASSERT_TRUE(GetChildAt(FC, 0, PC));
769
770 ASSERT_TRUE(HasChildCount(PC, 2));
771 ASSERT_TRUE(HasTextAt(PC, 0, " "));
772 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
773 }
774}
775
776TEST_F(CommentParserTest, InlineCommand2) {
777 const char *Source = "// \\c ";
778
779 FullComment *FC = parseString(Source);
780 ASSERT_TRUE(HasChildCount(FC, 1));
781
782 {
783 ParagraphComment *PC;
784 InlineCommandComment *ICC;
785 ASSERT_TRUE(GetChildAt(FC, 0, PC));
786
787 ASSERT_TRUE(HasChildCount(PC, 3));
788 ASSERT_TRUE(HasTextAt(PC, 0, " "));
789 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
790 ASSERT_TRUE(HasTextAt(PC, 2, " "));
791 }
792}
793
794TEST_F(CommentParserTest, InlineCommand3) {
795 const char *Source = "// \\c aaa\n";
796
797 FullComment *FC = parseString(Source);
798 ASSERT_TRUE(HasChildCount(FC, 1));
799
800 {
801 ParagraphComment *PC;
802 InlineCommandComment *ICC;
803 ASSERT_TRUE(GetChildAt(FC, 0, PC));
804
805 ASSERT_TRUE(HasChildCount(PC, 2));
806 ASSERT_TRUE(HasTextAt(PC, 0, " "));
807 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
808 }
809}
810
811TEST_F(CommentParserTest, InlineCommand4) {
812 const char *Source = "// \\c aaa bbb";
813
814 FullComment *FC = parseString(Source);
815 ASSERT_TRUE(HasChildCount(FC, 1));
816
817 {
818 ParagraphComment *PC;
819 InlineCommandComment *ICC;
820 ASSERT_TRUE(GetChildAt(FC, 0, PC));
821
822 ASSERT_TRUE(HasChildCount(PC, 3));
823 ASSERT_TRUE(HasTextAt(PC, 0, " "));
824 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
825 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
826 }
827}
828
829TEST_F(CommentParserTest, InlineCommand5) {
830 const char *Source = "// \\unknown aaa\n";
831
832 FullComment *FC = parseString(Source);
833 ASSERT_TRUE(HasChildCount(FC, 1));
834
835 {
836 ParagraphComment *PC;
837 InlineCommandComment *ICC;
838 ASSERT_TRUE(GetChildAt(FC, 0, PC));
839
840 ASSERT_TRUE(HasChildCount(PC, 3));
841 ASSERT_TRUE(HasTextAt(PC, 0, " "));
842 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs()));
843 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
844 }
845}
846
847TEST_F(CommentParserTest, HTML1) {
848 const char *Sources[] = {
849 "// <a",
850 "// <a>",
851 "// <a >"
852 };
853
854 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
855 FullComment *FC = parseString(Sources[i]);
856 ASSERT_TRUE(HasChildCount(FC, 1));
857
858 {
859 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000860 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000861 ASSERT_TRUE(GetChildAt(FC, 0, PC));
862
863 ASSERT_TRUE(HasChildCount(PC, 2));
864 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000865 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000866 }
867 }
868}
869
870TEST_F(CommentParserTest, HTML2) {
871 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000872 "// <br/>",
873 "// <br />"
874 };
875
876 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
877 FullComment *FC = parseString(Sources[i]);
878 ASSERT_TRUE(HasChildCount(FC, 1));
879
880 {
881 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000882 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000883 ASSERT_TRUE(GetChildAt(FC, 0, PC));
884
885 ASSERT_TRUE(HasChildCount(PC, 2));
886 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000887 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000888 }
889 }
890}
891
892TEST_F(CommentParserTest, HTML3) {
893 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000894 "// <a href",
895 "// <a href ",
896 "// <a href>",
897 "// <a href >",
898 };
899
900 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
901 FullComment *FC = parseString(Sources[i]);
902 ASSERT_TRUE(HasChildCount(FC, 1));
903
904 {
905 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000906 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000907 ASSERT_TRUE(GetChildAt(FC, 0, PC));
908
909 ASSERT_TRUE(HasChildCount(PC, 2));
910 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000911 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000912 }
913 }
914}
915
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000916TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000917 const char *Sources[] = {
918 "// <a href=\"bbb\"",
919 "// <a href=\"bbb\">",
920 };
921
922 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
923 FullComment *FC = parseString(Sources[i]);
924 ASSERT_TRUE(HasChildCount(FC, 1));
925
926 {
927 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000928 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000929 ASSERT_TRUE(GetChildAt(FC, 0, PC));
930
931 ASSERT_TRUE(HasChildCount(PC, 2));
932 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000933 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000934 }
935 }
936}
937
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000938TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000939 const char *Sources[] = {
940 "// </a",
941 "// </a>",
942 "// </a >"
943 };
944
945 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
946 FullComment *FC = parseString(Sources[i]);
947 ASSERT_TRUE(HasChildCount(FC, 1));
948
949 {
950 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000951 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000952 ASSERT_TRUE(GetChildAt(FC, 0, PC));
953
954 ASSERT_TRUE(HasChildCount(PC, 2));
955 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000956 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000957 }
958 }
959}
960
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000961TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000962 const char *Source =
963 "// <pre>\n"
964 "// Aaa\n"
965 "// Bbb\n"
966 "// </pre>\n";
967
968 FullComment *FC = parseString(Source);
969 ASSERT_TRUE(HasChildCount(FC, 1));
970
971 {
972 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000973 HTMLStartTagComment *HST;
974 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000975 ASSERT_TRUE(GetChildAt(FC, 0, PC));
976
977 ASSERT_TRUE(HasChildCount(PC, 6));
978 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000979 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000980 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
981 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
982 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000983 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000984 }
985}
986
987TEST_F(CommentParserTest, VerbatimBlock1) {
988 const char *Source = "// \\verbatim\\endverbatim\n";
989
990 FullComment *FC = parseString(Source);
991 ASSERT_TRUE(HasChildCount(FC, 2));
992
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000993 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000994 {
995 VerbatimBlockComment *VCC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000996 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
997 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000998 }
999}
1000
1001TEST_F(CommentParserTest, VerbatimBlock2) {
1002 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1003
1004 FullComment *FC = parseString(Source);
1005 ASSERT_TRUE(HasChildCount(FC, 2));
1006
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001007 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001008 {
1009 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001010 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1011 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001012 }
1013}
1014
1015TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001016 const char *Source = "// \\verbatim Aaa\n";
1017
1018 FullComment *FC = parseString(Source);
1019 ASSERT_TRUE(HasChildCount(FC, 2));
1020
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001021 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001022 {
1023 VerbatimBlockComment *VBC;
1024 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
1025 Lines(), " Aaa"));
1026 }
1027}
1028
1029TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001030 const char *Source =
1031 "//\\verbatim\n"
1032 "//\\endverbatim\n";
1033
1034 FullComment *FC = parseString(Source);
1035 ASSERT_TRUE(HasChildCount(FC, 1));
1036
1037 {
1038 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001039 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1040 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001041 }
1042}
1043
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001044TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001045 const char *Sources[] = {
1046 "//\\verbatim\n"
1047 "// Aaa\n"
1048 "//\\endverbatim\n",
1049
1050 "/*\\verbatim\n"
1051 " * Aaa\n"
1052 " *\\endverbatim*/"
1053 };
1054
1055 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1056 FullComment *FC = parseString(Sources[i]);
1057 ASSERT_TRUE(HasChildCount(FC, 1));
1058
1059 {
1060 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001061 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1062 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001063 }
1064 }
1065}
1066
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001067TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001068 const char *Sources[] = {
1069 "// \\verbatim\n"
1070 "// Aaa\n"
1071 "// \\endverbatim\n",
1072
1073 "/* \\verbatim\n"
1074 " * Aaa\n"
1075 " * \\endverbatim*/"
1076 };
1077
1078 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1079 FullComment *FC = parseString(Sources[i]);
1080 ASSERT_TRUE(HasChildCount(FC, 2));
1081
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001082 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001083 {
1084 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001085 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1086 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001087 }
1088 }
1089}
1090
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001091TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001092 const char *Sources[] = {
1093 "// \\verbatim\n"
1094 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001095 "// Bbb\n"
1096 "// \\endverbatim\n",
1097
1098 "/* \\verbatim\n"
1099 " * Aaa\n"
1100 " * Bbb\n"
1101 " * \\endverbatim*/"
1102 };
1103
1104 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1105 FullComment *FC = parseString(Sources[i]);
1106 ASSERT_TRUE(HasChildCount(FC, 2));
1107
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001108 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001109 {
1110 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001111 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1112 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001113 }
1114 }
1115}
1116
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001117TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001118 const char *Sources[] = {
1119 "// \\verbatim\n"
1120 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001121 "//\n"
1122 "// Bbb\n"
1123 "// \\endverbatim\n",
1124
1125 "/* \\verbatim\n"
1126 " * Aaa\n"
1127 " *\n"
1128 " * Bbb\n"
1129 " * \\endverbatim*/"
1130 };
1131 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001132 FullComment *FC = parseString(Sources[i]);
1133 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001134
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001135 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001136 {
1137 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001138 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001139 ASSERT_EQ(3U, VBC->getNumLines());
1140 ASSERT_EQ(" Aaa", VBC->getText(0));
1141 ASSERT_EQ("", VBC->getText(1));
1142 ASSERT_EQ(" Bbb", VBC->getText(2));
1143 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001144 }
1145}
1146
1147TEST_F(CommentParserTest, VerbatimLine1) {
1148 const char *Sources[] = {
1149 "// \\fn",
1150 "// \\fn\n"
1151 };
1152
1153 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1154 FullComment *FC = parseString(Sources[i]);
1155 ASSERT_TRUE(HasChildCount(FC, 2));
1156
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001157 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001158 {
1159 VerbatimLineComment *VLC;
1160 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
1161 }
1162 }
1163}
1164
1165TEST_F(CommentParserTest, VerbatimLine2) {
1166 const char *Sources[] = {
1167 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1168 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1169 };
1170
1171 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1172 FullComment *FC = parseString(Sources[i]);
1173 ASSERT_TRUE(HasChildCount(FC, 2));
1174
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001175 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001176 {
1177 VerbatimLineComment *VLC;
1178 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
1179 " void *foo(const char *zzz = \"\\$\");"));
1180 }
1181 }
1182}
1183
1184} // unnamed namespace
1185
1186} // end namespace comments
1187} // end namespace clang
1188