Permalink
Browse files

everything using tap now

  • Loading branch information...
substack committed May 11, 2012
1 parent d356db9 commit ca77ba877be38fceb604dbe26a2a76f8ec94edde
Showing with 48 additions and 51 deletions.
  1. +3 −3 package.json
  2. +13 −13 test/eof.js
  3. +24 −31 test/parse.js
  4. +8 −4 test/put.js
View
@@ -26,11 +26,11 @@
"buffers" : "0.1.x"
},
"devDependencies" : {
- "seq" : ">=0.2.5 <0.3",
- "expresso" : "=0.7.x"
+ "seq" : "~0.2.5",
+ "tap" : "~0.2.4"
},
"scripts" : {
- "test" : "expresso"
+ "test" : "tap test/*.js"
},
"license" : "MIT/X11",
"engine" : {
View
@@ -1,29 +1,29 @@
-var Binary = require('../');
+var binary = require('../');
+var test = require('tap').test;
var EventEmitter = require('events').EventEmitter;
-var assert = require('assert');
-exports.eof = function () {
- var to = setTimeout(function () {
- assert.fail('never finished');
- }, 1000);
+test('eof', function (t) {
+ t.plan(4);
var stream = new EventEmitter;
- Binary.stream(stream)
+ binary.stream(stream)
.buffer('sixone', 5)
.peek(function () {
this.word32le('len');
})
.buffer('buf', 'len')
.word8('x')
.tap(function (vars) {
- clearTimeout(to);
- assert.eql(vars.sixone, new Buffer([ 6, 1, 6, 1, 6 ]));
- assert.eql(vars.buf.length, vars.len);
- assert.eql(
+ t.same(
+ [].slice.call(vars.sixone),
+ [].slice.call(new Buffer([ 6, 1, 6, 1, 6 ]))
+ );
+ t.same(vars.buf.length, vars.len);
+ t.same(
[].slice.call(vars.buf),
[ 9, 0, 0, 0, 97, 98, 99, 100, 101 ]
);
- assert.eql(vars.x, 102);
+ t.same(vars.x, 102);
})
;
@@ -38,4 +38,4 @@ exports.eof = function () {
});
stream.emit('end');
-};
+});
View
@@ -1,49 +1,42 @@
-var Binary = require('../');
-var EventEmitter = require('events').EventEmitter;
-var assert = require('assert');
+var binary = require('../');
+var test = require('tap').test;
-exports.parse = function () {
- var to = setTimeout(function () {
- assert.fail('never tapped');
- }, 50);
-
- var res = Binary.parse(new Buffer([ 97, 98, 99, 99, 99, 99, 1, 2, 3 ]))
+test('parse', function (t) {
+ t.plan(6);
+ var res = binary.parse(new Buffer([ 97, 98, 99, 99, 99, 99, 1, 2, 3 ]))
.word8('a')
.word16be('bc')
.skip(3)
.buffer('def', 3)
.tap(function (vars) {
- clearTimeout(to);
- assert.eql(vars, {
- a : 97,
- bc : 25187,
- def : new Buffer([ 1, 2, 3]),
- });
+ t.equal(vars.a, 97);
+ t.equal(vars.bc, 25187);
+ t.same(
+ [].slice.call(vars.def),
+ [].slice.call(new Buffer([ 1, 2, 3]))
+ );
})
.vars
;
- assert.eql(res, {
- a : 97,
- bc : 25187,
- def : new Buffer([ 1, 2, 3 ]),
- });
-};
+ t.equal(res.a, 97);
+ t.equal(res.bc, 25187);
+ t.same(
+ [].slice.call(res.def),
+ [].slice.call(new Buffer([ 1, 2, 3 ]))
+ );
+});
-exports.loop = function () {
- var to = setTimeout(function () {
- assert.fail('never tapped');
- }, 50);
-
- var res = Binary.parse(new Buffer([ 97, 98, 99, 4, 5, 2, -3, 9 ]))
+test('loop', function (t) {
+ t.plan(2);
+ var res = binary.parse(new Buffer([ 97, 98, 99, 4, 5, 2, -3, 9 ]))
.word8('a')
.word16be('bc')
.loop(function (end) {
var x = this.word8s('x').vars.x;
if (x < 0) end();
})
.tap(function (vars) {
- clearTimeout(to);
- assert.eql(vars, {
+ t.same(vars, {
a : 97,
bc : 25187,
x : -3,
@@ -52,10 +45,10 @@ exports.loop = function () {
.word8('y')
.vars
;
- assert.eql(res, {
+ t.same(res, {
a : 97,
bc : 25187,
x : -3,
y : 9,
});
-};
+});
View
@@ -1,11 +1,15 @@
-var assert = require('assert');
var Binary = require('../');
+var test = require('tap').test;
-exports.builder = function () {
+test('builder', function (t) {
+ t.plan(1);
var buf = Binary.put()
.word16be(1337)
.put(new Buffer([ 7, 8, 9 ]))
.buffer()
;
- assert.eql(buf, new Buffer([ 0x05, 0x39, 0x07, 0x08, 0x09 ]));
-};
+ t.same(
+ [].slice.call(buf),
+ [].slice.call(new Buffer([ 0x05, 0x39, 0x07, 0x08, 0x09 ]))
+ );
+});

0 comments on commit ca77ba8

Please sign in to comment.