14 #include "clang/AST/RecursiveASTVisitor.h" 15 #include "gmock/gmock.h" 16 #include "gtest/gtest-param-test.h" 17 #include "gtest/gtest.h" 18 #include "gtest/internal/gtest-param-util-generated.h" 24 using ::testing::ElementsAreArray;
30 class ASTUtils :
public ::testing::Test,
31 public ::testing::WithParamInterface<Case> {};
33 TEST_P(ASTUtils, PrintTemplateArgs) {
34 auto Pair = GetParam();
35 Annotations Test(Pair.AnnotatedCode);
37 struct Visitor : RecursiveASTVisitor<Visitor> {
38 Visitor(std::vector<Position> Points) : Points(std::move(Points)) {}
39 bool VisitNamedDecl(
const NamedDecl *ND) {
40 if (TemplateArgsAtPoints.size() == Points.size())
44 if (Pos != Points[TemplateArgsAtPoints.size()])
49 std::vector<std::string> TemplateArgsAtPoints;
50 const std::vector<Position> Points;
52 Visitor V(Test.points());
53 V.TraverseDecl(
AST.getASTContext().getTranslationUnitDecl());
54 EXPECT_THAT(V.TemplateArgsAtPoints, ElementsAreArray(Pair.Expected));
57 INSTANTIATE_TEST_CASE_P(ASTUtilsTests, ASTUtils,
58 ::testing::ValuesIn(std::vector<Case>({
61 template <class X> class Bar {}; 62 template <> class ^Bar<double> {};)cpp", 66 template <class X> class Bar {}; 67 template <class T, class U, 68 template<typename> class Z, int Q> 70 template struct ^Foo<int, bool, Bar, 8>; 72 struct ^Foo<T *, T, Bar, 3> {};)cpp", 73 {"<int, bool, Bar, 8>",
"<T *, T, Bar, 3>"}},
76 template <int ...> void Foz() {}; 77 template <> void ^Foz<3, 5, 8>() {};)cpp", 81 template <class X> class Bar {}; 82 template <template <class> class ...> 84 template <> class ^Aux<Bar, Bar> {}; 85 template <template <class> T> 86 class ^Aux<T, T> {};)cpp", 87 {"<Bar, Bar>",
"<T, T>"}},
90 template <typename T> T var = 1234; 91 template <> int ^var<int> = 1;)cpp", 95 template <typename T> struct Foo; 96 struct Bar { friend class Foo<int>; }; 97 template <> struct ^Foo<int> {};)cpp",
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