diff options
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r-- | clang/unittests/Lex/LexerTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp index 44ae368..8932265 100644 --- a/clang/unittests/Lex/LexerTest.cpp +++ b/clang/unittests/Lex/LexerTest.cpp @@ -26,9 +26,11 @@ #include "clang/Lex/PreprocessorOptions.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Testing/Annotations/Annotations.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include <memory> +#include <string> #include <vector> namespace { @@ -660,4 +662,36 @@ TEST_F(LexerTest, RawAndNormalLexSameForLineComments) { } EXPECT_TRUE(ToksView.empty()); } + +TEST(LexerPreambleTest, PreambleBounds) { + std::vector<std::string> Cases = { + R"cc([[ + #include <foo> + ]]int bar; + )cc", + R"cc([[ + #include <foo> + ]])cc", + R"cc([[ + // leading comment + #include <foo> + ]]// trailing comment + int bar; + )cc", + R"cc([[ + module; + #include <foo> + ]]module bar; + int x; + )cc", + }; + for (const auto& Case : Cases) { + llvm::Annotations A(Case); + clang::LangOptions LangOpts; + LangOpts.CPlusPlusModules = true; + auto Bounds = Lexer::ComputePreamble(A.code(), LangOpts); + EXPECT_EQ(Bounds.Size, A.range().End) << Case; + } +} + } // anonymous namespace |