10using namespace stdex::parser;
12using namespace Microsoft::VisualStudio::CppUnitTestFramework;
22 static const wchar_t text[] =
L"This is a test.\nSecond line.";
26 Assert::IsTrue(
p.match(
text));
33 Assert::IsFalse(
p.match(
text));
34 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
41 Assert::IsFalse(
p.match(
text));
42 Assert::IsTrue(
p.match(
text, 4));
49 Assert::IsFalse(
p.match(
text));
50 Assert::IsTrue(
p.match(
text, 14));
57 Assert::IsFalse(
p.match(
text));
58 Assert::IsTrue(
p.match(
text, 4));
61 Assert::IsTrue(
p.match(
text, 14));
68 Assert::IsTrue(
p.match(
text));
71 Assert::IsFalse(
p.match(
text, 1));
72 Assert::IsFalse(
p.match(
text, 15));
73 Assert::IsTrue(
p.match(
text, 16));
80 Assert::IsFalse(
p.match(
text));
81 Assert::IsFalse(
p.match(
text, 1));
82 Assert::IsTrue(
p.match(
text, 15));
85 Assert::IsFalse(
p.match(
text, 16));
90 Assert::IsFalse(
p.match(
text));
91 Assert::IsTrue(
p.match(
text, 8));
94 Assert::AreEqual((
size_t)0,
p.hit_offset);
95 Assert::IsFalse(
p.match(
text, 21));
96 Assert::IsTrue(
p.match(
text, 21, _countof(
text), match_case_insensitive));
99 Assert::AreEqual((
size_t)3,
p.hit_offset);
103 stdex::parser::wstring
p(
L"this");
104 Assert::IsFalse(
p.match(
text));
105 Assert::IsTrue(
p.match(
text, 0,
sizeof(
text), match_case_insensitive));
113 Assert::IsTrue(
p.match(
text));
121 Assert::IsTrue(
p.match(
text));
130 make_shared_no_delete(&
chr_t),
131 make_shared_no_delete(&
chr_h),
132 make_shared_no_delete(&
chr_i),
133 make_shared_no_delete(&
chr_s),
134 make_shared_no_delete(&space) });
135 Assert::IsFalse(
p.match(
text));
136 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
145 make_shared_no_delete(&
apple),
146 make_shared_no_delete(&
orange),
147 make_shared_no_delete(&
_this),
148 make_shared_no_delete(&space) });
149 Assert::IsFalse(
p.match(
text));
150 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
151 Assert::AreEqual((
size_t)2,
p.hit_offset);
158 Assert::IsFalse(
p.match(
text));
159 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
160 Assert::AreEqual((
size_t)2,
p.hit_offset);
168 make_shared_no_delete(&
chr_s),
169 make_shared_no_delete(&
chr_h),
170 make_shared_no_delete(&
chr_i),
171 make_shared_no_delete(&
chr_t) });
172 Assert::IsFalse(
p.match(
text));
173 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
182 static const char text[] =
"V kožuščku zlobnega mizarja stopiclja fant\nin kliče 1234567890.";
186 Assert::IsTrue(
p.match(
text));
193 Assert::IsFalse(
p.match(
text));
194 Assert::IsTrue(
p.match(
text, 0, _countof(
text), match_case_insensitive));
201 Assert::IsFalse(
p.match(
text, 4));
202 Assert::IsTrue(
p.match(
text, 4, _countof(
text), match_case_insensitive));
209 Assert::IsFalse(
p.match(
text));
210 Assert::IsTrue(
p.match(
text, 1));
213 Assert::IsTrue(
p.match(
text, 79));
220 Assert::IsFalse(
p.match(
text, 2));
221 Assert::IsTrue(
p.match(
text, 2, _countof(
text), match_case_insensitive));
222 Assert::AreEqual((
size_t)2,
p.hit_offset);
230 static const std::locale locale(
"en_US.UTF-8");
233 "Host: stackoverflow.com\r\n"
234 "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0\r\n"
235 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n"
236 "Accept-Language: sl,en-US;q=0.8,en;q=0.6,de-DE;q=0.4,de;q=0.2\r\n"
237 "Accept-Encoding: gzip, deflate, br\r\n"
239 "Connection: keep-alive\r\n"
240 "Cookie: prov=00000000-0000-0000-0000-000000000000; acct=t=00000000000000000%2f%2f0000%2b0000%2b000&s=00000000000000000000000000000000; OptanonConsent=isGpcEnabled=0&datestamp=Fri+Feb+03+2023+11%3A11%3A08+GMT%2B0100+(Srednjeevropski+standardni+%C4%8Das)&version=6.37.0&isIABGlobal=false&hosts=&consentId=00000000-0000-0000-0000-000000000000&interactionCount=1&landingPath=NotLandingPage&groups=00000%3A0%2C00000%3A0%2C00000%3A0%2C00000%3A0; OptanonAlertBoxClosed=2023-02-03T10:11:08.683Z\r\n"
241 "Upgrade-Insecure-Requests: 1\r\n"
242 "Sec-Fetch-Dest: document\r\n"
243 "Sec-Fetch-Mode: navigate\r\n"
244 "Sec-Fetch-Site: none\r\n"
245 "Sec-Fetch-User: ?1\r\n"
246 "Pragma: no-cache\r\n"
247 "Cache-Control: no-cache\r\n"
255 Assert::AreEqual((
size_t)0,
p.verb.start);
256 Assert::AreEqual((
size_t)3,
p.verb.end);
261 Assert::AreEqual((
uint16_t)0x200,
p.protocol.version);
265 std::list<http_header>
hdrs;
271 hdrs.push_back(std::move(
h));
276 Assert::AreEqual((
size_t)15,
hdrs.size());
278 for (
const auto&
h :
hdrs)
279 if (strnicmp(
request +
h.name.start,
h.name.size(),
"Accept-Language", (
size_t)-1, locale) == 0)
281 Assert::IsTrue(!
langs.empty());
284 "sl",
"en-US",
"en",
"de-DE",
"de"
290 Assert::IsTrue(
c ==
control.cend());
291 Assert::IsTrue(
l ==
langs.cend());
interval< size_t > interval
Region of the last match.
Definition parser.hpp:169
Test for given string.
Definition parser.hpp:815
Test for HTTP request.
Definition parser.hpp:6139
Test for specific SGML code point.
Definition parser.hpp:340
Test for any SGML space code point.
Definition parser.hpp:427
T size() const
Returns interval size.
Definition interval.hpp:47
T end
interval end
Definition interval.hpp:20
T start
interval start
Definition interval.hpp:19