mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
8c509bd885
refactor: Parse URLs more sequentially. This makes it easier to change matching behaviour depending on the protocol. fix: Fail when a host isn't given for certain protocols. fix: Convert back-slashes info forward-slashes.
37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
// 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"
|
|
);
|
|
});
|