diff options
Diffstat (limited to 'clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp')
| -rw-r--r-- | clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp index 2ce20e6a8aa..39652ce6a4c 100644 --- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp +++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp @@ -9,7 +9,6 @@ #include "index/SymbolCollector.h" #include "index/SymbolYAML.h" -#include "clang/Index/IndexingAction.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/VirtualFileSystem.h" @@ -26,12 +25,24 @@ #include <memory> #include <string> +using testing::AllOf; using testing::Eq; using testing::Field; +using testing::Not; using testing::UnorderedElementsAre; using testing::UnorderedElementsAreArray; // GMock helpers for matching Symbol. +MATCHER_P(Labeled, Label, "") { return arg.CompletionLabel == Label; } +MATCHER(HasDetail, "") { return arg.Detail; } +MATCHER_P(Detail, D, "") { + return arg.Detail && arg.Detail->CompletionDetail == D; +} +MATCHER_P(Doc, D, "") { return arg.Detail && arg.Detail->Documentation == D; } +MATCHER_P(Plain, Text, "") { return arg.CompletionPlainInsertText == Text; } +MATCHER_P(Snippet, S, "") { + return arg.CompletionSnippetInsertText == S; +} MATCHER_P(QName, Name, "") { return (arg.Scope + (arg.Scope.empty() ? "" : "::") + arg.Name).str() == Name; } @@ -147,6 +158,38 @@ TEST_F(SymbolCollectorTest, CollectSymbol) { QName("foo::baz")})); } +TEST_F(SymbolCollectorTest, SymbolWithDocumentation) { + const std::string Main = R"( + namespace nx { + /// Foo comment. + int ff(int x, double y) { return 0; } + } + )"; + runSymbolCollector(/*Header=*/"", Main); + EXPECT_THAT(Symbols, + UnorderedElementsAre(QName("nx"), + AllOf(QName("nx::ff"), + Labeled("ff(int x, double y)"), + Detail("int"), Doc("Foo comment.")))); +} + +TEST_F(SymbolCollectorTest, PlainAndSnippet) { + const std::string Main = R"( + namespace nx { + void f() {} + int ff(int x, double y) { return 0; } + } + )"; + runSymbolCollector(/*Header=*/"", Main); + EXPECT_THAT( + Symbols, + UnorderedElementsAre( + QName("nx"), + AllOf(QName("nx::f"), Labeled("f()"), Plain("f"), Snippet("f()")), + AllOf(QName("nx::ff"), Labeled("ff(int x, double y)"), Plain("ff"), + Snippet("ff(${1:int x}, ${2:double y})")))); +} + TEST_F(SymbolCollectorTest, YAMLConversions) { const std::string YAML1 = R"( --- @@ -160,6 +203,12 @@ CanonicalDeclaration: StartOffset: 0 EndOffset: 1 FilePath: /path/foo.h +CompletionLabel: 'Foo1-label' +CompletionFilterText: 'filter' +CompletionPlainInsertText: 'plain' +Detail: + Documentation: 'Foo doc' + CompletionDetail: 'int' ... )"; const std::string YAML2 = R"( @@ -174,15 +223,21 @@ CanonicalDeclaration: StartOffset: 10 EndOffset: 12 FilePath: /path/foo.h +CompletionLabel: 'Foo2-label' +CompletionFilterText: 'filter' +CompletionPlainInsertText: 'plain' +CompletionSnippetInsertText: 'snippet' ... )"; auto Symbols1 = SymbolFromYAML(YAML1); - EXPECT_THAT(Symbols1, - UnorderedElementsAre(QName("clang::Foo1"))); + EXPECT_THAT(Symbols1, UnorderedElementsAre( + AllOf(QName("clang::Foo1"), Labeled("Foo1-label"), + Doc("Foo doc"), Detail("int")))); auto Symbols2 = SymbolFromYAML(YAML2); - EXPECT_THAT(Symbols2, - UnorderedElementsAre(QName("clang::Foo2"))); + EXPECT_THAT(Symbols2, UnorderedElementsAre(AllOf(QName("clang::Foo2"), + Labeled("Foo2-label"), + Not(HasDetail())))); std::string ConcatenatedYAML = SymbolsToYAML(Symbols1) + SymbolsToYAML(Symbols2); |

