Skip to content

Commit

Permalink
fix: prevent branch highlighting from extending pass the end of a line (
Browse files Browse the repository at this point in the history
  • Loading branch information
vinteo authored and bcoe committed Aug 25, 2017
1 parent bbaf8d3 commit f490377
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/istanbul-reports/lib/html/annotator.js
Expand Up @@ -57,13 +57,12 @@ function annotateStatements(fileCoverage, structuredText) {

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endLine = startLine;
endCol = structuredText[startLine].text.originalLength();
}
text = structuredText[startLine].text;
text.wrap(startCol,
openSpan,
startLine === endLine ? endCol : text.originalLength(),
startCol < endCol ? endCol : text.originalLength(),
closeSpan);
}
});
Expand All @@ -90,13 +89,12 @@ function annotateFunctions(fileCoverage, structuredText) {

if (type === 'no' && structuredText[startLine]) {
if (endLine !== startLine) {
endLine = startLine;
endCol = structuredText[startLine].text.originalLength();
}
text = structuredText[startLine].text;
text.wrap(startCol,
openSpan,
startLine === endLine ? endCol : text.originalLength(),
startCol < endCol ? endCol : text.originalLength(),
closeSpan);
}
});
Expand Down Expand Up @@ -145,7 +143,6 @@ function annotateBranches(fileCoverage, structuredText) {

if (count === 0 && structuredText[startLine]) { //skip branches taken
if (endLine !== startLine) {
endLine = startLine;
endCol = structuredText[startLine].text.originalLength();
}
text = structuredText[startLine].text;
Expand All @@ -159,7 +156,7 @@ function annotateBranches(fileCoverage, structuredText) {
} else {
text.wrap(startCol,
openSpan,
startLine === endLine ? endCol : text.originalLength(),
startCol < endCol ? endCol : text.originalLength(),
closeSpan);
}
}
Expand Down
25 changes: 25 additions & 0 deletions packages/istanbul-reports/test/fixtures/github-80a.json
@@ -0,0 +1,25 @@
{
"statementMap": {
"0": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 0
}
}
},
"fnMap": {
},
"branchMap": {
},
"s": {
"0": 0
},
"f": {
},
"b": {
}
}
38 changes: 38 additions & 0 deletions packages/istanbul-reports/test/fixtures/github-80b.json
@@ -0,0 +1,38 @@
{
"statementMap": {
},
"fnMap": {
"0": {
"name": "test",
"decl": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 0
}
},
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
}
}
},
"branchMap": {
},
"s": {
},
"f": {
"0": 0
},
"b": {
}
}
42 changes: 42 additions & 0 deletions packages/istanbul-reports/test/fixtures/github-80c.json
@@ -0,0 +1,42 @@
{
"statementMap": {
},
"fnMap": {
},
"branchMap": {
"0": {
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"type": "default-arg",
"locations": [
{
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 0
}
}
]
}
},
"s": {
},
"f": {
},
"b": {
"0": [
0
]
}
}
33 changes: 33 additions & 0 deletions packages/istanbul-reports/test/html/annotator.js
Expand Up @@ -32,5 +32,38 @@ describe('annotator', function () {
});
annotated.annotatedCode[0].should.not.match(/Cannot read property/);
});

// see: https://github.com/istanbuljs/istanbuljs/pull/80
it('handles statement meta information with end column less than start column', function () {
var annotated = annotator.annotateSourceCode(getFixture('github-80a'), {
getSource: function () {
return ' var test = "test";';
}
});
annotated.annotatedCode[0].should
.equal('<span class="cstat-no" title="statement not covered" > var test = "test";</span>');
});

// see: https://github.com/istanbuljs/istanbuljs/pull/80
it('handles function meta information with end column less than start column', function () {
var annotated = annotator.annotateSourceCode(getFixture('github-80b'), {
getSource: function () {
return ' function test () {};';
}
});
annotated.annotatedCode[0].should
.equal('<span class="fstat-no" title="function not covered" > function test () {};</span>');
});

// see: https://github.com/istanbuljs/istanbuljs/pull/80
it('handles branch meta information with end column less than start column', function () {
var annotated = annotator.annotateSourceCode(getFixture('github-80c'), {
getSource: function () {
return 'if (cond1 && cond2) {';
}
});
annotated.annotatedCode[0].should
.equal('if (cond1 &amp;&amp; <span class="branch-0 cbranch-no" title="branch not covered" >cond2) {</span>');
});
});
});

0 comments on commit f490377

Please sign in to comment.