+
+describe("isWRMGBase32", () => {
+ it("[[Call]] returns true for W·R·M·G base32 strings", () => {
+ for (const { wrmg } of data.values()) {
+ assert(isWRMGBase32(wrmg));
+ assert(isWRMGBase32(wrmg.toLowerCase()));
+ assert(isWRMGBase32(`--${wrmg}--`));
+ assert(isWRMGBase32(wrmg.replaceAll(/1/gu, "I")));
+ assert(isWRMGBase32(wrmg.replaceAll(/1/gu, "L")));
+ assert(isWRMGBase32(wrmg.replaceAll(/0/gu, "O")));
+ assert(isWRMGBase32(wrmg.replaceAll(/1/gu, "i")));
+ assert(isWRMGBase32(wrmg.replaceAll(/1/gu, "l")));
+ assert(isWRMGBase32(wrmg.replaceAll(/0/gu, "o")));
+ assert(isWRMGBase32(wrmg.replaceAll(/./gu, ($) => {
+ const rand = Math.random();
+ return rand < 0.25
+ ? $
+ : rand < 0.5
+ ? `-${$}`
+ : rand < 0.75
+ ? `${$}-`
+ : `-${$}-`;
+ })));
+ }
+ });
+
+ it("[[Call]] returns false for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "ABCU",
+ "A",
+ "ABCDEFGH1",
+ ].forEach((value) => assert(!isWRMGBase32(value)));
+ });
+});
+
+describe("wrmgBase32Binary", () => {
+ it("[[Call]] returns the correct data", () => {
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("")),
+ new Uint8Array([]),
+ "<empty>",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("01H00R80EC06A01P00T0")),
+ Uint8Array.from(
+ "\u{0}b\u{0}a\u{0}s\u{0}e\u{0}6\u{0}4",
+ ($) => $.charCodeAt(0),
+ ),
+ "01H00R80EC06A01P00T0",
+ );
+ assertEquals(
+ new Uint16Array(wrmgBase32Binary("8ZT0")),
+ new Uint16Array([62535]),
+ "8ZT0",
+ );
+ assertEquals(
+ new Uint8ClampedArray(wrmgBase32Binary("9D4M4J8")),
+ new Uint8ClampedArray([75, 73, 66, 73]),
+ "9D4M4J8",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("C9GQ6S9P6G")),
+ new Uint8Array([98, 97, 115, 101, 54, 52]),
+ "C9GQ6S9P6G",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("2KXSR0YSFR")),
+ new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9, 0x7E]),
+ "2KXSR0YSFR",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("2KXSR0YS")),
+ new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9]),
+ "2KXSR0YS",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("2KXSR0R")),
+ new Uint8Array([0x14, 0xFB, 0x9C, 0x03]),
+ "2KXSR0R",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("50")),
+ new Uint8Array([0x28]),
+ "50",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TR")),
+ new Uint8Array([0xD6]),
+ "TR",
+ );
+ assertEquals(
+ new Uint16Array(wrmgBase32Binary("TVW0")),
+ new Uint16Array([0xF8D6]),
+ "TVW0",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVW00")),
+ new Uint8Array([0xD6, 0xF8, 0x00]),
+ "TVW00",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVW10")),
+ new Uint8Array([0xD6, 0xF8, 0x10]),
+ "TVW10",
+ );
+ assertEquals(
+ new Uint32Array(wrmgBase32Binary("TVW1230")),
+ new Uint32Array([0x0C11F8D6]),
+ "TVW1230",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVW12340")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "TVW12340",
+ );
+ assertEquals(
+ new Uint16Array(wrmgBase32Binary("TVW1234560")),
+ new Uint16Array([0xF8D6, 0x0C11, 0x3085]),
+ "TVW1234560",
+ );
+ });
+
+ it("[[Call]] is case‐insensitive", () => {
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("tVw12340")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "tVw12340",
+ );
+ });
+
+ it("[[Call]] casts I, L & O", () => {
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVWI234O")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "TVWI234O",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVWi234o")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "TVWi234o",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVWL234O")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "TVWL234O",
+ );
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("TVWl234o")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "TVWl234o",
+ );
+ });
+
+ it("[[Call]] ignores hyphens", () => {
+ assertEquals(
+ new Uint8Array(wrmgBase32Binary("--TVW---123-40-----")),
+ new Uint8Array([0xD6, 0xF8, 0x11, 0x0C, 0x80]),
+ "--TVW---123-40-----",
+ );
+ });
+
+ it("[[Call]] throws when provided with an invalid character", () => {
+ assertThrows(() => wrmgBase32Binary("ABCu"));
+ assertThrows(() => wrmgBase32Binary("ABCU"));
+ assertThrows(() => wrmgBase32Binary("ABC="));
+ });
+
+ it("[[Call]] throws when provided with a length with a remainder of 1 when divided by 4", () => {
+ assertThrows(() => wrmgBase32Binary("234BCDEAA"));
+ assertThrows(() => wrmgBase32Binary("2-34-B--CD-EA-A-"));
+ });
+});
+
+describe("wrmgBase32String", () => {
+ it("[[Call]] returns the correct string", () => {
+ for (const [source, { wrmg }] of data) {
+ assertStrictEquals(wrmgBase32String(source), wrmg);
+ }
+ });
+});