 {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


describe 'combine', ->

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

      lazy_stream_from_array
    ], (make_stream) ->
      it "combines #{inspect left} with #{inspect right}", (done) ->
        combined = combine make_stream(left), make_stream(right)
        _.stream(combined).run (err, output) ->
          assert.ifError err
          # Order doesn't matter
          assert.deepEqual output.sort(), left.concat(right).sort()
          done()

  it 'works with objectMode: false', (done) ->
    [left, right] = [['abc', 'def', 'gh'], ['123', '456', '78']]
    combined = combine stream_from_array(left, false), stream_from_array(right, false)
    _.stream(combined).run (err, output) ->
      assert.ifError err
      assert.equal _(output).invoke('toString').sort().join(''),
        left.concat(right).sort().join('')
      done()

  it 'uses objectMode if the left stream is in objectMode', ->
    combined = combine stream_from_array([], false), stream_from_array([])
    assert combined._readableState.objectMode
  it 'uses objectMode if the right stream is in objectMode', ->
    combined = combine stream_from_array([]), stream_from_array([], false)
    assert combined._readableState.objectMode
