Skip to content

Commit 423d177

Browse files
committed
Document and test ignoreWhiteSpace for createPatch
1 parent d358a57 commit 423d177

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ npm install diff --save
7272
* `oldStr` : Original string value
7373
* `newStr` : New string value
7474
* `oldHeader` : Additional information to include in the old file header
75-
* `newHeader` : Additional information to include in the new file header
76-
* `options` : An object with options. Currently, only `context` is supported and describes how many lines of context should be included.
75+
* `newHeader` : Additional information to include in the new file header* `options` : An object with options.
76+
- `context` describes how many lines of context should be included.
77+
- `ignoreWhitespace`: `true` to ignore leading and trailing whitespace.
7778

7879
* `Diff.createPatch(fileName, oldStr, newStr, oldHeader, newHeader)` - creates a unified diff patch.
7980

test/patch/create.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,37 @@ describe('patch/create', function() {
631631
const diffResult = createTwoFilesPatch('foo', 'bar', '', '');
632632
expect(diffResult).to.equal(expectedResult);
633633
});
634+
635+
describe('ignoreWhitespace', function() {
636+
it('ignoreWhitespace: false', function() {
637+
const expectedResult =
638+
'Index: testFileName\n'
639+
+ '===================================================================\n'
640+
+ '--- testFileName\n'
641+
+ '+++ testFileName\n'
642+
+ '@@ -1,2 +1,2 @@\n'
643+
+ '-line \n'
644+
+ '- line\n'
645+
+ '\\ No newline at end of file\n'
646+
+ '+line\n'
647+
+ '+line\n'
648+
+ '\\ No newline at end of file\n';
649+
650+
const diffResult = createPatch('testFileName', 'line \n\ line', 'line\n\line', undefined, undefined, {ignoreWhitespace: false});
651+
expect(diffResult).to.equal(expectedResult);
652+
});
653+
654+
it('ignoreWhitespace: true', function() {
655+
const expectedResult =
656+
'Index: testFileName\n'
657+
+ '===================================================================\n'
658+
+ '--- testFileName\n'
659+
+ '+++ testFileName\n';
660+
661+
const diffResult = createPatch('testFileName', 'line \n\ line', 'line\n\line', undefined, undefined, {ignoreWhitespace: true});
662+
expect(diffResult).to.equal(expectedResult);
663+
});
664+
});
634665
});
635666

636667
describe('#structuredPatch', function() {

0 commit comments

Comments
 (0)