blob: 2c2175070c1f03ad2735aaeaf49263167c28faeb [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
388::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
389 size_t Idx,
390 VerbatimBlockComment *&VBC,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000391 StringRef Name,
392 StringRef CloseName) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000393 ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
394 if (!AR)
395 return AR;
396
397 StringRef ActualName = VBC->getCommandName();
398 if (ActualName != Name)
399 return ::testing::AssertionFailure()
400 << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
401 "expected \"" << Name.str() << "\"";
402
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000403 StringRef ActualCloseName = VBC->getCloseName();
404 if (ActualCloseName != CloseName)
405 return ::testing::AssertionFailure()
406 << "VerbatimBlockComment has closing command name \""
407 << ActualCloseName.str() << "\", "
408 "expected \"" << CloseName.str() << "\"";
409
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000410 return ::testing::AssertionSuccess();
411}
412
413struct NoLines {};
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000414struct Lines {};
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000415
416::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
417 size_t Idx,
418 VerbatimBlockComment *&VBC,
419 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000420 StringRef CloseName,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000421 NoLines) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000422 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
423 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000424 if (!AR)
425 return AR;
426
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000427 if (VBC->getNumLines() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000428 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000429 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000430 "expected 0";
431
432 return ::testing::AssertionSuccess();
433}
434
435::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
436 size_t Idx,
437 VerbatimBlockComment *&VBC,
438 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000439 StringRef CloseName,
440 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000441 StringRef Line0) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000442 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
443 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000444 if (!AR)
445 return AR;
446
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000447 if (VBC->getNumLines() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000448 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000449 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000450 "expected 1";
451
452 StringRef ActualLine0 = VBC->getText(0);
453 if (ActualLine0 != Line0)
454 return ::testing::AssertionFailure()
455 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
456 "expected \"" << Line0.str() << "\"";
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,
468 StringRef Line1) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000469 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
470 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000471 if (!AR)
472 return AR;
473
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000474 if (VBC->getNumLines() != 2)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000475 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000476 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000477 "expected 2";
478
479 StringRef ActualLine0 = VBC->getText(0);
480 if (ActualLine0 != Line0)
481 return ::testing::AssertionFailure()
482 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
483 "expected \"" << Line0.str() << "\"";
484
485 StringRef ActualLine1 = VBC->getText(1);
486 if (ActualLine1 != Line1)
487 return ::testing::AssertionFailure()
488 << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
489 "expected \"" << Line1.str() << "\"";
490
491 return ::testing::AssertionSuccess();
492}
493
494::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
495 size_t Idx,
496 VerbatimLineComment *&VLC,
497 StringRef Name,
498 StringRef Text) {
499 ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
500 if (!AR)
501 return AR;
502
503 StringRef ActualName = VLC->getCommandName();
504 if (ActualName != Name)
505 return ::testing::AssertionFailure()
506 << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
507 "expected \"" << Name.str() << "\"";
508
509 StringRef ActualText = VLC->getText();
510 if (ActualText != Text)
511 return ::testing::AssertionFailure()
512 << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
513 "expected \"" << Text.str() << "\"";
514
515 return ::testing::AssertionSuccess();
516}
517
518
519TEST_F(CommentParserTest, Basic1) {
520 const char *Source = "//";
521
522 FullComment *FC = parseString(Source);
523 ASSERT_TRUE(HasChildCount(FC, 0));
524}
525
526TEST_F(CommentParserTest, Basic2) {
527 const char *Source = "// Meow";
528
529 FullComment *FC = parseString(Source);
530 ASSERT_TRUE(HasChildCount(FC, 1));
531
532 {
533 ParagraphComment *PC;
534 ASSERT_TRUE(GetChildAt(FC, 0, PC));
535
536 ASSERT_TRUE(HasChildCount(PC, 1));
537 ASSERT_TRUE(HasTextAt(PC, 0, " Meow"));
538 }
539}
540
541TEST_F(CommentParserTest, Basic3) {
542 const char *Source =
543 "// Aaa\n"
544 "// Bbb";
545
546 FullComment *FC = parseString(Source);
547 ASSERT_TRUE(HasChildCount(FC, 1));
548
549 {
550 ParagraphComment *PC;
551 ASSERT_TRUE(GetChildAt(FC, 0, PC));
552
553 ASSERT_TRUE(HasChildCount(PC, 2));
554 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
555 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
556 }
557}
558
559TEST_F(CommentParserTest, Paragraph1) {
560 const char *Sources[] = {
561 "// Aaa\n"
562 "//\n"
563 "// Bbb",
564
565 "// Aaa\n"
566 "//\n"
567 "//\n"
568 "// Bbb",
569 };
570
571
572 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
573 FullComment *FC = parseString(Sources[i]);
574 ASSERT_TRUE(HasChildCount(FC, 2));
575
576 {
577 ParagraphComment *PC;
578 ASSERT_TRUE(GetChildAt(FC, 0, PC));
579
580 ASSERT_TRUE(HasChildCount(PC, 1));
581 ASSERT_TRUE(HasTextAt(PC, 0, " Aaa"));
582 }
583 {
584 ParagraphComment *PC;
585 ASSERT_TRUE(GetChildAt(FC, 1, PC));
586
587 ASSERT_TRUE(HasChildCount(PC, 1));
588 ASSERT_TRUE(HasTextAt(PC, 0, " Bbb"));
589 }
590 }
591}
592
593TEST_F(CommentParserTest, Paragraph2) {
594 const char *Source =
595 "// \\brief Aaa\n"
596 "//\n"
597 "// Bbb";
598
599 FullComment *FC = parseString(Source);
600 ASSERT_TRUE(HasChildCount(FC, 3));
601
602 {
603 ParagraphComment *PC;
604 ASSERT_TRUE(GetChildAt(FC, 0, PC));
605
606 ASSERT_TRUE(HasChildCount(PC, 1));
607 ASSERT_TRUE(HasTextAt(PC, 0, " "));
608 }
609 {
610 BlockCommandComment *BCC;
611 ParagraphComment *PC;
612 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
613
614 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
615
616 ASSERT_TRUE(HasChildCount(PC, 1));
617 ASSERT_TRUE(HasTextAt(PC, 0, " Aaa"));
618 }
619 {
620 ParagraphComment *PC;
621 ASSERT_TRUE(GetChildAt(FC, 2, PC));
622
623 ASSERT_TRUE(HasChildCount(PC, 1));
624 ASSERT_TRUE(HasTextAt(PC, 0, " Bbb"));
625 }
626}
627
628TEST_F(CommentParserTest, Paragraph3) {
629 const char *Source = "// \\brief \\author";
630
631 FullComment *FC = parseString(Source);
632 ASSERT_TRUE(HasChildCount(FC, 3));
633
634 {
635 ParagraphComment *PC;
636 ASSERT_TRUE(GetChildAt(FC, 0, PC));
637
638 ASSERT_TRUE(HasChildCount(PC, 1));
639 ASSERT_TRUE(HasTextAt(PC, 0, " "));
640 }
641 {
642 BlockCommandComment *BCC;
643 ParagraphComment *PC;
644 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
645
646 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
647 ASSERT_TRUE(HasChildCount(PC, 1));
648 ASSERT_TRUE(HasTextAt(PC, 0, " "));
649 }
650 {
651 BlockCommandComment *BCC;
652 ParagraphComment *PC;
653 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
654
655 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
656 ASSERT_TRUE(HasChildCount(PC, 0));
657 }
658}
659
660TEST_F(CommentParserTest, Paragraph4) {
661 const char *Source =
662 "// \\brief Aaa\n"
663 "// Bbb \\author\n"
664 "// Ccc";
665
666 FullComment *FC = parseString(Source);
667 ASSERT_TRUE(HasChildCount(FC, 3));
668
669 {
670 ParagraphComment *PC;
671 ASSERT_TRUE(GetChildAt(FC, 0, PC));
672
673 ASSERT_TRUE(HasChildCount(PC, 1));
674 ASSERT_TRUE(HasTextAt(PC, 0, " "));
675 }
676 {
677 BlockCommandComment *BCC;
678 ParagraphComment *PC;
679 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
680
681 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
682 ASSERT_TRUE(HasChildCount(PC, 2));
683 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
684 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
685 }
686 {
687 BlockCommandComment *BCC;
688 ParagraphComment *PC;
689 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
690
691 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
692 ASSERT_TRUE(HasChildCount(PC, 1));
693 ASSERT_TRUE(HasTextAt(PC, 0, " Ccc"));
694 }
695}
696
697TEST_F(CommentParserTest, ParamCommand1) {
698 const char *Source =
699 "// \\param aaa\n"
700 "// \\param [in] aaa\n"
701 "// \\param [out] aaa\n"
702 "// \\param [in,out] aaa\n"
703 "// \\param [in, out] aaa\n";
704
705 FullComment *FC = parseString(Source);
706 ASSERT_TRUE(HasChildCount(FC, 6));
707
708 {
709 ParagraphComment *PC;
710 ASSERT_TRUE(GetChildAt(FC, 0, PC));
711
712 ASSERT_TRUE(HasChildCount(PC, 1));
713 ASSERT_TRUE(HasTextAt(PC, 0, " "));
714 }
715 {
716 ParamCommandComment *PCC;
717 ParagraphComment *PC;
718 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
719 ParamCommandComment::In,
720 /* IsDirectionExplicit = */ false,
721 "aaa", PC));
722 ASSERT_TRUE(HasChildCount(PCC, 1));
723 ASSERT_TRUE(HasChildCount(PC, 1));
724 ASSERT_TRUE(HasTextAt(PC, 0, " "));
725 }
726 {
727 ParamCommandComment *PCC;
728 ParagraphComment *PC;
729 ASSERT_TRUE(HasParamCommandAt(FC, 2, PCC, "param",
730 ParamCommandComment::In,
731 /* IsDirectionExplicit = */ true,
732 "aaa", PC));
733 ASSERT_TRUE(HasChildCount(PCC, 1));
734 ASSERT_TRUE(HasChildCount(PC, 1));
735 ASSERT_TRUE(HasTextAt(PC, 0, " "));
736 }
737 {
738 ParamCommandComment *PCC;
739 ParagraphComment *PC;
740 ASSERT_TRUE(HasParamCommandAt(FC, 3, PCC, "param",
741 ParamCommandComment::Out,
742 /* IsDirectionExplicit = */ true,
743 "aaa", PC));
744 ASSERT_TRUE(HasChildCount(PCC, 1));
745 ASSERT_TRUE(HasChildCount(PC, 1));
746 ASSERT_TRUE(HasTextAt(PC, 0, " "));
747 }
748 {
749 ParamCommandComment *PCC;
750 ParagraphComment *PC;
751 ASSERT_TRUE(HasParamCommandAt(FC, 4, PCC, "param",
752 ParamCommandComment::InOut,
753 /* IsDirectionExplicit = */ true,
754 "aaa", PC));
755 ASSERT_TRUE(HasChildCount(PCC, 1));
756 ASSERT_TRUE(HasChildCount(PC, 1));
757 ASSERT_TRUE(HasTextAt(PC, 0, " "));
758 }
759 {
760 ParamCommandComment *PCC;
761 ParagraphComment *PC;
762 ASSERT_TRUE(HasParamCommandAt(FC, 5, PCC, "param",
763 ParamCommandComment::InOut,
764 /* IsDirectionExplicit = */ true,
765 "aaa", PC));
766 ASSERT_TRUE(HasChildCount(PCC, 1));
767 ASSERT_TRUE(HasChildCount(PC, 0));
768 }
769}
770
771TEST_F(CommentParserTest, InlineCommand1) {
772 const char *Source = "// \\c";
773
774 FullComment *FC = parseString(Source);
775 ASSERT_TRUE(HasChildCount(FC, 1));
776
777 {
778 ParagraphComment *PC;
779 InlineCommandComment *ICC;
780 ASSERT_TRUE(GetChildAt(FC, 0, PC));
781
782 ASSERT_TRUE(HasChildCount(PC, 2));
783 ASSERT_TRUE(HasTextAt(PC, 0, " "));
784 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
785 }
786}
787
788TEST_F(CommentParserTest, InlineCommand2) {
789 const char *Source = "// \\c ";
790
791 FullComment *FC = parseString(Source);
792 ASSERT_TRUE(HasChildCount(FC, 1));
793
794 {
795 ParagraphComment *PC;
796 InlineCommandComment *ICC;
797 ASSERT_TRUE(GetChildAt(FC, 0, PC));
798
799 ASSERT_TRUE(HasChildCount(PC, 3));
800 ASSERT_TRUE(HasTextAt(PC, 0, " "));
801 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
802 ASSERT_TRUE(HasTextAt(PC, 2, " "));
803 }
804}
805
806TEST_F(CommentParserTest, InlineCommand3) {
807 const char *Source = "// \\c aaa\n";
808
809 FullComment *FC = parseString(Source);
810 ASSERT_TRUE(HasChildCount(FC, 1));
811
812 {
813 ParagraphComment *PC;
814 InlineCommandComment *ICC;
815 ASSERT_TRUE(GetChildAt(FC, 0, PC));
816
817 ASSERT_TRUE(HasChildCount(PC, 2));
818 ASSERT_TRUE(HasTextAt(PC, 0, " "));
819 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
820 }
821}
822
823TEST_F(CommentParserTest, InlineCommand4) {
824 const char *Source = "// \\c aaa bbb";
825
826 FullComment *FC = parseString(Source);
827 ASSERT_TRUE(HasChildCount(FC, 1));
828
829 {
830 ParagraphComment *PC;
831 InlineCommandComment *ICC;
832 ASSERT_TRUE(GetChildAt(FC, 0, PC));
833
834 ASSERT_TRUE(HasChildCount(PC, 3));
835 ASSERT_TRUE(HasTextAt(PC, 0, " "));
836 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
837 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
838 }
839}
840
841TEST_F(CommentParserTest, InlineCommand5) {
842 const char *Source = "// \\unknown aaa\n";
843
844 FullComment *FC = parseString(Source);
845 ASSERT_TRUE(HasChildCount(FC, 1));
846
847 {
848 ParagraphComment *PC;
849 InlineCommandComment *ICC;
850 ASSERT_TRUE(GetChildAt(FC, 0, PC));
851
852 ASSERT_TRUE(HasChildCount(PC, 3));
853 ASSERT_TRUE(HasTextAt(PC, 0, " "));
854 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs()));
855 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
856 }
857}
858
859TEST_F(CommentParserTest, HTML1) {
860 const char *Sources[] = {
861 "// <a",
862 "// <a>",
863 "// <a >"
864 };
865
866 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
867 FullComment *FC = parseString(Sources[i]);
868 ASSERT_TRUE(HasChildCount(FC, 1));
869
870 {
871 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000872 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000873 ASSERT_TRUE(GetChildAt(FC, 0, PC));
874
875 ASSERT_TRUE(HasChildCount(PC, 2));
876 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000877 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000878 }
879 }
880}
881
882TEST_F(CommentParserTest, HTML2) {
883 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000884 "// <br/>",
885 "// <br />"
886 };
887
888 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
889 FullComment *FC = parseString(Sources[i]);
890 ASSERT_TRUE(HasChildCount(FC, 1));
891
892 {
893 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000894 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000895 ASSERT_TRUE(GetChildAt(FC, 0, PC));
896
897 ASSERT_TRUE(HasChildCount(PC, 2));
898 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000899 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000900 }
901 }
902}
903
904TEST_F(CommentParserTest, HTML3) {
905 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000906 "// <a href",
907 "// <a href ",
908 "// <a href>",
909 "// <a href >",
910 };
911
912 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
913 FullComment *FC = parseString(Sources[i]);
914 ASSERT_TRUE(HasChildCount(FC, 1));
915
916 {
917 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000918 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000919 ASSERT_TRUE(GetChildAt(FC, 0, PC));
920
921 ASSERT_TRUE(HasChildCount(PC, 2));
922 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000923 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000924 }
925 }
926}
927
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000928TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000929 const char *Sources[] = {
930 "// <a href=\"bbb\"",
931 "// <a href=\"bbb\">",
932 };
933
934 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
935 FullComment *FC = parseString(Sources[i]);
936 ASSERT_TRUE(HasChildCount(FC, 1));
937
938 {
939 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000940 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000941 ASSERT_TRUE(GetChildAt(FC, 0, PC));
942
943 ASSERT_TRUE(HasChildCount(PC, 2));
944 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000945 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000946 }
947 }
948}
949
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000950TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000951 const char *Sources[] = {
952 "// </a",
953 "// </a>",
954 "// </a >"
955 };
956
957 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
958 FullComment *FC = parseString(Sources[i]);
959 ASSERT_TRUE(HasChildCount(FC, 1));
960
961 {
962 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000963 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000964 ASSERT_TRUE(GetChildAt(FC, 0, PC));
965
966 ASSERT_TRUE(HasChildCount(PC, 2));
967 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000968 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000969 }
970 }
971}
972
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000973TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000974 const char *Source =
975 "// <pre>\n"
976 "// Aaa\n"
977 "// Bbb\n"
978 "// </pre>\n";
979
980 FullComment *FC = parseString(Source);
981 ASSERT_TRUE(HasChildCount(FC, 1));
982
983 {
984 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000985 HTMLStartTagComment *HST;
986 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000987 ASSERT_TRUE(GetChildAt(FC, 0, PC));
988
989 ASSERT_TRUE(HasChildCount(PC, 6));
990 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000991 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000992 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
993 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
994 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000995 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000996 }
997}
998
999TEST_F(CommentParserTest, VerbatimBlock1) {
1000 const char *Source = "// \\verbatim\\endverbatim\n";
1001
1002 FullComment *FC = parseString(Source);
1003 ASSERT_TRUE(HasChildCount(FC, 2));
1004
1005 {
1006 ParagraphComment *PC;
1007 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1008
1009 ASSERT_TRUE(HasChildCount(PC, 1));
1010 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1011 }
1012 {
1013 VerbatimBlockComment *VCC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001014 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
1015 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001016 }
1017}
1018
1019TEST_F(CommentParserTest, VerbatimBlock2) {
1020 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1021
1022 FullComment *FC = parseString(Source);
1023 ASSERT_TRUE(HasChildCount(FC, 2));
1024
1025 {
1026 ParagraphComment *PC;
1027 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1028
1029 ASSERT_TRUE(HasChildCount(PC, 1));
1030 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1031 }
1032 {
1033 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001034 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1035 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001036 }
1037}
1038
1039TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001040 const char *Source = "// \\verbatim Aaa\n";
1041
1042 FullComment *FC = parseString(Source);
1043 ASSERT_TRUE(HasChildCount(FC, 2));
1044
1045 {
1046 ParagraphComment *PC;
1047 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1048
1049 ASSERT_TRUE(HasChildCount(PC, 1));
1050 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1051 }
1052 {
1053 VerbatimBlockComment *VBC;
1054 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
1055 Lines(), " Aaa"));
1056 }
1057}
1058
1059TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001060 const char *Source =
1061 "//\\verbatim\n"
1062 "//\\endverbatim\n";
1063
1064 FullComment *FC = parseString(Source);
1065 ASSERT_TRUE(HasChildCount(FC, 1));
1066
1067 {
1068 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001069 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1070 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001071 }
1072}
1073
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001074TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001075 const char *Sources[] = {
1076 "//\\verbatim\n"
1077 "// Aaa\n"
1078 "//\\endverbatim\n",
1079
1080 "/*\\verbatim\n"
1081 " * Aaa\n"
1082 " *\\endverbatim*/"
1083 };
1084
1085 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1086 FullComment *FC = parseString(Sources[i]);
1087 ASSERT_TRUE(HasChildCount(FC, 1));
1088
1089 {
1090 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001091 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1092 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001093 }
1094 }
1095}
1096
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001097TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001098 const char *Sources[] = {
1099 "// \\verbatim\n"
1100 "// Aaa\n"
1101 "// \\endverbatim\n",
1102
1103 "/* \\verbatim\n"
1104 " * Aaa\n"
1105 " * \\endverbatim*/"
1106 };
1107
1108 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1109 FullComment *FC = parseString(Sources[i]);
1110 ASSERT_TRUE(HasChildCount(FC, 2));
1111
1112 {
1113 ParagraphComment *PC;
1114 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1115
1116 ASSERT_TRUE(HasChildCount(PC, 1));
1117 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1118 }
1119 {
1120 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001121 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1122 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001123 }
1124 }
1125}
1126
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001127TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001128 const char *Sources[] = {
1129 "// \\verbatim\n"
1130 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001131 "// Bbb\n"
1132 "// \\endverbatim\n",
1133
1134 "/* \\verbatim\n"
1135 " * Aaa\n"
1136 " * Bbb\n"
1137 " * \\endverbatim*/"
1138 };
1139
1140 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1141 FullComment *FC = parseString(Sources[i]);
1142 ASSERT_TRUE(HasChildCount(FC, 2));
1143
1144 {
1145 ParagraphComment *PC;
1146 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1147
1148 ASSERT_TRUE(HasChildCount(PC, 1));
1149 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1150 }
1151 {
1152 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001153 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1154 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001155 }
1156 }
1157}
1158
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001159TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001160 const char *Sources[] = {
1161 "// \\verbatim\n"
1162 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001163 "//\n"
1164 "// Bbb\n"
1165 "// \\endverbatim\n",
1166
1167 "/* \\verbatim\n"
1168 " * Aaa\n"
1169 " *\n"
1170 " * Bbb\n"
1171 " * \\endverbatim*/"
1172 };
1173 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001174 FullComment *FC = parseString(Sources[i]);
1175 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001176
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001177 {
1178 ParagraphComment *PC;
1179 ASSERT_TRUE(GetChildAt(FC, 0, PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001180
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001181 ASSERT_TRUE(HasChildCount(PC, 1));
1182 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1183 }
1184 {
1185 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001186 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001187 ASSERT_EQ(3U, VBC->getNumLines());
1188 ASSERT_EQ(" Aaa", VBC->getText(0));
1189 ASSERT_EQ("", VBC->getText(1));
1190 ASSERT_EQ(" Bbb", VBC->getText(2));
1191 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001192 }
1193}
1194
1195TEST_F(CommentParserTest, VerbatimLine1) {
1196 const char *Sources[] = {
1197 "// \\fn",
1198 "// \\fn\n"
1199 };
1200
1201 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1202 FullComment *FC = parseString(Sources[i]);
1203 ASSERT_TRUE(HasChildCount(FC, 2));
1204
1205 {
1206 ParagraphComment *PC;
1207 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1208
1209 ASSERT_TRUE(HasChildCount(PC, 1));
1210 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1211 }
1212 {
1213 VerbatimLineComment *VLC;
1214 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
1215 }
1216 }
1217}
1218
1219TEST_F(CommentParserTest, VerbatimLine2) {
1220 const char *Sources[] = {
1221 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1222 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1223 };
1224
1225 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1226 FullComment *FC = parseString(Sources[i]);
1227 ASSERT_TRUE(HasChildCount(FC, 2));
1228
1229 {
1230 ParagraphComment *PC;
1231 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1232
1233 ASSERT_TRUE(HasChildCount(PC, 1));
1234 ASSERT_TRUE(HasTextAt(PC, 0, " "));
1235 }
1236 {
1237 VerbatimLineComment *VLC;
1238 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
1239 " void *foo(const char *zzz = \"\\$\");"));
1240 }
1241 }
1242}
1243
1244} // unnamed namespace
1245
1246} // end namespace comments
1247} // end namespace clang
1248