-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.ts
39 lines (33 loc) · 983 Bytes
/
test.ts
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
// Copyright 2020-present the denosaurs team. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "jsr:@std/[email protected]";
import { compress, decompress } from "./mod.ts";
function encode(input: string): Uint8Array {
return new TextEncoder().encode(input);
}
Deno.test({
name: "compress",
fn: () => {
// empty
assertEquals(compress(encode("")), Uint8Array.from([0]));
// 'X' x64 times
assertEquals(
compress(encode("X".repeat(64))),
Uint8Array.from([31, 88, 1, 0, 44, 0]),
);
},
});
Deno.test({
name: "decompress",
fn: () => {
// empty
assertEquals(decompress(Uint8Array.from([0])), Uint8Array.from([]));
// 'X' x64 times
assertEquals(
decompress(Uint8Array.from([31, 88, 1, 0, 44, 0])),
encode("X".repeat(64)),
);
// errors
assertThrows(() => decompress(Uint8Array.from([16, 97, 2, 0])));
assertThrows(() => decompress(Uint8Array.from([64, 97, 1, 0])));
},
});