2018-12-18 21:29:39 -05:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
// Ported from https://github.com/browserify/path-browserify/
|
|
|
|
|
2019-03-06 16:39:50 -05:00
|
|
|
import { test } from "../../testing/mod.ts";
|
2019-03-06 19:42:24 -05: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 dirname() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.posix.dirname("/a/b/"), "/a");
|
|
|
|
assertEquals(path.posix.dirname("/a/b"), "/a");
|
|
|
|
assertEquals(path.posix.dirname("/a"), "/");
|
|
|
|
assertEquals(path.posix.dirname(""), ".");
|
|
|
|
assertEquals(path.posix.dirname("/"), "/");
|
|
|
|
assertEquals(path.posix.dirname("////"), "/");
|
|
|
|
assertEquals(path.posix.dirname("//a"), "//");
|
|
|
|
assertEquals(path.posix.dirname("foo"), ".");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function dirnameWin32() {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.win32.dirname("c:\\"), "c:\\");
|
|
|
|
assertEquals(path.win32.dirname("c:\\foo"), "c:\\");
|
|
|
|
assertEquals(path.win32.dirname("c:\\foo\\"), "c:\\");
|
|
|
|
assertEquals(path.win32.dirname("c:\\foo\\bar"), "c:\\foo");
|
|
|
|
assertEquals(path.win32.dirname("c:\\foo\\bar\\"), "c:\\foo");
|
|
|
|
assertEquals(path.win32.dirname("c:\\foo\\bar\\baz"), "c:\\foo\\bar");
|
|
|
|
assertEquals(path.win32.dirname("\\"), "\\");
|
|
|
|
assertEquals(path.win32.dirname("\\foo"), "\\");
|
|
|
|
assertEquals(path.win32.dirname("\\foo\\"), "\\");
|
|
|
|
assertEquals(path.win32.dirname("\\foo\\bar"), "\\foo");
|
|
|
|
assertEquals(path.win32.dirname("\\foo\\bar\\"), "\\foo");
|
|
|
|
assertEquals(path.win32.dirname("\\foo\\bar\\baz"), "\\foo\\bar");
|
|
|
|
assertEquals(path.win32.dirname("c:"), "c:");
|
|
|
|
assertEquals(path.win32.dirname("c:foo"), "c:");
|
|
|
|
assertEquals(path.win32.dirname("c:foo\\"), "c:");
|
|
|
|
assertEquals(path.win32.dirname("c:foo\\bar"), "c:foo");
|
|
|
|
assertEquals(path.win32.dirname("c:foo\\bar\\"), "c:foo");
|
|
|
|
assertEquals(path.win32.dirname("c:foo\\bar\\baz"), "c:foo\\bar");
|
|
|
|
assertEquals(path.win32.dirname("file:stream"), ".");
|
|
|
|
assertEquals(path.win32.dirname("dir\\file:stream"), "dir");
|
|
|
|
assertEquals(path.win32.dirname("\\\\unc\\share"), "\\\\unc\\share");
|
|
|
|
assertEquals(path.win32.dirname("\\\\unc\\share\\foo"), "\\\\unc\\share\\");
|
|
|
|
assertEquals(path.win32.dirname("\\\\unc\\share\\foo\\"), "\\\\unc\\share\\");
|
|
|
|
assertEquals(
|
2018-12-18 21:29:39 -05:00
|
|
|
path.win32.dirname("\\\\unc\\share\\foo\\bar"),
|
|
|
|
"\\\\unc\\share\\foo"
|
|
|
|
);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(
|
2018-12-18 21:29:39 -05:00
|
|
|
path.win32.dirname("\\\\unc\\share\\foo\\bar\\"),
|
|
|
|
"\\\\unc\\share\\foo"
|
|
|
|
);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(
|
2018-12-18 21:29:39 -05:00
|
|
|
path.win32.dirname("\\\\unc\\share\\foo\\bar\\baz"),
|
|
|
|
"\\\\unc\\share\\foo\\bar"
|
|
|
|
);
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(path.win32.dirname("/a/b/"), "/a");
|
|
|
|
assertEquals(path.win32.dirname("/a/b"), "/a");
|
|
|
|
assertEquals(path.win32.dirname("/a"), "/");
|
|
|
|
assertEquals(path.win32.dirname(""), ".");
|
|
|
|
assertEquals(path.win32.dirname("/"), "/");
|
|
|
|
assertEquals(path.win32.dirname("////"), "/");
|
|
|
|
assertEquals(path.win32.dirname("foo"), ".");
|
2018-12-18 21:29:39 -05:00
|
|
|
});
|