diff options
author | Alexey Kozyatinskiy <kozyatinskiy@chromium.org> | 2018-08-30 14:58:38 -0700 |
---|---|---|
committer | Alexey Kozyatinskiy <kozyatinskiy@chromium.org> | 2018-09-14 08:32:08 -0700 |
commit | cf340fe0f5201b77a6e9af7f3b3b82d0d4868fc3 (patch) | |
tree | c86b0ced63e4d620e8af76a27431900c16af3389 /test/cctest | |
parent | ab150160f8149063865729e52c6a7597133f9057 (diff) | |
download | android-node-v8-cf340fe0f5201b77a6e9af7f3b3b82d0d4868fc3.tar.gz android-node-v8-cf340fe0f5201b77a6e9af7f3b3b82d0d4868fc3.tar.bz2 android-node-v8-cf340fe0f5201b77a6e9af7f3b3b82d0d4868fc3.zip |
src: added URL::FromFilePath method
Method returns file URL from native file path.
PR-URL: https://github.com/nodejs/node/pull/22251
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_url.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/cctest/test_url.cc b/test/cctest/test_url.cc index 088634152a..2e9b06e3a4 100644 --- a/test/cctest/test_url.cc +++ b/test/cctest/test_url.cc @@ -109,3 +109,36 @@ TEST_F(URLTest, ToFilePath) { #undef T } + +TEST_F(URLTest, FromFilePath) { + URL file_url; +#ifdef _WIN32 + file_url = URL::FromFilePath("C:\\Program Files\\"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/C:/Program%20Files/", file_url.path()); + + file_url = URL::FromFilePath("C:\\a\\b\\c"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/C:/a/b/c", file_url.path()); + + file_url = URL::FromFilePath("b:\\a\\%%.js"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/b:/a/%25%25.js", file_url.path()); + + file_url = URL::FromFilePath("\\\\host\\a\\b\\c"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("host/a/b/c", file_url.path()); +#else + file_url = URL::FromFilePath("/"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/", file_url.path()); + + file_url = URL::FromFilePath("/a/b/c"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/a/b/c", file_url.path()); + + file_url = URL::FromFilePath("/a/%%.js"); + EXPECT_EQ("file:", file_url.protocol()); + EXPECT_EQ("/a/%25%25.js", file_url.path()); +#endif +} |