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 {
|
2020-04-29 16:00:31 -04:00
|
|
|
name = "";
|
2020-04-16 01:40:30 -04:00
|
|
|
isFile = false;
|
|
|
|
isDirectory = false;
|
|
|
|
isSymlink = false;
|
2020-03-03 08:56:10 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-03 08:56:10 -05:00
|
|
|
name: "Directories are correctly identified",
|
|
|
|
fn() {
|
2020-04-29 16:00:31 -04:00
|
|
|
const entry: DirEntryMock = new DirEntryMock();
|
|
|
|
entry.isDirectory = true;
|
|
|
|
entry.isFile = false;
|
|
|
|
entry.isSymlink = false;
|
|
|
|
assert(new Dirent(entry).isDirectory());
|
|
|
|
assert(!new Dirent(entry).isFile());
|
|
|
|
assert(!new Dirent(entry).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-03 08:56:10 -05:00
|
|
|
name: "Files are correctly identified",
|
|
|
|
fn() {
|
2020-04-29 16:00:31 -04:00
|
|
|
const entry: DirEntryMock = new DirEntryMock();
|
|
|
|
entry.isDirectory = false;
|
|
|
|
entry.isFile = true;
|
|
|
|
entry.isSymlink = false;
|
|
|
|
assert(!new Dirent(entry).isDirectory());
|
|
|
|
assert(new Dirent(entry).isFile());
|
|
|
|
assert(!new Dirent(entry).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-03 08:56:10 -05:00
|
|
|
name: "Symlinks are correctly identified",
|
|
|
|
fn() {
|
2020-04-29 16:00:31 -04:00
|
|
|
const entry: DirEntryMock = new DirEntryMock();
|
|
|
|
entry.isDirectory = false;
|
|
|
|
entry.isFile = false;
|
|
|
|
entry.isSymlink = true;
|
|
|
|
assert(!new Dirent(entry).isDirectory());
|
|
|
|
assert(!new Dirent(entry).isFile());
|
|
|
|
assert(new Dirent(entry).isSymbolicLink());
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-03 08:56:10 -05:00
|
|
|
name: "File name is correct",
|
|
|
|
fn() {
|
2020-04-29 16:00:31 -04:00
|
|
|
const entry: DirEntryMock = new DirEntryMock();
|
|
|
|
entry.name = "my_file";
|
|
|
|
assertEquals(new Dirent(entry).name, "my_file");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2020-03-03 08:56:10 -05:00
|
|
|
name: "Socket and FIFO pipes aren't yet available",
|
|
|
|
fn() {
|
2020-04-29 16:00:31 -04:00
|
|
|
const entry: DirEntryMock = new DirEntryMock();
|
2020-03-03 08:56:10 -05:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
2020-04-29 16:00:31 -04:00
|
|
|
new Dirent(entry).isFIFO();
|
2020-03-03 08:56:10 -05:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"does not yet support"
|
|
|
|
);
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
2020-04-29 16:00:31 -04:00
|
|
|
new Dirent(entry).isSocket();
|
2020-03-03 08:56:10 -05:00
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"does not yet support"
|
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-03-03 08:56:10 -05:00
|
|
|
});
|