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
|
|
|
|
|
|
|
test(function basename() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.basename(".js", ".js"), "");
|
|
|
|
assertEquals(path.basename(""), "");
|
|
|
|
assertEquals(path.basename("/dir/basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.basename("/basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.basename("basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.basename("basename.ext/"), "basename.ext");
|
|
|
|
assertEquals(path.basename("basename.ext//"), "basename.ext");
|
|
|
|
assertEquals(path.basename("aaa/bbb", "/bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("aaa/bbb", "a/bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("aaa/bbb", "bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("aaa/bbb//", "bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("aaa/bbb", "bb"), "b");
|
|
|
|
assertEquals(path.basename("aaa/bbb", "b"), "bb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb", "/bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb", "a/bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb", "bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb//", "bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb", "bb"), "b");
|
|
|
|
assertEquals(path.basename("/aaa/bbb", "b"), "bb");
|
|
|
|
assertEquals(path.basename("/aaa/bbb"), "bbb");
|
|
|
|
assertEquals(path.basename("/aaa/"), "aaa");
|
|
|
|
assertEquals(path.basename("/aaa/b"), "b");
|
|
|
|
assertEquals(path.basename("/a/b"), "b");
|
|
|
|
assertEquals(path.basename("//a"), "a");
|
2018-12-18 21:29:39 -05:00
|
|
|
|
|
|
|
// On unix a backslash is just treated as any other character.
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(
|
|
|
|
path.posix.basename("\\dir\\basename.ext"),
|
|
|
|
"\\dir\\basename.ext"
|
|
|
|
);
|
|
|
|
assertEquals(path.posix.basename("\\basename.ext"), "\\basename.ext");
|
|
|
|
assertEquals(path.posix.basename("basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.posix.basename("basename.ext\\"), "basename.ext\\");
|
|
|
|
assertEquals(path.posix.basename("basename.ext\\\\"), "basename.ext\\\\");
|
|
|
|
assertEquals(path.posix.basename("foo"), "foo");
|
2018-12-18 21:29:39 -05:00
|
|
|
|
|
|
|
// POSIX filenames may include control characters
|
|
|
|
const controlCharFilename = "Icon" + String.fromCharCode(13);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(
|
2018-12-18 21:29:39 -05:00
|
|
|
path.posix.basename("/a/b/" + controlCharFilename),
|
|
|
|
controlCharFilename
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test(function basenameWin32() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.win32.basename("\\dir\\basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("\\basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("basename.ext\\"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("basename.ext\\\\"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("foo"), "foo");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb", "\\bbb"), "bbb");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb", "a\\bbb"), "bbb");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb", "bbb"), "bbb");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb\\\\\\\\", "bbb"), "bbb");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb", "bb"), "b");
|
|
|
|
assertEquals(path.win32.basename("aaa\\bbb", "b"), "bb");
|
|
|
|
assertEquals(path.win32.basename("C:"), "");
|
|
|
|
assertEquals(path.win32.basename("C:."), ".");
|
|
|
|
assertEquals(path.win32.basename("C:\\"), "");
|
|
|
|
assertEquals(path.win32.basename("C:\\dir\\base.ext"), "base.ext");
|
|
|
|
assertEquals(path.win32.basename("C:\\basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("C:basename.ext"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("C:basename.ext\\"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("C:basename.ext\\\\"), "basename.ext");
|
|
|
|
assertEquals(path.win32.basename("C:foo"), "foo");
|
|
|
|
assertEquals(path.win32.basename("file:stream"), "file:stream");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|