2020-04-29 16:20:55 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-06-26 08:34:17 -04:00
|
|
|
import { posix, win32 } from "./mod.ts";
|
2020-07-30 18:37:26 -04:00
|
|
|
import { assertEquals, assertThrows } from "../testing/asserts.ts";
|
2020-04-29 16:20:55 -04:00
|
|
|
|
|
|
|
Deno.test("[path] fromFileUrl", function () {
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file:///"), "/");
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo");
|
2020-07-29 18:23:09 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar");
|
2020-08-21 09:37:06 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file:///%"), "/%");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file://localhost/foo"), "/foo");
|
|
|
|
assertEquals(posix.fromFileUrl("file:///C:"), "/C:");
|
|
|
|
assertEquals(posix.fromFileUrl("file:///C:/"), "/C:/");
|
|
|
|
assertEquals(posix.fromFileUrl("file:///C:/Users/"), "/C:/Users/");
|
2020-07-23 21:37:11 -04:00
|
|
|
assertEquals(posix.fromFileUrl("file:///C:foo/bar"), "/C:foo/bar");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertThrows(
|
|
|
|
() => posix.fromFileUrl("http://localhost/foo"),
|
|
|
|
TypeError,
|
|
|
|
"Must be a file URL.",
|
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => posix.fromFileUrl("abcd://localhost/foo"),
|
|
|
|
TypeError,
|
|
|
|
"Must be a file URL.",
|
|
|
|
);
|
2020-04-29 16:20:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("[path] fromFileUrl (win32)", function () {
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(win32.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///"), "\\");
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///home/foo"), "\\home\\foo");
|
2020-07-29 18:23:09 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///home/foo%20bar"), "\\home\\foo bar");
|
2020-08-21 09:37:06 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///%"), "\\%");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file://localhost/foo"), "\\\\localhost\\foo");
|
|
|
|
assertEquals(win32.fromFileUrl("file:///C:"), "C:\\");
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///C:/"), "C:\\");
|
2020-07-30 18:37:26 -04:00
|
|
|
// Drop the hostname if a drive letter is parsed.
|
|
|
|
assertEquals(win32.fromFileUrl("file://localhost/C:/"), "C:\\");
|
2020-06-26 08:34:17 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\");
|
2020-07-23 21:37:11 -04:00
|
|
|
assertEquals(win32.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar");
|
2020-07-30 18:37:26 -04:00
|
|
|
assertThrows(
|
|
|
|
() => win32.fromFileUrl("http://localhost/foo"),
|
|
|
|
TypeError,
|
|
|
|
"Must be a file URL.",
|
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => win32.fromFileUrl("abcd://localhost/foo"),
|
|
|
|
TypeError,
|
|
|
|
"Must be a file URL.",
|
|
|
|
);
|
2020-04-29 16:20:55 -04:00
|
|
|
});
|