1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +09:00

Tests/LibURL: Port to Windows

This commit is contained in:
stasoid 2025-05-29 21:10:33 +05:00 committed by Andrew Kaster
parent e2d0d8e2b9
commit 8d33a97630
Notes: github-actions[bot] 2025-06-01 22:43:21 +00:00
2 changed files with 38 additions and 1 deletions

View file

@ -5,6 +5,7 @@ add_subdirectory(LibDiff)
add_subdirectory(LibGC)
add_subdirectory(LibJS)
add_subdirectory(LibRegex)
add_subdirectory(LibURL)
# FIXME: Increase support for building targets on Windows
if (WIN32 AND ENABLE_WINDOWS_CI)
@ -18,7 +19,6 @@ add_subdirectory(LibTextCodec)
add_subdirectory(LibThreading)
add_subdirectory(LibTLS)
add_subdirectory(LibUnicode)
add_subdirectory(LibURL)
add_subdirectory(LibWasm)
add_subdirectory(LibXML)

View file

@ -263,6 +263,7 @@ TEST_CASE(equality)
EXPECT_NE(URL::Parser::basic_parse("http://serenityos.org/index.html"sv), URL::Parser::basic_parse("http://serenityos.org/test.html"sv));
}
#ifndef AK_OS_WINDOWS
TEST_CASE(create_with_file_scheme)
{
auto maybe_url = URL::create_with_file_scheme("/home/anon/README.md");
@ -290,6 +291,42 @@ TEST_CASE(create_with_file_scheme)
url = URL::Parser::basic_parse("file:///home/anon/"sv).value();
EXPECT_EQ(url.serialize_path(), "/home/anon/");
}
#else
TEST_CASE(create_with_file_scheme)
{
// create_with_file_scheme doesn't work for Unix paths on Windows because it returns nothing if the path is not absolute
auto maybe_url = URL::create_with_file_scheme("C:\\home\\anon\\README.md");
EXPECT(maybe_url.has_value());
auto url = maybe_url.release_value();
EXPECT_EQ(url.scheme(), "file");
EXPECT_EQ(url.port_or_default(), 0);
EXPECT_EQ(url.path_segment_count(), 4u);
EXPECT_EQ(url.path_segment_at_index(0), "C:");
EXPECT_EQ(url.path_segment_at_index(1), "home");
EXPECT_EQ(url.path_segment_at_index(2), "anon");
EXPECT_EQ(url.path_segment_at_index(3), "README.md");
EXPECT_EQ(url.serialize_path(), "/C:/home/anon/README.md");
EXPECT_EQ(url.file_path(), "C:/home/anon/README.md");
EXPECT(!url.query().has_value());
EXPECT(!url.fragment().has_value());
maybe_url = URL::create_with_file_scheme("C:/home/anon/");
EXPECT(maybe_url.has_value());
url = maybe_url.release_value();
EXPECT_EQ(url.path_segment_count(), 4u);
EXPECT_EQ(url.path_segment_at_index(0), "C:");
EXPECT_EQ(url.path_segment_at_index(1), "home");
EXPECT_EQ(url.path_segment_at_index(2), "anon");
EXPECT_EQ(url.path_segment_at_index(3), "");
EXPECT_EQ(url.serialize_path(), "/C:/home/anon/");
url = URL::Parser::basic_parse("file://C:/home/anon/"sv).value();
EXPECT_EQ(url.serialize_path(), "/C:/home/anon/");
url = URL::Parser::basic_parse("file:///home/anon/"sv).value();
EXPECT_EQ(url.serialize_path(), "/home/anon/");
}
#endif
TEST_CASE(complete_url)
{