bufferutils: add equal
This commit is contained in:
parent
8d3686d046
commit
5beee20038
2 changed files with 27 additions and 0 deletions
|
@ -165,6 +165,16 @@ function varIntBuffer (i) {
|
||||||
return buffer
|
return buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function equal (a, b) {
|
||||||
|
if (a.length !== b.length) return false
|
||||||
|
|
||||||
|
for (var i = 0; i < a.length; ++i) {
|
||||||
|
if (a[i] !== b[i]) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
function reverse (buffer) {
|
function reverse (buffer) {
|
||||||
var buffer2 = new Buffer(buffer)
|
var buffer2 = new Buffer(buffer)
|
||||||
Array.prototype.reverse.call(buffer2)
|
Array.prototype.reverse.call(buffer2)
|
||||||
|
@ -172,6 +182,7 @@ function reverse (buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
equal: equal,
|
||||||
pushDataSize: pushDataSize,
|
pushDataSize: pushDataSize,
|
||||||
readPushDataInt: readPushDataInt,
|
readPushDataInt: readPushDataInt,
|
||||||
readUInt64LE: readUInt64LE,
|
readUInt64LE: readUInt64LE,
|
||||||
|
|
|
@ -77,6 +77,22 @@ describe('bufferutils', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('equal', function () {
|
||||||
|
fixtures.valid.forEach(function (f) {
|
||||||
|
describe('for ' + f.hexVI, function () {
|
||||||
|
fixtures.valid.forEach(function (f2) {
|
||||||
|
it('equates the string comparison: ' + f.hexVI + ' === ' + f2.hexVI, function () {
|
||||||
|
var a = new Buffer(f.hexVI, 'hex')
|
||||||
|
var b = new Buffer(f2.hexVI, 'hex')
|
||||||
|
var expected = f.hexVI === f2.hexVI
|
||||||
|
|
||||||
|
assert.equal(bufferutils.equal(a, b), expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('reverse', function () {
|
describe('reverse', function () {
|
||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
it('reverses ' + f.hex64 + ' correctly', function () {
|
it('reverses ' + f.hex64 + ' correctly', function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue