diff options
author | skdltmxn <supershop@naver.com> | 2020-05-24 22:10:01 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 09:10:01 -0400 |
commit | f6e31603563bad38c663494ddec6a363989b5786 (patch) | |
tree | 3059f472cbe2616397d97c3b5eec3fbcbf0b7c2f /std/encoding/base64_test.ts | |
parent | 2bbe475dbbd46c505cdb2a5e511caadbd63dd1fd (diff) |
feat(std/encoding): add base64 (#5811)
Diffstat (limited to 'std/encoding/base64_test.ts')
-rw-r--r-- | std/encoding/base64_test.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/std/encoding/base64_test.ts b/std/encoding/base64_test.ts new file mode 100644 index 000000000..bd559140a --- /dev/null +++ b/std/encoding/base64_test.ts @@ -0,0 +1,47 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +const { test } = Deno; +import { assertEquals } from "../testing/asserts.ts"; +import { encode, decode, decodeString } from "./base64.ts"; + +const testsetString = [ + ["", ""], + ["f", "Zg=="], + ["fo", "Zm8="], + ["foo", "Zm9v"], + ["foob", "Zm9vYg=="], + ["fooba", "Zm9vYmE="], + ["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=="], +]; + +test("[encoding/base64] testBase64EncodeString", () => { + for (const [input, output] of testsetString) { + assertEquals(encode(input), output); + } +}); + +test("[encoding/base64] testBase64DecodeString", () => { + for (const [input, output] of testsetString) { + assertEquals(decodeString(output), input); + } +}); + +test("[encoding/base64] testBase64EncodeBinary", () => { + for (const [input, output] of testsetBinary) { + assertEquals(encode(input), output); + } +}); + +test("[encoding/base64] testBase64DecodeBinary", () => { + for (const [input, output] of testsetBinary) { + const outputBinary = new Uint8Array(decode(output as string)); + assertEquals(outputBinary, input as Uint8Array); + } +}); |