diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2017-12-29 14:59:22 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2017-12-29 14:59:22 +0000 |
commit | fb9df48c8557005bc10be1cf48e9294d0693fb3d (patch) | |
tree | 2f85c8cf7b49a39f49d5bb401d99d3b5aa7dc05c /unittests | |
parent | 74e0320e6f7e63cc4dd8de46658eccee52ae75f5 (diff) |
[clangd] Properly set filterText for index-based completion items
It was previously set to an identifier that the user typed, leading to
surprising behavior in VSCode (probably in other editors too).
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@321554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/clangd/CodeCompleteTests.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/unittests/clangd/CodeCompleteTests.cpp b/unittests/clangd/CodeCompleteTests.cpp index e3042c3d..5f852d02 100644 --- a/unittests/clangd/CodeCompleteTests.cpp +++ b/unittests/clangd/CodeCompleteTests.cpp @@ -54,6 +54,7 @@ namespace { using namespace llvm; using ::testing::AllOf; using ::testing::Contains; +using ::testing::Each; using ::testing::ElementsAre; using ::testing::Not; @@ -75,6 +76,11 @@ MATCHER_P(Snippet, Text, "") { return arg.insertTextFormat == clangd::InsertTextFormat::Snippet && arg.insertText == Text; } +MATCHER(FilterContainsName, "") { + if (arg.filterText.empty()) + return true; + return llvm::StringRef(arg.insertText).contains(arg.filterText); +} // Shorthand for Contains(Named(Name)). Matcher<const std::vector<CompletionItem> &> Has(std::string Name) { return Contains(Named(std::move(Name))); @@ -95,9 +101,13 @@ CompletionList completions(StringRef Text, auto File = getVirtualTestFilePath("foo.cpp"); Annotations Test(Text); Server.addDocument(Context::empty(), File, Test.code()); - return Server.codeComplete(Context::empty(), File, Test.point(), Opts) - .get() - .second.Value; + auto CompletionList = + Server.codeComplete(Context::empty(), File, Test.point(), Opts) + .get() + .second.Value; + // Sanity-check that filterText is valid. + EXPECT_THAT(CompletionList.items, Each(FilterContainsName())); + return CompletionList; } TEST(CompletionTest, Limit) { @@ -513,7 +523,7 @@ TEST(CompletionTest, IndexBasedWithFilter) { void f() { ns::x^ } )cpp", Opts); - EXPECT_THAT(Results.items, Contains(AllOf(Named("XYZ"), Filter("x")))); + EXPECT_THAT(Results.items, Contains(AllOf(Named("XYZ"), Filter("XYZ")))); EXPECT_THAT(Results.items, Not(Has("foo"))); } |