diff options
Diffstat (limited to 'std/node/_fs/promises/_fs_writeFile_test.ts')
-rw-r--r-- | std/node/_fs/promises/_fs_writeFile_test.ts | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/std/node/_fs/promises/_fs_writeFile_test.ts b/std/node/_fs/promises/_fs_writeFile_test.ts index 777971046..8f6ef0842 100644 --- a/std/node/_fs/promises/_fs_writeFile_test.ts +++ b/std/node/_fs/promises/_fs_writeFile_test.ts @@ -6,6 +6,7 @@ import { assertThrowsAsync, } from "../../../testing/asserts.ts"; import { writeFile } from "./_fs_writeFile.ts"; +import { TextEncodings } from "../_fs_common.ts"; const decoder = new TextDecoder("utf-8"); @@ -35,19 +36,10 @@ Deno.test( function testUnsupportedEncoding() { assertThrowsAsync( async () => { - await writeFile("some/path", "some data", "hex"); + await writeFile("some/path", "some data", "utf16le"); }, Error, - `Not implemented: "hex" encoding` - ); - assertThrowsAsync( - async () => { - await writeFile("some/path", "some data", { - encoding: "base64", - }); - }, - Error, - `Not implemented: "base64" encoding` + `Not implemented: "utf16le" encoding` ); } ); @@ -85,6 +77,32 @@ Deno.test( } ); +Deno.test( + "Data is written to correct file encodings", + async function testCorrectWritePromiseUsingDifferentEncodings() { + const encodings = [ + ["hex", "68656c6c6f20776f726c64"], + ["HEX", "68656c6c6f20776f726c64"], + ["base64", "aGVsbG8gd29ybGQ="], + ["BASE64", "aGVsbG8gd29ybGQ="], + ["utf8", "hello world"], + ["utf-8", "hello world"], + ]; + + for (const [encoding, value] of encodings) { + await writeFile( + "_fs_writeFile_test_file.txt", + value, + encoding as TextEncodings + ); + + const data = await Deno.readFile("_fs_writeFile_test_file.txt"); + await Deno.remove("_fs_writeFile_test_file.txt"); + assertEquals(decoder.decode(data), "hello world"); + } + } +); + Deno.test("Mode is correctly set", async function testCorrectFileMode() { if (Deno.build.os === "windows") return; const filename = "_fs_writeFile_test_file.txt"; |