summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2019-04-23 21:15:26 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2019-04-23 21:15:26 +0000
commit8c099ce72d480fbff943613c7482992449fafe2d (patch)
tree8267c823a4c59b202a1fba84bf73bd4b39c764f5 /clang/unittests/Lex/LexerTest.cpp
parentfc79ab9857adc96d243cc5ed0a641eef8ef3f253 (diff)
downloadbcm5719-llvm-8c099ce72d480fbff943613c7482992449fafe2d.tar.gz
bcm5719-llvm-8c099ce72d480fbff943613c7482992449fafe2d.zip
Re-apply r357823 "[Lexer] NFC: Fix an off-by-one bug in getAsCharRange()."
It now comes with a follow-up fix for the clients of this API in clangd and clang-tidy. Differential Revision: https://reviews.llvm.org/D59977 llvm-svn: 359035
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r--clang/unittests/Lex/LexerTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index 320b60ea639..7b14f56201e 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -513,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
OpenPOWER on IntegriCloud