summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-04-25 10:08:31 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-04-25 10:08:31 +0000
commitb49771998876cbb356bcbf39f518d2dafdb5b76b (patch)
treef7844f3a1c1f706e712ab0ad7e6b3fe465d5d6f4 /unittests
parentf96b3f1e98b1251ff19a5895cda9e1d840d3c209 (diff)
downloadclang-b49771998876cbb356bcbf39f518d2dafdb5b76b.tar.gz
[Testing] Move clangd::Annotations to llvm testing support
Summary: Annotations allow writing nice-looking unit test code when one needs access to locations from the source code, e.g. running code completion at particular offsets in a file. See comments in Annotations.cpp for more details on the API. Also got rid of a duplicate annotations parsing code in clang's code complete tests. Reviewers: gribozavr, sammccall Reviewed By: gribozavr Subscribers: mgorny, hiraditya, ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D59814 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359179 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Sema/CMakeLists.txt1
-rw-r--r--unittests/Sema/CodeCompleteTest.cpp34
2 files changed, 7 insertions, 28 deletions
diff --git a/unittests/Sema/CMakeLists.txt b/unittests/Sema/CMakeLists.txt
index 78601046dc..00ffa65864 100644
--- a/unittests/Sema/CMakeLists.txt
+++ b/unittests/Sema/CMakeLists.txt
@@ -16,4 +16,5 @@ target_link_libraries(SemaTests
clangSema
clangSerialization
clangTooling
+ LLVMTestingSupport
)
diff --git a/unittests/Sema/CodeCompleteTest.cpp b/unittests/Sema/CodeCompleteTest.cpp
index a636855098..4e1068f4a3 100644
--- a/unittests/Sema/CodeCompleteTest.cpp
+++ b/unittests/Sema/CodeCompleteTest.cpp
@@ -13,6 +13,7 @@
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/Testing/Support/Annotations.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstddef>
@@ -107,41 +108,18 @@ CompletionContext runCompletion(StringRef Code, size_t Offset) {
return ResultCtx;
}
-struct ParsedAnnotations {
- std::vector<size_t> Points;
- std::string Code;
-};
-
-ParsedAnnotations parseAnnotations(StringRef AnnotatedCode) {
- ParsedAnnotations R;
- while (!AnnotatedCode.empty()) {
- size_t NextPoint = AnnotatedCode.find('^');
- if (NextPoint == StringRef::npos) {
- R.Code += AnnotatedCode;
- AnnotatedCode = "";
- break;
- }
- R.Code += AnnotatedCode.substr(0, NextPoint);
- R.Points.push_back(R.Code.size());
-
- AnnotatedCode = AnnotatedCode.substr(NextPoint + 1);
- }
- return R;
-}
-
CompletionContext runCodeCompleteOnCode(StringRef AnnotatedCode) {
- ParsedAnnotations P = parseAnnotations(AnnotatedCode);
- assert(P.Points.size() == 1 && "expected exactly one annotation point");
- return runCompletion(P.Code, P.Points.front());
+ llvm::Annotations A(AnnotatedCode);
+ return runCompletion(A.code(), A.point());
}
std::vector<std::string>
collectPreferredTypes(StringRef AnnotatedCode,
std::string *PtrDiffType = nullptr) {
- ParsedAnnotations P = parseAnnotations(AnnotatedCode);
+ llvm::Annotations A(AnnotatedCode);
std::vector<std::string> Types;
- for (size_t Point : P.Points) {
- auto Results = runCompletion(P.Code, Point);
+ for (size_t Point : A.points()) {
+ auto Results = runCompletion(A.code(), Point);
if (PtrDiffType) {
assert(PtrDiffType->empty() || *PtrDiffType == Results.PtrDiffType);
*PtrDiffType = Results.PtrDiffType;