Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: pkg/observe/test/observe_test.dart

Issue 24076005: fix observing superclass fields, issue 13255 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/observe/lib/src/observable.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:logging/logging.dart'; 6 import 'package:logging/logging.dart';
7 import 'package:observe/observe.dart'; 7 import 'package:observe/observe.dart';
8 import 'package:observe/src/dirty_check.dart' as dirty_check; 8 import 'package:observe/src/dirty_check.dart' as dirty_check;
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'observe_test_utils.dart'; 10 import 'observe_test_utils.dart';
11 11
12 // Note: this ensures we run the dartanalyzer on the @observe package. 12 // Note: this ensures we run the dartanalyzer on the @observe package.
13 // @static-clean 13 // @static-clean
14 14
15 const _VALUE = const Symbol('value'); 15 const _VALUE = const Symbol('value');
16 16
17 void main() { 17 void main() {
18 // Note: to test the basic Observable system, we use ObservableBox due to its 18 // Note: to test the basic Observable system, we use ObservableBox due to its
19 // simplicity. We also test a variant that is based on dirty-checking. 19 // simplicity. We also test a variant that is based on dirty-checking.
20 20
21 observeTest('no observers at the start', () { 21 observeTest('no observers at the start', () {
22 expect(dirty_check.allObservablesCount, 0); 22 expect(dirty_check.allObservablesCount, 0);
23 }); 23 });
24 24
25 group('WatcherModel', () { _observeTests(watch: true); }); 25 group('WatcherModel', () => _observeTests((x) => new WatcherModel(x)));
26 26
27 group('ObservableBox', () { _observeTests(); }); 27 group('ObservableBox', () => _observeTests((x) => new ObservableBox(x)));
28
29 group('ModelSubclass', () => _observeTests((x) => new ModelSubclass(x)));
28 30
29 group('dirtyCheck loops can be debugged', () { 31 group('dirtyCheck loops can be debugged', () {
30 var messages; 32 var messages;
31 var subscription; 33 var subscription;
32 setUp(() { 34 setUp(() {
33 messages = []; 35 messages = [];
34 subscription = Logger.root.onRecord.listen((record) { 36 subscription = Logger.root.onRecord.listen((record) {
35 messages.add(record.message); 37 messages.add(record.message);
36 }); 38 });
37 }); 39 });
(...skipping 15 matching lines...) Expand all
53 55
54 expect(messages[0], contains('Possible loop')); 56 expect(messages[0], contains('Possible loop'));
55 expect(messages[1], contains('index 0')); 57 expect(messages[1], contains('index 0'));
56 expect(messages[1], contains('object: $x')); 58 expect(messages[1], contains('object: $x'));
57 59
58 sub.cancel(); 60 sub.cancel();
59 }); 61 });
60 }); 62 });
61 } 63 }
62 64
63 void _observeTests({bool watch: false}) { 65 void _observeTests(createModel(x)) {
64 final createModel = watch ? (x) => new WatcherModel(x) 66 final watch = createModel(null) is! ChangeNotifierMixin;
65 : (x) => new ObservableBox(x);
66 67
67 // Track the subscriptions so we can clean them up in tearDown. 68 // Track the subscriptions so we can clean them up in tearDown.
68 List subs; 69 List subs;
69 70
70 int initialObservers; 71 int initialObservers;
71 setUp(() { 72 setUp(() {
72 initialObservers = dirty_check.allObservablesCount; 73 initialObservers = dirty_check.allObservablesCount;
73 subs = []; 74 subs = [];
74 75
75 if (watch) runAsync(Observable.dirtyCheck); 76 if (watch) runAsync(Observable.dirtyCheck);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 _changedValue(len) => new List.filled(len, new PropertyChangeRecord(_VALUE)); 249 _changedValue(len) => new List.filled(len, new PropertyChangeRecord(_VALUE));
249 250
250 // A test model based on dirty checking. 251 // A test model based on dirty checking.
251 class WatcherModel<T> extends ObservableBase { 252 class WatcherModel<T> extends ObservableBase {
252 @observable T value; 253 @observable T value;
253 254
254 WatcherModel([T initialValue]) : value = initialValue; 255 WatcherModel([T initialValue]) : value = initialValue;
255 256
256 String toString() => '#<$runtimeType value: $value>'; 257 String toString() => '#<$runtimeType value: $value>';
257 } 258 }
259
260 class ModelSubclass<T> extends WatcherModel<T> {
261 ModelSubclass([T initialValue]) : super(initialValue);
262 }
OLDNEW
« no previous file with comments | « pkg/observe/lib/src/observable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698