Adds test for whitespaces and indentation and adds template for the wrapper
This commit is contained in:
parent
da2cd63a75
commit
e15cde2d6f
4 changed files with 89 additions and 1 deletions
|
|
@ -25,6 +25,10 @@
|
|||
return nunjucksEnv.render('file-diff.html', {'file': file, 'diffs': diffs});
|
||||
};
|
||||
|
||||
LineByLinePrinter.prototype.makeLineByLineHtmlWrapper = function(content) {
|
||||
return nunjucksEnv.render('wrapper.html', {'content': content});
|
||||
};
|
||||
|
||||
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
|
||||
var that = this;
|
||||
var htmlDiffs = diffFiles.map(function(file) {
|
||||
|
|
@ -37,7 +41,7 @@
|
|||
return that.makeFileDiffHtml(file, diffs);
|
||||
});
|
||||
|
||||
return '<div class="d2h-wrapper">\n' + htmlDiffs.join('\n') + '</div>\n';
|
||||
return this.makeLineByLineHtmlWrapper(htmlDiffs.join('\n'));
|
||||
};
|
||||
|
||||
var matcher = Rematch.rematch(function(a, b) {
|
||||
|
|
|
|||
3
src/templates/line-by-line/wrapper.html
Normal file
3
src/templates/line-by-line/wrapper.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<div class="d2h-wrapper">
|
||||
{{ content }}
|
||||
</div>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
var assert = require('assert');
|
||||
var Utils = require('../src/utils.js').Utils;
|
||||
|
||||
var LineByLinePrinter = require('../src/line-by-line-printer.js').LineByLinePrinter;
|
||||
|
||||
|
|
@ -62,6 +63,72 @@ describe('LineByLinePrinter', function() {
|
|||
' </td>\n' +
|
||||
'</tr>\n';
|
||||
|
||||
assert.equal(expected, fileHtml);
|
||||
});
|
||||
it('should convert indents into non breakin spaces (2 white spaces)', function() {
|
||||
|
||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||
var lineByLinePrinter = new LineByLinePrinter({});
|
||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
|
||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||
var expected = '<tr>\n' +
|
||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||
' <div class="line-num1"></div>\n' +
|
||||
' <div class="line-num2">30</div>\n' +
|
||||
' </td>\n' +
|
||||
' <td class="d2h-ins">\n' +
|
||||
' <div class="d2h-code-line d2h-ins">\n' +
|
||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
||||
' </div>\n' +
|
||||
' </td>\n' +
|
||||
'</tr>\n';
|
||||
|
||||
assert.equal(expected, fileHtml);
|
||||
});
|
||||
it('should convert indents into non breakin spaces (4 white spaces)', function() {
|
||||
|
||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||
var lineByLinePrinter = new LineByLinePrinter({});
|
||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', ' test');
|
||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||
var expected = '<tr>\n' +
|
||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||
' <div class="line-num1"></div>\n' +
|
||||
' <div class="line-num2">30</div>\n' +
|
||||
' </td>\n' +
|
||||
' <td class="d2h-ins">\n' +
|
||||
' <div class="d2h-code-line d2h-ins">\n' +
|
||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
||||
' </div>\n' +
|
||||
' </td>\n' +
|
||||
'</tr>\n';
|
||||
|
||||
assert.equal(expected, fileHtml);
|
||||
});
|
||||
it('should convert indents into non breakin spaces (one tab)', function() {
|
||||
|
||||
var diffParser = require('../src/diff-parser.js').DiffParser;
|
||||
var lineByLinePrinter = new LineByLinePrinter({});
|
||||
var fileHtml = lineByLinePrinter.makeLineHtml(
|
||||
diffParser.LINE_TYPE.INSERTS, '', 30, '+', Utils.escape('\ttest'));
|
||||
fileHtml = fileHtml.replace(/\n\n+/g, '\n');
|
||||
var expected = '<tr>\n' +
|
||||
' <td class="d2h-code-linenumber d2h-ins">\n' +
|
||||
' <div class="line-num1"></div>\n' +
|
||||
' <div class="line-num2">30</div>\n' +
|
||||
' </td>\n' +
|
||||
' <td class="d2h-ins">\n' +
|
||||
' <div class="d2h-code-line d2h-ins">\n' +
|
||||
' <span class="d2h-code-line-prefix"> test</span>\n' +
|
||||
' <span class="d2h-code-line-ctn">+</span>\n' +
|
||||
' </div>\n' +
|
||||
' </td>\n' +
|
||||
'</tr>\n';
|
||||
|
||||
assert.equal(expected, fileHtml);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,4 +22,18 @@ describe('Utils', function() {
|
|||
assert.equal(expected, result);
|
||||
});
|
||||
});
|
||||
describe('convertWhiteSpaceToNonBreakingSpace', function() {
|
||||
it('should escape 1 whitespaces with ', function() {
|
||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
||||
assert.equal(' ', result);
|
||||
});
|
||||
it('should escape 2 whitespaces with ', function() {
|
||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
||||
assert.equal(' ', result);
|
||||
});
|
||||
it('should escape 4 whitespaces with ', function() {
|
||||
var result = Utils.convertWhiteSpaceToNonBreakingSpace(' ');
|
||||
assert.equal(' ', result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue