summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-alloc.js
diff options
context:
space:
mode:
authorstarkwang <381152119@qq.com>2017-06-28 23:58:39 -0400
committerRefael Ackermann <refack@gmail.com>2017-07-12 17:00:30 -0400
commitdbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f (patch)
tree35c3e4c7942fcb826e19f7a9eead918f9caa805b /test/parallel/test-buffer-alloc.js
parent1562fb9ea7b993382a4aef0433a10b1029419f17 (diff)
downloadandroid-node-v8-dbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f.tar.gz
android-node-v8-dbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f.tar.bz2
android-node-v8-dbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f.zip
errors,buffer: port errors to internal/errors
PR-URL: https://github.com/nodejs/node/pull/13976 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-alloc.js')
-rw-r--r--test/parallel/test-buffer-alloc.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js
index 2a69d967a5..77c0c60425 100644
--- a/test/parallel/test-buffer-alloc.js
+++ b/test/parallel/test-buffer-alloc.js
@@ -888,7 +888,11 @@ assert.throws(() => Buffer.allocUnsafe(8).writeFloatLE(0.0, -1), RangeError);
// Regression test for #5482: should throw but not assert in C++ land.
assert.throws(() => Buffer.from('', 'buffer'),
- /^TypeError: "encoding" must be a valid string encoding$/);
+ common.expectsError({
+ code: 'ERR_UNKNOWN_ENCODING',
+ type: TypeError,
+ message: 'Unknown encoding: buffer'
+ }));
// Regression test for #6111. Constructing a buffer from another buffer
// should a) work, and b) not corrupt the source buffer.
@@ -930,7 +934,8 @@ assert.throws(() => Buffer.allocUnsafe(10).copy(),
/TypeError: argument should be a Buffer/);
const regErrorMsg =
- /First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object\./;
+ new RegExp('The first argument must be one of type string, buffer, ' +
+ 'arrayBuffer, array, or array-like object\\.');
assert.throws(() => Buffer.from(), regErrorMsg);
assert.throws(() => Buffer.from(null), regErrorMsg);
@@ -957,8 +962,14 @@ assert.strictEqual(SlowBuffer.prototype.offset, undefined);
// Test that ParseArrayIndex handles full uint32
-assert.throws(() => Buffer.from(new ArrayBuffer(0), -1 >>> 0),
- /RangeError: 'offset' is out of bounds/);
+{
+ const errMsg = common.expectsError({
+ code: 'ERR_BUFFER_OUT_OF_BOUNDS',
+ type: RangeError,
+ message: '"offset" is outside of buffer bounds'
+ });
+ assert.throws(() => Buffer.from(new ArrayBuffer(0), -1 >>> 0), errMsg);
+}
// ParseArrayIndex() should reject values that don't fit in a 32 bits size_t.
assert.throws(() => {
@@ -985,9 +996,9 @@ assert.doesNotThrow(() => Buffer.from(arrayBuf));
assert.doesNotThrow(() => Buffer.from({ buffer: arrayBuf }));
assert.throws(() => Buffer.alloc({ valueOf: () => 1 }),
- /"size" argument must be a number/);
+ /"size" argument must be of type number/);
assert.throws(() => Buffer.alloc({ valueOf: () => -1 }),
- /"size" argument must be a number/);
+ /"size" argument must be of type number/);
assert.strictEqual(Buffer.prototype.toLocaleString, Buffer.prototype.toString);
{