SRC_DIR = '../../../../src/database/impl/iterate/'

ByteIterableUtil =
  (require SRC_DIR + 'ByteIterableUtil.coffee').ByteIterableUtil
ArrayByteIterable =
  (require SRC_DIR + 'ArrayByteIterable.coffee').ArrayByteIterable

exports.testCreation = (test) ->
  test.expect 6
  a = ArrayByteIterable.create$Buffer new Buffer("")
  test.equal a.length, 0
  test.equal ByteIterableUtil.
  compare$Buffer$int$Buffer$int(a.bytes, 0, new Buffer(""), 0), 0
  a = ArrayByteIterable.create$Buffer new Buffer("A")
  test.equal a.length, 1
  test.equal ByteIterableUtil.
  compare$Buffer$int$Buffer$int(a.bytes, 1, new Buffer("A"), 1), 0
  a = ArrayByteIterable.create$Buffer new Buffer("ABCDE")
  test.equal a.length, 5
  test.equal ByteIterableUtil.
  compare$Buffer$int$Buffer$int(a.bytes, 5, new Buffer("ABCDE"), 5), 0
  test.done()

exports.testEmptyIterable = (test) ->
  test.expect 3
  a = ArrayByteIterable.EMPTY
  test.equal a.length, 0
  test.equal ByteIterableUtil.
  compare$Buffer$int$Buffer$int(a.bytes, 0, new Buffer(""), 0), 0
  test.equal a.iterator().hasNext$emit(), false
  test.done()

exports.testIterator = (test) ->
  test.expect 5
  a = ArrayByteIterable.create$Buffer new Buffer("ABCDE")
  it = a.iterator()
  test.equal it.next$emit(), 65
  test.equal it.next$emit(), 66
  test.equal it.skip$int(2), 2
  test.equal it.next$emit(), 69
  test.equal it.hasNext$emit(), false
  test.done()

