diff --git a/diff.js b/diff.js index e151a475..fce6422f 100644 --- a/diff.js +++ b/diff.js @@ -196,13 +196,19 @@ return retLines; }; - return { - Diff: Diff, + var SentenceDiff = new Diff(); + SentenceDiff.tokenize = function (value) { + return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/)); + }; + + return { + Diff: Diff, diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); }, diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); }, diffWordsWithSpace: function(oldStr, newStr) { return WordWithSpaceDiff.diff(oldStr, newStr); }, diffLines: function(oldStr, newStr) { return LineDiff.diff(oldStr, newStr); }, + diffSentences: function(oldStr, newStr) { return SentenceDiff.diff(oldStr, newStr); }, diffCss: function(oldStr, newStr) { return CssDiff.diff(oldStr, newStr); }, diff --git a/test/diffTest.js b/test/diffTest.js index e2aa8eab..817376f2 100644 --- a/test/diffTest.js +++ b/test/diffTest.js @@ -69,6 +69,19 @@ describe('#diffWordsWithSpace', function() { }); }); +describe('#diffSentences', function() { + + it('Should diff Sentences', function() { + var diffResult = diff.diffSentences('New Value.', 'New ValueMoreData.'); + diff.convertChangesToXML(diffResult).should.equal('New ValueMoreData.New Value.'); + }); + + it('should diff only the last sentence', function() { + var diffResult = diff.diffSentences('Here im. Rock you like old man.', 'Here im. Rock you like hurricane.'); + diff.convertChangesToXML(diffResult).should.equal('Here im. Rock you like hurricane.Rock you like old man.'); + }); +}); + // CSS Diff describe('#diffCss', function() { it('should diff css', function() {