Fix parsing body lines starting with --- and +++
This commit is contained in:
parent
730dccf069
commit
7c79cc32db
2 changed files with 33 additions and 4 deletions
|
|
@ -183,8 +183,8 @@
|
||||||
(
|
(
|
||||||
currentFile && // If we already have some file in progress and
|
currentFile && // If we already have some file in progress and
|
||||||
(
|
(
|
||||||
currentFile.oldName && utils.startsWith(line, '---') || // Either we reached a old file identification line
|
currentFile.oldName && utils.startsWith(line, '--- ') || // Either we reached a old file identification line
|
||||||
currentFile.newName && utils.startsWith(line, '+++') // Or we reached a new file identification line
|
currentFile.newName && utils.startsWith(line, '+++ ') // Or we reached a new file identification line
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
@ -198,7 +198,7 @@
|
||||||
* --- 2002-02-21 23:30:39.942229878 -0800
|
* --- 2002-02-21 23:30:39.942229878 -0800
|
||||||
*/
|
*/
|
||||||
if (currentFile && !currentFile.oldName &&
|
if (currentFile && !currentFile.oldName &&
|
||||||
utils.startsWith(line, '---') && (values = getSrcFilename(line, config))) {
|
utils.startsWith(line, '--- ') && (values = getSrcFilename(line, config))) {
|
||||||
currentFile.oldName = values;
|
currentFile.oldName = values;
|
||||||
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
|
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
|
||||||
return;
|
return;
|
||||||
|
|
@ -209,7 +209,7 @@
|
||||||
* +++ 2002-02-21 23:30:39.942229878 -0800
|
* +++ 2002-02-21 23:30:39.942229878 -0800
|
||||||
*/
|
*/
|
||||||
if (currentFile && !currentFile.newName &&
|
if (currentFile && !currentFile.newName &&
|
||||||
utils.startsWith(line, '+++') && (values = getDstFilename(line, config))) {
|
utils.startsWith(line, '+++ ') && (values = getDstFilename(line, config))) {
|
||||||
currentFile.newName = values;
|
currentFile.newName = values;
|
||||||
currentFile.language = getExtension(currentFile.newName, currentFile.language);
|
currentFile.language = getExtension(currentFile.newName, currentFile.language);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -424,5 +424,34 @@ describe('DiffParser', function() {
|
||||||
assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']);
|
assert.deepEqual(linesContent, ['-test', '+test1r', '+test2r']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should parse diff with --- and +++ in the context lines', function() {
|
||||||
|
var diff =
|
||||||
|
'--- sample.js\n' +
|
||||||
|
'+++ sample.js\n' +
|
||||||
|
'@@ -1,15 +1,12 @@\n' +
|
||||||
|
' test\n' +
|
||||||
|
' \n' +
|
||||||
|
'----\n' +
|
||||||
|
'+test\n' +
|
||||||
|
' \n' +
|
||||||
|
' test\n' +
|
||||||
|
'----\n' +
|
||||||
|
'\\ No newline at end of file';
|
||||||
|
|
||||||
|
var result = DiffParser.generateDiffJson(diff);
|
||||||
|
var file1 = result[0];
|
||||||
|
assert.equal(1, result.length);
|
||||||
|
assert.equal(1, file1.addedLines);
|
||||||
|
assert.equal(2, file1.deletedLines);
|
||||||
|
assert.equal('sample.js', file1.oldName);
|
||||||
|
assert.equal('sample.js', file1.newName);
|
||||||
|
assert.equal(1, file1.blocks.length);
|
||||||
|
|
||||||
|
var linesContent = file1.blocks[0].lines.map(function(line) {
|
||||||
|
return line.content;
|
||||||
|
});
|
||||||
|
assert.deepEqual(linesContent, [' test', ' ', '----', '+test', ' ', ' test', '----']);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue