-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialize.test.ts
45 lines (40 loc) · 1.13 KB
/
serialize.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
40
41
42
43
44
45
import "https://deno.land/x/[email protected]/testing.ts";
import { deserialize, serialize } from "./mod.ts";
const raw = {
...{
str: "string",
num: 0,
obj: { foo: "foo" },
arr: [1, 2, 3],
bool: true,
nil: null,
undef: undefined,
inf: Infinity,
date: new Date("Thu, 28 Apr 2016 22:02:17 GMT"),
map: new Map([["hello", "world"]]),
set: new Set([123, 456]),
re: /([^\s]+)/g,
big: 10n,
} as const,
};
type raw = typeof raw;
describe("serialize()", () => {
const encoded = serialize({ ...raw } as raw);
const decoded = deserialize<raw>(encoded);
it("should deserialize properly", () => {
assertObjectMatch(decoded, raw);
});
it("should deserialize literal bigints", () => {
assertEquals(decoded.big, raw.big);
});
it("should deserialize infinities", () => {
assertEquals(decoded.inf, raw.inf);
});
it("should deserialize deeply nested values", () => {
assertEquals(decoded.obj.foo, raw.obj.foo);
});
it("should deserialize regular expressions", () => {
assertEquals(decoded.re.source, raw.re.source);
assertEquals(decoded.re.flags, raw.re.flags);
});
});