8#include <catch2/catch.hpp>
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());
26 SECTION(
"URI without scheme")
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());
38 SECTION(
"URI with scheme")
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());
50 SECTION(
"URI with scheme and fragment")
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");
62 SECTION(
"URI with scheme and query")
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());
74 SECTION(
"URI with scheme and path")
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());
86 SECTION(
"URI with scheme, path and query")
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());
98 SECTION(
"URI with scheme, path and fragment")
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");
110 SECTION(
"URI with scheme, path, query and fragment")
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");
122 SECTION(
"URI with scheme, user info, host, port, path, query and fragment")
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");
139 SECTION(
"Empty query")
142 REQUIRE(result.empty());
145 SECTION(
"Query without delimiter")
148 REQUIRE(result.size() == 1);
149 REQUIRE(result[
"test"].empty());
152 SECTION(
"Query with single item")
155 REQUIRE(result.size() == 1);
156 REQUIRE(result[
"test"] ==
"value");
159 SECTION(
"Query with multiple items")
162 REQUIRE(result.size() == 2);
163 REQUIRE(result[
"test1"] ==
"value1");
164 REQUIRE(result[
"test2"] ==
"value2");
167 SECTION(
"Query with multiple items without values")
170 REQUIRE(result.size() == 2);
171 REQUIRE(result[
"test1"].empty());
172 REQUIRE(result[
"test2"].empty());
175 SECTION(
"Query with multiple mixed items")
178 REQUIRE(result.size() == 3);
179 REQUIRE(result[
"test1"].empty());
180 REQUIRE(result[
"test2"] ==
"value");
181 REQUIRE(result[
"test3"].empty());
184 SECTION(
"Query with multiple items and custom delimiter")
186 auto result =
ParseUriQuery(
"test1=value1;test2=value2",
";");
187 REQUIRE(result.size() == 2);
188 REQUIRE(result[
"test1"] ==
"value1");
189 REQUIRE(result[
"test2"] ==
"value2");
QueryFields ParseUriQuery(std::string_view query, std::string_view delimiter) noexcept
Parses URI query and returns QueryFields structure with parsed fields.
UriFields ParseUri(std::string_view uri) noexcept
TEST_CASE("ParseUri", "[StringUtils]")