Merge pull request #59 from rtfpessoa/fix-windows-parsing
Fix parsing on Windows
This commit is contained in:
commit
4e9dfa76ba
2 changed files with 69 additions and 0 deletions
|
|
@ -124,6 +124,7 @@
|
||||||
|
|
||||||
var diffLines =
|
var diffLines =
|
||||||
diffInput.replace(/\\ No newline at end of file/g, '')
|
diffInput.replace(/\\ No newline at end of file/g, '')
|
||||||
|
.replace(/\r\n?/g, '\n')
|
||||||
.split('\n');
|
.split('\n');
|
||||||
|
|
||||||
/* Diff */
|
/* Diff */
|
||||||
|
|
|
||||||
68
test/diff-parser-tests.js
Normal file
68
test/diff-parser-tests.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var DiffParser = require('../src/diff-parser.js').DiffParser;
|
||||||
|
|
||||||
|
describe('DiffParser', function() {
|
||||||
|
describe('generateDiffJson', function() {
|
||||||
|
|
||||||
|
it('should parse unix with \n diff', 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' +
|
||||||
|
'+test1r\n';
|
||||||
|
checkDiffSample(diff)
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should parse windows with \r\n diff', function() {
|
||||||
|
var diff =
|
||||||
|
'diff --git a/sample b/sample\r\n' +
|
||||||
|
'index 0000001..0ddf2ba\r\n' +
|
||||||
|
'--- a/sample\r\n' +
|
||||||
|
'+++ 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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue