14 #include "clang/AST/RecursiveASTVisitor.h" 15 #include "gmock/gmock.h" 16 #include "gtest/gtest-param-test.h" 17 #include "gtest/gtest.h" 23 using ::testing::ElementsAreArray;
29 class ASTUtils :
public ::testing::Test,
30 public ::testing::WithParamInterface<Case> {};
32 TEST_P(ASTUtils, PrintTemplateArgs) {
33 auto Pair = GetParam();
34 Annotations Test(Pair.AnnotatedCode);
36 struct Visitor : RecursiveASTVisitor<Visitor> {
37 Visitor(std::vector<Position> Points) : Points(std::move(Points)) {}
38 bool VisitNamedDecl(
const NamedDecl *ND) {
39 if (TemplateArgsAtPoints.size() == Points.size())
43 if (
Pos != Points[TemplateArgsAtPoints.size()])
48 std::vector<std::string> TemplateArgsAtPoints;
49 const std::vector<Position> Points;
51 Visitor V(Test.points());
52 V.TraverseDecl(
AST.getASTContext().getTranslationUnitDecl());
53 EXPECT_THAT(V.TemplateArgsAtPoints, ElementsAreArray(Pair.Expected));
56 INSTANTIATE_TEST_CASE_P(ASTUtilsTests, ASTUtils,
57 ::testing::ValuesIn(std::vector<Case>({
60 template <class X> class Bar {}; 61 template <> class ^Bar<double> {};)cpp", 65 template <class X> class Bar {}; 66 template <class T, class U, 67 template<typename> class Z, int Q> 69 template struct ^Foo<int, bool, Bar, 8>; 71 struct ^Foo<T *, T, Bar, 3> {};)cpp", 72 {"<int, bool, Bar, 8>",
"<T *, T, Bar, 3>"}},
75 template <int ...> void Foz() {}; 76 template <> void ^Foz<3, 5, 8>() {};)cpp", 80 template <class X> class Bar {}; 81 template <template <class> class ...> 83 template <> class ^Aux<Bar, Bar> {}; 84 template <template <class> T> 85 class ^Aux<T, T> {};)cpp", 86 {"<Bar, Bar>",
"<T, T>"}},
89 template <typename T> T var = 1234; 90 template <> int ^var<int> = 1;)cpp", 94 template <typename T> struct Foo; 95 struct Bar { friend class Foo<int>; }; 96 template <> struct ^Foo<int> {};)cpp", 105 int ^S<double> = 0;)cpp", 106 {"<T *>",
"<double>"}},
const char * AnnotatedCode
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.
static TestTU withCode(llvm::StringRef Code)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< const char * > Expected