| OLD | NEW |
| 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 '../../../pkg/unittest/lib/unittest.dart'; | 9 import '../../../pkg/unittest/lib/unittest.dart'; |
| 10 import '../../pub/error_group.dart'; | 10 import '../../pub/error_group.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 errorGroup.signalError(new AsyncError(new FormatException())); | 30 errorGroup.signalError(new AsyncError(new FormatException())); |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 test("shouldn't allow additional futures or streams once an error has been " | 33 test("shouldn't allow additional futures or streams once an error has been " |
| 34 "signaled", () { | 34 "signaled", () { |
| 35 expect(errorGroup.done, throwsFormatException); | 35 expect(errorGroup.done, throwsFormatException); |
| 36 errorGroup.signalError(new AsyncError(new FormatException())); | 36 errorGroup.signalError(new AsyncError(new FormatException())); |
| 37 | 37 |
| 38 expect(() => errorGroup.registerFuture(new Future.immediate(null)), | 38 expect(() => errorGroup.registerFuture(new Future.immediate(null)), |
| 39 throwsStateError); | 39 throwsStateError); |
| 40 expect(() => errorGroup.registerStream(new StreamController()), | 40 expect(() => errorGroup.registerStream(new StreamController().stream), |
| 41 throwsStateError); | 41 throwsStateError); |
| 42 }); | 42 }); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 group('with a single future', () { | 45 group('with a single future', () { |
| 46 Completer completer; | 46 Completer completer; |
| 47 Future future; | 47 Future future; |
| 48 | 48 |
| 49 setUp(() { | 49 setUp(() { |
| 50 errorGroup = new ErrorGroup(); | 50 errorGroup = new ErrorGroup(); |
| 51 completer = new Completer(); | 51 completer = new Completer(); |
| 52 future = errorGroup.registerFuture(completer.future); | 52 future = errorGroup.registerFuture(completer.future); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('should pass through a value from the future', () { | 55 test('should pass through a value from the future', () { |
| 56 expect(future, completion(equals('value'))); | 56 expect(future, completion(equals('value'))); |
| 57 expect(errorGroup.done, completes); | 57 expect(errorGroup.done, completes); |
| 58 completer.complete('value'); | 58 completer.complete('value'); |
| 59 }); | 59 }); |
| 60 | 60 |
| 61 test("shouldn't allow additional futures or streams once .done has " | 61 test("shouldn't allow additional futures or streams once .done has " |
| 62 "been called", () { | 62 "been called", () { |
| 63 completer.complete('value'); | 63 completer.complete('value'); |
| 64 | 64 |
| 65 expect(() => errorGroup.registerFuture(new Future.immediate(null)), | 65 expect(() => errorGroup.registerFuture(new Future.immediate(null)), |
| 66 throwsStateError); | 66 throwsStateError); |
| 67 expect(() => errorGroup.registerStream(new StreamController()), | 67 expect(() => errorGroup.registerStream(new StreamController().stream), |
| 68 throwsStateError); | 68 throwsStateError); |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 test('should pass through an exception from the future if it has a ' | 71 test('should pass through an exception from the future if it has a ' |
| 72 'listener', () { | 72 'listener', () { |
| 73 expect(future, throwsFormatException); | 73 expect(future, throwsFormatException); |
| 74 // errorGroup shouldn't top-level the exception | 74 // errorGroup shouldn't top-level the exception |
| 75 completer.completeError(new FormatException()); | 75 completer.completeError(new FormatException()); |
| 76 }); | 76 }); |
| 77 | 77 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 }); | 196 }); |
| 197 }); | 197 }); |
| 198 | 198 |
| 199 group('with a single stream', () { | 199 group('with a single stream', () { |
| 200 StreamController controller; | 200 StreamController controller; |
| 201 Stream stream; | 201 Stream stream; |
| 202 | 202 |
| 203 setUp(() { | 203 setUp(() { |
| 204 errorGroup = new ErrorGroup(); | 204 errorGroup = new ErrorGroup(); |
| 205 controller = new StreamController.multiSubscription(); | 205 controller = new StreamController.multiSubscription(); |
| 206 stream = errorGroup.registerStream(controller); | 206 stream = errorGroup.registerStream(controller.stream); |
| 207 }); | 207 }); |
| 208 | 208 |
| 209 test('should pass through values from the stream', () { | 209 test('should pass through values from the stream', () { |
| 210 expect(stream.elementAt(0), completion(equals(1))); | 210 expect(stream.elementAt(0), completion(equals(1))); |
| 211 expect(stream.elementAt(1), completion(equals(2))); | 211 expect(stream.elementAt(1), completion(equals(2))); |
| 212 expect(errorGroup.done, completes); | 212 expect(errorGroup.done, completes); |
| 213 | 213 |
| 214 controller..add(1)..add(2)..close(); | 214 controller..add(1)..add(2)..close(); |
| 215 }); | 215 }); |
| 216 | 216 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 }); | 286 }); |
| 287 }); | 287 }); |
| 288 | 288 |
| 289 group('with a single single-subscription stream', () { | 289 group('with a single single-subscription stream', () { |
| 290 StreamController controller; | 290 StreamController controller; |
| 291 Stream stream; | 291 Stream stream; |
| 292 | 292 |
| 293 setUp(() { | 293 setUp(() { |
| 294 errorGroup = new ErrorGroup(); | 294 errorGroup = new ErrorGroup(); |
| 295 controller = new StreamController(); | 295 controller = new StreamController(); |
| 296 stream = errorGroup.registerStream(controller); | 296 stream = errorGroup.registerStream(controller.stream); |
| 297 }); | 297 }); |
| 298 | 298 |
| 299 test("should complete .done when the stream is done even if the stream " | 299 test("should complete .done when the stream is done even if the stream " |
| 300 "doesn't have a listener", () { | 300 "doesn't have a listener", () { |
| 301 expect(errorGroup.done, completes); | 301 expect(errorGroup.done, completes); |
| 302 controller.add('value'); | 302 controller.add('value'); |
| 303 controller.close(); | 303 controller.close(); |
| 304 | 304 |
| 305 // A listener added afterwards should receive the value | 305 // A listener added afterwards should receive the value |
| 306 expect(errorGroup.done.then((_) => stream.toList()), | 306 expect(errorGroup.done.then((_) => stream.toList()), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 336 group('with multiple streams', () { | 336 group('with multiple streams', () { |
| 337 StreamController controller1; | 337 StreamController controller1; |
| 338 StreamController controller2; | 338 StreamController controller2; |
| 339 Stream stream1; | 339 Stream stream1; |
| 340 Stream stream2; | 340 Stream stream2; |
| 341 | 341 |
| 342 setUp(() { | 342 setUp(() { |
| 343 errorGroup = new ErrorGroup(); | 343 errorGroup = new ErrorGroup(); |
| 344 controller1 = new StreamController.multiSubscription(); | 344 controller1 = new StreamController.multiSubscription(); |
| 345 controller2 = new StreamController.multiSubscription(); | 345 controller2 = new StreamController.multiSubscription(); |
| 346 stream1 = errorGroup.registerStream(controller1); | 346 stream1 = errorGroup.registerStream(controller1.stream); |
| 347 stream2 = errorGroup.registerStream(controller2); | 347 stream2 = errorGroup.registerStream(controller2.stream); |
| 348 }); | 348 }); |
| 349 | 349 |
| 350 test("should pipe exceptions from one stream to the other and to .done", | 350 test("should pipe exceptions from one stream to the other and to .done", |
| 351 () { | 351 () { |
| 352 expect(stream1.first, throwsFormatException); | 352 expect(stream1.first, throwsFormatException); |
| 353 expect(stream2.first, throwsFormatException); | 353 expect(stream2.first, throwsFormatException); |
| 354 expect(errorGroup.done, throwsFormatException); | 354 expect(errorGroup.done, throwsFormatException); |
| 355 | 355 |
| 356 controller1.signalError(new AsyncError(new FormatException())); | 356 controller1.signalError(new AsyncError(new FormatException())); |
| 357 }); | 357 }); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 390 |
| 391 group('with a stream and a future', () { | 391 group('with a stream and a future', () { |
| 392 StreamController controller; | 392 StreamController controller; |
| 393 Stream stream; | 393 Stream stream; |
| 394 Completer completer; | 394 Completer completer; |
| 395 Future future; | 395 Future future; |
| 396 | 396 |
| 397 setUp(() { | 397 setUp(() { |
| 398 errorGroup = new ErrorGroup(); | 398 errorGroup = new ErrorGroup(); |
| 399 controller = new StreamController.multiSubscription(); | 399 controller = new StreamController.multiSubscription(); |
| 400 stream = errorGroup.registerStream(controller); | 400 stream = errorGroup.registerStream(controller.stream); |
| 401 completer = new Completer(); | 401 completer = new Completer(); |
| 402 future = errorGroup.registerFuture(completer.future); | 402 future = errorGroup.registerFuture(completer.future); |
| 403 }); | 403 }); |
| 404 | 404 |
| 405 test("should pipe exceptions from the stream to the future", () { | 405 test("should pipe exceptions from the stream to the future", () { |
| 406 expect(stream.first, throwsFormatException); | 406 expect(stream.first, throwsFormatException); |
| 407 expect(future, throwsFormatException); | 407 expect(future, throwsFormatException); |
| 408 expect(errorGroup.done, throwsFormatException); | 408 expect(errorGroup.done, throwsFormatException); |
| 409 | 409 |
| 410 controller.signalError(new AsyncError(new FormatException())); | 410 controller.signalError(new AsyncError(new FormatException())); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 const isStateError = const _StateError(); | 457 const isStateError = const _StateError(); |
| 458 | 458 |
| 459 /// A matcher for functions that throw StateError. | 459 /// A matcher for functions that throw StateError. |
| 460 const Matcher throwsStateError = | 460 const Matcher throwsStateError = |
| 461 const Throws(isStateError); | 461 const Throws(isStateError); |
| 462 | 462 |
| 463 class _StateError extends TypeMatcher { | 463 class _StateError extends TypeMatcher { |
| 464 const _StateError() : super("StateError"); | 464 const _StateError() : super("StateError"); |
| 465 bool matches(item, MatchState matchState) => item is StateError; | 465 bool matches(item, MatchState matchState) => item is StateError; |
| 466 } | 466 } |
| OLD | NEW |