diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-29 21:20:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 16:20:55 -0400 |
commit | b51c863550cb377f6e720bccf4f1485ed8d97222 (patch) | |
tree | b17087c22cecc21d1020c8580be712280aafa9ab /std/path/from_file_url_test.ts | |
parent | 3e6ea6284178df0be4982d9775f47b47b14c6139 (diff) |
feat(std/path): Add fromFileUrl() (#4993)
Fix: URL constructor accepts a URL object which is not a base
Diffstat (limited to 'std/path/from_file_url_test.ts')
-rw-r--r-- | std/path/from_file_url_test.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/std/path/from_file_url_test.ts b/std/path/from_file_url_test.ts new file mode 100644 index 000000000..79389b91b --- /dev/null +++ b/std/path/from_file_url_test.ts @@ -0,0 +1,37 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import * as path from "./mod.ts"; +import { assertEquals } from "../testing/asserts.ts"; + +Deno.test("[path] fromFileUrl", function () { + assertEquals( + path.posix.fromFileUrl(new URL("file:///home/foo")), + "/home/foo" + ); + assertEquals(path.posix.fromFileUrl("file:///home/foo"), "/home/foo"); + assertEquals(path.posix.fromFileUrl("https://example.com/foo"), "/foo"); + assertEquals(path.posix.fromFileUrl("file:///"), "/"); +}); + +Deno.test("[path] fromFileUrl (win32)", function () { + assertEquals( + path.win32.fromFileUrl(new URL("file:///home/foo")), + "\\home\\foo" + ); + assertEquals(path.win32.fromFileUrl("file:///home/foo"), "\\home\\foo"); + assertEquals(path.win32.fromFileUrl("https://example.com/foo"), "\\foo"); + assertEquals(path.win32.fromFileUrl("file:///"), "\\"); + // FIXME(nayeemrmn): Support UNC paths. Needs support in the underlying URL + // built-in like Chrome has. + // assertEquals(path.win32.fromFileUrl("file:////"), "\\"); + // assertEquals(path.win32.fromFileUrl("file:////server"), "\\"); + // assertEquals(path.win32.fromFileUrl("file:////server/file"), "\\file"); + assertEquals(path.win32.fromFileUrl("file:///c"), "\\c"); + assertEquals(path.win32.fromFileUrl("file:///c:"), "\\c:"); + assertEquals(path.win32.fromFileUrl("file:///c:/"), "c:\\"); + assertEquals(path.win32.fromFileUrl("file:///C:/"), "C:\\"); + assertEquals(path.win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\"); + assertEquals( + path.win32.fromFileUrl("file:///C:cwd/another"), + "\\C:cwd\\another" + ); +}); |