 Path     = require 'fspath'
 
 describe 'test kevas', ->
+
+  it 'should use a noop function when not given values', ->
+
+    string = 'test {{noop}} function'
+    transform = kevas()
+
+    calledData = []
+    transform.on 'data', (data) -> calledData.push data
+    transform.end string
+
+    assert calledData.length > 0
+    for each, index in calledData
+      assert Buffer.isBuffer(each), 'index ' + index + ' isnt a buffer'
+    assert.equal Buffer.concat(calledData).toString(), string
+
+
+  it 'should use a values function when given', ->
+
+    string = 'test {{value}} function'
+    transform = kevas values: (key) -> if key is 'value' then 'VALUE'
+
+    calledData = []
+    transform.on 'data', (data) -> calledData.push data
+    transform.end string
+
+    assert calledData.length > 0
+    for each, index in calledData
+      assert Buffer.isBuffer(each), 'index ' + index + ' isnt a buffer'
+    assert.equal Buffer.concat(calledData).toString(), 'test VALUE function'
+
+
+  it 'should use a noop function when given an invalid values type', ->
+
+    string = 'test {{noop}} function'
+    transform = kevas values: 123
+
+    calledData = []
+    transform.on 'data', (data) -> calledData.push data
+    transform.end string
+
+    assert calledData.length > 0
+    for each, index in calledData
+      assert Buffer.isBuffer(each), 'index ' + index + ' isnt a buffer'
+    assert.equal Buffer.concat(calledData).toString(), string
+
+
+  it 'should leave key wrapped with braces when there\'s no value for the key', ->
+
+    string = 'test {{unknown}} function'
+    transform = kevas values: {}
+
+    calledData = []
+    transform.on 'data', (data) -> calledData.push data
+    transform.end string
+
+    assert calledData.length > 0
+    for each, index in calledData
+      assert Buffer.isBuffer(each), 'index ' + index + ' isnt a buffer'
+    assert.equal Buffer.concat(calledData).toString(), string
+
 
   shouldReplaceKeyWithValue = 'should replace the key with its value'
   for test in [

      values: key:'good'
      result:'some good value'
    }

  ]
    do (test) ->
      describe test.desc, ->

        it test.should ? shouldReplaceKeyWithValue, (done) ->

          # create a through stream as a pass-through to pipe to our stream
          input = through()

          # create our stream with values provided by the test
          stream = kevas values:test.values

          # create a sink stream to collect all it receives into a string
          output = strung()

          # when all writes are finished then verify the results
          output.on 'finish', ->
            assert.equal output?.string, test.result
            done() # tell Mocha the test is done

          # send any errors to Mocha's callback
          input.on  'error', done
          stream.on 'error', done
          output.on 'error', done

          # pipe our test input to our stream and then to our output collector.
          input.pipe(stream).pipe(output)

          # asynchronously write chunks to the input stream
          # allow for pause/resume with on-drain.
          index = 0
          ready = true
          writeout = (error) ->
            if error? then return done error
            unless ready then return input.once('drain', writeout)
            if index < test.output.length
              ready = input.write test.output[index], 'utf8', writeout
              index++
            else
              input.end()

          writeout()

# TODO: set of tests using a file stream as input (use filed? or paths?)
  describe 'with json file input stream', ->

    it 'should convert unescaped keys to values', (done) ->

      dir = new Path 'test/helpers'

      file = dir.to 'kevas.json'

      expected = JSON.parse dir.to('expected.kevas.json').read()

      stream = kevas values:key:'good'

      output = strung()

      # when all writes are finished then verify the results
      output.on 'finish', (error) ->
        if error? then return done error
        result = JSON.parse output.string
        assert.deepEqual result, expected
        done() # tell Mocha the test is done

      # send any errors to Mocha's callback
      stream.on 'error', done
      output.on 'error', done

      options = # send errors to `done`
        reader:
          events:
            'error': done
        writer:
          events:
            'error': done

      # pipe our test input to our stream and then to our output collector.
      file.pipe(stream, options).pipe(output)




    }
    {
      desc: 'with escaped opening brace'
      should:'should include the braces without the slash'
      output:['some \\{{ value']
      values: key:'good'
      result:'some {{ value'
    }
    {
      desc: 'with escaped closing brace'
      should:'should include the brace without the slash'
      output:['some {{key\\}}} value']
      values: 'key}':'good'
      result:'some good value'
    }
    {
      desc: 'with an escape slash before first opening brace which voids key'
