2018-12-18 21:29:39 -05:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
// Ported from https://github.com/browserify/path-browserify/
|
|
|
|
|
2020-02-11 11:24:27 -05:00
|
|
|
const { test } = Deno;
|
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 slashRE = /\//g;
|
|
|
|
|
|
|
|
const pairs = [
|
|
|
|
["", ""],
|
|
|
|
["/path/to/file", ""],
|
|
|
|
["/path/to/file.ext", ".ext"],
|
|
|
|
["/path.to/file.ext", ".ext"],
|
|
|
|
["/path.to/file", ""],
|
|
|
|
["/path.to/.file", ""],
|
|
|
|
["/path.to/.file.ext", ".ext"],
|
|
|
|
["/path/to/f.ext", ".ext"],
|
|
|
|
["/path/to/..ext", ".ext"],
|
|
|
|
["/path/to/..", ""],
|
|
|
|
["file", ""],
|
|
|
|
["file.ext", ".ext"],
|
|
|
|
[".file", ""],
|
|
|
|
[".file.ext", ".ext"],
|
|
|
|
["/file", ""],
|
|
|
|
["/file.ext", ".ext"],
|
|
|
|
["/.file", ""],
|
|
|
|
["/.file.ext", ".ext"],
|
|
|
|
[".path/file.ext", ".ext"],
|
|
|
|
["file.ext.ext", ".ext"],
|
|
|
|
["file.", "."],
|
|
|
|
[".", ""],
|
|
|
|
["./", ""],
|
|
|
|
[".file.ext", ".ext"],
|
|
|
|
[".file", ""],
|
|
|
|
[".file.", "."],
|
|
|
|
[".file..", "."],
|
|
|
|
["..", ""],
|
|
|
|
["../", ""],
|
|
|
|
["..file.ext", ".ext"],
|
|
|
|
["..file", ".file"],
|
|
|
|
["..file.", "."],
|
|
|
|
["..file..", "."],
|
|
|
|
["...", "."],
|
|
|
|
["...ext", ".ext"],
|
|
|
|
["....", "."],
|
|
|
|
["file.ext/", ".ext"],
|
|
|
|
["file.ext//", ".ext"],
|
|
|
|
["file/", ""],
|
|
|
|
["file//", ""],
|
|
|
|
["file./", "."],
|
2020-03-28 13:03:49 -04:00
|
|
|
["file.//", "."],
|
2018-12-18 21:29:39 -05:00
|
|
|
];
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
test("extname", function () {
|
2020-03-28 13:03:49 -04:00
|
|
|
pairs.forEach(function (p) {
|
2018-12-18 21:29:39 -05:00
|
|
|
const input = p[0];
|
|
|
|
const expected = p[1];
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(expected, path.posix.extname(input));
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// On *nix, backslash is a valid name component like any other character.
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.posix.extname(".\\"), "");
|
|
|
|
assertEquals(path.posix.extname("..\\"), ".\\");
|
|
|
|
assertEquals(path.posix.extname("file.ext\\"), ".ext\\");
|
|
|
|
assertEquals(path.posix.extname("file.ext\\\\"), ".ext\\\\");
|
|
|
|
assertEquals(path.posix.extname("file\\"), "");
|
|
|
|
assertEquals(path.posix.extname("file\\\\"), "");
|
|
|
|
assertEquals(path.posix.extname("file.\\"), ".\\");
|
|
|
|
assertEquals(path.posix.extname("file.\\\\"), ".\\\\");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
test("extnameWin32", function () {
|
2020-03-28 13:03:49 -04:00
|
|
|
pairs.forEach(function (p) {
|
2018-12-18 21:29:39 -05:00
|
|
|
const input = p[0].replace(slashRE, "\\");
|
|
|
|
const expected = p[1];
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(expected, path.win32.extname(input));
|
|
|
|
assertEquals(expected, path.win32.extname("C:" + input));
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// On Windows, backslash is a path separator.
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.win32.extname(".\\"), "");
|
|
|
|
assertEquals(path.win32.extname("..\\"), "");
|
|
|
|
assertEquals(path.win32.extname("file.ext\\"), ".ext");
|
|
|
|
assertEquals(path.win32.extname("file.ext\\\\"), ".ext");
|
|
|
|
assertEquals(path.win32.extname("file\\"), "");
|
|
|
|
assertEquals(path.win32.extname("file\\\\"), "");
|
|
|
|
assertEquals(path.win32.extname("file.\\"), ".");
|
|
|
|
assertEquals(path.win32.extname("file.\\\\"), ".");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|