blob: 47433aee2be5e72ea145ad83fb3a710528370fea [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
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000208 if (!PCC->hasParamName())
209 return ::testing::AssertionFailure()
210 << "ParamCommandComment has no parameter name";
211
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000212 StringRef ActualParamName = PCC->getParamName();
213 if (ActualParamName != ParamName)
214 return ::testing::AssertionFailure()
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000215 << "ParamCommandComment has parameter name \"" << ActualParamName.str()
216 << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000217 "expected \"" << ParamName.str() << "\"";
218
219 Paragraph = PCC->getParagraph();
220
221 return ::testing::AssertionSuccess();
222}
223
224::testing::AssertionResult HasInlineCommandAt(const Comment *C,
225 size_t Idx,
226 InlineCommandComment *&ICC,
227 StringRef Name) {
228 ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
229 if (!AR)
230 return AR;
231
232 StringRef ActualName = ICC->getCommandName();
233 if (ActualName != Name)
234 return ::testing::AssertionFailure()
235 << "InlineCommandComment has name \"" << ActualName.str() << "\", "
236 "expected \"" << Name.str() << "\"";
237
238 return ::testing::AssertionSuccess();
239}
240
241struct NoArgs {};
242
243::testing::AssertionResult HasInlineCommandAt(const Comment *C,
244 size_t Idx,
245 InlineCommandComment *&ICC,
246 StringRef Name,
247 NoArgs) {
248 ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name);
249 if (!AR)
250 return AR;
251
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000252 if (ICC->getNumArgs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000253 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000254 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000255 "expected 0";
256
257 return ::testing::AssertionSuccess();
258}
259
260::testing::AssertionResult HasInlineCommandAt(const Comment *C,
261 size_t Idx,
262 InlineCommandComment *&ICC,
263 StringRef Name,
264 StringRef Arg) {
265 ::testing::AssertionResult AR = HasInlineCommandAt(C, Idx, ICC, Name);
266 if (!AR)
267 return AR;
268
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000269 if (ICC->getNumArgs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000270 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000271 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000272 "expected 1";
273
274 StringRef ActualArg = ICC->getArgText(0);
275 if (ActualArg != Arg)
276 return ::testing::AssertionFailure()
277 << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
278 "expected \"" << Arg.str() << "\"";
279
280 return ::testing::AssertionSuccess();
281}
282
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000283::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
284 size_t Idx,
285 HTMLStartTagComment *&HST,
286 StringRef TagName) {
287 ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000288 if (!AR)
289 return AR;
290
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000291 StringRef ActualTagName = HST->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000292 if (ActualTagName != TagName)
293 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000294 << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000295 "expected \"" << TagName.str() << "\"";
296
297 return ::testing::AssertionSuccess();
298}
299
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000300struct SelfClosing {};
301
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000302::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
303 size_t Idx,
304 HTMLStartTagComment *&HST,
305 StringRef TagName,
306 SelfClosing) {
307 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000308 if (!AR)
309 return AR;
310
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000311 if (!HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000312 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000313 << "HTMLStartTagComment is not self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000314
315 return ::testing::AssertionSuccess();
316}
317
318
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000319struct NoAttrs {};
320
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000321::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
322 size_t Idx,
323 HTMLStartTagComment *&HST,
324 StringRef TagName,
325 NoAttrs) {
326 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000327 if (!AR)
328 return AR;
329
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000330 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000331 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000332 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000333
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000334 if (HST->getNumAttrs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000335 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000336 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000337 "expected 0";
338
339 return ::testing::AssertionSuccess();
340}
341
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000342::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
343 size_t Idx,
344 HTMLStartTagComment *&HST,
345 StringRef TagName,
346 StringRef AttrName,
347 StringRef AttrValue) {
348 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000349 if (!AR)
350 return AR;
351
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000352 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000353 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000354 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000355
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000356 if (HST->getNumAttrs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000357 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000358 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000359 "expected 1";
360
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000361 StringRef ActualName = HST->getAttr(0).Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000362 if (ActualName != AttrName)
363 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000364 << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000365 "expected \"" << AttrName.str() << "\"";
366
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000367 StringRef ActualValue = HST->getAttr(0).Value;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000368 if (ActualValue != AttrValue)
369 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000370 << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000371 "expected \"" << AttrValue.str() << "\"";
372
373 return ::testing::AssertionSuccess();
374}
375
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000376::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
377 size_t Idx,
378 HTMLEndTagComment *&HET,
379 StringRef TagName) {
380 ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000381 if (!AR)
382 return AR;
383
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000384 StringRef ActualTagName = HET->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000385 if (ActualTagName != TagName)
386 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000387 << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000388 "expected \"" << TagName.str() << "\"";
389
390 return ::testing::AssertionSuccess();
391}
392
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000393::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
394 size_t Idx,
395 StringRef Text) {
396 ParagraphComment *PC;
397
398 {
399 ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
400 if (!AR)
401 return AR;
402 }
403
404 {
405 ::testing::AssertionResult AR = HasChildCount(PC, 1);
406 if (!AR)
407 return AR;
408 }
409
410 {
411 ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
412 if (!AR)
413 return AR;
414 }
415
416 return ::testing::AssertionSuccess();
417}
418
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000419::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
420 size_t Idx,
421 VerbatimBlockComment *&VBC,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000422 StringRef Name,
423 StringRef CloseName) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000424 ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
425 if (!AR)
426 return AR;
427
428 StringRef ActualName = VBC->getCommandName();
429 if (ActualName != Name)
430 return ::testing::AssertionFailure()
431 << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
432 "expected \"" << Name.str() << "\"";
433
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000434 StringRef ActualCloseName = VBC->getCloseName();
435 if (ActualCloseName != CloseName)
436 return ::testing::AssertionFailure()
437 << "VerbatimBlockComment has closing command name \""
438 << ActualCloseName.str() << "\", "
439 "expected \"" << CloseName.str() << "\"";
440
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000441 return ::testing::AssertionSuccess();
442}
443
444struct NoLines {};
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000445struct Lines {};
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000446
447::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
448 size_t Idx,
449 VerbatimBlockComment *&VBC,
450 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000451 StringRef CloseName,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000452 NoLines) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000453 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
454 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000455 if (!AR)
456 return AR;
457
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000458 if (VBC->getNumLines() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000459 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000460 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000461 "expected 0";
462
463 return ::testing::AssertionSuccess();
464}
465
466::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
467 size_t Idx,
468 VerbatimBlockComment *&VBC,
469 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000470 StringRef CloseName,
471 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000472 StringRef Line0) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000473 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
474 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000475 if (!AR)
476 return AR;
477
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000478 if (VBC->getNumLines() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000479 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000480 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000481 "expected 1";
482
483 StringRef ActualLine0 = VBC->getText(0);
484 if (ActualLine0 != Line0)
485 return ::testing::AssertionFailure()
486 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
487 "expected \"" << Line0.str() << "\"";
488
489 return ::testing::AssertionSuccess();
490}
491
492::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
493 size_t Idx,
494 VerbatimBlockComment *&VBC,
495 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000496 StringRef CloseName,
497 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000498 StringRef Line0,
499 StringRef Line1) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000500 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Idx, VBC, Name,
501 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000502 if (!AR)
503 return AR;
504
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000505 if (VBC->getNumLines() != 2)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000506 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000507 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000508 "expected 2";
509
510 StringRef ActualLine0 = VBC->getText(0);
511 if (ActualLine0 != Line0)
512 return ::testing::AssertionFailure()
513 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
514 "expected \"" << Line0.str() << "\"";
515
516 StringRef ActualLine1 = VBC->getText(1);
517 if (ActualLine1 != Line1)
518 return ::testing::AssertionFailure()
519 << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
520 "expected \"" << Line1.str() << "\"";
521
522 return ::testing::AssertionSuccess();
523}
524
525::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
526 size_t Idx,
527 VerbatimLineComment *&VLC,
528 StringRef Name,
529 StringRef Text) {
530 ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
531 if (!AR)
532 return AR;
533
534 StringRef ActualName = VLC->getCommandName();
535 if (ActualName != Name)
536 return ::testing::AssertionFailure()
537 << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
538 "expected \"" << Name.str() << "\"";
539
540 StringRef ActualText = VLC->getText();
541 if (ActualText != Text)
542 return ::testing::AssertionFailure()
543 << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
544 "expected \"" << Text.str() << "\"";
545
546 return ::testing::AssertionSuccess();
547}
548
549
550TEST_F(CommentParserTest, Basic1) {
551 const char *Source = "//";
552
553 FullComment *FC = parseString(Source);
554 ASSERT_TRUE(HasChildCount(FC, 0));
555}
556
557TEST_F(CommentParserTest, Basic2) {
558 const char *Source = "// Meow";
559
560 FullComment *FC = parseString(Source);
561 ASSERT_TRUE(HasChildCount(FC, 1));
562
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000563 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000564}
565
566TEST_F(CommentParserTest, Basic3) {
567 const char *Source =
568 "// Aaa\n"
569 "// Bbb";
570
571 FullComment *FC = parseString(Source);
572 ASSERT_TRUE(HasChildCount(FC, 1));
573
574 {
575 ParagraphComment *PC;
576 ASSERT_TRUE(GetChildAt(FC, 0, PC));
577
578 ASSERT_TRUE(HasChildCount(PC, 2));
579 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
580 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
581 }
582}
583
584TEST_F(CommentParserTest, Paragraph1) {
585 const char *Sources[] = {
586 "// Aaa\n"
587 "//\n"
588 "// Bbb",
589
590 "// Aaa\n"
591 "//\n"
592 "//\n"
593 "// Bbb",
594 };
595
596
597 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
598 FullComment *FC = parseString(Sources[i]);
599 ASSERT_TRUE(HasChildCount(FC, 2));
600
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000601 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
602 ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000603 }
604}
605
606TEST_F(CommentParserTest, Paragraph2) {
607 const char *Source =
608 "// \\brief Aaa\n"
609 "//\n"
610 "// Bbb";
611
612 FullComment *FC = parseString(Source);
613 ASSERT_TRUE(HasChildCount(FC, 3));
614
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000615 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000616 {
617 BlockCommandComment *BCC;
618 ParagraphComment *PC;
619 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
620
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000621 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000622 }
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000623 ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000624}
625
626TEST_F(CommentParserTest, Paragraph3) {
627 const char *Source = "// \\brief \\author";
628
629 FullComment *FC = parseString(Source);
630 ASSERT_TRUE(HasChildCount(FC, 3));
631
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000632 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000633 {
634 BlockCommandComment *BCC;
635 ParagraphComment *PC;
636 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
637
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000638 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000639 }
640 {
641 BlockCommandComment *BCC;
642 ParagraphComment *PC;
643 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
644
645 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
646 ASSERT_TRUE(HasChildCount(PC, 0));
647 }
648}
649
650TEST_F(CommentParserTest, Paragraph4) {
651 const char *Source =
652 "// \\brief Aaa\n"
653 "// Bbb \\author\n"
654 "// Ccc";
655
656 FullComment *FC = parseString(Source);
657 ASSERT_TRUE(HasChildCount(FC, 3));
658
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000659 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000660 {
661 BlockCommandComment *BCC;
662 ParagraphComment *PC;
663 ASSERT_TRUE(HasBlockCommandAt(FC, 1, BCC, "brief", PC));
664
665 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
666 ASSERT_TRUE(HasChildCount(PC, 2));
667 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
668 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
669 }
670 {
671 BlockCommandComment *BCC;
672 ParagraphComment *PC;
673 ASSERT_TRUE(HasBlockCommandAt(FC, 2, BCC, "author", PC));
674
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000675 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000676 }
677}
678
679TEST_F(CommentParserTest, ParamCommand1) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000680 const char *Sources[] = {
681 "// \\param aaa Bbb\n",
682 "// \\param\n"
683 "// aaa Bbb\n",
684 "// \\param \n"
685 "// aaa Bbb\n",
686 "// \\param aaa\n"
687 "// Bbb\n"
688 };
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000689
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000690 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
691 FullComment *FC = parseString(Sources[i]);
692 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000693
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000694 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
695 {
696 ParamCommandComment *PCC;
697 ParagraphComment *PC;
698 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
699 ParamCommandComment::In,
700 /* IsDirectionExplicit = */ false,
701 "aaa", PC));
702 ASSERT_TRUE(HasChildCount(PCC, 1));
703 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
704 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000705 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000706}
707
708TEST_F(CommentParserTest, ParamCommand2) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000709 const char *Sources[] = {
710 "// \\param [in] aaa Bbb\n",
711 "// \\param\n"
712 "// [in] aaa Bbb\n",
713 "// \\param [in]\n"
714 "// aaa Bbb\n",
715 "// \\param [in] aaa\n"
716 "// Bbb\n",
717 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000718
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000719 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
720 FullComment *FC = parseString(Sources[i]);
721 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000722
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000723 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
724 {
725 ParamCommandComment *PCC;
726 ParagraphComment *PC;
727 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
728 ParamCommandComment::In,
729 /* IsDirectionExplicit = */ true,
730 "aaa", PC));
731 ASSERT_TRUE(HasChildCount(PCC, 1));
732 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
733 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000734 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000735}
736
737TEST_F(CommentParserTest, ParamCommand3) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000738 const char *Sources[] = {
739 "// \\param [out] aaa Bbb\n",
740 "// \\param\n"
741 "// [out] aaa Bbb\n",
742 "// \\param [out]\n"
743 "// aaa Bbb\n",
744 "// \\param [out] aaa\n"
745 "// Bbb\n",
746 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000747
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000748 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
749 FullComment *FC = parseString(Sources[i]);
750 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000751
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000752 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
753 {
754 ParamCommandComment *PCC;
755 ParagraphComment *PC;
756 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
757 ParamCommandComment::Out,
758 /* IsDirectionExplicit = */ true,
759 "aaa", PC));
760 ASSERT_TRUE(HasChildCount(PCC, 1));
761 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
762 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000763 }
764}
765
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000766TEST_F(CommentParserTest, ParamCommand4) {
767 const char *Sources[] = {
768 "// \\param [in,out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000769 "// \\param [in, out] aaa Bbb\n",
770 "// \\param [in,\n"
771 "// out] aaa Bbb\n",
772 "// \\param [in,out]\n"
773 "// aaa Bbb\n",
774 "// \\param [in,out] aaa\n"
775 "// Bbb\n"
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000776 };
777
778 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
779 FullComment *FC = parseString(Sources[i]);
780 ASSERT_TRUE(HasChildCount(FC, 2));
781
782 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
783 {
784 ParamCommandComment *PCC;
785 ParagraphComment *PC;
786 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
787 ParamCommandComment::InOut,
788 /* IsDirectionExplicit = */ true,
789 "aaa", PC));
790 ASSERT_TRUE(HasChildCount(PCC, 1));
791 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
792 }
793 }
794}
795
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000796TEST_F(CommentParserTest, ParamCommand5) {
797 const char *Source =
798 "// \\param aaa \\% Bbb \\$ ccc\n";
799
800 FullComment *FC = parseString(Source);
801 ASSERT_TRUE(HasChildCount(FC, 2));
802
803 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
804 {
805 ParamCommandComment *PCC;
806 ParagraphComment *PC;
807 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
808 ParamCommandComment::In,
809 /* IsDirectionExplicit = */ false,
810 "aaa", PC));
811 ASSERT_TRUE(HasChildCount(PCC, 1));
812
813 ASSERT_TRUE(HasChildCount(PC, 5));
814 ASSERT_TRUE(HasTextAt(PC, 0, " "));
815 ASSERT_TRUE(HasTextAt(PC, 1, "%"));
816 ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
817 ASSERT_TRUE(HasTextAt(PC, 3, "$"));
818 ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
819 }
820}
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000821
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000822TEST_F(CommentParserTest, InlineCommand1) {
823 const char *Source = "// \\c";
824
825 FullComment *FC = parseString(Source);
826 ASSERT_TRUE(HasChildCount(FC, 1));
827
828 {
829 ParagraphComment *PC;
830 InlineCommandComment *ICC;
831 ASSERT_TRUE(GetChildAt(FC, 0, PC));
832
833 ASSERT_TRUE(HasChildCount(PC, 2));
834 ASSERT_TRUE(HasTextAt(PC, 0, " "));
835 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
836 }
837}
838
839TEST_F(CommentParserTest, InlineCommand2) {
840 const char *Source = "// \\c ";
841
842 FullComment *FC = parseString(Source);
843 ASSERT_TRUE(HasChildCount(FC, 1));
844
845 {
846 ParagraphComment *PC;
847 InlineCommandComment *ICC;
848 ASSERT_TRUE(GetChildAt(FC, 0, PC));
849
850 ASSERT_TRUE(HasChildCount(PC, 3));
851 ASSERT_TRUE(HasTextAt(PC, 0, " "));
852 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
853 ASSERT_TRUE(HasTextAt(PC, 2, " "));
854 }
855}
856
857TEST_F(CommentParserTest, InlineCommand3) {
858 const char *Source = "// \\c aaa\n";
859
860 FullComment *FC = parseString(Source);
861 ASSERT_TRUE(HasChildCount(FC, 1));
862
863 {
864 ParagraphComment *PC;
865 InlineCommandComment *ICC;
866 ASSERT_TRUE(GetChildAt(FC, 0, PC));
867
868 ASSERT_TRUE(HasChildCount(PC, 2));
869 ASSERT_TRUE(HasTextAt(PC, 0, " "));
870 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
871 }
872}
873
874TEST_F(CommentParserTest, InlineCommand4) {
875 const char *Source = "// \\c aaa bbb";
876
877 FullComment *FC = parseString(Source);
878 ASSERT_TRUE(HasChildCount(FC, 1));
879
880 {
881 ParagraphComment *PC;
882 InlineCommandComment *ICC;
883 ASSERT_TRUE(GetChildAt(FC, 0, PC));
884
885 ASSERT_TRUE(HasChildCount(PC, 3));
886 ASSERT_TRUE(HasTextAt(PC, 0, " "));
887 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
888 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
889 }
890}
891
892TEST_F(CommentParserTest, InlineCommand5) {
893 const char *Source = "// \\unknown aaa\n";
894
895 FullComment *FC = parseString(Source);
896 ASSERT_TRUE(HasChildCount(FC, 1));
897
898 {
899 ParagraphComment *PC;
900 InlineCommandComment *ICC;
901 ASSERT_TRUE(GetChildAt(FC, 0, PC));
902
903 ASSERT_TRUE(HasChildCount(PC, 3));
904 ASSERT_TRUE(HasTextAt(PC, 0, " "));
905 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs()));
906 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
907 }
908}
909
910TEST_F(CommentParserTest, HTML1) {
911 const char *Sources[] = {
912 "// <a",
913 "// <a>",
914 "// <a >"
915 };
916
917 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
918 FullComment *FC = parseString(Sources[i]);
919 ASSERT_TRUE(HasChildCount(FC, 1));
920
921 {
922 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000923 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000924 ASSERT_TRUE(GetChildAt(FC, 0, PC));
925
926 ASSERT_TRUE(HasChildCount(PC, 2));
927 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000928 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000929 }
930 }
931}
932
933TEST_F(CommentParserTest, HTML2) {
934 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000935 "// <br/>",
936 "// <br />"
937 };
938
939 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
940 FullComment *FC = parseString(Sources[i]);
941 ASSERT_TRUE(HasChildCount(FC, 1));
942
943 {
944 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000945 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000946 ASSERT_TRUE(GetChildAt(FC, 0, PC));
947
948 ASSERT_TRUE(HasChildCount(PC, 2));
949 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000950 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000951 }
952 }
953}
954
955TEST_F(CommentParserTest, HTML3) {
956 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000957 "// <a href",
958 "// <a href ",
959 "// <a href>",
960 "// <a href >",
961 };
962
963 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
964 FullComment *FC = parseString(Sources[i]);
965 ASSERT_TRUE(HasChildCount(FC, 1));
966
967 {
968 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000969 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000970 ASSERT_TRUE(GetChildAt(FC, 0, PC));
971
972 ASSERT_TRUE(HasChildCount(PC, 2));
973 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000974 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000975 }
976 }
977}
978
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000979TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000980 const char *Sources[] = {
981 "// <a href=\"bbb\"",
982 "// <a href=\"bbb\">",
983 };
984
985 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
986 FullComment *FC = parseString(Sources[i]);
987 ASSERT_TRUE(HasChildCount(FC, 1));
988
989 {
990 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000991 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000992 ASSERT_TRUE(GetChildAt(FC, 0, PC));
993
994 ASSERT_TRUE(HasChildCount(PC, 2));
995 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000996 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000997 }
998 }
999}
1000
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001001TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001002 const char *Sources[] = {
1003 "// </a",
1004 "// </a>",
1005 "// </a >"
1006 };
1007
1008 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1009 FullComment *FC = parseString(Sources[i]);
1010 ASSERT_TRUE(HasChildCount(FC, 1));
1011
1012 {
1013 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001014 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001015 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1016
1017 ASSERT_TRUE(HasChildCount(PC, 2));
1018 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001019 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001020 }
1021 }
1022}
1023
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001024TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001025 const char *Source =
1026 "// <pre>\n"
1027 "// Aaa\n"
1028 "// Bbb\n"
1029 "// </pre>\n";
1030
1031 FullComment *FC = parseString(Source);
1032 ASSERT_TRUE(HasChildCount(FC, 1));
1033
1034 {
1035 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001036 HTMLStartTagComment *HST;
1037 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001038 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1039
1040 ASSERT_TRUE(HasChildCount(PC, 6));
1041 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001042 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001043 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1044 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1045 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001046 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001047 }
1048}
1049
1050TEST_F(CommentParserTest, VerbatimBlock1) {
1051 const char *Source = "// \\verbatim\\endverbatim\n";
1052
1053 FullComment *FC = parseString(Source);
1054 ASSERT_TRUE(HasChildCount(FC, 2));
1055
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001056 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001057 {
1058 VerbatimBlockComment *VCC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001059 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
1060 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001061 }
1062}
1063
1064TEST_F(CommentParserTest, VerbatimBlock2) {
1065 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1066
1067 FullComment *FC = parseString(Source);
1068 ASSERT_TRUE(HasChildCount(FC, 2));
1069
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001070 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001071 {
1072 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001073 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1074 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001075 }
1076}
1077
1078TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001079 const char *Source = "// \\verbatim Aaa\n";
1080
1081 FullComment *FC = parseString(Source);
1082 ASSERT_TRUE(HasChildCount(FC, 2));
1083
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001084 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001085 {
1086 VerbatimBlockComment *VBC;
1087 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
1088 Lines(), " Aaa"));
1089 }
1090}
1091
1092TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001093 const char *Source =
1094 "//\\verbatim\n"
1095 "//\\endverbatim\n";
1096
1097 FullComment *FC = parseString(Source);
1098 ASSERT_TRUE(HasChildCount(FC, 1));
1099
1100 {
1101 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001102 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1103 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001104 }
1105}
1106
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001107TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001108 const char *Sources[] = {
1109 "//\\verbatim\n"
1110 "// Aaa\n"
1111 "//\\endverbatim\n",
1112
1113 "/*\\verbatim\n"
1114 " * Aaa\n"
1115 " *\\endverbatim*/"
1116 };
1117
1118 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1119 FullComment *FC = parseString(Sources[i]);
1120 ASSERT_TRUE(HasChildCount(FC, 1));
1121
1122 {
1123 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001124 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1125 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001126 }
1127 }
1128}
1129
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001130TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001131 const char *Sources[] = {
1132 "// \\verbatim\n"
1133 "// Aaa\n"
1134 "// \\endverbatim\n",
1135
1136 "/* \\verbatim\n"
1137 " * Aaa\n"
1138 " * \\endverbatim*/"
1139 };
1140
1141 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1142 FullComment *FC = parseString(Sources[i]);
1143 ASSERT_TRUE(HasChildCount(FC, 2));
1144
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001145 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001146 {
1147 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001148 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1149 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001150 }
1151 }
1152}
1153
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001154TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001155 const char *Sources[] = {
1156 "// \\verbatim\n"
1157 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001158 "// Bbb\n"
1159 "// \\endverbatim\n",
1160
1161 "/* \\verbatim\n"
1162 " * Aaa\n"
1163 " * Bbb\n"
1164 " * \\endverbatim*/"
1165 };
1166
1167 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1168 FullComment *FC = parseString(Sources[i]);
1169 ASSERT_TRUE(HasChildCount(FC, 2));
1170
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001171 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001172 {
1173 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001174 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1175 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001176 }
1177 }
1178}
1179
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001180TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001181 const char *Sources[] = {
1182 "// \\verbatim\n"
1183 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001184 "//\n"
1185 "// Bbb\n"
1186 "// \\endverbatim\n",
1187
1188 "/* \\verbatim\n"
1189 " * Aaa\n"
1190 " *\n"
1191 " * Bbb\n"
1192 " * \\endverbatim*/"
1193 };
1194 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001195 FullComment *FC = parseString(Sources[i]);
1196 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001197
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001198 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001199 {
1200 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001201 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001202 ASSERT_EQ(3U, VBC->getNumLines());
1203 ASSERT_EQ(" Aaa", VBC->getText(0));
1204 ASSERT_EQ("", VBC->getText(1));
1205 ASSERT_EQ(" Bbb", VBC->getText(2));
1206 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001207 }
1208}
1209
1210TEST_F(CommentParserTest, VerbatimLine1) {
1211 const char *Sources[] = {
1212 "// \\fn",
1213 "// \\fn\n"
1214 };
1215
1216 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1217 FullComment *FC = parseString(Sources[i]);
1218 ASSERT_TRUE(HasChildCount(FC, 2));
1219
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001220 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001221 {
1222 VerbatimLineComment *VLC;
1223 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
1224 }
1225 }
1226}
1227
1228TEST_F(CommentParserTest, VerbatimLine2) {
1229 const char *Sources[] = {
1230 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1231 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1232 };
1233
1234 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1235 FullComment *FC = parseString(Sources[i]);
1236 ASSERT_TRUE(HasChildCount(FC, 2));
1237
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001238 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001239 {
1240 VerbatimLineComment *VLC;
1241 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
1242 " void *foo(const char *zzz = \"\\$\");"));
1243 }
1244 }
1245}
1246
1247} // unnamed namespace
1248
1249} // end namespace comments
1250} // end namespace clang
1251