MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / test

Function test

test/bigint.js:7–53  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

5module.exports = require('./common').runTest(test);
6
7function test (binding) {
8 const {
9 TestInt64,
10 TestUint64,
11 TestWords,
12 IsLossless,
13 IsBigInt,
14 TestTooBigBigInt
15 } = binding.bigint;
16
17 [
18 0n,
19 -0n,
20 1n,
21 -1n,
22 100n,
23 2121n,
24 -1233n,
25 986583n,
26 -976675n,
27 98765432213456789876546896323445679887645323232436587988766545658n,
28 -4350987086545760976737453646576078997096876957864353245245769809n
29 ].forEach((num) => {
30 if (num > -(2n ** 63n) && num < 2n ** 63n) {
31 assert.strictEqual(TestInt64(num), num);
32 assert.strictEqual(IsLossless(num, true), true);
33 } else {
34 assert.strictEqual(IsLossless(num, true), false);
35 }
36
37 if (num >= 0 && num < 2n ** 64n) {
38 assert.strictEqual(TestUint64(num), num);
39 assert.strictEqual(IsLossless(num, false), true);
40 } else {
41 assert.strictEqual(IsLossless(num, false), false);
42 }
43
44 assert.strictEqual(IsBigInt(num), true);
45
46 assert.strictEqual(num, TestWords(num));
47 });
48
49 assert.throws(TestTooBigBigInt, {
50 name: /^(RangeError|Error)$/,
51 message: /^(Maximum BigInt size exceeded|Invalid argument)$/
52 });
53}

Callers

nothing calls this directly

Calls 5

TestInt64Function · 0.85
IsLosslessFunction · 0.85
TestUint64Function · 0.85
IsBigIntFunction · 0.85
TestWordsFunction · 0.85

Tested by

no test coverage detected