Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
escape: test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 8, 2018
1 parent 1bded5e commit 83a917e
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions test/options.escape.coffee
Expand Up @@ -3,27 +3,51 @@ parse = require '../src'

describe 'options escape', ->

it 'only apply to quote and escape characters', (next) ->
parse """
20322051544,"19""79.0",8.8017226E7,"A""B""C",45,2000-01-01
28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
""", escape: '"', (err, data) ->
it 'is same as quote', (next) ->
parse '''
aa,"b1""b2","c""d""e"
"f""g",h,"i1""i2"
''', escape: '"', (err, data) ->
return next err if err
data.should.eql [
[ '20322051544','19"79.0','8.8017226E7','A"B"C','45','2000-01-01' ]
[ '28392898392','1974.0','8.8392926E7','DEF','23','2050-11-27' ]
[ 'aa','b1"b2','c"d"e' ]
[ 'f"g','h','i1"i2' ]
]
next()

it 'should honor the backslash escape charactere', (next) ->
parse """
20322051544,"19\\"79.0",8.8017226E7,"A\\"B\\"C",45,2000-01-01
28392898392,1974.0,8.8392926E7,DEF,23,2050-11-27
""", escape: '\\', (err, data) ->
it 'is different than quote and apply to quote char', (next) ->
parse '''
aa,"b1\\"b2","c\\"d\\"e"
"f\\"g",h,"i1\\"i2"
''', escape: '\\', (err, data) ->
return next err if err
data.should.eql [
[ '20322051544','19\"79.0','8.8017226E7','A\"B\"C','45','2000-01-01' ]
[ '28392898392','1974.0','8.8392926E7','DEF','23','2050-11-27' ]
[ 'aa','b1"b2','c"d"e' ]
[ 'f"g','h','i1"i2' ]
]
next()

it 'is different than quote and apply to escape char', (next) ->
parse '''
aa,"b1\\\\b2","c\\\\d\\\\e"
"f\\\\g",h,"i1\\\\i2"
''', escape: '\\', (err, data) ->
return next err if err
data.should.eql [
[ 'aa','b1\\b2','c\\d\\e' ]
[ 'f\\g','h','i1\\i2' ]
]
next()

it 'is different than quote and apply to escape char outside quoted field', (next) ->
parse '''
aa,b1\\\\b2,c\\\\d\\\\e
f\\\\g,h,i1\\\\i2
''', escape: '\\', (err, data) ->
return next err if err
data.should.eql [
[ 'aa','b1\\b2','c\\d\\e' ]
[ 'f\\g','h','i1\\i2' ]
]
next()

Expand All @@ -35,9 +59,10 @@ describe 'options escape', ->
data.push d
parser.on 'end', ->
data.should.eql [
[ 'field with " inside' ]
[ 'abc " def' ]
]
next()
parser.write '"field with \\'
parser.write '" inside"'
parser.write chr for chr in '''
"abc \\" def"
'''
parser.end()

0 comments on commit 83a917e

Please sign in to comment.