2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-21 07:39:51 +00:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
|
|
|
import * as path from "@std/path";
|
2023-12-21 07:39:51 +00:00
|
|
|
import { isSamePath } from "./_is_same_path.ts";
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "isSamePath() works correctly for win32",
|
|
|
|
ignore: Deno.build.os !== "windows",
|
|
|
|
fn() {
|
|
|
|
const pairs: (string | URL | boolean)[][] = [
|
|
|
|
["", "", true],
|
|
|
|
["C:\\test", "C:\\test", true],
|
|
|
|
["C:\\test", "C:\\test\\test", false],
|
|
|
|
["C:\\test", path.toFileUrl("C:\\test"), true],
|
|
|
|
["C:\\test", path.toFileUrl("C:\\test\\test"), false],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const p of pairs) {
|
|
|
|
const src = p[0] as string | URL;
|
|
|
|
const dest = p[1] as string | URL;
|
|
|
|
const expected = p[2] as boolean;
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
isSamePath(src, dest),
|
|
|
|
expected,
|
|
|
|
`'${src}' should ${expected ? "" : "not"} be the same as '${dest}'`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "isSamePath() works correctly for posix",
|
|
|
|
ignore: Deno.build.os === "windows",
|
|
|
|
fn() {
|
|
|
|
const pairs: (string | URL | boolean)[][] = [
|
|
|
|
["", "", true],
|
|
|
|
["/test", "/test/", true],
|
|
|
|
["/test", "/test/test", false],
|
|
|
|
["/test", "/test/test/..", true],
|
|
|
|
["/test", path.toFileUrl("/test"), true],
|
|
|
|
["/test", path.toFileUrl("/test/test"), false],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const p of pairs) {
|
|
|
|
const src = p[0] as string | URL;
|
|
|
|
const dest = p[1] as string | URL;
|
|
|
|
const expected = p[2] as boolean;
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
isSamePath(src, dest),
|
|
|
|
expected,
|
|
|
|
`'${src}' should ${expected ? "" : "not"} be the same as '${dest}'`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|