aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2025-01-16 17:06:05 +0100
committerGitHub <noreply@github.com>2025-01-16 17:06:05 +0100
commit18196466238ff25d5c76906645ba1d92f08bd0f7 (patch)
treece5b5248212a7984a64d5bb86ade91229a834543 /clang/unittests/Lex/LexerTest.cpp
parentf6b0555a433cea1d32a6904c120516cd94b8f3db (diff)
downloadllvm-18196466238ff25d5c76906645ba1d92f08bd0f7.zip
llvm-18196466238ff25d5c76906645ba1d92f08bd0f7.tar.gz
llvm-18196466238ff25d5c76906645ba1d92f08bd0f7.tar.bz2
[clang][refactor] Refactor `findNextTokenIncludingComments` (#123060)
We have two copies of the same code in clang-tidy and clang-reorder-fields, and those are extremenly similar to `Lexer::findNextToken`, so just add an extra agument to the latter. --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r--clang/unittests/Lex/LexerTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index aead7fb..c897998 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -603,6 +603,7 @@ TEST_F(LexerTest, CharRangeOffByOne) {
TEST_F(LexerTest, FindNextToken) {
Lex("int abcd = 0;\n"
+ "// A comment.\n"
"int xyz = abcd;\n");
std::vector<std::string> GeneratedByNextToken;
SourceLocation Loc =
@@ -619,6 +620,26 @@ TEST_F(LexerTest, FindNextToken) {
"xyz", "=", "abcd", ";"));
}
+TEST_F(LexerTest, FindNextTokenIncludingComments) {
+ Lex("int abcd = 0;\n"
+ "// A comment.\n"
+ "int xyz = abcd;\n");
+ std::vector<std::string> GeneratedByNextToken;
+ SourceLocation Loc =
+ SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+ while (true) {
+ auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts, true);
+ ASSERT_TRUE(T);
+ if (T->is(tok::eof))
+ break;
+ GeneratedByNextToken.push_back(getSourceText(*T, *T));
+ Loc = T->getLocation();
+ }
+ EXPECT_THAT(GeneratedByNextToken,
+ ElementsAre("abcd", "=", "0", ";", "// A comment.", "int", "xyz",
+ "=", "abcd", ";"));
+}
+
TEST_F(LexerTest, CreatedFIDCountForPredefinedBuffer) {
TrivialModuleLoader ModLoader;
auto PP = CreatePP("", ModLoader);