deno.land / std@0.166.0 / fs / _util_test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Copyright the Browserify authors. MIT License.
import { assertEquals } from "../testing/asserts.ts";import * as path from "../path/mod.ts";import { getFileInfoType, isSubdir, PathType } from "./_util.ts";import { ensureFileSync } from "./ensure_file.ts";import { ensureDirSync } from "./ensure_dir.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));const testdataDir = path.resolve(moduleDir, "testdata");
Deno.test("_isSubdir", function () { 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) { 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 () { const pairs = [ [path.join(testdataDir, "file_type_1"), "file"], [path.join(testdataDir, "file_type_dir_1"), "dir"], ];
pairs.forEach(function (p) { 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); });});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago