Skip to content

Commit

Permalink
test: 100% coverage on parser.js
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Sep 28, 2018
1 parent 5618ad7 commit 441b761
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export function matchProgress (line) {
export function matchPropsEquals (line) {
const regexp = /^(?<property>.+) = (?<value>.+)$/
const match = line.match(regexp)
if (match) {
const groups = match.groups
const props = {[groups.property]: groups.value}
return [props]
} else {
return null
}
if (match) {
const groups = match.groups
const prop = {[groups.property]: groups.value}
return [prop]
} else {
return null
}
}

export function matchSymbolFile (line) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "npx mocha -r esm",
"coverage": "npx nyc --reporter=html --reporter=lcov npx mocha -r esm",
"coveralls": "npx nyc report --reporter=text-lcov | npx coveralls"
"coveralls": "cat ./coverage/lcov.info | npx coveralls"
},
"repository": {
"type": "git",
Expand Down
53 changes: 53 additions & 0 deletions test/lib/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,57 @@ describe('Specification: parser.js', function () {
expect(space).to.have.lengthOf(1)
expect(space[0]['Prop of archive']).to.equal('322 MB')
})

it('matchSymbolFile() should return null on non match', function () {
const r = matchSymbolFile('random/test/file/null')
expect(r).to.be.null
})

it('matchSymbolFile() should return file on add', function () {
const r = matchSymbolFile('+ test/file')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('+')
expect(r[0]['file']).to.equal('test/file')
})

it('matchSymbolFile() should return file on update', function () {
const r = matchSymbolFile('U test/file')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('U')
expect(r[0]['file']).to.equal('test/file')
})

it('matchSymbolFile() should return file on test', function () {
const r = matchSymbolFile('T test/file')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('T')
expect(r[0]['file']).to.equal('test/file')
})

it('matchSymbolFile() should return file on Windows drive', function () {
const r = matchSymbolFile('+ C:\\test\\file')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('+')
expect(r[0]['file']).to.equal('C:\\test\\file')
})

it('matchSymbolFile() should return file on Windows remote', function () {
const r = matchSymbolFile('+ \\test\\file')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('+')
expect(r[0]['file']).to.equal('\\test\\file')
})

it('matchSymbolFile() should return file with emoji☕️', function () {
const r = matchSymbolFile('T test/f☕️le')
expect(r).to.be.an('array')
expect(r).to.have.lengthOf(1)
expect(r[0]['symbol']).to.equal('T')
expect(r[0]['file']).to.equal('test/f☕️le')
})
})

0 comments on commit 441b761

Please sign in to comment.