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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
const { test } = Deno;
import { assert, assertEquals, assertThrows } from "../../testing/asserts.ts";
import Dirent from "./_fs_dirent.ts";
class FileInfoMock implements Deno.FileInfo {
size = -1;
modified = -1;
accessed = -1;
created = -1;
name = "";
dev = -1;
ino = -1;
mode = -1;
nlink = -1;
uid = -1;
gid = -1;
rdev = -1;
blksize = -1;
blocks: number | null = null;
isFileMock = false;
isDirectoryMock = false;
isSymlinkMock = false;
isFile(): boolean {
return this.isFileMock;
}
isDirectory(): boolean {
return this.isDirectoryMock;
}
isSymlink(): boolean {
return this.isSymlinkMock;
}
}
test({
name: "Block devices are correctly identified",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.blocks = 5;
assert(new Dirent(fileInfo).isBlockDevice());
assert(!new Dirent(fileInfo).isCharacterDevice());
},
});
test({
name: "Character devices are correctly identified",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.blocks = null;
assert(new Dirent(fileInfo).isCharacterDevice());
assert(!new Dirent(fileInfo).isBlockDevice());
},
});
test({
name: "Directories are correctly identified",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.isDirectoryMock = true;
fileInfo.isFileMock = false;
fileInfo.isSymlinkMock = false;
assert(new Dirent(fileInfo).isDirectory());
assert(!new Dirent(fileInfo).isFile());
assert(!new Dirent(fileInfo).isSymbolicLink());
},
});
test({
name: "Files are correctly identified",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.isDirectoryMock = false;
fileInfo.isFileMock = true;
fileInfo.isSymlinkMock = false;
assert(!new Dirent(fileInfo).isDirectory());
assert(new Dirent(fileInfo).isFile());
assert(!new Dirent(fileInfo).isSymbolicLink());
},
});
test({
name: "Symlinks are correctly identified",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.isDirectoryMock = false;
fileInfo.isFileMock = false;
fileInfo.isSymlinkMock = true;
assert(!new Dirent(fileInfo).isDirectory());
assert(!new Dirent(fileInfo).isFile());
assert(new Dirent(fileInfo).isSymbolicLink());
},
});
test({
name: "File name is correct",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
fileInfo.name = "my_file";
assertEquals(new Dirent(fileInfo).name, "my_file");
},
});
test({
name: "Socket and FIFO pipes aren't yet available",
fn() {
const fileInfo: FileInfoMock = new FileInfoMock();
assertThrows(
() => {
new Dirent(fileInfo).isFIFO();
},
Error,
"does not yet support"
);
assertThrows(
() => {
new Dirent(fileInfo).isSocket();
},
Error,
"does not yet support"
);
},
});
|