2020-05-20 02:50:48 -04:00
|
|
|
import { readFile } from "./_fs_readFile.ts";
|
|
|
|
import * as path from "../../../path/mod.ts";
|
|
|
|
import { assertEquals, assert } from "../../../testing/asserts.ts";
|
|
|
|
|
|
|
|
const testData = path.resolve(
|
|
|
|
path.join("node", "_fs", "testdata", "hello.txt")
|
|
|
|
);
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("readFileSuccess", async function () {
|
2020-05-20 02:50:48 -04:00
|
|
|
const data = await readFile(testData);
|
|
|
|
|
|
|
|
assert(data instanceof Uint8Array);
|
|
|
|
assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("readFileEncodeUtf8Success", async function () {
|
2020-05-20 02:50:48 -04:00
|
|
|
const data = await readFile(testData, { encoding: "utf8" });
|
|
|
|
|
|
|
|
assertEquals(typeof data, "string");
|
|
|
|
assertEquals(data as string, "hello world");
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("readFileEncodingAsString", async function () {
|
2020-05-20 02:50:48 -04:00
|
|
|
const data = await readFile(testData, "utf8");
|
|
|
|
|
|
|
|
assertEquals(typeof data, "string");
|
|
|
|
assertEquals(data as string, "hello world");
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("readFileError", async function () {
|
2020-05-20 02:50:48 -04:00
|
|
|
try {
|
|
|
|
await readFile("invalid-file", "utf8");
|
|
|
|
} catch (e) {
|
|
|
|
assert(e instanceof Deno.errors.NotFound);
|
|
|
|
}
|
|
|
|
});
|