Merge pull request #44 from pbu88/add-mocha-tests
Adds simple tests for utils and diff2html
This commit is contained in:
commit
598c2d365c
2 changed files with 51 additions and 0 deletions
26
test/diff2html-tests.js
Normal file
26
test/diff2html-tests.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var Diff2Html = require('../src/diff2html.js').Diff2Html;
|
||||||
|
|
||||||
|
describe('Diff2Html', function() {
|
||||||
|
describe('getJsonFromDiff', function() {
|
||||||
|
it('should parse simple diff to json', function() {
|
||||||
|
var diff =
|
||||||
|
'diff --git a/sample b/sample\n'+
|
||||||
|
'index 0000001..0ddf2ba\n'+
|
||||||
|
'--- a/sample\n'+
|
||||||
|
'+++ b/sample\n'+
|
||||||
|
'@@ -1 +1 @@\n'+
|
||||||
|
'-test\n'+
|
||||||
|
'+test1\n';
|
||||||
|
var result = Diff2Html.getJsonFromDiff(diff);
|
||||||
|
var file1 = result[0];
|
||||||
|
assert.equal(1, result.length);
|
||||||
|
assert.equal(1, file1.addedLines);
|
||||||
|
assert.equal(1, file1.deletedLines);
|
||||||
|
assert.equal('sample', file1.oldName);
|
||||||
|
assert.equal('sample', file1.newName);
|
||||||
|
assert.equal(1, file1.blocks.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
25
test/utils-tests.js
Normal file
25
test/utils-tests.js
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var Utils = require('../src/utils.js').Utils;
|
||||||
|
|
||||||
|
describe('Utils', function() {
|
||||||
|
describe('escape', function() {
|
||||||
|
it('should escape & with &', function() {
|
||||||
|
var result = Utils.escape('&');
|
||||||
|
assert.equal('&', result);
|
||||||
|
});
|
||||||
|
it('should escape < with <', function() {
|
||||||
|
var result = Utils.escape('<');
|
||||||
|
assert.equal('<', result);
|
||||||
|
});
|
||||||
|
it('should escape > with >', function() {
|
||||||
|
var result = Utils.escape('>');
|
||||||
|
assert.equal('>', result);
|
||||||
|
});
|
||||||
|
it('should escape a string with multiple problematic characters', function() {
|
||||||
|
var result = Utils.escape('<a href="#">\tlink text</a>');
|
||||||
|
var expected = '<a href="#"> link text</a>';
|
||||||
|
assert.equal(expected, result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue