summaryrefslogtreecommitdiff
path: root/std/path/to_file_url_test.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-10-19 13:36:53 +0100
committerGitHub <noreply@github.com>2020-10-19 14:36:53 +0200
commit19b918d112c786b1db17fe2d83be79f1114ba240 (patch)
treeb8ae7e1f5aa4b70570245b61c504c5c46e2e78e8 /std/path/to_file_url_test.ts
parent342b151b5d9d6c97926588dd118b59032f3b0e40 (diff)
feat(std/path): Add toFileUrl() (#7971)
Diffstat (limited to 'std/path/to_file_url_test.ts')
-rw-r--r--std/path/to_file_url_test.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/std/path/to_file_url_test.ts b/std/path/to_file_url_test.ts
new file mode 100644
index 000000000..6d0ca8d80
--- /dev/null
+++ b/std/path/to_file_url_test.ts
@@ -0,0 +1,49 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import { posix, win32 } from "./mod.ts";
+import { assertEquals, assertThrows } from "../testing/asserts.ts";
+
+Deno.test("[path] toFileUrl", function () {
+ assertEquals(posix.toFileUrl("/home/foo").href, "file:///home/foo");
+ assertEquals(posix.toFileUrl("/home/ ").href, "file:///home/%20");
+ 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.",
+ );
+ 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");
+ assertEquals(win32.toFileUrl("/home/ ").href, "file:///home/%20");
+ 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:/");
+ assertEquals(
+ win32.toFileUrl("//localhost/home/foo").href,
+ "file://localhost/home/foo",
+ );
+ assertEquals(win32.toFileUrl("//localhost/").href, "file:////localhost/");
+ assertThrows(
+ () => win32.toFileUrl("//:/home/foo").href,
+ TypeError,
+ "Invalid hostname.",
+ );
+});