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

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: 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
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(new StreamController(sync: true).st ream),
floitsch 2013/05/30 12:13:48 long line.
Lasse Reichstein Nielsen 2013/05/31 05:51:59 Done.
42 throwsStateError); 42 throwsStateError);
43 }); 43 });
44 }); 44 });
45 45
46 group('with a single future', () { 46 group('with a single future', () {
47 Completer completer; 47 Completer completer;
48 Future future; 48 Future future;
49 49
50 setUp(() { 50 setUp(() {
51 errorGroup = new ErrorGroup(); 51 errorGroup = new ErrorGroup();
52 completer = new Completer(); 52 completer = new Completer();
53 future = errorGroup.registerFuture(completer.future); 53 future = errorGroup.registerFuture(completer.future);
54 }); 54 });
55 55
56 test('should pass through a value from the future', () { 56 test('should pass through a value from the future', () {
57 expect(future, completion(equals('value'))); 57 expect(future, completion(equals('value')));
58 expect(errorGroup.done, completes); 58 expect(errorGroup.done, completes);
59 completer.complete('value'); 59 completer.complete('value');
60 }); 60 });
61 61
62 test("shouldn't allow additional futures or streams once .done has " 62 test("shouldn't allow additional futures or streams once .done has "
63 "been called", () { 63 "been called", () {
64 completer.complete('value'); 64 completer.complete('value');
65 65
66 completer.future.then(expectAsync1((_) { 66 completer.future.then(expectAsync1((_) {
67 expect(() => errorGroup.registerFuture(new Future.value()), 67 expect(() => errorGroup.registerFuture(new Future.value()),
68 throwsStateError); 68 throwsStateError);
69 expect(() => errorGroup.registerStream(new StreamController().stream), 69 expect(() => errorGroup.registerStream(new StreamController(sync: true). stream),
floitsch 2013/05/30 12:13:48 ditto.
Lasse Reichstein Nielsen 2013/05/31 05:51:59 Done.
70 throwsStateError); 70 throwsStateError);
71 })); 71 }));
72 }); 72 });
73 73
74 test('should pass through an exception from the future if it has a ' 74 test('should pass through an exception from the future if it has a '
75 'listener', () { 75 'listener', () {
76 expect(future, throwsFormatException); 76 expect(future, throwsFormatException);
77 // errorGroup shouldn't top-level the exception 77 // errorGroup shouldn't top-level the exception
78 completer.completeError(new FormatException()); 78 completer.completeError(new FormatException());
79 }); 79 });
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }), completes); 198 }), completes);
199 }); 199 });
200 }); 200 });
201 201
202 group('with a single stream', () { 202 group('with a single stream', () {
203 StreamController controller; 203 StreamController controller;
204 Stream stream; 204 Stream stream;
205 205
206 setUp(() { 206 setUp(() {
207 errorGroup = new ErrorGroup(); 207 errorGroup = new ErrorGroup();
208 controller = new StreamController(); 208 controller = new StreamController(sync: true);
209 stream = errorGroup.registerStream(controller.stream.asBroadcastStream()); 209 stream = errorGroup.registerStream(controller.stream.asBroadcastStream());
210 }); 210 });
211 211
212 test('should pass through values from the stream', () { 212 test('should pass through values from the stream', () {
213 StreamIterator iter = new StreamIterator(stream); 213 StreamIterator iter = new StreamIterator(stream);
214 iter.moveNext().then((hasNext) { 214 iter.moveNext().then((hasNext) {
215 expect(hasNext, isTrue); 215 expect(hasNext, isTrue);
216 expect(iter.current, equals(1)); 216 expect(iter.current, equals(1));
217 iter.moveNext().then((hasNext) { 217 iter.moveNext().then((hasNext) {
218 expect(hasNext, isTrue); 218 expect(hasNext, isTrue);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 }); 270 });
271 271
272 }); 272 });
273 273
274 group('with a single single-subscription stream', () { 274 group('with a single single-subscription stream', () {
275 StreamController controller; 275 StreamController controller;
276 Stream stream; 276 Stream stream;
277 277
278 setUp(() { 278 setUp(() {
279 errorGroup = new ErrorGroup(); 279 errorGroup = new ErrorGroup();
280 controller = new StreamController(); 280 controller = new StreamController(sync: true);
281 stream = errorGroup.registerStream(controller.stream); 281 stream = errorGroup.registerStream(controller.stream);
282 }); 282 });
283 283
284 test("should complete .done when the stream is done even if the stream " 284 test("should complete .done when the stream is done even if the stream "
285 "doesn't have a listener", () { 285 "doesn't have a listener", () {
286 expect(errorGroup.done, completes); 286 expect(errorGroup.done, completes);
287 controller.add('value'); 287 controller.add('value');
288 controller.close(); 288 controller.close();
289 289
290 // A listener added afterwards should receive the value 290 // A listener added afterwards should receive the value
(...skipping 28 matching lines...) Expand all
319 }); 319 });
320 320
321 group('with multiple streams', () { 321 group('with multiple streams', () {
322 StreamController controller1; 322 StreamController controller1;
323 StreamController controller2; 323 StreamController controller2;
324 Stream stream1; 324 Stream stream1;
325 Stream stream2; 325 Stream stream2;
326 326
327 setUp(() { 327 setUp(() {
328 errorGroup = new ErrorGroup(); 328 errorGroup = new ErrorGroup();
329 controller1 = new StreamController(); 329 controller1 = new StreamController(sync: true);
330 controller2 = new StreamController(); 330 controller2 = new StreamController(sync: true);
331 stream1 = errorGroup.registerStream(controller1.stream.asBroadcastStream() ); 331 stream1 = errorGroup.registerStream(controller1.stream.asBroadcastStream() );
332 stream2 = errorGroup.registerStream(controller2.stream.asBroadcastStream() ); 332 stream2 = errorGroup.registerStream(controller2.stream.asBroadcastStream() );
333 }); 333 });
334 334
335 test("should pipe exceptions from one stream to the other and to .done", 335 test("should pipe exceptions from one stream to the other and to .done",
336 () { 336 () {
337 expect(stream1.first, throwsFormatException); 337 expect(stream1.first, throwsFormatException);
338 expect(stream2.first, throwsFormatException); 338 expect(stream2.first, throwsFormatException);
339 expect(errorGroup.done, throwsFormatException); 339 expect(errorGroup.done, throwsFormatException);
340 340
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 }); 378 });
379 379
380 group('with a stream and a future', () { 380 group('with a stream and a future', () {
381 StreamController controller; 381 StreamController controller;
382 Stream stream; 382 Stream stream;
383 Completer completer; 383 Completer completer;
384 Future future; 384 Future future;
385 385
386 setUp(() { 386 setUp(() {
387 errorGroup = new ErrorGroup(); 387 errorGroup = new ErrorGroup();
388 controller = new StreamController(); 388 controller = new StreamController(sync: true);
389 stream = errorGroup.registerStream(controller.stream.asBroadcastStream()); 389 stream = errorGroup.registerStream(controller.stream.asBroadcastStream());
390 completer = new Completer(); 390 completer = new Completer();
391 future = errorGroup.registerFuture(completer.future); 391 future = errorGroup.registerFuture(completer.future);
392 }); 392 });
393 393
394 test("should pipe exceptions from the stream to the future", () { 394 test("should pipe exceptions from the stream to the future", () {
395 expect(stream.first, throwsFormatException); 395 expect(stream.first, throwsFormatException);
396 expect(future, throwsFormatException); 396 expect(future, throwsFormatException);
397 expect(errorGroup.done, throwsFormatException); 397 expect(errorGroup.done, throwsFormatException);
398 398
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 completion(equals(['value1', 'value2']))); 435 completion(equals(['value1', 'value2'])));
436 controller..add('value1')..add('value2')..close(); 436 controller..add('value1')..add('value2')..close();
437 437
438 expect(signal.future.then((_) { 438 expect(signal.future.then((_) {
439 // shouldn't cause a top-level exception 439 // shouldn't cause a top-level exception
440 completer.completeError(new FormatException()); 440 completer.completeError(new FormatException());
441 }), completes); 441 }), completes);
442 }); 442 });
443 }); 443 });
444 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698