/
to_file_url_test.ts
68 lines (65 loc) · 2.33 KB
/
to_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { posix, win32 } from "./mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
const isCanary = /\d\.\d\.\d\+[0-9a-f]{7}/.test(Deno.version.deno);
Deno.test("[path] toFileUrl", function () {
assertEquals(posix.toFileUrl("/home/foo").href, "file:///home/foo");
// TODO(kt3k): Enable this assertion again in stable deno when 1.8.0 is landed.
if (isCanary) {
assertEquals(posix.toFileUrl("/home/ ").href, "file:///home/");
}
assertEquals(posix.toFileUrl("/home/%20").href, "file:///home/%2520");
assertEquals(posix.toFileUrl("/home\\foo").href, "file:///home%5Cfoo");
assertThrows(
() => posix.toFileUrl("foo").href,
TypeError,
"Must be an absolute path.",
);
assertThrows(
() => posix.toFileUrl("C:/"),
TypeError,
"Must be an absolute path.",
);
// TODO(kt3k): Enable this assertion again in stable deno when 1.8.0 is landed.
if (isCanary) {
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");
}
});
Deno.test("[path] toFileUrl (win32)", function () {
assertEquals(win32.toFileUrl("/home/foo").href, "file:///home/foo");
// TODO(kt3k): Enable this assertion again in stable deno when 1.8.0 is landed.
if (isCanary) {
assertEquals(win32.toFileUrl("/home/ ").href, "file:///home/");
}
assertEquals(win32.toFileUrl("/home/%20").href, "file:///home/%2520");
assertEquals(win32.toFileUrl("/home\\foo").href, "file:///home/foo");
assertThrows(
() => win32.toFileUrl("foo").href,
TypeError,
"Must be an absolute path.",
);
assertEquals(win32.toFileUrl("C:/").href, "file:///C:/");
// TODO(kt3k): Enable this assertion again in stable deno when 1.8.0 is landed.
if (isCanary) {
assertThrows(
() =>
assertEquals(
win32.toFileUrl("//localhost/home/foo").href,
"file://localhost/home/foo",
),
TypeError,
"Invalid hostname.",
);
assertEquals(win32.toFileUrl("//localhost/").href, "file:///localhost/");
}
assertThrows(
() => win32.toFileUrl("//:/home/foo").href,
TypeError,
"Invalid hostname.",
);
});