1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447 |
- //===- unittests/AST/CommentParser.cpp ------ Comment parser tests --------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is distributed under the University of Illinois Open Source
- // License. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #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"
- #include <vector>
- using namespace llvm;
- using namespace clang;
- namespace clang {
- namespace comments {
- namespace {
- const bool 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 (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
|