2020-03-03 08:56:10 -05:00
|
|
|
const { test } = Deno;
|
2020-03-12 10:12:27 -04:00
|
|
|
import { assert, assertEquals, assertThrows } from "../../testing/asserts.ts";
|
2020-03-03 08:56:10 -05:00
|
|
|
import Dirent from "./_fs_dirent.ts";
|
|
|
|
|
2020-04-16 01:40:30 -04:00
|
|
|
class DirEntryMock implements Deno.DirEntry {
|
|
|
|
isFile = false;
|
|
|
|
isDirectory = false;
|
|
|
|
isSymlink = false;
|
2020-03-14 22:57:42 -04:00
|
|
|
size = -1;
|
2020-04-27 14:09:56 -04:00
|
|
|
mtime = new Date(-1);
|
|
|
|
atime = new Date(-1);
|
|
|
|
birthtime = new Date(-1);
|
2020-03-03 08:56:10 -05:00
|
|
|
name = "";
|
|
|
|
dev = -1;
|
|
|
|
ino = -1;
|
|
|
|
mode = -1;
|
|
|
|
nlink = -1;
|
|
|
|
uid = -1;
|
|
|
|
gid = -1;
|
|
|
|
rdev = -1;
|
|
|
|
blksize = -1;
|
|
|
|
blocks: number | null = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Block devices are correctly identified",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
2020-03-03 08:56:10 -05:00
|
|
|
fileInfo.blocks = 5;
|
|
|
|
assert(new Dirent(fileInfo).isBlockDevice());
|
|
|
|
assert(!new Dirent(fileInfo).isCharacterDevice());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Character devices are correctly identified",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
2020-03-03 08:56:10 -05:00
|
|
|
fileInfo.blocks = null;
|
|
|
|
assert(new Dirent(fileInfo).isCharacterDevice());
|
|
|
|
assert(!new Dirent(fileInfo).isBlockDevice());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Directories are correctly identified",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
|
|
|
fileInfo.isDirectory = true;
|
|
|
|
fileInfo.isFile = false;
|
|
|
|
fileInfo.isSymlink = false;
|
2020-03-03 08:56:10 -05:00
|
|
|
assert(new Dirent(fileInfo).isDirectory());
|
|
|
|
assert(!new Dirent(fileInfo).isFile());
|
|
|
|
assert(!new Dirent(fileInfo).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Files are correctly identified",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
|
|
|
fileInfo.isDirectory = false;
|
|
|
|
fileInfo.isFile = true;
|
|
|
|
fileInfo.isSymlink = false;
|
2020-03-03 08:56:10 -05:00
|
|
|
assert(!new Dirent(fileInfo).isDirectory());
|
|
|
|
assert(new Dirent(fileInfo).isFile());
|
|
|
|
assert(!new Dirent(fileInfo).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Symlinks are correctly identified",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
|
|
|
fileInfo.isDirectory = false;
|
|
|
|
fileInfo.isFile = false;
|
|
|
|
fileInfo.isSymlink = true;
|
2020-03-03 08:56:10 -05:00
|
|
|
assert(!new Dirent(fileInfo).isDirectory());
|
|
|
|
assert(!new Dirent(fileInfo).isFile());
|
|
|
|
assert(new Dirent(fileInfo).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "File name is correct",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
2020-03-03 08:56:10 -05:00
|
|
|
fileInfo.name = "my_file";
|
|
|
|
assertEquals(new Dirent(fileInfo).name, "my_file");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
name: "Socket and FIFO pipes aren't yet available",
|
|
|
|
fn() {
|
2020-04-16 01:40:30 -04:00
|
|
|
const fileInfo: DirEntryMock = new DirEntryMock();
|
2020-03-03 08:56:10 -05:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
new Dirent(fileInfo).isFIFO();
|
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"does not yet support"
|
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
new Dirent(fileInfo).isSocket();
|
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"does not yet support"
|
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|