]>
Lady’s Gitweb - Pisces/blob - binary.test.js
1 // ♓🌟 Piscēs ∷ binary.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";
21 filenameSafeBase64Binary
,
22 filenameSafeBase64String
,
28 "AGIAYQBzAGUANgA0": "base64",
29 "R/Q=": new Uint16Array([62535]),
30 "S0lCSQ==": new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
31 YmFzZTY0
: new DataView(
32 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
36 describe("base64Binary", () => {
37 it("[[Call]] returns the correct data", () => {
39 base64Binary("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),
50 new Uint16Array([62535]).buffer
,
54 base64Binary("S0lCSQ=="),
55 new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
59 base64Binary("YmFzZTY0"),
60 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
65 it("[[Call]] throws when provided with an invalid character", () => {
66 assertThrows(() => base64Binary("abc_"));
69 it("[[Call]] throws when provided with an invalid equals", () => {
70 assertThrows(() => base64Binary("abc=="));
73 it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
74 assertThrows(() => base64Binary("abcde"));
75 assertThrows(() => base64Binary("abcde==="));
79 describe("base64String", () => {
80 it("[[Call]] returns the correct string", () => {
81 Object
.entries(base64s
).forEach(([key
, value
]) =>
82 assertStrictEquals(base64String(value
), key
)
87 describe("filenameSafeBase64Binary", () => {
88 it("[[Call]] returns the correct data", () => {
90 filenameSafeBase64Binary("AGIAYQBzAGUANgA0"),
92 Array
.prototype.map
.call(
93 "\u{0}b\u{0}a\u{0}s\u{0}e\u{0}6\u{0}4",
94 ($) => $.charCodeAt(0),
100 filenameSafeBase64Binary("R_Q="),
101 new Uint16Array([62535]).buffer
,
105 filenameSafeBase64Binary("S0lCSQ=="),
106 new Uint8ClampedArray([75, 73, 66, 73]).buffer
,
110 filenameSafeBase64Binary("YmFzZTY0"),
111 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer
,
116 it("[[Call]] throws when provided with an invalid character", () => {
117 assertThrows(() => filenameSafeBase64Binary("abc/"));
120 it("[[Call]] throws when provided with an invalid equals", () => {
121 assertThrows(() => filenameSafeBase64Binary("abc=="));
124 it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
125 assertThrows(() => filenameSafeBase64Binary("abcde"));
126 assertThrows(() => filenameSafeBase64Binary("abcde==="));
130 describe("filenameSafeBase64String", () => {
131 it("[[Call]] returns the correct string", () => {
132 Object
.entries(base64s
).forEach(([key
, value
]) =>
134 filenameSafeBase64String(value
),
135 key
.replace("+", "-").replace("/", "_"),
141 describe("isBase64", () => {
142 it("[[Call]] returns true for base64 strings", () => {
143 Object
.keys(base64s
).forEach((key
) => assert(isBase64(key
)));
146 it("[[Call]] returns false for others", () => {
161 ].forEach((value
) => assert(!isBase64(value
)));
165 describe("isFilenameSafeBase64", () => {
166 it("[[Call]] returns true for filename‐safe base64 strings", () => {
167 Object
.keys(base64s
).forEach((key
) =>
169 isFilenameSafeBase64(key
.replace("+", "-").replace("/", "_")),
174 it("[[Call]] returns false for others", () => {
189 ].forEach((value
) => assert(!isFilenameSafeBase64(value
)));
This page took 0.102963 seconds and 5 git commands to generate.