diff options
| author | Nathan Ridge <zeratul976@hotmail.com> | 2019-06-15 02:26:47 +0000 |
|---|---|---|
| committer | Nathan Ridge <zeratul976@hotmail.com> | 2019-06-15 02:26:47 +0000 |
| commit | f1e6f5713caac5da97dcde34a7042061bb0e6afa (patch) | |
| tree | 3749a6a8cc46c27e65c31811fd870f2c3f9056f8 /clang-tools-extra/clangd/unittests/FileIndexTests.cpp | |
| parent | 0b1ea8cb2825cb51c1c2f6dfa9bef95f4a450f93 (diff) | |
| download | bcm5719-llvm-f1e6f5713caac5da97dcde34a7042061bb0e6afa.tar.gz bcm5719-llvm-f1e6f5713caac5da97dcde34a7042061bb0e6afa.zip | |
[clangd] Index API and implementations for relations
Summary:
This builds on the relations support added in D59407, D62459,
and D62471 to expose relations in SymbolIndex and its
implementations.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62839
llvm-svn: 363481
Diffstat (limited to 'clang-tools-extra/clangd/unittests/FileIndexTests.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/unittests/FileIndexTests.cpp | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp index 781f5313fbf..f37b73ff4c8 100644 --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -82,7 +82,8 @@ TEST(FileSymbolsTest, UpdateAndGet) { FileSymbols FS; EXPECT_THAT(runFuzzyFind(*FS.buildIndex(IndexType::Light), ""), IsEmpty()); - FS.update("f1", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cc"), false); + FS.update("f1", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cc"), nullptr, + false); EXPECT_THAT(runFuzzyFind(*FS.buildIndex(IndexType::Light), ""), UnorderedElementsAre(QName("1"), QName("2"), QName("3"))); EXPECT_THAT(getRefs(*FS.buildIndex(IndexType::Light), SymbolID("1")), @@ -91,8 +92,8 @@ TEST(FileSymbolsTest, UpdateAndGet) { TEST(FileSymbolsTest, Overlap) { FileSymbols FS; - FS.update("f1", numSlab(1, 3), nullptr, false); - FS.update("f2", numSlab(3, 5), nullptr, false); + FS.update("f1", numSlab(1, 3), nullptr, nullptr, false); + FS.update("f2", numSlab(3, 5), nullptr, nullptr, false); for (auto Type : {IndexType::Light, IndexType::Heavy}) EXPECT_THAT(runFuzzyFind(*FS.buildIndex(Type), ""), UnorderedElementsAre(QName("1"), QName("2"), QName("3"), @@ -111,8 +112,8 @@ TEST(FileSymbolsTest, MergeOverlap) { auto X2 = symbol("x"); X2.Definition.FileURI = "file:///x2"; - FS.update("f1", OneSymboSlab(X1), nullptr, false); - FS.update("f2", OneSymboSlab(X2), nullptr, false); + FS.update("f1", OneSymboSlab(X1), nullptr, nullptr, false); + FS.update("f2", OneSymboSlab(X2), nullptr, nullptr, false); for (auto Type : {IndexType::Light, IndexType::Heavy}) EXPECT_THAT( runFuzzyFind(*FS.buildIndex(Type, DuplicateHandling::Merge), "x"), @@ -124,14 +125,14 @@ TEST(FileSymbolsTest, SnapshotAliveAfterRemove) { FileSymbols FS; SymbolID ID("1"); - FS.update("f1", numSlab(1, 3), refSlab(ID, "f1.cc"), false); + FS.update("f1", numSlab(1, 3), refSlab(ID, "f1.cc"), nullptr, false); auto Symbols = FS.buildIndex(IndexType::Light); EXPECT_THAT(runFuzzyFind(*Symbols, ""), UnorderedElementsAre(QName("1"), QName("2"), QName("3"))); EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")})); - FS.update("f1", nullptr, nullptr, false); + FS.update("f1", nullptr, nullptr, nullptr, false); auto Empty = FS.buildIndex(IndexType::Light); EXPECT_THAT(runFuzzyFind(*Empty, ""), IsEmpty()); EXPECT_THAT(getRefs(*Empty, ID), ElementsAre()); @@ -347,6 +348,24 @@ TEST(FileIndexTest, CollectMacros) { EXPECT_THAT(runFuzzyFind(M, ""), Contains(QName("CLANGD"))); } +TEST(FileIndexTest, Relations) { + TestTU TU; + TU.Filename = "f.cpp"; + TU.HeaderFilename = "f.h"; + TU.HeaderCode = "class A {}; class B : public A {};"; + auto AST = TU.build(); + FileIndex Index; + Index.updatePreamble(TU.Filename, AST.getASTContext(), + AST.getPreprocessorPtr(), AST.getCanonicalIncludes()); + SymbolID A = findSymbol(TU.headerSymbols(), "A").ID; + uint32_t Results = 0; + RelationsRequest Req; + Req.Subjects.insert(A); + Req.Predicate = index::SymbolRole::RelationBaseOf; + Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; }); + EXPECT_EQ(Results, 1u); +} + TEST(FileIndexTest, ReferencesInMainFileWithPreamble) { TestTU TU; TU.HeaderCode = "class Foo{};"; @@ -369,8 +388,8 @@ TEST(FileIndexTest, ReferencesInMainFileWithPreamble) { TEST(FileSymbolsTest, CountReferencesNoRefSlabs) { FileSymbols FS; - FS.update("f1", numSlab(1, 3), nullptr, true); - FS.update("f2", numSlab(1, 3), nullptr, false); + FS.update("f1", numSlab(1, 3), nullptr, nullptr, true); + FS.update("f2", numSlab(1, 3), nullptr, nullptr, false); EXPECT_THAT( runFuzzyFind(*FS.buildIndex(IndexType::Light, DuplicateHandling::Merge), ""), @@ -381,12 +400,18 @@ TEST(FileSymbolsTest, CountReferencesNoRefSlabs) { TEST(FileSymbolsTest, CountReferencesWithRefSlabs) { FileSymbols FS; - FS.update("f1cpp", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cpp"), true); - FS.update("f1h", numSlab(1, 3), refSlab(SymbolID("1"), "f1.h"), false); - FS.update("f2cpp", numSlab(1, 3), refSlab(SymbolID("2"), "f2.cpp"), true); - FS.update("f2h", numSlab(1, 3), refSlab(SymbolID("2"), "f2.h"), false); - FS.update("f3cpp", numSlab(1, 3), refSlab(SymbolID("3"), "f3.cpp"), true); - FS.update("f3h", numSlab(1, 3), refSlab(SymbolID("3"), "f3.h"), false); + FS.update("f1cpp", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cpp"), nullptr, + true); + FS.update("f1h", numSlab(1, 3), refSlab(SymbolID("1"), "f1.h"), nullptr, + false); + FS.update("f2cpp", numSlab(1, 3), refSlab(SymbolID("2"), "f2.cpp"), nullptr, + true); + FS.update("f2h", numSlab(1, 3), refSlab(SymbolID("2"), "f2.h"), nullptr, + false); + FS.update("f3cpp", numSlab(1, 3), refSlab(SymbolID("3"), "f3.cpp"), nullptr, + true); + FS.update("f3h", numSlab(1, 3), refSlab(SymbolID("3"), "f3.h"), nullptr, + false); EXPECT_THAT( runFuzzyFind(*FS.buildIndex(IndexType::Light, DuplicateHandling::Merge), ""), |

