Skip to content

Commit e439222

Browse files
WenheLImhdawson
authored andcommitted
test: add bigint value test
PR-URL: #1096 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 0dfa89f commit e439222

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

test/bigint.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Value IsLossless(const CallbackInfo& info) {
2525
return Boolean::New(env, lossless);
2626
}
2727

28+
Value IsBigInt(const CallbackInfo& info) {
29+
Env env = info.Env();
30+
31+
BigInt big = info[0].As<BigInt>();
32+
33+
return Boolean::New(env, big.IsBigInt());
34+
}
35+
2836
Value TestInt64(const CallbackInfo& info) {
2937
bool lossless;
3038
int64_t input = info[0].As<BigInt>().Int64Value(&lossless);
@@ -71,6 +79,7 @@ Value TestTooBigBigInt(const CallbackInfo& info) {
7179
Object InitBigInt(Env env) {
7280
Object exports = Object::New(env);
7381
exports["IsLossless"] = Function::New(env, IsLossless);
82+
exports["IsBigInt"] = Function::New(env, IsBigInt);
7483
exports["TestInt64"] = Function::New(env, TestInt64);
7584
exports["TestUint64"] = Function::New(env, TestUint64);
7685
exports["TestWords"] = Function::New(env, TestWords);

test/bigint.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ const assert = require('assert');
44

55
module.exports = require('./common').runTest(test);
66

7-
function test(binding) {
7+
function test (binding) {
88
const {
99
TestInt64,
1010
TestUint64,
1111
TestWords,
1212
IsLossless,
13-
TestTooBigBigInt,
13+
IsBigInt,
14+
TestTooBigBigInt
1415
} = binding.bigint;
1516

1617
[
@@ -24,7 +25,7 @@ function test(binding) {
2425
986583n,
2526
-976675n,
2627
98765432213456789876546896323445679887645323232436587988766545658n,
27-
-4350987086545760976737453646576078997096876957864353245245769809n,
28+
-4350987086545760976737453646576078997096876957864353245245769809n
2829
].forEach((num) => {
2930
if (num > -(2n ** 63n) && num < 2n ** 63n) {
3031
assert.strictEqual(TestInt64(num), num);
@@ -40,11 +41,13 @@ function test(binding) {
4041
assert.strictEqual(IsLossless(num, false), false);
4142
}
4243

44+
assert.strictEqual(IsBigInt(num), true);
45+
4346
assert.strictEqual(num, TestWords(num));
4447
});
4548

4649
assert.throws(TestTooBigBigInt, {
4750
name: /^(RangeError|Error)$/,
48-
message: /^(Maximum BigInt size exceeded|Invalid argument)$/,
51+
message: /^(Maximum BigInt size exceeded|Invalid argument)$/
4952
});
5053
}

0 commit comments

Comments
 (0)