OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** Tests for some of the utility helper functions used by the compiler. */ | 5 /** Tests for some of the utility helper functions used by the compiler. */ |
6 library observe_test; | 6 library observe_test; |
7 | 7 |
| 8 import 'dart:async'; |
8 import 'dart:collection' show LinkedHashMap; | 9 import 'dart:collection' show LinkedHashMap; |
9 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
10 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
11 import 'package:web_ui/observe.dart'; | 12 import 'package:web_ui/observe.dart'; |
12 import 'package:web_ui/observe/observable.dart' show hasObservers, observeReads; | 13 import 'package:web_ui/observe/observable.dart' show hasObservers, observeReads; |
13 import 'package:web_ui/src/utils_observe.dart' show setImmediate; | |
14 | 14 |
15 main() { | 15 main() { |
16 useCompactVMConfiguration(); | 16 useCompactVMConfiguration(); |
17 | 17 |
18 group('ObservableReference', () { | 18 group('ObservableReference', () { |
19 test('no observers', () { | 19 test('no observers', () { |
20 var t = new ObservableReference<int>(123); | 20 var t = new ObservableReference<int>(123); |
21 expect(t.value, 123); | 21 expect(t.value, 123); |
22 t.value = 42; | 22 t.value = 42; |
23 expect(t.value, 42); | 23 expect(t.value, 42); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 test('unobserve one of two observers', () { | 126 test('unobserve one of two observers', () { |
127 var t = new ObservableReference<int>(123); | 127 var t = new ObservableReference<int>(123); |
128 ChangeUnobserver unobserve; | 128 ChangeUnobserver unobserve; |
129 unobserve = observe(() => t.value, expectAsync1((n) { | 129 unobserve = observe(() => t.value, expectAsync1((n) { |
130 expect(n.oldValue, 123); | 130 expect(n.oldValue, 123); |
131 expect(n.newValue, 42); | 131 expect(n.newValue, 42); |
132 | 132 |
133 // This will not affect the other observer, so it still gets the event. | 133 // This will not affect the other observer, so it still gets the event. |
134 unobserve(); | 134 unobserve(); |
135 setImmediate(() => t.value = 777); | 135 runAsync(() => t.value = 777); |
136 })); | 136 })); |
137 int count = 0; | 137 int count = 0; |
138 observe(() => t.value + 1000, expectAsync1((n) { | 138 observe(() => t.value + 1000, expectAsync1((n) { |
139 if (++count == 1) { | 139 if (++count == 1) { |
140 expect(n.oldValue, 1123); | 140 expect(n.oldValue, 1123); |
141 expect(n.newValue, 1042); | 141 expect(n.newValue, 1042); |
142 } else { | 142 } else { |
143 expect(n.oldValue, 1042); | 143 expect(n.oldValue, 1042); |
144 expect(n.newValue, 1777); | 144 expect(n.newValue, 1777); |
145 } | 145 } |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 var c = _change(123, 43); | 870 var c = _change(123, 43); |
871 expect(a.hashCode, b.hashCode, reason: 'a == b'); | 871 expect(a.hashCode, b.hashCode, reason: 'a == b'); |
872 expect(b.hashCode, isNot(equals(c.hashCode)), reason: 'b != c'); | 872 expect(b.hashCode, isNot(equals(c.hashCode)), reason: 'b != c'); |
873 }); | 873 }); |
874 } | 874 } |
875 | 875 |
876 _change(oldValue, newValue) => new ChangeNotification(oldValue, newValue); | 876 _change(oldValue, newValue) => new ChangeNotification(oldValue, newValue); |
877 | 877 |
878 _record(type, key, oldValue, newValue) => | 878 _record(type, key, oldValue, newValue) => |
879 new ChangeRecord(type, key, oldValue, newValue); | 879 new ChangeRecord(type, key, oldValue, newValue); |
OLD | NEW |