2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-08-07 07:45:33 +00:00
|
|
|
|
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-10-19 12:36:53 +00:00
|
|
|
|
2023-11-01 07:42:29 +00:00
|
|
|
Deno.test("posix.toFileUrl()", function () {
|
2020-10-19 12:36:53 +00:00
|
|
|
assertEquals(posix.toFileUrl("/home/foo").href, "file:///home/foo");
|
2021-03-15 12:09:18 +00:00
|
|
|
assertEquals(posix.toFileUrl("/home/ ").href, "file:///home/%20");
|
2020-10-19 12:36:53 +00:00
|
|
|
assertEquals(posix.toFileUrl("/home/%20").href, "file:///home/%2520");
|
|
|
|
assertEquals(posix.toFileUrl("/home\\foo").href, "file:///home%5Cfoo");
|
|
|
|
assertThrows(
|
|
|
|
() => posix.toFileUrl("foo").href,
|
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'Path must be absolute: received "foo"',
|
2020-10-19 12:36:53 +00:00
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => posix.toFileUrl("C:/"),
|
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'Path must be absolute: received "C:/"',
|
2020-10-19 12:36:53 +00:00
|
|
|
);
|
2021-03-15 12:09:18 +00:00
|
|
|
assertEquals(
|
|
|
|
posix.toFileUrl("//localhost/home/foo").href,
|
|
|
|
"file:///localhost/home/foo",
|
|
|
|
);
|
|
|
|
assertEquals(posix.toFileUrl("//localhost/").href, "file:///localhost/");
|
|
|
|
assertEquals(posix.toFileUrl("//:/home/foo").href, "file:///:/home/foo");
|
2020-10-19 12:36:53 +00:00
|
|
|
});
|
|
|
|
|
2024-01-03 21:05:20 +00:00
|
|
|
Deno.test("windows.toFileUrl()", function () {
|
|
|
|
assertEquals(windows.toFileUrl("/home/foo").href, "file:///home/foo");
|
|
|
|
assertEquals(windows.toFileUrl("/home/ ").href, "file:///home/%20");
|
|
|
|
assertEquals(windows.toFileUrl("/home/%20").href, "file:///home/%2520");
|
|
|
|
assertEquals(windows.toFileUrl("/home\\foo").href, "file:///home/foo");
|
2020-10-19 12:36:53 +00:00
|
|
|
assertThrows(
|
2024-01-03 21:05:20 +00:00
|
|
|
() => windows.toFileUrl("foo").href,
|
2020-10-19 12:36:53 +00:00
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'Path must be absolute: received "foo"',
|
2020-10-19 12:36:53 +00:00
|
|
|
);
|
2024-01-03 21:05:20 +00:00
|
|
|
assertEquals(windows.toFileUrl("C:/").href, "file:///C:/");
|
2021-03-15 12:09:18 +00:00
|
|
|
assertEquals(
|
2024-01-03 21:05:20 +00:00
|
|
|
windows.toFileUrl("//localhost/home/foo").href,
|
2021-03-15 12:09:18 +00:00
|
|
|
"file:///home/foo",
|
|
|
|
);
|
|
|
|
assertEquals(
|
2024-01-03 21:05:20 +00:00
|
|
|
windows.toFileUrl("//127.0.0.1/home/foo").href,
|
2021-03-15 12:09:18 +00:00
|
|
|
"file://127.0.0.1/home/foo",
|
|
|
|
);
|
2024-01-03 21:05:20 +00:00
|
|
|
assertEquals(windows.toFileUrl("//localhost/").href, "file:///");
|
|
|
|
assertEquals(windows.toFileUrl("//127.0.0.1/").href, "file://127.0.0.1/");
|
2020-10-19 12:36:53 +00:00
|
|
|
assertThrows(
|
2024-01-03 21:05:20 +00:00
|
|
|
() => windows.toFileUrl("//:/home/foo").href,
|
2020-10-19 12:36:53 +00:00
|
|
|
TypeError,
|
2024-08-23 03:31:01 +00:00
|
|
|
'Invalid hostname: ""',
|
2020-10-19 12:36:53 +00:00
|
|
|
);
|
|
|
|
});
|