| 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 scheduled_test.stream_matcher_test; | 5 library scheduled_test.stream_matcher_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:scheduled_test/scheduled_stream.dart'; | 9 import 'package:scheduled_test/scheduled_stream.dart'; |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | 10 import 'package:scheduled_test/scheduled_test.dart'; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 }, (errors) { | 176 }, (errors) { |
| 177 expect(errors, hasLength(1)); | 177 expect(errors, hasLength(1)); |
| 178 expect(errors.first.error.message, equals( | 178 expect(errors.first.error.message, equals( |
| 179 "Expected: <100>\n" | 179 "Expected: <100>\n" |
| 180 " Emitted: * 1")); | 180 " Emitted: * 1")); |
| 181 }); | 181 }); |
| 182 | 182 |
| 183 expectTestPasses("consumeThrough() consumes values through the given matcher", | 183 expectTestPasses("consumeThrough() consumes values through the given matcher", |
| 184 () { | 184 () { |
| 185 var stream = createStream(); | 185 var stream = createStream(); |
| 186 stream.expect(consumeThrough(greaterThan(2))); | 186 stream.expect(consumeThrough(inOrder([2, 3]))); |
| 187 stream.expect(4); | 187 stream.expect(4); |
| 188 }); | 188 }); |
| 189 | 189 |
| 190 expectTestPasses("consumeThrough() will stop if the first value matches", () { | 190 expectTestPasses("consumeThrough() will stop if the first value matches", () { |
| 191 var stream = createStream(); | 191 var stream = createStream(); |
| 192 stream.expect(consumeThrough(1)); | 192 stream.expect(consumeThrough(inOrder([1, 2]))); |
| 193 stream.expect(2); | 193 stream.expect(3); |
| 194 }); | 194 }); |
| 195 | 195 |
| 196 expectTestFails("consumeThrough() will fail if the stream ends before the " | 196 expectTestFails("consumeThrough() will fail if the stream ends before the " |
| 197 "value is reached", () { | 197 "value is reached", () { |
| 198 createStream().expect(consumeThrough(100)); | 198 createStream().expect(consumeThrough(inOrder([5, 6]))); |
| 199 }, (errors) { | 199 }, (errors) { |
| 200 expect(errors, hasLength(1)); | 200 expect(errors, hasLength(1)); |
| 201 expect(errors.first.error.message, equals( | 201 expect(errors.first.error.message, equals( |
| 202 "Expected: values followed by <100>\n" | 202 "Expected: values followed by:\n" |
| 203 " | * <5>\n" |
| 204 " | * <6>\n" |
| 203 " Emitted: * 1\n" | 205 " Emitted: * 1\n" |
| 204 " * 2\n" | 206 " * 2\n" |
| 205 " * 3\n" | 207 " * 3\n" |
| 206 " * 4\n" | 208 " * 4\n" |
| 207 " * 5\n" | 209 " * 5\n" |
| 208 " Which: unexpected end of stream")); | 210 " Which: unexpected end of stream")); |
| 209 }); | 211 }); |
| 210 | 212 |
| 211 expectTestPasses("consumeWhile() consumes values while the given matcher " | 213 expectTestPasses("consumeWhile() consumes values while the given matcher " |
| 212 "matches", () { | 214 "matches", () { |
| 213 var stream = createStream(); | 215 var stream = createStream(); |
| 214 stream.expect(consumeWhile(lessThan(4))); | 216 stream.expect(consumeWhile(lessThan(4))); |
| 215 stream.expect(4); | 217 stream.expect(4); |
| 216 }); | 218 }); |
| 217 | 219 |
| 220 expectTestPasses("consumeWhile() consumes values in chunks", () { |
| 221 var stream = createStream(); |
| 222 stream.expect(consumeWhile(inOrder([anything, anything]))); |
| 223 stream.expect(5); |
| 224 }); |
| 225 |
| 218 expectTestPasses("consumeWhile() will stop if the first value doesn't match", | 226 expectTestPasses("consumeWhile() will stop if the first value doesn't match", |
| 219 () { | 227 () { |
| 220 var stream = createStream(); | 228 var stream = createStream(); |
| 221 stream.expect(consumeWhile(2)); | 229 stream.expect(consumeWhile(inOrder([2, 3]))); |
| 222 stream.expect(1); | 230 stream.expect(1); |
| 223 }); | 231 }); |
| 224 | 232 |
| 225 expectTestPasses("either() will match if the first branch matches", () { | 233 expectTestPasses("either() will match if the first branch matches", () { |
| 226 createStream().expect(either(1, 100)); | 234 createStream().expect(either(1, 100)); |
| 227 }); | 235 }); |
| 228 | 236 |
| 229 expectTestPasses("either() will match if the second branch matches", () { | 237 expectTestPasses("either() will match if the second branch matches", () { |
| 230 createStream().expect(either(100, 1)); | 238 createStream().expect(either(100, 1)); |
| 231 }); | 239 }); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 expect(errors.first.error.message, equals( | 324 expect(errors.first.error.message, equals( |
| 317 "Expected: is done\n" | 325 "Expected: is done\n" |
| 318 " Emitted: * 1\n" | 326 " Emitted: * 1\n" |
| 319 " * 2\n" | 327 " * 2\n" |
| 320 " * 3\n" | 328 " * 3\n" |
| 321 " * 4\n" | 329 " * 4\n" |
| 322 " * 5\n" | 330 " * 5\n" |
| 323 " Which: stream wasn't finished")); | 331 " Which: stream wasn't finished")); |
| 324 }); | 332 }); |
| 325 } | 333 } |
| OLD | NEW |