-
Notifications
You must be signed in to change notification settings - Fork 5
/
size_of.test.ts
130 lines (115 loc) Β· 2.37 KB
/
size_of.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { assert, assertEquals } from "./_test_util.ts";
import { sizeOf } from "./size_of.ts";
Deno.test({
name: "sizeOf - string",
fn() {
assertEquals(sizeOf("abcdefghijklmnopq"), 21);
assertEquals(sizeOf("π₯π₯"), 12);
},
});
Deno.test({
name: "sizeOf - number",
fn() {
assertEquals(sizeOf(63), 4);
assertEquals(sizeOf(64), 5);
assertEquals(sizeOf(8_191), 5);
assertEquals(sizeOf(8_192), 6);
assertEquals(sizeOf(1_048_575), 6);
assertEquals(sizeOf(1_048_576), 7);
assertEquals(sizeOf(134_217_727), 7);
assertEquals(sizeOf(134_217_728), 8);
assertEquals(sizeOf(2_147_483_647), 8);
assertEquals(sizeOf(2_147_483_648), 11);
assertEquals(sizeOf(Number.MAX_SAFE_INTEGER), 11);
},
});
Deno.test({
name: "sizeOf - boolean",
fn() {
assertEquals(sizeOf(true), 3);
assertEquals(sizeOf(false), 3);
},
});
Deno.test({
name: "sizeOf - bigint",
fn() {
assertEquals(sizeOf(63n), 12);
assertEquals(sizeOf(BigInt(Number.MAX_SAFE_INTEGER + 1)), 12);
},
});
Deno.test({
name: "sizeOf - undefined",
fn() {
assertEquals(sizeOf(undefined), 3);
},
});
Deno.test({
name: "sizeOf - null",
fn() {
assertEquals(sizeOf(null), 3);
},
});
Deno.test({
name: "sizeOf - Date",
fn() {
assertEquals(sizeOf(new Date()), 11);
},
});
Deno.test({
name: "sizeOf - RegExp",
fn() {
assertEquals(sizeOf(/ab[cdefg]hijklmnopq/ig), 25);
},
});
Deno.test({
name: "sizeOf - Error",
fn() {
assert(
sizeOf(new URIError("boo hoo", { cause: new Error("boo") })) >= 496,
);
},
});
Deno.test({
name: "sizeOf - Uint8Array",
fn() {
assertEquals(sizeOf(new Uint8Array([1, 2, 3])), 12);
},
});
Deno.test({
name: "sizeOf - ArrayBuffer",
fn() {
assertEquals(sizeOf(new Uint8Array([1, 2, 3]).buffer), 12);
},
});
Deno.test({
name: "sizeOf - Array",
fn() {
assertEquals(sizeOf([1, 2, 3, "boo", true, false, /abc/]), 27);
},
});
Deno.test({
name: "sizeOf - Set",
fn() {
assertEquals(sizeOf(new Set([1, 2, 3, 4, "foo"])), 18);
},
});
Deno.test({
name: "sizeOf - Map",
fn() {
assertEquals(
sizeOf(
new Map<string, string | number>([["a", 1], ["b", 2], ["c", "d"]]),
),
21,
);
},
});
Deno.test({
name: "sizeOf - object",
fn() {
assertEquals(
sizeOf({ a: new Map([[{ a: 1 }, { b: /234/ }]]), b: false }),
36,
);
},
});