 {Readable, Writable, PassThrough} = require 'stream'
 {inspect} = require 'util'
 
-{combine} = require '../index'
+understream = require '../index'
+{combine} = understream
+_.mixin understream.exports()
 
-stream_from_array = (arr) ->
-  # TODO test objectMode: false
-  rs = new Readable objectMode: true
+stream_from_array = (arr, objectMode = true) ->
+  rs = new Readable {objectMode}
   _.each arr, (elt) -> rs.push elt
   rs.push null
   rs

      lazy_stream_from_array
    ], (make_stream) ->
      it "combines #{inspect left} with #{inspect right}", (done) ->
        result = combine make_stream(left), make_stream(right)
        output = []
        result.on 'data', (chunk) -> output.push chunk
        result.on 'error', done
        result.on 'end', ->
          # Order doesn't matter
          assert.deepEqual output.sort(), left.concat(right).sort()
          done()

  expected_err = /Expected Readable streams/
  it 'only accepts Readable streams on the right', ->
    assert.throws (-> combine new Readable(), new Writable()), expected_err
  it 'only accepts Readable streams on the left', ->
    assert.throws (-> combine new Writable(), new Readable()), expected_err
  it 'accepts any Readable streams', ->
    assert.doesNotThrow (-> combine new PassThrough(), new Readable())


describe 'combine', ->

  expected_err = /Expected Readable streams/
  it 'only accepts Readable streams on the right', ->
    assert.throws (-> combine stream_from_array([]), new Writable()), expected_err
  it 'only accepts Readable streams on the left', ->
    assert.throws (-> combine new Writable(), stream_from_array([])), expected_err
  it 'accepts any Readable streams', ->
    assert.doesNotThrow (-> combine new PassThrough(), stream_from_array([]))

  _.each [
    [[]                 , []]
    [['a', 'bc', 'def'] , []]
