Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* Modified by Piotr Kaminski.
* Modified by Piotr Kaminski and Sergei Vorobev.
*/

/**
Expand Down Expand Up @@ -297,6 +297,9 @@ diff.prototype.diff_lineMode_ = function(text1, text2, deadline) {
}
diffs.pop(); // Remove the dummy entry at the end.

// Cleanup one more time after the rediff.
this.diff_cleanupSemantic(diffs);

return diffs;
};

Expand Down
1 change: 1 addition & 0 deletions tests/diff_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
'testDiffCommonSuffix',
'testDiffCommonOverlap',
'testDiffHalfMatch',
'testDiffLineMode',
'testDiffLinesToChars',
'testDiffCharsToLines',
'testDiffCleanupMerge',
Expand Down
30 changes: 30 additions & 0 deletions tests/diff_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ function testDiffCleanupSemanticLossless() {
diffs = [[DIFF_EQUAL, 'AAA\r\n\r\nBBB'], [DIFF_INSERT, '\r\nDDD\r\n\r\nBBB'], [DIFF_EQUAL, '\r\nEEE']];
dmp.diff_cleanupSemanticLossless(diffs);
assertEquivalent([[DIFF_EQUAL, 'AAA\r\n\r\n'], [DIFF_INSERT, 'BBB\r\nDDD\r\n\r\n'], [DIFF_EQUAL, 'BBB\r\nEEE']], diffs);
// Blank lines, next level
diffs = [
[DIFF_EQUAL, 'websites:\n'],
[DIFF_DELETE, 'name: ADP\nurl: https://www.adp.com\ntfa: No\n\n'],
[DIFF_EQUAL, 'name: Adirondack Insurance Exchange\nurl: http://www.aie-ny.com/\nimg: adirondackinsurnaceexchange.png\n'],
[DIFF_INSERT, 'tfa: No\n\nname: ADP\nurl: https://www.adp.com\n'],
[DIFF_EQUAL, 'tfa: No\n\nname: Credit Karma'],
];
dmp.diff_cleanupSemanticLossless(diffs);
assertEquivalent([
[DIFF_EQUAL, 'websites:\n'],
[DIFF_DELETE, 'name: ADP\nurl: https://www.adp.com\ntfa: No\n\n'],
[DIFF_EQUAL, 'name: Adirondack Insurance Exchange\nurl: http://www.aie-ny.com/\nimg: adirondackinsurnaceexchange.png\ntfa: No\n\n'],
[DIFF_INSERT, 'name: ADP\nurl: https://www.adp.com\ntfa: No\n\n'],
[DIFF_EQUAL, 'name: Credit Karma'],
], diffs);

// Line boundaries.
diffs = [[DIFF_EQUAL, 'AAA\r\nBBB'], [DIFF_INSERT, ' DDD\r\nBBB'], [DIFF_EQUAL, ' EEE']];
Expand Down Expand Up @@ -635,6 +651,20 @@ function testDiffMain() {
}
}

function testDiffLineMode() {
// Test lines aligment (at the blank line border) in line-mode.
a = 'websites:\n - name: ADP\n url: https://www.adp.com\n twitter: adp\n img: adp.png\n tfa: No\n\n - name: Adirondack Insurance Exchange\n url: http://www.aie-ny.com/\n img: adirondackinsurnaceexchange.png\n tfa: No\n\n - name: Credit Karma\n url: https://www.creditkarma.com\n twitter: creditkarma';
b = 'websites:\n - name: Adirondack Insurance Exchange\n url: http://www.aie-ny.com/\n img: adirondackinsurnaceexchange.png\n tfa: No\n\n - name: ADP\n url: https://www.adp.com\n twitter: adp\n img: adp.png\n tfa: No\n\n - name: Credit Karma\n url: https://www.creditkarma.com\n twitter: creditkarma';
assertEquivalent(
[
[DIFF_EQUAL, 'websites:\n'],
[DIFF_DELETE, ' - name: ADP\n url: https://www.adp.com\n twitter: adp\n img: adp.png\n tfa: No\n\n'],
[DIFF_EQUAL, ' - name: Adirondack Insurance Exchange\n url: http://www.aie-ny.com/\n img: adirondackinsurnaceexchange.png\n tfa: No\n\n'],
[DIFF_INSERT, ' - name: ADP\n url: https://www.adp.com\n twitter: adp\n img: adp.png\n tfa: No\n\n'],
[DIFF_EQUAL, ' - name: Credit Karma\n url: https://www.creditkarma.com\n twitter: creditkarma']
], dmp.diff_lineMode_(a, b)
);
}

// MATCH TEST FUNCTIONS

Expand Down
2 changes: 1 addition & 1 deletion tests/speedtest.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <H1>Diff Speed Test</H1>
// No warmup loop since it risks triggering an 'unresponsive script' dialog
// in client-side JavaScript
var ms_start = (new Date()).getTime();
var d = dmp.diff_main(text1, text2, false);
var d = dmp.diff_lineMode_(text1, text2);
var ms_end = (new Date()).getTime();

var ds = dmp.diff_prettyHtml(d);
Expand Down