Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 55 lines (48 sloc) 1.77 kB
748a62b @wdavidw Convert delimiter to coffee
authored
1
d8ab520 @wdavidw Convert lib to coffee
authored
2 ###
3 Test CSV - Copyright David Worms <open@adaltas.com> (BSD Licensed)
4 ###
748a62b @wdavidw Convert delimiter to coffee
authored
5
d8ab520 @wdavidw Convert lib to coffee
authored
6 require 'coffee-script'
748a62b @wdavidw Convert delimiter to coffee
authored
7 fs = require 'fs'
8fee268 @wdavidw Convert all tests to mocha and should
authored
8 should = require 'should'
49a9b8a @wdavidw Integrate test coverage
authored
9 csv = if process.env.CSV_COV then require '../lib-cov/csv' else require '../src/csv'
748a62b @wdavidw Convert delimiter to coffee
authored
10
8fee268 @wdavidw Convert all tests to mocha and should
authored
11 describe 'delimiter', ->
ffdd75b @wdavidw Convert indentation to two spaces
authored
12
13 it 'Test empty value', (next) ->
14 csv()
15 .from.path( "#{__dirname}/delimiter/empty_value.in" )
16 .to.path( "#{__dirname}/delimiter/empty_value.tmp" )
17 .transform (record, index) ->
18 record.length.should.eql 5
19 if index is 0
20 record[1].should.eql ''
21 record[4].should.eql ''
22 else if index is 1
23 record[0].should.eql ''
24 record[3].should.eql ''
25 record[4].should.eql ''
26 record
a2b8f8f @wdavidw Externalize stringier code; Remove all buffer related code
authored
27 .on 'close', (count) ->
ffdd75b @wdavidw Convert indentation to two spaces
authored
28 count.should.eql 2
29 expect = fs.readFileSync "#{__dirname}/delimiter/empty_value.out"
30 result = fs.readFileSync "#{__dirname}/delimiter/empty_value.tmp"
31 result.should.eql expect
32 fs.unlink "#{__dirname}/delimiter/empty_value.tmp", next
33
34 it 'Test tabs to comma', (next) ->
35 csv()
36 .from.path( "#{__dirname}/delimiter/tab_to_coma.in", delimiter: '\t' )
37 .to.path( "#{__dirname}/delimiter/tab_to_coma.tmp", delimiter: ',' )
38 .transform (record, index) ->
39 record.length.should.eql 5
40 if index is 0
41 record[1].should.eql ''
42 record[4].should.eql ''
43 else if index is 1
44 record[0].should.eql ''
45 record[3].should.eql ''
46 record[4].should.eql ''
47 record
a2b8f8f @wdavidw Externalize stringier code; Remove all buffer related code
authored
48 .on 'close', (count) ->
ffdd75b @wdavidw Convert indentation to two spaces
authored
49 count.should.eql 2
50 expect = fs.readFileSync "#{__dirname}/delimiter/tab_to_coma.out"
51 result = fs.readFileSync "#{__dirname}/delimiter/tab_to_coma.tmp"
52 result.should.eql expect
53 fs.unlink "#{__dirname}/delimiter/tab_to_coma.tmp", next
748a62b @wdavidw Convert delimiter to coffee
authored
54
Something went wrong with that request. Please try again.