Permalink
Browse files

now using tap

  • Loading branch information...
substack committed Apr 10, 2012
1 parent 1b745ee commit 79ff9af3bf85f529b9e2530ce488afeea6eab20a
Showing with 78 additions and 58 deletions.
  1. +4 −1 package.json
  2. +74 −57 test/buffers.js
View
@@ -6,10 +6,13 @@
"author" : "James Halliday <mail@substack.net> (http://substack.net)",
"main" : "./index",
"scripts" : {
- "test" : "expresso"
+ "test" : "tap test/*.js"
},
"engines" : {
"node" : ">=0.2.0"
},
+ "devDependencies" : {
+ "tap" : "~0.2.4"
+ },
"license" : "MIT/X11"
}
View
@@ -1,4 +1,4 @@
-var assert = require('assert');
+var test = require('tap').test;
var Buffers = require('../');
function create (xs, split) {
@@ -11,13 +11,21 @@ function create (xs, split) {
return bufs;
}
-exports.slice = function () {
+function deepEqual (t, xs, ys, msg) {
+ t.deepEqual(
+ Buffer.isBuffer(xs) ? [].slice.call(xs) : xs,
+ Buffer.isBuffer(ys) ? [].slice.call(xs) : ys,
+ msg
+ );
+}
+
+test('slice', function (t) {
var xs = [0,1,2,3,4,5,6,7,8,9];
var splits = [ [4,2,3,1], [2,2,2,2,2], [1,6,3,1], [9,2], [10], [5,5] ];
splits.forEach(function (split) {
var bufs = create(xs, split);
- assert.eql(new Buffer(xs), bufs.slice(),
+ deepEqual(t, new Buffer(xs), bufs.slice(),
'[' + xs.join(',') + ']'
+ ' != ' +
'[' + [].join.call(bufs.slice(), ',') + ']'
@@ -28,17 +36,18 @@ exports.slice = function () {
var a = bufs.slice(i,j);
var b = new Buffer(xs.slice(i,j));
- assert.eql(a, b,
+ deepEqual(t, a, b,
'[' + [].join.call(a, ',') + ']'
+ ' != ' +
'[' + [].join.call(b, ',') + ']'
);
}
}
});
-};
+ t.end();
+});
-exports.splice = function () {
+test('splice', function (t) {
var xs = [0,1,2,3,4,5,6,7,8,9];
var splits = [ [4,2,3,1], [2,2,2,2,2], [1,6,3,1], [9,2], [10], [5,5] ];
@@ -51,23 +60,24 @@ exports.splice = function () {
var a_ = bufs.splice(i,j);
var a = [].slice.call(a_.slice());
var b = xs_.splice(i,j);
- assert.eql(a, b,
+ deepEqual(t, a, b,
'[' + a.join(',') + ']'
+ ' != ' +
'[' + b.join(',') + ']'
);
- assert.eql(bufs.slice(), new Buffer(xs_),
+ deepEqual(t, bufs.slice(), new Buffer(xs_),
'[' + [].join.call(bufs.slice(), ',') + ']'
+ ' != ' +
'[' + [].join.call(xs_, ',') + ']'
);
}
}
});
-};
+ t.end();
+});
-exports.spliceRep = function () {
+test('splice rep', function (t) {
var xs = [0,1,2,3,4,5,6,7,8,9];
var splits = [ [4,2,3,1], [2,2,2,2,2], [1,6,3,1], [9,2], [10], [5,5] ];
var reps = [ [], [1], [5,6], [3,1,3,3,7], [9,8,7,6,5,4,3,2,1,2,3,4,5] ];
@@ -85,13 +95,13 @@ exports.spliceRep = function () {
var a = [].slice.call(a_.slice());
var b = xs_.splice.apply(xs_, [ i, j ].concat(rep));
- assert.eql(a, b,
+ deepEqual(t, a, b,
'[' + a.join(',') + ']'
+ ' != ' +
'[' + b.join(',') + ']'
);
- assert.eql(bufs.slice(), new Buffer(xs_),
+ deepEqual(t, bufs.slice(), new Buffer(xs_),
'[' + [].join.call(bufs.slice(), ',') + ']'
+ ' != ' +
'[' + [].join.call(xs_, ',') + ']'
@@ -100,9 +110,10 @@ exports.spliceRep = function () {
}
});
});
-};
+ t.end();
+});
-exports.copy = function () {
+test('copy', function (t) {
var xs = [0,1,2,3,4,5,6,7,8,9];
var splits = [ [4,2,3,1], [2,2,2,2,2], [1,6,3,1], [9,2], [10], [5,5] ];
@@ -115,95 +126,101 @@ exports.copy = function () {
var t0 = new Buffer(j - i);
var t1 = new Buffer(j - i);
- assert.eql(
+ deepEqual(
+ t,
bufs.copy(t0, 0, i, j),
buf.copy(t1, 0, i, j)
);
- assert.eql(
- [].slice.call(t0),
- [].slice.call(t1)
- );
+ deepEqual(t, t0, t1);
}
}
});
-};
+ t.end();
+});
-exports.push = function () {
+test('push', function (t) {
var bufs = Buffers();
bufs.push(new Buffer([0]));
bufs.push(new Buffer([1,2,3]));
bufs.push(new Buffer([4,5]));
bufs.push(new Buffer([6,7,8,9]));
- assert.eql(
- [].slice.call(bufs.slice()),
+ deepEqual(
+ t,
+ bufs.slice(),
[0,1,2,3,4,5,6,7,8,9]
);
- assert.throws(function () {
+ t.throws(function () {
bufs.push(new Buffer([11,12]), 'moo');
});
- assert.eql(bufs.buffers.length, 4);
-};
+ t.equal(bufs.buffers.length, 4);
+ t.end();
+});
-exports.unshift = function () {
+test('unshift', function (t) {
var bufs = Buffers();
bufs.unshift(new Buffer([6,7,8,9]));
bufs.unshift(new Buffer([4,5]));
bufs.unshift(new Buffer([1,2,3]));
bufs.unshift(new Buffer([0]));
- assert.eql(
- [].slice.call(bufs.slice()),
+ deepEqual(
+ t,
+ bufs.slice(),
[0,1,2,3,4,5,6,7,8,9]
);
- assert.throws(function () {
+ t.throws(function () {
bufs.unshift(new Buffer([-2,-1]), 'moo');
});
- assert.eql(bufs.buffers.length, 4);
-};
+ t.equal(bufs.buffers.length, 4);
+ t.end();
+});
-exports.get = function () {
+test('get', function (t) {
var bufs = Buffers();
bufs.unshift(new Buffer([6,7,8,9]));
bufs.unshift(new Buffer([4,5]));
bufs.unshift(new Buffer([1,2,3]));
bufs.unshift(new Buffer([0]));
- assert.eql( bufs.get(0), 0 );
- assert.eql( bufs.get(1), 1 );
- assert.eql( bufs.get(2), 2 );
- assert.eql( bufs.get(3), 3 );
- assert.eql( bufs.get(4), 4 );
- assert.eql( bufs.get(5), 5 );
- assert.eql( bufs.get(6), 6 );
- assert.eql( bufs.get(7), 7 );
- assert.eql( bufs.get(8), 8 );
- assert.eql( bufs.get(9), 9 );
-};
+ t.equal( bufs.get(0), 0 );
+ t.equal( bufs.get(1), 1 );
+ t.equal( bufs.get(2), 2 );
+ t.equal( bufs.get(3), 3 );
+ t.equal( bufs.get(4), 4 );
+ t.equal( bufs.get(5), 5 );
+ t.equal( bufs.get(6), 6 );
+ t.equal( bufs.get(7), 7 );
+ t.equal( bufs.get(8), 8 );
+ t.equal( bufs.get(9), 9 );
+ t.end();
+});
-exports.set = function () {
+test('set', function (t) {
var bufs = Buffers();
bufs.push(new Buffer("Hel"));
bufs.push(new Buffer("lo"));
bufs.push(new Buffer("!"));
bufs.set(0, 'h'.charCodeAt(0) );
bufs.set(3, 'L'.charCodeAt(0) );
bufs.set(5, '.'.charCodeAt(0) );
- assert.eql( bufs.slice(0).toString(), 'helLo.' );
-};
+ t.equal( bufs.slice(0).toString(), 'helLo.' );
+ t.end();
+});
-exports.indexOf = function () {
+test('indexOf', function (t) {
var bufs = Buffers();
bufs.push(new Buffer("Hel"));
bufs.push(new Buffer("lo,"));
bufs.push(new Buffer(" how are "));
bufs.push(new Buffer("you"));
bufs.push(new Buffer("?"));
- assert.eql( bufs.indexOf("Hello"), 0 );
- assert.eql( bufs.indexOf("Hello", 1), -1 );
- assert.eql( bufs.indexOf("ello"), 1 );
- assert.eql( bufs.indexOf("ello", 1), 1 );
- assert.eql( bufs.indexOf("ello", 2), -1 );
- assert.eql( bufs.indexOf("e"), 1 );
- assert.eql( bufs.indexOf("e", 2), 13 );
- assert.eql( bufs.indexOf(new Buffer([0x65]), 2), 13 );
-};
+ t.equal( bufs.indexOf("Hello"), 0 );
+ t.equal( bufs.indexOf("Hello", 1), -1 );
+ t.equal( bufs.indexOf("ello"), 1 );
+ t.equal( bufs.indexOf("ello", 1), 1 );
+ t.equal( bufs.indexOf("ello", 2), -1 );
+ t.equal( bufs.indexOf("e"), 1 );
+ t.equal( bufs.indexOf("e", 2), 13 );
+ t.equal( bufs.indexOf(new Buffer([0x65]), 2), 13 );
+ t.end();
+});

0 comments on commit 79ff9af

Please sign in to comment.