Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add bignum value #1096

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/bigint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Value IsLossless(const CallbackInfo& info) {
return Boolean::New(env, lossless);
}

Value IsBigInt(const CallbackInfo& info) {
Env env = info.Env();

BigInt big = info[0].As<BigInt>();

return Boolean::New(env, big.IsBigInt());
}

Value TestInt64(const CallbackInfo& info) {
bool lossless;
int64_t input = info[0].As<BigInt>().Int64Value(&lossless);
Expand Down Expand Up @@ -71,6 +79,7 @@ Value TestTooBigBigInt(const CallbackInfo& info) {
Object InitBigInt(Env env) {
Object exports = Object::New(env);
exports["IsLossless"] = Function::New(env, IsLossless);
exports["IsBigInt"] = Function::New(env, IsBigInt);
exports["TestInt64"] = Function::New(env, TestInt64);
exports["TestUint64"] = Function::New(env, TestUint64);
exports["TestWords"] = Function::New(env, TestWords);
Expand Down
11 changes: 7 additions & 4 deletions test/bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const assert = require('assert');

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

function test(binding) {
function test (binding) {
const {
TestInt64,
TestUint64,
TestWords,
IsLossless,
TestTooBigBigInt,
IsBigInt,
TestTooBigBigInt
} = binding.bigint;

[
Expand All @@ -24,7 +25,7 @@ function test(binding) {
986583n,
-976675n,
98765432213456789876546896323445679887645323232436587988766545658n,
-4350987086545760976737453646576078997096876957864353245245769809n,
-4350987086545760976737453646576078997096876957864353245245769809n
].forEach((num) => {
if (num > -(2n ** 63n) && num < 2n ** 63n) {
assert.strictEqual(TestInt64(num), num);
Expand All @@ -40,11 +41,13 @@ function test(binding) {
assert.strictEqual(IsLossless(num, false), false);
}

assert.strictEqual(IsBigInt(num), true);

assert.strictEqual(num, TestWords(num));
});

assert.throws(TestTooBigBigInt, {
name: /^(RangeError|Error)$/,
message: /^(Maximum BigInt size exceeded|Invalid argument)$/,
message: /^(Maximum BigInt size exceeded|Invalid argument)$/
});
}