@@ -288,6 +288,31 @@ void testWithGetterFactory(FieldGetterFactory getterFactory) {
288
288
moves: ['2[1 -> 0]' , '1[0 -> 1]' ],
289
289
removals: []));
290
290
});
291
+
292
+ it ('should handle swapping elements correctly - gh1097' , () {
293
+ // This test would only have failed in non-checked mode only
294
+ var list = ['a' , 'b' , 'c' ];
295
+ var record = detector.watch (list, null , null );
296
+ var iterator = detector.collectChanges ()..moveNext ();
297
+
298
+ list..clear ()..addAll (['b' , 'a' , 'c' ]);
299
+ iterator = detector.collectChanges ()..moveNext ();
300
+ expect (iterator.current.currentValue, toEqualCollectionRecord (
301
+ collection: ['b[1 -> 0]' , 'a[0 -> 1]' , 'c' ],
302
+ previous: ['a[0 -> 1]' , 'b[1 -> 0]' , 'c' ],
303
+ additions: [],
304
+ moves: ['b[1 -> 0]' , 'a[0 -> 1]' , 'c' ],
305
+ removals: []));
306
+
307
+ list..clear ()..addAll (['b' , 'c' , 'a' ]);
308
+ iterator = detector.collectChanges ()..moveNext ();
309
+ expect (iterator.current.currentValue, toEqualCollectionRecord (
310
+ collection: ['b' , 'c[2 -> 1]' , 'a[1 -> 2]' ],
311
+ previous: ['b' , 'a[1 -> 2]' , 'c[2 -> 1]' ],
312
+ additions: [],
313
+ moves: ['c[2 -> 1]' , 'a[1 -> 2]' ],
314
+ removals: []));
315
+ });
291
316
});
292
317
293
318
it ('should detect changes in list' , () {
0 commit comments