diff options
author | timonson <54777088+timonson@users.noreply.github.com> | 2020-06-03 15:44:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 09:44:51 -0400 |
commit | 9a97e61b78fcec4ac9bb3da3e49afd0a2f849b9a (patch) | |
tree | 0a8b5faa4ef53e54509120a53deaa221c2d3d5e9 /std/encoding/base64url_test.ts | |
parent | a1915a0d4fd7d760c234e209967d842f851628d5 (diff) |
feat(std/encoding): add base64url module (#5976)
Diffstat (limited to 'std/encoding/base64url_test.ts')
-rw-r--r-- | std/encoding/base64url_test.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/std/encoding/base64url_test.ts b/std/encoding/base64url_test.ts new file mode 100644 index 000000000..2af9096a4 --- /dev/null +++ b/std/encoding/base64url_test.ts @@ -0,0 +1,42 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +const { test } = Deno; +import { assertEquals } from "../testing/asserts.ts"; +import { encode, decode } from "./base64url.ts"; + +const testsetString = [ + ["", ""], + ["f", "Zg"], + ["fo", "Zm8"], + ["foo", "Zm9v"], + ["foob", "Zm9vYg"], + ["fooba", "Zm9vYmE"], + ["foobar", "Zm9vYmFy"], + [">?>d?ß", "Pj8-ZD_f"], +]; + +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/base64url] testBase64urlEncodeString", () => { + for (const [input, output] of testsetString) { + assertEquals(encode(input), output); + } +}); + +test("[encoding/base64url] testBase64urlEncodeBinary", () => { + for (const [input, output] of testsetBinary) { + assertEquals(encode(input), output); + } +}); + +test("[encoding/base64ur] testBase64urDecodeBinary", () => { + for (const [input, output] of testsetBinary) { + const outputBinary = new Uint8Array(decode(output as string)); + assertEquals(outputBinary, input as Uint8Array); + } +}); |