2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2018-12-19 02:29:39 +00:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
// Ported from https://github.com/browserify/path-browserify/
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2024-01-03 21:05:20 +00:00
|
|
|
import * as posix from "./posix/mod.ts";
|
|
|
|
import * as windows from "./windows/mod.ts";
|
2024-01-10 21:34:53 +00:00
|
|
|
import { resolve } from "./resolve.ts";
|
2018-12-19 02:29:39 +00:00
|
|
|
|
|
|
|
const windowsTests =
|
|
|
|
// arguments result
|
|
|
|
[
|
|
|
|
[["c:/blah\\blah", "d:/games", "c:../a"], "c:\\blah\\a"],
|
|
|
|
[["c:/ignore", "d:\\a/b\\c/d", "\\e.exe"], "d:\\e.exe"],
|
|
|
|
[["c:/ignore", "c:/some/file"], "c:\\some\\file"],
|
|
|
|
[["d:/ignore", "d:some/dir//"], "d:\\ignore\\some\\dir"],
|
|
|
|
[["//server/share", "..", "relative\\"], "\\\\server\\share\\relative"],
|
|
|
|
[["c:/", "//"], "c:\\"],
|
|
|
|
[["c:/", "//dir"], "c:\\dir"],
|
|
|
|
[["c:/", "//server/share"], "\\\\server\\share\\"],
|
|
|
|
[["c:/", "//server//share"], "\\\\server\\share\\"],
|
|
|
|
[["c:/", "///some//dir"], "c:\\some\\dir"],
|
|
|
|
[
|
|
|
|
["C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"],
|
2020-03-28 17:03:49 +00:00
|
|
|
"C:\\foo\\tmp.3\\cycles\\root.js",
|
|
|
|
],
|
2018-12-19 02:29:39 +00:00
|
|
|
];
|
|
|
|
const posixTests =
|
|
|
|
// arguments result
|
|
|
|
[
|
|
|
|
[["/var/lib", "../", "file/"], "/var/file"],
|
|
|
|
[["/var/lib", "/../", "file/"], "/file"],
|
2020-06-12 19:23:38 +00:00
|
|
|
[["a/b/c/", "../../.."], Deno.cwd()],
|
|
|
|
[["."], Deno.cwd()],
|
2018-12-19 02:29:39 +00:00
|
|
|
[["/some/dir", ".", "/absolute/"], "/absolute"],
|
2020-03-28 17:03:49 +00:00
|
|
|
[["/foo/tmp.3/", "../tmp.3/cycles/root.js"], "/foo/tmp.3/cycles/root.js"],
|
2018-12-19 02:29:39 +00:00
|
|
|
];
|
|
|
|
|
2023-11-01 07:42:29 +00:00
|
|
|
Deno.test("posix.resolve()", function () {
|
2020-03-28 17:03:49 +00:00
|
|
|
posixTests.forEach(function (p) {
|
2019-05-30 12:59:30 +00:00
|
|
|
const _p = p[0] as string[];
|
2024-01-03 21:05:20 +00:00
|
|
|
const actual = posix.resolve.apply(null, _p);
|
2019-03-07 00:42:24 +00:00
|
|
|
assertEquals(actual, p[1]);
|
2018-12-19 02:29:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-01-03 21:05:20 +00:00
|
|
|
Deno.test("windows.resolve()", function () {
|
2020-03-28 17:03:49 +00:00
|
|
|
windowsTests.forEach(function (p) {
|
2019-05-30 12:59:30 +00:00
|
|
|
const _p = p[0] as string[];
|
2024-01-03 21:05:20 +00:00
|
|
|
const actual = windows.resolve.apply(null, _p);
|
2019-03-07 00:42:24 +00:00
|
|
|
assertEquals(actual, p[1]);
|
2018-12-19 02:29:39 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-10 21:34:53 +00:00
|
|
|
|
|
|
|
Deno.test("resolve() returns current working directory if input is empty", function () {
|
|
|
|
const pwd = Deno.cwd();
|
|
|
|
assertEquals(resolve(""), pwd);
|
|
|
|
assertEquals(resolve("", ""), pwd);
|
|
|
|
});
|