//===- unittests/AST/CommentLexer.cpp ------ Comment lexer 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/CommentLexer.h"
#include "llvm/ADT/STLExtras.h"
#include <vector>
#include "gtest/gtest.h"
using namespace llvm;
using namespace clang;
namespace clang {
namespace comments {
namespace {
class CommentLexerTest : public ::testing::Test {
protected:
CommentLexerTest()
: FileMgr(FileMgrOpts),
DiagID(new DiagnosticIDs()),
Diags(DiagID, new IgnoringDiagConsumer()),
SourceMgr(Diags, FileMgr) {
}
FileSystemOptions FileMgrOpts;
FileManager FileMgr;
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
DiagnosticsEngine Diags;
SourceManager SourceMgr;
void lexString(const char *Source, std::vector<Token> &Toks);
};
void CommentLexerTest::lexString(const char *Source,
std::vector<Token> &Toks) {
MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
comments::Lexer L(Begin, CommentOptions(),
Source, Source + strlen(Source));
while (1) {
Token Tok;
L.lex(Tok);
if (Tok.is(tok::eof))
break;
Toks.push_back(Tok);
}
}
} // unnamed namespace
// Empty source range should be handled.
TEST_F(CommentLexerTest, Basic1) {
const char *Source = "";
std::vector<Token> Toks;
lexString(Source, Toks);
ASSERT_EQ(0U, Toks.size());
}
// Empty comments should be handled.
TEST_F(CommentLexerTest, Basic2) {
const char *Sources[] = {
"//", "///", "//!", "///<", "//!<"
};
for (size_t i = 0, e