blob: 343d32d2c68dfe004b74f33a345331357eb29f00 [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
Chandler Carruth1050e8b2012-12-04 09:45:34 +000010#include "clang/AST/CommentParser.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000011#include "clang/AST/Comment.h"
12#include "clang/AST/CommentCommandTraits.h"
13#include "clang/AST/CommentLexer.h"
14#include "clang/AST/CommentSema.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000015#include "clang/Basic/Diagnostic.h"
Douglas Gregor3aeb34f2012-10-23 22:38:58 +000016#include "clang/Basic/DiagnosticOptions.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000017#include "clang/Basic/FileManager.h"
Chandler Carruth7cc315c2012-12-04 09:53:37 +000018#include "clang/Basic/SourceManager.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000019#include "llvm/ADT/STLExtras.h"
20#include "llvm/Support/Allocator.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000021#include "gtest/gtest.h"
Chandler Carruth1050e8b2012-12-04 09:45:34 +000022#include <vector>
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000023
24using namespace llvm;
25using namespace clang;
26
27namespace clang {
28namespace comments {
29
30namespace {
31
32const bool DEBUG = true;
33
34class CommentParserTest : public ::testing::Test {
35protected:
36 CommentParserTest()
37 : FileMgr(FileMgrOpts),
38 DiagID(new DiagnosticIDs()),
Douglas Gregor8e023612012-10-23 22:31:51 +000039 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000040 SourceMgr(Diags, FileMgr),
41 Traits(Allocator) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000042 }
43
44 FileSystemOptions FileMgrOpts;
45 FileManager FileMgr;
46 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
47 DiagnosticsEngine Diags;
48 SourceManager SourceMgr;
49 llvm::BumpPtrAllocator Allocator;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000050 CommandTraits Traits;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000051
52 FullComment *parseString(const char *Source);
53};
54
55FullComment *CommentParserTest::parseString(const char *Source) {
56 MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
57 FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
58 SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
59
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000060 Lexer L(Allocator, Traits, Begin, Source, Source + strlen(Source));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000061
Dmitri Gribenko19523542012-09-29 11:40:46 +000062 Sema S(Allocator, SourceMgr, Diags, Traits, /*PP=*/ NULL);
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000063 Parser P(L, S, Allocator, SourceMgr, Diags, Traits);
64 FullComment *FC = P.parseFullComment();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000065
66 if (DEBUG) {
67 llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000068 FC->dump(llvm::errs(), &Traits, &SourceMgr);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000069 }
70
71 Token Tok;
72 L.lex(Tok);
73 if (Tok.is(tok::eof))
74 return FC;
75 else
76 return NULL;
77}
78
79::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) {
80 if (!C)
81 return ::testing::AssertionFailure() << "Comment is NULL";
82
83 if (Count != C->child_count())
84 return ::testing::AssertionFailure()
85 << "Count = " << Count
86 << ", child_count = " << C->child_count();
87
88 return ::testing::AssertionSuccess();
89}
90
91template <typename T>
92::testing::AssertionResult GetChildAt(const Comment *C,
93 size_t Idx,
94 T *&Child) {
95 if (!C)
96 return ::testing::AssertionFailure() << "Comment is NULL";
97
98 if (Idx >= C->child_count())
99 return ::testing::AssertionFailure()
100 << "Idx out of range. Idx = " << Idx
101 << ", child_count = " << C->child_count();
102
103 Comment::child_iterator I = C->child_begin() + Idx;
104 Comment *CommentChild = *I;
105 if (!CommentChild)
106 return ::testing::AssertionFailure() << "Child is NULL";
107
108 Child = dyn_cast<T>(CommentChild);
109 if (!Child)
110 return ::testing::AssertionFailure()
111 << "Child is not of requested type, but a "
112 << CommentChild->getCommentKindName();
113
114 return ::testing::AssertionSuccess();
115}
116
117::testing::AssertionResult HasTextAt(const Comment *C,
118 size_t Idx,
119 StringRef Text) {
120 TextComment *TC;
121 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
122 if (!AR)
123 return AR;
124
125 StringRef ActualText = TC->getText();
126 if (ActualText != Text)
127 return ::testing::AssertionFailure()
128 << "TextComment has text \"" << ActualText.str() << "\", "
129 "expected \"" << Text.str() << "\"";
130
131 if (TC->hasTrailingNewline())
132 return ::testing::AssertionFailure()
133 << "TextComment has a trailing newline";
134
135 return ::testing::AssertionSuccess();
136}
137
138::testing::AssertionResult HasTextWithNewlineAt(const Comment *C,
139 size_t Idx,
140 StringRef Text) {
141 TextComment *TC;
142 ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
143 if (!AR)
144 return AR;
145
146 StringRef ActualText = TC->getText();
147 if (ActualText != Text)
148 return ::testing::AssertionFailure()
149 << "TextComment has text \"" << ActualText.str() << "\", "
150 "expected \"" << Text.str() << "\"";
151
152 if (!TC->hasTrailingNewline())
153 return ::testing::AssertionFailure()
154 << "TextComment has no trailing newline";
155
156 return ::testing::AssertionSuccess();
157}
158
159::testing::AssertionResult HasBlockCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000160 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000161 size_t Idx,
162 BlockCommandComment *&BCC,
163 StringRef Name,
164 ParagraphComment *&Paragraph) {
165 ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC);
166 if (!AR)
167 return AR;
168
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000169 StringRef ActualName = BCC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000170 if (ActualName != Name)
171 return ::testing::AssertionFailure()
172 << "BlockCommandComment has name \"" << ActualName.str() << "\", "
173 "expected \"" << Name.str() << "\"";
174
175 Paragraph = BCC->getParagraph();
176
177 return ::testing::AssertionSuccess();
178}
179
180::testing::AssertionResult HasParamCommandAt(
181 const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000182 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000183 size_t Idx,
184 ParamCommandComment *&PCC,
185 StringRef CommandName,
186 ParamCommandComment::PassDirection Direction,
187 bool IsDirectionExplicit,
188 StringRef ParamName,
189 ParagraphComment *&Paragraph) {
190 ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC);
191 if (!AR)
192 return AR;
193
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000194 StringRef ActualCommandName = PCC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000195 if (ActualCommandName != CommandName)
196 return ::testing::AssertionFailure()
197 << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", "
198 "expected \"" << CommandName.str() << "\"";
199
200 if (PCC->getDirection() != Direction)
201 return ::testing::AssertionFailure()
202 << "ParamCommandComment has direction " << PCC->getDirection() << ", "
203 "expected " << Direction;
204
205 if (PCC->isDirectionExplicit() != IsDirectionExplicit)
206 return ::testing::AssertionFailure()
207 << "ParamCommandComment has "
208 << (PCC->isDirectionExplicit() ? "explicit" : "implicit")
209 << " direction, "
210 "expected " << (IsDirectionExplicit ? "explicit" : "implicit");
211
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000212 if (!ParamName.empty() && !PCC->hasParamName())
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000213 return ::testing::AssertionFailure()
214 << "ParamCommandComment has no parameter name";
215
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000216 StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamNameAsWritten() : "";
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000217 if (ActualParamName != ParamName)
218 return ::testing::AssertionFailure()
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000219 << "ParamCommandComment has parameter name \"" << ActualParamName.str()
220 << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000221 "expected \"" << ParamName.str() << "\"";
222
223 Paragraph = PCC->getParagraph();
224
225 return ::testing::AssertionSuccess();
226}
227
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000228::testing::AssertionResult HasTParamCommandAt(
229 const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000230 const CommandTraits &Traits,
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000231 size_t Idx,
232 TParamCommandComment *&TPCC,
233 StringRef CommandName,
234 StringRef ParamName,
235 ParagraphComment *&Paragraph) {
236 ::testing::AssertionResult AR = GetChildAt(C, Idx, TPCC);
237 if (!AR)
238 return AR;
239
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000240 StringRef ActualCommandName = TPCC->getCommandName(Traits);
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000241 if (ActualCommandName != CommandName)
242 return ::testing::AssertionFailure()
243 << "TParamCommandComment has name \"" << ActualCommandName.str() << "\", "
244 "expected \"" << CommandName.str() << "\"";
245
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000246 if (!ParamName.empty() && !TPCC->hasParamName())
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000247 return ::testing::AssertionFailure()
248 << "TParamCommandComment has no parameter name";
249
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000250 StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamNameAsWritten() : "";
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000251 if (ActualParamName != ParamName)
252 return ::testing::AssertionFailure()
253 << "TParamCommandComment has parameter name \"" << ActualParamName.str()
254 << "\", "
255 "expected \"" << ParamName.str() << "\"";
256
257 Paragraph = TPCC->getParagraph();
258
259 return ::testing::AssertionSuccess();
260}
261
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000262::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000263 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000264 size_t Idx,
265 InlineCommandComment *&ICC,
266 StringRef Name) {
267 ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
268 if (!AR)
269 return AR;
270
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000271 StringRef ActualName = ICC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000272 if (ActualName != Name)
273 return ::testing::AssertionFailure()
274 << "InlineCommandComment has name \"" << ActualName.str() << "\", "
275 "expected \"" << Name.str() << "\"";
276
277 return ::testing::AssertionSuccess();
278}
279
280struct NoArgs {};
281
282::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000283 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000284 size_t Idx,
285 InlineCommandComment *&ICC,
286 StringRef Name,
287 NoArgs) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000288 ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000289 if (!AR)
290 return AR;
291
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000292 if (ICC->getNumArgs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000293 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000294 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000295 "expected 0";
296
297 return ::testing::AssertionSuccess();
298}
299
300::testing::AssertionResult HasInlineCommandAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000301 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000302 size_t Idx,
303 InlineCommandComment *&ICC,
304 StringRef Name,
305 StringRef Arg) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000306 ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000307 if (!AR)
308 return AR;
309
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000310 if (ICC->getNumArgs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000311 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000312 << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000313 "expected 1";
314
315 StringRef ActualArg = ICC->getArgText(0);
316 if (ActualArg != Arg)
317 return ::testing::AssertionFailure()
318 << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
319 "expected \"" << Arg.str() << "\"";
320
321 return ::testing::AssertionSuccess();
322}
323
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000324::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
325 size_t Idx,
326 HTMLStartTagComment *&HST,
327 StringRef TagName) {
328 ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000329 if (!AR)
330 return AR;
331
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000332 StringRef ActualTagName = HST->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000333 if (ActualTagName != TagName)
334 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000335 << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000336 "expected \"" << TagName.str() << "\"";
337
338 return ::testing::AssertionSuccess();
339}
340
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000341struct SelfClosing {};
342
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000343::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
344 size_t Idx,
345 HTMLStartTagComment *&HST,
346 StringRef TagName,
347 SelfClosing) {
348 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +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 not self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000355
356 return ::testing::AssertionSuccess();
357}
358
359
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000360struct NoAttrs {};
361
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000362::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
363 size_t Idx,
364 HTMLStartTagComment *&HST,
365 StringRef TagName,
366 NoAttrs) {
367 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000368 if (!AR)
369 return AR;
370
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000371 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000372 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000373 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000374
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000375 if (HST->getNumAttrs() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000376 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000377 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000378 "expected 0";
379
380 return ::testing::AssertionSuccess();
381}
382
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000383::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
384 size_t Idx,
385 HTMLStartTagComment *&HST,
386 StringRef TagName,
387 StringRef AttrName,
388 StringRef AttrValue) {
389 ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000390 if (!AR)
391 return AR;
392
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000393 if (HST->isSelfClosing())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000394 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000395 << "HTMLStartTagComment is self-closing";
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000396
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000397 if (HST->getNumAttrs() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000398 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000399 << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000400 "expected 1";
401
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000402 StringRef ActualName = HST->getAttr(0).Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000403 if (ActualName != AttrName)
404 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000405 << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000406 "expected \"" << AttrName.str() << "\"";
407
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000408 StringRef ActualValue = HST->getAttr(0).Value;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000409 if (ActualValue != AttrValue)
410 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000411 << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000412 "expected \"" << AttrValue.str() << "\"";
413
414 return ::testing::AssertionSuccess();
415}
416
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000417::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
418 size_t Idx,
419 HTMLEndTagComment *&HET,
420 StringRef TagName) {
421 ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000422 if (!AR)
423 return AR;
424
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000425 StringRef ActualTagName = HET->getTagName();
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000426 if (ActualTagName != TagName)
427 return ::testing::AssertionFailure()
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000428 << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000429 "expected \"" << TagName.str() << "\"";
430
431 return ::testing::AssertionSuccess();
432}
433
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000434::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
435 size_t Idx,
436 StringRef Text) {
437 ParagraphComment *PC;
438
439 {
440 ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
441 if (!AR)
442 return AR;
443 }
444
445 {
446 ::testing::AssertionResult AR = HasChildCount(PC, 1);
447 if (!AR)
448 return AR;
449 }
450
451 {
452 ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
453 if (!AR)
454 return AR;
455 }
456
457 return ::testing::AssertionSuccess();
458}
459
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000460::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000461 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000462 size_t Idx,
463 VerbatimBlockComment *&VBC,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000464 StringRef Name,
465 StringRef CloseName) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000466 ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
467 if (!AR)
468 return AR;
469
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000470 StringRef ActualName = VBC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000471 if (ActualName != Name)
472 return ::testing::AssertionFailure()
473 << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
474 "expected \"" << Name.str() << "\"";
475
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000476 StringRef ActualCloseName = VBC->getCloseName();
477 if (ActualCloseName != CloseName)
478 return ::testing::AssertionFailure()
479 << "VerbatimBlockComment has closing command name \""
480 << ActualCloseName.str() << "\", "
481 "expected \"" << CloseName.str() << "\"";
482
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000483 return ::testing::AssertionSuccess();
484}
485
486struct NoLines {};
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000487struct Lines {};
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000488
489::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000490 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000491 size_t Idx,
492 VerbatimBlockComment *&VBC,
493 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000494 StringRef CloseName,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000495 NoLines) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000496 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000497 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000498 if (!AR)
499 return AR;
500
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000501 if (VBC->getNumLines() != 0)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000502 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000503 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000504 "expected 0";
505
506 return ::testing::AssertionSuccess();
507}
508
509::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000510 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000511 size_t Idx,
512 VerbatimBlockComment *&VBC,
513 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000514 StringRef CloseName,
515 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000516 StringRef Line0) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000517 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000518 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000519 if (!AR)
520 return AR;
521
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000522 if (VBC->getNumLines() != 1)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000523 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000524 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000525 "expected 1";
526
527 StringRef ActualLine0 = VBC->getText(0);
528 if (ActualLine0 != Line0)
529 return ::testing::AssertionFailure()
530 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
531 "expected \"" << Line0.str() << "\"";
532
533 return ::testing::AssertionSuccess();
534}
535
536::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000537 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000538 size_t Idx,
539 VerbatimBlockComment *&VBC,
540 StringRef Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000541 StringRef CloseName,
542 Lines,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000543 StringRef Line0,
544 StringRef Line1) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000545 ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
Dmitri Gribenko9f08f492012-07-20 20:18:53 +0000546 CloseName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000547 if (!AR)
548 return AR;
549
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000550 if (VBC->getNumLines() != 2)
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000551 return ::testing::AssertionFailure()
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000552 << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000553 "expected 2";
554
555 StringRef ActualLine0 = VBC->getText(0);
556 if (ActualLine0 != Line0)
557 return ::testing::AssertionFailure()
558 << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
559 "expected \"" << Line0.str() << "\"";
560
561 StringRef ActualLine1 = VBC->getText(1);
562 if (ActualLine1 != Line1)
563 return ::testing::AssertionFailure()
564 << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
565 "expected \"" << Line1.str() << "\"";
566
567 return ::testing::AssertionSuccess();
568}
569
570::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000571 const CommandTraits &Traits,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000572 size_t Idx,
573 VerbatimLineComment *&VLC,
574 StringRef Name,
575 StringRef Text) {
576 ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
577 if (!AR)
578 return AR;
579
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000580 StringRef ActualName = VLC->getCommandName(Traits);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000581 if (ActualName != Name)
582 return ::testing::AssertionFailure()
583 << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
584 "expected \"" << Name.str() << "\"";
585
586 StringRef ActualText = VLC->getText();
587 if (ActualText != Text)
588 return ::testing::AssertionFailure()
589 << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
590 "expected \"" << Text.str() << "\"";
591
592 return ::testing::AssertionSuccess();
593}
594
595
596TEST_F(CommentParserTest, Basic1) {
597 const char *Source = "//";
598
599 FullComment *FC = parseString(Source);
600 ASSERT_TRUE(HasChildCount(FC, 0));
601}
602
603TEST_F(CommentParserTest, Basic2) {
604 const char *Source = "// Meow";
605
606 FullComment *FC = parseString(Source);
607 ASSERT_TRUE(HasChildCount(FC, 1));
608
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000609 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000610}
611
612TEST_F(CommentParserTest, Basic3) {
613 const char *Source =
614 "// Aaa\n"
615 "// Bbb";
616
617 FullComment *FC = parseString(Source);
618 ASSERT_TRUE(HasChildCount(FC, 1));
619
620 {
621 ParagraphComment *PC;
622 ASSERT_TRUE(GetChildAt(FC, 0, PC));
623
624 ASSERT_TRUE(HasChildCount(PC, 2));
625 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
626 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
627 }
628}
629
630TEST_F(CommentParserTest, Paragraph1) {
631 const char *Sources[] = {
632 "// Aaa\n"
633 "//\n"
634 "// Bbb",
635
636 "// Aaa\n"
637 "//\n"
638 "//\n"
639 "// Bbb",
640 };
641
642
643 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
644 FullComment *FC = parseString(Sources[i]);
645 ASSERT_TRUE(HasChildCount(FC, 2));
646
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000647 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
648 ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000649 }
650}
651
652TEST_F(CommentParserTest, Paragraph2) {
653 const char *Source =
654 "// \\brief Aaa\n"
655 "//\n"
656 "// Bbb";
657
658 FullComment *FC = parseString(Source);
659 ASSERT_TRUE(HasChildCount(FC, 3));
660
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000661 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000662 {
663 BlockCommandComment *BCC;
664 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000665 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000666
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000667 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000668 }
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000669 ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000670}
671
672TEST_F(CommentParserTest, Paragraph3) {
673 const char *Source = "// \\brief \\author";
674
675 FullComment *FC = parseString(Source);
676 ASSERT_TRUE(HasChildCount(FC, 3));
677
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000678 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000679 {
680 BlockCommandComment *BCC;
681 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000682 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000683
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000684 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000685 }
686 {
687 BlockCommandComment *BCC;
688 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000689 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000690
691 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
692 ASSERT_TRUE(HasChildCount(PC, 0));
693 }
694}
695
696TEST_F(CommentParserTest, Paragraph4) {
697 const char *Source =
698 "// \\brief Aaa\n"
699 "// Bbb \\author\n"
700 "// Ccc";
701
702 FullComment *FC = parseString(Source);
703 ASSERT_TRUE(HasChildCount(FC, 3));
704
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000705 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000706 {
707 BlockCommandComment *BCC;
708 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000709 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000710
711 ASSERT_TRUE(GetChildAt(BCC, 0, PC));
712 ASSERT_TRUE(HasChildCount(PC, 2));
713 ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
714 ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
715 }
716 {
717 BlockCommandComment *BCC;
718 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000719 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000720
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +0000721 ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000722 }
723}
724
725TEST_F(CommentParserTest, ParamCommand1) {
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000726 const char *Source = "// \\param aaa";
727
728 FullComment *FC = parseString(Source);
729 ASSERT_TRUE(HasChildCount(FC, 2));
730
731 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
732 {
733 ParamCommandComment *PCC;
734 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000735 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko3ccc1732012-07-30 16:52:51 +0000736 ParamCommandComment::In,
737 /* IsDirectionExplicit = */ false,
738 "aaa", PC));
739 ASSERT_TRUE(HasChildCount(PCC, 1));
740 ASSERT_TRUE(HasChildCount(PC, 0));
741 }
742}
743
744TEST_F(CommentParserTest, ParamCommand2) {
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000745 const char *Source = "// \\param\\brief";
746
747 FullComment *FC = parseString(Source);
748 ASSERT_TRUE(HasChildCount(FC, 3));
749
750 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
751 {
752 ParamCommandComment *PCC;
753 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000754 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000755 ParamCommandComment::In,
756 /* IsDirectionExplicit = */ false,
757 "", PC));
758 ASSERT_TRUE(HasChildCount(PCC, 1));
759 ASSERT_TRUE(HasChildCount(PC, 0));
760 }
761 {
762 BlockCommandComment *BCC;
763 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000764 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000765 ASSERT_TRUE(HasChildCount(PC, 0));
766 }
767}
768
769TEST_F(CommentParserTest, ParamCommand3) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000770 const char *Sources[] = {
771 "// \\param aaa Bbb\n",
772 "// \\param\n"
773 "// aaa Bbb\n",
774 "// \\param \n"
775 "// aaa Bbb\n",
776 "// \\param aaa\n"
777 "// Bbb\n"
778 };
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000779
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000780 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
781 FullComment *FC = parseString(Sources[i]);
782 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000783
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000784 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
785 {
786 ParamCommandComment *PCC;
787 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000788 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000789 ParamCommandComment::In,
790 /* IsDirectionExplicit = */ false,
791 "aaa", PC));
792 ASSERT_TRUE(HasChildCount(PCC, 1));
793 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
794 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000795 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000796}
797
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000798TEST_F(CommentParserTest, ParamCommand4) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000799 const char *Sources[] = {
800 "// \\param [in] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000801 "// \\param[in] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000802 "// \\param\n"
803 "// [in] aaa Bbb\n",
804 "// \\param [in]\n"
805 "// aaa Bbb\n",
806 "// \\param [in] aaa\n"
807 "// Bbb\n",
808 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000809
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000810 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
811 FullComment *FC = parseString(Sources[i]);
812 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000813
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000814 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
815 {
816 ParamCommandComment *PCC;
817 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000818 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000819 ParamCommandComment::In,
820 /* IsDirectionExplicit = */ true,
821 "aaa", PC));
822 ASSERT_TRUE(HasChildCount(PCC, 1));
823 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
824 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000825 }
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000826}
827
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000828TEST_F(CommentParserTest, ParamCommand5) {
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000829 const char *Sources[] = {
830 "// \\param [out] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000831 "// \\param[out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000832 "// \\param\n"
833 "// [out] aaa Bbb\n",
834 "// \\param [out]\n"
835 "// aaa Bbb\n",
836 "// \\param [out] aaa\n"
837 "// Bbb\n",
838 };
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000839
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000840 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
841 FullComment *FC = parseString(Sources[i]);
842 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000843
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000844 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
845 {
846 ParamCommandComment *PCC;
847 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000848 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000849 ParamCommandComment::Out,
850 /* IsDirectionExplicit = */ true,
851 "aaa", PC));
852 ASSERT_TRUE(HasChildCount(PCC, 1));
853 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
854 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000855 }
856}
857
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000858TEST_F(CommentParserTest, ParamCommand6) {
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000859 const char *Sources[] = {
860 "// \\param [in,out] aaa Bbb\n",
Dmitri Gribenkod076e012012-08-01 23:49:32 +0000861 "// \\param[in,out] aaa Bbb\n",
Dmitri Gribenko0c43a922012-07-24 18:23:31 +0000862 "// \\param [in, out] aaa Bbb\n",
863 "// \\param [in,\n"
864 "// out] aaa Bbb\n",
865 "// \\param [in,out]\n"
866 "// aaa Bbb\n",
867 "// \\param [in,out] aaa\n"
868 "// Bbb\n"
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000869 };
870
871 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
872 FullComment *FC = parseString(Sources[i]);
873 ASSERT_TRUE(HasChildCount(FC, 2));
874
875 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
876 {
877 ParamCommandComment *PCC;
878 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000879 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000880 ParamCommandComment::InOut,
881 /* IsDirectionExplicit = */ true,
882 "aaa", PC));
883 ASSERT_TRUE(HasChildCount(PCC, 1));
884 ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
885 }
886 }
887}
888
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000889TEST_F(CommentParserTest, ParamCommand7) {
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000890 const char *Source =
891 "// \\param aaa \\% Bbb \\$ ccc\n";
892
893 FullComment *FC = parseString(Source);
894 ASSERT_TRUE(HasChildCount(FC, 2));
895
896 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
897 {
898 ParamCommandComment *PCC;
899 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000900 ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
Dmitri Gribenkofd939162012-07-24 16:10:47 +0000901 ParamCommandComment::In,
902 /* IsDirectionExplicit = */ false,
903 "aaa", PC));
904 ASSERT_TRUE(HasChildCount(PCC, 1));
905
906 ASSERT_TRUE(HasChildCount(PC, 5));
907 ASSERT_TRUE(HasTextAt(PC, 0, " "));
908 ASSERT_TRUE(HasTextAt(PC, 1, "%"));
909 ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
910 ASSERT_TRUE(HasTextAt(PC, 3, "$"));
911 ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
912 }
913}
Dmitri Gribenkoe68c2292012-07-23 23:37:11 +0000914
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000915TEST_F(CommentParserTest, TParamCommand1) {
916 const char *Sources[] = {
917 "// \\tparam aaa Bbb\n",
918 "// \\tparam\n"
919 "// aaa Bbb\n",
920 "// \\tparam \n"
921 "// aaa Bbb\n",
922 "// \\tparam aaa\n"
923 "// Bbb\n"
924 };
925
926 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
927 FullComment *FC = parseString(Sources[i]);
928 ASSERT_TRUE(HasChildCount(FC, 2));
929
930 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
931 {
932 TParamCommandComment *TPCC;
933 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000934 ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam",
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000935 "aaa", PC));
936 ASSERT_TRUE(HasChildCount(TPCC, 1));
937 ASSERT_TRUE(HasParagraphCommentAt(TPCC, 0, " Bbb"));
938 }
939 }
940}
941
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000942TEST_F(CommentParserTest, TParamCommand2) {
943 const char *Source = "// \\tparam\\brief";
944
945 FullComment *FC = parseString(Source);
946 ASSERT_TRUE(HasChildCount(FC, 3));
947
948 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
949 {
950 TParamCommandComment *TPCC;
951 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000952 ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam", "", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000953 ASSERT_TRUE(HasChildCount(TPCC, 1));
954 ASSERT_TRUE(HasChildCount(PC, 0));
955 }
956 {
957 BlockCommandComment *BCC;
958 ParagraphComment *PC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000959 ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
Dmitri Gribenko8a903932012-08-06 23:48:44 +0000960 ASSERT_TRUE(HasChildCount(PC, 0));
961 }
962}
963
964
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000965TEST_F(CommentParserTest, InlineCommand1) {
966 const char *Source = "// \\c";
967
968 FullComment *FC = parseString(Source);
969 ASSERT_TRUE(HasChildCount(FC, 1));
970
971 {
972 ParagraphComment *PC;
973 InlineCommandComment *ICC;
974 ASSERT_TRUE(GetChildAt(FC, 0, PC));
975
976 ASSERT_TRUE(HasChildCount(PC, 2));
977 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000978 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000979 }
980}
981
982TEST_F(CommentParserTest, InlineCommand2) {
983 const char *Source = "// \\c ";
984
985 FullComment *FC = parseString(Source);
986 ASSERT_TRUE(HasChildCount(FC, 1));
987
988 {
989 ParagraphComment *PC;
990 InlineCommandComment *ICC;
991 ASSERT_TRUE(GetChildAt(FC, 0, PC));
992
993 ASSERT_TRUE(HasChildCount(PC, 3));
994 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000995 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000996 ASSERT_TRUE(HasTextAt(PC, 2, " "));
997 }
998}
999
1000TEST_F(CommentParserTest, InlineCommand3) {
1001 const char *Source = "// \\c aaa\n";
1002
1003 FullComment *FC = parseString(Source);
1004 ASSERT_TRUE(HasChildCount(FC, 1));
1005
1006 {
1007 ParagraphComment *PC;
1008 InlineCommandComment *ICC;
1009 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1010
1011 ASSERT_TRUE(HasChildCount(PC, 2));
1012 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001013 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001014 }
1015}
1016
1017TEST_F(CommentParserTest, InlineCommand4) {
1018 const char *Source = "// \\c aaa bbb";
1019
1020 FullComment *FC = parseString(Source);
1021 ASSERT_TRUE(HasChildCount(FC, 1));
1022
1023 {
1024 ParagraphComment *PC;
1025 InlineCommandComment *ICC;
1026 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1027
1028 ASSERT_TRUE(HasChildCount(PC, 3));
1029 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001030 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001031 ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
1032 }
1033}
1034
1035TEST_F(CommentParserTest, InlineCommand5) {
1036 const char *Source = "// \\unknown aaa\n";
1037
1038 FullComment *FC = parseString(Source);
1039 ASSERT_TRUE(HasChildCount(FC, 1));
1040
1041 {
1042 ParagraphComment *PC;
1043 InlineCommandComment *ICC;
1044 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1045
1046 ASSERT_TRUE(HasChildCount(PC, 3));
1047 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001048 ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "unknown", NoArgs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001049 ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
1050 }
1051}
1052
1053TEST_F(CommentParserTest, HTML1) {
1054 const char *Sources[] = {
1055 "// <a",
1056 "// <a>",
1057 "// <a >"
1058 };
1059
1060 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1061 FullComment *FC = parseString(Sources[i]);
1062 ASSERT_TRUE(HasChildCount(FC, 1));
1063
1064 {
1065 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001066 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001067 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1068
1069 ASSERT_TRUE(HasChildCount(PC, 2));
1070 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001071 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001072 }
1073 }
1074}
1075
1076TEST_F(CommentParserTest, HTML2) {
1077 const char *Sources[] = {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001078 "// <br/>",
1079 "// <br />"
1080 };
1081
1082 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1083 FullComment *FC = parseString(Sources[i]);
1084 ASSERT_TRUE(HasChildCount(FC, 1));
1085
1086 {
1087 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001088 HTMLStartTagComment *HST;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001089 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1090
1091 ASSERT_TRUE(HasChildCount(PC, 2));
1092 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001093 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001094 }
1095 }
1096}
1097
1098TEST_F(CommentParserTest, HTML3) {
1099 const char *Sources[] = {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001100 "// <a href",
1101 "// <a href ",
1102 "// <a href>",
1103 "// <a href >",
1104 };
1105
1106 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1107 FullComment *FC = parseString(Sources[i]);
1108 ASSERT_TRUE(HasChildCount(FC, 1));
1109
1110 {
1111 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001112 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001113 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1114
1115 ASSERT_TRUE(HasChildCount(PC, 2));
1116 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001117 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001118 }
1119 }
1120}
1121
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001122TEST_F(CommentParserTest, HTML4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001123 const char *Sources[] = {
1124 "// <a href=\"bbb\"",
1125 "// <a href=\"bbb\">",
1126 };
1127
1128 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1129 FullComment *FC = parseString(Sources[i]);
1130 ASSERT_TRUE(HasChildCount(FC, 1));
1131
1132 {
1133 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001134 HTMLStartTagComment *HST;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001135 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1136
1137 ASSERT_TRUE(HasChildCount(PC, 2));
1138 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001139 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001140 }
1141 }
1142}
1143
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001144TEST_F(CommentParserTest, HTML5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001145 const char *Sources[] = {
1146 "// </a",
1147 "// </a>",
1148 "// </a >"
1149 };
1150
1151 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1152 FullComment *FC = parseString(Sources[i]);
1153 ASSERT_TRUE(HasChildCount(FC, 1));
1154
1155 {
1156 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001157 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001158 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1159
1160 ASSERT_TRUE(HasChildCount(PC, 2));
1161 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001162 ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001163 }
1164 }
1165}
1166
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +00001167TEST_F(CommentParserTest, HTML6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001168 const char *Source =
1169 "// <pre>\n"
1170 "// Aaa\n"
1171 "// Bbb\n"
1172 "// </pre>\n";
1173
1174 FullComment *FC = parseString(Source);
1175 ASSERT_TRUE(HasChildCount(FC, 1));
1176
1177 {
1178 ParagraphComment *PC;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001179 HTMLStartTagComment *HST;
1180 HTMLEndTagComment *HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001181 ASSERT_TRUE(GetChildAt(FC, 0, PC));
1182
1183 ASSERT_TRUE(HasChildCount(PC, 6));
1184 ASSERT_TRUE(HasTextAt(PC, 0, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001185 ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001186 ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1187 ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1188 ASSERT_TRUE(HasTextAt(PC, 4, " "));
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +00001189 ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001190 }
1191}
1192
1193TEST_F(CommentParserTest, VerbatimBlock1) {
1194 const char *Source = "// \\verbatim\\endverbatim\n";
1195
1196 FullComment *FC = parseString(Source);
1197 ASSERT_TRUE(HasChildCount(FC, 2));
1198
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001199 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001200 {
1201 VerbatimBlockComment *VCC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001202 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VCC,
1203 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001204 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001205 }
1206}
1207
1208TEST_F(CommentParserTest, VerbatimBlock2) {
1209 const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1210
1211 FullComment *FC = parseString(Source);
1212 ASSERT_TRUE(HasChildCount(FC, 2));
1213
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001214 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001215 {
1216 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001217 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1218 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001219 Lines(), " Aaa "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001220 }
1221}
1222
1223TEST_F(CommentParserTest, VerbatimBlock3) {
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001224 const char *Source = "// \\verbatim Aaa\n";
1225
1226 FullComment *FC = parseString(Source);
1227 ASSERT_TRUE(HasChildCount(FC, 2));
1228
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001229 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001230 {
1231 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001232 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC, "verbatim", "",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001233 Lines(), " Aaa"));
1234 }
1235}
1236
1237TEST_F(CommentParserTest, VerbatimBlock4) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001238 const char *Source =
1239 "//\\verbatim\n"
1240 "//\\endverbatim\n";
1241
1242 FullComment *FC = parseString(Source);
1243 ASSERT_TRUE(HasChildCount(FC, 1));
1244
1245 {
1246 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001247 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1248 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001249 NoLines()));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001250 }
1251}
1252
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001253TEST_F(CommentParserTest, VerbatimBlock5) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001254 const char *Sources[] = {
1255 "//\\verbatim\n"
1256 "// Aaa\n"
1257 "//\\endverbatim\n",
1258
1259 "/*\\verbatim\n"
1260 " * Aaa\n"
1261 " *\\endverbatim*/"
1262 };
1263
1264 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1265 FullComment *FC = parseString(Sources[i]);
1266 ASSERT_TRUE(HasChildCount(FC, 1));
1267
1268 {
1269 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001270 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1271 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001272 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001273 }
1274 }
1275}
1276
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001277TEST_F(CommentParserTest, VerbatimBlock6) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001278 const char *Sources[] = {
1279 "// \\verbatim\n"
1280 "// Aaa\n"
1281 "// \\endverbatim\n",
1282
1283 "/* \\verbatim\n"
1284 " * Aaa\n"
1285 " * \\endverbatim*/"
1286 };
1287
1288 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1289 FullComment *FC = parseString(Sources[i]);
1290 ASSERT_TRUE(HasChildCount(FC, 2));
1291
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001292 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001293 {
1294 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001295 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1296 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001297 Lines(), " Aaa"));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001298 }
1299 }
1300}
1301
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001302TEST_F(CommentParserTest, VerbatimBlock7) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001303 const char *Sources[] = {
1304 "// \\verbatim\n"
1305 "// Aaa\n"
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001306 "// Bbb\n"
1307 "// \\endverbatim\n",
1308
1309 "/* \\verbatim\n"
1310 " * Aaa\n"
1311 " * Bbb\n"
1312 " * \\endverbatim*/"
1313 };
1314
1315 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1316 FullComment *FC = parseString(Sources[i]);
1317 ASSERT_TRUE(HasChildCount(FC, 2));
1318
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001319 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001320 {
1321 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001322 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1323 "verbatim", "endverbatim",
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001324 Lines(), " Aaa", " Bbb"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001325 }
1326 }
1327}
1328
Dmitri Gribenko9f08f492012-07-20 20:18:53 +00001329TEST_F(CommentParserTest, VerbatimBlock8) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001330 const char *Sources[] = {
1331 "// \\verbatim\n"
1332 "// Aaa\n"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001333 "//\n"
1334 "// Bbb\n"
1335 "// \\endverbatim\n",
1336
1337 "/* \\verbatim\n"
1338 " * Aaa\n"
1339 " *\n"
1340 " * Bbb\n"
1341 " * \\endverbatim*/"
1342 };
1343 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001344 FullComment *FC = parseString(Sources[i]);
1345 ASSERT_TRUE(HasChildCount(FC, 2));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001346
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001347 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001348 {
1349 VerbatimBlockComment *VBC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001350 ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1351 "verbatim", "endverbatim"));
Dmitri Gribenko64da4e52012-07-18 23:01:58 +00001352 ASSERT_EQ(3U, VBC->getNumLines());
1353 ASSERT_EQ(" Aaa", VBC->getText(0));
1354 ASSERT_EQ("", VBC->getText(1));
1355 ASSERT_EQ(" Bbb", VBC->getText(2));
1356 }
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001357 }
1358}
1359
1360TEST_F(CommentParserTest, VerbatimLine1) {
1361 const char *Sources[] = {
1362 "// \\fn",
1363 "// \\fn\n"
1364 };
1365
1366 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1367 FullComment *FC = parseString(Sources[i]);
1368 ASSERT_TRUE(HasChildCount(FC, 2));
1369
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001370 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001371 {
1372 VerbatimLineComment *VLC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001373 ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn", ""));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001374 }
1375 }
1376}
1377
1378TEST_F(CommentParserTest, VerbatimLine2) {
1379 const char *Sources[] = {
1380 "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1381 "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1382 };
1383
1384 for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1385 FullComment *FC = parseString(Sources[i]);
1386 ASSERT_TRUE(HasChildCount(FC, 2));
1387
Dmitri Gribenkodebd16f2012-07-23 23:09:32 +00001388 ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001389 {
1390 VerbatimLineComment *VLC;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +00001391 ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn",
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001392 " void *foo(const char *zzz = \"\\$\");"));
1393 }
1394 }
1395}
1396
1397} // unnamed namespace
1398
1399} // end namespace comments
1400} // end namespace clang
1401