Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorgarygsc <GaryGSC@users.noreply.github.com>2019-11-11 21:59:07 +0300
committerBeth Griggs <Bethany.Griggs@uk.ibm.com>2020-02-25 03:17:56 +0300
commit64744a282e661a426d2092901bb7f4f02a0cb746 (patch)
tree67a95655bed1c29e3d5a7f2ba84a316c295e5ffe /test
parent1cfb45732a9b257d0c039cae76789757426f263a (diff)
buffer: add {read|write}Big[U]Int64{BE|LE} methods
Backport-PR-URL: https://github.com/nodejs/node/pull/30361 PR-URL: https://github.com/nodejs/node/pull/19691 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-buffer-bigint64.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-bigint64.js b/test/parallel/test-buffer-bigint64.js
new file mode 100644
index 00000000000..859a40811e1
--- /dev/null
+++ b/test/parallel/test-buffer-bigint64.js
@@ -0,0 +1,51 @@
+'use strict';
+require('../common');
+const assert = require('assert');
+
+const buf = Buffer.allocUnsafe(8);
+
+['LE', 'BE'].forEach(function(endianness) {
+ // Should allow simple BigInts to be written and read
+ let val = 123456789n;
+ buf['writeBigInt64' + endianness](val, 0);
+ let rtn = buf['readBigInt64' + endianness](0);
+ assert.strictEqual(val, rtn);
+
+ // Should allow INT64_MAX to be written and read
+ val = 0x7fffffffffffffffn;
+ buf['writeBigInt64' + endianness](val, 0);
+ rtn = buf['readBigInt64' + endianness](0);
+ assert.strictEqual(val, rtn);
+
+ // Should read and write a negative signed 64-bit integer
+ val = -123456789n;
+ buf['writeBigInt64' + endianness](val, 0);
+ assert.strictEqual(val, buf['readBigInt64' + endianness](0));
+
+ // Should read and write an unsigned 64-bit integer
+ val = 123456789n;
+ buf['writeBigUInt64' + endianness](val, 0);
+ assert.strictEqual(val, buf['readBigUInt64' + endianness](0));
+
+ // Should throw a RangeError upon INT64_MAX+1 being written
+ assert.throws(function() {
+ const val = 0x8000000000000000n;
+ buf['writeBigInt64' + endianness](val, 0);
+ }, RangeError);
+
+ // Should throw a RangeError upon UINT64_MAX+1 being written
+ assert.throws(function() {
+ const val = 0x10000000000000000n;
+ buf['writeBigUInt64' + endianness](val, 0);
+ }, RangeError);
+
+ // Should throw a TypeError upon invalid input
+ assert.throws(function() {
+ buf['writeBigInt64' + endianness]('bad', 0);
+ }, TypeError);
+
+ // Should throw a TypeError upon invalid input
+ assert.throws(function() {
+ buf['writeBigUInt64' + endianness]('bad', 0);
+ }, TypeError);
+});