diff options
author | timonson <54777088+timonson@users.noreply.github.com> | 2020-10-13 03:12:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-13 12:12:10 +1100 |
commit | 1956cb81372b96bc476e74ab43a62a6e60861277 (patch) | |
tree | 014dd7c132239eab61cceb0d31b6d27304a8ead5 /std/encoding/base64_test.ts | |
parent | 26639b3bac463768c65f7fc40a1c53317549e1eb (diff) |
fix(std/encoding): base64 properly encodes mbc and handles Uint8Arrays (#7807)
Fixes #6094
Fixes #4794
Diffstat (limited to 'std/encoding/base64_test.ts')
-rw-r--r-- | std/encoding/base64_test.ts | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/std/encoding/base64_test.ts b/std/encoding/base64_test.ts index 5fe89410b..65c62f4cd 100644 --- a/std/encoding/base64_test.ts +++ b/std/encoding/base64_test.ts @@ -1,9 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + import { assertEquals } from "../testing/asserts.ts"; -import { decode, decodeString, encode } from "./base64.ts"; +import { decode, encode } from "./base64.ts"; const testsetString = [ ["", ""], + ["ß", "w58="], ["f", "Zg=="], ["fo", "Zm8="], ["foo", "Zm9v"], @@ -12,12 +14,10 @@ const testsetString = [ ["foobar", "Zm9vYmFy"], ]; -const testsetBinary = [ - [new TextEncoder().encode("\x00"), "AA=="], - [new TextEncoder().encode("\x00\x00"), "AAA="], - [new TextEncoder().encode("\x00\x00\x00"), "AAAA"], - [new TextEncoder().encode("\x00\x00\x00\x00"), "AAAAAA=="], -]; +const testsetBinary = testsetString.map(([str, b64]) => [ + new TextEncoder().encode(str), + b64, +]) as Array<[Uint8Array, string]>; Deno.test("[encoding/base64] testBase64EncodeString", () => { for (const [input, output] of testsetString) { @@ -25,21 +25,21 @@ Deno.test("[encoding/base64] testBase64EncodeString", () => { } }); -Deno.test("[encoding/base64] testBase64DecodeString", () => { - for (const [input, output] of testsetString) { - assertEquals(decodeString(output), input); +Deno.test("[encoding/base64] testBase64EncodeBinary", () => { + for (const [input, output] of testsetBinary) { + assertEquals(encode(input), output); } }); -Deno.test("[encoding/base64] testBase64EncodeBinary", () => { +Deno.test("[encoding/base64] testBase64EncodeBinaryBuffer", () => { for (const [input, output] of testsetBinary) { - assertEquals(encode(input), output); + assertEquals(encode(input.buffer), output); } }); Deno.test("[encoding/base64] testBase64DecodeBinary", () => { for (const [input, output] of testsetBinary) { - const outputBinary = new Uint8Array(decode(output as string)); - assertEquals(outputBinary, input as Uint8Array); + const outputBinary = decode(output); + assertEquals(outputBinary, input); } }); |