Skip to content

Commit 71d029c

Browse files
committed
test(base64): write peter-jr tests to make sure atob/btoa works
1 parent fa60ab8 commit 71d029c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/js/test-atob-btoa.simple

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @file test-atob-btoa.simple
3+
* Simple test which ensures atob/btoa works
4+
* @author Tom Tang <[email protected]>
5+
* @date July 2023
6+
*/
7+
8+
function expect(a) {
9+
return {
10+
toBe(b) {
11+
if (a !== b) throw new Error(`'${a}' does not equal to '${b}'`);
12+
}
13+
}
14+
}
15+
16+
/*!
17+
* Modified from https://github.com/oven-sh/bun/blob/bun-v0.6.12/test/js/web/util/atob.test.js
18+
* Bun
19+
* MIT License
20+
*/
21+
22+
//
23+
// atob
24+
//
25+
expect(atob("YQ==")).toBe("a");
26+
expect(atob("YWI=")).toBe("ab");
27+
expect(atob("YWJj")).toBe("abc");
28+
expect(atob("YWJjZA==")).toBe("abcd");
29+
expect(atob("YWJjZGU=")).toBe("abcde");
30+
expect(atob("YWJjZGVm")).toBe("abcdef");
31+
expect(atob("zzzz")).toBe("Ï<ó");
32+
expect(atob("")).toBe("");
33+
expect(atob("null")).toBe("žée");
34+
expect(atob("6ek=")).toBe("éé");
35+
// expect(atob("6ek")).toBe("éé"); // FIXME (Tom Tang): binascii.Error: Incorrect padding
36+
expect(atob("gIE=")).toBe("€");
37+
// expect(atob("zz")).toBe("Ï"); // FIXME (Tom Tang): same here
38+
// expect(atob("zzz")).toBe("Ï<");
39+
expect(atob("zzz=")).toBe("Ï<");
40+
expect(atob(" YQ==")).toBe("a");
41+
expect(atob("YQ==\u000a")).toBe("a");
42+
43+
//
44+
// btoa
45+
//
46+
expect(btoa("a")).toBe("YQ==");
47+
expect(btoa("ab")).toBe("YWI=");
48+
expect(btoa("abc")).toBe("YWJj");
49+
expect(btoa("abcd")).toBe("YWJjZA==");
50+
expect(btoa("abcde")).toBe("YWJjZGU=");
51+
expect(btoa("abcdef")).toBe("YWJjZGVm");
52+
expect(typeof btoa).toBe("function");
53+
expect(btoa("")).toBe("");
54+
expect(btoa("null")).toBe("bnVsbA==");
55+
expect(btoa("undefined")).toBe("dW5kZWZpbmVk");
56+
expect(btoa("[object Window]")).toBe("W29iamVjdCBXaW5kb3dd");
57+
expect(btoa("éé")).toBe("6ek=");
58+
expect(btoa("\u0080\u0081")).toBe("gIE=");

0 commit comments

Comments
 (0)