 assert = require 'power-assert'
 exec = require('child_process').exec
 pack = require '../package.json'
+eol = require('os').EOL
 
 sco = 'node bin/sco '
-
-# trim last linebreak
-t = (str) ->
-  str[0...-1]
 
 encode_testset =
   'ascii':

        do (key, value) ->
          it algo + ': ' + key + ' -> ' + value, (done) ->
            exec sco + "-e #{algo} \"#{key}\"", (error, stdout, stderr) ->
              assert t(stdout) == value
              done()

describe 'cli decode test', ->

        do (key, value) ->
          it algo + ': ' + key + ' -> ' + value, (done) ->
            exec sco + "-d #{algo} \"#{key}\"", (error, stdout, stderr) ->
              assert stdout is value
              done()

describe 'cli encode and decode test using pipes', ->
  it 'echo hello | sco -e base64 | sco -d base64', (done) ->
    test_using_pipe = "echo hello | #{sco} -e base64 | #{sco} -d base64"
    exec test_using_pipe, (error, stdout, stderr) ->
      assert stdout is "hello"+eol
      done()
