aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-15 22:42:48 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-03-15 23:19:01 +0800
commitf6c01520ae75d173937f0847ac45e636b06f4146 (patch)
tree6c16d0a8050bf470fd9a7e93c88b8f840b35b604 /packages/sol-cov/src
parent40ebb533b324bf7dd454243fcb1ee092ab85f7eb (diff)
downloaddexon-sol-tools-f6c01520ae75d173937f0847ac45e636b06f4146.tar.gz
dexon-sol-tools-f6c01520ae75d173937f0847ac45e636b06f4146.tar.zst
dexon-sol-tools-f6c01520ae75d173937f0847ac45e636b06f4146.zip
Add tests for sol-cov
Diffstat (limited to 'packages/sol-cov/src')
-rw-r--r--packages/sol-cov/src/ast_visitor.ts4
-rw-r--r--packages/sol-cov/src/collect_coverage_entries.ts2
-rw-r--r--packages/sol-cov/src/coverage_manager.ts2
-rw-r--r--packages/sol-cov/src/globals.d.ts3
-rw-r--r--packages/sol-cov/src/source_maps.ts11
5 files changed, 11 insertions, 11 deletions
diff --git a/packages/sol-cov/src/ast_visitor.ts b/packages/sol-cov/src/ast_visitor.ts
index 66190afec..88309d3eb 100644
--- a/packages/sol-cov/src/ast_visitor.ts
+++ b/packages/sol-cov/src/ast_visitor.ts
@@ -113,8 +113,8 @@ export class ASTVisitor {
this._statementMap[this._entryId++] = this._getExpressionRange(ast);
}
private _getExpressionRange(ast: Parser.ASTNode): SingleFileSourceRange {
- const start = this._locationByOffset[ast.range[0] - 1];
- const end = this._locationByOffset[ast.range[1]];
+ const start = this._locationByOffset[ast.range[0]];
+ const end = this._locationByOffset[ast.range[1] + 1];
const range = {
start,
end,
diff --git a/packages/sol-cov/src/collect_coverage_entries.ts b/packages/sol-cov/src/collect_coverage_entries.ts
index 6da81fbfc..97218616c 100644
--- a/packages/sol-cov/src/collect_coverage_entries.ts
+++ b/packages/sol-cov/src/collect_coverage_entries.ts
@@ -10,7 +10,7 @@ import { getLocationByOffset } from './source_maps';
// Parsing source code for each transaction/code is slow and therefore we cache it
const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {};
-export const collectCoverageEntries = (contractSource: string, fileName: string) => {
+export const collectCoverageEntries = (contractSource: string) => {
const sourceHash = ethUtil.sha3(contractSource).toString('hex');
if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) {
const ast = parser.parse(contractSource, { range: true });
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts
index b1ba8b22b..230ccc3c9 100644
--- a/packages/sol-cov/src/coverage_manager.ts
+++ b/packages/sol-cov/src/coverage_manager.ts
@@ -39,7 +39,7 @@ export class CoverageManager {
fileIndex: number,
): Coverage {
const fileName = contractData.sources[fileIndex];
- const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex], fileName);
+ const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex]);
let sourceRanges = _.map(coveredPcs, coveredPc => pcToSourceRange[coveredPc]);
sourceRanges = _.compact(sourceRanges); // Some PC's don't map to a source range and we just ignore them.
// By default lodash does a shallow object comparasion. We JSON.stringify them and compare as strings.
diff --git a/packages/sol-cov/src/globals.d.ts b/packages/sol-cov/src/globals.d.ts
index 3e457f0b5..0ee0f394c 100644
--- a/packages/sol-cov/src/globals.d.ts
+++ b/packages/sol-cov/src/globals.d.ts
@@ -1,5 +1,6 @@
-// tslint:disable:completed-docs
+declare module 'dirty-chai';
+// tslint:disable:completed-docs
declare module '*.json' {
const json: any;
/* tslint:disable */
diff --git a/packages/sol-cov/src/source_maps.ts b/packages/sol-cov/src/source_maps.ts
index 9b3ea9e24..694171442 100644
--- a/packages/sol-cov/src/source_maps.ts
+++ b/packages/sol-cov/src/source_maps.ts
@@ -12,12 +12,12 @@ export interface SourceLocation {
}
export function getLocationByOffset(str: string): LocationByOffset {
- const locationByOffset: LocationByOffset = {};
+ const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } };
let currentOffset = 0;
for (const char of str.split('')) {
- const location = locationByOffset[currentOffset - 1] || { line: 1, column: 0 };
+ const location = locationByOffset[currentOffset];
const isNewline = char === '\n';
- locationByOffset[currentOffset] = {
+ locationByOffset[currentOffset + 1] = {
line: location.line + (isNewline ? 1 : 0),
column: isNewline ? 0 : location.column + 1,
};
@@ -59,9 +59,8 @@ export function parseSourceMap(
if (parsedEntry.fileIndex !== -1) {
const sourceRange = {
location: {
- start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset - 1],
- end:
- locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length - 1],
+ start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset],
+ end: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length],
},
fileName: sources[parsedEntry.fileIndex],
};