forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64_test.ts
More file actions
45 lines (38 loc) · 1.15 KB
/
Copy pathbase64_test.ts
File metadata and controls
45 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2018-2026 the Deno authors. MIT license.
import { assertEquals } from "@std/assert";
import { decodeBase64, encodeBase64 } from "./base64.ts";
const testsetString = [
["", ""],
["ß", "w58="],
["f", "Zg=="],
["fo", "Zm8="],
["foo", "Zm9v"],
["foob", "Zm9vYg=="],
["fooba", "Zm9vYmE="],
["foobar", "Zm9vYmFy"],
] as const;
const testsetBinary = testsetString.map(([str, b64]) => [
new TextEncoder().encode(str),
b64,
]) as Array<[Uint8Array, string]>;
Deno.test("encodeBase64() encodes string", () => {
for (const [input, output] of testsetString) {
assertEquals(encodeBase64(input), output);
}
});
Deno.test("encodeBase64() encodes binary", () => {
for (const [input, output] of testsetBinary) {
assertEquals(encodeBase64(input), output);
}
});
Deno.test("encodeBase64() encodes binary buffer", () => {
for (const [input, output] of testsetBinary) {
assertEquals(encodeBase64(input.buffer as ArrayBuffer), output);
}
});
Deno.test("decodeBase64() decodes binary", () => {
for (const [input, output] of testsetBinary) {
const outputBinary = decodeBase64(output);
assertEquals(outputBinary, input);
}
});