1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-04 17:18:23 -05:00
denoland-deno/std/encoding/base64_test.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-05-24 09:10:01 -04:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2020-05-24 09:10:01 -04:00
import { assertEquals } from "../testing/asserts.ts";
import { decode, encode } from "./base64.ts";
2020-05-24 09:10:01 -04:00
const testsetString = [
["", ""],
["ß", "w58="],
2020-05-24 09:10:01 -04:00
["f", "Zg=="],
["fo", "Zm8="],
["foo", "Zm9v"],
["foob", "Zm9vYg=="],
["fooba", "Zm9vYmE="],
["foobar", "Zm9vYmFy"],
];
const testsetBinary = testsetString.map(([str, b64]) => [
new TextEncoder().encode(str),
b64,
]) as Array<[Uint8Array, string]>;
2020-05-24 09:10:01 -04:00
Deno.test("[encoding/base64] testBase64EncodeString", () => {
2020-05-24 09:10:01 -04:00
for (const [input, output] of testsetString) {
assertEquals(encode(input), output);
}
});
Deno.test("[encoding/base64] testBase64EncodeBinary", () => {
for (const [input, output] of testsetBinary) {
assertEquals(encode(input), output);
2020-05-24 09:10:01 -04:00
}
});
Deno.test("[encoding/base64] testBase64EncodeBinaryBuffer", () => {
2020-05-24 09:10:01 -04:00
for (const [input, output] of testsetBinary) {
assertEquals(encode(input.buffer), output);
2020-05-24 09:10:01 -04:00
}
});
Deno.test("[encoding/base64] testBase64DecodeBinary", () => {
2020-05-24 09:10:01 -04:00
for (const [input, output] of testsetBinary) {
const outputBinary = decode(output);
assertEquals(outputBinary, input);
2020-05-24 09:10:01 -04:00
}
});