Permalink
Browse files

insert test now always passes

  • Loading branch information...
1 parent f78ba29 commit 642f62ae1073409bc7fce083d4fbfcc11cfb39a9 @substack committed Oct 10, 2011
Showing with 6 additions and 3 deletions.
  1. +6 −3 test/insert.js
View
@@ -2,7 +2,7 @@ var test = require('tap').test;
var insertHeaders = require('../lib/insert_headers');
test('insert headers', function (t) {
- t.plan(50 * 2);
+ t.plan(50 * 3);
var msg = [
'POST / HTTP/1.1',
'Host: beep',
@@ -12,6 +12,8 @@ test('insert headers', function (t) {
for (var i = 0; i < 50; i++) {
var bufs = splitUp(msg);
+ t.equal(bufs.map(String).join(''), msg);
+
var bufs_ = bufs.slice();
var n = insertHeaders(bufs, { foo : 'bar', baz : 'quux' });
@@ -27,13 +29,14 @@ test('insert headers', function (t) {
function splitUp (msg) {
var bufs = [];
for (
- var i = 0, j = Math.floor(Math.random() * msg.length);
- j < msg.length;
+ var i = 0, j = Math.floor(Math.random() * (msg.length + 1));
+ j <= msg.length;
j += Math.floor(Math.random() * (msg.length - j + 1))
) {
var s = msg.slice(i, j);
bufs.push(new Buffer(s));
i = j;
+ if (j === msg.length) break;
}
return bufs;

0 comments on commit 642f62a

Please sign in to comment.