diff --git a/test/patch/apply.js b/test/patch/apply.js index d5b06ace..266f2adc 100755 --- a/test/patch/apply.js +++ b/test/patch/apply.js @@ -525,6 +525,7 @@ describe('patch/apply', function() { + ' line5\n')) .to.equal(false); }); + it('should succeed within fuzz factor', function() { expect(applyPatch( 'line2\n' @@ -736,6 +737,24 @@ describe('patch/apply', function() { expect(applyPatch(oldContent, patch)).to.equal(newContent); }); + + // Regression test based on bug https://github.com/kpdecker/jsdiff/issues/177 + it('should correctly apply a patch that truncates an entire file', function() { + const patch = parsePatch( + '===================================================================\n' + + '--- index.js\n' + + '+++ index.js\n' + + '@@ -1,3 +1,0 @@\n' + + '-this\n' + + '-\n' + + '-tos\n' + + '\\ No newline at end of file\n' + ); + const fileContents = 'this\n\ntos'; + + expect(applyPatch(fileContents, patch)) + .to.equal(''); + }); }); describe('#applyPatches', function() {