rm deprecated bufferutils
This commit is contained in:
parent
93b815c20e
commit
549b36bf1a
4 changed files with 22 additions and 207 deletions
test
|
@ -6,49 +6,10 @@ var bufferutils = require('../src/bufferutils')
|
|||
var fixtures = require('./fixtures/bufferutils.json')
|
||||
|
||||
describe('bufferutils', function () {
|
||||
describe('pushDataSize', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('determines the pushDataSize of ' + f.dec + ' correctly', function () {
|
||||
if (!f.hexPD) return
|
||||
|
||||
var size = bufferutils.pushDataSize(f.dec)
|
||||
|
||||
assert.strictEqual(size, f.hexPD.length / 2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('readPushDataInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (!f.hexPD) return
|
||||
|
||||
it('decodes ' + f.hexPD + ' correctly', function () {
|
||||
var buffer = Buffer.from(f.hexPD, 'hex')
|
||||
var d = bufferutils.readPushDataInt(buffer, 0)
|
||||
var fopcode = parseInt(f.hexPD.substr(0, 2), 16)
|
||||
|
||||
assert.strictEqual(d.opcode, fopcode)
|
||||
assert.strictEqual(d.number, f.dec)
|
||||
assert.strictEqual(d.size, buffer.length)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.readPushDataInt.forEach(function (f) {
|
||||
if (!f.hexPD) return
|
||||
|
||||
it('decodes ' + f.hexPD + ' as null', function () {
|
||||
var buffer = Buffer.from(f.hexPD, 'hex')
|
||||
|
||||
var n = bufferutils.readPushDataInt(buffer, 0)
|
||||
assert.strictEqual(n, null)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('readUInt64LE', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('decodes ' + f.hex64 + ' correctly', function () {
|
||||
var buffer = Buffer.from(f.hex64, 'hex')
|
||||
it('decodes ' + f.hex, function () {
|
||||
var buffer = Buffer.from(f.hex, 'hex')
|
||||
var number = bufferutils.readUInt64LE(buffer, 0)
|
||||
|
||||
assert.strictEqual(number, f.dec)
|
||||
|
@ -57,7 +18,7 @@ describe('bufferutils', function () {
|
|||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = Buffer.from(f.hex64, 'hex')
|
||||
var buffer = Buffer.from(f.hex, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.readUInt64LE(buffer, 0)
|
||||
|
@ -66,68 +27,13 @@ describe('bufferutils', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('readVarInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('decodes ' + f.hexVI + ' correctly', function () {
|
||||
var buffer = Buffer.from(f.hexVI, 'hex')
|
||||
var d = bufferutils.readVarInt(buffer, 0)
|
||||
|
||||
assert.strictEqual(d.number, f.dec)
|
||||
assert.strictEqual(d.size, buffer.length)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = Buffer.from(f.hexVI, 'hex')
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.readVarInt(buffer, 0)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('varIntBuffer', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = bufferutils.varIntBuffer(f.dec)
|
||||
|
||||
assert.strictEqual(buffer.toString('hex'), f.hexVI)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('varIntSize', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('determines the varIntSize of ' + f.dec + ' correctly', function () {
|
||||
var size = bufferutils.varIntSize(f.dec)
|
||||
|
||||
assert.strictEqual(size, f.hexVI.length / 2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('writePushDataInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (!f.hexPD) return
|
||||
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = Buffer.alloc(5, 0)
|
||||
|
||||
var n = bufferutils.writePushDataInt(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexPD)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('writeUInt64LE', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
it('encodes ' + f.dec, function () {
|
||||
var buffer = Buffer.alloc(8, 0)
|
||||
|
||||
bufferutils.writeUInt64LE(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.toString('hex'), f.hex64)
|
||||
assert.strictEqual(buffer.toString('hex'), f.hex)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -141,25 +47,4 @@ describe('bufferutils', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('writeVarInt', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('encodes ' + f.dec + ' correctly', function () {
|
||||
var buffer = Buffer.alloc(9, 0)
|
||||
|
||||
var n = bufferutils.writeVarInt(buffer, f.dec, 0)
|
||||
assert.strictEqual(buffer.slice(0, n).toString('hex'), f.hexVI)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
||||
it('throws on ' + f.description, function () {
|
||||
var buffer = Buffer.alloc(9, 0)
|
||||
|
||||
assert.throws(function () {
|
||||
bufferutils.writeVarInt(buffer, f.dec, 0)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue