2019-04-14 16:14:57 -04:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2019-10-16 14:39:33 -04:00
|
|
|
import * as path from "../path/mod.ts";
|
2019-04-14 16:14:57 -04:00
|
|
|
import { writeFileStr, writeFileStrSync } from "./write_file_str.ts";
|
|
|
|
|
|
|
|
const testdataDir = path.resolve("fs", "testdata");
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
Deno.test("testReadFileSync", function (): void {
|
2019-04-14 16:14:57 -04:00
|
|
|
const jsonFile = path.join(testdataDir, "write_file_1.json");
|
|
|
|
const content = "write_file_str_test";
|
|
|
|
writeFileStrSync(jsonFile, content);
|
|
|
|
|
|
|
|
// make sure file have been create.
|
|
|
|
Deno.statSync(jsonFile);
|
|
|
|
|
|
|
|
const result = new TextDecoder().decode(Deno.readFileSync(jsonFile));
|
|
|
|
|
|
|
|
// remove test file
|
|
|
|
Deno.removeSync(jsonFile);
|
|
|
|
|
|
|
|
assertEquals(content, result);
|
|
|
|
});
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
Deno.test("testReadFile", async function (): Promise<void> {
|
2019-04-14 16:14:57 -04:00
|
|
|
const jsonFile = path.join(testdataDir, "write_file_2.json");
|
|
|
|
const content = "write_file_str_test";
|
|
|
|
await writeFileStr(jsonFile, content);
|
|
|
|
|
|
|
|
// make sure file have been create.
|
|
|
|
await Deno.stat(jsonFile);
|
|
|
|
|
|
|
|
const result = new TextDecoder().decode(await Deno.readFile(jsonFile));
|
|
|
|
|
|
|
|
// remove test file
|
|
|
|
await Deno.remove(jsonFile);
|
|
|
|
|
|
|
|
assertEquals(content, result);
|
|
|
|
});
|