summaryrefslogtreecommitdiffstats
path: root/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Lex/LexerTest.cpp')
-rw-r--r--unittests/Lex/LexerTest.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp
index c913062a7a..7b14f56201 100644
--- a/unittests/Lex/LexerTest.cpp
+++ b/unittests/Lex/LexerTest.cpp
@@ -1,9 +1,8 @@
//===- unittests/Lex/LexerTest.cpp ------ Lexer tests ---------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
@@ -12,7 +11,6 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/MemoryBufferCache.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
@@ -49,12 +47,11 @@ protected:
llvm::MemoryBuffer::getMemBuffer(Source);
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
- MemoryBufferCache PCMCache;
HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr,
Diags, LangOpts, Target.get());
std::unique_ptr<Preprocessor> PP = llvm::make_unique<Preprocessor>(
std::make_shared<PreprocessorOptions>(), Diags, LangOpts, SourceMgr,
- PCMCache, HeaderInfo, ModLoader,
+ HeaderInfo, ModLoader,
/*IILookup =*/nullptr,
/*OwnsHeaderSearch =*/false);
PP->Initialize(*Target);
@@ -516,4 +513,23 @@ TEST_F(LexerTest, StringizingRasString) {
EXPECT_EQ(String6, R"(a\\\n\n\n \\\\b)");
}
+TEST_F(LexerTest, CharRangeOffByOne) {
+ std::vector<Token> toks = Lex(R"(#define MOO 1
+ void foo() { MOO; })");
+ const Token &moo = toks[5];
+
+ EXPECT_EQ(getSourceText(moo, moo), "MOO");
+
+ SourceRange R{moo.getLocation(), moo.getLocation()};
+
+ EXPECT_TRUE(
+ Lexer::isAtStartOfMacroExpansion(R.getBegin(), SourceMgr, LangOpts));
+ EXPECT_TRUE(
+ Lexer::isAtEndOfMacroExpansion(R.getEnd(), SourceMgr, LangOpts));
+
+ CharSourceRange CR = Lexer::getAsCharRange(R, SourceMgr, LangOpts);
+
+ EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
+}
+
} // anonymous namespace