aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r--clang/unittests/Lex/LexerTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index 319c63f..df22e77 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -23,6 +23,8 @@
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
@@ -632,4 +634,27 @@ TEST_F(LexerTest, CreatedFIDCountForPredefinedBuffer) {
EXPECT_EQ(SourceMgr.getNumCreatedFIDsForFileID(PP->getPredefinesFileID()),
1U);
}
+
+TEST_F(LexerTest, RawAndNormalLexSameForLineComments) {
+ const llvm::StringLiteral Source = R"cpp(
+ // First line comment.
+ //* Second line comment which is ambigious.
+ )cpp";
+ LangOpts.LineComment = false;
+ auto Toks = Lex(Source);
+ auto &SM = PP->getSourceManager();
+ auto SrcBuffer = SM.getBufferData(SM.getMainFileID());
+ Lexer L(SM.getLocForStartOfFile(SM.getMainFileID()), PP->getLangOpts(),
+ SrcBuffer.data(), SrcBuffer.data(),
+ SrcBuffer.data() + SrcBuffer.size());
+
+ auto ToksView = llvm::makeArrayRef(Toks);
+ clang::Token T;
+ while (!L.LexFromRawLexer(T)) {
+ ASSERT_TRUE(!ToksView.empty());
+ EXPECT_EQ(T.getKind(), ToksView.front().getKind());
+ ToksView = ToksView.drop_front();
+ }
+ EXPECT_TRUE(ToksView.empty());
+}
} // anonymous namespace