// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
-import { a2b, b2a, isBase64 } from "./base64.js";
import {
assert,
assertEquals,
assertStrictEquals,
assertThrows,
+ describe,
+ it,
} from "./dev-deps.js";
+import { a2b, b2a, isBase64 } from "./base64.js";
const base64s = {
"AGIAYQBzAGUANgA0": "base64",
),
};
-Deno.test({
- name: "Calling b2a returns the correct string.",
- fn: () =>
- Object.entries(base64s).forEach(([key, value]) =>
- assertStrictEquals(b2a(value), key)
- ),
-});
-
-Deno.test({
- name: "Calling a2b returns the correct data.",
- fn: () => {
+describe("a2b", () => {
+ it("[[Call]] returns the correct data", () => {
assertEquals(
a2b("AGIAYQBzAGUANgA0"),
new Uint8Array(
($) => $.charCodeAt(0),
),
).buffer,
+ "AGIAYQBzAGUANgA0",
);
assertEquals(
a2b("R/Q="),
new Uint16Array([62535]).buffer,
+ "R/Q=",
);
assertEquals(
a2b("S0lCSQ=="),
new Uint8ClampedArray([75, 73, 66, 73]).buffer,
+ "S0lCSQ==",
);
assertEquals(
a2b("YmFzZTY0"),
new Uint8Array([98, 97, 115, 101, 54, 52]).buffer,
+ "YmFzZTY0",
);
- },
-});
+ });
-Deno.test({
- name: "Calling a2b throws when provided with an invalid character.",
- fn: () => assertThrows(() => a2b("abc_")),
-});
+ it("[[Call]] throws when provided with an invalid character", () => {
+ assertThrows(() => a2b("abc_"));
+ });
-Deno.test({
- name: "Calling a2b throws when provided with an invalid equals.",
- fn: () => assertThrows(() => a2b("abc==")),
-});
+ it("[[Call]] throws when provided with an invalid equals", () => {
+ assertThrows(() => a2b("abc=="));
+ });
-Deno.test({
- name:
- "Calling a2b throws when provided with a length with a remainder of 1 when divided by 4.",
- fn: () => {
+ it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
assertThrows(() => a2b("abcde"));
assertThrows(() => a2b("abcde==="));
- },
+ });
});
-Deno.test({
- name: "isBase64 returns true for base64 strings.",
- fn: () =>
- Object.keys(base64s).forEach((key) => assert(isBase64(key))),
+describe("b2a", () => {
+ it("[[Call]] returns the correct string", () => {
+ Object.entries(base64s).forEach(([key, value]) =>
+ assertStrictEquals(b2a(value), key)
+ );
+ });
});
-Deno.test({
- name: "isBase64 returns false for others.",
- fn: () =>
+describe("isBase64", () => {
+ it("[[Call]] returns true for base64 strings", () => {
+ Object.keys(base64s).forEach((key) => assert(isBase64(key)));
+ });
+
+ it("[[Call]] returns false for others", () => {
[
undefined,
null,
"abc_",
"a",
"abc==",
- ].forEach((value) => assert(!isBase64(value))),
+ ].forEach((value) => assert(!isBase64(value)));
+ });
});