2015-02-23 00:36:57 +01:00
|
|
|
/* global describe, it */
|
|
|
|
|
2014-05-13 08:35:07 +02:00
|
|
|
var assert = require('assert')
|
2014-05-13 09:55:53 +02:00
|
|
|
var bufferutils = require('../src/bufferutils')
|
2014-05-13 08:35:07 +02:00
|
|
|
|
2014-05-31 05:19:46 +02:00
|
|
|
var fixtures = require('./fixtures/bufferutils.json')
|
2014-05-13 08:35:07 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('bufferutils', function () {
|
|
|
|
describe('readUInt64LE', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2018-04-13 17:07:10 +02:00
|
|
|
it('decodes ' + f.hex, function () {
|
|
|
|
var buffer = Buffer.from(f.hex, 'hex')
|
2014-05-13 08:35:07 +02:00
|
|
|
var number = bufferutils.readUInt64LE(buffer, 0)
|
|
|
|
|
2015-05-07 03:29:20 +02:00
|
|
|
assert.strictEqual(number, f.dec)
|
2014-05-13 08:35:07 +02:00
|
|
|
})
|
|
|
|
})
|
2014-05-31 05:18:57 +02:00
|
|
|
|
2015-03-04 10:32:08 +01:00
|
|
|
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
2015-02-23 00:36:57 +01:00
|
|
|
it('throws on ' + f.description, function () {
|
2018-04-13 17:07:10 +02:00
|
|
|
var buffer = Buffer.from(f.hex, 'hex')
|
2014-05-31 05:18:57 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
assert.throws(function () {
|
2014-05-31 05:18:57 +02:00
|
|
|
bufferutils.readUInt64LE(buffer, 0)
|
|
|
|
}, new RegExp(f.exception))
|
|
|
|
})
|
|
|
|
})
|
2014-05-13 08:35:07 +02:00
|
|
|
})
|
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('writeUInt64LE', function () {
|
|
|
|
fixtures.valid.forEach(function (f) {
|
2018-04-13 17:07:10 +02:00
|
|
|
it('encodes ' + f.dec, function () {
|
2017-04-19 09:39:16 +02:00
|
|
|
var buffer = Buffer.alloc(8, 0)
|
2014-05-13 08:35:07 +02:00
|
|
|
|
|
|
|
bufferutils.writeUInt64LE(buffer, f.dec, 0)
|
2018-04-13 17:07:10 +02:00
|
|
|
assert.strictEqual(buffer.toString('hex'), f.hex)
|
2014-05-13 08:35:07 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-03-04 10:32:08 +01:00
|
|
|
fixtures.invalid.readUInt64LE.forEach(function (f) {
|
2015-02-23 00:36:57 +01:00
|
|
|
it('throws on ' + f.description, function () {
|
2017-04-19 09:39:16 +02:00
|
|
|
var buffer = Buffer.alloc(8, 0)
|
2014-05-13 08:35:07 +02:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
assert.throws(function () {
|
2014-05-13 08:35:07 +02:00
|
|
|
bufferutils.writeUInt64LE(buffer, f.dec, 0)
|
2014-05-31 05:18:57 +02:00
|
|
|
}, new RegExp(f.exception))
|
2014-05-13 08:35:07 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|