Skip to content

Commit b558546

Browse files
committed
add tests
1 parent 64553cc commit b558546

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

test/codec-int.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "assert";
2-
import { setInt64, getInt64 } from "../src/utils/int";
2+
import { setInt64, getInt64, getUint64, setUint64 } from "../src/utils/int";
33

44
const INT64SPECS = {
55
ZERO: 0,
@@ -13,17 +13,33 @@ const INT64SPECS = {
1313
MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER,
1414
} as Record<string, number>;
1515

16-
describe("codec: encode and decode int 32/64", () => {
16+
describe("codec: int64 / uint64", () => {
1717
context("int 64", () => {
1818
for (const name of Object.keys(INT64SPECS)) {
1919
const value = INT64SPECS[name];
2020

21-
it(`${value} (${value < 0 ? "-" : ""}0x${Math.abs(value).toString(16)})`, () => {
21+
it(`sets and gets ${value} (${value < 0 ? "-" : ""}0x${Math.abs(value).toString(16)})`, () => {
2222
const b = new Uint8Array(8);
2323
const view = new DataView(b.buffer);
24-
setInt64(new DataView(b.buffer), 0, value);
24+
setInt64(view, 0, value);
2525
assert.deepStrictEqual(getInt64(view, 0), value);
2626
});
2727
}
2828
});
29+
30+
context("uint 64", () => {
31+
it(`sets and gets 0`, () => {
32+
const b = new Uint8Array(8);
33+
const view = new DataView(b.buffer);
34+
setUint64(view, 0, 0);
35+
assert.deepStrictEqual(getUint64(view, 0), 0);
36+
});
37+
38+
it(`sets and gets MAX_SAFE_INTEGER`, () => {
39+
const b = new Uint8Array(8);
40+
const view = new DataView(b.buffer);
41+
setUint64(view, 0, Number.MAX_SAFE_INTEGER);
42+
assert.deepStrictEqual(getUint64(view, 0), Number.MAX_SAFE_INTEGER);
43+
});
44+
});
2945
});

0 commit comments

Comments
 (0)