]>
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/>.
10 import { a2b
, b2a
, isBase64
} from "./base64.js";
16 } from "./dev-deps.js";
19 "AGIAYQBzAGUANgA0": "base64",
20 "R/Q=": new Uint16Array([62535]),
21 "S0lCSQ==": new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
22 YmFzZTY0
: new DataView(
23 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
28 name
: "Calling b2a returns the correct string.",
30 Object
.entries(base64s
).forEach(([key
, value
]) =>
31 assertStrictEquals(b2a(value
), key
)
36 name
: "Calling a2b returns the correct data.",
39 a2b("AGIAYQBzAGUANgA0"),
41 Array
.prototype.map
.call(
42 "\u{0}b\u{0}a\u{0}s\u{0}e\u{0}6\u{0}4",
43 ($) => $.charCodeAt(0),
49 new Uint16Array([62535]).buffer
,
53 new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
57 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
63 name
: "Calling a2b throws when provided with an invalid character.",
64 fn
: () => assertThrows(() => a2b("abc_")),
68 name
: "Calling a2b throws when provided with an invalid equals.",
69 fn
: () => assertThrows(() => a2b("abc==")),
74 "Calling a2b throws when provided with a length with a remainder of 1 when divided by 4.",
76 assertThrows(() => a2b("abcde"));
77 assertThrows(() => a2b("abcde==="));
82 name
: "isBase64 returns true for base64 strings.",
84 Object
.keys(base64s
).forEach((key
) => assert(isBase64(key
))),
88 name
: "isBase64 returns false for others.",
104 ].forEach((value
) => assert(!isBase64(value
))),
This page took 0.063649 seconds and 5 git commands to generate.