summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/URITests.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-06-15 08:55:00 +0000
committerEric Liu <ioeric@google.com>2018-06-15 08:55:00 +0000
commit13e503f68a0ec42807c46aa76540b3eb06450b9d (patch)
treea4ad95a19d776794ffa1226b0ffc76fe70548b1f /clang-tools-extra/unittests/clangd/URITests.cpp
parent0651eb1b31ce0ab3e2dd88947f38de7e3ebc8bc9 (diff)
downloadbcm5719-llvm-13e503f68a0ec42807c46aa76540b3eb06450b9d.tar.gz
bcm5719-llvm-13e503f68a0ec42807c46aa76540b3eb06450b9d.zip
[clangd] Customizable URI schemes for dynamic index.
Summary: This allows dynamic index to have consistent URI schemes with the static index which can have customized URI schemes, which would make file proximity scoring based on URIs easier. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47931 llvm-svn: 334809
Diffstat (limited to 'clang-tools-extra/unittests/clangd/URITests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/URITests.cpp41
1 files changed, 7 insertions, 34 deletions
diff --git a/clang-tools-extra/unittests/clangd/URITests.cpp b/clang-tools-extra/unittests/clangd/URITests.cpp
index 4ddc1645afb..f6ac0c6b7f0 100644
--- a/clang-tools-extra/unittests/clangd/URITests.cpp
+++ b/clang-tools-extra/unittests/clangd/URITests.cpp
@@ -14,6 +14,11 @@
namespace clang {
namespace clangd {
+
+// Force the unittest URI scheme to be linked,
+static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
+ UnittestSchemeAnchorSource;
+
namespace {
using ::testing::AllOf;
@@ -22,38 +27,6 @@ MATCHER_P(Scheme, S, "") { return arg.scheme() == S; }
MATCHER_P(Authority, A, "") { return arg.authority() == A; }
MATCHER_P(Body, B, "") { return arg.body() == B; }
-// Assume all files in the schema have a "test-root/" root directory, and the
-// schema path is the relative path to the root directory.
-// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z".
-class TestScheme : public URIScheme {
-public:
- static const char *Scheme;
-
- static const char *TestRoot;
-
- llvm::Expected<std::string>
- getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
- llvm::StringRef HintPath) const override {
- auto Pos = HintPath.find(TestRoot);
- assert(Pos != llvm::StringRef::npos);
- return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body)
- .str();
- }
-
- llvm::Expected<URI>
- uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
- auto Pos = AbsolutePath.find(TestRoot);
- assert(Pos != llvm::StringRef::npos);
- return URI(Scheme, /*Authority=*/"",
- AbsolutePath.substr(Pos + llvm::StringRef(TestRoot).size()));
- }
-};
-
-const char *TestScheme::Scheme = "unittest";
-const char *TestScheme::TestRoot = "/test-root/";
-
-static URISchemeRegistry::Add<TestScheme> X(TestScheme::Scheme, "Test schema");
-
std::string createOrDie(llvm::StringRef AbsolutePath,
llvm::StringRef Scheme = "file") {
auto Uri = URI::create(AbsolutePath, Scheme);
@@ -167,12 +140,12 @@ TEST(URITest, Resolve) {
#else
EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c");
EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "/a/b/c");
- EXPECT_EQ(resolveOrDie(parseOrDie("unittest:a/b/c"), "/dir/test-root/x/y/z"),
- "/dir/test-root/a/b/c");
EXPECT_THAT(resolveOrDie(parseOrDie("file://au%3dth/%28x%29/y/%20z")),
"/(x)/y/ z");
EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:/x/y/z");
#endif
+ EXPECT_EQ(resolveOrDie(parseOrDie("unittest:a"), testPath("x")),
+ testPath("a"));
}
TEST(URITest, Platform) {
OpenPOWER on IntegriCloud