2018-12-18 21:29:39 -05:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
// Ported from https://github.com/browserify/path-browserify/
|
|
|
|
|
2019-02-26 00:35:50 -05:00
|
|
|
const { cwd } = Deno;
|
2019-10-16 14:39:33 -04:00
|
|
|
import { test } from "../testing/mod.ts";
|
|
|
|
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 pwd = cwd();
|
|
|
|
|
|
|
|
test(function joinZeroLength() {
|
|
|
|
// join will internally ignore all the zero-length strings and it will return
|
|
|
|
// '.' if the joined string is a zero-length string.
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.posix.join(""), ".");
|
|
|
|
assertEquals(path.posix.join("", ""), ".");
|
|
|
|
if (path.win32) assertEquals(path.win32.join(""), ".");
|
|
|
|
if (path.win32) assertEquals(path.win32.join("", ""), ".");
|
|
|
|
assertEquals(path.join(pwd), pwd);
|
|
|
|
assertEquals(path.join(pwd, ""), pwd);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function normalizeZeroLength() {
|
|
|
|
// normalize will return '.' if the input is a zero-length string
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.posix.normalize(""), ".");
|
|
|
|
if (path.win32) assertEquals(path.win32.normalize(""), ".");
|
|
|
|
assertEquals(path.normalize(pwd), pwd);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function isAbsoluteZeroLength() {
|
2019-10-05 12:02:34 -04:00
|
|
|
// Since '' is not a valid path in any of the common environments,
|
|
|
|
// return false
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.posix.isAbsolute(""), false);
|
|
|
|
if (path.win32) assertEquals(path.win32.isAbsolute(""), false);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function resolveZeroLength() {
|
|
|
|
// resolve, internally ignores all the zero-length strings and returns the
|
|
|
|
// current working directory
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.resolve(""), pwd);
|
|
|
|
assertEquals(path.resolve("", ""), pwd);
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function relativeZeroLength() {
|
2019-10-05 12:02:34 -04:00
|
|
|
// relative, internally calls resolve. So, '' is actually the current
|
|
|
|
// directory
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.relative("", pwd), "");
|
|
|
|
assertEquals(path.relative(pwd, ""), "");
|
|
|
|
assertEquals(path.relative(pwd, pwd), "");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|