blob: faf11b28fd1a9178a6e2c98bb9279cac71256601 [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
Dmitri Gribenko477a9f52012-07-27 20:37:06 +000057 comments::Lexer L(Allocator, Begin, CommentOptions(),
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000058 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 Gribenko3ccc1732012-07-30 16:52:51 +0000680 const char *Source = "// \\param aaa";
681
682 FullComment *FC = parseString(Source);
683 ASSERT_TRUE(HasChildCount(FC, 2));
684
685 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
686 {
687 ParamCommandComment *PCC;
688 ParagraphComment *PC;
689 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
690 ParamCommandComment::In,
691 /* IsDirectionExplicit = */ false,
692 "aaa", PC));
693 ASSERT_TRUE(HasChildCount(PCC, 1));
694 ASSERT_TRUE(HasChildCount(PC, 0));
695 }
696}
697
698TEST_F(CommentParserTest, ParamCommand2) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000699 const char *Sources[] = {
700 "// \\param aaa Bbb\n",
701 "// \\param\n"
702 "// aaa Bbb\n",
703 "// \\param \n"
704 "// aaa Bbb\n",
705 "// \\param aaa\n"
706 "// Bbb\n"
707 };
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000708
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000709 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
710 FullComment *FC = parseString(Sources[i]);
711 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000712
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000713 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
714 {
715 ParamCommandComment *PCC;
716 ParagraphComment *PC;
717 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
718 ParamCommandComment::In,
719 /* IsDirectionExplicit = */ false,
720 "aaa", PC));
721 ASSERT_TRUE(HasChildCount(PCC, 1));
722 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
723 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000724 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000725}
726
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000727TEST_F(CommentParserTest, ParamCommand3) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000728 const char *Sources[] = {
729 "// \\param [in] aaa Bbb\n",
730 "// \\param\n"
731 "// [in] aaa Bbb\n",
732 "// \\param [in]\n"
733 "// aaa Bbb\n",
734 "// \\param [in] aaa\n"
735 "// Bbb\n",
736 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000737
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000738 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
739 FullComment *FC = parseString(Sources[i]);
740 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000741
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000742 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
743 {
744 ParamCommandComment *PCC;
745 ParagraphComment *PC;
746 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
747 ParamCommandComment::In,
748 /* IsDirectionExplicit = */ true,
749 "aaa", PC));
750 ASSERT_TRUE(HasChildCount(PCC, 1));
751 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
752 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000753 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000754}
755
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000756TEST_F(CommentParserTest, ParamCommand4) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000757 const char *Sources[] = {
758 "// \\param [out] aaa Bbb\n",
759 "// \\param\n"
760 "// [out] aaa Bbb\n",
761 "// \\param [out]\n"
762 "// aaa Bbb\n",
763 "// \\param [out] aaa\n"
764 "// Bbb\n",
765 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000766
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000767 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
768 FullComment *FC = parseString(Sources[i]);
769 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000770
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000771 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
772 {
773 ParamCommandComment *PCC;
774 ParagraphComment *PC;
775 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
776 ParamCommandComment::Out,
777 /* IsDirectionExplicit = */ true,
778 "aaa", PC));
779 ASSERT_TRUE(HasChildCount(PCC, 1));
780 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
781 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000782 }
783}
784
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000785TEST_F(CommentParserTest, ParamCommand5) {
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000786 const char *Sources[] = {
787 "// \\param [in,out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000788 "// \\param [in, out] aaa Bbb\n",
789 "// \\param [in,\n"
790 "// out] aaa Bbb\n",
791 "// \\param [in,out]\n"
792 "// aaa Bbb\n",
793 "// \\param [in,out] aaa\n"
794 "// Bbb\n"
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000795 };
796
797 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
798 FullComment *FC = parseString(Sources[i]);
799 ASSERT_TRUE(HasChildCount(FC, 2));
800
801 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
802 {
803 ParamCommandComment *PCC;
804 ParagraphComment *PC;
805 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
806 ParamCommandComment::InOut,
807 /* IsDirectionExplicit = */ true,
808 "aaa", PC));
809 ASSERT_TRUE(HasChildCount(PCC, 1));
810 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
811 }
812 }
813}
814
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000815TEST_F(CommentParserTest, ParamCommand6) {
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000816 const char *Source =
817 "// \\param aaa \\% Bbb \\$ ccc\n";
818
819 FullComment *FC = parseString(Source);
820 ASSERT_TRUE(HasChildCount(FC, 2));
821
822 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
823 {
824 ParamCommandComment *PCC;
825 ParagraphComment *PC;
826 ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
827 ParamCommandComment::In,
828 /* IsDirectionExplicit = */ false,
829 "aaa", PC));
830 ASSERT_TRUE(HasChildCount(PCC, 1));
831
832 ASSERT_TRUE(HasChildCount(PC, 5));
833 ASSERT_TRUE(HasTextAt(PC, 0, " "));
834 ASSERT_TRUE(HasTextAt(PC, 1, "%"));
835 ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
836 ASSERT_TRUE(HasTextAt(PC, 3, "$"));
837 ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
838 }
839}
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000840
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000841TEST_F(CommentParserTest, InlineCommand1) {
842 const char *Source = "// \\c";
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, 2));
853 ASSERT_TRUE(HasTextAt(PC, 0, " "));
854 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
855 }
856}
857
858TEST_F(CommentParserTest, InlineCommand2) {
859 const char *Source = "// \\c ";
860
861 FullComment *FC = parseString(Source);
862 ASSERT_TRUE(HasChildCount(FC, 1));
863
864 {
865 ParagraphComment *PC;
866 InlineCommandComment *ICC;
867 ASSERT_TRUE(GetChildAt(FC, 0, PC));
868
869 ASSERT_TRUE(HasChildCount(PC, 3));
870 ASSERT_TRUE(HasTextAt(PC, 0, " "));
871 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", NoArgs()));
872 ASSERT_TRUE(HasTextAt(PC, 2, " "));
873 }
874}
875
876TEST_F(CommentParserTest, InlineCommand3) {
877 const char *Source = "// \\c aaa\n";
878
879 FullComment *FC = parseString(Source);
880 ASSERT_TRUE(HasChildCount(FC, 1));
881
882 {
883 ParagraphComment *PC;
884 InlineCommandComment *ICC;
885 ASSERT_TRUE(GetChildAt(FC, 0, PC));
886
887 ASSERT_TRUE(HasChildCount(PC, 2));
888 ASSERT_TRUE(HasTextAt(PC, 0, " "));
889 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
890 }
891}
892
893TEST_F(CommentParserTest, InlineCommand4) {
894 const char *Source = "// \\c aaa bbb";
895
896 FullComment *FC = parseString(Source);
897 ASSERT_TRUE(HasChildCount(FC, 1));
898
899 {
900 ParagraphComment *PC;
901 InlineCommandComment *ICC;
902 ASSERT_TRUE(GetChildAt(FC, 0, PC));
903
904 ASSERT_TRUE(HasChildCount(PC, 3));
905 ASSERT_TRUE(HasTextAt(PC, 0, " "));
906 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "c", "aaa"));
907 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
908 }
909}
910
911TEST_F(CommentParserTest, InlineCommand5) {
912 const char *Source = "// \\unknown aaa\n";
913
914 FullComment *FC = parseString(Source);
915 ASSERT_TRUE(HasChildCount(FC, 1));
916
917 {
918 ParagraphComment *PC;
919 InlineCommandComment *ICC;
920 ASSERT_TRUE(GetChildAt(FC, 0, PC));
921
922 ASSERT_TRUE(HasChildCount(PC, 3));
923 ASSERT_TRUE(HasTextAt(PC, 0, " "));
924 ASSERT_TRUE(HasInlineCommandAt(PC, 1, ICC, "unknown", NoArgs()));
925 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
926 }
927}
928
929TEST_F(CommentParserTest, HTML1) {
930 const char *Sources[] = {
931 "// <a",
932 "// <a>",
933 "// <a >"
934 };
935
936 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
937 FullComment *FC = parseString(Sources[i]);
938 ASSERT_TRUE(HasChildCount(FC, 1));
939
940 {
941 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000942 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000943 ASSERT_TRUE(GetChildAt(FC, 0, PC));
944
945 ASSERT_TRUE(HasChildCount(PC, 2));
946 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000947 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000948 }
949 }
950}
951
952TEST_F(CommentParserTest, HTML2) {
953 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000954 "// <br/>",
955 "// <br />"
956 };
957
958 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
959 FullComment *FC = parseString(Sources[i]);
960 ASSERT_TRUE(HasChildCount(FC, 1));
961
962 {
963 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000964 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000965 ASSERT_TRUE(GetChildAt(FC, 0, PC));
966
967 ASSERT_TRUE(HasChildCount(PC, 2));
968 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000969 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000970 }
971 }
972}
973
974TEST_F(CommentParserTest, HTML3) {
975 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000976 "// <a href",
977 "// <a href ",
978 "// <a href>",
979 "// <a href >",
980 };
981
982 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
983 FullComment *FC = parseString(Sources[i]);
984 ASSERT_TRUE(HasChildCount(FC, 1));
985
986 {
987 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000988 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000989 ASSERT_TRUE(GetChildAt(FC, 0, PC));
990
991 ASSERT_TRUE(HasChildCount(PC, 2));
992 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000993 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000994 }
995 }
996}
997
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000998TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000999 const char *Sources[] = {
1000 "// <a href=\"bbb\"",
1001 "// <a href=\"bbb\">",
1002 };
1003
1004 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1005 FullComment *FC = parseString(Sources[i]);
1006 ASSERT_TRUE(HasChildCount(FC, 1));
1007
1008 {
1009 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001010 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001011 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1012
1013 ASSERT_TRUE(HasChildCount(PC, 2));
1014 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001015 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001016 }
1017 }
1018}
1019
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001020TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001021 const char *Sources[] = {
1022 "// </a",
1023 "// </a>",
1024 "// </a >"
1025 };
1026
1027 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1028 FullComment *FC = parseString(Sources[i]);
1029 ASSERT_TRUE(HasChildCount(FC, 1));
1030
1031 {
1032 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001033 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001034 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1035
1036 ASSERT_TRUE(HasChildCount(PC, 2));
1037 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001038 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001039 }
1040 }
1041}
1042
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001043TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001044 const char *Source =
1045 "// <pre>\n"
1046 "// Aaa\n"
1047 "// Bbb\n"
1048 "// </pre>\n";
1049
1050 FullComment *FC = parseString(Source);
1051 ASSERT_TRUE(HasChildCount(FC, 1));
1052
1053 {
1054 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001055 HTMLStartTagComment *HST;
1056 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001057 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1058
1059 ASSERT_TRUE(HasChildCount(PC, 6));
1060 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001061 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001062 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1063 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1064 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001065 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001066 }
1067}
1068
1069TEST_F(CommentParserTest, VerbatimBlock1) {
1070 const char *Source = "// \\verbatim\\endverbatim\n";
1071
1072 FullComment *FC = parseString(Source);
1073 ASSERT_TRUE(HasChildCount(FC, 2));
1074
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001075 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001076 {
1077 VerbatimBlockComment *VCC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001078 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VCC, "verbatim", "endverbatim",
1079 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001080 }
1081}
1082
1083TEST_F(CommentParserTest, VerbatimBlock2) {
1084 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1085
1086 FullComment *FC = parseString(Source);
1087 ASSERT_TRUE(HasChildCount(FC, 2));
1088
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001089 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001090 {
1091 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001092 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1093 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001094 }
1095}
1096
1097TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001098 const char *Source = "// \\verbatim Aaa\n";
1099
1100 FullComment *FC = parseString(Source);
1101 ASSERT_TRUE(HasChildCount(FC, 2));
1102
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001103 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001104 {
1105 VerbatimBlockComment *VBC;
1106 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "",
1107 Lines(), " Aaa"));
1108 }
1109}
1110
1111TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001112 const char *Source =
1113 "//\\verbatim\n"
1114 "//\\endverbatim\n";
1115
1116 FullComment *FC = parseString(Source);
1117 ASSERT_TRUE(HasChildCount(FC, 1));
1118
1119 {
1120 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001121 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1122 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001123 }
1124}
1125
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001126TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001127 const char *Sources[] = {
1128 "//\\verbatim\n"
1129 "// Aaa\n"
1130 "//\\endverbatim\n",
1131
1132 "/*\\verbatim\n"
1133 " * Aaa\n"
1134 " *\\endverbatim*/"
1135 };
1136
1137 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1138 FullComment *FC = parseString(Sources[i]);
1139 ASSERT_TRUE(HasChildCount(FC, 1));
1140
1141 {
1142 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001143 ASSERT_TRUE(HasVerbatimBlockAt(FC, 0, VBC, "verbatim", "endverbatim",
1144 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001145 }
1146 }
1147}
1148
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001149TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001150 const char *Sources[] = {
1151 "// \\verbatim\n"
1152 "// Aaa\n"
1153 "// \\endverbatim\n",
1154
1155 "/* \\verbatim\n"
1156 " * Aaa\n"
1157 " * \\endverbatim*/"
1158 };
1159
1160 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1161 FullComment *FC = parseString(Sources[i]);
1162 ASSERT_TRUE(HasChildCount(FC, 2));
1163
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001164 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001165 {
1166 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001167 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1168 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001169 }
1170 }
1171}
1172
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001173TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001174 const char *Sources[] = {
1175 "// \\verbatim\n"
1176 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001177 "// Bbb\n"
1178 "// \\endverbatim\n",
1179
1180 "/* \\verbatim\n"
1181 " * Aaa\n"
1182 " * Bbb\n"
1183 " * \\endverbatim*/"
1184 };
1185
1186 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1187 FullComment *FC = parseString(Sources[i]);
1188 ASSERT_TRUE(HasChildCount(FC, 2));
1189
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001190 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001191 {
1192 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001193 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim",
1194 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001195 }
1196 }
1197}
1198
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001199TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001200 const char *Sources[] = {
1201 "// \\verbatim\n"
1202 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001203 "//\n"
1204 "// Bbb\n"
1205 "// \\endverbatim\n",
1206
1207 "/* \\verbatim\n"
1208 " * Aaa\n"
1209 " *\n"
1210 " * Bbb\n"
1211 " * \\endverbatim*/"
1212 };
1213 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001214 FullComment *FC = parseString(Sources[i]);
1215 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001216
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001217 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001218 {
1219 VerbatimBlockComment *VBC;
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001220 ASSERT_TRUE(HasVerbatimBlockAt(FC, 1, VBC, "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001221 ASSERT_EQ(3U, VBC->getNumLines());
1222 ASSERT_EQ(" Aaa", VBC->getText(0));
1223 ASSERT_EQ("", VBC->getText(1));
1224 ASSERT_EQ(" Bbb", VBC->getText(2));
1225 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001226 }
1227}
1228
1229TEST_F(CommentParserTest, VerbatimLine1) {
1230 const char *Sources[] = {
1231 "// \\fn",
1232 "// \\fn\n"
1233 };
1234
1235 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1236 FullComment *FC = parseString(Sources[i]);
1237 ASSERT_TRUE(HasChildCount(FC, 2));
1238
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001239 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001240 {
1241 VerbatimLineComment *VLC;
1242 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn", ""));
1243 }
1244 }
1245}
1246
1247TEST_F(CommentParserTest, VerbatimLine2) {
1248 const char *Sources[] = {
1249 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1250 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1251 };
1252
1253 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1254 FullComment *FC = parseString(Sources[i]);
1255 ASSERT_TRUE(HasChildCount(FC, 2));
1256
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001257 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001258 {
1259 VerbatimLineComment *VLC;
1260 ASSERT_TRUE(HasVerbatimLineAt(FC, 1, VLC, "fn",
1261 " void *foo(const char *zzz = \"\\$\");"));
1262 }
1263 }
1264}
1265
1266} // unnamed namespace
1267
1268} // end namespace comments
1269} // end namespace clang
1270