2020-06-03 09:44:51 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-10-12 21:12:10 -04:00
|
|
|
|
2020-06-03 09:44:51 -04:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2020-09-27 06:22:32 -04:00
|
|
|
import { decode, encode } from "./base64url.ts";
|
2020-06-03 09:44:51 -04:00
|
|
|
|
|
|
|
const testsetString = [
|
|
|
|
["", ""],
|
2020-10-12 21:12:10 -04:00
|
|
|
["ß", "w58"],
|
2020-06-03 09:44:51 -04:00
|
|
|
["f", "Zg"],
|
|
|
|
["fo", "Zm8"],
|
|
|
|
["foo", "Zm9v"],
|
|
|
|
["foob", "Zm9vYg"],
|
|
|
|
["fooba", "Zm9vYmE"],
|
|
|
|
["foobar", "Zm9vYmFy"],
|
2020-10-12 21:12:10 -04:00
|
|
|
[">?>d?ß", "Pj8-ZD_Dnw"],
|
2020-06-03 09:44:51 -04:00
|
|
|
];
|
|
|
|
|
2020-10-12 21:12:10 -04:00
|
|
|
const testsetBinary = testsetString.map(([str, b64]) => [
|
|
|
|
new TextEncoder().encode(str),
|
|
|
|
b64,
|
|
|
|
]) as Array<[Uint8Array, string]>;
|
2020-06-03 09:44:51 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => {
|
2020-06-03 09:44:51 -04:00
|
|
|
for (const [input, output] of testsetBinary) {
|
|
|
|
assertEquals(encode(input), output);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-12 21:12:10 -04:00
|
|
|
Deno.test("[decoding/base64url] testBase64urlDecodeBinary", () => {
|
2020-06-03 09:44:51 -04:00
|
|
|
for (const [input, output] of testsetBinary) {
|
2020-10-12 21:12:10 -04:00
|
|
|
assertEquals(decode(output), input);
|
2020-06-03 09:44:51 -04:00
|
|
|
}
|
|
|
|
});
|