aboutsummaryrefslogtreecommitdiff
path: root/test/js-native-api/test_bigint/test.js
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-11-17 12:34:54 -0800
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-12-04 13:58:17 -0800
commit938e11882b96e19b443477571455088baaa054d8 (patch)
treeeb828a60957a2881995ba9a83f44a32a18fbff16 /test/js-native-api/test_bigint/test.js
parent83ee137c4565112177f22f2c735b266b22262220 (diff)
downloadandroid-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.gz
android-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.bz2
android-node-v8-938e11882b96e19b443477571455088baaa054d8.zip
test: partition N-API tests
Partition test/addons-napi into test/js-native-api and test/node-api to isolate the Node.js-agnostic portion of the N-API tests from the Node.js-specific portion. PR-URL: https://github.com/nodejs/node/pull/24557 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test/js-native-api/test_bigint/test.js')
-rw-r--r--test/js-native-api/test_bigint/test.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/js-native-api/test_bigint/test.js b/test/js-native-api/test_bigint/test.js
new file mode 100644
index 0000000000..b92c810459
--- /dev/null
+++ b/test/js-native-api/test_bigint/test.js
@@ -0,0 +1,45 @@
+'use strict';
+const common = require('../../common');
+const assert = require('assert');
+const {
+ IsLossless,
+ TestInt64,
+ TestUint64,
+ TestWords,
+ CreateTooBigBigInt,
+} = require(`./build/${common.buildType}/test_bigint`);
+
+[
+ 0n,
+ -0n,
+ 1n,
+ -1n,
+ 100n,
+ 2121n,
+ -1233n,
+ 986583n,
+ -976675n,
+ 98765432213456789876546896323445679887645323232436587988766545658n,
+ -4350987086545760976737453646576078997096876957864353245245769809n,
+].forEach((num) => {
+ if (num > -(2n ** 63n) && num < 2n ** 63n) {
+ assert.strictEqual(TestInt64(num), num);
+ assert.strictEqual(IsLossless(num, true), true);
+ } else {
+ assert.strictEqual(IsLossless(num, true), false);
+ }
+
+ if (num >= 0 && num < 2n ** 64n) {
+ assert.strictEqual(TestUint64(num), num);
+ assert.strictEqual(IsLossless(num, false), true);
+ } else {
+ assert.strictEqual(IsLossless(num, false), false);
+ }
+
+ assert.strictEqual(num, TestWords(num));
+});
+
+assert.throws(CreateTooBigBigInt, {
+ name: 'RangeError',
+ message: 'Maximum BigInt size exceeded',
+});