import { diff } from "./diff" ; it ( "produces no patch for unchanged primitive type" , ( ) => { expect ( diff ( { left : 1 , right : 1 , } ) ) . toStrictEqual ( undefined ) ; } ) ; it ( "produces patch for changed primitive type" , ( ) => { expect ( diff ( { left : 1 , right : 2 , } ) ) . toStrictEqual ( [ null , 2 ] ) ; } ) ; it ( "produces patch for changed primitive type (include previous value)" , ( ) => { expect ( diff ( { left : 1 , right : 2 , } , { includePreviousValue : true , } ) ) . toStrictEqual ( [ 1 , 2 ] ) ; } ) ; it ( "produces patch for removed primitive type" , ( ) => { expect ( diff ( { left : 1 , right : undefined , } ) ) . toStrictEqual ( [ null , 0 , 0 ] ) ; } ) ; it ( "produces patch for removed primitive type (exclude previous value)" , ( ) => { expect ( diff ( { left : 1 , right : undefined , } , { includePreviousValue : true , } ) ) . toStrictEqual ( [ 1 , 0 , 0 ] ) ; } ) ; it ( "produces patch for added primitive type" , ( ) => { expect ( diff ( { left : undefined , right : 1 , } ) ) . toStrictEqual ( [ 1 ] ) ; } ) ; it ( "produces no patch for identical nested types" , ( ) => { expect ( diff ( { left : { a : 1 } , right : { a : 1 } , } ) ) . toStrictEqual ( undefined ) ; } ) ; it ( "produces patch for changed nested types" , ( ) => { expect ( diff ( { left : { a : 1 } , right : { a : 2 } , } ) ) . toStrictEqual ( { a : [ null , 2 ] } ) ; } ) ; it ( "produces patch for changed nested types (include previous value)" , ( ) => { expect ( diff ( { left : { a : 1 } , right : { a : 2 } , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { a : [ 1 , 2 ] } ) ; } ) ; it ( "produces patch for removed nested property" , ( ) => { expect ( diff ( { left : { a : 2 } , right : { } , } ) ) . toStrictEqual ( { a : [ null , 0 , 0 ] } ) ; } ) ; it ( "produces patch for removed nested property (include previous value)" , ( ) => { expect ( diff ( { left : { a : 2 } , right : { } , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { a : [ 2 , 0 , 0 ] } ) ; } ) ; it ( "produces patch for added nested property" , ( ) => { expect ( diff ( { left : { } , right : { a : 2 } , } ) ) . toStrictEqual ( { a : [ 2 ] } ) ; } ) ; it ( "produces patch for changed deeply nested types" , ( ) => { expect ( diff ( { left : { a : { a : 1 } } , right : { a : { a : 2 } } , } ) ) . toStrictEqual ( { a : { a : [ null , 2 ] } } ) ; } ) ; it ( "produces patch for changed deeply nested types (include previous value)" , ( ) => { expect ( diff ( { left : { a : { a : 1 } } , right : { a : { a : 2 } } , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { a : { a : [ 1 , 2 ] } } ) ; } ) ; it ( "produces patch for removed deeply nested property" , ( ) => { expect ( diff ( { left : { a : { a : 2 } } , right : { } , } ) ) . toStrictEqual ( { a : [ null , 0 , 0 ] } ) ; } ) ; it ( "produces patch for removed deeply nested property (include previous value)" , ( ) => { expect ( diff ( { left : { a : { a : 2 } } , right : { } , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { a : [ { a : 2 } , 0 , 0 ] } ) ; } ) ; it ( "produces patch for added deeply nested property" , ( ) => { expect ( diff ( { left : { } , right : { a : { a : 2 } } , } ) ) . toStrictEqual ( { a : [ { a : 2 } ] } ) ; } ) ; it ( "produces no patch for unmoved array items" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 1 , 2 ] , } ) ) . toStrictEqual ( undefined ) ; } ) ; it ( "produces a patch for deleted array items (first member)" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 2 ] , } ) ) . toStrictEqual ( { _t : "a" , _0 : [ null , 0 , 0 , ] , } ) ; } ) ; it ( "produces a patch for deleted array items (first member and include previous value)" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 2 ] , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { _t : "a" , _0 : [ 1 , 0 , 0 , ] , } ) ; } ) ; it ( "produces a patch for deleted array items (last member)" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 1 ] , } ) ) . toStrictEqual ( { _t : "a" , _1 : [ null , 0 , 0 , ] , } ) ; } ) ; it ( "produces a patch for deleted array items (last member and exclude previous value)" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 1 ] , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { _t : "a" , _1 : [ 2 , 0 , 0 , ] , } ) ; } ) ; it ( "produces a patch for replaced array items" , ( ) => { expect ( diff ( { left : [ 1 , 2 ] , right : [ 2 , 2 ] , } ) ) . toStrictEqual ( { _t : "a" , "0" : [ 2 ] , _0 : [ null , 0 , 0 , ] , } ) ; } ) ; it ( "produces an inefficient patch for replaced array items without objectHash" , ( ) => { expect ( diff ( { left : [ { a : 1 } , { a : 2 } ] , right : [ { a : 2 } , { a : 1 } ] , } ) ) . toStrictEqual ( { "0" : { a : [ null , 2 ] , } , "1" : { a : [ null , 1 ] , } , _t : "a" , } ) ; } ) ; it ( "produces an inefficient patch for replaced array items without objectHash (exclude previous value)" , ( ) => { expect ( diff ( { left : [ { a : 1 } , { a : 2 } ] , right : [ { a : 2 } , { a : 1 } ] , } , { includePreviousValue : true , } ) ) . toStrictEqual ( { "0" : { a : [ 1 , 2 ] , } , "1" : { a : [ 2 , 1 ] , } , _t : "a" , } ) ; } ) ; it ( "produces a more efficient patch for replaced array items with objectHash" , ( ) => { expect ( diff ( { left : [ { id : 1 } , { id : 2 } ] , right : [ { id : 2 } , { id : 1 } ] , } , { objectHash : ( item ) => item [ "id" ] , } ) ) . toStrictEqual ( { _1 : [ null , 0 , 3 , ] , _t : "a" , } ) ; } ) ; it ( "produces a more efficient patch for replaced array items with objectHash (exclude previous value)" , ( ) => { expect ( diff ( { left : [ { id : 1 } , { id : 2 } ] , right : [ { id : 2 } , { id : 1 } ] , } , { objectHash : ( item ) => item [ "id" ] , includePreviousValue : true , } ) ) . toStrictEqual ( { _1 : [ { id : 2 } , 0 , 3 , ] , _t : "a" , } ) ; } ) ; test ( "replace with null" , ( ) => { expect ( diff ( { left : { map : { id : "2" } , } , right : { map : null , } , } ) ) . toStrictEqual ( { map : [ null , null ] , } ) ; } ) ;