2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-01-03 21:05:20 +00:00
|
|
|
import * as posix from "./posix/mod.ts";
|
|
|
|
import * as windows from "./windows/mod.ts";
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals, assertThrows } from "@std/assert";
|
2020-04-29 20:20:55 +00:00
|
|
|
|
2023-11-01 07:42:29 +00:00
|
|
|
Deno.test("posix.fromFileUrl()", function () {
|
2020-06-26 12:34:17 +00:00
|
|
|
assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo");
|
2020-07-30 22:37:26 +00:00
|
|
|
assertEquals(posix.fromFileUrl("file:///"), "/");
|
2020-06-26 12:34:17 +00:00
|
|
|
assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo");
|
2020-07-29 22:23:09 +00:00
|
|
|
assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar");
|
2020-08-21 13:37:06 +00:00
|
|
|
assertEquals(posix.fromFileUrl("file:///%"), "/%");
|
2020-07-30 22:37:26 +00: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-24 01:37:11 +00:00
|
|
|
assertEquals(posix.fromFileUrl("file:///C:foo/bar"), "/C:foo/bar");
|
2020-07-30 22:37:26 +00:00
|
|
|
assertThrows(
|
|
|
|
() => posix.fromFileUrl("http://localhost/foo"),
|
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'URL must be a file URL: received "http:"',
|
2020-07-30 22:37:26 +00:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => posix.fromFileUrl("abcd://localhost/foo"),
|
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'URL must be a file URL: received "abcd:"',
|
2020-07-30 22:37:26 +00:00
|
|
|
);
|
2020-04-29 20:20:55 +00:00
|
|
|
});
|
|
|
|
|
2024-01-03 21:05:20 +00:00
|
|
|
Deno.test("windows.fromFileUrl()", function () {
|
|
|
|
assertEquals(windows.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///"), "\\");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///home/foo"), "\\home\\foo");
|
|
|
|
assertEquals(
|
|
|
|
windows.fromFileUrl("file:///home/foo%20bar"),
|
|
|
|
"\\home\\foo bar",
|
|
|
|
);
|
|
|
|
assertEquals(windows.fromFileUrl("file:///%"), "\\%");
|
|
|
|
assertEquals(
|
|
|
|
windows.fromFileUrl("file://127.0.0.1/foo"),
|
|
|
|
"\\\\127.0.0.1\\foo",
|
|
|
|
);
|
|
|
|
assertEquals(windows.fromFileUrl("file://localhost/foo"), "\\foo");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///C:"), "C:\\");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///C:/"), "C:\\");
|
2020-07-30 22:37:26 +00:00
|
|
|
// Drop the hostname if a drive letter is parsed.
|
2024-01-03 21:05:20 +00:00
|
|
|
assertEquals(windows.fromFileUrl("file://localhost/C:/"), "C:\\");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///C:/Users/"), "C:\\Users\\");
|
|
|
|
assertEquals(windows.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar");
|
2020-07-30 22:37:26 +00:00
|
|
|
assertThrows(
|
2024-01-03 21:05:20 +00:00
|
|
|
() => windows.fromFileUrl("http://localhost/foo"),
|
2020-07-30 22:37:26 +00:00
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'URL must be a file URL: received "http:"',
|
2020-07-30 22:37:26 +00:00
|
|
|
);
|
|
|
|
assertThrows(
|
2024-01-03 21:05:20 +00:00
|
|
|
() => windows.fromFileUrl("abcd://localhost/foo"),
|
2020-07-30 22:37:26 +00:00
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'URL must be a file URL: received "abcd:"',
|
2020-07-30 22:37:26 +00:00
|
|
|
);
|
2020-04-29 20:20:55 +00:00
|
|
|
});
|