2016-04-25 16:33:43 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
|
|
var PrinterUtils = require('../src/printer-utils.js').PrinterUtils;
|
|
|
|
|
|
|
|
|
|
describe('Utils', function() {
|
|
|
|
|
describe('getHtmlId', function() {
|
|
|
|
|
it('should generate file unique id', function() {
|
|
|
|
|
var result = PrinterUtils.getHtmlId({
|
|
|
|
|
oldName: 'sample.js',
|
|
|
|
|
newName: 'sample.js'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('d2h-960013', result);
|
|
|
|
|
});
|
2016-04-25 18:24:35 +00:00
|
|
|
it('should generate file unique id for empty hashes', function() {
|
|
|
|
|
var result = PrinterUtils.getHtmlId({
|
|
|
|
|
oldName: 'sample.js',
|
|
|
|
|
newName: 'sample.js'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('d2h-960013', result);
|
|
|
|
|
});
|
2016-04-25 16:33:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getDiffName', function() {
|
|
|
|
|
it('should generate the file name for a changed file', function() {
|
|
|
|
|
var result = PrinterUtils.getDiffName({
|
|
|
|
|
oldName: 'sample.js',
|
|
|
|
|
newName: 'sample.js'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('sample.js', result);
|
|
|
|
|
});
|
|
|
|
|
it('should generate the file name for a changed file and renamed', function() {
|
|
|
|
|
var result = PrinterUtils.getDiffName({
|
|
|
|
|
oldName: 'sample1.js',
|
|
|
|
|
newName: 'sample2.js'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('sample1.js -> sample2.js', result);
|
|
|
|
|
});
|
|
|
|
|
it('should generate the file name for a deleted file', function() {
|
|
|
|
|
var result = PrinterUtils.getDiffName({
|
|
|
|
|
oldName: 'src/my/file.js',
|
|
|
|
|
newName: '/dev/null'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('src/my/file.js', result);
|
|
|
|
|
});
|
|
|
|
|
it('should generate the file name for a new file', function() {
|
|
|
|
|
var result = PrinterUtils.getDiffName({
|
|
|
|
|
oldName: '/dev/null',
|
|
|
|
|
newName: 'src/my/file.js'
|
|
|
|
|
});
|
|
|
|
|
assert.equal('src/my/file.js', result);
|
|
|
|
|
});
|
2016-04-25 18:24:35 +00:00
|
|
|
it('should generate handle undefined filenames', function() {
|
|
|
|
|
var result = PrinterUtils.getDiffName({});
|
|
|
|
|
assert.equal('Unknown filename', result);
|
|
|
|
|
});
|
2016-04-25 16:33:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('diffHighlight', function() {
|
|
|
|
|
it('should highlight two lines', function() {
|
|
|
|
|
var result = PrinterUtils.diffHighlight(
|
2016-04-25 18:24:35 +00:00
|
|
|
'-var myVar = 2;',
|
|
|
|
|
'+var myVariable = 3;',
|
2016-04-25 16:33:43 +00:00
|
|
|
{matching: 'words'}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual({
|
2016-04-25 18:24:35 +00:00
|
|
|
first: {
|
|
|
|
|
prefix: '-',
|
|
|
|
|
line: 'var <del>myVar</del> = <del>2</del>;'
|
|
|
|
|
},
|
2016-04-25 16:33:43 +00:00
|
|
|
second: {
|
2016-04-25 18:24:35 +00:00
|
|
|
prefix: '+',
|
|
|
|
|
line: 'var <ins>myVariable</ins> = <ins>3</ins>;'
|
2016-04-25 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
}, result);
|
|
|
|
|
});
|
|
|
|
|
it('should highlight two lines char by char', function() {
|
|
|
|
|
var result = PrinterUtils.diffHighlight(
|
2016-04-25 18:24:35 +00:00
|
|
|
'-var myVar = 2;',
|
|
|
|
|
'+var myVariable = 3;',
|
2016-04-25 16:33:43 +00:00
|
|
|
{charByChar: true}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual({
|
2016-04-25 18:24:35 +00:00
|
|
|
first: {
|
|
|
|
|
prefix: '-',
|
|
|
|
|
line: 'var myVar = <del>2</del>;'
|
|
|
|
|
},
|
|
|
|
|
second: {
|
|
|
|
|
prefix: '+',
|
|
|
|
|
line: 'var myVar<ins>iable</ins> = <ins>3</ins>;'
|
|
|
|
|
}
|
|
|
|
|
}, result);
|
|
|
|
|
});
|
|
|
|
|
it('should highlight combined diff lines', function() {
|
|
|
|
|
var result = PrinterUtils.diffHighlight(
|
|
|
|
|
' -var myVar = 2;',
|
|
|
|
|
' +var myVariable = 3;',
|
|
|
|
|
{
|
|
|
|
|
isCombined: true,
|
|
|
|
|
matching: 'words',
|
|
|
|
|
matchWordsThreshold: 1.00
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.deepEqual({
|
|
|
|
|
first: {
|
|
|
|
|
prefix: ' -',
|
|
|
|
|
line: 'var <del class="d2h-change">myVar</del> = <del class="d2h-change">2</del>;'
|
|
|
|
|
},
|
2016-04-25 16:33:43 +00:00
|
|
|
second: {
|
2016-04-25 18:24:35 +00:00
|
|
|
prefix: ' +',
|
|
|
|
|
line: 'var <ins class="d2h-change">myVariable</ins> = <ins class="d2h-change">3</ins>;'
|
2016-04-25 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
}, result);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|