var tape = require('tape');
var bl = require('bl');
var tapeworm = require('../');

tapeworm.infect(tape);

test('infect should add a method html to t', function (t) {
  t.equal(typeof t.html, 'function');
  t.end();
}, verifyAsserts({ok: 1, fail: 0}));


/**
 * Helper functions stolen directly from blue-tape
 * Allows tape to test itself (whaaaa!?)
 */

function test (name, test, checkErrors) {
  tape.test(name, function (t) {
    var htest = tape.createHarness()
    htest.createStream().pipe(bl(function (_, data) {
      checkErrors && checkErrors(data.toString().split('\n'), t)
    }))
    htest(function (t) {
      return test(t, htest)
    })
  })
}

function verifyAsserts (counts) {
  return function (lines, t) {
    t.equal(count(lines, /^ok/), counts.ok, 'should have ' + counts.ok + ' ok asserts')
    t.equal(count(lines, /^not ok/), counts.fail, 'should have ' + counts.fail + ' failed asserts')
    t.end()
  }
}

function count (lines, regex) {
  var c = 0
  for (var k = 0; k < lines.length; ++k) {
    if (regex.test(lines[k])) {
      ++c
    }
  }
  return c
}

@@ -1,16 +1,16 @@
 var t
-ape
+est
  = requi
@@ -25,32 +25,8 @@
 ');%0A
-var bl = require('bl');%0A
 var 
@@ -70,19 +70,19 @@
 infect(t
-ape
+est
 );%0A%0Atest
@@ -191,874 +191,9 @@
 );%0A%7D
-, verifyAsserts(%7Bok: 1, fail: 0%7D));%0A%0A%0A/**%0A * Helper functions stolen directly from blue-tape%0A * Allows tape to test itself (whaaaa!?)%0A */%0A%0Afunction test (name, test, checkErrors) %7B%0A  tape.test(name, function (t) %7B%0A    var htest = tape.createHarness()%0A    htest.createStream().pipe(bl(function (_, data) %7B%0A      checkErrors && checkErrors(data.toString().split('%5Cn'), t)%0A    %7D))%0A    htest(function (t) %7B%0A      return test(t, htest)%0A    %7D)%0A  %7D)%0A%7D%0A%0Afunction verifyAsserts (counts) %7B%0A  return function (lines, t) %7B%0A    t.equal(count(lines, /%5Eok/), counts.ok, 'should have ' + counts.ok + ' ok asserts')%0A    t.equal(count(lines, /%5Enot ok/), counts.fail, 'should have ' + counts.fail + ' failed asserts')%0A    t.end()%0A  %7D%0A%7D%0A%0Afunction count (lines, regex) %7B%0A  var c = 0%0A  for (var k = 0; k %3C lines.length; ++k) %7B%0A    if (regex.test(lines%5Bk%5D)) %7B%0A      ++c%0A    %7D%0A  %7D%0A  return c%0A%7D
+);%0A%0A
 %0A

Remove bluetape style of testing itself