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

Commit

Permalink
empty_lines: count last line
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 12, 2018
1 parent a0ca48b commit b1b66a3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
10 changes: 5 additions & 5 deletions lib/es5/index.js
Expand Up @@ -508,11 +508,6 @@ function (_Transform) {
}
}

if (this.state.wasRowDelimiter === true) {
this.info.lines++;
this.state.wasRowDelimiter = false;
}

if (end === true) {
if (this.state.quoting === true) {
var _err4 = this.__error("Invalid Closing Quote: quote is not closed at line ".concat(this.info.lines));
Expand All @@ -535,6 +530,11 @@ function (_Transform) {
} else {
this.state.previousBuf = buf.slice(pos);
}

if (this.state.wasRowDelimiter === true) {
this.info.lines++;
this.state.wasRowDelimiter = false;
}
}
}, {
key: "__isCharTrimable",
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
Expand Up @@ -369,10 +369,6 @@ class Parser extends Transform {
if(err !== undefined) return err
}
}
if(this.state.wasRowDelimiter === true){
this.info.lines++
this.state.wasRowDelimiter = false
}
if(end === true){
if(this.state.quoting === true){
const err = this.__error(`Invalid Closing Quote: quote is not closed at line ${this.info.lines}`)
Expand All @@ -391,6 +387,10 @@ class Parser extends Transform {
}else{
this.state.previousBuf = buf.slice(pos)
}
if(this.state.wasRowDelimiter === true){
this.info.lines++
this.state.wasRowDelimiter = false
}
}
__isCharTrimable(chr){
return chr === space || chr === cr || chr === nl
Expand Down
35 changes: 35 additions & 0 deletions test/info.empty_lines.coffee
@@ -0,0 +1,35 @@

parse = require '../lib'

describe 'properties empty_lines', ->

it 'no lines', (next) ->
parse '', (err, data, {empty_lines}) ->
empty_lines.should.eql 0
next()

it 'no empty lines', (next) ->
parse '''
a,b,c
d,e,f
''', (err, data, {empty_lines}) ->
empty_lines.should.eql 0
next()

it 'one line in the middle of dataset', (next) ->
parse '''
a,b,c
d,e,f
''', skip_empty_lines: true, (err, data, {empty_lines}) ->
empty_lines.should.eql 1
next()

it 'one line at the end of dataset', (next) ->
parse '''
a,b,c
d,e,f
''', (err, data, {empty_lines}) ->
empty_lines.should.eql 1
next()
File renamed without changes.
Expand Up @@ -3,15 +3,6 @@ parse = require '../lib'

describe 'properties lines_count', ->

it 'adds up with default settings', (next) ->
parser = parse()
parser.on 'data', -> while this.read() then null
parser.on 'end', ->
this.info.lines.should.eql(this.info.records + this.info.empty_lines + this.info.skipped_lines)
next()
parser.write 'ABC\n\nDEF'
parser.end()

it 'displays no skipped lines when not skip_empty_lines', (next) ->
parser = parse skip_empty_lines: false
parser.on 'readable', ->
Expand Down
File renamed without changes.

0 comments on commit b1b66a3

Please sign in to comment.