diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-16 17:49:20 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-16 17:49:20 +0800 |
commit | a9b1dcb32ab72e7f0f8423bd519f80df12281dbe (patch) | |
tree | 6262ef188952635789a9347d7319de923d2322a5 /packages/sol-cov/test/collect_coverage_entries_test.ts | |
parent | 8f8577b7c6387c13799fc78c448d9d19cf361f40 (diff) | |
download | dexon-0x-contracts-a9b1dcb32ab72e7f0f8423bd519f80df12281dbe.tar.gz dexon-0x-contracts-a9b1dcb32ab72e7f0f8423bd519f80df12281dbe.tar.zst dexon-0x-contracts-a9b1dcb32ab72e7f0f8423bd519f80df12281dbe.zip |
Add a complex test for ast visitor
Diffstat (limited to 'packages/sol-cov/test/collect_coverage_entries_test.ts')
-rw-r--r-- | packages/sol-cov/test/collect_coverage_entries_test.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/sol-cov/test/collect_coverage_entries_test.ts b/packages/sol-cov/test/collect_coverage_entries_test.ts index 84451686f..c7bc45bbf 100644 --- a/packages/sol-cov/test/collect_coverage_entries_test.ts +++ b/packages/sol-cov/test/collect_coverage_entries_test.ts @@ -60,5 +60,70 @@ describe('Collect coverage entries', () => { ); expect(coverageEntries.modifiersStatementIds).to.be.deep.equal([]); }); + it('correctly collects coverage entries for AllSolidityFeatures contract', () => { + const simpleStorageContractBaseName = 'AllSolidityFeatures.sol'; + const simpleStorageContractFileName = path.resolve( + __dirname, + 'fixtures/contracts', + simpleStorageContractBaseName, + ); + const simpleStorageContract = fs.readFileSync(simpleStorageContractFileName).toString(); + const coverageEntries = collectCoverageEntries(simpleStorageContract); + const fnDescriptions = _.values(coverageEntries.fnMap); + const fnNames = _.map(fnDescriptions, fnDescription => fnDescription.name); + const expectedFnNames = [ + 'f', + 'c', + 'test', + 'getChoice', + 'Base', + 'Derived', + 'f', + 'f', + '', + 'g', + 'setData', + 'getData', + 'sendHalf', + 'insert', + 'remove', + 'contains', + 'iterate_start', + 'iterate_valid', + 'iterate_advance', + 'iterate_get', + 'insert', + 'sum', + 'restricted', + 'DualIndex', + 'set', + 'transfer_ownership', + 'lookup', + '', + '', + 'sum', + 'someFunction', + 'fun', + 'at', + 'test', + 'get', + 'returnNumber', + 'alloc', + 'ham', + 'getMyTuple', + 'ham', + 'abstain', + 'foobar', + 'foobar', + 'a', + ]; + expect(fnNames).to.be.deep.equal(expectedFnNames); + + const branchDescriptions = _.values(coverageEntries.branchMap); + const branchLines = _.map(branchDescriptions, branchDescription => branchDescription.line); + expect(branchLines).to.be.deep.equal([94, 115, 119, 130, 151, 187]); + const branchTypes = _.map(branchDescriptions, branchDescription => branchDescription.type); + expect(branchTypes).to.be.deep.equal(['if', 'if', 'if', 'if', 'binary-expr', 'if']); + }); }); }); |