-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathbigint64.test.ts
38 lines (33 loc) · 1.42 KB
/
bigint64.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 assert from "assert";
import { encode, decode } from "../src/index";
describe("useBigInt64: true", () => {
before(function () {
if (typeof BigInt === "undefined") {
this.skip();
}
});
it("encodes and decodes 0n", () => {
const value = BigInt(0);
const encoded = encode(value, { useBigInt64: true });
assert.deepStrictEqual(decode(encoded, { useBigInt64: true }), value);
});
it("encodes and decodes MAX_SAFE_INTEGER+1", () => {
const value = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1);
const encoded = encode(value, { useBigInt64: true });
assert.deepStrictEqual(decode(encoded, { useBigInt64: true }), value);
});
it("encodes and decodes MIN_SAFE_INTEGER-1", () => {
const value = BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1);
const encoded = encode(value, { useBigInt64: true });
assert.deepStrictEqual(decode(encoded, { useBigInt64: true }), value);
});
it("encodes and decodes values with numbers and bigints", () => {
const value = {
ints: [0, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
nums: [Number.NaN, Math.PI, Math.E, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
bigints: [BigInt(0), BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1), BigInt(Number.MIN_SAFE_INTEGER) - BigInt(1)],
};
const encoded = encode(value, { useBigInt64: true });
assert.deepStrictEqual(decode(encoded, { useBigInt64: true }), value);
});
});