From a2dc5ec38c93a8836a43553fdaabf893870b1043 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Wed, 27 Dec 2023 14:03:03 +0000 Subject: [PATCH] Add test showing patch from bug #177 is handled correctly now (#447) * Fix a trivial code formatting inconsistency * Add test showing patch from bug https://github.com/kpdecker/jsdiff/issues/177 is handled correctly now --- test/patch/apply.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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() {