2018-12-18 21:29:39 -05:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
// Ported from https://github.com/browserify/path-browserify/
|
2019-10-16 14:39:33 -04:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2019-01-10 17:11:44 -05:00
|
|
|
import * as path from "./mod.ts";
|
2018-12-18 21:29:39 -05: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 13:03:49 -04:00
|
|
|
"C:\\foo\\tmp.3\\cycles\\root.js",
|
|
|
|
],
|
2018-12-18 21:29:39 -05:00
|
|
|
];
|
|
|
|
const posixTests =
|
|
|
|
// arguments result
|
|
|
|
[
|
|
|
|
[["/var/lib", "../", "file/"], "/var/file"],
|
|
|
|
[["/var/lib", "/../", "file/"], "/file"],
|
2020-06-12 15:23:38 -04:00
|
|
|
[["a/b/c/", "../../.."], Deno.cwd()],
|
|
|
|
[["."], Deno.cwd()],
|
2018-12-18 21:29:39 -05:00
|
|
|
[["/some/dir", ".", "/absolute/"], "/absolute"],
|
2020-03-28 13:03:49 -04:00
|
|
|
[["/foo/tmp.3/", "../tmp.3/cycles/root.js"], "/foo/tmp.3/cycles/root.js"],
|
2018-12-18 21:29:39 -05:00
|
|
|
];
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("resolve", function () {
|
2020-03-28 13:03:49 -04:00
|
|
|
posixTests.forEach(function (p) {
|
2019-05-30 08:59:30 -04:00
|
|
|
const _p = p[0] as string[];
|
|
|
|
const actual = path.posix.resolve.apply(null, _p);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(actual, p[1]);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("resolveWin32", function () {
|
2020-03-28 13:03:49 -04:00
|
|
|
windowsTests.forEach(function (p) {
|
2019-05-30 08:59:30 -04:00
|
|
|
const _p = p[0] as string[];
|
|
|
|
const actual = path.win32.resolve.apply(null, _p);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(actual, p[1]);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
});
|