14 #include "clang/Basic/SourceLocation.h" 15 #include "llvm/Support/ScopedPrinter.h" 16 #include "gmock/gmock.h" 17 #include "gtest/gtest.h" 23 using testing::UnorderedElementsAreArray;
25 TEST(CollectMainFileMacros, SelectedMacros) {
30 const char *Tests[] = {
31 R
"cpp(// Macros: Cursor on definition. 32 #define $1[[FOO]](x,y) (x + y) 33 int main() { int x = $1[[FOO]]($1[[FOO]](3, 4), $1[[FOO]](5, 6)); } 38 int s = $1[[M]]($2[[abc]]); 52 #ifdef $Unknown[[UNDEFINED]] 56 #ifndef $Unknown[[abc]] 63 // Macros from token concatenations not included. 64 #define $1[[CONCAT]](X) X##A() 65 #define $2[[PREPEND]](X) MACRO##X() 66 #define $3[[MACROA]]() 123 67 int B = $1[[CONCAT]](MACRO); 68 int D = $2[[PREPEND]](A) 71 // FIXME: Macro names in a definition are not detected. 72 #define $1[[MACRO_ARGS2]](X, Y) X Y 77 for (
const char *Test : Tests) {
85 for (
int I = 1;; I++) {
86 const auto ExpectedRefs = T.ranges(llvm::to_string(I));
87 if (ExpectedRefs.empty())
94 auto SID =
getSymbolID(Macro->Name, Macro->Info, SM);
96 EXPECT_THAT(ExpectedRefs,
97 UnorderedElementsAreArray(ActualMacroRefs.MacroRefs[*SID]))
98 <<
"Annotation=" << I <<
", MacroName=" << Macro->Name
99 <<
", Test = " << Test;
103 UnorderedElementsAreArray(T.ranges(
"Unknown")))
104 <<
"Unknown macros doesn't match in " << Test;
SourceLocation Loc
'#' location in the include directive
const LangOptions & getLangOpts() const
llvm::Optional< SymbolID > getSymbolID(const Decl *D)
Gets the symbol ID for a declaration, if possible.
Preprocessor & getPreprocessor()
SourceLocation getBeginningOfIdentifier(const Position &Pos, const SourceManager &SM, const LangOptions &LangOpts)
Get the beginning SourceLocation at a specified Pos in the main file.
std::vector< Range > UnknownMacros
TEST(BackgroundQueueTest, Priority)
static TestTU withCode(llvm::StringRef Code)
SourceManager & getSourceManager()
const MainFileMacros & getMacros() const
Gets all macro references (definition, expansions) present in the main file, including those in the p...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< DefinedMacro > locateMacroAt(SourceLocation Loc, Preprocessor &PP)
Gets the macro at a specified Loc.