summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-fill.js
diff options
context:
space:
mode:
authorWeijia Wang <381152119@qq.com>2017-08-22 19:57:26 +0800
committerJames M Snell <jasnell@gmail.com>2017-08-24 14:49:47 -0700
commit9e0f771224759484bd95358f02de650916287488 (patch)
treeaba239ccc9c9f6988843d04483bffd7ddb63a527 /test/parallel/test-buffer-fill.js
parent52fe7626068c7110696104139a063942bdb3fd83 (diff)
downloadandroid-node-v8-9e0f771224759484bd95358f02de650916287488.tar.gz
android-node-v8-9e0f771224759484bd95358f02de650916287488.tar.bz2
android-node-v8-9e0f771224759484bd95358f02de650916287488.zip
buffer: improve error messages
Some errors in buffer module losed some arguments or received wrong arguments when they were created. This PR added these losing arguments and fixed the wrong arguments. PR-URL: https://github.com/nodejs/node/pull/14975 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-fill.js')
-rw-r--r--test/parallel/test-buffer-fill.js66
1 files changed, 35 insertions, 31 deletions
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js
index 33e71be8cf..63db4ce13c 100644
--- a/test/parallel/test-buffer-fill.js
+++ b/test/parallel/test-buffer-fill.js
@@ -192,45 +192,49 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, -1]), [0, 0, 0, 0]);
// Check exceptions
-assert.throws(
- () => buf1.fill(0, -1),
- common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' }));
-assert.throws(
- () => buf1.fill(0, 0, buf1.length + 1),
- common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' }));
-assert.throws(
- () => buf1.fill('', -1),
- common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' }));
-assert.throws(
- () => buf1.fill('', 0, buf1.length + 1),
- common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' }));
-assert.throws(
+[
+ [0, -1],
+ [0, 0, buf1.length + 1],
+ ['', -1],
+ ['', 0, buf1.length + 1]
+].forEach((args) => {
+ common.expectsError(
+ () => buf1.fill(...args),
+ { code: 'ERR_INDEX_OUT_OF_RANGE' }
+ );
+});
+
+common.expectsError(
() => buf1.fill('a', 0, buf1.length, 'node rocks!'),
- common.expectsError({
+ {
code: 'ERR_UNKNOWN_ENCODING',
type: TypeError,
message: 'Unknown encoding: node rocks!'
- }));
-assert.throws(
- () => buf1.fill('a', 0, 0, NaN),
- common.expectsError({
- code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "encoding" argument must be of type string'
- }));
-assert.throws(
- () => buf1.fill('a', 0, 0, null),
- common.expectsError({
- code: 'ERR_INVALID_ARG_TYPE',
- message: 'The "encoding" argument must be of type string'
- }));
-assert.throws(
+ }
+);
+
+[
+ ['a', 0, 0, NaN],
+ ['a', 0, 0, null]
+].forEach((args) => {
+ common.expectsError(
+ () => buf1.fill(...args),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "encoding" argument must be of type ' +
+ `string. Received type ${args[3] === null ? 'null' : typeof args[3]}`
+ }
+ );
+});
+
+common.expectsError(
() => buf1.fill('a', 0, 0, 'foo'),
- common.expectsError({
+ {
code: 'ERR_UNKNOWN_ENCODING',
type: TypeError,
message: 'Unknown encoding: foo'
- }));
-
+ }
+);
function genBuffer(size, args) {
const b = Buffer.allocUnsafe(size);