-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
38 lines (31 loc) · 863 Bytes
/
index.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
import { it, describe } from "node:test";
import assert, { deepStrictEqual } from "node:assert";
import "./index";
type Disposable = {
[Symbol.dispose]: () => void;
};
type TestFunc = (cls: {
prototype: Disposable;
from: (arr: Array<number>) => Disposable;
}) => void;
const genCheckTest: TestFunc = (cls) =>
assert(typeof cls.prototype[Symbol.dispose] === "function");
const genDisposeTest: TestFunc = (cls) => {
const input = cls.from([1, 2, 3]);
input[Symbol.dispose]();
deepStrictEqual(input, cls.from([0, 0, 0]));
};
const typedArrays = [
Uint8Array,
Int8Array,
Uint8ClampedArray,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Buffer,
];
describe("nullize", () => {
it("check dispose function", () => typedArrays.forEach(genCheckTest));
it("call dispose function", () => typedArrays.forEach(genDisposeTest));
});