1*67e74705SXin Li //===- unittests/AST/CommentParser.cpp ------ Comment parser tests --------===//
2*67e74705SXin Li //
3*67e74705SXin Li // The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li
10*67e74705SXin Li #include "clang/AST/CommentParser.h"
11*67e74705SXin Li #include "clang/AST/Comment.h"
12*67e74705SXin Li #include "clang/AST/CommentCommandTraits.h"
13*67e74705SXin Li #include "clang/AST/CommentLexer.h"
14*67e74705SXin Li #include "clang/AST/CommentSema.h"
15*67e74705SXin Li #include "clang/Basic/CommentOptions.h"
16*67e74705SXin Li #include "clang/Basic/Diagnostic.h"
17*67e74705SXin Li #include "clang/Basic/DiagnosticOptions.h"
18*67e74705SXin Li #include "clang/Basic/FileManager.h"
19*67e74705SXin Li #include "clang/Basic/SourceManager.h"
20*67e74705SXin Li #include "llvm/ADT/STLExtras.h"
21*67e74705SXin Li #include "llvm/Support/Allocator.h"
22*67e74705SXin Li #include "gtest/gtest.h"
23*67e74705SXin Li #include <vector>
24*67e74705SXin Li
25*67e74705SXin Li using namespace llvm;
26*67e74705SXin Li using namespace clang;
27*67e74705SXin Li
28*67e74705SXin Li namespace clang {
29*67e74705SXin Li namespace comments {
30*67e74705SXin Li
31*67e74705SXin Li namespace {
32*67e74705SXin Li
33*67e74705SXin Li const bool DEBUG = true;
34*67e74705SXin Li
35*67e74705SXin Li class CommentParserTest : public ::testing::Test {
36*67e74705SXin Li protected:
CommentParserTest()37*67e74705SXin Li CommentParserTest()
38*67e74705SXin Li : FileMgr(FileMgrOpts),
39*67e74705SXin Li DiagID(new DiagnosticIDs()),
40*67e74705SXin Li Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
41*67e74705SXin Li SourceMgr(Diags, FileMgr),
42*67e74705SXin Li Traits(Allocator, CommentOptions()) {
43*67e74705SXin Li }
44*67e74705SXin Li
45*67e74705SXin Li FileSystemOptions FileMgrOpts;
46*67e74705SXin Li FileManager FileMgr;
47*67e74705SXin Li IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
48*67e74705SXin Li DiagnosticsEngine Diags;
49*67e74705SXin Li SourceManager SourceMgr;
50*67e74705SXin Li llvm::BumpPtrAllocator Allocator;
51*67e74705SXin Li CommandTraits Traits;
52*67e74705SXin Li
53*67e74705SXin Li FullComment *parseString(const char *Source);
54*67e74705SXin Li };
55*67e74705SXin Li
parseString(const char * Source)56*67e74705SXin Li FullComment *CommentParserTest::parseString(const char *Source) {
57*67e74705SXin Li std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
58*67e74705SXin Li FileID File = SourceMgr.createFileID(std::move(Buf));
59*67e74705SXin Li SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
60*67e74705SXin Li
61*67e74705SXin Li Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
62*67e74705SXin Li
63*67e74705SXin Li Sema S(Allocator, SourceMgr, Diags, Traits, /*PP=*/ nullptr);
64*67e74705SXin Li Parser P(L, S, Allocator, SourceMgr, Diags, Traits);
65*67e74705SXin Li FullComment *FC = P.parseFullComment();
66*67e74705SXin Li
67*67e74705SXin Li if (DEBUG) {
68*67e74705SXin Li llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
69*67e74705SXin Li FC->dump(llvm::errs(), &Traits, &SourceMgr);
70*67e74705SXin Li }
71*67e74705SXin Li
72*67e74705SXin Li Token Tok;
73*67e74705SXin Li L.lex(Tok);
74*67e74705SXin Li if (Tok.is(tok::eof))
75*67e74705SXin Li return FC;
76*67e74705SXin Li else
77*67e74705SXin Li return nullptr;
78*67e74705SXin Li }
79*67e74705SXin Li
HasChildCount(const Comment * C,size_t Count)80*67e74705SXin Li ::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) {
81*67e74705SXin Li if (!C)
82*67e74705SXin Li return ::testing::AssertionFailure() << "Comment is NULL";
83*67e74705SXin Li
84*67e74705SXin Li if (Count != C->child_count())
85*67e74705SXin Li return ::testing::AssertionFailure()
86*67e74705SXin Li << "Count = " << Count
87*67e74705SXin Li << ", child_count = " << C->child_count();
88*67e74705SXin Li
89*67e74705SXin Li return ::testing::AssertionSuccess();
90*67e74705SXin Li }
91*67e74705SXin Li
92*67e74705SXin Li template <typename T>
GetChildAt(const Comment * C,size_t Idx,T * & Child)93*67e74705SXin Li ::testing::AssertionResult GetChildAt(const Comment *C,
94*67e74705SXin Li size_t Idx,
95*67e74705SXin Li T *&Child) {
96*67e74705SXin Li if (!C)
97*67e74705SXin Li return ::testing::AssertionFailure() << "Comment is NULL";
98*67e74705SXin Li
99*67e74705SXin Li if (Idx >= C->child_count())
100*67e74705SXin Li return ::testing::AssertionFailure()
101*67e74705SXin Li << "Idx out of range. Idx = " << Idx
102*67e74705SXin Li << ", child_count = " << C->child_count();
103*67e74705SXin Li
104*67e74705SXin Li Comment::child_iterator I = C->child_begin() + Idx;
105*67e74705SXin Li Comment *CommentChild = *I;
106*67e74705SXin Li if (!CommentChild)
107*67e74705SXin Li return ::testing::AssertionFailure() << "Child is NULL";
108*67e74705SXin Li
109*67e74705SXin Li Child = dyn_cast<T>(CommentChild);
110*67e74705SXin Li if (!Child)
111*67e74705SXin Li return ::testing::AssertionFailure()
112*67e74705SXin Li << "Child is not of requested type, but a "
113*67e74705SXin Li << CommentChild->getCommentKindName();
114*67e74705SXin Li
115*67e74705SXin Li return ::testing::AssertionSuccess();
116*67e74705SXin Li }
117*67e74705SXin Li
HasTextAt(const Comment * C,size_t Idx,StringRef Text)118*67e74705SXin Li ::testing::AssertionResult HasTextAt(const Comment *C,
119*67e74705SXin Li size_t Idx,
120*67e74705SXin Li StringRef Text) {
121*67e74705SXin Li TextComment *TC;
122*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
123*67e74705SXin Li if (!AR)
124*67e74705SXin Li return AR;
125*67e74705SXin Li
126*67e74705SXin Li StringRef ActualText = TC->getText();
127*67e74705SXin Li if (ActualText != Text)
128*67e74705SXin Li return ::testing::AssertionFailure()
129*67e74705SXin Li << "TextComment has text \"" << ActualText.str() << "\", "
130*67e74705SXin Li "expected \"" << Text.str() << "\"";
131*67e74705SXin Li
132*67e74705SXin Li if (TC->hasTrailingNewline())
133*67e74705SXin Li return ::testing::AssertionFailure()
134*67e74705SXin Li << "TextComment has a trailing newline";
135*67e74705SXin Li
136*67e74705SXin Li return ::testing::AssertionSuccess();
137*67e74705SXin Li }
138*67e74705SXin Li
HasTextWithNewlineAt(const Comment * C,size_t Idx,StringRef Text)139*67e74705SXin Li ::testing::AssertionResult HasTextWithNewlineAt(const Comment *C,
140*67e74705SXin Li size_t Idx,
141*67e74705SXin Li StringRef Text) {
142*67e74705SXin Li TextComment *TC;
143*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
144*67e74705SXin Li if (!AR)
145*67e74705SXin Li return AR;
146*67e74705SXin Li
147*67e74705SXin Li StringRef ActualText = TC->getText();
148*67e74705SXin Li if (ActualText != Text)
149*67e74705SXin Li return ::testing::AssertionFailure()
150*67e74705SXin Li << "TextComment has text \"" << ActualText.str() << "\", "
151*67e74705SXin Li "expected \"" << Text.str() << "\"";
152*67e74705SXin Li
153*67e74705SXin Li if (!TC->hasTrailingNewline())
154*67e74705SXin Li return ::testing::AssertionFailure()
155*67e74705SXin Li << "TextComment has no trailing newline";
156*67e74705SXin Li
157*67e74705SXin Li return ::testing::AssertionSuccess();
158*67e74705SXin Li }
159*67e74705SXin Li
HasBlockCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,BlockCommandComment * & BCC,StringRef Name,ParagraphComment * & Paragraph)160*67e74705SXin Li ::testing::AssertionResult HasBlockCommandAt(const Comment *C,
161*67e74705SXin Li const CommandTraits &Traits,
162*67e74705SXin Li size_t Idx,
163*67e74705SXin Li BlockCommandComment *&BCC,
164*67e74705SXin Li StringRef Name,
165*67e74705SXin Li ParagraphComment *&Paragraph) {
166*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC);
167*67e74705SXin Li if (!AR)
168*67e74705SXin Li return AR;
169*67e74705SXin Li
170*67e74705SXin Li StringRef ActualName = BCC->getCommandName(Traits);
171*67e74705SXin Li if (ActualName != Name)
172*67e74705SXin Li return ::testing::AssertionFailure()
173*67e74705SXin Li << "BlockCommandComment has name \"" << ActualName.str() << "\", "
174*67e74705SXin Li "expected \"" << Name.str() << "\"";
175*67e74705SXin Li
176*67e74705SXin Li Paragraph = BCC->getParagraph();
177*67e74705SXin Li
178*67e74705SXin Li return ::testing::AssertionSuccess();
179*67e74705SXin Li }
180*67e74705SXin Li
HasParamCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,ParamCommandComment * & PCC,StringRef CommandName,ParamCommandComment::PassDirection Direction,bool IsDirectionExplicit,StringRef ParamName,ParagraphComment * & Paragraph)181*67e74705SXin Li ::testing::AssertionResult HasParamCommandAt(
182*67e74705SXin Li const Comment *C,
183*67e74705SXin Li const CommandTraits &Traits,
184*67e74705SXin Li size_t Idx,
185*67e74705SXin Li ParamCommandComment *&PCC,
186*67e74705SXin Li StringRef CommandName,
187*67e74705SXin Li ParamCommandComment::PassDirection Direction,
188*67e74705SXin Li bool IsDirectionExplicit,
189*67e74705SXin Li StringRef ParamName,
190*67e74705SXin Li ParagraphComment *&Paragraph) {
191*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC);
192*67e74705SXin Li if (!AR)
193*67e74705SXin Li return AR;
194*67e74705SXin Li
195*67e74705SXin Li StringRef ActualCommandName = PCC->getCommandName(Traits);
196*67e74705SXin Li if (ActualCommandName != CommandName)
197*67e74705SXin Li return ::testing::AssertionFailure()
198*67e74705SXin Li << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", "
199*67e74705SXin Li "expected \"" << CommandName.str() << "\"";
200*67e74705SXin Li
201*67e74705SXin Li if (PCC->getDirection() != Direction)
202*67e74705SXin Li return ::testing::AssertionFailure()
203*67e74705SXin Li << "ParamCommandComment has direction " << PCC->getDirection() << ", "
204*67e74705SXin Li "expected " << Direction;
205*67e74705SXin Li
206*67e74705SXin Li if (PCC->isDirectionExplicit() != IsDirectionExplicit)
207*67e74705SXin Li return ::testing::AssertionFailure()
208*67e74705SXin Li << "ParamCommandComment has "
209*67e74705SXin Li << (PCC->isDirectionExplicit() ? "explicit" : "implicit")
210*67e74705SXin Li << " direction, "
211*67e74705SXin Li "expected " << (IsDirectionExplicit ? "explicit" : "implicit");
212*67e74705SXin Li
213*67e74705SXin Li if (!ParamName.empty() && !PCC->hasParamName())
214*67e74705SXin Li return ::testing::AssertionFailure()
215*67e74705SXin Li << "ParamCommandComment has no parameter name";
216*67e74705SXin Li
217*67e74705SXin Li StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamNameAsWritten() : "";
218*67e74705SXin Li if (ActualParamName != ParamName)
219*67e74705SXin Li return ::testing::AssertionFailure()
220*67e74705SXin Li << "ParamCommandComment has parameter name \"" << ActualParamName.str()
221*67e74705SXin Li << "\", "
222*67e74705SXin Li "expected \"" << ParamName.str() << "\"";
223*67e74705SXin Li
224*67e74705SXin Li Paragraph = PCC->getParagraph();
225*67e74705SXin Li
226*67e74705SXin Li return ::testing::AssertionSuccess();
227*67e74705SXin Li }
228*67e74705SXin Li
HasTParamCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,TParamCommandComment * & TPCC,StringRef CommandName,StringRef ParamName,ParagraphComment * & Paragraph)229*67e74705SXin Li ::testing::AssertionResult HasTParamCommandAt(
230*67e74705SXin Li const Comment *C,
231*67e74705SXin Li const CommandTraits &Traits,
232*67e74705SXin Li size_t Idx,
233*67e74705SXin Li TParamCommandComment *&TPCC,
234*67e74705SXin Li StringRef CommandName,
235*67e74705SXin Li StringRef ParamName,
236*67e74705SXin Li ParagraphComment *&Paragraph) {
237*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, TPCC);
238*67e74705SXin Li if (!AR)
239*67e74705SXin Li return AR;
240*67e74705SXin Li
241*67e74705SXin Li StringRef ActualCommandName = TPCC->getCommandName(Traits);
242*67e74705SXin Li if (ActualCommandName != CommandName)
243*67e74705SXin Li return ::testing::AssertionFailure()
244*67e74705SXin Li << "TParamCommandComment has name \"" << ActualCommandName.str() << "\", "
245*67e74705SXin Li "expected \"" << CommandName.str() << "\"";
246*67e74705SXin Li
247*67e74705SXin Li if (!ParamName.empty() && !TPCC->hasParamName())
248*67e74705SXin Li return ::testing::AssertionFailure()
249*67e74705SXin Li << "TParamCommandComment has no parameter name";
250*67e74705SXin Li
251*67e74705SXin Li StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamNameAsWritten() : "";
252*67e74705SXin Li if (ActualParamName != ParamName)
253*67e74705SXin Li return ::testing::AssertionFailure()
254*67e74705SXin Li << "TParamCommandComment has parameter name \"" << ActualParamName.str()
255*67e74705SXin Li << "\", "
256*67e74705SXin Li "expected \"" << ParamName.str() << "\"";
257*67e74705SXin Li
258*67e74705SXin Li Paragraph = TPCC->getParagraph();
259*67e74705SXin Li
260*67e74705SXin Li return ::testing::AssertionSuccess();
261*67e74705SXin Li }
262*67e74705SXin Li
HasInlineCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,InlineCommandComment * & ICC,StringRef Name)263*67e74705SXin Li ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
264*67e74705SXin Li const CommandTraits &Traits,
265*67e74705SXin Li size_t Idx,
266*67e74705SXin Li InlineCommandComment *&ICC,
267*67e74705SXin Li StringRef Name) {
268*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
269*67e74705SXin Li if (!AR)
270*67e74705SXin Li return AR;
271*67e74705SXin Li
272*67e74705SXin Li StringRef ActualName = ICC->getCommandName(Traits);
273*67e74705SXin Li if (ActualName != Name)
274*67e74705SXin Li return ::testing::AssertionFailure()
275*67e74705SXin Li << "InlineCommandComment has name \"" << ActualName.str() << "\", "
276*67e74705SXin Li "expected \"" << Name.str() << "\"";
277*67e74705SXin Li
278*67e74705SXin Li return ::testing::AssertionSuccess();
279*67e74705SXin Li }
280*67e74705SXin Li
281*67e74705SXin Li struct NoArgs {};
282*67e74705SXin Li
HasInlineCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,InlineCommandComment * & ICC,StringRef Name,NoArgs)283*67e74705SXin Li ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
284*67e74705SXin Li const CommandTraits &Traits,
285*67e74705SXin Li size_t Idx,
286*67e74705SXin Li InlineCommandComment *&ICC,
287*67e74705SXin Li StringRef Name,
288*67e74705SXin Li NoArgs) {
289*67e74705SXin Li ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
290*67e74705SXin Li if (!AR)
291*67e74705SXin Li return AR;
292*67e74705SXin Li
293*67e74705SXin Li if (ICC->getNumArgs() != 0)
294*67e74705SXin Li return ::testing::AssertionFailure()
295*67e74705SXin Li << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
296*67e74705SXin Li "expected 0";
297*67e74705SXin Li
298*67e74705SXin Li return ::testing::AssertionSuccess();
299*67e74705SXin Li }
300*67e74705SXin Li
HasInlineCommandAt(const Comment * C,const CommandTraits & Traits,size_t Idx,InlineCommandComment * & ICC,StringRef Name,StringRef Arg)301*67e74705SXin Li ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
302*67e74705SXin Li const CommandTraits &Traits,
303*67e74705SXin Li size_t Idx,
304*67e74705SXin Li InlineCommandComment *&ICC,
305*67e74705SXin Li StringRef Name,
306*67e74705SXin Li StringRef Arg) {
307*67e74705SXin Li ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
308*67e74705SXin Li if (!AR)
309*67e74705SXin Li return AR;
310*67e74705SXin Li
311*67e74705SXin Li if (ICC->getNumArgs() != 1)
312*67e74705SXin Li return ::testing::AssertionFailure()
313*67e74705SXin Li << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
314*67e74705SXin Li "expected 1";
315*67e74705SXin Li
316*67e74705SXin Li StringRef ActualArg = ICC->getArgText(0);
317*67e74705SXin Li if (ActualArg != Arg)
318*67e74705SXin Li return ::testing::AssertionFailure()
319*67e74705SXin Li << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
320*67e74705SXin Li "expected \"" << Arg.str() << "\"";
321*67e74705SXin Li
322*67e74705SXin Li return ::testing::AssertionSuccess();
323*67e74705SXin Li }
324*67e74705SXin Li
HasHTMLStartTagAt(const Comment * C,size_t Idx,HTMLStartTagComment * & HST,StringRef TagName)325*67e74705SXin Li ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
326*67e74705SXin Li size_t Idx,
327*67e74705SXin Li HTMLStartTagComment *&HST,
328*67e74705SXin Li StringRef TagName) {
329*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
330*67e74705SXin Li if (!AR)
331*67e74705SXin Li return AR;
332*67e74705SXin Li
333*67e74705SXin Li StringRef ActualTagName = HST->getTagName();
334*67e74705SXin Li if (ActualTagName != TagName)
335*67e74705SXin Li return ::testing::AssertionFailure()
336*67e74705SXin Li << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
337*67e74705SXin Li "expected \"" << TagName.str() << "\"";
338*67e74705SXin Li
339*67e74705SXin Li return ::testing::AssertionSuccess();
340*67e74705SXin Li }
341*67e74705SXin Li
342*67e74705SXin Li struct SelfClosing {};
343*67e74705SXin Li
HasHTMLStartTagAt(const Comment * C,size_t Idx,HTMLStartTagComment * & HST,StringRef TagName,SelfClosing)344*67e74705SXin Li ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
345*67e74705SXin Li size_t Idx,
346*67e74705SXin Li HTMLStartTagComment *&HST,
347*67e74705SXin Li StringRef TagName,
348*67e74705SXin Li SelfClosing) {
349*67e74705SXin Li ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
350*67e74705SXin Li if (!AR)
351*67e74705SXin Li return AR;
352*67e74705SXin Li
353*67e74705SXin Li if (!HST->isSelfClosing())
354*67e74705SXin Li return ::testing::AssertionFailure()
355*67e74705SXin Li << "HTMLStartTagComment is not self-closing";
356*67e74705SXin Li
357*67e74705SXin Li return ::testing::AssertionSuccess();
358*67e74705SXin Li }
359*67e74705SXin Li
360*67e74705SXin Li
361*67e74705SXin Li struct NoAttrs {};
362*67e74705SXin Li
HasHTMLStartTagAt(const Comment * C,size_t Idx,HTMLStartTagComment * & HST,StringRef TagName,NoAttrs)363*67e74705SXin Li ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
364*67e74705SXin Li size_t Idx,
365*67e74705SXin Li HTMLStartTagComment *&HST,
366*67e74705SXin Li StringRef TagName,
367*67e74705SXin Li NoAttrs) {
368*67e74705SXin Li ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
369*67e74705SXin Li if (!AR)
370*67e74705SXin Li return AR;
371*67e74705SXin Li
372*67e74705SXin Li if (HST->isSelfClosing())
373*67e74705SXin Li return ::testing::AssertionFailure()
374*67e74705SXin Li << "HTMLStartTagComment is self-closing";
375*67e74705SXin Li
376*67e74705SXin Li if (HST->getNumAttrs() != 0)
377*67e74705SXin Li return ::testing::AssertionFailure()
378*67e74705SXin Li << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
379*67e74705SXin Li "expected 0";
380*67e74705SXin Li
381*67e74705SXin Li return ::testing::AssertionSuccess();
382*67e74705SXin Li }
383*67e74705SXin Li
HasHTMLStartTagAt(const Comment * C,size_t Idx,HTMLStartTagComment * & HST,StringRef TagName,StringRef AttrName,StringRef AttrValue)384*67e74705SXin Li ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
385*67e74705SXin Li size_t Idx,
386*67e74705SXin Li HTMLStartTagComment *&HST,
387*67e74705SXin Li StringRef TagName,
388*67e74705SXin Li StringRef AttrName,
389*67e74705SXin Li StringRef AttrValue) {
390*67e74705SXin Li ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
391*67e74705SXin Li if (!AR)
392*67e74705SXin Li return AR;
393*67e74705SXin Li
394*67e74705SXin Li if (HST->isSelfClosing())
395*67e74705SXin Li return ::testing::AssertionFailure()
396*67e74705SXin Li << "HTMLStartTagComment is self-closing";
397*67e74705SXin Li
398*67e74705SXin Li if (HST->getNumAttrs() != 1)
399*67e74705SXin Li return ::testing::AssertionFailure()
400*67e74705SXin Li << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
401*67e74705SXin Li "expected 1";
402*67e74705SXin Li
403*67e74705SXin Li StringRef ActualName = HST->getAttr(0).Name;
404*67e74705SXin Li if (ActualName != AttrName)
405*67e74705SXin Li return ::testing::AssertionFailure()
406*67e74705SXin Li << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
407*67e74705SXin Li "expected \"" << AttrName.str() << "\"";
408*67e74705SXin Li
409*67e74705SXin Li StringRef ActualValue = HST->getAttr(0).Value;
410*67e74705SXin Li if (ActualValue != AttrValue)
411*67e74705SXin Li return ::testing::AssertionFailure()
412*67e74705SXin Li << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
413*67e74705SXin Li "expected \"" << AttrValue.str() << "\"";
414*67e74705SXin Li
415*67e74705SXin Li return ::testing::AssertionSuccess();
416*67e74705SXin Li }
417*67e74705SXin Li
HasHTMLEndTagAt(const Comment * C,size_t Idx,HTMLEndTagComment * & HET,StringRef TagName)418*67e74705SXin Li ::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
419*67e74705SXin Li size_t Idx,
420*67e74705SXin Li HTMLEndTagComment *&HET,
421*67e74705SXin Li StringRef TagName) {
422*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
423*67e74705SXin Li if (!AR)
424*67e74705SXin Li return AR;
425*67e74705SXin Li
426*67e74705SXin Li StringRef ActualTagName = HET->getTagName();
427*67e74705SXin Li if (ActualTagName != TagName)
428*67e74705SXin Li return ::testing::AssertionFailure()
429*67e74705SXin Li << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
430*67e74705SXin Li "expected \"" << TagName.str() << "\"";
431*67e74705SXin Li
432*67e74705SXin Li return ::testing::AssertionSuccess();
433*67e74705SXin Li }
434*67e74705SXin Li
HasParagraphCommentAt(const Comment * C,size_t Idx,StringRef Text)435*67e74705SXin Li ::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
436*67e74705SXin Li size_t Idx,
437*67e74705SXin Li StringRef Text) {
438*67e74705SXin Li ParagraphComment *PC;
439*67e74705SXin Li
440*67e74705SXin Li {
441*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
442*67e74705SXin Li if (!AR)
443*67e74705SXin Li return AR;
444*67e74705SXin Li }
445*67e74705SXin Li
446*67e74705SXin Li {
447*67e74705SXin Li ::testing::AssertionResult AR = HasChildCount(PC, 1);
448*67e74705SXin Li if (!AR)
449*67e74705SXin Li return AR;
450*67e74705SXin Li }
451*67e74705SXin Li
452*67e74705SXin Li {
453*67e74705SXin Li ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
454*67e74705SXin Li if (!AR)
455*67e74705SXin Li return AR;
456*67e74705SXin Li }
457*67e74705SXin Li
458*67e74705SXin Li return ::testing::AssertionSuccess();
459*67e74705SXin Li }
460*67e74705SXin Li
HasVerbatimBlockAt(const Comment * C,const CommandTraits & Traits,size_t Idx,VerbatimBlockComment * & VBC,StringRef Name,StringRef CloseName)461*67e74705SXin Li ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
462*67e74705SXin Li const CommandTraits &Traits,
463*67e74705SXin Li size_t Idx,
464*67e74705SXin Li VerbatimBlockComment *&VBC,
465*67e74705SXin Li StringRef Name,
466*67e74705SXin Li StringRef CloseName) {
467*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
468*67e74705SXin Li if (!AR)
469*67e74705SXin Li return AR;
470*67e74705SXin Li
471*67e74705SXin Li StringRef ActualName = VBC->getCommandName(Traits);
472*67e74705SXin Li if (ActualName != Name)
473*67e74705SXin Li return ::testing::AssertionFailure()
474*67e74705SXin Li << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
475*67e74705SXin Li "expected \"" << Name.str() << "\"";
476*67e74705SXin Li
477*67e74705SXin Li StringRef ActualCloseName = VBC->getCloseName();
478*67e74705SXin Li if (ActualCloseName != CloseName)
479*67e74705SXin Li return ::testing::AssertionFailure()
480*67e74705SXin Li << "VerbatimBlockComment has closing command name \""
481*67e74705SXin Li << ActualCloseName.str() << "\", "
482*67e74705SXin Li "expected \"" << CloseName.str() << "\"";
483*67e74705SXin Li
484*67e74705SXin Li return ::testing::AssertionSuccess();
485*67e74705SXin Li }
486*67e74705SXin Li
487*67e74705SXin Li struct NoLines {};
488*67e74705SXin Li struct Lines {};
489*67e74705SXin Li
HasVerbatimBlockAt(const Comment * C,const CommandTraits & Traits,size_t Idx,VerbatimBlockComment * & VBC,StringRef Name,StringRef CloseName,NoLines)490*67e74705SXin Li ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
491*67e74705SXin Li const CommandTraits &Traits,
492*67e74705SXin Li size_t Idx,
493*67e74705SXin Li VerbatimBlockComment *&VBC,
494*67e74705SXin Li StringRef Name,
495*67e74705SXin Li StringRef CloseName,
496*67e74705SXin Li NoLines) {
497*67e74705SXin Li ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
498*67e74705SXin Li CloseName);
499*67e74705SXin Li if (!AR)
500*67e74705SXin Li return AR;
501*67e74705SXin Li
502*67e74705SXin Li if (VBC->getNumLines() != 0)
503*67e74705SXin Li return ::testing::AssertionFailure()
504*67e74705SXin Li << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
505*67e74705SXin Li "expected 0";
506*67e74705SXin Li
507*67e74705SXin Li return ::testing::AssertionSuccess();
508*67e74705SXin Li }
509*67e74705SXin Li
HasVerbatimBlockAt(const Comment * C,const CommandTraits & Traits,size_t Idx,VerbatimBlockComment * & VBC,StringRef Name,StringRef CloseName,Lines,StringRef Line0)510*67e74705SXin Li ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
511*67e74705SXin Li const CommandTraits &Traits,
512*67e74705SXin Li size_t Idx,
513*67e74705SXin Li VerbatimBlockComment *&VBC,
514*67e74705SXin Li StringRef Name,
515*67e74705SXin Li StringRef CloseName,
516*67e74705SXin Li Lines,
517*67e74705SXin Li StringRef Line0) {
518*67e74705SXin Li ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
519*67e74705SXin Li CloseName);
520*67e74705SXin Li if (!AR)
521*67e74705SXin Li return AR;
522*67e74705SXin Li
523*67e74705SXin Li if (VBC->getNumLines() != 1)
524*67e74705SXin Li return ::testing::AssertionFailure()
525*67e74705SXin Li << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
526*67e74705SXin Li "expected 1";
527*67e74705SXin Li
528*67e74705SXin Li StringRef ActualLine0 = VBC->getText(0);
529*67e74705SXin Li if (ActualLine0 != Line0)
530*67e74705SXin Li return ::testing::AssertionFailure()
531*67e74705SXin Li << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
532*67e74705SXin Li "expected \"" << Line0.str() << "\"";
533*67e74705SXin Li
534*67e74705SXin Li return ::testing::AssertionSuccess();
535*67e74705SXin Li }
536*67e74705SXin Li
HasVerbatimBlockAt(const Comment * C,const CommandTraits & Traits,size_t Idx,VerbatimBlockComment * & VBC,StringRef Name,StringRef CloseName,Lines,StringRef Line0,StringRef Line1)537*67e74705SXin Li ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
538*67e74705SXin Li const CommandTraits &Traits,
539*67e74705SXin Li size_t Idx,
540*67e74705SXin Li VerbatimBlockComment *&VBC,
541*67e74705SXin Li StringRef Name,
542*67e74705SXin Li StringRef CloseName,
543*67e74705SXin Li Lines,
544*67e74705SXin Li StringRef Line0,
545*67e74705SXin Li StringRef Line1) {
546*67e74705SXin Li ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
547*67e74705SXin Li CloseName);
548*67e74705SXin Li if (!AR)
549*67e74705SXin Li return AR;
550*67e74705SXin Li
551*67e74705SXin Li if (VBC->getNumLines() != 2)
552*67e74705SXin Li return ::testing::AssertionFailure()
553*67e74705SXin Li << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
554*67e74705SXin Li "expected 2";
555*67e74705SXin Li
556*67e74705SXin Li StringRef ActualLine0 = VBC->getText(0);
557*67e74705SXin Li if (ActualLine0 != Line0)
558*67e74705SXin Li return ::testing::AssertionFailure()
559*67e74705SXin Li << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
560*67e74705SXin Li "expected \"" << Line0.str() << "\"";
561*67e74705SXin Li
562*67e74705SXin Li StringRef ActualLine1 = VBC->getText(1);
563*67e74705SXin Li if (ActualLine1 != Line1)
564*67e74705SXin Li return ::testing::AssertionFailure()
565*67e74705SXin Li << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
566*67e74705SXin Li "expected \"" << Line1.str() << "\"";
567*67e74705SXin Li
568*67e74705SXin Li return ::testing::AssertionSuccess();
569*67e74705SXin Li }
570*67e74705SXin Li
HasVerbatimLineAt(const Comment * C,const CommandTraits & Traits,size_t Idx,VerbatimLineComment * & VLC,StringRef Name,StringRef Text)571*67e74705SXin Li ::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
572*67e74705SXin Li const CommandTraits &Traits,
573*67e74705SXin Li size_t Idx,
574*67e74705SXin Li VerbatimLineComment *&VLC,
575*67e74705SXin Li StringRef Name,
576*67e74705SXin Li StringRef Text) {
577*67e74705SXin Li ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
578*67e74705SXin Li if (!AR)
579*67e74705SXin Li return AR;
580*67e74705SXin Li
581*67e74705SXin Li StringRef ActualName = VLC->getCommandName(Traits);
582*67e74705SXin Li if (ActualName != Name)
583*67e74705SXin Li return ::testing::AssertionFailure()
584*67e74705SXin Li << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
585*67e74705SXin Li "expected \"" << Name.str() << "\"";
586*67e74705SXin Li
587*67e74705SXin Li StringRef ActualText = VLC->getText();
588*67e74705SXin Li if (ActualText != Text)
589*67e74705SXin Li return ::testing::AssertionFailure()
590*67e74705SXin Li << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
591*67e74705SXin Li "expected \"" << Text.str() << "\"";
592*67e74705SXin Li
593*67e74705SXin Li return ::testing::AssertionSuccess();
594*67e74705SXin Li }
595*67e74705SXin Li
596*67e74705SXin Li
TEST_F(CommentParserTest,Basic1)597*67e74705SXin Li TEST_F(CommentParserTest, Basic1) {
598*67e74705SXin Li const char *Source = "//";
599*67e74705SXin Li
600*67e74705SXin Li FullComment *FC = parseString(Source);
601*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 0));
602*67e74705SXin Li }
603*67e74705SXin Li
TEST_F(CommentParserTest,Basic2)604*67e74705SXin Li TEST_F(CommentParserTest, Basic2) {
605*67e74705SXin Li const char *Source = "// Meow";
606*67e74705SXin Li
607*67e74705SXin Li FullComment *FC = parseString(Source);
608*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
609*67e74705SXin Li
610*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
611*67e74705SXin Li }
612*67e74705SXin Li
TEST_F(CommentParserTest,Basic3)613*67e74705SXin Li TEST_F(CommentParserTest, Basic3) {
614*67e74705SXin Li const char *Source =
615*67e74705SXin Li "// Aaa\n"
616*67e74705SXin Li "// Bbb";
617*67e74705SXin Li
618*67e74705SXin Li FullComment *FC = parseString(Source);
619*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
620*67e74705SXin Li
621*67e74705SXin Li {
622*67e74705SXin Li ParagraphComment *PC;
623*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
624*67e74705SXin Li
625*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
626*67e74705SXin Li ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
627*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
628*67e74705SXin Li }
629*67e74705SXin Li }
630*67e74705SXin Li
TEST_F(CommentParserTest,ParagraphSplitting1)631*67e74705SXin Li TEST_F(CommentParserTest, ParagraphSplitting1) {
632*67e74705SXin Li const char *Sources[] = {
633*67e74705SXin Li "// Aaa\n"
634*67e74705SXin Li "//\n"
635*67e74705SXin Li "// Bbb",
636*67e74705SXin Li
637*67e74705SXin Li "// Aaa\n"
638*67e74705SXin Li "// \n"
639*67e74705SXin Li "// Bbb",
640*67e74705SXin Li
641*67e74705SXin Li "// Aaa\n"
642*67e74705SXin Li "//\t\n"
643*67e74705SXin Li "// Bbb",
644*67e74705SXin Li
645*67e74705SXin Li "// Aaa\n"
646*67e74705SXin Li "//\n"
647*67e74705SXin Li "//\n"
648*67e74705SXin Li "// Bbb",
649*67e74705SXin Li
650*67e74705SXin Li "/**\n"
651*67e74705SXin Li " Aaa\n"
652*67e74705SXin Li "\n"
653*67e74705SXin Li " Bbb\n"
654*67e74705SXin Li "*/",
655*67e74705SXin Li
656*67e74705SXin Li "/**\n"
657*67e74705SXin Li " Aaa\n"
658*67e74705SXin Li " \n"
659*67e74705SXin Li " Bbb\n"
660*67e74705SXin Li "*/",
661*67e74705SXin Li
662*67e74705SXin Li "/**\n"
663*67e74705SXin Li " Aaa\n"
664*67e74705SXin Li "\t \n"
665*67e74705SXin Li " Bbb\n"
666*67e74705SXin Li "*/",
667*67e74705SXin Li };
668*67e74705SXin Li
669*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
670*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
671*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
672*67e74705SXin Li
673*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
674*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
675*67e74705SXin Li }
676*67e74705SXin Li }
677*67e74705SXin Li
TEST_F(CommentParserTest,Paragraph1)678*67e74705SXin Li TEST_F(CommentParserTest, Paragraph1) {
679*67e74705SXin Li const char *Source =
680*67e74705SXin Li "// \\brief Aaa\n"
681*67e74705SXin Li "//\n"
682*67e74705SXin Li "// Bbb";
683*67e74705SXin Li
684*67e74705SXin Li FullComment *FC = parseString(Source);
685*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 3));
686*67e74705SXin Li
687*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
688*67e74705SXin Li {
689*67e74705SXin Li BlockCommandComment *BCC;
690*67e74705SXin Li ParagraphComment *PC;
691*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
692*67e74705SXin Li
693*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
694*67e74705SXin Li }
695*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
696*67e74705SXin Li }
697*67e74705SXin Li
TEST_F(CommentParserTest,Paragraph2)698*67e74705SXin Li TEST_F(CommentParserTest, Paragraph2) {
699*67e74705SXin Li const char *Source = "// \\brief \\author";
700*67e74705SXin Li
701*67e74705SXin Li FullComment *FC = parseString(Source);
702*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 3));
703*67e74705SXin Li
704*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
705*67e74705SXin Li {
706*67e74705SXin Li BlockCommandComment *BCC;
707*67e74705SXin Li ParagraphComment *PC;
708*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
709*67e74705SXin Li
710*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
711*67e74705SXin Li }
712*67e74705SXin Li {
713*67e74705SXin Li BlockCommandComment *BCC;
714*67e74705SXin Li ParagraphComment *PC;
715*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
716*67e74705SXin Li
717*67e74705SXin Li ASSERT_TRUE(GetChildAt(BCC, 0, PC));
718*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
719*67e74705SXin Li }
720*67e74705SXin Li }
721*67e74705SXin Li
TEST_F(CommentParserTest,Paragraph3)722*67e74705SXin Li TEST_F(CommentParserTest, Paragraph3) {
723*67e74705SXin Li const char *Source =
724*67e74705SXin Li "// \\brief Aaa\n"
725*67e74705SXin Li "// Bbb \\author\n"
726*67e74705SXin Li "// Ccc";
727*67e74705SXin Li
728*67e74705SXin Li FullComment *FC = parseString(Source);
729*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 3));
730*67e74705SXin Li
731*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
732*67e74705SXin Li {
733*67e74705SXin Li BlockCommandComment *BCC;
734*67e74705SXin Li ParagraphComment *PC;
735*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
736*67e74705SXin Li
737*67e74705SXin Li ASSERT_TRUE(GetChildAt(BCC, 0, PC));
738*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
739*67e74705SXin Li ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
740*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
741*67e74705SXin Li }
742*67e74705SXin Li {
743*67e74705SXin Li BlockCommandComment *BCC;
744*67e74705SXin Li ParagraphComment *PC;
745*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
746*67e74705SXin Li
747*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
748*67e74705SXin Li }
749*67e74705SXin Li }
750*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand1)751*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand1) {
752*67e74705SXin Li const char *Source = "// \\param aaa";
753*67e74705SXin Li
754*67e74705SXin Li FullComment *FC = parseString(Source);
755*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
756*67e74705SXin Li
757*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
758*67e74705SXin Li {
759*67e74705SXin Li ParamCommandComment *PCC;
760*67e74705SXin Li ParagraphComment *PC;
761*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
762*67e74705SXin Li ParamCommandComment::In,
763*67e74705SXin Li /* IsDirectionExplicit = */ false,
764*67e74705SXin Li "aaa", PC));
765*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
766*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
767*67e74705SXin Li }
768*67e74705SXin Li }
769*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand2)770*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand2) {
771*67e74705SXin Li const char *Source = "// \\param\\brief";
772*67e74705SXin Li
773*67e74705SXin Li FullComment *FC = parseString(Source);
774*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 3));
775*67e74705SXin Li
776*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
777*67e74705SXin Li {
778*67e74705SXin Li ParamCommandComment *PCC;
779*67e74705SXin Li ParagraphComment *PC;
780*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
781*67e74705SXin Li ParamCommandComment::In,
782*67e74705SXin Li /* IsDirectionExplicit = */ false,
783*67e74705SXin Li "", PC));
784*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
785*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
786*67e74705SXin Li }
787*67e74705SXin Li {
788*67e74705SXin Li BlockCommandComment *BCC;
789*67e74705SXin Li ParagraphComment *PC;
790*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
791*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
792*67e74705SXin Li }
793*67e74705SXin Li }
794*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand3)795*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand3) {
796*67e74705SXin Li const char *Sources[] = {
797*67e74705SXin Li "// \\param aaa Bbb\n",
798*67e74705SXin Li "// \\param\n"
799*67e74705SXin Li "// aaa Bbb\n",
800*67e74705SXin Li "// \\param \n"
801*67e74705SXin Li "// aaa Bbb\n",
802*67e74705SXin Li "// \\param aaa\n"
803*67e74705SXin Li "// Bbb\n"
804*67e74705SXin Li };
805*67e74705SXin Li
806*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
807*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
808*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
809*67e74705SXin Li
810*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
811*67e74705SXin Li {
812*67e74705SXin Li ParamCommandComment *PCC;
813*67e74705SXin Li ParagraphComment *PC;
814*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
815*67e74705SXin Li ParamCommandComment::In,
816*67e74705SXin Li /* IsDirectionExplicit = */ false,
817*67e74705SXin Li "aaa", PC));
818*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
819*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
820*67e74705SXin Li }
821*67e74705SXin Li }
822*67e74705SXin Li }
823*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand4)824*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand4) {
825*67e74705SXin Li const char *Sources[] = {
826*67e74705SXin Li "// \\param [in] aaa Bbb\n",
827*67e74705SXin Li "// \\param[in] aaa Bbb\n",
828*67e74705SXin Li "// \\param\n"
829*67e74705SXin Li "// [in] aaa Bbb\n",
830*67e74705SXin Li "// \\param [in]\n"
831*67e74705SXin Li "// aaa Bbb\n",
832*67e74705SXin Li "// \\param [in] aaa\n"
833*67e74705SXin Li "// Bbb\n",
834*67e74705SXin Li };
835*67e74705SXin Li
836*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
837*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
838*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
839*67e74705SXin Li
840*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
841*67e74705SXin Li {
842*67e74705SXin Li ParamCommandComment *PCC;
843*67e74705SXin Li ParagraphComment *PC;
844*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
845*67e74705SXin Li ParamCommandComment::In,
846*67e74705SXin Li /* IsDirectionExplicit = */ true,
847*67e74705SXin Li "aaa", PC));
848*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
849*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
850*67e74705SXin Li }
851*67e74705SXin Li }
852*67e74705SXin Li }
853*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand5)854*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand5) {
855*67e74705SXin Li const char *Sources[] = {
856*67e74705SXin Li "// \\param [out] aaa Bbb\n",
857*67e74705SXin Li "// \\param[out] aaa Bbb\n",
858*67e74705SXin Li "// \\param\n"
859*67e74705SXin Li "// [out] aaa Bbb\n",
860*67e74705SXin Li "// \\param [out]\n"
861*67e74705SXin Li "// aaa Bbb\n",
862*67e74705SXin Li "// \\param [out] aaa\n"
863*67e74705SXin Li "// Bbb\n",
864*67e74705SXin Li };
865*67e74705SXin Li
866*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
867*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
868*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
869*67e74705SXin Li
870*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
871*67e74705SXin Li {
872*67e74705SXin Li ParamCommandComment *PCC;
873*67e74705SXin Li ParagraphComment *PC;
874*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
875*67e74705SXin Li ParamCommandComment::Out,
876*67e74705SXin Li /* IsDirectionExplicit = */ true,
877*67e74705SXin Li "aaa", PC));
878*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
879*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
880*67e74705SXin Li }
881*67e74705SXin Li }
882*67e74705SXin Li }
883*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand6)884*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand6) {
885*67e74705SXin Li const char *Sources[] = {
886*67e74705SXin Li "// \\param [in,out] aaa Bbb\n",
887*67e74705SXin Li "// \\param[in,out] aaa Bbb\n",
888*67e74705SXin Li "// \\param [in, out] aaa Bbb\n",
889*67e74705SXin Li "// \\param [in,\n"
890*67e74705SXin Li "// out] aaa Bbb\n",
891*67e74705SXin Li "// \\param [in,out]\n"
892*67e74705SXin Li "// aaa Bbb\n",
893*67e74705SXin Li "// \\param [in,out] aaa\n"
894*67e74705SXin Li "// Bbb\n"
895*67e74705SXin Li };
896*67e74705SXin Li
897*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
898*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
899*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
900*67e74705SXin Li
901*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
902*67e74705SXin Li {
903*67e74705SXin Li ParamCommandComment *PCC;
904*67e74705SXin Li ParagraphComment *PC;
905*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
906*67e74705SXin Li ParamCommandComment::InOut,
907*67e74705SXin Li /* IsDirectionExplicit = */ true,
908*67e74705SXin Li "aaa", PC));
909*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
910*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
911*67e74705SXin Li }
912*67e74705SXin Li }
913*67e74705SXin Li }
914*67e74705SXin Li
TEST_F(CommentParserTest,ParamCommand7)915*67e74705SXin Li TEST_F(CommentParserTest, ParamCommand7) {
916*67e74705SXin Li const char *Source =
917*67e74705SXin Li "// \\param aaa \\% Bbb \\$ ccc\n";
918*67e74705SXin Li
919*67e74705SXin Li FullComment *FC = parseString(Source);
920*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
921*67e74705SXin Li
922*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
923*67e74705SXin Li {
924*67e74705SXin Li ParamCommandComment *PCC;
925*67e74705SXin Li ParagraphComment *PC;
926*67e74705SXin Li ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
927*67e74705SXin Li ParamCommandComment::In,
928*67e74705SXin Li /* IsDirectionExplicit = */ false,
929*67e74705SXin Li "aaa", PC));
930*67e74705SXin Li ASSERT_TRUE(HasChildCount(PCC, 1));
931*67e74705SXin Li
932*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 5));
933*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
934*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 1, "%"));
935*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
936*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 3, "$"));
937*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
938*67e74705SXin Li }
939*67e74705SXin Li }
940*67e74705SXin Li
TEST_F(CommentParserTest,TParamCommand1)941*67e74705SXin Li TEST_F(CommentParserTest, TParamCommand1) {
942*67e74705SXin Li const char *Sources[] = {
943*67e74705SXin Li "// \\tparam aaa Bbb\n",
944*67e74705SXin Li "// \\tparam\n"
945*67e74705SXin Li "// aaa Bbb\n",
946*67e74705SXin Li "// \\tparam \n"
947*67e74705SXin Li "// aaa Bbb\n",
948*67e74705SXin Li "// \\tparam aaa\n"
949*67e74705SXin Li "// Bbb\n"
950*67e74705SXin Li };
951*67e74705SXin Li
952*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
953*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
954*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
955*67e74705SXin Li
956*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
957*67e74705SXin Li {
958*67e74705SXin Li TParamCommandComment *TPCC;
959*67e74705SXin Li ParagraphComment *PC;
960*67e74705SXin Li ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam",
961*67e74705SXin Li "aaa", PC));
962*67e74705SXin Li ASSERT_TRUE(HasChildCount(TPCC, 1));
963*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(TPCC, 0, " Bbb"));
964*67e74705SXin Li }
965*67e74705SXin Li }
966*67e74705SXin Li }
967*67e74705SXin Li
TEST_F(CommentParserTest,TParamCommand2)968*67e74705SXin Li TEST_F(CommentParserTest, TParamCommand2) {
969*67e74705SXin Li const char *Source = "// \\tparam\\brief";
970*67e74705SXin Li
971*67e74705SXin Li FullComment *FC = parseString(Source);
972*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 3));
973*67e74705SXin Li
974*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
975*67e74705SXin Li {
976*67e74705SXin Li TParamCommandComment *TPCC;
977*67e74705SXin Li ParagraphComment *PC;
978*67e74705SXin Li ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam", "", PC));
979*67e74705SXin Li ASSERT_TRUE(HasChildCount(TPCC, 1));
980*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
981*67e74705SXin Li }
982*67e74705SXin Li {
983*67e74705SXin Li BlockCommandComment *BCC;
984*67e74705SXin Li ParagraphComment *PC;
985*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
986*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
987*67e74705SXin Li }
988*67e74705SXin Li }
989*67e74705SXin Li
990*67e74705SXin Li
TEST_F(CommentParserTest,InlineCommand1)991*67e74705SXin Li TEST_F(CommentParserTest, InlineCommand1) {
992*67e74705SXin Li const char *Source = "// \\c";
993*67e74705SXin Li
994*67e74705SXin Li FullComment *FC = parseString(Source);
995*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
996*67e74705SXin Li
997*67e74705SXin Li {
998*67e74705SXin Li ParagraphComment *PC;
999*67e74705SXin Li InlineCommandComment *ICC;
1000*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1001*67e74705SXin Li
1002*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1003*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1004*67e74705SXin Li ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
1005*67e74705SXin Li }
1006*67e74705SXin Li }
1007*67e74705SXin Li
TEST_F(CommentParserTest,InlineCommand2)1008*67e74705SXin Li TEST_F(CommentParserTest, InlineCommand2) {
1009*67e74705SXin Li const char *Source = "// \\c ";
1010*67e74705SXin Li
1011*67e74705SXin Li FullComment *FC = parseString(Source);
1012*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1013*67e74705SXin Li
1014*67e74705SXin Li {
1015*67e74705SXin Li ParagraphComment *PC;
1016*67e74705SXin Li InlineCommandComment *ICC;
1017*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1018*67e74705SXin Li
1019*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 3));
1020*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1021*67e74705SXin Li ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
1022*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 2, " "));
1023*67e74705SXin Li }
1024*67e74705SXin Li }
1025*67e74705SXin Li
TEST_F(CommentParserTest,InlineCommand3)1026*67e74705SXin Li TEST_F(CommentParserTest, InlineCommand3) {
1027*67e74705SXin Li const char *Source = "// \\c aaa\n";
1028*67e74705SXin Li
1029*67e74705SXin Li FullComment *FC = parseString(Source);
1030*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1031*67e74705SXin Li
1032*67e74705SXin Li {
1033*67e74705SXin Li ParagraphComment *PC;
1034*67e74705SXin Li InlineCommandComment *ICC;
1035*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1036*67e74705SXin Li
1037*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1038*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1039*67e74705SXin Li ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
1040*67e74705SXin Li }
1041*67e74705SXin Li }
1042*67e74705SXin Li
TEST_F(CommentParserTest,InlineCommand4)1043*67e74705SXin Li TEST_F(CommentParserTest, InlineCommand4) {
1044*67e74705SXin Li const char *Source = "// \\c aaa bbb";
1045*67e74705SXin Li
1046*67e74705SXin Li FullComment *FC = parseString(Source);
1047*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1048*67e74705SXin Li
1049*67e74705SXin Li {
1050*67e74705SXin Li ParagraphComment *PC;
1051*67e74705SXin Li InlineCommandComment *ICC;
1052*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1053*67e74705SXin Li
1054*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 3));
1055*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1056*67e74705SXin Li ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
1057*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
1058*67e74705SXin Li }
1059*67e74705SXin Li }
1060*67e74705SXin Li
TEST_F(CommentParserTest,InlineCommand5)1061*67e74705SXin Li TEST_F(CommentParserTest, InlineCommand5) {
1062*67e74705SXin Li const char *Source = "// \\unknown aaa\n";
1063*67e74705SXin Li
1064*67e74705SXin Li FullComment *FC = parseString(Source);
1065*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1066*67e74705SXin Li
1067*67e74705SXin Li {
1068*67e74705SXin Li ParagraphComment *PC;
1069*67e74705SXin Li InlineCommandComment *ICC;
1070*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1071*67e74705SXin Li
1072*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 3));
1073*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1074*67e74705SXin Li ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "unknown", NoArgs()));
1075*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
1076*67e74705SXin Li }
1077*67e74705SXin Li }
1078*67e74705SXin Li
TEST_F(CommentParserTest,HTML1)1079*67e74705SXin Li TEST_F(CommentParserTest, HTML1) {
1080*67e74705SXin Li const char *Sources[] = {
1081*67e74705SXin Li "// <a",
1082*67e74705SXin Li "// <a>",
1083*67e74705SXin Li "// <a >"
1084*67e74705SXin Li };
1085*67e74705SXin Li
1086*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1087*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1088*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1089*67e74705SXin Li
1090*67e74705SXin Li {
1091*67e74705SXin Li ParagraphComment *PC;
1092*67e74705SXin Li HTMLStartTagComment *HST;
1093*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1094*67e74705SXin Li
1095*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1096*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1097*67e74705SXin Li ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
1098*67e74705SXin Li }
1099*67e74705SXin Li }
1100*67e74705SXin Li }
1101*67e74705SXin Li
TEST_F(CommentParserTest,HTML2)1102*67e74705SXin Li TEST_F(CommentParserTest, HTML2) {
1103*67e74705SXin Li const char *Sources[] = {
1104*67e74705SXin Li "// <br/>",
1105*67e74705SXin Li "// <br />"
1106*67e74705SXin Li };
1107*67e74705SXin Li
1108*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1109*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1110*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1111*67e74705SXin Li
1112*67e74705SXin Li {
1113*67e74705SXin Li ParagraphComment *PC;
1114*67e74705SXin Li HTMLStartTagComment *HST;
1115*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1116*67e74705SXin Li
1117*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1118*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1119*67e74705SXin Li ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
1120*67e74705SXin Li }
1121*67e74705SXin Li }
1122*67e74705SXin Li }
1123*67e74705SXin Li
TEST_F(CommentParserTest,HTML3)1124*67e74705SXin Li TEST_F(CommentParserTest, HTML3) {
1125*67e74705SXin Li const char *Sources[] = {
1126*67e74705SXin Li "// <a href",
1127*67e74705SXin Li "// <a href ",
1128*67e74705SXin Li "// <a href>",
1129*67e74705SXin Li "// <a href >",
1130*67e74705SXin Li };
1131*67e74705SXin Li
1132*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1133*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1134*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1135*67e74705SXin Li
1136*67e74705SXin Li {
1137*67e74705SXin Li ParagraphComment *PC;
1138*67e74705SXin Li HTMLStartTagComment *HST;
1139*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1140*67e74705SXin Li
1141*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1142*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1143*67e74705SXin Li ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
1144*67e74705SXin Li }
1145*67e74705SXin Li }
1146*67e74705SXin Li }
1147*67e74705SXin Li
TEST_F(CommentParserTest,HTML4)1148*67e74705SXin Li TEST_F(CommentParserTest, HTML4) {
1149*67e74705SXin Li const char *Sources[] = {
1150*67e74705SXin Li "// <a href=\"bbb\"",
1151*67e74705SXin Li "// <a href=\"bbb\">",
1152*67e74705SXin Li };
1153*67e74705SXin Li
1154*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1155*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1156*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1157*67e74705SXin Li
1158*67e74705SXin Li {
1159*67e74705SXin Li ParagraphComment *PC;
1160*67e74705SXin Li HTMLStartTagComment *HST;
1161*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1162*67e74705SXin Li
1163*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1164*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1165*67e74705SXin Li ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
1166*67e74705SXin Li }
1167*67e74705SXin Li }
1168*67e74705SXin Li }
1169*67e74705SXin Li
TEST_F(CommentParserTest,HTML5)1170*67e74705SXin Li TEST_F(CommentParserTest, HTML5) {
1171*67e74705SXin Li const char *Sources[] = {
1172*67e74705SXin Li "// </a",
1173*67e74705SXin Li "// </a>",
1174*67e74705SXin Li "// </a >"
1175*67e74705SXin Li };
1176*67e74705SXin Li
1177*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1178*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1179*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1180*67e74705SXin Li
1181*67e74705SXin Li {
1182*67e74705SXin Li ParagraphComment *PC;
1183*67e74705SXin Li HTMLEndTagComment *HET;
1184*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1185*67e74705SXin Li
1186*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 2));
1187*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1188*67e74705SXin Li ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
1189*67e74705SXin Li }
1190*67e74705SXin Li }
1191*67e74705SXin Li }
1192*67e74705SXin Li
TEST_F(CommentParserTest,HTML6)1193*67e74705SXin Li TEST_F(CommentParserTest, HTML6) {
1194*67e74705SXin Li const char *Source =
1195*67e74705SXin Li "// <pre>\n"
1196*67e74705SXin Li "// Aaa\n"
1197*67e74705SXin Li "// Bbb\n"
1198*67e74705SXin Li "// </pre>\n";
1199*67e74705SXin Li
1200*67e74705SXin Li FullComment *FC = parseString(Source);
1201*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1202*67e74705SXin Li
1203*67e74705SXin Li {
1204*67e74705SXin Li ParagraphComment *PC;
1205*67e74705SXin Li HTMLStartTagComment *HST;
1206*67e74705SXin Li HTMLEndTagComment *HET;
1207*67e74705SXin Li ASSERT_TRUE(GetChildAt(FC, 0, PC));
1208*67e74705SXin Li
1209*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 6));
1210*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 0, " "));
1211*67e74705SXin Li ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
1212*67e74705SXin Li ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
1213*67e74705SXin Li ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
1214*67e74705SXin Li ASSERT_TRUE(HasTextAt(PC, 4, " "));
1215*67e74705SXin Li ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
1216*67e74705SXin Li }
1217*67e74705SXin Li }
1218*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock1)1219*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock1) {
1220*67e74705SXin Li const char *Source = "// \\verbatim\\endverbatim\n";
1221*67e74705SXin Li
1222*67e74705SXin Li FullComment *FC = parseString(Source);
1223*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1224*67e74705SXin Li
1225*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1226*67e74705SXin Li {
1227*67e74705SXin Li VerbatimBlockComment *VCC;
1228*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VCC,
1229*67e74705SXin Li "verbatim", "endverbatim",
1230*67e74705SXin Li NoLines()));
1231*67e74705SXin Li }
1232*67e74705SXin Li }
1233*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock2)1234*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock2) {
1235*67e74705SXin Li const char *Source = "// \\verbatim Aaa \\endverbatim\n";
1236*67e74705SXin Li
1237*67e74705SXin Li FullComment *FC = parseString(Source);
1238*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1239*67e74705SXin Li
1240*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1241*67e74705SXin Li {
1242*67e74705SXin Li VerbatimBlockComment *VBC;
1243*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1244*67e74705SXin Li "verbatim", "endverbatim",
1245*67e74705SXin Li Lines(), " Aaa "));
1246*67e74705SXin Li }
1247*67e74705SXin Li }
1248*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock3)1249*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock3) {
1250*67e74705SXin Li const char *Source = "// \\verbatim Aaa\n";
1251*67e74705SXin Li
1252*67e74705SXin Li FullComment *FC = parseString(Source);
1253*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1254*67e74705SXin Li
1255*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1256*67e74705SXin Li {
1257*67e74705SXin Li VerbatimBlockComment *VBC;
1258*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC, "verbatim", "",
1259*67e74705SXin Li Lines(), " Aaa"));
1260*67e74705SXin Li }
1261*67e74705SXin Li }
1262*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock4)1263*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock4) {
1264*67e74705SXin Li const char *Source =
1265*67e74705SXin Li "//\\verbatim\n"
1266*67e74705SXin Li "//\\endverbatim\n";
1267*67e74705SXin Li
1268*67e74705SXin Li FullComment *FC = parseString(Source);
1269*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1270*67e74705SXin Li
1271*67e74705SXin Li {
1272*67e74705SXin Li VerbatimBlockComment *VBC;
1273*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1274*67e74705SXin Li "verbatim", "endverbatim",
1275*67e74705SXin Li NoLines()));
1276*67e74705SXin Li }
1277*67e74705SXin Li }
1278*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock5)1279*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock5) {
1280*67e74705SXin Li const char *Sources[] = {
1281*67e74705SXin Li "//\\verbatim\n"
1282*67e74705SXin Li "// Aaa\n"
1283*67e74705SXin Li "//\\endverbatim\n",
1284*67e74705SXin Li
1285*67e74705SXin Li "/*\\verbatim\n"
1286*67e74705SXin Li " * Aaa\n"
1287*67e74705SXin Li " *\\endverbatim*/"
1288*67e74705SXin Li };
1289*67e74705SXin Li
1290*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1291*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1292*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 1));
1293*67e74705SXin Li
1294*67e74705SXin Li {
1295*67e74705SXin Li VerbatimBlockComment *VBC;
1296*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
1297*67e74705SXin Li "verbatim", "endverbatim",
1298*67e74705SXin Li Lines(), " Aaa"));
1299*67e74705SXin Li }
1300*67e74705SXin Li }
1301*67e74705SXin Li }
1302*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock6)1303*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock6) {
1304*67e74705SXin Li const char *Sources[] = {
1305*67e74705SXin Li "// \\verbatim\n"
1306*67e74705SXin Li "// Aaa\n"
1307*67e74705SXin Li "// \\endverbatim\n",
1308*67e74705SXin Li
1309*67e74705SXin Li "/* \\verbatim\n"
1310*67e74705SXin Li " * Aaa\n"
1311*67e74705SXin Li " * \\endverbatim*/"
1312*67e74705SXin Li };
1313*67e74705SXin Li
1314*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1315*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1316*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1317*67e74705SXin Li
1318*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1319*67e74705SXin Li {
1320*67e74705SXin Li VerbatimBlockComment *VBC;
1321*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1322*67e74705SXin Li "verbatim", "endverbatim",
1323*67e74705SXin Li Lines(), " Aaa"));
1324*67e74705SXin Li }
1325*67e74705SXin Li }
1326*67e74705SXin Li }
1327*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock7)1328*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock7) {
1329*67e74705SXin Li const char *Sources[] = {
1330*67e74705SXin Li "// \\verbatim\n"
1331*67e74705SXin Li "// Aaa\n"
1332*67e74705SXin Li "// Bbb\n"
1333*67e74705SXin Li "// \\endverbatim\n",
1334*67e74705SXin Li
1335*67e74705SXin Li "/* \\verbatim\n"
1336*67e74705SXin Li " * Aaa\n"
1337*67e74705SXin Li " * Bbb\n"
1338*67e74705SXin Li " * \\endverbatim*/"
1339*67e74705SXin Li };
1340*67e74705SXin Li
1341*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1342*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1343*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1344*67e74705SXin Li
1345*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1346*67e74705SXin Li {
1347*67e74705SXin Li VerbatimBlockComment *VBC;
1348*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1349*67e74705SXin Li "verbatim", "endverbatim",
1350*67e74705SXin Li Lines(), " Aaa", " Bbb"));
1351*67e74705SXin Li }
1352*67e74705SXin Li }
1353*67e74705SXin Li }
1354*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimBlock8)1355*67e74705SXin Li TEST_F(CommentParserTest, VerbatimBlock8) {
1356*67e74705SXin Li const char *Sources[] = {
1357*67e74705SXin Li "// \\verbatim\n"
1358*67e74705SXin Li "// Aaa\n"
1359*67e74705SXin Li "//\n"
1360*67e74705SXin Li "// Bbb\n"
1361*67e74705SXin Li "// \\endverbatim\n",
1362*67e74705SXin Li
1363*67e74705SXin Li "/* \\verbatim\n"
1364*67e74705SXin Li " * Aaa\n"
1365*67e74705SXin Li " *\n"
1366*67e74705SXin Li " * Bbb\n"
1367*67e74705SXin Li " * \\endverbatim*/"
1368*67e74705SXin Li };
1369*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1370*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1371*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1372*67e74705SXin Li
1373*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1374*67e74705SXin Li {
1375*67e74705SXin Li VerbatimBlockComment *VBC;
1376*67e74705SXin Li ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
1377*67e74705SXin Li "verbatim", "endverbatim"));
1378*67e74705SXin Li ASSERT_EQ(3U, VBC->getNumLines());
1379*67e74705SXin Li ASSERT_EQ(" Aaa", VBC->getText(0));
1380*67e74705SXin Li ASSERT_EQ("", VBC->getText(1));
1381*67e74705SXin Li ASSERT_EQ(" Bbb", VBC->getText(2));
1382*67e74705SXin Li }
1383*67e74705SXin Li }
1384*67e74705SXin Li }
1385*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimLine1)1386*67e74705SXin Li TEST_F(CommentParserTest, VerbatimLine1) {
1387*67e74705SXin Li const char *Sources[] = {
1388*67e74705SXin Li "// \\fn",
1389*67e74705SXin Li "// \\fn\n"
1390*67e74705SXin Li };
1391*67e74705SXin Li
1392*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1393*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1394*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1395*67e74705SXin Li
1396*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1397*67e74705SXin Li {
1398*67e74705SXin Li VerbatimLineComment *VLC;
1399*67e74705SXin Li ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn", ""));
1400*67e74705SXin Li }
1401*67e74705SXin Li }
1402*67e74705SXin Li }
1403*67e74705SXin Li
TEST_F(CommentParserTest,VerbatimLine2)1404*67e74705SXin Li TEST_F(CommentParserTest, VerbatimLine2) {
1405*67e74705SXin Li const char *Sources[] = {
1406*67e74705SXin Li "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
1407*67e74705SXin Li "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
1408*67e74705SXin Li };
1409*67e74705SXin Li
1410*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1411*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1412*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1413*67e74705SXin Li
1414*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1415*67e74705SXin Li {
1416*67e74705SXin Li VerbatimLineComment *VLC;
1417*67e74705SXin Li ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn",
1418*67e74705SXin Li " void *foo(const char *zzz = \"\\$\");"));
1419*67e74705SXin Li }
1420*67e74705SXin Li }
1421*67e74705SXin Li }
1422*67e74705SXin Li
TEST_F(CommentParserTest,Deprecated)1423*67e74705SXin Li TEST_F(CommentParserTest, Deprecated) {
1424*67e74705SXin Li const char *Sources[] = {
1425*67e74705SXin Li "/** @deprecated*/",
1426*67e74705SXin Li "/// @deprecated\n"
1427*67e74705SXin Li };
1428*67e74705SXin Li
1429*67e74705SXin Li for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
1430*67e74705SXin Li FullComment *FC = parseString(Sources[i]);
1431*67e74705SXin Li ASSERT_TRUE(HasChildCount(FC, 2));
1432*67e74705SXin Li
1433*67e74705SXin Li ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
1434*67e74705SXin Li {
1435*67e74705SXin Li BlockCommandComment *BCC;
1436*67e74705SXin Li ParagraphComment *PC;
1437*67e74705SXin Li ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "deprecated", PC));
1438*67e74705SXin Li ASSERT_TRUE(HasChildCount(PC, 0));
1439*67e74705SXin Li }
1440*67e74705SXin Li }
1441*67e74705SXin Li }
1442*67e74705SXin Li
1443*67e74705SXin Li } // unnamed namespace
1444*67e74705SXin Li
1445*67e74705SXin Li } // end namespace comments
1446*67e74705SXin Li } // end namespace clang
1447*67e74705SXin Li
1448