summaryrefslogtreecommitdiff
path: root/AK/Tests/TestURL.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-11 23:38:28 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-12 01:18:39 +0200
commitc8d0a2eb3c88a4d0751245ca83a1d01a87f2bb91 (patch)
treef954e7b5624ad3f4ce3d1dbb691ee87c97efb5f6 /AK/Tests/TestURL.cpp
parent21a61b276b5fbf244b28ded5fa2634a86df45498 (diff)
downloadserenity-c8d0a2eb3c88a4d0751245ca83a1d01a87f2bb91.zip
AK: Parse query and fragment in URL::parse()
Diffstat (limited to 'AK/Tests/TestURL.cpp')
-rw-r--r--AK/Tests/TestURL.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/AK/Tests/TestURL.cpp b/AK/Tests/TestURL.cpp
index 10d5a33d15..1c9f2e388e 100644
--- a/AK/Tests/TestURL.cpp
+++ b/AK/Tests/TestURL.cpp
@@ -36,18 +36,74 @@ TEST_CASE(construct)
TEST_CASE(basic)
{
{
- URL url("http://www.serenityos.org/index.html");
+ URL url("http://www.serenityos.org");
EXPECT_EQ(url.is_valid(), true);
EXPECT_EQ(url.protocol(), "http");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
EXPECT_EQ(url.port(), 80);
+ EXPECT_EQ(url.path(), "/");
+ EXPECT_EQ(url.query(), "");
+ EXPECT_EQ(url.fragment(), "");
+ }
+ {
+ URL url("https://www.serenityos.org/index.html");
+ EXPECT_EQ(url.is_valid(), true);
+ EXPECT_EQ(url.protocol(), "https");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
+ EXPECT_EQ(url.port(), 443);
EXPECT_EQ(url.path(), "/index.html");
+ EXPECT_EQ(url.query(), "");
+ EXPECT_EQ(url.fragment(), "");
}
{
URL url("https://localhost:1234/~anon/test/page.html");
EXPECT_EQ(url.is_valid(), true);
EXPECT_EQ(url.protocol(), "https");
+ EXPECT_EQ(url.host(), "localhost");
EXPECT_EQ(url.port(), 1234);
EXPECT_EQ(url.path(), "/~anon/test/page.html");
+ EXPECT_EQ(url.query(), "");
+ EXPECT_EQ(url.fragment(), "");
+ }
+ {
+ URL url("http://www.serenityos.org/index.html?#");
+ EXPECT_EQ(url.is_valid(), true);
+ EXPECT_EQ(url.protocol(), "http");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
+ EXPECT_EQ(url.port(), 80);
+ EXPECT_EQ(url.path(), "/index.html");
+ EXPECT_EQ(url.query(), "");
+ EXPECT_EQ(url.fragment(), "");
+ }
+ {
+ URL url("http://www.serenityos.org/index.html?foo=1&bar=2");
+ EXPECT_EQ(url.is_valid(), true);
+ EXPECT_EQ(url.protocol(), "http");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
+ EXPECT_EQ(url.port(), 80);
+ EXPECT_EQ(url.path(), "/index.html");
+ EXPECT_EQ(url.query(), "foo=1&bar=2");
+ EXPECT_EQ(url.fragment(), "");
+ }
+ {
+ URL url("http://www.serenityos.org/index.html#fragment");
+ EXPECT_EQ(url.is_valid(), true);
+ EXPECT_EQ(url.protocol(), "http");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
+ EXPECT_EQ(url.port(), 80);
+ EXPECT_EQ(url.path(), "/index.html");
+ EXPECT_EQ(url.query(), "");
+ EXPECT_EQ(url.fragment(), "fragment");
+ }
+ {
+ URL url("http://www.serenityos.org/index.html?foo=1&bar=2&baz=/?#frag/ment?test#");
+ EXPECT_EQ(url.is_valid(), true);
+ EXPECT_EQ(url.protocol(), "http");
+ EXPECT_EQ(url.host(), "www.serenityos.org");
+ EXPECT_EQ(url.port(), 80);
+ EXPECT_EQ(url.path(), "/index.html");
+ EXPECT_EQ(url.query(), "foo=1&bar=2&baz=/?");
+ EXPECT_EQ(url.fragment(), "frag/ment?test#");
}
}
@@ -71,6 +127,7 @@ TEST_CASE(serialization)
{
EXPECT_EQ(URL("http://www.serenityos.org/").to_string(), "http://www.serenityos.org/");
EXPECT_EQ(URL("http://www.serenityos.org:81/").to_string(), "http://www.serenityos.org:81/");
+ EXPECT_EQ(URL("https://www.serenityos.org:443/foo/bar.html?query#fragment").to_string(), "https://www.serenityos.org/foo/bar.html?query#fragment");
}
TEST_MAIN(URL)