summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-read.js
diff options
context:
space:
mode:
authorArvind Pandey <arvind3157@gmail.com>2018-10-29 21:16:32 +0530
committerRich Trott <rtrott@gmail.com>2018-10-31 12:59:13 -0700
commite35f671aa796c8f755c96ea9c0b87d6565a7fe08 (patch)
treef8f79f5db1007257684f760fc46d50d062aee495 /test/parallel/test-buffer-read.js
parentc515e5c604492b2e7171e8d859c77cba33063d40 (diff)
downloadandroid-node-v8-e35f671aa796c8f755c96ea9c0b87d6565a7fe08.tar.gz
android-node-v8-e35f671aa796c8f755c96ea9c0b87d6565a7fe08.tar.bz2
android-node-v8-e35f671aa796c8f755c96ea9c0b87d6565a7fe08.zip
test: fixed error message in test-buffer-read
PR-URL: https://github.com/nodejs/node/pull/23957 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-read.js')
-rw-r--r--test/parallel/test-buffer-read.js40
1 files changed, 26 insertions, 14 deletions
diff --git a/test/parallel/test-buffer-read.js b/test/parallel/test-buffer-read.js
index 1fdfd0145f..6f4ff3ca86 100644
--- a/test/parallel/test-buffer-read.js
+++ b/test/parallel/test-buffer-read.js
@@ -51,34 +51,46 @@ read(buf, 'readUInt32LE', [1], 0xcfea48fd);
read(buf, 'readUIntBE', [2, 2], 0x48ea);
read(buf, 'readUIntLE', [2, 2], 0xea48);
+// Error name and message
+const OOR_ERROR =
+{
+ name: 'RangeError [ERR_OUT_OF_RANGE]'
+};
+
+const OOB_ERROR =
+{
+ name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
+ message: 'Attempt to write outside buffer bounds'
+};
+
// Attempt to overflow buffers, similar to previous bug in array buffers
-assert.throws(() => Buffer.allocUnsafe(8).readFloatBE(0xffffffff),
- RangeError);
-assert.throws(() => Buffer.allocUnsafe(8).readFloatLE(0xffffffff),
- RangeError);
+assert.throws(
+ () => Buffer.allocUnsafe(8).readFloatBE(0xffffffff), OOR_ERROR);
+
+assert.throws(
+ () => Buffer.allocUnsafe(8).readFloatLE(0xffffffff), OOR_ERROR);
// Ensure negative values can't get past offset
-assert.throws(() => Buffer.allocUnsafe(8).readFloatBE(-1), RangeError);
-assert.throws(() => Buffer.allocUnsafe(8).readFloatLE(-1), RangeError);
+assert.throws(
+ () => Buffer.allocUnsafe(8).readFloatBE(-1), OOR_ERROR);
+assert.throws(
+ () => Buffer.allocUnsafe(8).readFloatLE(-1), OOR_ERROR);
// Offset checks
{
const buf = Buffer.allocUnsafe(0);
- assert.throws(() => buf.readUInt8(0), RangeError);
- assert.throws(() => buf.readInt8(0), RangeError);
+ assert.throws(
+ () => buf.readUInt8(0), OOB_ERROR);
+ assert.throws(
+ () => buf.readInt8(0), OOB_ERROR);
}
[16, 32].forEach((bit) => {
const buf = Buffer.allocUnsafe(bit / 8 - 1);
[`Int${bit}B`, `Int${bit}L`, `UInt${bit}B`, `UInt${bit}L`].forEach((fn) => {
assert.throws(
- () => buf[`read${fn}E`](0),
- {
- name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
- message: 'Attempt to write outside buffer bounds'
- }
- );
+ () => buf[`read${fn}E`](0), OOB_ERROR);
});
});