1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-31 19:44:10 -05:00
denoland-deno/fs/path/dirname_test.ts

63 lines
2.5 KiB
TypeScript
Raw Normal View History

// 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";
import { assertEq } from "../../testing/asserts.ts";
2019-01-10 17:11:44 -05:00
import * as path from "./mod.ts";
test(function dirname() {
2019-03-06 16:39:50 -05:00
assertEq(path.posix.dirname("/a/b/"), "/a");
assertEq(path.posix.dirname("/a/b"), "/a");
assertEq(path.posix.dirname("/a"), "/");
assertEq(path.posix.dirname(""), ".");
assertEq(path.posix.dirname("/"), "/");
assertEq(path.posix.dirname("////"), "/");
assertEq(path.posix.dirname("//a"), "//");
assertEq(path.posix.dirname("foo"), ".");
});
test(function dirnameWin32() {
2019-03-06 16:39:50 -05:00
assertEq(path.win32.dirname("c:\\"), "c:\\");
assertEq(path.win32.dirname("c:\\foo"), "c:\\");
assertEq(path.win32.dirname("c:\\foo\\"), "c:\\");
assertEq(path.win32.dirname("c:\\foo\\bar"), "c:\\foo");
assertEq(path.win32.dirname("c:\\foo\\bar\\"), "c:\\foo");
assertEq(path.win32.dirname("c:\\foo\\bar\\baz"), "c:\\foo\\bar");
assertEq(path.win32.dirname("\\"), "\\");
assertEq(path.win32.dirname("\\foo"), "\\");
assertEq(path.win32.dirname("\\foo\\"), "\\");
assertEq(path.win32.dirname("\\foo\\bar"), "\\foo");
assertEq(path.win32.dirname("\\foo\\bar\\"), "\\foo");
assertEq(path.win32.dirname("\\foo\\bar\\baz"), "\\foo\\bar");
assertEq(path.win32.dirname("c:"), "c:");
assertEq(path.win32.dirname("c:foo"), "c:");
assertEq(path.win32.dirname("c:foo\\"), "c:");
assertEq(path.win32.dirname("c:foo\\bar"), "c:foo");
assertEq(path.win32.dirname("c:foo\\bar\\"), "c:foo");
assertEq(path.win32.dirname("c:foo\\bar\\baz"), "c:foo\\bar");
assertEq(path.win32.dirname("file:stream"), ".");
assertEq(path.win32.dirname("dir\\file:stream"), "dir");
assertEq(path.win32.dirname("\\\\unc\\share"), "\\\\unc\\share");
assertEq(path.win32.dirname("\\\\unc\\share\\foo"), "\\\\unc\\share\\");
assertEq(path.win32.dirname("\\\\unc\\share\\foo\\"), "\\\\unc\\share\\");
assertEq(
path.win32.dirname("\\\\unc\\share\\foo\\bar"),
"\\\\unc\\share\\foo"
);
2019-03-06 16:39:50 -05:00
assertEq(
path.win32.dirname("\\\\unc\\share\\foo\\bar\\"),
"\\\\unc\\share\\foo"
);
2019-03-06 16:39:50 -05:00
assertEq(
path.win32.dirname("\\\\unc\\share\\foo\\bar\\baz"),
"\\\\unc\\share\\foo\\bar"
);
2019-03-06 16:39:50 -05:00
assertEq(path.win32.dirname("/a/b/"), "/a");
assertEq(path.win32.dirname("/a/b"), "/a");
assertEq(path.win32.dirname("/a"), "/");
assertEq(path.win32.dirname(""), ".");
assertEq(path.win32.dirname("/"), "/");
assertEq(path.win32.dirname("////"), "/");
assertEq(path.win32.dirname("foo"), ".");
});