From bda1a8321c4c60c713a7e306e0f872e5eeab87e3 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 29 May 2014 16:26:13 +1000 Subject: [PATCH] bufferutils: unrolls tests and adds more 16 bit test fixtures --- test/bufferutils.js | 36 ++++++++++++++++++------------------ test/fixtures/buffer.json | 12 ++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/test/bufferutils.js b/test/bufferutils.js index a06f4d1..72cec2d 100644 --- a/test/bufferutils.js +++ b/test/bufferutils.js @@ -5,8 +5,8 @@ var fixtures = require('./fixtures/buffer.json') describe('bufferutils', function() { describe('pushDataSize', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('determines the pushDataSize of ' + f.dec + ' correctly', function() { if (!f.hexPD) return var size = bufferutils.pushDataSize(f.dec) @@ -17,10 +17,10 @@ describe('bufferutils', function() { }) describe('readPushDataInt', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { - if (!f.hexPD) return + fixtures.valid.forEach(function(f) { + if (!f.hexPD) return + it('decodes ' + f.hexPD + ' correctly', function() { var buffer = new Buffer(f.hexPD, 'hex') var d = bufferutils.readPushDataInt(buffer, 0) @@ -31,8 +31,8 @@ describe('bufferutils', function() { }) describe('readUInt64LE', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('decodes ' + f.hex64 + ' correctly', function() { var buffer = new Buffer(f.hex64, 'hex') var number = bufferutils.readUInt64LE(buffer, 0) @@ -42,8 +42,8 @@ describe('bufferutils', function() { }) describe('readVarInt', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('decodes ' + f.hexVI + ' correctly', function() { var buffer = new Buffer(f.hexVI, 'hex') var d = bufferutils.readVarInt(buffer, 0) @@ -54,8 +54,8 @@ describe('bufferutils', function() { }) describe('varIntSize', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('determines the varIntSize of ' + f.dec + ' correctly', function() { var size = bufferutils.varIntSize(f.dec) assert.equal(size, f.hexVI.length / 2) @@ -64,10 +64,10 @@ describe('bufferutils', function() { }) describe('writePushDataInt', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f, i) { - if (!f.hexPD) return + fixtures.valid.forEach(function(f, i) { + if (!f.hexPD) return + it('encodes ' + f.dec + ' correctly', function() { var buffer = new Buffer(5) buffer.fill(0) @@ -89,8 +89,8 @@ describe('bufferutils', function() { }) describe('writeUInt64LE', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('encodes ' + f.dec + ' correctly', function() { var buffer = new Buffer(8) buffer.fill(0) @@ -112,8 +112,8 @@ describe('bufferutils', function() { }) describe('writeVarInt', function() { - it('matches test vectors', function() { - fixtures.valid.forEach(function(f) { + fixtures.valid.forEach(function(f) { + it('encodes ' + f.dec + ' correctly', function() { var buffer = new Buffer(9) buffer.fill(0) diff --git a/test/fixtures/buffer.json b/test/fixtures/buffer.json index 16d5c47..116e70a 100644 --- a/test/fixtures/buffer.json +++ b/test/fixtures/buffer.json @@ -30,6 +30,18 @@ "hexVI": "fdfe00", "hexPD": "4cfe" }, + { + "dec": 255, + "hex64": "ff00000000000000", + "hexVI": "fdff00", + "hexPD": "4dff00" + }, + { + "dec": 65534, + "hex64": "feff000000000000", + "hexVI": "fdfeff", + "hexPD": "4dfeff" + }, { "dec": 65535, "hex64": "ffff000000000000",