| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:observe/observe.dart'; | 6 import 'package:observe/observe.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'observe_test_utils.dart'; | 8 import 'observe_test_utils.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 // TODO(jmesserly): need all standard List API tests. | 11 // TODO(jmesserly): need all standard List API tests. |
| 12 | 12 |
| 13 const _LENGTH = const Symbol('length'); | |
| 14 | |
| 15 StreamSubscription sub; | 13 StreamSubscription sub; |
| 16 | 14 |
| 17 sharedTearDown() { sub.cancel(); } | 15 sharedTearDown() { sub.cancel(); } |
| 18 | 16 |
| 19 group('observe length', () { | 17 group('observe length', () { |
| 20 | 18 |
| 21 ObservableList list; | 19 ObservableList list; |
| 22 List<ChangeRecord> changes; | 20 List<ChangeRecord> changes; |
| 23 | 21 |
| 24 setUp(() { | 22 setUp(() { |
| 25 list = toObservable([1, 2, 3]); | 23 list = toObservable([1, 2, 3]); |
| 26 changes = null; | 24 changes = null; |
| 27 sub = list.changes.listen((records) { | 25 sub = list.changes.listen((records) { |
| 28 changes = records.where((r) => r.changes(_LENGTH)).toList(); | 26 changes = records.where((r) => r.changes(#length)).toList(); |
| 29 }); | 27 }); |
| 30 }); | 28 }); |
| 31 | 29 |
| 32 tearDown(sharedTearDown); | 30 tearDown(sharedTearDown); |
| 33 | 31 |
| 34 observeTest('add changes length', () { | 32 observeTest('add changes length', () { |
| 35 list.add(4); | 33 list.add(4); |
| 36 expect(list, [1, 2, 3, 4]); | 34 expect(list, [1, 2, 3, 4]); |
| 37 performMicrotaskCheckpoint(); | 35 performMicrotaskCheckpoint(); |
| 38 expectChanges(changes, [_lengthChange]); | 36 expectChanges(changes, [_lengthChange]); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 247 |
| 250 performMicrotaskCheckpoint(); | 248 performMicrotaskCheckpoint(); |
| 251 expectChanges(records, [ | 249 expectChanges(records, [ |
| 252 _lengthChange, | 250 _lengthChange, |
| 253 _change(0, removedCount: 6) | 251 _change(0, removedCount: 6) |
| 254 ]); | 252 ]); |
| 255 }); | 253 }); |
| 256 }); | 254 }); |
| 257 } | 255 } |
| 258 | 256 |
| 259 const _LENGTH = const Symbol('length'); | 257 final _lengthChange = new PropertyChangeRecord(#length); |
| 260 | |
| 261 final _lengthChange = new PropertyChangeRecord(_LENGTH); | |
| 262 | 258 |
| 263 _change(index, {removedCount: 0, addedCount: 0}) => new ListChangeRecord( | 259 _change(index, {removedCount: 0, addedCount: 0}) => new ListChangeRecord( |
| 264 index, removedCount: removedCount, addedCount: addedCount); | 260 index, removedCount: removedCount, addedCount: addedCount); |
| OLD | NEW |