//===- 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/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/AST/Comment.h"
#include "clang/AST/CommentLexer.h"
#include "clang/AST/CommentParser.h"
#include "clang/AST/CommentSema.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Allocator.h"
#include <vector>
#include "gtest/gtest.h"
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 IgnoringDiagConsumer()),
SourceMgr(Diags, FileMgr) {
}
FileSystemOptions FileMgrOpts;
FileManager FileMgr;
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
DiagnosticsEngine Diags;
SourceManager SourceMgr;
llvm::BumpPtrAllocator Allocator;
FullComment *parseString(const char *Source);
};
FullComment *CommentParserTest::parseString(const char *Source) {
MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
comments::Lexer L(Begin, CommentOptions(),
Source, Source + strlen(Source));
comments::Sema S(Allocator, SourceMgr, Diags);
comments::Parser P(L, S, Allocator, SourceMgr, Diags);
comments::FullComment *FC = P.parseFullComment();
if (DEBUG) {
llvm::errs() << "=== Source:\n" << Source << "\n=== AST:\n";
FC->dump(SourceMgr);
}
Token Tok;
L.lex(Tok);
if (Tok.is(tok::eof))
return FC;
else
return NULL;
}
::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