Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
3652181
Fix assorted trivial capitalisation typos (#410)
ExplodingCabbage Dec 14, 2023
ff14775
Upgrade packages that Dependabot has open PRs about (#415)
ExplodingCabbage Dec 15, 2023
8ca7068
Bump karma from 5.1.1 to 6.3.16 (#357)
dependabot[bot] Dec 15, 2023
0e7a0cb
yarn eslint . --fix (#421)
ExplodingCabbage Dec 15, 2023
bbb2359
Update package.json version to 5.1.0 (#422)
ExplodingCabbage Dec 15, 2023
902e7da
Bump more dependencies to please Dependabot (#425)
ExplodingCabbage Dec 15, 2023
e67c2a0
Bump qs from 6.7.0 to 6.11.0 (#426)
dependabot[bot] Dec 15, 2023
a3759a1
Move demo link to the top of the README (#370)
waldyrious Dec 15, 2023
021c973
chore: update license file (#331)
eddiemonge Dec 16, 2023
87dedb6
readme: add links to section: change objects (#316)
milahu Dec 18, 2023
e0e960a
Document diffJson() options (#332)
cincodenada Dec 18, 2023
976d60d
Fix `exports` field in `package.json` (#351)
fisker Dec 18, 2023
1387be9
Remove index.html from master (#429)
ExplodingCabbage Dec 19, 2023
96f5998
Update comment in index.js to reflect JsDiff->Diff rename in 5.0.0 (#…
ExplodingCabbage Dec 19, 2023
b4d7491
Document in a comment in web_example.html that you need to run a buil…
ExplodingCabbage Dec 19, 2023
f2596ea
Fix a typo (#433)
ExplodingCabbage Dec 20, 2023
6183041
Default value of line delimiters when a patch is applied (#228) (#393)
Cinedin Dec 20, 2023
2e08d01
Fix bug that leads to worse time complexity and cripplingly slow perf…
ExplodingCabbage Dec 23, 2023
5897c8f
Update CONTRIBUTING.md to use yarn (#441)
ExplodingCabbage Dec 23, 2023
a19bded
Fix typo / grammar error in CONTRIBUTING.md (#442)
ExplodingCabbage Dec 23, 2023
14bfcb6
Update release-notes.md with content on npm that never got pushed to …
ExplodingCabbage Dec 23, 2023
8e51326
Write release notes for PRs already merged to master (#444)
ExplodingCabbage Dec 23, 2023
573b7af
Option to strip trailing CR (#344)
oBusk Dec 27, 2023
e35c347
Add release notes for @oBusk's PR #344 (#445)
ExplodingCabbage Dec 27, 2023
a4eac49
Stop treating stuff like vertical tabs as line breaks when dealing wi…
ExplodingCabbage Dec 27, 2023
a2dc5ec
Add test showing patch from bug #177 is handled correctly now (#447)
ExplodingCabbage Dec 27, 2023
bf5ec4a
Flip core algorithm so everything is no longer the mirror image of My…
ExplodingCabbage Dec 27, 2023
97c676d
Merge remote-tracking branch 'origin/master' into 6.0.0-staging
ExplodingCabbage Dec 27, 2023
fe261ae
Prefer to order deletions before insertions when the edit cost is the…
ExplodingCabbage Dec 27, 2023
b1b2035
Speed up algorithm by not considering diagonals that take us off the …
ExplodingCabbage Dec 29, 2023
8bd13d6
Consistently capitalize "jsdiff" in all-lowercase in docs (#449)
ExplodingCabbage Dec 29, 2023
56c6a8a
Expose `formatPatch` on `diff` object and document (#451)
ExplodingCabbage Dec 29, 2023
6a574cc
Merge branch 'master' into 6.0.0-staging
ExplodingCabbage Dec 29, 2023
8365367
Add function to reverse a patch (#450)
ExplodingCabbage Jan 2, 2024
3351c82
Merge remote-tracking branch 'origin/master' into 6.0.0-staging
ExplodingCabbage Jan 2, 2024
3a99253
Always set `added` and `removed` to `true` or `false`, rather than le…
ExplodingCabbage Jan 2, 2024
a98b974
Flesh out the README a bit and fix some errors and omissions (#458)
ExplodingCabbage Jan 4, 2024
c8c5132
Merge branch 'master' into 6.0.0-staging
ExplodingCabbage Jan 4, 2024
c6498e3
Document that applyPatch can return false (#459)
ExplodingCabbage Jan 4, 2024
7eacf2a
Merge branch 'master' into 6.0.0-staging
ExplodingCabbage Jan 5, 2024
b3aab68
Handle case where the user explicitly passes `maxEditLength: 0` the w…
ExplodingCabbage Jan 8, 2024
ea983ba
Fix more gaps in the docs (#466)
ExplodingCabbage Jan 8, 2024
12e092d
Merge remote-tracking branch 'origin/master' into 6.0.0-staging
ExplodingCabbage Jan 8, 2024
e6c45b0
Add a oneChangePerToken option (#460)
ExplodingCabbage Jan 8, 2024
1e79116
Fix order of arguments to .equals and comparator (#467)
ExplodingCabbage Jan 8, 2024
25a14af
Migrate to DABH's fork of colors (#469)
ExplodingCabbage Jan 8, 2024
ca8718c
Bump follow-redirects from 1.14.8 to 1.15.4 (#470)
dependabot[bot] Jan 9, 2024
1c7514c
Fix mistake in README (#471)
ExplodingCabbage Jan 10, 2024
707fccc
Add note to README about setting `context` to Infinity or MAX_SAFE_IN…
ExplodingCabbage Jan 10, 2024
1f1ec96
Replace broken link to Myers's paper in the README with a working one…
ExplodingCabbage Jan 11, 2024
533893d
Add `timeout` option (#478)
ExplodingCabbage Jan 26, 2024
b5d1cfa
Modify node_example.js to support showing added/deleted spaces (#479)
ExplodingCabbage Jan 26, 2024
06a669b
Merge branch 'master' into 6.0.0-staging
ExplodingCabbage Jan 29, 2024
4abb5f3
Support max edit length in patch creation functions (#480)
ExplodingCabbage Jan 29, 2024
dfc6fe4
Add examples to docs of creating and applying patches (importantly in…
ExplodingCabbage Jan 29, 2024
a2f726a
Add myself to the list of maintainers (#482)
ExplodingCabbage Feb 12, 2024
370a9df
5.2.0 release (#483)
ExplodingCabbage Feb 12, 2024
ad635b1
Add a reminder to the releasing docs to update the gh-pages site afte…
ExplodingCabbage Feb 13, 2024
b9f56d3
Merge branch 'master' into 6.0.0-staging
ExplodingCabbage Feb 13, 2024
fc2e36d
Merge pull request #446 from kpdecker/6.0.0-staging
ExplodingCabbage Feb 13, 2024
5f9cd41
Sort out behaviour of newlineIsToken and ignoreWhitespace (#486)
ExplodingCabbage Feb 15, 2024
e83674b
Remove failing test (#487)
ExplodingCabbage Feb 15, 2024
a3e4812
Add some more exhaustive tests based on @Mingun's work (#488)
ExplodingCabbage Feb 15, 2024
13d9749
Fix the weird function signature of async callbacks (#490)
ExplodingCabbage Feb 15, 2024
bf45b03
Fix race conditions involving this.options being overwritten during e…
ExplodingCabbage Feb 15, 2024
a73b771
Add further assertion to test, as suggested by Mingun (#491)
ExplodingCabbage Feb 16, 2024
f38e47d
Support `Object.create(null)` in JSON diffing (#493)
danbeam Feb 19, 2024
3da78c2
Simplify tokenization logic in diffWords (#494)
ExplodingCabbage Feb 19, 2024
7a73dc1
Bump ip from 1.1.5 to 1.1.9 (#495)
dependabot[bot] Feb 21, 2024
f925d4c
Fix trivial typo ("threat"->"treat" in test name) (#498)
ExplodingCabbage Mar 5, 2024
045c346
Add test of how diffWordsWithSpace handles Windows-style newlines (#499)
ExplodingCabbage Mar 6, 2024
490f5ab
Make diffChars diff Unicode code points instead of UTF-16 code units …
ExplodingCabbage Mar 8, 2024
59161e0
Fix diffWords handling of whitespace (#497)
ExplodingCabbage Mar 11, 2024
f4f11df
Bump follow-redirects from 1.15.4 to 1.15.6 (#502)
dependabot[bot] Mar 18, 2024
c9bc8e3
Run: (#503)
ExplodingCabbage Mar 19, 2024
16a060e
Purge inactive/broken Travis and Sauce Labs integrations (#504)
ExplodingCabbage Mar 19, 2024
84b5c9e
Upgrade some more dev dependencies (#505)
ExplodingCabbage Mar 20, 2024
b90a3eb
Bump Mocha one major version (#507)
ExplodingCabbage Mar 20, 2024
64f587c
Always enable "strict mode" in parsePatch (#508)
ExplodingCabbage Mar 20, 2024
53339e2
Remove unused Grunt `version` task; flesh out docs on how to do a rel…
ExplodingCabbage Mar 20, 2024
eb73eb8
Remove style.css from master branch (it's part of the gh-pages site, …
ExplodingCabbage Mar 20, 2024
046b5d3
Bump webpack-dev-middleware from 7.0.0 to 7.1.1 (#511)
dependabot[bot] Mar 22, 2024
4ebc4bf
Bump express from 4.18.3 to 4.19.2 (#512)
dependabot[bot] Apr 28, 2024
c8a9cc5
Remove linedelimiters, improve handling of Windows vs Unix line endin…
ExplodingCabbage Jun 7, 2024
9bb34dc
Support `callback` in patch functions, not just diffFoo functions (#521)
ExplodingCabbage Jun 7, 2024
0126325
Add tests of existing broken parsePatch behaviour, to fix before next…
ExplodingCabbage Jun 14, 2024
5ecab06
Bump braces from 3.0.2 to 3.0.3 (#526)
dependabot[bot] Jun 18, 2024
323e8bb
Fix parse patch bug (#529)
ExplodingCabbage Jun 24, 2024
896c982
Fix release notes typo
ExplodingCabbage Jun 24, 2024
0e7c20c
Add ignoreNewlineAtEof (#530)
ExplodingCabbage Jun 24, 2024
353d117
Rewrite applyPatch (#533)
ExplodingCabbage Jul 26, 2024
939bb45
Fix handling of EOF in createPatch (#535)
ExplodingCabbage Jul 29, 2024
244df82
Fix more logic around newlines at EOF - this time stuff I recently br…
ExplodingCabbage Jul 29, 2024
4f0430a
Add Intl.Segmenter support (#539)
ExplodingCabbage Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Always set added and removed to true or false, rather than le…
…aving them unset or explicitly using `undefined` (kpdecker#455)

* Always set `added` and `removed` to `true` or `false`, rather than leaving them unset or explicitly using `undefined`

Resolves kpdecker#233

* Add release notes
  • Loading branch information
ExplodingCabbage authored Jan 2, 2024
commit 3a9925370336a2782dbfa0a6fd5cdd7e9662abd9
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ All methods above which accept the optional `callback` method will run in sync m
Many of the methods above return change objects. These objects consist of the following fields:
* `value`: Text content
* `added`: True if the value was inserted into the new string
* `removed`: True if the value was removed from the old string
Note that some cases may omit a particular flag field. Comparison on the flag fields should always be done in a truthy or falsy manner.
* `added`: true if the value was inserted into the new string, otherwise false
* `removed`: true if the value was removed from the old string, otherwise false
## Examples
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [#435](https://github.com/kpdecker/jsdiff/pull/435) Fix `parsePatch` handling of control characters. `parsePatch` used to interpret various unusual control characters - namely vertical tabs, form feeds, lone carriage returns without a line feed, and EBCDIC NELs - as line breaks when parsing a patch file. This was inconsistent with the behavior of both JsDiff's own `diffLines` method and also the Unix `diff` and `patch` utils, which all simply treat those control characters as ordinary characters. The result of this discrepancy was that some well-formed patches - produced either by `diff` or by JsDiff itself and handled properly by the `patch` util - would be wrongly parsed by `parsePatch`, with the effect that it would disregard the remainder of a hunk after encountering one of these control characters.
- [#439](https://github.com/kpdecker/jsdiff/pull/439) Prefer diffs that order deletions before insertions. When faced with a choice between two diffs with an equal total edit distance, the Myers diff algorithm generally prefers one that does deletions before insertions rather than insertions before deletions. For instance, when diffing `abcd` against `acbd`, it will prefer a diff that says to delete the `b` and then insert a new `b` after the `c`, over a diff that says to insert a `c` before the `b` and then delete the existing `c`. JsDiff deviated from the published Myers algorithm in a way that led to it having the opposite preference in many cases, including that example. This is now fixed, meaning diffs output by JsDiff will more accurately reflect what the published Myers diff algorithm would output.
- [#455](https://github.com/kpdecker/jsdiff/pull/455) The `added` and `removed` properties of change objects are now guaranteed to be set to a boolean value. (Previously, they would be set to `undefined` or omitted entirely instead of setting them to false.)

## Development

Expand Down
8 changes: 4 additions & 4 deletions src/diff/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Diff.prototype = {
let newPos = this.extractCommon(bestPath[0], newString, oldString, 0);
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
// Identity per the equality and tokenizer
return done([{value: this.join(newString), count: newString.length}]);
return done([{value: this.join(newString), count: newString.length, added: false, removed: false}]);
}

// Once we hit the right edge of the edit graph on some diagonal k, we can
Expand Down Expand Up @@ -95,9 +95,9 @@ Diff.prototype = {
// path whose position in the old string is the farthest from the origin
// and does not pass the bounds of the diff graph
if (!canRemove || (canAdd && removePath.oldPos < addPath.oldPos)) {
basePath = self.addToPath(addPath, true, undefined, 0);
basePath = self.addToPath(addPath, true, false, 0);
} else {
basePath = self.addToPath(removePath, undefined, true, 1);
basePath = self.addToPath(removePath, false, true, 1);
}

newPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
Expand Down Expand Up @@ -173,7 +173,7 @@ Diff.prototype = {
}

if (commonCount) {
basePath.lastComponent = {count: commonCount, previousComponent: basePath.lastComponent};
basePath.lastComponent = {count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false};
}

basePath.oldPos = oldPos;
Expand Down
30 changes: 15 additions & 15 deletions test/diff/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('diff/array', function() {
const diffResult = diffArrays([a, b, c], [a, c, b]);
console.log(diffResult);
expect(diffResult).to.deep.equals([
{count: 1, value: [a]},
{count: 1, value: [b], removed: true, added: undefined},
{count: 1, value: [c]},
{count: 1, value: [b], removed: undefined, added: true}
{count: 1, value: [a], removed: false, added: false},
{count: 1, value: [b], removed: true, added: false},
{count: 1, value: [c], removed: false, added: false},
{count: 1, value: [b], removed: false, added: true}
]);
});
it('should diff falsey values', function() {
Expand All @@ -24,20 +24,20 @@ describe('diff/array', function() {
const arrayB = [c, b, a, b, a, c];
const diffResult = diffArrays(arrayA, arrayB);
expect(diffResult).to.deep.equals([
{count: 2, value: [a, b], removed: true, added: undefined},
{count: 1, value: [c]},
{count: 1, value: [b], removed: undefined, added: true},
{count: 2, value: [a, b]},
{count: 1, value: [b], removed: true, added: undefined},
{count: 1, value: [a]},
{count: 1, value: [c], removed: undefined, added: true}
{count: 2, value: [a, b], removed: true, added: false},
{count: 1, value: [c], removed: false, added: false},
{count: 1, value: [b], removed: false, added: true},
{count: 2, value: [a, b], removed: false, added: false},
{count: 1, value: [b], removed: true, added: false},
{count: 1, value: [a], removed: false, added: false},
{count: 1, value: [c], removed: false, added: true}
]);
});
describe('anti-aliasing', function() {
// Test apparent contract that no chunk value is ever an input argument.
const value = [0, 1, 2];
const expected = [
{count: value.length, value: value}
{count: value.length, value: value, removed: false, added: false}
];

const input = value.slice();
Expand Down Expand Up @@ -70,9 +70,9 @@ describe('diff/array', function() {
const diffResult = diffArrays([a, b, c], [a, b, d], { comparator: comparator });
console.log(diffResult);
expect(diffResult).to.deep.equals([
{count: 2, value: [a, b]},
{count: 1, value: [c], removed: true, added: undefined},
{count: 1, value: [d], removed: undefined, added: true}
{count: 2, value: [a, b], removed: false, added: false},
{count: 1, value: [c], removed: true, added: false},
{count: 1, value: [d], removed: false, added: true}
]);
});
});
Expand Down
82 changes: 41 additions & 41 deletions test/diff/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe('diff/json', function() {
{a: 123, b: 456, c: 789},
{a: 123, b: 456}
)).to.eql([
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n' },
{ count: 1, value: ' "c": 789\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n', removed: false, added: false },
{ count: 1, value: ' "c": 789\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
});

Expand All @@ -21,9 +21,9 @@ describe('diff/json', function() {
{a: 123, b: 456, c: 789},
{b: 456, a: 123}
)).to.eql([
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n' },
{ count: 1, value: ' "c": 789\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n', removed: false, added: false },
{ count: 1, value: ' "c": 789\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
});

Expand All @@ -32,9 +32,9 @@ describe('diff/json', function() {
{a: 123, b: 456, c: [1, 2, {foo: 'bar'}, 4]},
{a: 123, b: 456, c: [1, {foo: 'bar'}, 4]}
)).to.eql([
{ count: 5, value: '{\n "a": 123,\n "b": 456,\n "c": [\n 1,\n' },
{ count: 1, value: ' 2,\n', added: undefined, removed: true },
{ count: 6, value: ' {\n "foo": "bar"\n },\n 4\n ]\n}' }
{ count: 5, value: '{\n "a": 123,\n "b": 456,\n "c": [\n 1,\n', removed: false, added: false },
{ count: 1, value: ' 2,\n', added: false, removed: true },
{ count: 6, value: ' {\n "foo": "bar"\n },\n 4\n ]\n}', removed: false, added: false }
]);
});

Expand All @@ -43,12 +43,12 @@ describe('diff/json', function() {
{a: new Date(123), b: new Date(456), c: new Date(789)},
{a: new Date(124), b: new Date(456)}
)).to.eql([
{ count: 1, value: '{\n' },
{ count: 1, value: ' "a": "1970-01-01T00:00:00.123Z",\n', added: undefined, removed: true },
{ count: 1, value: ' "a": "1970-01-01T00:00:00.124Z",\n', added: true, removed: undefined },
{ count: 1, value: ' "b": "1970-01-01T00:00:00.456Z",\n' },
{ count: 1, value: ' "c": "1970-01-01T00:00:00.789Z"\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 1, value: '{\n', removed: false, added: false },
{ count: 1, value: ' "a": "1970-01-01T00:00:00.123Z",\n', added: false, removed: true },
{ count: 1, value: ' "a": "1970-01-01T00:00:00.124Z",\n', added: true, removed: false },
{ count: 1, value: ' "b": "1970-01-01T00:00:00.456Z",\n', removed: false, added: false },
{ count: 1, value: ' "c": "1970-01-01T00:00:00.789Z"\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
});

Expand All @@ -57,24 +57,24 @@ describe('diff/json', function() {
{a: 123, b: 456, c: null},
{a: 123, b: 456}
)).to.eql([
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n' },
{ count: 1, value: ' "c": null\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n', removed: false, added: false },
{ count: 1, value: ' "c": null\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
expect(diffJson(
{a: 123, b: 456, c: undefined},
{a: 123, b: 456}
)).to.eql([
{ count: 4, value: '{\n "a": 123,\n "b": 456\n}' }
{ count: 4, value: '{\n "a": 123,\n "b": 456\n}', removed: false, added: false }
]);
expect(diffJson(
{a: 123, b: 456, c: undefined},
{a: 123, b: 456},
{undefinedReplacement: null}
)).to.eql([
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n' },
{ count: 1, value: ' "c": null\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n', removed: false, added: false },
{ count: 1, value: ' "c": null\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
});

Expand All @@ -83,9 +83,9 @@ describe('diff/json', function() {
JSON.stringify({a: 123, b: 456, c: 789}, undefined, ' '),
JSON.stringify({a: 123, b: 456}, undefined, ' ')
)).to.eql([
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n' },
{ count: 1, value: ' "c": 789\n', added: undefined, removed: true },
{ count: 1, value: '}' }
{ count: 3, value: '{\n "a": 123,\n "b": 456,\n', removed: false, added: false },
{ count: 1, value: ' "c": 789\n', added: false, removed: true },
{ count: 1, value: '}', removed: false, added: false }
]);
});

Expand Down Expand Up @@ -143,43 +143,43 @@ describe('diff/json', function() {
{a: 123},
{a: /foo/}
)).to.eql([
{ count: 1, value: '{\n' },
{ count: 1, value: ' \"a\": 123\n', added: undefined, removed: true },
{ count: 1, value: ' \"a\": {}\n', added: true, removed: undefined },
{ count: 1, value: '}' }
{ count: 1, value: '{\n', removed: false, added: false },
{ count: 1, value: ' \"a\": 123\n', added: false, removed: true },
{ count: 1, value: ' \"a\": {}\n', added: true, removed: false },
{ count: 1, value: '}', removed: false, added: false }
]);

expect(diffJson(
{a: 123},
{a: /foo/gi},
{stringifyReplacer: (k, v) => v instanceof RegExp ? v.toString() : v}
)).to.eql([
{ count: 1, value: '{\n' },
{ count: 1, value: ' \"a\": 123\n', added: undefined, removed: true },
{ count: 1, value: ' \"a\": "/foo/gi"\n', added: true, removed: undefined },
{ count: 1, value: '}' }
{ count: 1, value: '{\n', removed: false, added: false },
{ count: 1, value: ' \"a\": 123\n', added: false, removed: true },
{ count: 1, value: ' \"a\": "/foo/gi"\n', added: true, removed: false },
{ count: 1, value: '}', removed: false, added: false }
]);

expect(diffJson(
{a: 123},
{a: new Error('ohaider')},
{stringifyReplacer: (k, v) => v instanceof Error ? `${v.name}: ${v.message}` : v}
)).to.eql([
{ count: 1, value: '{\n' },
{ count: 1, value: ' \"a\": 123\n', added: undefined, removed: true },
{ count: 1, value: ' \"a\": "Error: ohaider"\n', added: true, removed: undefined },
{ count: 1, value: '}' }
{ count: 1, value: '{\n', removed: false, added: false },
{ count: 1, value: ' \"a\": 123\n', added: false, removed: true },
{ count: 1, value: ' \"a\": "Error: ohaider"\n', added: true, removed: false },
{ count: 1, value: '}', removed: false, added: false }
]);

expect(diffJson(
{a: 123},
{a: [new Error('ohaider')]},
{stringifyReplacer: (k, v) => v instanceof Error ? `${v.name}: ${v.message}` : v}
)).to.eql([
{ count: 1, value: '{\n' },
{ count: 1, value: ' \"a\": 123\n', added: undefined, removed: true },
{ count: 3, value: ' \"a\": [\n "Error: ohaider"\n ]\n', added: true, removed: undefined },
{ count: 1, value: '}' }
{ count: 1, value: '{\n', removed: false, added: false },
{ count: 1, value: ' \"a\": 123\n', added: false, removed: true },
{ count: 3, value: ' \"a\": [\n "Error: ohaider"\n ]\n', added: true, removed: false },
{ count: 1, value: '}', removed: false, added: false }
]);
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/diff/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ describe('diff/line', function() {

describe('#diffLinesNL', function() {
expect(diffLines('restaurant', 'restaurant\n', {newlineIsToken: true})).to.eql([
{value: 'restaurant', count: 1},
{value: '\n', count: 1, added: true, removed: undefined}
{value: 'restaurant', count: 1, added: false, removed: false},
{value: '\n', count: 1, added: true, removed: false}
]);
expect(diffLines('restaurant', 'restaurant\nhello', {newlineIsToken: true})).to.eql([
{value: 'restaurant', count: 1},
{value: '\nhello', count: 2, added: true, removed: undefined}
{value: 'restaurant', count: 1, added: false, removed: false},
{value: '\nhello', count: 2, added: true, removed: false}
]);
});

describe('Strip trailing CR', function() {
expect(diffLines('line\nline', 'line\r\nline', {stripTrailingCr: true})).to.eql([
{value: 'line\nline', count: 2}
{value: 'line\nline', count: 2, added: false, removed: false}
]);
});
});
22 changes: 11 additions & 11 deletions test/diff/word.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ describe('WordDiff', function() {
});

it('should include count with identity cases', function() {
expect(diffWords('foo', 'foo')).to.eql([{value: 'foo', count: 1}]);
expect(diffWords('foo bar', 'foo bar')).to.eql([{value: 'foo bar', count: 3}]);
expect(diffWords('foo', 'foo')).to.eql([{value: 'foo', count: 1, removed: false, added: false}]);
expect(diffWords('foo bar', 'foo bar')).to.eql([{value: 'foo bar', count: 3, removed: false, added: false}]);
});
it('should include count with empty cases', function() {
expect(diffWords('foo', '')).to.eql([{value: 'foo', count: 1, added: undefined, removed: true}]);
expect(diffWords('foo bar', '')).to.eql([{value: 'foo bar', count: 3, added: undefined, removed: true}]);
expect(diffWords('foo', '')).to.eql([{value: 'foo', count: 1, added: false, removed: true}]);
expect(diffWords('foo bar', '')).to.eql([{value: 'foo bar', count: 3, added: false, removed: true}]);

expect(diffWords('', 'foo')).to.eql([{value: 'foo', count: 1, added: true, removed: undefined}]);
expect(diffWords('', 'foo bar')).to.eql([{value: 'foo bar', count: 3, added: true, removed: undefined}]);
expect(diffWords('', 'foo')).to.eql([{value: 'foo', count: 1, added: true, removed: false}]);
expect(diffWords('', 'foo bar')).to.eql([{value: 'foo bar', count: 3, added: true, removed: false}]);
});

it('should ignore whitespace', function() {
expect(diffWords('hase igel fuchs', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs' }]);
expect(diffWords('hase igel fuchs', 'hase igel fuchs\n')).to.eql([{ count: 5, value: 'hase igel fuchs\n' }]);
expect(diffWords('hase igel fuchs\n', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs\n' }]);
expect(diffWords('hase igel fuchs', 'hase igel\nfuchs')).to.eql([{ count: 5, value: 'hase igel\nfuchs' }]);
expect(diffWords('hase igel\nfuchs', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs' }]);
expect(diffWords('hase igel fuchs', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs', removed: false, added: false }]);
expect(diffWords('hase igel fuchs', 'hase igel fuchs\n')).to.eql([{ count: 5, value: 'hase igel fuchs\n', removed: false, added: false }]);
expect(diffWords('hase igel fuchs\n', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs\n', removed: false, added: false }]);
expect(diffWords('hase igel fuchs', 'hase igel\nfuchs')).to.eql([{ count: 5, value: 'hase igel\nfuchs', removed: false, added: false }]);
expect(diffWords('hase igel\nfuchs', 'hase igel fuchs')).to.eql([{ count: 5, value: 'hase igel fuchs', removed: false, added: false }]);
});

it('should diff whitespace with flag', function() {
Expand Down