12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- //===- unittests/AST/CommentParser.cpp ------ Comment parser tests --------===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- #include "clang/AST/CommentParser.h"
- #include "clang/AST/Comment.h"
- #include "clang/AST/CommentCommandTraits.h"
- #include "clang/AST/CommentLexer.h"
- #include "clang/AST/CommentSema.h"
- #include "clang/Basic/CommentOptions.h"
- #include "clang/Basic/Diagnostic.h"
- #include "clang/Basic/DiagnosticOptions.h"
- #include "clang/Basic/FileManager.h"
- #include "clang/Basic/SourceManager.h"
- #include "llvm/ADT/STLExtras.h"
- #include "llvm/Support/Allocator.h"
- #include "gtest/gtest.h"
- using namespace llvm;
- using namespace clang;
- namespace clang {
- namespace comments {
- namespace {
- const bool MY_DEBUG = true;
- class CommentParserTest : public ::testing::Test {
- protected:
- CommentParserTest()
- : FileMgr(FileMgrOpts),
- DiagID(new DiagnosticIDs()),
- Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
- SourceMgr(Diags, FileMgr),
- Traits(Allocator, CommentOptions()) {
- }
- FileSystemOptions FileMgrOpts;
- FileManager FileMgr;
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
- DiagnosticsEngine Diags;
- SourceManager SourceMgr;
- llvm::BumpPtrAllocator Allocator;
- CommandTraits Traits;
- FullComment *parseString(const char *Source);
- };
- FullComment *CommentParserTest::parseString(const char *Source) {
- std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
- FileID File = SourceMgr.createFileID(std::move(Buf));
- SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
- Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
- Sema S(Allocator, SourceMgr, Diags, Traits, /*PP=*/ nullptr);
- Parser P(L, S, Allocator, SourceMgr, Diags, Traits);
- FullComment *FC = P.parseFullComment();
- if (MY_DEBUG) {
- llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
- FC->dump(llvm::errs(), &Traits, &SourceMgr);
- }
- Token Tok;
- L.lex(Tok);
- if (Tok.is(tok::eof))
- return FC;
- else
- return nullptr;
- }
- ::testing::AssertionResult HasChildCount(const Comment *C, size_t Count) {
- if (!C)
- return ::testing::AssertionFailure() << "Comment is NULL";
- if (Count != C->child_count())
- return ::testing::AssertionFailure()
- << "Count = " << Count
- << ", child_count = " << C->child_count();
- return ::testing::AssertionSuccess();
- }
- template <typename T>
- ::testing::AssertionResult GetChildAt(const Comment *C,
- size_t Idx,
- T *&Child) {
- if (!C)
- return ::testing::AssertionFailure() << "Comment is NULL";
- if (Idx >= C->child_count())
- return ::testing::AssertionFailure()
- << "Idx out of range. Idx = " << Idx
- << ", child_count = " << C->child_count();
- Comment::child_iterator I = C->child_begin() + Idx;
- Comment *CommentChild = *I;
- if (!CommentChild)
- return ::testing::AssertionFailure() << "Child is NULL";
- Child = dyn_cast<T>(CommentChild);
- if (!Child)
- return ::testing::AssertionFailure()
- << "Child is not of requested type, but a "
- << CommentChild->getCommentKindName();
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasTextAt(const Comment *C,
- size_t Idx,
- StringRef Text) {
- TextComment *TC;
- ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
- if (!AR)
- return AR;
- StringRef ActualText = TC->getText();
- if (ActualText != Text)
- return ::testing::AssertionFailure()
- << "TextComment has text \"" << ActualText.str() << "\", "
- "expected \"" << Text.str() << "\"";
- if (TC->hasTrailingNewline())
- return ::testing::AssertionFailure()
- << "TextComment has a trailing newline";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasTextWithNewlineAt(const Comment *C,
- size_t Idx,
- StringRef Text) {
- TextComment *TC;
- ::testing::AssertionResult AR = GetChildAt(C, Idx, TC);
- if (!AR)
- return AR;
- StringRef ActualText = TC->getText();
- if (ActualText != Text)
- return ::testing::AssertionFailure()
- << "TextComment has text \"" << ActualText.str() << "\", "
- "expected \"" << Text.str() << "\"";
- if (!TC->hasTrailingNewline())
- return ::testing::AssertionFailure()
- << "TextComment has no trailing newline";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasBlockCommandAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- BlockCommandComment *&BCC,
- StringRef Name,
- ParagraphComment *&Paragraph) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, BCC);
- if (!AR)
- return AR;
- StringRef ActualName = BCC->getCommandName(Traits);
- if (ActualName != Name)
- return ::testing::AssertionFailure()
- << "BlockCommandComment has name \"" << ActualName.str() << "\", "
- "expected \"" << Name.str() << "\"";
- Paragraph = BCC->getParagraph();
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasParamCommandAt(
- const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- ParamCommandComment *&PCC,
- StringRef CommandName,
- ParamCommandComment::PassDirection Direction,
- bool IsDirectionExplicit,
- StringRef ParamName,
- ParagraphComment *&Paragraph) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC);
- if (!AR)
- return AR;
- StringRef ActualCommandName = PCC->getCommandName(Traits);
- if (ActualCommandName != CommandName)
- return ::testing::AssertionFailure()
- << "ParamCommandComment has name \"" << ActualCommandName.str() << "\", "
- "expected \"" << CommandName.str() << "\"";
- if (PCC->getDirection() != Direction)
- return ::testing::AssertionFailure()
- << "ParamCommandComment has direction " << PCC->getDirection() << ", "
- "expected " << Direction;
- if (PCC->isDirectionExplicit() != IsDirectionExplicit)
- return ::testing::AssertionFailure()
- << "ParamCommandComment has "
- << (PCC->isDirectionExplicit() ? "explicit" : "implicit")
- << " direction, "
- "expected " << (IsDirectionExplicit ? "explicit" : "implicit");
- if (!ParamName.empty() && !PCC->hasParamName())
- return ::testing::AssertionFailure()
- << "ParamCommandComment has no parameter name";
- StringRef ActualParamName = PCC->hasParamName() ? PCC->getParamNameAsWritten() : "";
- if (ActualParamName != ParamName)
- return ::testing::AssertionFailure()
- << "ParamCommandComment has parameter name \"" << ActualParamName.str()
- << "\", "
- "expected \"" << ParamName.str() << "\"";
- Paragraph = PCC->getParagraph();
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasTParamCommandAt(
- const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- TParamCommandComment *&TPCC,
- StringRef CommandName,
- StringRef ParamName,
- ParagraphComment *&Paragraph) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, TPCC);
- if (!AR)
- return AR;
- StringRef ActualCommandName = TPCC->getCommandName(Traits);
- if (ActualCommandName != CommandName)
- return ::testing::AssertionFailure()
- << "TParamCommandComment has name \"" << ActualCommandName.str() << "\", "
- "expected \"" << CommandName.str() << "\"";
- if (!ParamName.empty() && !TPCC->hasParamName())
- return ::testing::AssertionFailure()
- << "TParamCommandComment has no parameter name";
- StringRef ActualParamName = TPCC->hasParamName() ? TPCC->getParamNameAsWritten() : "";
- if (ActualParamName != ParamName)
- return ::testing::AssertionFailure()
- << "TParamCommandComment has parameter name \"" << ActualParamName.str()
- << "\", "
- "expected \"" << ParamName.str() << "\"";
- Paragraph = TPCC->getParagraph();
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- InlineCommandComment *&ICC,
- StringRef Name) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, ICC);
- if (!AR)
- return AR;
- StringRef ActualName = ICC->getCommandName(Traits);
- if (ActualName != Name)
- return ::testing::AssertionFailure()
- << "InlineCommandComment has name \"" << ActualName.str() << "\", "
- "expected \"" << Name.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- struct NoArgs {};
- ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- InlineCommandComment *&ICC,
- StringRef Name,
- NoArgs) {
- ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
- if (!AR)
- return AR;
- if (ICC->getNumArgs() != 0)
- return ::testing::AssertionFailure()
- << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
- "expected 0";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasInlineCommandAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- InlineCommandComment *&ICC,
- StringRef Name,
- StringRef Arg) {
- ::testing::AssertionResult AR = HasInlineCommandAt(C, Traits, Idx, ICC, Name);
- if (!AR)
- return AR;
- if (ICC->getNumArgs() != 1)
- return ::testing::AssertionFailure()
- << "InlineCommandComment has " << ICC->getNumArgs() << " arg(s), "
- "expected 1";
- StringRef ActualArg = ICC->getArgText(0);
- if (ActualArg != Arg)
- return ::testing::AssertionFailure()
- << "InlineCommandComment has argument \"" << ActualArg.str() << "\", "
- "expected \"" << Arg.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
- size_t Idx,
- HTMLStartTagComment *&HST,
- StringRef TagName) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, HST);
- if (!AR)
- return AR;
- StringRef ActualTagName = HST->getTagName();
- if (ActualTagName != TagName)
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment has name \"" << ActualTagName.str() << "\", "
- "expected \"" << TagName.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- struct SelfClosing {};
- ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
- size_t Idx,
- HTMLStartTagComment *&HST,
- StringRef TagName,
- SelfClosing) {
- ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
- if (!AR)
- return AR;
- if (!HST->isSelfClosing())
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment is not self-closing";
- return ::testing::AssertionSuccess();
- }
- struct NoAttrs {};
- ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
- size_t Idx,
- HTMLStartTagComment *&HST,
- StringRef TagName,
- NoAttrs) {
- ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
- if (!AR)
- return AR;
- if (HST->isSelfClosing())
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment is self-closing";
- if (HST->getNumAttrs() != 0)
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
- "expected 0";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasHTMLStartTagAt(const Comment *C,
- size_t Idx,
- HTMLStartTagComment *&HST,
- StringRef TagName,
- StringRef AttrName,
- StringRef AttrValue) {
- ::testing::AssertionResult AR = HasHTMLStartTagAt(C, Idx, HST, TagName);
- if (!AR)
- return AR;
- if (HST->isSelfClosing())
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment is self-closing";
- if (HST->getNumAttrs() != 1)
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment has " << HST->getNumAttrs() << " attr(s), "
- "expected 1";
- StringRef ActualName = HST->getAttr(0).Name;
- if (ActualName != AttrName)
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment has attr \"" << ActualName.str() << "\", "
- "expected \"" << AttrName.str() << "\"";
- StringRef ActualValue = HST->getAttr(0).Value;
- if (ActualValue != AttrValue)
- return ::testing::AssertionFailure()
- << "HTMLStartTagComment has attr value \"" << ActualValue.str() << "\", "
- "expected \"" << AttrValue.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasHTMLEndTagAt(const Comment *C,
- size_t Idx,
- HTMLEndTagComment *&HET,
- StringRef TagName) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, HET);
- if (!AR)
- return AR;
- StringRef ActualTagName = HET->getTagName();
- if (ActualTagName != TagName)
- return ::testing::AssertionFailure()
- << "HTMLEndTagComment has name \"" << ActualTagName.str() << "\", "
- "expected \"" << TagName.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasParagraphCommentAt(const Comment *C,
- size_t Idx,
- StringRef Text) {
- ParagraphComment *PC;
- {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, PC);
- if (!AR)
- return AR;
- }
- {
- ::testing::AssertionResult AR = HasChildCount(PC, 1);
- if (!AR)
- return AR;
- }
- {
- ::testing::AssertionResult AR = HasTextAt(PC, 0, Text);
- if (!AR)
- return AR;
- }
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- VerbatimBlockComment *&VBC,
- StringRef Name,
- StringRef CloseName) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, VBC);
- if (!AR)
- return AR;
- StringRef ActualName = VBC->getCommandName(Traits);
- if (ActualName != Name)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has name \"" << ActualName.str() << "\", "
- "expected \"" << Name.str() << "\"";
- StringRef ActualCloseName = VBC->getCloseName();
- if (ActualCloseName != CloseName)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has closing command name \""
- << ActualCloseName.str() << "\", "
- "expected \"" << CloseName.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- struct NoLines {};
- struct Lines {};
- ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- VerbatimBlockComment *&VBC,
- StringRef Name,
- StringRef CloseName,
- NoLines) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
- CloseName);
- if (!AR)
- return AR;
- if (VBC->getNumLines() != 0)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
- "expected 0";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- VerbatimBlockComment *&VBC,
- StringRef Name,
- StringRef CloseName,
- Lines,
- StringRef Line0) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
- CloseName);
- if (!AR)
- return AR;
- if (VBC->getNumLines() != 1)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
- "expected 1";
- StringRef ActualLine0 = VBC->getText(0);
- if (ActualLine0 != Line0)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
- "expected \"" << Line0.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasVerbatimBlockAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- VerbatimBlockComment *&VBC,
- StringRef Name,
- StringRef CloseName,
- Lines,
- StringRef Line0,
- StringRef Line1) {
- ::testing::AssertionResult AR = HasVerbatimBlockAt(C, Traits, Idx, VBC, Name,
- CloseName);
- if (!AR)
- return AR;
- if (VBC->getNumLines() != 2)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has " << VBC->getNumLines() << " lines(s), "
- "expected 2";
- StringRef ActualLine0 = VBC->getText(0);
- if (ActualLine0 != Line0)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has lines[0] \"" << ActualLine0.str() << "\", "
- "expected \"" << Line0.str() << "\"";
- StringRef ActualLine1 = VBC->getText(1);
- if (ActualLine1 != Line1)
- return ::testing::AssertionFailure()
- << "VerbatimBlockComment has lines[1] \"" << ActualLine1.str() << "\", "
- "expected \"" << Line1.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- ::testing::AssertionResult HasVerbatimLineAt(const Comment *C,
- const CommandTraits &Traits,
- size_t Idx,
- VerbatimLineComment *&VLC,
- StringRef Name,
- StringRef Text) {
- ::testing::AssertionResult AR = GetChildAt(C, Idx, VLC);
- if (!AR)
- return AR;
- StringRef ActualName = VLC->getCommandName(Traits);
- if (ActualName != Name)
- return ::testing::AssertionFailure()
- << "VerbatimLineComment has name \"" << ActualName.str() << "\", "
- "expected \"" << Name.str() << "\"";
- StringRef ActualText = VLC->getText();
- if (ActualText != Text)
- return ::testing::AssertionFailure()
- << "VerbatimLineComment has text \"" << ActualText.str() << "\", "
- "expected \"" << Text.str() << "\"";
- return ::testing::AssertionSuccess();
- }
- TEST_F(CommentParserTest, Basic1) {
- const char *Source = "//";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 0));
- }
- TEST_F(CommentParserTest, Basic2) {
- const char *Source = "// Meow";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Meow"));
- }
- TEST_F(CommentParserTest, Basic3) {
- const char *Source =
- "// Aaa\n"
- "// Bbb";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
- ASSERT_TRUE(HasTextAt(PC, 1, " Bbb"));
- }
- }
- TEST_F(CommentParserTest, ParagraphSplitting1) {
- const char *Sources[] = {
- "// Aaa\n"
- "//\n"
- "// Bbb",
- "// Aaa\n"
- "// \n"
- "// Bbb",
- "// Aaa\n"
- "//\t\n"
- "// Bbb",
- "// Aaa\n"
- "//\n"
- "//\n"
- "// Bbb",
- "/**\n"
- " Aaa\n"
- "\n"
- " Bbb\n"
- "*/",
- "/**\n"
- " Aaa\n"
- " \n"
- " Bbb\n"
- "*/",
- "/**\n"
- " Aaa\n"
- "\t \n"
- " Bbb\n"
- "*/",
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " Aaa"));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 1, " Bbb"));
- }
- }
- TEST_F(CommentParserTest, Paragraph1) {
- const char *Source =
- "// \\brief Aaa\n"
- "//\n"
- "// Bbb";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 3));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
- ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Aaa"));
- }
- ASSERT_TRUE(HasParagraphCommentAt(FC, 2, " Bbb"));
- }
- TEST_F(CommentParserTest, Paragraph2) {
- const char *Source = "// \\brief \\author";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 3));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
- ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " "));
- }
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
- ASSERT_TRUE(GetChildAt(BCC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- }
- TEST_F(CommentParserTest, Paragraph3) {
- const char *Source =
- "// \\brief Aaa\n"
- "// Bbb \\author\n"
- "// Ccc";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 3));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "brief", PC));
- ASSERT_TRUE(GetChildAt(BCC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextWithNewlineAt(PC, 0, " Aaa"));
- ASSERT_TRUE(HasTextAt(PC, 1, " Bbb "));
- }
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "author", PC));
- ASSERT_TRUE(HasParagraphCommentAt(BCC, 0, " Ccc"));
- }
- }
- TEST_F(CommentParserTest, ParamCommand1) {
- const char *Source = "// \\param aaa";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::In,
- /* IsDirectionExplicit = */ false,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- }
- TEST_F(CommentParserTest, ParamCommand2) {
- const char *Source = "// \\param\\brief";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 3));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::In,
- /* IsDirectionExplicit = */ false,
- "", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- }
- TEST_F(CommentParserTest, ParamCommand3) {
- const char *Sources[] = {
- "// \\param aaa Bbb\n",
- "// \\param\n"
- "// aaa Bbb\n",
- "// \\param \n"
- "// aaa Bbb\n",
- "// \\param aaa\n"
- "// Bbb\n"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::In,
- /* IsDirectionExplicit = */ false,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, ParamCommand4) {
- const char *Sources[] = {
- "// \\param [in] aaa Bbb\n",
- "// \\param[in] aaa Bbb\n",
- "// \\param\n"
- "// [in] aaa Bbb\n",
- "// \\param [in]\n"
- "// aaa Bbb\n",
- "// \\param [in] aaa\n"
- "// Bbb\n",
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::In,
- /* IsDirectionExplicit = */ true,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, ParamCommand5) {
- const char *Sources[] = {
- "// \\param [out] aaa Bbb\n",
- "// \\param[out] aaa Bbb\n",
- "// \\param\n"
- "// [out] aaa Bbb\n",
- "// \\param [out]\n"
- "// aaa Bbb\n",
- "// \\param [out] aaa\n"
- "// Bbb\n",
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::Out,
- /* IsDirectionExplicit = */ true,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, ParamCommand6) {
- const char *Sources[] = {
- "// \\param [in,out] aaa Bbb\n",
- "// \\param[in,out] aaa Bbb\n",
- "// \\param [in, out] aaa Bbb\n",
- "// \\param [in,\n"
- "// out] aaa Bbb\n",
- "// \\param [in,out]\n"
- "// aaa Bbb\n",
- "// \\param [in,out] aaa\n"
- "// Bbb\n"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::InOut,
- /* IsDirectionExplicit = */ true,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, ParamCommand7) {
- const char *Source =
- "// \\param aaa \\% Bbb \\$ ccc\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- ParamCommandComment *PCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param",
- ParamCommandComment::In,
- /* IsDirectionExplicit = */ false,
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(PCC, 1));
- ASSERT_TRUE(HasChildCount(PC, 5));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasTextAt(PC, 1, "%"));
- ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
- ASSERT_TRUE(HasTextAt(PC, 3, "$"));
- ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
- }
- }
- TEST_F(CommentParserTest, TParamCommand1) {
- const char *Sources[] = {
- "// \\tparam aaa Bbb\n",
- "// \\tparam\n"
- "// aaa Bbb\n",
- "// \\tparam \n"
- "// aaa Bbb\n",
- "// \\tparam aaa\n"
- "// Bbb\n"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- TParamCommandComment *TPCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam",
- "aaa", PC));
- ASSERT_TRUE(HasChildCount(TPCC, 1));
- ASSERT_TRUE(HasParagraphCommentAt(TPCC, 0, " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, TParamCommand2) {
- const char *Source = "// \\tparam\\brief";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 3));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- TParamCommandComment *TPCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasTParamCommandAt(FC, Traits, 1, TPCC, "tparam", "", PC));
- ASSERT_TRUE(HasChildCount(TPCC, 1));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 2, BCC, "brief", PC));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- }
- TEST_F(CommentParserTest, InlineCommand1) {
- const char *Source = "// \\c";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- InlineCommandComment *ICC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
- }
- }
- TEST_F(CommentParserTest, InlineCommand2) {
- const char *Source = "// \\c ";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- InlineCommandComment *ICC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 3));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", NoArgs()));
- ASSERT_TRUE(HasTextAt(PC, 2, " "));
- }
- }
- TEST_F(CommentParserTest, InlineCommand3) {
- const char *Source = "// \\c aaa\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- InlineCommandComment *ICC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
- }
- }
- TEST_F(CommentParserTest, InlineCommand4) {
- const char *Source = "// \\c aaa bbb";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- InlineCommandComment *ICC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 3));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "c", "aaa"));
- ASSERT_TRUE(HasTextAt(PC, 2, " bbb"));
- }
- }
- TEST_F(CommentParserTest, InlineCommand5) {
- const char *Source = "// \\unknown aaa\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- InlineCommandComment *ICC;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 3));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasInlineCommandAt(PC, Traits, 1, ICC, "unknown", NoArgs()));
- ASSERT_TRUE(HasTextAt(PC, 2, " aaa"));
- }
- }
- TEST_F(CommentParserTest, HTML1) {
- const char *Sources[] = {
- "// <a",
- "// <a>",
- "// <a >"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLStartTagComment *HST;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", NoAttrs()));
- }
- }
- }
- TEST_F(CommentParserTest, HTML2) {
- const char *Sources[] = {
- "// <br/>",
- "// <br />"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLStartTagComment *HST;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "br", SelfClosing()));
- }
- }
- }
- TEST_F(CommentParserTest, HTML3) {
- const char *Sources[] = {
- "// <a href",
- "// <a href ",
- "// <a href>",
- "// <a href >",
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLStartTagComment *HST;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", ""));
- }
- }
- }
- TEST_F(CommentParserTest, HTML4) {
- const char *Sources[] = {
- "// <a href=\"bbb\"",
- "// <a href=\"bbb\">",
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLStartTagComment *HST;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "a", "href", "bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, HTML5) {
- const char *Sources[] = {
- "// </a",
- "// </a>",
- "// </a >"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLEndTagComment *HET;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 2));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLEndTagAt(PC, 1, HET, "a"));
- }
- }
- }
- TEST_F(CommentParserTest, HTML6) {
- const char *Source =
- "// <pre>\n"
- "// Aaa\n"
- "// Bbb\n"
- "// </pre>\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- ParagraphComment *PC;
- HTMLStartTagComment *HST;
- HTMLEndTagComment *HET;
- ASSERT_TRUE(GetChildAt(FC, 0, PC));
- ASSERT_TRUE(HasChildCount(PC, 6));
- ASSERT_TRUE(HasTextAt(PC, 0, " "));
- ASSERT_TRUE(HasHTMLStartTagAt(PC, 1, HST, "pre", NoAttrs()));
- ASSERT_TRUE(HasTextWithNewlineAt(PC, 2, " Aaa"));
- ASSERT_TRUE(HasTextWithNewlineAt(PC, 3, " Bbb"));
- ASSERT_TRUE(HasTextAt(PC, 4, " "));
- ASSERT_TRUE(HasHTMLEndTagAt(PC, 5, HET, "pre"));
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock1) {
- const char *Source = "// \\verbatim\\endverbatim\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VCC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VCC,
- "verbatim", "endverbatim",
- NoLines()));
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock2) {
- const char *Source = "// \\verbatim Aaa \\endverbatim\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
- "verbatim", "endverbatim",
- Lines(), " Aaa "));
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock3) {
- const char *Source = "// \\verbatim Aaa\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC, "verbatim", "",
- Lines(), " Aaa"));
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock4) {
- const char *Source =
- "//\\verbatim\n"
- "//\\endverbatim\n";
- FullComment *FC = parseString(Source);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
- "verbatim", "endverbatim",
- NoLines()));
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock5) {
- const char *Sources[] = {
- "//\\verbatim\n"
- "// Aaa\n"
- "//\\endverbatim\n",
- "/*\\verbatim\n"
- " * Aaa\n"
- " *\\endverbatim*/"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 1));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 0, VBC,
- "verbatim", "endverbatim",
- Lines(), " Aaa"));
- }
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock6) {
- const char *Sources[] = {
- "// \\verbatim\n"
- "// Aaa\n"
- "// \\endverbatim\n",
- "/* \\verbatim\n"
- " * Aaa\n"
- " * \\endverbatim*/"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
- "verbatim", "endverbatim",
- Lines(), " Aaa"));
- }
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock7) {
- const char *Sources[] = {
- "// \\verbatim\n"
- "// Aaa\n"
- "// Bbb\n"
- "// \\endverbatim\n",
- "/* \\verbatim\n"
- " * Aaa\n"
- " * Bbb\n"
- " * \\endverbatim*/"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
- "verbatim", "endverbatim",
- Lines(), " Aaa", " Bbb"));
- }
- }
- }
- TEST_F(CommentParserTest, VerbatimBlock8) {
- const char *Sources[] = {
- "// \\verbatim\n"
- "// Aaa\n"
- "//\n"
- "// Bbb\n"
- "// \\endverbatim\n",
- "/* \\verbatim\n"
- " * Aaa\n"
- " *\n"
- " * Bbb\n"
- " * \\endverbatim*/"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimBlockComment *VBC;
- ASSERT_TRUE(HasVerbatimBlockAt(FC, Traits, 1, VBC,
- "verbatim", "endverbatim"));
- ASSERT_EQ(3U, VBC->getNumLines());
- ASSERT_EQ(" Aaa", VBC->getText(0));
- ASSERT_EQ("", VBC->getText(1));
- ASSERT_EQ(" Bbb", VBC->getText(2));
- }
- }
- }
- TEST_F(CommentParserTest, VerbatimLine1) {
- const char *Sources[] = {
- "// \\fn",
- "// \\fn\n"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimLineComment *VLC;
- ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn", ""));
- }
- }
- }
- TEST_F(CommentParserTest, VerbatimLine2) {
- const char *Sources[] = {
- "/// \\fn void *foo(const char *zzz = \"\\$\");\n//",
- "/** \\fn void *foo(const char *zzz = \"\\$\");*/"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- VerbatimLineComment *VLC;
- ASSERT_TRUE(HasVerbatimLineAt(FC, Traits, 1, VLC, "fn",
- " void *foo(const char *zzz = \"\\$\");"));
- }
- }
- }
- TEST_F(CommentParserTest, Deprecated) {
- const char *Sources[] = {
- "/** @deprecated*/",
- "/// @deprecated\n"
- };
- for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) {
- FullComment *FC = parseString(Sources[i]);
- ASSERT_TRUE(HasChildCount(FC, 2));
- ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
- {
- BlockCommandComment *BCC;
- ParagraphComment *PC;
- ASSERT_TRUE(HasBlockCommandAt(FC, Traits, 1, BCC, "deprecated", PC));
- ASSERT_TRUE(HasChildCount(PC, 0));
- }
- }
- }
- } // unnamed namespace
- } // end namespace comments
- } // end namespace clang
|