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

Side by Side Diff: sdk/lib/_internal/pub/test/error_group_test.dart

Issue 16125005: Make new StreamController be async by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 7 years, 6 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 | « sdk/lib/_internal/pub/lib/src/utils.dart ('k') | sdk/lib/async/stream.dart » ('j') | 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 library error_group_test; 5 library error_group_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 20 matching lines...) Expand all
31 errorGroup.signalError(new FormatException()); 31 errorGroup.signalError(new FormatException());
32 }); 32 });
33 33
34 test("shouldn't allow additional futures or streams once an error has been " 34 test("shouldn't allow additional futures or streams once an error has been "
35 "signaled", () { 35 "signaled", () {
36 expect(errorGroup.done, throwsFormatException); 36 expect(errorGroup.done, throwsFormatException);
37 errorGroup.signalError(new FormatException()); 37 errorGroup.signalError(new FormatException());
38 38
39 expect(() => errorGroup.registerFuture(new Future.value()), 39 expect(() => errorGroup.registerFuture(new Future.value()),
40 throwsStateError); 40 throwsStateError);
41 expect(() => errorGroup.registerStream(new StreamController().stream), 41 expect(() => errorGroup.registerStream(
42 new StreamController(sync: true).stream),
42 throwsStateError); 43 throwsStateError);
43 }); 44 });
44 }); 45 });
45 46
46 group('with a single future', () { 47 group('with a single future', () {
47 Completer completer; 48 Completer completer;
48 Future future; 49 Future future;
49 50
50 setUp(() { 51 setUp(() {
51 errorGroup = new ErrorGroup(); 52 errorGroup = new ErrorGroup();
52 completer = new Completer(); 53 completer = new Completer();
53 future = errorGroup.registerFuture(completer.future); 54 future = errorGroup.registerFuture(completer.future);
54 }); 55 });
55 56
56 test('should pass through a value from the future', () { 57 test('should pass through a value from the future', () {
57 expect(future, completion(equals('value'))); 58 expect(future, completion(equals('value')));
58 expect(errorGroup.done, completes); 59 expect(errorGroup.done, completes);
59 completer.complete('value'); 60 completer.complete('value');
60 }); 61 });
61 62
62 test("shouldn't allow additional futures or streams once .done has " 63 test("shouldn't allow additional futures or streams once .done has "
63 "been called", () { 64 "been called", () {
64 completer.complete('value'); 65 completer.complete('value');
65 66
66 completer.future.then(expectAsync1((_) { 67 completer.future.then(expectAsync1((_) {
67 expect(() => errorGroup.registerFuture(new Future.value()), 68 expect(() => errorGroup.registerFuture(new Future.value()),
68 throwsStateError); 69 throwsStateError);
69 expect(() => errorGroup.registerStream(new StreamController().stream), 70 expect(() => errorGroup.registerStream(
71 new StreamController(sync: true).stream),
70 throwsStateError); 72 throwsStateError);
71 })); 73 }));
72 }); 74 });
73 75
74 test('should pass through an exception from the future if it has a ' 76 test('should pass through an exception from the future if it has a '
75 'listener', () { 77 'listener', () {
76 expect(future, throwsFormatException); 78 expect(future, throwsFormatException);
77 // errorGroup shouldn't top-level the exception 79 // errorGroup shouldn't top-level the exception
78 completer.completeError(new FormatException()); 80 completer.completeError(new FormatException());
79 }); 81 });
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }), completes); 200 }), completes);
199 }); 201 });
200 }); 202 });
201 203
202 group('with a single stream', () { 204 group('with a single stream', () {
203 StreamController controller; 205 StreamController controller;
204 Stream stream; 206 Stream stream;
205 207
206 setUp(() { 208 setUp(() {
207 errorGroup = new ErrorGroup(); 209 errorGroup = new ErrorGroup();
208 controller = new StreamController(); 210 controller = new StreamController(sync: true);
209 stream = errorGroup.registerStream(controller.stream.asBroadcastStream()); 211 stream = errorGroup.registerStream(controller.stream.asBroadcastStream());
210 }); 212 });
211 213
212 test('should pass through values from the stream', () { 214 test('should pass through values from the stream', () {
213 StreamIterator iter = new StreamIterator(stream); 215 StreamIterator iter = new StreamIterator(stream);
214 iter.moveNext().then((hasNext) { 216 iter.moveNext().then((hasNext) {
215 expect(hasNext, isTrue); 217 expect(hasNext, isTrue);
216 expect(iter.current, equals(1)); 218 expect(iter.current, equals(1));
217 iter.moveNext().then((hasNext) { 219 iter.moveNext().then((hasNext) {
218 expect(hasNext, isTrue); 220 expect(hasNext, isTrue);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 }); 272 });
271 273
272 }); 274 });
273 275
274 group('with a single single-subscription stream', () { 276 group('with a single single-subscription stream', () {
275 StreamController controller; 277 StreamController controller;
276 Stream stream; 278 Stream stream;
277 279
278 setUp(() { 280 setUp(() {
279 errorGroup = new ErrorGroup(); 281 errorGroup = new ErrorGroup();
280 controller = new StreamController(); 282 controller = new StreamController(sync: true);
281 stream = errorGroup.registerStream(controller.stream); 283 stream = errorGroup.registerStream(controller.stream);
282 }); 284 });
283 285
284 test("should complete .done when the stream is done even if the stream " 286 test("should complete .done when the stream is done even if the stream "
285 "doesn't have a listener", () { 287 "doesn't have a listener", () {
286 expect(errorGroup.done, completes); 288 expect(errorGroup.done, completes);
287 controller.add('value'); 289 controller.add('value');
288 controller.close(); 290 controller.close();
289 291
290 // A listener added afterwards should receive the value 292 // A listener added afterwards should receive the value
(...skipping 28 matching lines...) Expand all
319 }); 321 });
320 322
321 group('with multiple streams', () { 323 group('with multiple streams', () {
322 StreamController controller1; 324 StreamController controller1;
323 StreamController controller2; 325 StreamController controller2;
324 Stream stream1; 326 Stream stream1;
325 Stream stream2; 327 Stream stream2;
326 328
327 setUp(() { 329 setUp(() {
328 errorGroup = new ErrorGroup(); 330 errorGroup = new ErrorGroup();
329 controller1 = new StreamController(); 331 controller1 = new StreamController(sync: true);
330 controller2 = new StreamController(); 332 controller2 = new StreamController(sync: true);
331 stream1 = errorGroup.registerStream(controller1.stream.asBroadcastStream() ); 333 stream1 = errorGroup.registerStream(controller1.stream.asBroadcastStream() );
332 stream2 = errorGroup.registerStream(controller2.stream.asBroadcastStream() ); 334 stream2 = errorGroup.registerStream(controller2.stream.asBroadcastStream() );
333 }); 335 });
334 336
335 test("should pipe exceptions from one stream to the other and to .done", 337 test("should pipe exceptions from one stream to the other and to .done",
336 () { 338 () {
337 expect(stream1.first, throwsFormatException); 339 expect(stream1.first, throwsFormatException);
338 expect(stream2.first, throwsFormatException); 340 expect(stream2.first, throwsFormatException);
339 expect(errorGroup.done, throwsFormatException); 341 expect(errorGroup.done, throwsFormatException);
340 342
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 }); 380 });
379 381
380 group('with a stream and a future', () { 382 group('with a stream and a future', () {
381 StreamController controller; 383 StreamController controller;
382 Stream stream; 384 Stream stream;
383 Completer completer; 385 Completer completer;
384 Future future; 386 Future future;
385 387
386 setUp(() { 388 setUp(() {
387 errorGroup = new ErrorGroup(); 389 errorGroup = new ErrorGroup();
388 controller = new StreamController(); 390 controller = new StreamController(sync: true);
389 stream = errorGroup.registerStream(controller.stream.asBroadcastStream()); 391 stream = errorGroup.registerStream(controller.stream.asBroadcastStream());
390 completer = new Completer(); 392 completer = new Completer();
391 future = errorGroup.registerFuture(completer.future); 393 future = errorGroup.registerFuture(completer.future);
392 }); 394 });
393 395
394 test("should pipe exceptions from the stream to the future", () { 396 test("should pipe exceptions from the stream to the future", () {
395 expect(stream.first, throwsFormatException); 397 expect(stream.first, throwsFormatException);
396 expect(future, throwsFormatException); 398 expect(future, throwsFormatException);
397 expect(errorGroup.done, throwsFormatException); 399 expect(errorGroup.done, throwsFormatException);
398 400
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 completion(equals(['value1', 'value2']))); 437 completion(equals(['value1', 'value2'])));
436 controller..add('value1')..add('value2')..close(); 438 controller..add('value1')..add('value2')..close();
437 439
438 expect(signal.future.then((_) { 440 expect(signal.future.then((_) {
439 // shouldn't cause a top-level exception 441 // shouldn't cause a top-level exception
440 completer.completeError(new FormatException()); 442 completer.completeError(new FormatException());
441 }), completes); 443 }), completes);
442 }); 444 });
443 }); 445 });
444 } 446 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/utils.dart ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698