mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK+Userland+Tests: Remove URL(char const*) constructor
The StringView(char const*) constructor is being removed, and there was only a few users of this left, which are also cleaned up in this commit.
This commit is contained in:
parent
3f8060d859
commit
604aac531c
Notes:
sideshowbarker
2024-07-18 05:01:22 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/604aac531c Pull-request: https://github.com/SerenityOS/serenity/pull/14555 Reviewed-by: https://github.com/Dexesttp ✅ Reviewed-by: https://github.com/kleinesfilmroellchen
3 changed files with 62 additions and 66 deletions
4
AK/URL.h
4
AK/URL.h
|
@ -38,10 +38,6 @@ public:
|
|||
|
||||
URL() = default;
|
||||
URL(StringView);
|
||||
URL(char const* string)
|
||||
: URL(StringView(string))
|
||||
{
|
||||
}
|
||||
URL(String const& string)
|
||||
: URL(string.view())
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ TEST_CASE(construct)
|
|||
TEST_CASE(basic)
|
||||
{
|
||||
{
|
||||
URL url("http://www.serenityos.org");
|
||||
URL url("http://www.serenityos.org"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -28,7 +28,7 @@ TEST_CASE(basic)
|
|||
EXPECT(url.fragment().is_null());
|
||||
}
|
||||
{
|
||||
URL url("https://www.serenityos.org/index.html");
|
||||
URL url("https://www.serenityos.org/index.html"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "https");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -38,7 +38,7 @@ TEST_CASE(basic)
|
|||
EXPECT(url.fragment().is_null());
|
||||
}
|
||||
{
|
||||
URL url("https://localhost:1234/~anon/test/page.html");
|
||||
URL url("https://localhost:1234/~anon/test/page.html"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "https");
|
||||
EXPECT_EQ(url.host(), "localhost");
|
||||
|
@ -48,7 +48,7 @@ TEST_CASE(basic)
|
|||
EXPECT(url.fragment().is_null());
|
||||
}
|
||||
{
|
||||
URL url("http://www.serenityos.org/index.html?#");
|
||||
URL url("http://www.serenityos.org/index.html?#"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -58,7 +58,7 @@ TEST_CASE(basic)
|
|||
EXPECT_EQ(url.fragment(), "");
|
||||
}
|
||||
{
|
||||
URL url("http://www.serenityos.org/index.html?foo=1&bar=2");
|
||||
URL url("http://www.serenityos.org/index.html?foo=1&bar=2"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -68,7 +68,7 @@ TEST_CASE(basic)
|
|||
EXPECT(url.fragment().is_null());
|
||||
}
|
||||
{
|
||||
URL url("http://www.serenityos.org/index.html#fragment");
|
||||
URL url("http://www.serenityos.org/index.html#fragment"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -78,7 +78,7 @@ TEST_CASE(basic)
|
|||
EXPECT_EQ(url.fragment(), "fragment");
|
||||
}
|
||||
{
|
||||
URL url("http://www.serenityos.org/index.html?foo=1&bar=2&baz=/?#frag/ment?test#");
|
||||
URL url("http://www.serenityos.org/index.html?foo=1&bar=2&baz=/?#frag/ment?test#"sv);
|
||||
EXPECT_EQ(url.is_valid(), true);
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "www.serenityos.org");
|
||||
|
@ -91,30 +91,30 @@ TEST_CASE(basic)
|
|||
|
||||
TEST_CASE(some_bad_urls)
|
||||
{
|
||||
EXPECT_EQ(URL("http//serenityos.org").is_valid(), false);
|
||||
EXPECT_EQ(URL("serenityos.org").is_valid(), false);
|
||||
EXPECT_EQ(URL("://serenityos.org").is_valid(), false);
|
||||
EXPECT_EQ(URL("://:80").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:80:80/").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:80:80").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc:80").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc:80/").is_valid(), false);
|
||||
EXPECT_EQ(URL("data:").is_valid(), false);
|
||||
EXPECT_EQ(URL("http//serenityos.org"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("serenityos.org"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("://serenityos.org"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("://:80"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:80:80/"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:80:80"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc:80"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("http://serenityos.org:abc:80/"sv).is_valid(), false);
|
||||
EXPECT_EQ(URL("data:"sv).is_valid(), false);
|
||||
}
|
||||
|
||||
TEST_CASE(serialization)
|
||||
{
|
||||
EXPECT_EQ(URL("http://www.serenityos.org/").serialize(), "http://www.serenityos.org/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:0/").serialize(), "http://www.serenityos.org:0/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:80/").serialize(), "http://www.serenityos.org/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:81/").serialize(), "http://www.serenityos.org:81/");
|
||||
EXPECT_EQ(URL("https://www.serenityos.org:443/foo/bar.html?query#fragment").serialize(), "https://www.serenityos.org/foo/bar.html?query#fragment");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org/"sv).serialize(), "http://www.serenityos.org/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:0/"sv).serialize(), "http://www.serenityos.org:0/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:80/"sv).serialize(), "http://www.serenityos.org/");
|
||||
EXPECT_EQ(URL("http://www.serenityos.org:81/"sv).serialize(), "http://www.serenityos.org:81/");
|
||||
EXPECT_EQ(URL("https://www.serenityos.org:443/foo/bar.html?query#fragment"sv).serialize(), "https://www.serenityos.org/foo/bar.html?query#fragment");
|
||||
}
|
||||
|
||||
TEST_CASE(file_url_with_hostname)
|
||||
{
|
||||
URL url("file://courage/my/file");
|
||||
URL url("file://courage/my/file"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.host(), "courage");
|
||||
|
@ -127,7 +127,7 @@ TEST_CASE(file_url_with_hostname)
|
|||
|
||||
TEST_CASE(file_url_with_localhost)
|
||||
{
|
||||
URL url("file://localhost/my/file");
|
||||
URL url("file://localhost/my/file"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.host(), "");
|
||||
|
@ -137,7 +137,7 @@ TEST_CASE(file_url_with_localhost)
|
|||
|
||||
TEST_CASE(file_url_without_hostname)
|
||||
{
|
||||
URL url("file:///my/file");
|
||||
URL url("file:///my/file"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.host(), "");
|
||||
|
@ -147,7 +147,7 @@ TEST_CASE(file_url_without_hostname)
|
|||
|
||||
TEST_CASE(file_url_with_encoded_characters)
|
||||
{
|
||||
URL url("file:///my/file/test%23file.txt");
|
||||
URL url("file:///my/file/test%23file.txt"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.path(), "/my/file/test#file.txt");
|
||||
|
@ -157,7 +157,7 @@ TEST_CASE(file_url_with_encoded_characters)
|
|||
|
||||
TEST_CASE(file_url_with_fragment)
|
||||
{
|
||||
URL url("file:///my/file#fragment");
|
||||
URL url("file:///my/file#fragment"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.path(), "/my/file");
|
||||
|
@ -167,7 +167,7 @@ TEST_CASE(file_url_with_fragment)
|
|||
|
||||
TEST_CASE(file_url_with_root_path)
|
||||
{
|
||||
URL url("file:///");
|
||||
URL url("file:///"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "file");
|
||||
EXPECT_EQ(url.path(), "/");
|
||||
|
@ -175,17 +175,17 @@ TEST_CASE(file_url_with_root_path)
|
|||
|
||||
TEST_CASE(file_url_serialization)
|
||||
{
|
||||
EXPECT_EQ(URL("file://courage/my/file").serialize(), "file://courage/my/file");
|
||||
EXPECT_EQ(URL("file://localhost/my/file").serialize(), "file:///my/file");
|
||||
EXPECT_EQ(URL("file:///my/file").serialize(), "file:///my/file");
|
||||
EXPECT_EQ(URL("file:///my/directory/").serialize(), "file:///my/directory/");
|
||||
EXPECT_EQ(URL("file:///my/file%23test").serialize(), "file:///my/file%23test");
|
||||
EXPECT_EQ(URL("file:///my/file#fragment").serialize(), "file:///my/file#fragment");
|
||||
EXPECT_EQ(URL("file://courage/my/file"sv).serialize(), "file://courage/my/file");
|
||||
EXPECT_EQ(URL("file://localhost/my/file"sv).serialize(), "file:///my/file");
|
||||
EXPECT_EQ(URL("file:///my/file"sv).serialize(), "file:///my/file");
|
||||
EXPECT_EQ(URL("file:///my/directory/"sv).serialize(), "file:///my/directory/");
|
||||
EXPECT_EQ(URL("file:///my/file%23test"sv).serialize(), "file:///my/file%23test");
|
||||
EXPECT_EQ(URL("file:///my/file#fragment"sv).serialize(), "file:///my/file#fragment");
|
||||
}
|
||||
|
||||
TEST_CASE(about_url)
|
||||
{
|
||||
URL url("about:blank");
|
||||
URL url("about:blank"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "about");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -197,7 +197,7 @@ TEST_CASE(about_url)
|
|||
|
||||
TEST_CASE(mailto_url)
|
||||
{
|
||||
URL url("mailto:mail@example.com");
|
||||
URL url("mailto:mail@example.com"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "mailto");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -211,7 +211,7 @@ TEST_CASE(mailto_url)
|
|||
|
||||
TEST_CASE(data_url)
|
||||
{
|
||||
URL url("data:text/html,test");
|
||||
URL url("data:text/html,test"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -223,7 +223,7 @@ TEST_CASE(data_url)
|
|||
|
||||
TEST_CASE(data_url_default_mime_type)
|
||||
{
|
||||
URL url("data:,test");
|
||||
URL url("data:,test"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -235,7 +235,7 @@ TEST_CASE(data_url_default_mime_type)
|
|||
|
||||
TEST_CASE(data_url_encoded)
|
||||
{
|
||||
URL url("data:text/html,Hello%20friends%2C%0X%X0");
|
||||
URL url("data:text/html,Hello%20friends%2C%0X%X0"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -247,7 +247,7 @@ TEST_CASE(data_url_encoded)
|
|||
|
||||
TEST_CASE(data_url_base64_encoded)
|
||||
{
|
||||
URL url("data:text/html;base64,test");
|
||||
URL url("data:text/html;base64,test"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -259,7 +259,7 @@ TEST_CASE(data_url_base64_encoded)
|
|||
|
||||
TEST_CASE(data_url_base64_encoded_default_mime_type)
|
||||
{
|
||||
URL url("data:;base64,test");
|
||||
URL url("data:;base64,test"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -271,7 +271,7 @@ TEST_CASE(data_url_base64_encoded_default_mime_type)
|
|||
|
||||
TEST_CASE(data_url_base64_encoded_with_whitespace)
|
||||
{
|
||||
URL url("data: text/html ; bAsE64 , test with whitespace ");
|
||||
URL url("data: text/html ; bAsE64 , test with whitespace "sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -283,7 +283,7 @@ TEST_CASE(data_url_base64_encoded_with_whitespace)
|
|||
|
||||
TEST_CASE(data_url_base64_encoded_with_inline_whitespace)
|
||||
{
|
||||
URL url("data:text/javascript;base64,%20ZD%20Qg%0D%0APS%20An%20Zm91cic%0D%0A%207%20");
|
||||
URL url("data:text/javascript;base64,%20ZD%20Qg%0D%0APS%20An%20Zm91cic%0D%0A%207%20"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "data");
|
||||
EXPECT(url.host().is_null());
|
||||
|
@ -297,29 +297,29 @@ TEST_CASE(data_url_base64_encoded_with_inline_whitespace)
|
|||
|
||||
TEST_CASE(trailing_slash_with_complete_url)
|
||||
{
|
||||
EXPECT_EQ(URL("http://a/b/").complete_url("c/").serialize(), "http://a/b/c/");
|
||||
EXPECT_EQ(URL("http://a/b/").complete_url("c").serialize(), "http://a/b/c");
|
||||
EXPECT_EQ(URL("http://a/b").complete_url("c/").serialize(), "http://a/c/");
|
||||
EXPECT_EQ(URL("http://a/b").complete_url("c").serialize(), "http://a/c");
|
||||
EXPECT_EQ(URL("http://a/b/"sv).complete_url("c/"sv).serialize(), "http://a/b/c/");
|
||||
EXPECT_EQ(URL("http://a/b/"sv).complete_url("c"sv).serialize(), "http://a/b/c");
|
||||
EXPECT_EQ(URL("http://a/b"sv).complete_url("c/"sv).serialize(), "http://a/c/");
|
||||
EXPECT_EQ(URL("http://a/b"sv).complete_url("c"sv).serialize(), "http://a/c");
|
||||
}
|
||||
|
||||
TEST_CASE(trailing_port)
|
||||
{
|
||||
URL url("http://example.com:8086");
|
||||
URL url("http://example.com:8086"sv);
|
||||
EXPECT_EQ(url.port_or_default(), 8086);
|
||||
}
|
||||
|
||||
TEST_CASE(port_overflow)
|
||||
{
|
||||
EXPECT_EQ(URL("http://example.com:123456789/").is_valid(), false);
|
||||
EXPECT_EQ(URL("http://example.com:123456789/"sv).is_valid(), false);
|
||||
}
|
||||
|
||||
TEST_CASE(equality)
|
||||
{
|
||||
EXPECT(URL("http://serenityos.org").equals("http://serenityos.org#test"sv, URL::ExcludeFragment::Yes));
|
||||
EXPECT_EQ(URL("http://example.com/index.html"), URL("http://ex%61mple.com/index.html"));
|
||||
EXPECT_EQ(URL("file:///my/file"), URL("file://localhost/my/file"));
|
||||
EXPECT_NE(URL("http://serenityos.org/index.html"), URL("http://serenityos.org/test.html"));
|
||||
EXPECT(URL("http://serenityos.org"sv).equals("http://serenityos.org#test"sv, URL::ExcludeFragment::Yes));
|
||||
EXPECT_EQ(URL("http://example.com/index.html"sv), URL("http://ex%61mple.com/index.html"sv));
|
||||
EXPECT_EQ(URL("file:///my/file"sv), URL("file://localhost/my/file"sv));
|
||||
EXPECT_NE(URL("http://serenityos.org/index.html"sv), URL("http://serenityos.org/test.html"sv));
|
||||
}
|
||||
|
||||
TEST_CASE(create_with_file_scheme)
|
||||
|
@ -344,14 +344,14 @@ TEST_CASE(create_with_file_scheme)
|
|||
EXPECT_EQ(url.paths()[2], "");
|
||||
EXPECT_EQ(url.path(), "/home/anon/");
|
||||
|
||||
url = URL("file:///home/anon/");
|
||||
url = URL("file:///home/anon/"sv);
|
||||
EXPECT_EQ(url.path(), "/home/anon/");
|
||||
}
|
||||
|
||||
TEST_CASE(complete_url)
|
||||
{
|
||||
URL base_url("http://serenityos.org/index.html#fragment");
|
||||
URL url = base_url.complete_url("test.html");
|
||||
URL base_url("http://serenityos.org/index.html#fragment"sv);
|
||||
URL url = base_url.complete_url("test.html"sv);
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.scheme(), "http");
|
||||
EXPECT_EQ(url.host(), "serenityos.org");
|
||||
|
@ -360,33 +360,33 @@ TEST_CASE(complete_url)
|
|||
EXPECT(url.query().is_null());
|
||||
EXPECT_EQ(url.cannot_be_a_base_url(), false);
|
||||
|
||||
EXPECT(base_url.complete_url("../index.html#fragment").equals(base_url));
|
||||
EXPECT(base_url.complete_url("../index.html#fragment"sv).equals(base_url));
|
||||
}
|
||||
|
||||
TEST_CASE(leading_whitespace)
|
||||
{
|
||||
URL url { " https://foo.com/" };
|
||||
URL url { " https://foo.com/"sv };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
||||
TEST_CASE(trailing_whitespace)
|
||||
{
|
||||
URL url { "https://foo.com/ " };
|
||||
URL url { "https://foo.com/ "sv };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
||||
TEST_CASE(leading_and_trailing_whitespace)
|
||||
{
|
||||
URL url { " https://foo.com/ " };
|
||||
URL url { " https://foo.com/ "sv };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.to_string(), "https://foo.com/");
|
||||
}
|
||||
|
||||
TEST_CASE(unicode)
|
||||
{
|
||||
URL url { "http://example.com/_ünicöde_téxt_©" };
|
||||
URL url { "http://example.com/_ünicöde_téxt_©"sv };
|
||||
EXPECT(url.is_valid());
|
||||
EXPECT_EQ(url.path(), "/_ünicöde_téxt_©");
|
||||
EXPECT(url.query().is_null());
|
||||
|
|
|
@ -148,7 +148,7 @@ private:
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
char const* url_str = nullptr;
|
||||
StringView url_str;
|
||||
bool save_at_provided_name = false;
|
||||
bool should_follow_url = false;
|
||||
char const* data = nullptr;
|
||||
|
|
Loading…
Reference in a new issue