| OLD | NEW |
| 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 library stream_controller_test; | 6 library stream_controller_test; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'event_helper.dart'; | 9 import 'event_helper.dart'; |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); | 56 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); |
| 57 sentEvents.replay(c); | 57 sentEvents.replay(c); |
| 58 Expect.listEquals(expectedEvents.events, actualEvents.events); | 58 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 59 | 59 |
| 60 // Test handleError. | 60 // Test handleError. |
| 61 c = new StreamController(); | 61 c = new StreamController(); |
| 62 expectedEvents = new Events()..add("ab")..error("[foo]"); | 62 expectedEvents = new Events()..add("ab")..error("[foo]"); |
| 63 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); | 63 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); |
| 64 actualEvents = new Events.capture(c.handleError((v) { | 64 actualEvents = new Events.capture(c.handleError((v) { |
| 65 if (v.error is String) { | 65 if (v.error is String) { |
| 66 return new AsyncError("[${v.error}]", | 66 throw new AsyncError("[${v.error}]", |
| 67 "other stack"); | 67 "other stack"); |
| 68 } | 68 } |
| 69 }), unsubscribeOnError: true); | 69 }), unsubscribeOnError: true); |
| 70 sentEvents.replay(c); | 70 sentEvents.replay(c); |
| 71 Expect.listEquals(expectedEvents.events, actualEvents.events); | 71 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 72 | 72 |
| 73 // reduce is tested asynchronously and therefore not in this file. | 73 // reduce is tested asynchronously and therefore not in this file. |
| 74 | 74 |
| 75 // Test expand | 75 // Test expand |
| 76 c = new StreamController(); | 76 c = new StreamController(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ..add("snugglefluffy") | 108 ..add("snugglefluffy") |
| 109 ..add(7) | 109 ..add(7) |
| 110 ..add("42") | 110 ..add("42") |
| 111 ..error("not FormatException") // Unsubscribes. | 111 ..error("not FormatException") // Unsubscribes. |
| 112 ..close(); | 112 ..close(); |
| 113 expectedEvents = new Events()..add(42)..error("not FormatException"); | 113 expectedEvents = new Events()..add(42)..error("not FormatException"); |
| 114 actualEvents = new Events.capture( | 114 actualEvents = new Events.capture( |
| 115 c.where((v) => v is String) | 115 c.where((v) => v is String) |
| 116 .mappedBy((v) => int.parse(v)) | 116 .mappedBy((v) => int.parse(v)) |
| 117 .handleError((v) { | 117 .handleError((v) { |
| 118 if (v.error is! FormatException) return v; | 118 if (v.error is! FormatException) throw v; |
| 119 }) | 119 }) |
| 120 .where((v) => v > 10), | 120 .where((v) => v > 10), |
| 121 unsubscribeOnError: true); | 121 unsubscribeOnError: true); |
| 122 sentEvents.replay(c); | 122 sentEvents.replay(c); |
| 123 Expect.listEquals(expectedEvents.events, actualEvents.events); | 123 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 124 | 124 |
| 125 // Test subscription changes while firing. | 125 // Test subscription changes while firing. |
| 126 c = new StreamController(); | 126 c = new StreamController(); |
| 127 var sink = c.sink; | 127 var sink = c.sink; |
| 128 var stream = c.stream; | 128 var stream = c.stream; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); | 196 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); |
| 197 sentEvents.replay(c); | 197 sentEvents.replay(c); |
| 198 Expect.listEquals(expectedEvents.events, actualEvents.events); | 198 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 199 | 199 |
| 200 // Test handleError. | 200 // Test handleError. |
| 201 c = new StreamController.singleSubscription(); | 201 c = new StreamController.singleSubscription(); |
| 202 expectedEvents = new Events()..add("ab")..error("[foo]"); | 202 expectedEvents = new Events()..add("ab")..error("[foo]"); |
| 203 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); | 203 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); |
| 204 actualEvents = new Events.capture(c.handleError((v) { | 204 actualEvents = new Events.capture(c.handleError((v) { |
| 205 if (v.error is String) { | 205 if (v.error is String) { |
| 206 return new AsyncError("[${v.error}]", | 206 throw new AsyncError("[${v.error}]", |
| 207 "other stack"); | 207 "other stack"); |
| 208 } | 208 } |
| 209 }), unsubscribeOnError: true); | 209 }), unsubscribeOnError: true); |
| 210 sentEvents.replay(c); | 210 sentEvents.replay(c); |
| 211 Expect.listEquals(expectedEvents.events, actualEvents.events); | 211 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 212 | 212 |
| 213 // reduce is tested asynchronously and therefore not in this file. | 213 // reduce is tested asynchronously and therefore not in this file. |
| 214 | 214 |
| 215 // Test expand | 215 // Test expand |
| 216 c = new StreamController.singleSubscription(); | 216 c = new StreamController.singleSubscription(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 ..add("snugglefluffy") | 260 ..add("snugglefluffy") |
| 261 ..add(7) | 261 ..add(7) |
| 262 ..add("42") | 262 ..add("42") |
| 263 ..error("not FormatException") // Unsubscribes. | 263 ..error("not FormatException") // Unsubscribes. |
| 264 ..close(); | 264 ..close(); |
| 265 expectedEvents = new Events()..add(42)..error("not FormatException"); | 265 expectedEvents = new Events()..add(42)..error("not FormatException"); |
| 266 actualEvents = new Events.capture( | 266 actualEvents = new Events.capture( |
| 267 c.where((v) => v is String) | 267 c.where((v) => v is String) |
| 268 .mappedBy((v) => int.parse(v)) | 268 .mappedBy((v) => int.parse(v)) |
| 269 .handleError((v) { | 269 .handleError((v) { |
| 270 if (v.error is! FormatException) return v; | 270 if (v.error is! FormatException) throw v; |
| 271 }) | 271 }) |
| 272 .where((v) => v > 10), | 272 .where((v) => v > 10), |
| 273 unsubscribeOnError: true); | 273 unsubscribeOnError: true); |
| 274 sentEvents.replay(c); | 274 sentEvents.replay(c); |
| 275 Expect.listEquals(expectedEvents.events, actualEvents.events); | 275 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 276 | 276 |
| 277 // Test that only one subscription is allowed. | 277 // Test that only one subscription is allowed. |
| 278 c = new StreamController.singleSubscription(); | 278 c = new StreamController.singleSubscription(); |
| 279 var sink = c.sink; | 279 var sink = c.sink; |
| 280 var stream = c.stream; | 280 var stream = c.stream; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 actualEvents = new Events.capture(c.distinct((a, b) => a < b)); | 352 actualEvents = new Events.capture(c.distinct((a, b) => a < b)); |
| 353 sentEvents.replay(c); | 353 sentEvents.replay(c); |
| 354 Expect.listEquals(expectedEvents.events, actualEvents.events); | 354 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 355 } | 355 } |
| 356 | 356 |
| 357 main() { | 357 main() { |
| 358 testController(); | 358 testController(); |
| 359 testSingleController(); | 359 testSingleController(); |
| 360 testExtraMethods(); | 360 testExtraMethods(); |
| 361 } | 361 } |
| OLD | NEW |