@@ -89,12 +89,7 @@ describe("Jsondiff", function() {
89
89
]
90
90
}
91
91
] ;
92
- tests . forEach ( test => {
93
- it ( test . name , function ( ) {
94
- let output = jsondiff ( test . start , test . end ) ;
95
- expect ( output ) . to . deep . have . same . members ( test . expectedCommand ) ;
96
- } ) ;
97
- } ) ;
92
+ runTests ( tests ) ;
98
93
} ) ;
99
94
describe ( "List Replace (oi + od)" , function ( ) {
100
95
let tests = [
@@ -103,15 +98,9 @@ describe("Jsondiff", function() {
103
98
start : [ "one" , "two" ] ,
104
99
end : [ "one" , "three" , "two" ] ,
105
100
expectedCommand : [
106
- {
107
- p : [ 1 ] ,
108
- ld : "two" ,
109
- li : "three"
110
- } ,
111
- {
112
- p : [ 2 ] ,
113
- li : "two"
114
- }
101
+ { sd : 'wo' , p : [ 1 , 1 ] } ,
102
+ { si : 'hree' , p : [ 1 , 1 ] } ,
103
+ { p : [ 2 ] , li : 'two' }
115
104
]
116
105
} ,
117
106
{
@@ -147,12 +136,7 @@ describe("Jsondiff", function() {
147
136
]
148
137
}
149
138
] ;
150
- tests . forEach ( test => {
151
- it ( test . name , function ( ) {
152
- let output = jsondiff ( test . start , test . end ) ;
153
- expect ( output ) . to . deep . have . same . members ( test . expectedCommand ) ;
154
- } ) ;
155
- } ) ;
139
+ runTests ( tests ) ;
156
140
} ) ;
157
141
describe ( "Object Insert (oi)" , function ( ) {
158
142
let tests = [
@@ -190,12 +174,7 @@ describe("Jsondiff", function() {
190
174
]
191
175
}
192
176
] ;
193
- tests . forEach ( test => {
194
- it ( test . name , function ( ) {
195
- let output = jsondiff ( test . start , test . end ) ;
196
- expect ( output ) . to . deep . equal ( test . expectedCommand ) ;
197
- } ) ;
198
- } ) ;
177
+ runTests ( tests ) ;
199
178
} ) ;
200
179
describe ( "Object Replace (oi + od)" , function ( ) {
201
180
let tests = [
@@ -204,11 +183,8 @@ describe("Jsondiff", function() {
204
183
start : { one : "one" } ,
205
184
end : { one : "two" } ,
206
185
expectedCommand : [
207
- {
208
- p : [ "one" ] ,
209
- oi : "two" ,
210
- od : "one"
211
- }
186
+ { sd : 'one' , p : [ 'one' , 0 ] } ,
187
+ { si : 'two' , p : [ 'one' , 0 ] }
212
188
]
213
189
} ,
214
190
{
@@ -236,12 +212,7 @@ describe("Jsondiff", function() {
236
212
]
237
213
}
238
214
] ;
239
- tests . forEach ( test => {
240
- it ( test . name , function ( ) {
241
- let output = jsondiff ( test . start , test . end ) ;
242
- expect ( output ) . to . deep . equal ( test . expectedCommand ) ;
243
- } ) ;
244
- } ) ;
215
+ runTests ( tests ) ;
245
216
} ) ;
246
217
describe ( "String Mutation (si + sd)" , function ( ) {
247
218
// These test cases come from diff-match-patch tests.
@@ -298,6 +269,15 @@ describe("Jsondiff", function() {
298
269
{ si : 'xyz' , p : [ 'one' , 0 ] }
299
270
]
300
271
} ,
272
+ {
273
+ name : "Strings suffix/prefix overlap, overlap case" ,
274
+ start : { one : "123456xxx" } ,
275
+ end : { one : "xxxabcd" } ,
276
+ expectedCommand : [
277
+ { "p" : [ "one" , 0 ] , "sd" : "123456xxx" } ,
278
+ { "p" : [ "one" , 0 ] , "si" : "xxxabcd" }
279
+ ]
280
+ } ,
301
281
{
302
282
name : "Example from README" ,
303
283
start : [ "foo" , "The only change here is at the end." , 1 , 2 , 3 ] ,
@@ -308,39 +288,49 @@ describe("Jsondiff", function() {
308
288
]
309
289
}
310
290
] ;
311
- tests . forEach ( test => {
312
- it ( test . name , function ( ) {
291
+ runTests ( tests ) ;
292
+ } ) ;
293
+ } ) ;
294
+ } ) ;
295
+
296
+ function runTests ( tests ) {
297
+ tests . forEach ( test => {
298
+ it ( test . name , function ( ) {
299
+
300
+ //////////////////
301
+ // Verify JSON0 //
302
+ //////////////////
303
+ let json0Op = jsondiff ( test . start , test . end , diffMatchPatch ) ;
304
+ expect ( json0Op ) . to . deep . equal ( test . expectedCommand ) ;
313
305
314
- //////////////////
315
- // Verify JSON0 //
316
- //////////////////
317
- let json0Op = jsondiff ( test . start , test . end , diffMatchPatch ) ;
318
- expect ( json0Op ) . to . deep . equal ( test . expectedCommand ) ;
306
+ // Test actual application of the expected ops.
307
+ // Clone the input, because json0 mutates the input to `apply`.
308
+ let json0Start = clone ( test . start ) ;
309
+ let json0End = json0 . type . apply ( json0Start , json0Op ) ;
310
+ expect ( json0End ) . to . deep . equal ( test . end ) ;
319
311
320
- // Test actual application of the expected ops .
321
- // Clone the input, because json0 mutates the input to `apply`.
322
- let json0Start = clone ( test . start ) ;
323
- let json0End = json0 . type . apply ( json0Start , json0Op ) ;
324
- expect ( json0End ) . to . deep . equal ( test . end ) ;
312
+ // Test application of ops generated _without_ diffMatchPatch .
313
+ let json0SimpleOp = jsondiff ( test . start , test . end ) ;
314
+ let json0SimpleStart = clone ( test . start ) ;
315
+ let json0SimpleEnd = json0 . type . apply ( json0SimpleStart , json0SimpleOp ) ;
316
+ expect ( json0SimpleEnd ) . to . deep . equal ( test . end ) ;
325
317
326
318
327
- //////////////////
328
- // Verify JSON1 //
329
- //////////////////
330
- let json1Op = jsondiff (
331
- test . start ,
332
- test . end ,
333
- diffMatchPatch ,
334
- json1 ,
335
- textUnicode
336
- ) ;
319
+ //////////////////
320
+ // Verify JSON1 //
321
+ //////////////////
322
+ let json1Op = jsondiff (
323
+ test . start ,
324
+ test . end ,
325
+ diffMatchPatch ,
326
+ json1 ,
327
+ textUnicode
328
+ ) ;
337
329
338
- // Test actual application of the expected ops.
339
- // No need to clone the input, json1 does _not_ mutate the input to `apply`.
340
- let json1End = json1 . type . apply ( test . start , json1Op ) ;
341
- expect ( json1End ) . to . deep . equal ( test . end ) ;
342
- } ) ;
343
- } ) ;
330
+ // Test actual application of the expected ops.
331
+ // No need to clone the input, json1 does _not_ mutate the input to `apply`.
332
+ let json1End = json1 . type . apply ( test . start , json1Op ) ;
333
+ expect ( json1End ) . to . deep . equal ( test . end ) ;
344
334
} ) ;
345
335
} ) ;
346
- } ) ;
336
+ }
0 commit comments