forked from msgpack/msgpack-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodec-int.test.ts
28 lines (25 loc) · 838 Bytes
/
codec-int.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
import assert from "assert";
import { encodeInt64, decodeInt64 } from "../src/utils/int";
const INT64SPECS = {
ZERO: 0,
ONE: 1,
MINUS_ONE: -1,
X_FF: 0xff,
MINUS_X_FF: -0xff,
INT32_MAX: 0x7fffffff,
INT32_MIN: -0x7fffffff - 1,
MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER,
MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER,
} as Record<string, number>;
describe("codec: encode and decode int 32/64", () => {
context("int 64", () => {
for (const name of Object.keys(INT64SPECS)) {
const value = INT64SPECS[name];
it(`${value} (${value < 0 ? "-" : ""}0x${Math.abs(value).toString(16)})`, () => {
const b = new Uint8Array(8);
encodeInt64(value, new DataView(b.buffer), 0);
assert.deepStrictEqual(decodeInt64(b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]), value);
});
}
});
});