From 901cb8cb5e2eb887e1889f8f7946c71a642e14c0 Mon Sep 17 00:00:00 2001 From: DavidCai Date: Fri, 3 Feb 2017 09:47:55 +0800 Subject: [PATCH] test: increase coverage of buffer PR-URL: https://github.com/nodejs/node/pull/11122 Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Italo A. Casas Reviewed-By: Yuta Hiroto Reviewed-By: Sakthipriyan Vairamani --- test/parallel/test-buffer-compare-offset.js | 2 ++ test/parallel/test-buffer-write-noassert.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/test/parallel/test-buffer-compare-offset.js b/test/parallel/test-buffer-compare-offset.js index deed1a41cb664c..037e82e055cb91 100644 --- a/test/parallel/test-buffer-compare-offset.js +++ b/test/parallel/test-buffer-compare-offset.js @@ -11,6 +11,7 @@ assert.strictEqual(-1, a.compare(b)); // Equivalent to a.compare(b). assert.strictEqual(-1, a.compare(b, 0)); assert.strictEqual(-1, a.compare(b, '0')); +assert.strictEqual(-1, a.compare(b, undefined)); // Equivalent to a.compare(b). assert.strictEqual(-1, a.compare(b, 0, undefined, 0)); @@ -63,5 +64,6 @@ assert.throws(() => a.compare(b, 0, 1, 0, 100), oor); assert.throws(() => a.compare(b, -1), oor); assert.throws(() => a.compare(b, 0, '0xff'), oor); assert.throws(() => a.compare(b, 0, Infinity), oor); +assert.throws(() => a.compare(b, 0, 1, -1), oor); assert.throws(() => a.compare(b, -Infinity, Infinity), oor); assert.throws(() => a.compare(), /Argument must be a Buffer/); diff --git a/test/parallel/test-buffer-write-noassert.js b/test/parallel/test-buffer-write-noassert.js index c0054733b85bb2..ea5ca923f01983 100644 --- a/test/parallel/test-buffer-write-noassert.js +++ b/test/parallel/test-buffer-write-noassert.js @@ -20,6 +20,17 @@ function write(funx, args, result, res) { ); } + { + const error = /Int/.test(funx) ? + /^TypeError: "buffer" argument must be a Buffer or Uint8Array$/ : + /^TypeError: argument should be a Buffer$/; + + assert.throws( + () => Buffer.alloc(9)[funx].apply(new Uint32Array(1), args), + error + ); + } + { const buf2 = Buffer.alloc(9); assert.strictEqual(buf2[funx](...args, true), result);