var through = require('through2')
var test = require('tape')
var cuid = require('cuid')
var _ = require('underscore')

// attach a cuid like a mini cargo in bricoleur

// trace commands as they flow through bricoleur!

var cmds = [ // no objects 
  ['+@edit nimoy', cuid()],
  ['+gooshter', cuid()],
  ['+pumicle', cuid()],
  ['+gooshter|pumicle', cuid()],
  ['-gooshter|pumicle', cuid()],
  ['-gooshter', cuid()],
  ['-pumicle', cuid()],
  ['-@edit', cuid()]
]

module.exports = function ClientTest (opts) {
  var p = through.obj()

  test('bricoleur api', function (t) {
    t.plan(cmds.length) 

    cmds.forEach(function (c) {
      s.push(c[0]+':'+c[1])
    })

    p.on('data', function (d) {
      if (typeof d === 'object' && d.key && d.value) {
        var i = (d.key.split(':').length>1) 
          ? dex(d.key.split(':')[1],cmds) 
          : dex(d.key,cmds)

        if (typeof i === 'string') i = Math.abs(i)

        var c = cmds[i]
        if (i!==0&&i!==7) t.ok(isCuid(d.value), 'cmd: '+c[0])
        else t.ok(d.value, 'cmd: '+c[0])
      } else {
        console.log(JSON.stringify(d))
      }
    })
  })

  var s = through.obj(function (d, enc, next) { 
    p.write(d)
    next()
  })

  return s
}

function dex (str, arr) { 
  var res = null
  for (var i=0;i<arr.length;i++) {
    arr[i].forEach(function (item) { if (item === str) res = i })
  }
  return res.toString()
}

function isCuid (id) {
  var r = (typeof id==='string' && id.length===25 && id[0]==='c') 
    ? true 
    : false

  return r
}

@@ -31,20 +31,17 @@
 2')%0Avar 
-test
+_
  = requi
@@ -48,47 +48,29 @@
 re('
-tape')%0Avar cuid = require('cuid
+underscore
 ')%0Avar 
-_
+test
  = r
@@ -81,149 +81,55 @@
 re('
-underscore')%0A%0A// attach a cuid like a mini cargo in bricoleur%0A%0A// trace commands as they flow through bricoleur!%0A%0Avar cmds = %5B // no objects 
+tape')%0Avar cuid = require('cuid')%0A%0Avar cmds = %5B
 %0A  %5B
@@ -341,16 +341,94 @@
 d()%5D%0A%5D%0A%0A
+// update gooshter / pumicle to use dombii / dex / etc!%0A// actual use cases!%0A%0A
 module.e
@@ -528,16 +528,35 @@
 on (t) %7B
+ // add omni tests!
 %0A    t.p
@@ -725,24 +725,25 @@
  d.value) %7B%0A
+%0A
         var 
@@ -811,16 +811,17 @@
 ':')%5B1%5D,
+ 
 cmds) %0A 
@@ -841,16 +841,17 @@
 x(d.key,
+ 
 cmds)%0A%0A 
@@ -925,16 +925,17 @@
 cmds%5Bi%5D%0A
+%0A
         
@@ -943,18 +943,24 @@
 f (i
+ 
 !==
-0&&i
+ 0 && i 
 !==
+ 
 7) t
@@ -1006,102 +1006,97 @@
     
-else t.ok(d.value, 'cmd: '+c%5B0%5D)%0A      %7D else %7B%0A        console.log(JSON.stringify(d))%0A      %7D
+// if (i==7) winodw.location.hash = '@'%0A        else t.ok(d.value, 'cmd: '+c%5B0%5D)%0A      %7D 
 %0A   
@@ -1372,24 +1372,247 @@
 String()%0A%7D%0A%0A
+// MUTATIONS!%0A%0Adocument.body.addEventListener(%22DOMNodeInserted%22, function (ev) %7B%0A  var el = ev.target%0A%7D, false)%0A%0Adocument.body.addEventListener(%22DOMNodeRemoved%22, function (ev) %7B%0A  var el = ev.target%0A%7D, false)%0A%0A// HELPERS!%0A%0A
 function isC

comment out call set window.location.hash to @ in tests