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

Side by Side Diff: tests/lib/async/stream_controller_test.dart

Issue 11740027: Rename unsubscribe to cancel. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Address comments. Created 7 years, 11 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 | « tests/lib/async/stream_controller_async_test.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. 5 // Test the basic StreamController and StreamController.singleSubscription.
6 import 'dart:async'; 6 import 'dart:async';
7 import 'event_helper.dart'; 7 import 'event_helper.dart';
8 8
9 testController() { 9 testController() {
10 // Test normal flow. 10 // Test normal flow.
(...skipping 15 matching lines...) Expand all
26 Events sentEvents = 26 Events sentEvents =
27 new Events()..add(42)..error("error")..add("Are you there?"); 27 new Events()..add(42)..error("error")..add("Are you there?");
28 sentEvents.replay(c); 28 sentEvents.replay(c);
29 Expect.listEquals(expectedEvents.events, actualEvents.events); 29 Expect.listEquals(expectedEvents.events, actualEvents.events);
30 30
31 // Test manual unsubscription. 31 // Test manual unsubscription.
32 c = new StreamController(); 32 c = new StreamController();
33 expectedEvents = new Events()..add(42)..error("error")..add(37); 33 expectedEvents = new Events()..add(42)..error("error")..add(37);
34 actualEvents = new Events.capture(c, unsubscribeOnError: false); 34 actualEvents = new Events.capture(c, unsubscribeOnError: false);
35 expectedEvents.replay(c); 35 expectedEvents.replay(c);
36 actualEvents.subscription.unsubscribe(); 36 actualEvents.subscription.cancel();
37 c.add("Are you there"); // Not sent to actualEvents. 37 c.add("Are you there"); // Not sent to actualEvents.
38 Expect.listEquals(expectedEvents.events, actualEvents.events); 38 Expect.listEquals(expectedEvents.events, actualEvents.events);
39 39
40 // Test filter. 40 // Test filter.
41 c = new StreamController(); 41 c = new StreamController();
42 expectedEvents = new Events() 42 expectedEvents = new Events()
43 ..add("a string")..add("another string")..close(); 43 ..add("a string")..add("another string")..close();
44 sentEvents = new Events() 44 sentEvents = new Events()
45 ..add("a string")..add(42)..add("another string")..close(); 45 ..add("a string")..add(42)..add("another string")..close();
46 actualEvents = new Events.capture(c.where((v) => v is String)); 46 actualEvents = new Events.capture(c.where((v) => v is String));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 Expect.listEquals(expectedEvents.events, actualEvents.events); 121 Expect.listEquals(expectedEvents.events, actualEvents.events);
122 122
123 // Test subscription changes while firing. 123 // Test subscription changes while firing.
124 c = new StreamController(); 124 c = new StreamController();
125 var sink = c.sink; 125 var sink = c.sink;
126 var stream = c.stream; 126 var stream = c.stream;
127 var counter = 0; 127 var counter = 0;
128 var subscription = stream.listen(null); 128 var subscription = stream.listen(null);
129 subscription.onData((data) { 129 subscription.onData((data) {
130 counter += data; 130 counter += data;
131 subscription.unsubscribe(); 131 subscription.cancel();
132 stream.listen((data) { 132 stream.listen((data) {
133 counter += 10 * data; 133 counter += 10 * data;
134 }); 134 });
135 var subscription2 = stream.listen(null); 135 var subscription2 = stream.listen(null);
136 subscription2.onData((data) { 136 subscription2.onData((data) {
137 counter += 100 * data; 137 counter += 100 * data;
138 if (data == 4) subscription2.unsubscribe(); 138 if (data == 4) subscription2.cancel();
139 }); 139 });
140 }); 140 });
141 sink.add(1); // seen by stream 1 141 sink.add(1); // seen by stream 1
142 sink.add(2); // seen by stream 10 and 100 142 sink.add(2); // seen by stream 10 and 100
143 sink.add(3); // -"- 143 sink.add(3); // -"-
144 sink.add(4); // -"- 144 sink.add(4); // -"-
145 sink.add(5); // seen by stream 10 145 sink.add(5); // seen by stream 10
146 Expect.equals(1 + 20 + 200 + 30 + 300 + 40 + 400 + 50, counter); 146 Expect.equals(1 + 20 + 200 + 30 + 300 + 40 + 400 + 50, counter);
147 } 147 }
148 148
(...skipping 17 matching lines...) Expand all
166 Events sentEvents = 166 Events sentEvents =
167 new Events()..add(42)..error("error")..add("Are you there?"); 167 new Events()..add(42)..error("error")..add("Are you there?");
168 sentEvents.replay(c); 168 sentEvents.replay(c);
169 Expect.listEquals(expectedEvents.events, actualEvents.events); 169 Expect.listEquals(expectedEvents.events, actualEvents.events);
170 170
171 // Test manual unsubscription. 171 // Test manual unsubscription.
172 c = new StreamController.singleSubscription(); 172 c = new StreamController.singleSubscription();
173 expectedEvents = new Events()..add(42)..error("error")..add(37); 173 expectedEvents = new Events()..add(42)..error("error")..add(37);
174 actualEvents = new Events.capture(c, unsubscribeOnError: false); 174 actualEvents = new Events.capture(c, unsubscribeOnError: false);
175 expectedEvents.replay(c); 175 expectedEvents.replay(c);
176 actualEvents.subscription.unsubscribe(); 176 actualEvents.subscription.cancel();
177 c.add("Are you there"); // Not sent to actualEvents. 177 c.add("Are you there"); // Not sent to actualEvents.
178 Expect.listEquals(expectedEvents.events, actualEvents.events); 178 Expect.listEquals(expectedEvents.events, actualEvents.events);
179 179
180 // Test filter. 180 // Test filter.
181 c = new StreamController.singleSubscription(); 181 c = new StreamController.singleSubscription();
182 expectedEvents = new Events() 182 expectedEvents = new Events()
183 ..add("a string")..add("another string")..close(); 183 ..add("a string")..add("another string")..close();
184 sentEvents = new Events() 184 sentEvents = new Events()
185 ..add("a string")..add(42)..add("another string")..close(); 185 ..add("a string")..add(42)..add("another string")..close();
186 actualEvents = new Events.capture(c.where((v) => v is String)); 186 actualEvents = new Events.capture(c.where((v) => v is String));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 actualEvents = new Events.capture(c.distinct((a, b) => a < b)); 350 actualEvents = new Events.capture(c.distinct((a, b) => a < b));
351 sentEvents.replay(c); 351 sentEvents.replay(c);
352 Expect.listEquals(expectedEvents.events, actualEvents.events); 352 Expect.listEquals(expectedEvents.events, actualEvents.events);
353 } 353 }
354 354
355 main() { 355 main() {
356 testController(); 356 testController();
357 testSingleController(); 357 testSingleController();
358 testExtraMethods(); 358 testExtraMethods();
359 } 359 }
OLDNEW
« no previous file with comments | « tests/lib/async/stream_controller_async_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698