From 283bb601f417c8aa8532d643c9fc0a03ac95131a Mon Sep 17 00:00:00 2001 From: ZYSzys <17367077526@163.com> Date: Sun, 17 Feb 2019 19:28:06 +0800 Subject: [PATCH] test: remove duplicated buffer negative allocation test --- test/parallel/test-buffer-negative-length.js | 17 ----------------- .../test-buffer-no-negative-allocation.js | 8 +++++++- 2 files changed, 7 insertions(+), 18 deletions(-) delete mode 100644 test/parallel/test-buffer-negative-length.js diff --git a/test/parallel/test-buffer-negative-length.js b/test/parallel/test-buffer-negative-length.js deleted file mode 100644 index bf903b933d2689..00000000000000 --- a/test/parallel/test-buffer-negative-length.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const SlowBuffer = require('buffer').SlowBuffer; - -const bufferNegativeMsg = common.expectsError({ - code: 'ERR_INVALID_OPT_VALUE', - type: RangeError, - message: /^The value "[^"]*" is invalid for option "size"$/ -}, 5); -assert.throws(() => Buffer(-1).toString('utf8'), bufferNegativeMsg); -assert.throws(() => SlowBuffer(-1).toString('utf8'), bufferNegativeMsg); -assert.throws(() => Buffer.alloc(-1).toString('utf8'), bufferNegativeMsg); -assert.throws(() => Buffer.allocUnsafe(-1).toString('utf8'), bufferNegativeMsg); -assert.throws(() => Buffer.allocUnsafeSlow(-1).toString('utf8'), - bufferNegativeMsg); diff --git a/test/parallel/test-buffer-no-negative-allocation.js b/test/parallel/test-buffer-no-negative-allocation.js index 3a4958c8f62c60..d48d02cb9b2476 100644 --- a/test/parallel/test-buffer-no-negative-allocation.js +++ b/test/parallel/test-buffer-no-negative-allocation.js @@ -2,12 +2,13 @@ const common = require('../common'); const assert = require('assert'); +const { SlowBuffer } = require('buffer'); const msg = common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', type: RangeError, message: /^The value "[^"]*" is invalid for option "size"$/ -}, 16); +}, 20); // Test that negative Buffer length inputs throw errors. @@ -30,3 +31,8 @@ assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg); assert.throws(() => Buffer.allocUnsafeSlow(-100), msg); assert.throws(() => Buffer.allocUnsafeSlow(-1), msg); assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg); + +assert.throws(() => SlowBuffer(-Buffer.poolSize), msg); +assert.throws(() => SlowBuffer(-100), msg); +assert.throws(() => SlowBuffer(-1), msg); +assert.throws(() => SlowBuffer(NaN), msg);