|
| 1 | +/* eslint-env mocha */ |
| 2 | + |
| 3 | +const chai = require('chai'); |
| 4 | +chai.should(); |
| 5 | + |
| 6 | +const CoverageFile = require('../../lib/CoverageFile'); |
| 7 | + |
| 8 | +describe('Unit | CoverageFile', function () { |
| 9 | + it('should be constructable with the new operator', async function () { |
| 10 | + const instance = new CoverageFile('test-lcov.info'); |
| 11 | + |
| 12 | + instance.should.be.instanceOf(CoverageFile); |
| 13 | + instance.should.have.property('filename', 'test-lcov.info'); |
| 14 | + instance.should.have.property('BRDARecords').eql([]); |
| 15 | + instance.should.have.property('DARecords').eql([]); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should allow DA records to be added', async function () { |
| 19 | + const instance = new CoverageFile('test-lcov.info'); |
| 20 | + |
| 21 | + instance.DARecords.should.have.length(0); |
| 22 | + |
| 23 | + instance.addDA(10, 1); |
| 24 | + instance.DARecords.should.have.length(1); |
| 25 | + instance.DARecords[0].should.have.property('lineNumber', 10); |
| 26 | + instance.DARecords[0].should.have.property('hits', 1); |
| 27 | + |
| 28 | + instance.parseDA('20,2'); |
| 29 | + instance.DARecords.should.have.length(2); |
| 30 | + instance.DARecords[1].should.have.property('lineNumber', 20); |
| 31 | + instance.DARecords[1].should.have.property('hits', 2); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should add hits to an existing DA record when one exists, instead of creating a duplicate', async function () { |
| 35 | + const instance = new CoverageFile('test-lcov.info'); |
| 36 | + |
| 37 | + instance.addDA(10, 1); |
| 38 | + instance.DARecords.should.have.length(1); |
| 39 | + instance.DARecords[0].should.have.property('lineNumber', 10); |
| 40 | + instance.DARecords[0].should.have.property('hits', 1); |
| 41 | + |
| 42 | + instance.addDA(10, 3); |
| 43 | + instance.DARecords.should.have.length(1); |
| 44 | + instance.DARecords[0].should.have.property('lineNumber', 10); |
| 45 | + instance.DARecords[0].should.have.property('hits', 4); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should allow BRDA records to be added', async function () { |
| 49 | + const instance = new CoverageFile('test-lcov.info'); |
| 50 | + |
| 51 | + instance.BRDARecords.should.have.length(0); |
| 52 | + |
| 53 | + instance.addBRDA(10, 20, 30, 40); |
| 54 | + instance.BRDARecords.should.have.length(1); |
| 55 | + instance.BRDARecords[0].should.have.property('lineNumber', 10); |
| 56 | + instance.BRDARecords[0].should.have.property('blockNumber', 20); |
| 57 | + instance.BRDARecords[0].should.have.property('branchNumber', 30); |
| 58 | + instance.BRDARecords[0].should.have.property('hits', 40); |
| 59 | + |
| 60 | + instance.parseBRDA('1,2,3,4'); |
| 61 | + instance.BRDARecords.should.have.length(2); |
| 62 | + instance.BRDARecords[1].should.have.property('lineNumber', 1); |
| 63 | + instance.BRDARecords[1].should.have.property('blockNumber', 2); |
| 64 | + instance.BRDARecords[1].should.have.property('branchNumber', 3); |
| 65 | + instance.BRDARecords[1].should.have.property('hits', 4); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should add hits to an existing BRDA record when one exists, instead of creating a duplicate', async function () { |
| 69 | + const instance = new CoverageFile('test-lcov.info'); |
| 70 | + |
| 71 | + instance.addBRDA(10, 20, 30, 1); |
| 72 | + instance.BRDARecords.should.have.length(1); |
| 73 | + instance.BRDARecords[0].should.have.property('lineNumber', 10); |
| 74 | + instance.BRDARecords[0].should.have.property('blockNumber', 20); |
| 75 | + instance.BRDARecords[0].should.have.property('branchNumber', 30); |
| 76 | + instance.BRDARecords[0].should.have.property('hits', 1); |
| 77 | + |
| 78 | + instance.addBRDA(10, 20, 30, 3); |
| 79 | + instance.BRDARecords.should.have.length(1); |
| 80 | + instance.BRDARecords[0].should.have.property('lineNumber', 10); |
| 81 | + instance.BRDARecords[0].should.have.property('blockNumber', 20); |
| 82 | + instance.BRDARecords[0].should.have.property('branchNumber', 30); |
| 83 | + instance.BRDARecords[0].should.have.property('hits', 4); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should output a valid string representation of its content', async function () { |
| 87 | + const instance = new CoverageFile('test-lcov.info'); |
| 88 | + |
| 89 | + instance.addBRDA(10, 20, 30, 40); |
| 90 | + instance.addDA(50, 60); |
| 91 | + |
| 92 | + instance |
| 93 | + .toString() |
| 94 | + .should.equal( |
| 95 | + 'SF:test-lcov.info\n' + |
| 96 | + 'DA:50,60\n' + |
| 97 | + 'BRDA:10,20,30,40\n' + |
| 98 | + 'end_of_record\n' |
| 99 | + ); |
| 100 | + }); |
| 101 | +}); |
0 commit comments