summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2017-12-20 16:06:05 +0000
committerSam McCall <sam.mccall@gmail.com>2017-12-20 16:06:05 +0000
commit328cbdb9e4be6a2f61cc6017adda8a6ac2f36dab (patch)
treea25504f15a129d602c7952e4503ae140dbd5ad32 /clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
parentb1c9dbdd7da6156cae4f4eced3e43cd20850f631 (diff)
downloadbcm5719-llvm-328cbdb9e4be6a2f61cc6017adda8a6ac2f36dab.tar.gz
bcm5719-llvm-328cbdb9e4be6a2f61cc6017adda8a6ac2f36dab.zip
[clangd] Switch xrefs and documenthighlight to annotated-code unit tests. NFC
Summary: The goal here is again to make it easier to read and write the tests. I've extracted `parseTextMarker` from CodeCompleteTests into an `Annotations` class, adding features to it: - as well as points `^s` it allows ranges `[[...]]` - multiple points and ranges are supported - points and ranges may be named: `$name^` and `$name[[...]]` These features are used for the xrefs tests. This also paves the way for replacing the lit diagnostics.test with more readable unit tests, using named ranges. Alternative considered: `TestSelectionRange` in clang-refactor/TestSupport Main problems were: - delimiting the end of ranges is awkward, requiring counting - comment syntax is long and at least as cryptic for most cases - no separate syntax for point vs range, which keeps xrefs tests concise - Still need to convert to Position everywhere - Still need helpers for common case of expecting exactly one point/range (I'll probably promote the extra `PrintTo`s from some of the core Protocol types into `operator<<` in `Protocol.h` itself in a separate, prior patch...) Reviewers: ioeric Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41432 llvm-svn: 321184
Diffstat (limited to 'clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp55
1 files changed, 18 insertions, 37 deletions
diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
index 312725fc90e..7411e1c3edf 100644
--- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -7,7 +7,9 @@
//
//===----------------------------------------------------------------------===//
+#include "Annotations.h"
#include "ClangdServer.h"
+#include "CodeComplete.h"
#include "Compiler.h"
#include "Context.h"
#include "Matchers.h"
@@ -60,27 +62,6 @@ class IgnoreDiagnostics : public DiagnosticsConsumer {
PathRef File, Tagged<std::vector<DiagWithFixIts>> Diagnostics) override {}
};
-struct StringWithPos {
- std::string Text;
- clangd::Position MarkerPos;
-};
-
-/// Accepts a source file with a cursor marker ^.
-/// Returns the source file with the marker removed, and the marker position.
-StringWithPos parseTextMarker(StringRef Text) {
- std::size_t MarkerOffset = Text.find('^');
- assert(MarkerOffset != StringRef::npos && "^ wasn't found in Text.");
-
- std::string WithoutMarker;
- WithoutMarker += Text.take_front(MarkerOffset);
- WithoutMarker += Text.drop_front(MarkerOffset + 1);
- assert(StringRef(WithoutMarker).find('^') == StringRef::npos &&
- "There were multiple occurences of ^ inside Text");
-
- auto MarkerPos = offsetToPosition(WithoutMarker, MarkerOffset);
- return {std::move(WithoutMarker), MarkerPos};
-}
-
// GMock helpers for matching completion items.
MATCHER_P(Named, Name, "") { return arg.insertText == Name; }
MATCHER_P(Labeled, Label, "") { return arg.label == Label; }
@@ -112,9 +93,9 @@ CompletionList completions(StringRef Text,
ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
/*StorePreamblesInMemory=*/true);
auto File = getVirtualTestFilePath("foo.cpp");
- auto Test = parseTextMarker(Text);
- Server.addDocument(Context::empty(), File, Test.Text);
- return Server.codeComplete(Context::empty(), File, Test.MarkerPos, Opts)
+ Annotations Test(Text);
+ Server.addDocument(Context::empty(), File, Test.code());
+ return Server.codeComplete(Context::empty(), File, Test.point(), Opts)
.get()
.second.Value;
}
@@ -291,13 +272,13 @@ TEST(CompletionTest, CheckContentsOverride) {
auto File = getVirtualTestFilePath("foo.cpp");
Server.addDocument(Context::empty(), File, "ignored text!");
- auto Example = parseTextMarker("int cbc; int b = ^;");
- auto Results =
- Server
- .codeComplete(Context::empty(), File, Example.MarkerPos,
- clangd::CodeCompleteOptions(), StringRef(Example.Text))
- .get()
- .second.Value;
+ Annotations Example("int cbc; int b = ^;");
+ auto Results = Server
+ .codeComplete(Context::empty(), File, Example.point(),
+ clangd::CodeCompleteOptions(),
+ StringRef(Example.code()))
+ .get()
+ .second.Value;
EXPECT_THAT(Results.items, Contains(Named("cbc")));
}
@@ -392,9 +373,9 @@ SignatureHelp signatures(StringRef Text) {
ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
/*StorePreamblesInMemory=*/true);
auto File = getVirtualTestFilePath("foo.cpp");
- auto Test = parseTextMarker(Text);
- Server.addDocument(Context::empty(), File, Test.Text);
- auto R = Server.signatureHelp(Context::empty(), File, Test.MarkerPos);
+ Annotations Test(Text);
+ Server.addDocument(Context::empty(), File, Test.code());
+ auto R = Server.signatureHelp(Context::empty(), File, Test.point());
assert(R);
return R.get().Value;
}
@@ -573,13 +554,13 @@ TEST(CompletionTest, ASTIndexMultiFile) {
.wait();
auto File = getVirtualTestFilePath("bar.cpp");
- auto Test = parseTextMarker(R"cpp(
+ Annotations Test(R"cpp(
namespace ns { class XXX {}; void fooooo() {} }
void f() { ns::^ }
)cpp");
- Server.addDocument(Context::empty(), File, Test.Text).wait();
+ Server.addDocument(Context::empty(), File, Test.code()).wait();
- auto Results = Server.codeComplete(Context::empty(), File, Test.MarkerPos, {})
+ auto Results = Server.codeComplete(Context::empty(), File, Test.point(), {})
.get()
.second.Value;
// "XYZ" and "foo" are not included in the file being completed but are still
OpenPOWER on IntegriCloud