blob: ed7681d5c58ff856678006e9f821c3309854a983 [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
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000758TEST_F(CommentParserTest, ParamCommand5) {
759 const char *Source =
760 "// \\param aaa \\% Bbb \\$ ccc\n";
761
762 FullComment *FC = parseString(Source);
763 ASSERT_TRUE(HasChildCount(FC, 2));
764
765 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
766 {
767 ParamCommandComment *PCC;
768 ParagraphComment *PC;
769 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
770 ParamCommandComment::In,
771 /* IsDirectionExplicit = */ false,
772 "aaa", PC));
773 ASSERT_TRUE(HasChildCount(PCC, 1));
774
775 ASSERT_TRUE(HasChildCount(PC, 5));
776 ASSERT_TRUE(HasTextAt(PC, 0, " "));
777 ASSERT_TRUE(HasTextAt(PC, 1, "%"));
778 ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
779 ASSERT_TRUE(HasTextAt(PC, 3, "$"));
780 ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
781 }
782}
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000783
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000784TEST_F(CommentParserTest, InlineCommand1) {
785 const char *Source = "// \\c";
786
787 FullComment *FC = parseString(Source);
788 ASSERT_TRUE(HasChildCount(FC, 1));
789
790 {
791 ParagraphComment *PC;
792 InlineCommandComment *ICC;
793 ASSERT_TRUE(GetChildAt(FC, 0, PC));
794
795 ASSERT_TRUE(HasChildCount(PC, 2));
796 ASSERT_TRUE(HasTextAt(PC, 0, " "));
797 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
798 }
799}
800
801TEST_F(CommentParserTest, InlineCommand2) {
802 const char *Source = "// \\c ";
803
804 FullComment *FC = parseString(Source);
805 ASSERT_TRUE(HasChildCount(FC, 1));
806
807 {
808 ParagraphComment *PC;
809 InlineCommandComment *ICC;
810 ASSERT_TRUE(GetChildAt(FC, 0, PC));
811
812 ASSERT_TRUE(HasChildCount(PC, 3));
813 ASSERT_TRUE(HasTextAt(PC, 0, " "));
814 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
815 ASSERT_TRUE(HasTextAt(PC, 2, " "));
816 }
817}
818
819TEST_F(CommentParserTest, InlineCommand3) {
820 const char *Source = "// \\c aaa\n";
821
822 FullComment *FC = parseString(Source);
823 ASSERT_TRUE(HasChildCount(FC, 1));
824
825 {
826 ParagraphComment *PC;
827 InlineCommandComment *ICC;
828 ASSERT_TRUE(GetChildAt(FC, 0, PC));
829
830 ASSERT_TRUE(HasChildCount(PC, 2));
831 ASSERT_TRUE(HasTextAt(PC, 0, " "));
832 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
833 }
834}
835
836TEST_F(CommentParserTest, InlineCommand4) {
837 const char *Source = "// \\c aaa bbb";
838
839 FullComment *FC = parseString(Source);
840 ASSERT_TRUE(HasChildCount(FC, 1));
841
842 {
843 ParagraphComment *PC;
844 InlineCommandComment *ICC;
845 ASSERT_TRUE(GetChildAt(FC, 0, PC));
846
847 ASSERT_TRUE(HasChildCount(PC, 3));
848 ASSERT_TRUE(HasTextAt(PC, 0, " "));
849 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
850 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
851 }
852}
853
854TEST_F(CommentParserTest, InlineCommand5) {
855 const char *Source = "// \\unknown aaa\n";
856
857 FullComment *FC = parseString(Source);
858 ASSERT_TRUE(HasChildCount(FC, 1));
859
860 {
861 ParagraphComment *PC;
862 InlineCommandComment *ICC;
863 ASSERT_TRUE(GetChildAt(FC, 0, PC));
864
865 ASSERT_TRUE(HasChildCount(PC, 3));
866 ASSERT_TRUE(HasTextAt(PC, 0, " "));
867 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs()));
868 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
869 }
870}
871
872TEST_F(CommentParserTest, HTML1) {
873 const char *Sources[] = {
874 "// <a",
875 "// <a>",
876 "// <a >"
877 };
878
879 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
880 FullComment *FC = parseString(Sources[i]);
881 ASSERT_TRUE(HasChildCount(FC, 1));
882
883 {
884 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000885 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000886 ASSERT_TRUE(GetChildAt(FC, 0, PC));
887
888 ASSERT_TRUE(HasChildCount(PC, 2));
889 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000890 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000891 }
892 }
893}
894
895TEST_F(CommentParserTest, HTML2) {
896 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000897 "// <br/>",
898 "// <br />"
899 };
900
901 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
902 FullComment *FC = parseString(Sources[i]);
903 ASSERT_TRUE(HasChildCount(FC, 1));
904
905 {
906 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000907 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000908 ASSERT_TRUE(GetChildAt(FC, 0, PC));
909
910 ASSERT_TRUE(HasChildCount(PC, 2));
911 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000912 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000913 }
914 }
915}
916
917TEST_F(CommentParserTest, HTML3) {
918 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000919 "// <a href",
920 "// <a href ",
921 "// <a href>",
922 "// <a href >",
923 };
924
925 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
926 FullComment *FC = parseString(Sources[i]);
927 ASSERT_TRUE(HasChildCount(FC, 1));
928
929 {
930 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000931 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000932 ASSERT_TRUE(GetChildAt(FC, 0, PC));
933
934 ASSERT_TRUE(HasChildCount(PC, 2));
935 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000936 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000937 }
938 }
939}
940
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000941TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000942 const char *Sources[] = {
943 "// <a href=\"bbb\"",
944 "// <a href=\"bbb\">",
945 };
946
947 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
948 FullComment *FC = parseString(Sources[i]);
949 ASSERT_TRUE(HasChildCount(FC, 1));
950
951 {
952 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000953 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000954 ASSERT_TRUE(GetChildAt(FC, 0, PC));
955
956 ASSERT_TRUE(HasChildCount(PC, 2));
957 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000958 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000959 }
960 }
961}
962
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000963TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000964 const char *Sources[] = {
965 "// </a",
966 "// </a>",
967 "// </a >"
968 };
969
970 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
971 FullComment *FC = parseString(Sources[i]);
972 ASSERT_TRUE(HasChildCount(FC, 1));
973
974 {
975 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000976 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000977 ASSERT_TRUE(GetChildAt(FC, 0, PC));
978
979 ASSERT_TRUE(HasChildCount(PC, 2));
980 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000981 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000982 }
983 }
984}
985
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000986TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000987 const char *Source =
988 "// <pre>\n"
989 "// Aaa\n"
990 "// Bbb\n"
991 "// </pre>\n";
992
993 FullComment *FC = parseString(Source);
994 ASSERT_TRUE(HasChildCount(FC, 1));
995
996 {
997 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000998 HTMLStartTagComment *HST;
999 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001000 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1001
1002 ASSERT_TRUE(HasChildCount(PC, 6));
1003 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001004 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001005 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1006 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1007 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001008 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001009 }
1010}
1011
1012TEST_F(CommentParserTest, VerbatimBlock1) {
1013 const char *Source = "// \\verbatim\\endverbatim\n";
1014
1015 FullComment *FC = parseString(Source);
1016 ASSERT_TRUE(HasChildCount(FC, 2));
1017
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001018 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001019 {
1020 VerbatimBlockComment *VCC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001021 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
1022 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001023 }
1024}
1025
1026TEST_F(CommentParserTest, VerbatimBlock2) {
1027 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1028
1029 FullComment *FC = parseString(Source);
1030 ASSERT_TRUE(HasChildCount(FC, 2));
1031
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001032 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001033 {
1034 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001035 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1036 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001037 }
1038}
1039
1040TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001041 const char *Source = "// \\verbatim Aaa\n";
1042
1043 FullComment *FC = parseString(Source);
1044 ASSERT_TRUE(HasChildCount(FC, 2));
1045
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001046 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001047 {
1048 VerbatimBlockComment *VBC;
1049 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
1050 Lines(), " Aaa"));
1051 }
1052}
1053
1054TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001055 const char *Source =
1056 "//\\verbatim\n"
1057 "//\\endverbatim\n";
1058
1059 FullComment *FC = parseString(Source);
1060 ASSERT_TRUE(HasChildCount(FC, 1));
1061
1062 {
1063 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001064 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1065 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001066 }
1067}
1068
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001069TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001070 const char *Sources[] = {
1071 "//\\verbatim\n"
1072 "// Aaa\n"
1073 "//\\endverbatim\n",
1074
1075 "/*\\verbatim\n"
1076 " * Aaa\n"
1077 " *\\endverbatim*/"
1078 };
1079
1080 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1081 FullComment *FC = parseString(Sources[i]);
1082 ASSERT_TRUE(HasChildCount(FC, 1));
1083
1084 {
1085 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001086 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1087 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001088 }
1089 }
1090}
1091
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001092TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001093 const char *Sources[] = {
1094 "// \\verbatim\n"
1095 "// Aaa\n"
1096 "// \\endverbatim\n",
1097
1098 "/* \\verbatim\n"
1099 " * Aaa\n"
1100 " * \\endverbatim*/"
1101 };
1102
1103 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1104 FullComment *FC = parseString(Sources[i]);
1105 ASSERT_TRUE(HasChildCount(FC, 2));
1106
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001107 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001108 {
1109 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001110 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1111 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001112 }
1113 }
1114}
1115
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001116TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001117 const char *Sources[] = {
1118 "// \\verbatim\n"
1119 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001120 "// Bbb\n"
1121 "// \\endverbatim\n",
1122
1123 "/* \\verbatim\n"
1124 " * Aaa\n"
1125 " * Bbb\n"
1126 " * \\endverbatim*/"
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, 2));
1132
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001133 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001134 {
1135 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001136 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1137 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001138 }
1139 }
1140}
1141
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001142TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001143 const char *Sources[] = {
1144 "// \\verbatim\n"
1145 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001146 "//\n"
1147 "// Bbb\n"
1148 "// \\endverbatim\n",
1149
1150 "/* \\verbatim\n"
1151 " * Aaa\n"
1152 " *\n"
1153 " * Bbb\n"
1154 " * \\endverbatim*/"
1155 };
1156 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001157 FullComment *FC = parseString(Sources[i]);
1158 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001159
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001160 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001161 {
1162 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001163 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001164 ASSERT_EQ(3U, VBC->getNumLines());
1165 ASSERT_EQ(" Aaa", VBC->getText(0));
1166 ASSERT_EQ("", VBC->getText(1));
1167 ASSERT_EQ(" Bbb", VBC->getText(2));
1168 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001169 }
1170}
1171
1172TEST_F(CommentParserTest, VerbatimLine1) {
1173 const char *Sources[] = {
1174 "// \\fn",
1175 "// \\fn\n"
1176 };
1177
1178 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1179 FullComment *FC = parseString(Sources[i]);
1180 ASSERT_TRUE(HasChildCount(FC, 2));
1181
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001182 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001183 {
1184 VerbatimLineComment *VLC;
1185 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
1186 }
1187 }
1188}
1189
1190TEST_F(CommentParserTest, VerbatimLine2) {
1191 const char *Sources[] = {
1192 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1193 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1194 };
1195
1196 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1197 FullComment *FC = parseString(Sources[i]);
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 VerbatimLineComment *VLC;
1203 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
1204 " void *foo(const char *zzz = \"\\$\");"));
1205 }
1206 }
1207}
1208
1209} // unnamed namespace
1210
1211} // end namespace comments
1212} // end namespace clang
1213