]>
Lady’s Gitweb - Pisces/blob - base64.test.js
1 // ♓🌟 Piscēs ∷ base64.test.js
2 // ====================================================================
4 // Copyright © 2020–2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
17 } from "./dev-deps.js";
18 import { a2b
, b2a
, isBase64
} from "./base64.js";
21 "AGIAYQBzAGUANgA0": "base64",
22 "R/Q=": new Uint16Array([62535]),
23 "S0lCSQ==": new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
24 YmFzZTY0
: new DataView(
25 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
29 describe("a2b", () => {
30 it("[[Call]] returns the correct data", () => {
32 a2b("AGIAYQBzAGUANgA0"),
34 Array
.prototype.map
.call(
35 "\u{0}b\u{0}a\u{0}s\u{0}e\u{0}6\u{0}4",
36 ($) => $.charCodeAt(0),
43 new Uint16Array([62535]).buffer
,
48 new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
53 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
58 it("[[Call]] throws when provided with an invalid character", () => {
59 assertThrows(() => a2b("abc_"));
62 it("[[Call]] throws when provided with an invalid equals", () => {
63 assertThrows(() => a2b("abc=="));
66 it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
67 assertThrows(() => a2b("abcde"));
68 assertThrows(() => a2b("abcde==="));
72 describe("b2a", () => {
73 it("[[Call]] returns the correct string", () => {
74 Object
.entries(base64s
).forEach(([key
, value
]) =>
75 assertStrictEquals(b2a(value
), key
)
80 describe("isBase64", () => {
81 it("[[Call]] returns true for base64 strings", () => {
82 Object
.keys(base64s
).forEach((key
) => assert(isBase64(key
)));
85 it("[[Call]] returns false for others", () => {
100 ].forEach((value
) => assert(!isBase64(value
)));
This page took 0.179475 seconds and 5 git commands to generate.