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

LightOutputStream =
  (require SRC_DIR + 'LightOutputStream.coffee').LightOutputStream

stream = new Object()

exports.setUp = (callback) ->
  b = new Buffer 64
  b.fill 0
  stream = LightOutputStream.create$Buffer b
  callback()

exports.testCreation = (test) ->
  test.expect 2
  test.equal stream.getBufferBytes()[0], 0
  test.equal stream.getBufferLength(), 0
  test.done()

exports.testNext = (test) ->
  test.expect 66
  for i in [1..64]
    stream.writeFast$int i
    test.equal stream.getBufferLength(), i
  stream.writeFast$int 65
  test.equal stream.getBufferBytes().length, Math.round(64 * 8 / 5)
  test.equal stream.getBufferLength(), 65
  test.done()

exports.testSetValue = (test) ->
  test.expect 2
  for i in [48..48+64-1]
    stream.writeFast$int i
  test.equal stream.getBufferBytes().slice(0, 64).toString(),
          "0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmno"
  test.equal stream.getBufferLength(), 64
  test.done()

