14 #include "clang/AST/Decl.h"
15 #include "clang/AST/DeclBase.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Casting.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
29 TEST(GetDeducedType, KwAutoExpansion) {
34 {
"^auto i = 0;",
"int"},
35 {
"^auto f(){ return 1;};",
"int"},
37 for (Test T : Tests) {
38 Annotations File(T.AnnotatedCode);
40 SourceManagerForFile SM(
"foo.cpp", File.code());
42 for (Position
Pos : File.points()) {
46 EXPECT_EQ(
DeducedType->getAsString(), T.DeducedType);
51 TEST(ClangdAST, GetQualification) {
59 std::vector<llvm::StringRef> Qualifications;
60 std::vector<std::string> VisibleNamespaces;
64 namespace ns1 { namespace ns2 { class Foo {}; } }
65 void insert(); // ns1::ns2::Foo
67 void insert(); // ns2::Foo
75 void insert(); // ns2::Foo
79 {"ns1::ns2::",
"ns2::",
"",
"",
"ns2::",
""},
84 namespace ns1 { namespace ns2 { class Bar { void Foo(); }; } }
85 void insert(); // ns1::ns2::Bar::Foo
87 void insert(); // ns2::Bar::Foo
89 void insert(); // Bar::Foo
92 void insert(); // Bar::Foo
95 void insert(); // ns2::Bar::Foo
97 void insert(); // Bar::Foo
99 {"ns1::ns2::Bar::",
"ns2::Bar::",
"Bar::",
"Bar::",
"ns2::Bar::",
105 namespace ns1 { namespace ns2 { void Foo(); } }
106 void insert(); // ns2::Foo
108 void insert(); // ns2::Foo
110 void insert(); // Foo
114 {"ns2::",
"ns2::",
""},
118 for (
const auto &Case : Cases) {
119 Annotations Test(Case.Test);
121 ParsedAST AST = TU.
build();
122 std::vector<const Decl *> InsertionPoints;
123 const NamedDecl *TargetDecl;
124 findDecl(AST, [&](
const NamedDecl &ND) {
125 if (ND.getNameAsString() ==
"Foo") {
130 if (ND.getNameAsString() ==
"insert")
131 InsertionPoints.push_back(&ND);
135 ASSERT_EQ(InsertionPoints.size(), Case.Qualifications.size());
136 for (
size_t I = 0,
E = InsertionPoints.size(); I !=
E; ++I) {
137 const Decl *D = InsertionPoints[I];
138 if (Case.VisibleNamespaces.empty()) {
140 D->getLexicalDeclContext(), D->getBeginLoc(),
142 Case.Qualifications[I]);
145 D->getLexicalDeclContext(), TargetDecl,
146 Case.VisibleNamespaces),
147 Case.Qualifications[I]);
153 TEST(ClangdAST, PrintType) {
155 llvm::StringRef Test;
156 std::vector<llvm::StringRef> Types;
160 namespace ns1 { namespace ns2 { class Foo {}; } }
161 void insert(); // ns1::ns2::Foo
163 void insert(); // ns2::Foo
165 void insert(); // Foo
169 {"ns1::ns2::Foo",
"ns2::Foo",
"Foo"},
176 void insert(); // ns1::Foo
178 void insert(); // Foo
184 for (
const auto &Case : Cases) {
185 Annotations Test(Case.Test);
187 ParsedAST AST = TU.
build();
188 std::vector<const DeclContext *> InsertionPoints;
189 const TypeDecl *TargetDecl =
nullptr;
190 findDecl(AST, [&](
const NamedDecl &ND) {
191 if (ND.getNameAsString() ==
"Foo") {
192 if (
const auto *TD = llvm::dyn_cast<TypeDecl>(&ND)) {
196 }
else if (ND.getNameAsString() ==
"insert")
197 InsertionPoints.push_back(ND.getDeclContext());
201 ASSERT_EQ(InsertionPoints.size(), Case.Types.size());
202 for (
size_t I = 0,
E = InsertionPoints.size(); I !=
E; ++I) {
203 const auto *DC = InsertionPoints[I];