14#include "clang/AST/RecursiveASTVisitor.h"
15#include "gmock/gmock.h"
16#include "gtest/gtest.h"
22using ::testing::ElementsAreArray;
28class ASTUtils :
public ::testing::Test,
29 public ::testing::WithParamInterface<Case> {};
31TEST_P(ASTUtils, PrintTemplateArgs) {
32 auto Pair = GetParam();
33 Annotations Test(Pair.AnnotatedCode);
36 Visitor(std::vector<Position> Points) : Points(std::move(Points)) {}
37 bool VisitNamedDecl(
const NamedDecl *ND) {
38 if (TemplateArgsAtPoints.size() == Points.size())
42 if (
Pos != Points[TemplateArgsAtPoints.size()])
47 std::vector<std::string> TemplateArgsAtPoints;
48 const std::vector<Position> Points;
50 Visitor V(Test.points());
51 V.TraverseDecl(
AST.getASTContext().getTranslationUnitDecl());
52 EXPECT_THAT(V.TemplateArgsAtPoints, ElementsAreArray(Pair.Expected));
55INSTANTIATE_TEST_SUITE_P(ASTUtilsTests, ASTUtils,
56 ::testing::ValuesIn(std::vector<Case>({
59 template <class X> class Bar {};
60 template <> class ^Bar<double> {};)cpp",
64 template <class X> class Bar {};
65 template <class T, class U,
66 template<typename> class Z, int Q>
68 template struct ^Foo<int, bool, Bar, 8>;
70 struct ^Foo<T *, T, Bar, 3> {};)cpp",
71 {"<int, bool, Bar, 8>",
"<T *, T, Bar, 3>"}},
74 template <int ...> void Foz() {};
75 template <> void ^Foz<3, 5, 8>() {};)cpp",
79 template <class X> class Bar {};
80 template <template <class> class ...>
82 template <> class ^Aux<Bar, Bar> {};
83 template <template <class> class T>
84 class ^Aux<T, T> {};)cpp",
85 {"<Bar, Bar>",
"<T, T>"}},
88 template <typename T> T var = 1234;
89 template <> int ^var<int> = 1;)cpp",
93 template <typename T> struct Foo;
94 struct Bar { friend class Foo<int>; };
95 template <> struct ^Foo<int> {};)cpp",
104 int ^S<double> = 0;)cpp",
105 {"<T *>",
"<double>"}},
std::string AnnotatedCode
std::vector< const char * > Expected
std::string printTemplateSpecializationArgs(const NamedDecl &ND)
Prints template arguments of a decl as written in the source code, including enclosing '<' and '>',...
Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc)
Turn a SourceLocation into a [line, column] pair.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static TestTU withCode(llvm::StringRef Code)