Skip to content

Commit

Permalink
test(path): update test cases for canary (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Mar 2, 2021
1 parent b134d54 commit 3b0dd8a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
comment: false
codecov:
require_ci_to_pass: true
coverage:
status:
project:
default:
informational: true
7 changes: 6 additions & 1 deletion path/from_file_url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ Deno.test("[path] fromFileUrl", function () {
);
});

const isCanary = /\d\.\d\.\d\+[0-9a-f]{7}/.test(Deno.version.deno);

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://localhost/foo"), "\\\\localhost\\foo");
// TODO(kt3k): Enable this assertion again in stable deno when 1.8.0 is landed.
if (isCanary) {
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.
Expand Down
45 changes: 32 additions & 13 deletions path/to_file_url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
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");
assertEquals(posix.toFileUrl("/home/ ").href, "file:///home/%20");
// 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(
Expand All @@ -17,17 +22,23 @@ Deno.test("[path] toFileUrl", function () {
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");
// 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");
assertEquals(win32.toFileUrl("/home/ ").href, "file:///home/%20");
// 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(
Expand All @@ -36,11 +47,19 @@ Deno.test("[path] toFileUrl (win32)", function () {
"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/");
// 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,
Expand Down

0 comments on commit 3b0dd8a

Please sign in to comment.