Skip to content

Commit

Permalink
Add test showing patch from bug #177 is handled correctly now (#447)
Browse files Browse the repository at this point in the history
* Fix a trivial code formatting inconsistency

* Add test showing patch from bug #177 is handled correctly now
  • Loading branch information
ExplodingCabbage committed Dec 27, 2023
1 parent e35c347 commit a2dc5ec
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/patch/apply.js
Expand Up @@ -525,6 +525,7 @@ describe('patch/apply', function() {
+ ' line5\n'))
.to.equal(false);
});

it('should succeed within fuzz factor', function() {
expect(applyPatch(
'line2\n'
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a2dc5ec

Please sign in to comment.