diff options
author | starkwang <381152119@qq.com> | 2017-06-28 23:58:39 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-07-12 17:00:30 -0400 |
commit | dbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f (patch) | |
tree | 35c3e4c7942fcb826e19f7a9eead918f9caa805b /test/parallel/test-buffer-arraybuffer.js | |
parent | 1562fb9ea7b993382a4aef0433a10b1029419f17 (diff) | |
download | node-new-dbfe8c4ea2fb30f7d3dc4f8e361e3059b0e1e50f.tar.gz |
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-arraybuffer.js')
-rw-r--r-- | test/parallel/test-buffer-arraybuffer.js | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/test/parallel/test-buffer-arraybuffer.js b/test/parallel/test-buffer-arraybuffer.js index 8f89c4976c..ac1294ec8b 100644 --- a/test/parallel/test-buffer-arraybuffer.js +++ b/test/parallel/test-buffer-arraybuffer.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const LENGTH = 16; @@ -65,16 +65,16 @@ b.writeDoubleBE(11.11, 0, true); buf[0] = 9; assert.strictEqual(ab[1], 9); - assert.throws(() => Buffer.from(ab.buffer, 6), (err) => { - assert(err instanceof RangeError); - assert(/'offset' is out of bounds/.test(err.message)); - return true; - }); - assert.throws(() => Buffer.from(ab.buffer, 3, 6), (err) => { - assert(err instanceof RangeError); - assert(/'length' is out of bounds/.test(err.message)); - return true; - }); + assert.throws(() => Buffer.from(ab.buffer, 6), common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"offset" is outside of buffer bounds' + })); + assert.throws(() => Buffer.from(ab.buffer, 3, 6), common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"length" is outside of buffer bounds' + })); } // Test the deprecated Buffer() version also @@ -93,16 +93,16 @@ b.writeDoubleBE(11.11, 0, true); buf[0] = 9; assert.strictEqual(ab[1], 9); - assert.throws(() => Buffer(ab.buffer, 6), (err) => { - assert(err instanceof RangeError); - assert(/'offset' is out of bounds/.test(err.message)); - return true; - }); - assert.throws(() => Buffer(ab.buffer, 3, 6), (err) => { - assert(err instanceof RangeError); - assert(/'length' is out of bounds/.test(err.message)); - return true; - }); + assert.throws(() => Buffer(ab.buffer, 6), common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"offset" is outside of buffer bounds' + })); + assert.throws(() => Buffer(ab.buffer, 3, 6), common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"length" is outside of buffer bounds' + })); } { @@ -118,10 +118,13 @@ b.writeDoubleBE(11.11, 0, true); assert.deepStrictEqual(Buffer.from(ab, [1]), Buffer.from(ab, 1)); // If byteOffset is Infinity, throw. - assert.throws( - () => { Buffer.from(ab, Infinity); }, - /^RangeError: 'offset' is out of bounds$/ - ); + assert.throws(() => { + Buffer.from(ab, Infinity); + }, common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"offset" is outside of buffer bounds' + })); } { @@ -137,8 +140,11 @@ b.writeDoubleBE(11.11, 0, true); assert.deepStrictEqual(Buffer.from(ab, 0, [1]), Buffer.from(ab, 0, 1)); //If length is Infinity, throw. - assert.throws( - () => { Buffer.from(ab, 0, Infinity); }, - /^RangeError: 'length' is out of bounds$/ - ); + assert.throws(() => { + Buffer.from(ab, 0, Infinity); + }, common.expectsError({ + code: 'ERR_BUFFER_OUT_OF_BOUNDS', + type: RangeError, + message: '"length" is outside of buffer bounds' + })); } |