Skip to content

Commit 723a2f7

Browse files
Add test showing patch from bug #177 is handled correctly now
1 parent eaa3ce8 commit 723a2f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/patch/apply.js

+18
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,24 @@ describe('patch/apply', function() {
737737

738738
expect(applyPatch(oldContent, patch)).to.equal(newContent);
739739
});
740+
741+
// Regression test based on bug https://github.com/kpdecker/jsdiff/issues/177
742+
it('should correctly apply a patch that truncates an entire file', function() {
743+
const patch = parsePatch(
744+
'===================================================================\n'
745+
+ '--- index.js\n'
746+
+ '+++ index.js\n'
747+
+ '@@ -1,3 +1,0 @@\n'
748+
+ '-this\n'
749+
+ '-\n'
750+
+ '-tos\n'
751+
+ '\\ No newline at end of file\n'
752+
);
753+
const fileContents = 'this\n\ntos';
754+
755+
expect(applyPatch(fileContents, patch))
756+
.to.equal('');
757+
});
740758
});
741759

742760
describe('#applyPatches', function() {

0 commit comments

Comments
 (0)