12#include "gmock/gmock.h"
13#include "gtest/gtest.h"
20using ::testing::UnorderedElementsAreArray;
23struct ExpectedSymbolDetails {
25 std::string Container;
27 const char *DeclMarker =
nullptr;
28 const char *DefMarker =
nullptr;
32 std::pair<const char *, std::vector<ExpectedSymbolDetails>>
33 TestInputExpectedOutput[] = {
35 R
"cpp( // Simple function reference - declaration
42 {ExpectedSymbolDetails{"foo",
"",
"c:@F@foo#",
"decl"}}},
44 R
"cpp( // Simple function reference - definition
51 {ExpectedSymbolDetails{"foo",
"",
"c:@F@foo#",
"def",
"def"}}},
53 R
"cpp( // Simple function reference - decl and def
61 {ExpectedSymbolDetails{"foo",
"",
"c:@F@foo#",
"decl",
"def"}}},
63 R
"cpp( // Simple class reference - decl and def
64 @interface $decl[[Foo]]
66 @implementation $def[[Foo]]
68 void doSomething(F^oo *obj) {}
70 {ExpectedSymbolDetails{"Foo",
"",
"c:objc(cs)Foo",
"decl",
73 R
"cpp( // Simple method reference - decl and def
78 - (void)$def[[fo^o]] {}
81 {ExpectedSymbolDetails{"foo",
"Foo::",
"c:objc(cs)Foo(im)foo",
84 R
"cpp( // Function in namespace reference
93 {ExpectedSymbolDetails{"foo",
"bar::",
"c:@N@bar@F@foo#",
96 R
"cpp( // Function in different namespace reference
107 {ExpectedSymbolDetails{"foo",
"bar::",
"c:@N@bar@F@foo#",
110 R
"cpp( // Function in global namespace reference
121 {ExpectedSymbolDetails{"foo",
"",
"c:@F@foo#",
"decl"}}},
123 R
"cpp( // Function in anonymous namespace reference
134 {ExpectedSymbolDetails{"foo",
"(anonymous)",
135 "c:TestTU.cpp@aN@F@foo#",
"decl"}}},
137 R
"cpp( // Function reference - ADL
140 void $decl[[foo]](const BarType&);
150 {ExpectedSymbolDetails{
151 "foo",
"bar::",
"c:@N@bar@F@foo#&1$@N@bar@S@BarType#",
154 R
"cpp( // Global value reference
161 {ExpectedSymbolDetails{"value",
"",
"c:@value",
"def",
"def"}}},
163 R
"cpp( // Local value reference
164 void foo() { int $def[[aaa]]; int bbb = aa^a; }
166 {ExpectedSymbolDetails{"aaa",
"foo",
"c:TestTU.cpp@49@F@foo#@aaa",
169 R
"cpp( // Function param
170 void bar(int $def[[aaa]]) {
174 {ExpectedSymbolDetails{
175 "aaa",
"bar",
"c:TestTU.cpp@38@F@bar#I#@aaa",
"def",
"def"}}},
177 R
"cpp( // Lambda capture
185 {ExpectedSymbolDetails{"ii",
"foo",
"c:TestTU.cpp@54@F@foo#@ii",
188 R
"cpp( // Macro reference
189 #define MACRO 5\nint i = MAC^RO;
191 {ExpectedSymbolDetails{"MACRO",
"",
192 "c:TestTU.cpp@38@macro@MACRO"}}},
194 R
"cpp( // Macro reference
195 #define MACRO 5\nint i = MACRO^;
197 {ExpectedSymbolDetails{"MACRO",
"",
198 "c:TestTU.cpp@38@macro@MACRO"}}},
200 R
"cpp( // Multiple symbols returned - using overloaded function name
201 void $def[[foo]]() {}
202 void $def_bool[[foo]](bool) {}
203 void $def_int[[foo]](int) {}
205 using ::$decl[[fo^o]];
208 {ExpectedSymbolDetails{"foo",
"",
"c:@F@foo#",
"def",
"def"},
209 ExpectedSymbolDetails{
"foo",
"",
"c:@F@foo#b#",
"def_bool",
211 ExpectedSymbolDetails{
"foo",
"",
"c:@F@foo#I#",
"def_int",
213 ExpectedSymbolDetails{
"foo",
"bar::",
"c:@N@bar@UD@foo",
216 R
"cpp( // Multiple symbols returned - implicit conversion
221 void func_baz1(bar) {}
227 {ExpectedSymbolDetails{"ff",
"func_baz2",
228 "c:TestTU.cpp@218@F@func_baz2#@ff",
"def",
231 R
"cpp( // Type reference - declaration
235 {ExpectedSymbolDetails{"foo",
"",
"c:@S@foo",
"decl"}}},
237 R
"cpp( // Type reference - definition
238 struct $def[[foo]] {};
241 {ExpectedSymbolDetails{"foo",
"",
"c:@S@foo",
"def",
"def"}}},
243 R
"cpp( // Type Reference - template argument
244 struct $def[[foo]] {};
245 template<class T> struct bar {};
250 {ExpectedSymbolDetails{"foo",
"",
"c:@S@foo",
"def",
"def"}}},
252 R
"cpp( // Template parameter reference - type param
253 template<class $def[[TT]]> struct bar {
257 {ExpectedSymbolDetails{"TT",
"bar::",
"c:TestTU.cpp@65",
"def",
260 R
"cpp( // Template parameter reference - type param
261 template<int $def[[NN]]> struct bar {
265 {ExpectedSymbolDetails{"NN",
"bar::",
"c:TestTU.cpp@65",
"def",
268 R
"cpp( // Class member reference - objec
277 {ExpectedSymbolDetails{"aa",
"foo::",
"c:@S@foo@FI@aa",
"def",
280 R
"cpp( // Class member reference - pointer
288 {ExpectedSymbolDetails{"aa",
"foo::",
"c:@S@foo@FI@aa",
"def",
291 R
"cpp( // Class method reference - objec
300 {ExpectedSymbolDetails{"aa",
"foo::",
"c:@S@foo@F@aa#",
"def",
303 R
"cpp( // Class method reference - pointer
311 {ExpectedSymbolDetails{"aa",
"foo::",
"c:@S@foo@F@aa#",
"def",
315 typedef int $decl[[foo]];
320 {ExpectedSymbolDetails{"foo",
"",
"c:TestTU.cpp@T@foo",
"decl"}}},
323 using $decl[[foo]] = int;
328 {ExpectedSymbolDetails{"foo",
"",
"c:@foo",
"decl"}}},
330 R
"cpp( // Namespace reference
331 namespace $decl[[foo]] {}
332 using namespace fo^o;
334 {ExpectedSymbolDetails{"foo",
"",
"c:@N@foo",
"decl"}}},
336 R
"cpp( // Enum value reference
337 enum foo { $def[[bar]], baz };
342 {ExpectedSymbolDetails{"bar",
"foo",
"c:@E@foo@bar",
"def",
345 R
"cpp( // Enum class value reference
346 enum class foo { $def[[bar]], baz };
351 {ExpectedSymbolDetails{"bar",
"foo::",
"c:@E@foo@bar",
"def",
354 R
"cpp( // Parameters in declarations
355 void foo(int $def[[ba^r]]);
357 {ExpectedSymbolDetails{
358 "bar",
"foo",
"c:TestTU.cpp@50@F@foo#I#@bar",
"def",
"def"}}},
360 R
"cpp( // Type inference with auto keyword
362 foo getfoo() { return foo{}; }
379 for (
const auto &T : TestInputExpectedOutput) {
382 TU.
Code = std::string(TestInput.code());
383 TU.ExtraArgs.push_back(
"-xobjective-c++");
384 auto AST = TU.build();
386 std::vector<SymbolDetails> Expected;
387 for (
const auto &Sym :
T.second) {
388 std::optional<Location> Decl, Def;
391 TestInput.range(Sym.DeclMarker)};
394 TestInput.range(Sym.DefMarker)};
396 {Sym.Name, Sym.Container, Sym.USR,
SymbolID(Sym.USR), Decl, Def});
400 UnorderedElementsAreArray(Expected))
Same as llvm::Annotations, but adjusts functions to LSP-specific types for positions and ranges.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
std::vector< SymbolDetails > getSymbolInfo(ParsedAST &AST, Position Pos)
Get info about symbols at Pos.
std::string testPath(PathRef File, llvm::sys::path::Style Style)
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static URIForFile canonicalize(llvm::StringRef AbsPath, llvm::StringRef TUPath)
Canonicalizes AbsPath via URI.