| 1 |
//===- unittests/AST/QualTypeNamesTest.cpp --------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file contains tests for helpers from QualTypeNames.h. |
| 10 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 13 |
#include "clang/AST/QualTypeNames.h" |
| 14 |
#include "ASTPrint.h" |
| 15 |
#include "clang/AST/ASTContext.h" |
| 16 |
#include "clang/AST/Decl.h" |
| 17 |
#include "clang/AST/DeclarationName.h" |
| 18 |
#include "clang/AST/TypeBase.h" |
| 19 |
#include "clang/Tooling/Tooling.h" |
| 20 |
#include "llvm/ADT/StringRef.h" |
| 21 |
#include "llvm/Support/Casting.h" |
| 22 |
#include "gtest/gtest.h" |
| 23 |
|
| 24 |
namespace clang { |
| 25 |
namespace { |
| 26 |
|
| 27 |
TEST(QualTypeNamesTest, TemplateParameters) { |
| 28 |
constexpr llvm::StringLiteral Code = R"cpp( |
| 29 |
template <template<class> class T> struct Foo { |
| 30 |
using type_of_interest = T<int>; |
| 31 |
}; |
| 32 |
)cpp"; |
| 33 |
auto AST = tooling::buildASTFromCode(Code); |
| 34 |
ASSERT_NE(AST, nullptr); |
| 35 |
|
| 36 |
auto &Ctx = AST->getASTContext(); |
| 37 |
auto FooLR = Ctx.getTranslationUnitDecl()->lookup( |
| 38 |
DeclarationName(AST->getPreprocessor().getIdentifierInfo("Foo"))); |
| 39 |
ASSERT_TRUE(FooLR.isSingleResult()); |
| 40 |
|
| 41 |
auto TypeLR = |
| 42 |
llvm::cast<ClassTemplateDecl>(FooLR.front()) |
| 43 |
->getTemplatedDecl() |
| 44 |
->lookup(DeclarationName( |
| 45 |
AST->getPreprocessor().getIdentifierInfo("type_of_interest"))); |
| 46 |
ASSERT_TRUE(TypeLR.isSingleResult()); |
| 47 |
|
| 48 |
auto Type = cast<TypeAliasDecl>(TypeLR.front())->getUnderlyingType(); |
| 49 |
ASSERT_TRUE(isa<TemplateSpecializationType>(Type)); |
| 50 |
|
| 51 |
EXPECT_EQ(TypeName::getFullyQualifiedName(Type, Ctx, Ctx.getPrintingPolicy()), |
| 52 |
"T<int>"); |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace |
| 56 |
} // namespace clang |