| 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_async_test; | 6 library stream_controller_async_test; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import '../../../pkg/unittest/lib/unittest.dart'; | 10 import '../../../pkg/unittest/lib/unittest.dart'; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 sink.add(3); // -"- | 149 sink.add(3); // -"- |
| 150 sink.add(4); // -"- | 150 sink.add(4); // -"- |
| 151 sink.add(5); // seen by stream 10 | 151 sink.add(5); // seen by stream 10 |
| 152 sink.close(); | 152 sink.close(); |
| 153 }); | 153 }); |
| 154 } | 154 } |
| 155 | 155 |
| 156 testExtraMethods() { | 156 testExtraMethods() { |
| 157 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close(); | 157 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close(); |
| 158 | 158 |
| 159 test("firstMatching", () { | 159 test("firstWhere", () { |
| 160 StreamController c = new StreamController(); | 160 StreamController c = new StreamController(); |
| 161 Future f = c.stream.firstMatching((x) => (x % 3) == 0); | 161 Future f = c.stream.firstWhere((x) => (x % 3) == 0); |
| 162 f.then(expectAsync1((v) { Expect.equals(9, v); })); | 162 f.then(expectAsync1((v) { Expect.equals(9, v); })); |
| 163 sentEvents.replay(c); | 163 sentEvents.replay(c); |
| 164 }); | 164 }); |
| 165 | 165 |
| 166 test("firstMatching 2", () { | 166 test("firstWhere 2", () { |
| 167 StreamController c = new StreamController(); | 167 StreamController c = new StreamController(); |
| 168 Future f = c.stream.firstMatching((x) => (x % 4) == 0); | 168 Future f = c.stream.firstWhere((x) => (x % 4) == 0); |
| 169 f.catchError(expectAsync1((e) {})); | 169 f.catchError(expectAsync1((e) {})); |
| 170 sentEvents.replay(c); | 170 sentEvents.replay(c); |
| 171 }); | 171 }); |
| 172 | 172 |
| 173 test("firstMatching 3", () { | 173 test("firstWhere 3", () { |
| 174 StreamController c = new StreamController(); | 174 StreamController c = new StreamController(); |
| 175 Future f = c.stream.firstMatching((x) => (x % 4) == 0, defaultValue: () => 9
99); | 175 Future f = c.stream.firstWhere((x) => (x % 4) == 0, defaultValue: () => 999)
; |
| 176 f.then(expectAsync1((v) { Expect.equals(999, v); })); | 176 f.then(expectAsync1((v) { Expect.equals(999, v); })); |
| 177 sentEvents.replay(c); | 177 sentEvents.replay(c); |
| 178 }); | 178 }); |
| 179 | 179 |
| 180 | 180 |
| 181 test("lastMatching", () { | 181 test("lastWhere", () { |
| 182 StreamController c = new StreamController(); | 182 StreamController c = new StreamController(); |
| 183 Future f = c.stream.lastMatching((x) => (x % 3) == 0); | 183 Future f = c.stream.lastWhere((x) => (x % 3) == 0); |
| 184 f.then(expectAsync1((v) { Expect.equals(87, v); })); | 184 f.then(expectAsync1((v) { Expect.equals(87, v); })); |
| 185 sentEvents.replay(c); | 185 sentEvents.replay(c); |
| 186 }); | 186 }); |
| 187 | 187 |
| 188 test("lastMatching 2", () { | 188 test("lastWhere 2", () { |
| 189 StreamController c = new StreamController(); | 189 StreamController c = new StreamController(); |
| 190 Future f = c.stream.lastMatching((x) => (x % 4) == 0); | 190 Future f = c.stream.lastWhere((x) => (x % 4) == 0); |
| 191 f.catchError(expectAsync1((e) {})); | 191 f.catchError(expectAsync1((e) {})); |
| 192 sentEvents.replay(c); | 192 sentEvents.replay(c); |
| 193 }); | 193 }); |
| 194 | 194 |
| 195 test("lastMatching 3", () { | 195 test("lastWhere 3", () { |
| 196 StreamController c = new StreamController(); | 196 StreamController c = new StreamController(); |
| 197 Future f = c.stream.lastMatching((x) => (x % 4) == 0, defaultValue: () => 99
9); | 197 Future f = c.stream.lastWhere((x) => (x % 4) == 0, defaultValue: () => 999); |
| 198 f.then(expectAsync1((v) { Expect.equals(999, v); })); | 198 f.then(expectAsync1((v) { Expect.equals(999, v); })); |
| 199 sentEvents.replay(c); | 199 sentEvents.replay(c); |
| 200 }); | 200 }); |
| 201 | 201 |
| 202 test("singleMatching", () { | 202 test("singleWhere", () { |
| 203 StreamController c = new StreamController(); | 203 StreamController c = new StreamController(); |
| 204 Future f = c.stream.singleMatching((x) => (x % 9) == 0); | 204 Future f = c.stream.singleWhere((x) => (x % 9) == 0); |
| 205 f.then(expectAsync1((v) { Expect.equals(9, v); })); | 205 f.then(expectAsync1((v) { Expect.equals(9, v); })); |
| 206 sentEvents.replay(c); | 206 sentEvents.replay(c); |
| 207 }); | 207 }); |
| 208 | 208 |
| 209 test("singleMatching 2", () { | 209 test("singleWhere 2", () { |
| 210 StreamController c = new StreamController(); | 210 StreamController c = new StreamController(); |
| 211 Future f = c.stream.singleMatching((x) => (x % 3) == 0); // Matches both 9
and 87.. | 211 Future f = c.stream.singleWhere((x) => (x % 3) == 0); // Matches both 9 and
87.. |
| 212 f.catchError(expectAsync1((e) { Expect.isTrue(e.error is StateError); })); | 212 f.catchError(expectAsync1((e) { Expect.isTrue(e.error is StateError); })); |
| 213 sentEvents.replay(c); | 213 sentEvents.replay(c); |
| 214 }); | 214 }); |
| 215 | 215 |
| 216 test("first", () { | 216 test("first", () { |
| 217 StreamController c = new StreamController(); | 217 StreamController c = new StreamController(); |
| 218 Future f = c.stream.first; | 218 Future f = c.stream.first; |
| 219 f.then(expectAsync1((v) { Expect.equals(7, v);})); | 219 f.then(expectAsync1((v) { Expect.equals(7, v);})); |
| 220 sentEvents.replay(c); | 220 sentEvents.replay(c); |
| 221 }); | 221 }); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 testFuture("reduce", (s, act) => s.reduce(0, (a,b) => act(b))); | 451 testFuture("reduce", (s, act) => s.reduce(0, (a,b) => act(b))); |
| 452 } | 452 } |
| 453 | 453 |
| 454 main() { | 454 main() { |
| 455 testController(); | 455 testController(); |
| 456 testSingleController(); | 456 testSingleController(); |
| 457 testExtraMethods(); | 457 testExtraMethods(); |
| 458 testPause(); | 458 testPause(); |
| 459 testRethrow(); | 459 testRethrow(); |
| 460 } | 460 } |
| OLD | NEW |