Skip to content

Commit f08137f

Browse files
committed
Improve branch coverage
1 parent 95322eb commit f08137f

File tree

10 files changed

+267
-146
lines changed

10 files changed

+267
-146
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta10",
3+
"version": "2.0.0-beta15",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ process.umask = function() { return 0; };
27582758
})();
27592759

27602760
},{"./printer-utils.js":28}],25:[function(require,module,exports){
2761-
(function (global,__dirname){
2761+
(function (__dirname){
27622762
/*
27632763
*
27642764
* Utils (hoganjs-utils.js)
@@ -2776,7 +2776,6 @@ process.umask = function() { return 0; };
27762776
var hoganTemplates = require('./templates/diff2html-templates.js');
27772777

27782778
var templatesPath = path.resolve(__dirname, 'templates');
2779-
var templatesCache = {};
27802779

27812780
function HoganJsUtils() {
27822781
}
@@ -2815,7 +2814,7 @@ process.umask = function() { return 0; };
28152814
var templatePath = path.join(templatesPath, templateKey);
28162815
var templateContent = fs.readFileSync(templatePath + '.mustache', 'utf8');
28172816
template = hogan.compile(templateContent);
2818-
templatesCache[templateKey] = template;
2817+
hoganTemplates[templateKey] = template;
28192818
}
28202819
} catch (e) {
28212820
console.error('Failed to read (template: ' + templateKey + ') from fs: ' + e.message);
@@ -2825,9 +2824,7 @@ process.umask = function() { return 0; };
28252824
};
28262825

28272826
HoganJsUtils.prototype._readFromCache = function(templateKey) {
2828-
return global.browserTemplates && global.browserTemplates[templateKey] ||
2829-
hoganTemplates[templateKey] ||
2830-
templatesCache[templateKey];
2827+
return hoganTemplates[templateKey];
28312828
};
28322829

28332830
HoganJsUtils.prototype._templateKey = function(namespace, view) {
@@ -2838,7 +2835,7 @@ process.umask = function() { return 0; };
28382835

28392836
})();
28402837

2841-
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},"/src")
2838+
}).call(this,"/src")
28422839
},{"./templates/diff2html-templates.js":31,"fs":1,"hogan.js":18,"path":20}],26:[function(require,module,exports){
28432840
/*
28442841
*
@@ -3084,10 +3081,6 @@ process.umask = function() { return 0; };
30843081
var i, chr, len;
30853082
var hash = 0;
30863083

3087-
if (text.length === 0) {
3088-
return hash;
3089-
}
3090-
30913084
for (i = 0, len = text.length; i < len; i++) {
30923085
chr = text.charCodeAt(i);
30933086
hash = ((hash << 5) - hash) + chr;
@@ -3104,8 +3097,7 @@ process.umask = function() { return 0; };
31043097
var oldFilename = file.oldName;
31053098
var newFilename = file.newName;
31063099

3107-
if (oldFilename && newFilename && oldFilename !== newFilename &&
3108-
!isDevNullName(oldFilename) && !isDevNullName(newFilename)) {
3100+
if (oldFilename && newFilename && oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) {
31093101
return oldFilename + ' -> ' + newFilename;
31103102
} else if (newFilename && !isDevNullName(newFilename)) {
31113103
return newFilename;
@@ -3226,13 +3218,6 @@ process.umask = function() { return 0; };
32263218
(function() {
32273219

32283220
var Rematch = {};
3229-
Rematch.arrayToString = function arrayToString(a) {
3230-
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
3231-
return "[" + a.map(arrayToString).join(", ") + "]";
3232-
} else {
3233-
return a;
3234-
}
3235-
};
32363221

32373222
/*
32383223
Copyright (c) 2011 Andrei Mackenzie

dist/diff2html.min.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta13",
3+
"version": "2.0.0-beta15",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [
@@ -38,7 +38,7 @@
3838
"scripts": {
3939
"release": "./scripts/release.sh",
4040
"templates": "./scripts/hulk.js --wrapper node --variable 'browserTemplates' ./src/templates/*.mustache > ./src/templates/diff2html-templates.js",
41-
"test": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
41+
"test": "jscs src/*.js src/ui/js/*.js && istanbul cover _mocha -- -u exports -R spec ./test/**/* && istanbul check-coverage --statements 90 --functions 90 --branches 85 --lines 90 ./coverage/coverage.json",
4242
"style": "jscs src/*.js src/ui/js/*.js",
4343
"codacy": "istanbul cover _mocha -- -u exports -R spec ./test/**/* && cat ./coverage/lcov.info | codacy-coverage"
4444
},

src/hoganjs-utils.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
var hoganTemplates = require('./templates/diff2html-templates.js');
1616

1717
var templatesPath = path.resolve(__dirname, 'templates');
18-
var templatesCache = {};
1918

2019
function HoganJsUtils() {
2120
}
@@ -54,7 +53,7 @@
5453
var templatePath = path.join(templatesPath, templateKey);
5554
var templateContent = fs.readFileSync(templatePath + '.mustache', 'utf8');
5655
template = hogan.compile(templateContent);
57-
templatesCache[templateKey] = template;
56+
hoganTemplates[templateKey] = template;
5857
}
5958
} catch (e) {
6059
console.error('Failed to read (template: ' + templateKey + ') from fs: ' + e.message);
@@ -64,9 +63,7 @@
6463
};
6564

6665
HoganJsUtils.prototype._readFromCache = function(templateKey) {
67-
return global.browserTemplates && global.browserTemplates[templateKey] ||
68-
hoganTemplates[templateKey] ||
69-
templatesCache[templateKey];
66+
return hoganTemplates[templateKey];
7067
};
7168

7269
HoganJsUtils.prototype._templateKey = function(namespace, view) {

src/printer-utils.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
var i, chr, len;
2020
var hash = 0;
2121

22-
if (text.length === 0) {
23-
return hash;
24-
}
25-
2622
for (i = 0, len = text.length; i < len; i++) {
2723
chr = text.charCodeAt(i);
2824
hash = ((hash << 5) - hash) + chr;
@@ -39,8 +35,7 @@
3935
var oldFilename = file.oldName;
4036
var newFilename = file.newName;
4137

42-
if (oldFilename && newFilename && oldFilename !== newFilename &&
43-
!isDevNullName(oldFilename) && !isDevNullName(newFilename)) {
38+
if (oldFilename && newFilename && oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) {
4439
return oldFilename + ' -> ' + newFilename;
4540
} else if (newFilename && !isDevNullName(newFilename)) {
4641
return newFilename;

src/rematch.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
(function() {
1010

1111
var Rematch = {};
12-
Rematch.arrayToString = function arrayToString(a) {
13-
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
14-
return "[" + a.map(arrayToString).join(", ") + "]";
15-
} else {
16-
return a;
17-
}
18-
};
1912

2013
/*
2114
Copyright (c) 2011 Andrei Mackenzie

test/line-by-line-tests.js

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('LineByLinePrinter', function() {
1515
' File without changes\n' +
1616
' </div>\n' +
1717
' </td>\n' +
18-
'</tr>';
18+
'</tr>\n';
1919

2020
assert.equal(expected, fileHtml);
2121
});
@@ -282,21 +282,54 @@ describe('LineByLinePrinter', function() {
282282

283283
assert.equal(expected, html);
284284
});
285-
});
286285

287-
describe('makeColumnLineNumberHtml', function() {
288-
it('should work for simple block header', function() {
289-
var lineByLinePrinter = new LineByLinePrinter({});
290-
var html = lineByLinePrinter.makeColumnLineNumberHtml({
291-
header: '<span>So much html</span>'
292-
});
286+
it('should work for empty blocks', function() {
287+
var exampleJson = [{
288+
blocks: [],
289+
deletedLines: 0,
290+
addedLines: 0,
291+
oldName: 'sample',
292+
language: 'js',
293+
newName: 'sample',
294+
isCombined: false
295+
}];
296+
297+
var lineByLinePrinter = new LineByLinePrinter();
298+
var html = lineByLinePrinter.generateLineByLineJsonHtml(exampleJson);
293299
var expected =
294-
'<tr>\n' +
295-
' <td class="d2h-code-linenumber d2h-info"></td>\n' +
300+
'<div class="d2h-wrapper">\n' +
301+
' <div id="d2h-675094" class="d2h-file-wrapper" data-lang="js">\n' +
302+
' <div class="d2h-file-header">\n' +
303+
' <span class="d2h-file-stats">\n' +
304+
' <span class="d2h-lines-added">\n' +
305+
' <span>+0</span>\n' +
306+
' </span>\n' +
307+
' <span class="d2h-lines-deleted">\n' +
308+
' <span>-0</span>\n' +
309+
' </span>\n' +
310+
' </span>\n' +
311+
' <span class="d2h-file-name-wrapper">\n' +
312+
' <span class="d2h-file-name">&nbsp;sample</span>\n' +
313+
' </span>\n' +
314+
' </div>\n' +
315+
' <div class="d2h-file-diff">\n' +
316+
' <div class="d2h-code-wrapper">\n' +
317+
' <table class="d2h-diff-table">\n' +
318+
' <tbody class="d2h-diff-tbody">\n' +
319+
' <tr>\n' +
296320
' <td class="d2h-info">\n' +
297-
' <div class="d2h-code-line d2h-info"></div>\n' +
321+
' <div class="d2h-code-line d2h-info">\n' +
322+
' File without changes\n' +
323+
' </div>\n' +
298324
' </td>\n' +
299-
'</tr>';
325+
'</tr>\n' +
326+
'\n' +
327+
' </tbody>\n' +
328+
' </table>\n' +
329+
' </div>\n' +
330+
' </div>\n' +
331+
'</div>\n' +
332+
'</div>';
300333

301334
assert.equal(expected, html);
302335
});
@@ -353,16 +386,28 @@ describe('LineByLinePrinter', function() {
353386
var file = {
354387
blocks: [{
355388
lines: [{
356-
content: '-test',
357-
type: 'd2h-del',
389+
content: ' one context line',
390+
type: 'd2h-cntx',
358391
oldNumber: 1,
359-
newNumber: null
392+
newNumber: 1
360393
},
394+
{
395+
content: '-test',
396+
type: 'd2h-del',
397+
oldNumber: 2,
398+
newNumber: null
399+
},
361400
{
362401
content: '+test1r',
363402
type: 'd2h-ins',
364403
oldNumber: null,
365-
newNumber: 1
404+
newNumber: 2
405+
},
406+
{
407+
content: '+test2r',
408+
type: 'd2h-ins',
409+
oldNumber: null,
410+
newNumber: 3
366411
}],
367412
oldStartLine: '1',
368413
oldStartLine2: null,
@@ -388,8 +433,18 @@ describe('LineByLinePrinter', function() {
388433
' <div class="d2h-code-line d2h-info"></div>\n' +
389434
' </td>\n' +
390435
'</tr><tr>\n' +
391-
' <td class="d2h-code-linenumber d2h-del">\n' +
436+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
392437
' <div class="line-num1">1</div>\n' +
438+
' <div class="line-num2">1</div>\n' +
439+
' </td>\n' +
440+
' <td class="d2h-cntx">\n' +
441+
' <div class="d2h-code-line d2h-cntx">\n' +
442+
' <span class="d2h-code-line-ctn">&nbsp;one&nbsp;context&nbsp;line</span>\n' +
443+
' </div>\n' +
444+
' </td>\n' +
445+
'</tr><tr>\n' +
446+
' <td class="d2h-code-linenumber d2h-del">\n' +
447+
' <div class="line-num1">2</div>\n' +
393448
' <div class="line-num2"></div>\n' +
394449
' </td>\n' +
395450
' <td class="d2h-del">\n' +
@@ -401,14 +456,24 @@ describe('LineByLinePrinter', function() {
401456
'</tr><tr>\n' +
402457
' <td class="d2h-code-linenumber d2h-ins">\n' +
403458
' <div class="line-num1"></div>\n' +
404-
' <div class="line-num2">1</div>\n' +
459+
' <div class="line-num2">2</div>\n' +
405460
' </td>\n' +
406461
' <td class="d2h-ins">\n' +
407462
' <div class="d2h-code-line d2h-ins">\n' +
408463
' <span class="d2h-code-line-prefix">+</span>\n' +
409464
' <span class="d2h-code-line-ctn"><ins>test1r</ins></span>\n' +
410465
' </div>\n' +
411466
' </td>\n' +
467+
'</tr><tr>\n' +
468+
' <td class="d2h-code-linenumber d2h-ins">\n' +
469+
' <div class="line-num1"></div>\n' +
470+
' <div class="line-num2">3</div>\n' +
471+
' </td>\n' +
472+
' <td class="d2h-ins">\n' +
473+
' <div class="d2h-code-line d2h-ins">\n' +
474+
' <span class="d2h-code-line-ctn">+test2r</span>\n' +
475+
' </div>\n' +
476+
' </td>\n' +
412477
'</tr>';
413478

414479
assert.equal(expected, html);

0 commit comments

Comments
 (0)