Skip to content

Commit 1023590

Browse files
pedrottimarkkpdecker
authored andcommitted
Omit redundant slice in join method of diffArrays
1 parent c72ef4a commit 1023590

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/diff/array.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Diff from './base';
22

33
export const arrayDiff = new Diff();
4-
arrayDiff.tokenize = arrayDiff.join = function(value) {
4+
arrayDiff.tokenize = function(value) {
55
return value.slice();
66
};
7-
arrayDiff.removeEmpty = function(value) {
7+
arrayDiff.join = arrayDiff.removeEmpty = function(value) {
88
return value;
99
};
1010

test/diff/array.js

+28
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,35 @@ describe('diff/array', function() {
3333
{count: 1, value: [c], removed: true, added: undefined}
3434
]);
3535
});
36+
describe('anti-aliasing', function() {
37+
// Test apparent contract that no chunk value is ever an input argument.
38+
const value = [0, 1, 2];
39+
const expected = [
40+
{count: value.length, value: value}
41+
];
3642

43+
const input = value.slice();
44+
const diffResult = diffArrays(input, input);
45+
it('returns correct deep result for identical inputs', function() {
46+
expect(diffResult).to.deep.equals(expected);
47+
});
48+
it('does not return the input array', function() {
49+
expect(diffResult[0].value).to.not.equal(input);
50+
});
51+
52+
const input1 = value.slice();
53+
const input2 = value.slice();
54+
const diffResult2 = diffArrays(input1, input2);
55+
it('returns correct deep result for equivalent inputs', function() {
56+
expect(diffResult2).to.deep.equals(expected);
57+
});
58+
it('does not return the first input array', function() {
59+
expect(diffResult2[0].value).to.not.equal(input1);
60+
});
61+
it('does not return the second input array', function() {
62+
expect(diffResult2[0].value).to.not.equal(input2);
63+
});
64+
});
3765
it('Should diff arrays with comparator', function() {
3866
const a = {a: 0}, b = {a: 1}, c = {a: 2}, d = {a: 3};
3967
function comparator(left, right) {

0 commit comments

Comments
 (0)