-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathuri_from_path_test.cc
More file actions
122 lines (102 loc) · 4.38 KB
/
uri_from_path_test.cc
File metadata and controls
122 lines (102 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <gtest/gtest.h>
#include <sourcemeta/core/uri.h>
TEST(URI_from_path, unix_absolute) {
const std::filesystem::path example{"/foo/bar/baz"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///foo/bar/baz");
}
TEST(URI_from_path, unix_with_space_and_reserved) {
const std::filesystem::path example{"/foo/My Folder/has#hash?value%"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///foo/My%20Folder/has%23hash%3Fvalue%25");
}
TEST(URI_from_path, unix_trailing_slash) {
const std::filesystem::path example{"/foo/bar/"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///foo/bar/");
}
TEST(URI_from_path, windows_drive_absolute) {
const std::filesystem::path example{R"(C:\Program Files\Test)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///C:/Program%20Files/Test");
}
TEST(URI_from_path, windows_drive_lowercase) {
const std::filesystem::path example{R"(c:\temp\logs)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///c:/temp/logs");
}
TEST(URI_from_path, windows_drive_root) {
const std::filesystem::path example{R"(D:\)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///D:/");
}
TEST(URI_from_path, windows_trailing_slash) {
const std::filesystem::path example{R"(C:\foo\bar\)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///C:/foo/bar/");
}
TEST(URI_from_path, windows_percent_and_plus) {
// '%' → %25, '+' is allowed unencoded
const std::filesystem::path example{R"(C:\path\50%+plus.txt)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///C:/path/50%25+plus.txt");
}
TEST(URI_from_path, windows_unc_simple) {
const std::filesystem::path example{R"(\\server\share\file.txt)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(),
// For UNC, host=server, path=/share/file.txt
"file://server/share/file.txt");
}
TEST(URI_from_path, windows_unc_with_space) {
const std::filesystem::path example{R"(\\srv\My Docs\a b.txt)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file://srv/My%20Docs/a%20b.txt");
}
TEST(URI_from_path, unicode_unix) {
// U+00E9 (é) should be UTF-8 percent-encoded as %C3%A9
const std::filesystem::path example{u8"/data/éclair.txt"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///data/%C3%A9clair.txt");
}
TEST(URI_from_path, unicode_windows) {
// U+00E9 (é) should be UTF-8 percent-encoded as %C3%A9
const std::filesystem::path example{u8R"(C:\data\résumé.doc)"};
const auto uri{sourcemeta::core::URI::from_path(example)};
EXPECT_EQ(uri.recompose(), "file:///C:/data/r%C3%A9sum%C3%A9.doc");
}
TEST(URI_from_path, unix_relative_simple) {
const std::filesystem::path example{"foo/bar/baz"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, unix_relative_with_dot) {
const std::filesystem::path example{"./foo/bar"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, unix_relative_with_dotdot) {
const std::filesystem::path example{"../parent/dir"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, unix_empty_path) {
const std::filesystem::path example{""};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, windows_relative_simple) {
const std::filesystem::path example{"folder\\file.txt"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, windows_relative_with_dot) {
const std::filesystem::path example{".\\foo\\bar"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}
TEST(URI_from_path, windows_relative_with_dotdot) {
const std::filesystem::path example{"..\\up\\one\\level"};
EXPECT_THROW(sourcemeta::core::URI::from_path(example),
sourcemeta::core::URIError);
}