Browse Source

test: increase coverage of buffer

PR-URL: https://github.com/nodejs/node/pull/11312
Backport-of: https://github.com/nodejs/node/pull/11122
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
v7.x
DavidCai 8 years ago
committed by Italo A. Casas
parent
commit
66081d1ddb
No known key found for this signature in database GPG Key ID: 23EFEFE93C4CFFFE
  1. 2
      test/parallel/test-buffer-compare-offset.js
  2. 11
      test/parallel/test-buffer-write-noassert.js

2
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/);

11
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 instance$/ :
/^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);

Loading…
Cancel
Save