13{
14 SECTION("Empty URI")
15 {
17 REQUIRE(result.Scheme.empty());
18 REQUIRE(result.UserInfo.empty());
19 REQUIRE(result.Host.empty());
20 REQUIRE(result.Port.empty());
21 REQUIRE(result.Path.empty());
22 REQUIRE(result.Query.empty());
23 REQUIRE(result.Fragment.empty());
24 }
25
26 SECTION("URI without scheme")
27 {
29 REQUIRE(result.Scheme.empty());
30 REQUIRE(result.UserInfo.empty());
31 REQUIRE(result.Host == "test");
32 REQUIRE(result.Port.empty());
33 REQUIRE(result.Path.empty());
34 REQUIRE(result.Query.empty());
35 REQUIRE(result.Fragment.empty());
36 }
37
38 SECTION("URI with scheme")
39 {
40 auto result =
ParseUri(
"http://test");
41 REQUIRE(result.Scheme == "http");
42 REQUIRE(result.UserInfo.empty());
43 REQUIRE(result.Host == "test");
44 REQUIRE(result.Port.empty());
45 REQUIRE(result.Path.empty());
46 REQUIRE(result.Query.empty());
47 REQUIRE(result.Fragment.empty());
48 }
49
50 SECTION("URI with scheme and fragment")
51 {
52 auto result =
ParseUri(
"http://test#fragment");
53 REQUIRE(result.Scheme == "http");
54 REQUIRE(result.UserInfo.empty());
55 REQUIRE(result.Host == "test");
56 REQUIRE(result.Port.empty());
57 REQUIRE(result.Path.empty());
58 REQUIRE(result.Query.empty());
59 REQUIRE(result.Fragment == "fragment");
60 }
61
62 SECTION("URI with scheme and query")
63 {
64 auto result =
ParseUri(
"http://test?query");
65 REQUIRE(result.Scheme == "http");
66 REQUIRE(result.UserInfo.empty());
67 REQUIRE(result.Host == "test");
68 REQUIRE(result.Port.empty());
69 REQUIRE(result.Path.empty());
70 REQUIRE(result.Query == "query");
71 REQUIRE(result.Fragment.empty());
72 }
73
74 SECTION("URI with scheme and path")
75 {
76 auto result =
ParseUri(
"http://test/path");
77 REQUIRE(result.Scheme == "http");
78 REQUIRE(result.UserInfo.empty());
79 REQUIRE(result.Host == "test");
80 REQUIRE(result.Port.empty());
81 REQUIRE(result.Path == "path");
82 REQUIRE(result.Query.empty());
83 REQUIRE(result.Fragment.empty());
84 }
85
86 SECTION("URI with scheme, path and query")
87 {
88 auto result =
ParseUri(
"http://test/path?query");
89 REQUIRE(result.Scheme == "http");
90 REQUIRE(result.UserInfo.empty());
91 REQUIRE(result.Host == "test");
92 REQUIRE(result.Port.empty());
93 REQUIRE(result.Path == "path");
94 REQUIRE(result.Query == "query");
95 REQUIRE(result.Fragment.empty());
96 }
97
98 SECTION("URI with scheme, path and fragment")
99 {
100 auto result =
ParseUri(
"http://test/path#fragment");
101 REQUIRE(result.Scheme == "http");
102 REQUIRE(result.UserInfo.empty());
103 REQUIRE(result.Host == "test");
104 REQUIRE(result.Port.empty());
105 REQUIRE(result.Path == "path");
106 REQUIRE(result.Query.empty());
107 REQUIRE(result.Fragment == "fragment");
108 }
109
110 SECTION("URI with scheme, path, query and fragment")
111 {
112 auto result =
ParseUri(
"http://test/path?query#fragment");
113 REQUIRE(result.Scheme == "http");
114 REQUIRE(result.UserInfo.empty());
115 REQUIRE(result.Host == "test");
116 REQUIRE(result.Port.empty());
117 REQUIRE(result.Path == "path");
118 REQUIRE(result.Query == "query");
119 REQUIRE(result.Fragment == "fragment");
120 }
121
122 SECTION("URI with scheme, user info, host, port, path, query and fragment")
123 {
124 auto result =
125 ParseUri(
"http://user:password@test:1234/path?query#fragment");
126 REQUIRE(result.Scheme == "http");
127 REQUIRE(result.UserInfo == "user:password");
128 REQUIRE(result.Host == "test");
129 REQUIRE(result.Port == "1234");
130 REQUIRE(result.Path == "path");
131 REQUIRE(result.Query == "query");
132 REQUIRE(result.Fragment == "fragment");
133 }
134}
UriFields ParseUri(std::string_view uri) noexcept