@@ -33,7 +33,35 @@ describe('diff/array', function() {
33
33
{ count : 1 , value : [ c ] , removed : true , added : undefined }
34
34
] ) ;
35
35
} ) ;
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
+ ] ;
36
42
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
+ } ) ;
37
65
it ( 'Should diff arrays with comparator' , function ( ) {
38
66
const a = { a : 0 } , b = { a : 1 } , c = { a : 2 } , d = { a : 3 } ;
39
67
function comparator ( left , right ) {
0 commit comments