12#include "gmock/gmock.h"
13#include "gtest/gtest.h"
24using ::testing::AllOf;
26MATCHER_P(scheme, S,
"") {
return arg.scheme() == S; }
27MATCHER_P(authority, A,
"") {
return arg.authority() == A; }
28MATCHER_P(body, B,
"") {
return arg.body() == B; }
30std::string createOrDie(llvm::StringRef AbsolutePath,
31 llvm::StringRef Scheme =
"file") {
34 llvm_unreachable(
toString(Uri.takeError()).c_str());
35 return Uri->toString();
38URI parseOrDie(llvm::StringRef Uri) {
41 llvm_unreachable(
toString(U.takeError()).c_str());
45TEST(PercentEncodingTest, Encode) {
46 EXPECT_EQ(
URI(
"x",
"",
"a/b/c").
toString(),
"x:a/b/c");
47 EXPECT_EQ(
URI(
"x",
"",
"a!b;c~").
toString(),
"x:a%21b%3Bc~");
48 EXPECT_EQ(
URI(
"x",
"",
"a123b").
toString(),
"x:a123b");
49 EXPECT_EQ(
URI(
"x",
"",
"a:b;c").
toString(),
"x:a:b%3Bc");
52TEST(PercentEncodingTest, Decode) {
53 EXPECT_EQ(parseOrDie(
"x:a/b/c").body(),
"a/b/c");
55 EXPECT_EQ(parseOrDie(
"s%2b://%3a/%3").scheme(),
"s+");
56 EXPECT_EQ(parseOrDie(
"s%2b://%3a/%3").authority(),
":");
57 EXPECT_EQ(parseOrDie(
"s%2b://%3a/%3").body(),
"/%3");
59 EXPECT_EQ(parseOrDie(
"x:a%21b%3ac~").body(),
"a!b:c~");
60 EXPECT_EQ(parseOrDie(
"x:a:b%3bc").body(),
"a:b;c");
63std::string resolveOrDie(
const URI &U, llvm::StringRef HintPath =
"") {
70TEST(URITest, Create) {
72 EXPECT_THAT(createOrDie(
"c:\\x\\y\\z"),
"file:///c:/x/y/z");
74 EXPECT_THAT(createOrDie(
"/x/y/z"),
"file:///x/y/z");
75 EXPECT_THAT(createOrDie(
"/(x)/y/\\ z"),
"file:///%28x%29/y/%5C%20z");
79TEST(URITest, CreateUNC) {
81 EXPECT_THAT(createOrDie(
"\\\\test.org\\x\\y\\z"),
"file://test.org/x/y/z");
82 EXPECT_THAT(createOrDie(
"\\\\10.0.0.1\\x\\y\\z"),
"file://10.0.0.1/x/y/z");
84 EXPECT_THAT(createOrDie(
"//test.org/x/y/z"),
"file://test.org/x/y/z");
85 EXPECT_THAT(createOrDie(
"//10.0.0.1/x/y/z"),
"file://10.0.0.1/x/y/z");
89TEST(URITest, FailedCreate) {
96 EXPECT_THAT(parseOrDie(
"file://auth/x/y/z"),
97 AllOf(scheme(
"file"), authority(
"auth"), body(
"/x/y/z")));
99 EXPECT_THAT(parseOrDie(
"file://au%3dth/%28x%29/y/%5c%20z"),
100 AllOf(scheme(
"file"), authority(
"au=th"), body(
"/(x)/y/\\ z")));
102 EXPECT_THAT(parseOrDie(
"file:///%28x%29/y/%5c%20z"),
103 AllOf(scheme(
"file"), authority(
""), body(
"/(x)/y/\\ z")));
104 EXPECT_THAT(parseOrDie(
"file:///x/y/z"),
105 AllOf(scheme(
"file"), authority(
""), body(
"/x/y/z")));
106 EXPECT_THAT(parseOrDie(
"file:"),
107 AllOf(scheme(
"file"), authority(
""), body(
"")));
108 EXPECT_THAT(parseOrDie(
"file:///x/y/z%2"),
109 AllOf(scheme(
"file"), authority(
""), body(
"/x/y/z%2")));
110 EXPECT_THAT(parseOrDie(
"http://llvm.org"),
111 AllOf(scheme(
"http"), authority(
"llvm.org"), body(
"")));
112 EXPECT_THAT(parseOrDie(
"http://llvm.org/"),
113 AllOf(scheme(
"http"), authority(
"llvm.org"), body(
"/")));
114 EXPECT_THAT(parseOrDie(
"http://llvm.org/D"),
115 AllOf(scheme(
"http"), authority(
"llvm.org"), body(
"/D")));
116 EXPECT_THAT(parseOrDie(
"http:/"),
117 AllOf(scheme(
"http"), authority(
""), body(
"/")));
118 EXPECT_THAT(parseOrDie(
"urn:isbn:0451450523"),
119 AllOf(scheme(
"urn"), authority(
""), body(
"isbn:0451450523")));
121 parseOrDie(
"file:///c:/windows/system32/"),
122 AllOf(scheme(
"file"), authority(
""), body(
"/c:/windows/system32/")));
125TEST(URITest, ParseFailed) {
134TEST(URITest, Resolve) {
136 EXPECT_THAT(resolveOrDie(parseOrDie(
"file:///c%3a/x/y/z")),
"c:\\x\\y\\z");
137 EXPECT_THAT(resolveOrDie(parseOrDie(
"file:///c:/x/y/z")),
"c:\\x\\y\\z");
139 EXPECT_EQ(resolveOrDie(parseOrDie(
"file:/a/b/c")),
"/a/b/c");
140 EXPECT_EQ(resolveOrDie(parseOrDie(
"file://auth/a/b/c")),
"//auth/a/b/c");
141 EXPECT_THAT(resolveOrDie(parseOrDie(
"file://au%3dth/%28x%29/y/%20z")),
143 EXPECT_THAT(resolveOrDie(parseOrDie(
"file:///c:/x/y/z")),
"c:/x/y/z");
145 EXPECT_EQ(resolveOrDie(parseOrDie(
"unittest:///a"),
testPath(
"x")),
149TEST(URITest, ResolveUNC) {
151 EXPECT_THAT(resolveOrDie(parseOrDie(
"file://example.com/x/y/z")),
152 "\\\\example.com\\x\\y\\z");
153 EXPECT_THAT(resolveOrDie(parseOrDie(
"file://127.0.0.1/x/y/z")),
154 "\\\\127.0.0.1\\x\\y\\z");
156 EXPECT_THAT(resolveOrDie(parseOrDie(
"file:////127.0.0.1/x/y/z")),
157 "\\\\127.0.0.1\\x\\y\\z");
159 EXPECT_THAT(resolveOrDie(parseOrDie(
"file://example.com/x/y/z")),
160 "//example.com/x/y/z");
161 EXPECT_THAT(resolveOrDie(parseOrDie(
"file://127.0.0.1/x/y/z")),
162 "//127.0.0.1/x/y/z");
166std::string resolvePathOrDie(llvm::StringRef AbsPath,
167 llvm::StringRef HintPath =
"") {
174TEST(URITest, ResolvePath) {
181 EXPECT_EQ(resolvePathOrDie(FilePath), FilePath);
185 EXPECT_FALSE(Resolve);
186 llvm::consumeError(Resolve.takeError());
189TEST(URITest, Platform) {
192 EXPECT_TRUE(
static_cast<bool>(U));
193 EXPECT_THAT(resolveOrDie(*U),
Path);
196TEST(URITest, ResolveFailed) {
197 auto FailedResolve = [](StringRef Uri) {
200 consumeError(
Path.takeError());
207 EXPECT_TRUE(FailedResolve(
"no:/a/b/c"));
209 EXPECT_TRUE(FailedResolve(
"file:a/b/c"));
#define EXPECT_ERROR(expectedValue)
A URI describes the location of a source file.
static llvm::Expected< std::string > resolvePath(llvm::StringRef AbsPath, llvm::StringRef HintPath="")
Resolves AbsPath into a canonical path of its URI, by converting AbsPath to URI and resolving the URI...
static llvm::Expected< URI > create(llvm::StringRef AbsolutePath, llvm::StringRef Scheme)
Creates a URI for a file in the given scheme.
static llvm::Expected< std::string > resolve(const URI &U, llvm::StringRef HintPath="")
Resolves the absolute path of U.
static llvm::Expected< URI > parse(llvm::StringRef Uri)
Parse a URI string "<scheme>:[//<authority>/]<path>".
std::string Path
A typedef to represent a file path.
static const char * toString(OffsetEncoding OE)
std::string testPath(PathRef File, llvm::sys::path::Style Style)
TEST(BackgroundQueueTest, Priority)
volatile int UnittestSchemeAnchorSource
static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//