-
Notifications
You must be signed in to change notification settings - Fork 603
/
from_file_url_test.ts
52 lines (50 loc) · 2.22 KB
/
from_file_url_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { posix, win32 } from "./mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
Deno.test("[path] fromFileUrl", function () {
assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo");
assertEquals(posix.fromFileUrl("file:///"), "/");
assertEquals(posix.fromFileUrl("file:///home/foo"), "/home/foo");
assertEquals(posix.fromFileUrl("file:///home/foo%20bar"), "/home/foo bar");
assertEquals(posix.fromFileUrl("file:///%"), "/%");
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/");
assertEquals(posix.fromFileUrl("file:///C:foo/bar"), "/C:foo/bar");
assertThrows(
() => posix.fromFileUrl("http://localhost/foo"),
TypeError,
"Must be a file URL.",
);
assertThrows(
() => posix.fromFileUrl("abcd://localhost/foo"),
TypeError,
"Must be a file URL.",
);
});
Deno.test("[path] fromFileUrl (win32)", function () {
assertEquals(win32.fromFileUrl(new URL("file:///home/foo")), "\\home\\foo");
assertEquals(win32.fromFileUrl("file:///"), "\\");
assertEquals(win32.fromFileUrl("file:///home/foo"), "\\home\\foo");
assertEquals(win32.fromFileUrl("file:///home/foo%20bar"), "\\home\\foo bar");
assertEquals(win32.fromFileUrl("file:///%"), "\\%");
assertEquals(win32.fromFileUrl("file://127.0.0.1/foo"), "\\\\127.0.0.1\\foo");
assertEquals(win32.fromFileUrl("file://localhost/foo"), "\\foo");
assertEquals(win32.fromFileUrl("file:///C:"), "C:\\");
assertEquals(win32.fromFileUrl("file:///C:/"), "C:\\");
// Drop the hostname if a drive letter is parsed.
assertEquals(win32.fromFileUrl("file://localhost/C:/"), "C:\\");
assertEquals(win32.fromFileUrl("file:///C:/Users/"), "C:\\Users\\");
assertEquals(win32.fromFileUrl("file:///C:foo/bar"), "\\C:foo\\bar");
assertThrows(
() => win32.fromFileUrl("http://localhost/foo"),
TypeError,
"Must be a file URL.",
);
assertThrows(
() => win32.fromFileUrl("abcd://localhost/foo"),
TypeError,
"Must be a file URL.",
);
});