-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Separate unit tests from functional test
- Loading branch information
Showing
5 changed files
with
147 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* global describe, it */ | ||
import { expect } from 'chai' | ||
import { matchProgress, matchPropsColon, matchPropsEquals } from '../../lib/parser.js' | ||
|
||
describe('Specification: parser.js', function () { | ||
it('matchProgress() should return undefined on non match', function () { | ||
const r = matchProgress('Colon info: type colon info') | ||
expect(r).to.be.undefined | ||
}) | ||
|
||
it('matchProgress() should return undefined on pseudo-empty line', function () { | ||
const r = matchProgress(' ') | ||
expect(r).to.be.undefined | ||
}) | ||
|
||
it('matchProgress() should return progress info as int', function () { | ||
const digit1File = matchProgress(' 1% 3') | ||
expect(digit1File.percent).to.equal(1) | ||
expect(digit1File.fileCount).to.equal(3) | ||
|
||
const digit2File = matchProgress(' 42% 234') | ||
expect(digit2File.percent).to.equal(42) | ||
expect(digit2File.fileCount).to.equal(234) | ||
|
||
const digit3File = matchProgress('100% 23877') | ||
expect(digit3File.percent).to.equal(100) | ||
expect(digit3File.fileCount).to.equal(23877) | ||
|
||
const digit1NoFile = matchProgress(' 1%') | ||
expect(digit1NoFile.percent).to.equal(1) | ||
|
||
const digit2NoFile = matchProgress(' 42%') | ||
expect(digit2NoFile.percent).to.equal(42) | ||
|
||
const digit3NoFile = matchProgress('100%') | ||
expect(digit3NoFile.percent).to.equal(100) | ||
}) | ||
|
||
it('matchProgress() should return file on add', function () { | ||
const r = matchProgress('+ test/file') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('+') | ||
expect(r['file']).to.equal('test/file') | ||
}) | ||
|
||
it('matchProgress() should return file on update', function () { | ||
const r = matchProgress('U test/file') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('U') | ||
expect(r['file']).to.equal('test/file') | ||
}) | ||
|
||
it('matchProgress() should return file on test', function () { | ||
const r = matchProgress('T test/file') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('T') | ||
expect(r['file']).to.equal('test/file') | ||
}) | ||
|
||
it('matchProgress() should return file on Windows drive', function () { | ||
const r = matchProgress('+ C:\\test\\file') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('+') | ||
expect(r['file']).to.equal('C:\\test\\file') | ||
}) | ||
|
||
it('matchProgress() should return file on Windows remote', function () { | ||
const r = matchProgress('+ \\test\\file') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('+') | ||
expect(r['file']).to.equal('\\test\\file') | ||
}) | ||
|
||
it('matchProgress() should return file with emoji☕️', function () { | ||
const r = matchProgress('T test/f☕️le') | ||
expect(r).to.be.an('object') | ||
expect(r['symbol']).to.equal('T') | ||
expect(r['file']).to.equal('test/f☕️le') | ||
}) | ||
|
||
it('matchProgress() should parse files with or without progress', function () { | ||
const case1 = ` 0%\x08\x08\x08\x08 \x08\x08\x08\x08+ DirImages/LICENSE` | ||
const case2 = ` 29% 4\x08\x08\x08\x08 \x08\x08\x08\x08 36% 4\x08\x08\x08\x08 \x08\x08\x08\x08 40% 4\x08\x08\x08\x08 \x08\x08\x08\x08+ DirImages/architecture-art-colorful-161154.jpg` | ||
const case3 = `+ DirImages/LICENSE` | ||
const r1 = matchProgress(case1) | ||
const r2 = matchProgress(case2) | ||
const r3 = matchProgress(case3) | ||
expect(r1.percent).to.equal(0) | ||
expect(r1.symbol).to.equal('+') | ||
expect(r1.file).to.equal('DirImages/LICENSE') | ||
expect(r2.percent).to.equal(40) | ||
expect(r2.fileCount).to.equal(4) | ||
expect(r2.symbol).to.equal('+') | ||
expect(r2.file).to.equal('DirImages/architecture-art-colorful-161154.jpg') | ||
expect(r3.symbol).to.equal('+') | ||
expect(r3.file).to.equal('DirImages/LICENSE') | ||
}) | ||
|
||
it('matchPropsColon() should return null on non match', function () { | ||
const r = matchPropsColon('+ test/file/null') | ||
expect(r).to.be.null | ||
}) | ||
|
||
it('matchPropsColon() should return props and values', function () { | ||
const basic = matchPropsColon('Prop: Data') | ||
expect(basic).to.be.an('array') | ||
expect(basic).to.have.lengthOf(1) | ||
expect(basic[0]['Prop']).to.equal('Data') | ||
|
||
const space = matchPropsColon('Prop of archive: 322 MB') | ||
expect(space).to.be.an('array') | ||
expect(space).to.have.lengthOf(1) | ||
expect(space[0]['Prop of archive']).to.equal('322 MB') | ||
}) | ||
|
||
it('matchPropsColon() should works with line containing 2 infos', function () { | ||
const basic = matchPropsColon('Prop1: Data1, # Prop2: Data2') | ||
expect(basic).to.be.an('array') | ||
expect(basic).to.have.lengthOf(2) | ||
expect(basic[0]['Prop1']).to.equal('Data1') | ||
expect(basic[1]['Prop2']).to.equal('Data2') | ||
|
||
const space = matchPropsColon('Prop 1: Data 1, # Prop 2: Data 2') | ||
expect(space).to.be.an('array') | ||
expect(space).to.have.lengthOf(2) | ||
expect(space[0]['Prop 1']).to.equal('Data 1') | ||
expect(space[1]['Prop 2']).to.equal('Data 2') | ||
}) | ||
|
||
it('matchPropsEquals() should return null on non match', function () { | ||
const r = matchPropsEquals('+ test/file/null') | ||
expect(r).to.be.null | ||
}) | ||
|
||
it('matchPropsEquals() should return props and values', function () { | ||
const basic = matchPropsEquals('Prop = Data') | ||
expect(basic).to.be.an('array') | ||
expect(basic).to.have.lengthOf(1) | ||
expect(basic[0]['Prop']).to.equal('Data') | ||
|
||
const space = matchPropsEquals('Prop of archive = 322 MB') | ||
expect(space).to.be.an('array') | ||
expect(space).to.have.lengthOf(1) | ||
expect(space[0]['Prop of archive']).to.equal('322 MB') | ||
}) | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters