0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-buffer-equals.js
Weijia Wang 9e0f771224 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>
2017-08-24 14:49:47 -07:00

26 lines
625 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const b = Buffer.from('abcdf');
const c = Buffer.from('abcdf');
const d = Buffer.from('abcde');
const e = Buffer.from('abcdef');
assert.ok(b.equals(c));
assert.ok(!c.equals(d));
assert.ok(!d.equals(e));
assert.ok(d.equals(d));
assert.ok(d.equals(new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65])));
common.expectsError(
() => Buffer.alloc(1).equals('abc'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "otherBuffer" argument must be one of type ' +
'buffer or uint8Array. Received type string'
}
);