Skip to content

Commit

Permalink
Add more tests for upa::url_from_file_path
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Nov 25, 2023
1 parent 443d7c2 commit 5abb4a4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/test-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ TEST_CASE("url_from_file_path") {
// empty path
CHECK_THROWS_AS(upa::url_from_file_path(""), upa::url_error);
// non absolute path
CHECK_THROWS_AS(upa::url_from_file_path("path"), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("path", upa::file_path_format::posix), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("C:\\path", upa::file_path_format::posix), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("C:/path", upa::file_path_format::posix), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("\\\\h\\p", upa::file_path_format::posix), upa::url_error);
// null character
CHECK_THROWS_AS(upa::url_from_file_path(std::string{ "/p\0", 3 }, upa::file_path_format::posix), upa::url_error);
Expand All @@ -615,10 +617,16 @@ TEST_CASE("url_from_file_path") {
CHECK(upa::url_from_file_path("C|\\path").href() == "file:///C:/path");
CHECK(upa::url_from_file_path("C:/path").href() == "file:///C:/path");
CHECK(upa::url_from_file_path("C:\\path %#").href() == "file:///C:/path%20%25%23");
// UNC: one-character hostname
CHECK(upa::url_from_file_path("\\\\h\\path").href() == "file://h/path");
CHECK(upa::url_from_file_path("\\\\h\\a/b").href() == "file://h/a/b");
CHECK(upa::url_from_file_path("\\\\a/b\\path").href() == "file://a/b/path");
CHECK(upa::url_from_file_path("//h/path", upa::file_path_format::windows).href() == "file://h/path");
// UNC: two-character hostname
CHECK(upa::url_from_file_path("\\\\ab\\path").href() == "file://ab/path");
// UNC: three-character hostname
CHECK(upa::url_from_file_path("\\\\abc\\path").href() == "file://abc/path");
// Win32 file and device namespaces
// https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
// https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
CHECK(upa::url_from_file_path("\\\\?\\D:\\very_long_path").href() == "file:///D:/very_long_path");
Expand All @@ -632,6 +640,7 @@ TEST_CASE("url_from_file_path") {
// non absolute path
CHECK_THROWS_AS(upa::url_from_file_path("\\"), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("C:path"), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("path", upa::file_path_format::windows), upa::url_error);
CHECK_THROWS_AS(upa::url_from_file_path("/", upa::file_path_format::windows), upa::url_error);
// invalid UNC
CHECK_THROWS_AS(upa::url_from_file_path("\\\\"), upa::url_error);
Expand Down

0 comments on commit 5abb4a4

Please sign in to comment.