From 93dd3223822c09f291a87e57ccb1901c09576376 Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sun, 7 Feb 2016 12:47:00 +0000 Subject: [PATCH] Add more eol tests for old os x and mixed eols --- test/diff-parser-tests.js | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/test/diff-parser-tests.js b/test/diff-parser-tests.js index f2b924c..0f842ee 100644 --- a/test/diff-parser-tests.js +++ b/test/diff-parser-tests.js @@ -5,7 +5,7 @@ var DiffParser = require('../src/diff-parser.js').DiffParser; describe('DiffParser', function() { describe('generateDiffJson', function() { - it('should parse linux with \n diff', function() { + it('should parse unix with \n diff', function() { var diff = 'diff --git a/sample b/sample\n' + 'index 0000001..0ddf2ba\n' + @@ -14,14 +14,7 @@ describe('DiffParser', function() { '@@ -1 +1 @@\n' + '-test\n' + '+test1r\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); + checkDiffSample(diff) }); it('should parse windows with \r\n diff', function() { @@ -32,7 +25,35 @@ describe('DiffParser', function() { '+++ b/sample\r\n' + '@@ -1 +1 @@\r\n' + '-test\r\n' + + '+test1r\r\n'; + checkDiffSample(diff) + }); + + it('should parse old os x with \r diff', function() { + var diff = + 'diff --git a/sample b/sample\r' + + 'index 0000001..0ddf2ba\r' + + '--- a/sample\r' + + '+++ b/sample\r' + + '@@ -1 +1 @@\r' + + '-test\r' + + '+test1r\r'; + checkDiffSample(diff) + }); + + it('should parse mixed eols diff', function() { + var diff = + 'diff --git a/sample b/sample\n' + + 'index 0000001..0ddf2ba\r\n' + + '--- a/sample\r' + + '+++ b/sample\r\n' + + '@@ -1 +1 @@\n' + + '-test\r' + '+test1r\n'; + checkDiffSample(diff) + }); + + function checkDiffSample(diff) { var result = Diff2Html.getJsonFromDiff(diff); var file1 = result[0]; assert.equal(1, result.length); @@ -41,7 +62,7 @@ describe('DiffParser', function() { assert.equal('sample', file1.oldName); assert.equal('sample', file1.newName); assert.equal(1, file1.blocks.length); - }); + } }); });