1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/std/fs/utils_test.ts
Bartek Iwańczuk 8feb30e325
BREAKING: remove overload of Deno.test() (#4951)
This commit removes overload of Deno.test() that accepted named
function.
2020-04-28 12:33:09 +02:00

63 lines
1.8 KiB
TypeScript

// Copyright the Browserify authors. MIT License.
import { assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { isSubdir, getFileInfoType, PathType } from "./utils.ts";
import { ensureFileSync } from "./ensure_file.ts";
import { ensureDirSync } from "./ensure_dir.ts";
const testdataDir = path.resolve("fs", "testdata");
Deno.test("_isSubdir", function (): void {
const pairs = [
["", "", false, path.posix.sep],
["/first/second", "/first", false, path.posix.sep],
["/first", "/first", false, path.posix.sep],
["/first", "/first/second", true, path.posix.sep],
["first", "first/second", true, path.posix.sep],
["../first", "../first/second", true, path.posix.sep],
["c:\\first", "c:\\first", false, path.win32.sep],
["c:\\first", "c:\\first\\second", true, path.win32.sep],
];
pairs.forEach(function (p): void {
const src = p[0] as string;
const dest = p[1] as string;
const expected = p[2] as boolean;
const sep = p[3] as string;
assertEquals(
isSubdir(src, dest, sep),
expected,
`'${src}' should ${expected ? "" : "not"} be parent dir of '${dest}'`
);
});
});
Deno.test("_getFileInfoType", function (): void {
const pairs = [
[path.join(testdataDir, "file_type_1"), "file"],
[path.join(testdataDir, "file_type_dir_1"), "dir"],
];
pairs.forEach(function (p): void {
const filePath = p[0] as string;
const type = p[1] as PathType;
switch (type) {
case "file":
ensureFileSync(filePath);
break;
case "dir":
ensureDirSync(filePath);
break;
case "symlink":
// TODO(axetroy): test symlink
break;
}
const stat = Deno.statSync(filePath);
Deno.removeSync(filePath, { recursive: true });
assertEquals(getFileInfoType(stat), type);
});
});