From 09d422be7948c1e29a563237a3a0ef3d2c91ed1d Mon Sep 17 00:00:00 2001 From: Paulo Bu Date: Wed, 23 Dec 2015 14:12:32 +0100 Subject: [PATCH] Adds simple tests for utils and diff2html --- test/diff2html-tests.js | 26 ++++++++++++++++++++++++++ test/utils-tests.js | 25 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/diff2html-tests.js create mode 100644 test/utils-tests.js diff --git a/test/diff2html-tests.js b/test/diff2html-tests.js new file mode 100644 index 0000000..5e33112 --- /dev/null +++ b/test/diff2html-tests.js @@ -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); + }); + }); +}); diff --git a/test/utils-tests.js b/test/utils-tests.js new file mode 100644 index 0000000..69f9ab5 --- /dev/null +++ b/test/utils-tests.js @@ -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('\tlink text'); + var expected = '<a href="#"> link text</a>'; + assert.equal(expected, result); + }); + }); +});