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

Side by Side Diff: utils/tests/pub/error_group_test.dart

Issue 12610006: Renamed StreamSink to EventSink. Renamed signalError to addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed inheritance back! Now create StreamSink instead of EventSink where we create them. Created 7 years, 9 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 '../../../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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
217 test('should pass through an error from the stream if it has a ' 217 test('should pass through an error from the stream if it has a '
218 'listener', () { 218 'listener', () {
219 expect(stream.first, throwsFormatException); 219 expect(stream.first, throwsFormatException);
220 // errorGroup shouldn't top-level the exception 220 // errorGroup shouldn't top-level the exception
221 controller.signalError(new AsyncError(new FormatException())); 221 controller.addError(new AsyncError(new FormatException()));
222 }); 222 });
223 223
224 test('should notify the error group of an exception from the stream even ' 224 test('should notify the error group of an exception from the stream even '
225 'if it has a listener', () { 225 'if it has a listener', () {
226 expect(stream.first, throwsFormatException); 226 expect(stream.first, throwsFormatException);
227 expect(errorGroup.done, throwsFormatException); 227 expect(errorGroup.done, throwsFormatException);
228 controller.signalError(new AsyncError(new FormatException())); 228 controller.addError(new AsyncError(new FormatException()));
229 }); 229 });
230 230
231 test('should pass a signaled exception to the stream if it has a listener ' 231 test('should pass a signaled exception to the stream if it has a listener '
232 'and should unsubscribe that stream', () { 232 'and should unsubscribe that stream', () {
233 expect(stream.first, throwsFormatException); 233 expect(stream.first, throwsFormatException);
234 // errorGroup shouldn't top-level the exception 234 // errorGroup shouldn't top-level the exception
235 errorGroup.signalError(new AsyncError(new FormatException())); 235 errorGroup.signalError(new AsyncError(new FormatException()));
236 236
237 expect(stream.first.catchError((_) { 237 expect(stream.first.catchError((_) {
238 controller.add('value'); 238 controller.add('value');
(...skipping 16 matching lines...) Expand all
255 255
256 // A listener added afterwards should see an empty stream, since it's not 256 // A listener added afterwards should see an empty stream, since it's not
257 // single-subscription 257 // single-subscription
258 expect(errorGroup.done.then((_) => stream.toList()), 258 expect(errorGroup.done.then((_) => stream.toList()),
259 completion(isEmpty)); 259 completion(isEmpty));
260 }); 260 });
261 261
262 test("should pipe an exception from the stream to .done if the stream " 262 test("should pipe an exception from the stream to .done if the stream "
263 "doesn't have a listener", () { 263 "doesn't have a listener", () {
264 expect(errorGroup.done, throwsFormatException); 264 expect(errorGroup.done, throwsFormatException);
265 controller.signalError(new AsyncError(new FormatException())); 265 controller.addError(new AsyncError(new FormatException()));
266 266
267 // A listener added afterwards should see an empty stream, since it's not 267 // A listener added afterwards should see an empty stream, since it's not
268 // single-subscription 268 // single-subscription
269 expect(errorGroup.done.catchError((_) { 269 expect(errorGroup.done.catchError((_) {
270 controller.add('value'); // should be ignored 270 controller.add('value'); // should be ignored
271 return stream.toList(); 271 return stream.toList();
272 }), completion(isEmpty)); 272 }), completion(isEmpty));
273 }); 273 });
274 274
275 test("should pass a signaled exception to .done if the stream doesn't " 275 test("should pass a signaled exception to .done if the stream doesn't "
(...skipping 27 matching lines...) Expand all
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()),
307 completion(equals(['value']))); 307 completion(equals(['value'])));
308 }); 308 });
309 309
310 test("should pipe an exception from the stream to .done if the stream " 310 test("should pipe an exception from the stream to .done if the stream "
311 "doesn't have a listener", () { 311 "doesn't have a listener", () {
312 expect(errorGroup.done, throwsFormatException); 312 expect(errorGroup.done, throwsFormatException);
313 controller.signalError(new AsyncError(new FormatException())); 313 controller.addError(new AsyncError(new FormatException()));
314 314
315 // A listener added afterwards should receive the exception 315 // A listener added afterwards should receive the exception
316 expect(errorGroup.done.catchError((_) { 316 expect(errorGroup.done.catchError((_) {
317 controller.add('value'); // should be ignored 317 controller.add('value'); // should be ignored
318 expect(stream.first, throwsFormatException); 318 expect(stream.first, throwsFormatException);
319 }), completes); 319 }), completes);
320 }); 320 });
321 321
322 test("should pass a signaled exception to .done if the stream doesn't " 322 test("should pass a signaled exception to .done if the stream doesn't "
323 "have a listener", 323 "have a listener",
(...skipping 22 matching lines...) Expand all
346 stream1 = errorGroup.registerStream(controller1.stream); 346 stream1 = errorGroup.registerStream(controller1.stream);
347 stream2 = errorGroup.registerStream(controller2.stream); 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.addError(new AsyncError(new FormatException()));
357 }); 357 });
358 358
359 test("each future should be able to emit values independently", () { 359 test("each future should be able to emit values independently", () {
360 expect(stream1.toList(), completion(equals(['value1.1', 'value1.2']))); 360 expect(stream1.toList(), completion(equals(['value1.1', 'value1.2'])));
361 expect(stream2.toList(), completion(equals(['value2.1', 'value2.2']))); 361 expect(stream2.toList(), completion(equals(['value2.1', 'value2.2'])));
362 expect(errorGroup.done, completes); 362 expect(errorGroup.done, completes);
363 363
364 controller1..add('value1.1')..add('value1.2')..close(); 364 controller1..add('value1.1')..add('value1.2')..close();
365 controller2..add('value2.1')..add('value2.2')..close(); 365 controller2..add('value2.1')..add('value2.2')..close();
366 }); 366 });
367 367
368 test("shouldn't throw a top-level exception if a stream receives an error " 368 test("shouldn't throw a top-level exception if a stream receives an error "
369 "after the other listened stream completes", () { 369 "after the other listened stream completes", () {
370 expect(stream1.toList(), completion(equals(['value1', 'value2']))); 370 expect(stream1.toList(), completion(equals(['value1', 'value2'])));
371 controller1..add('value1')..add('value2')..close(); 371 controller1..add('value1')..add('value2')..close();
372 372
373 expect(stream1.toList().then((_) { 373 expect(stream1.toList().then((_) {
374 // shouldn't cause a top-level exception 374 // shouldn't cause a top-level exception
375 controller2.signalError(new AsyncError(new FormatException())); 375 controller2.addError(new AsyncError(new FormatException()));
376 }), completes); 376 }), completes);
377 }); 377 });
378 378
379 test("shouldn't throw a top-level exception if an error is signaled after " 379 test("shouldn't throw a top-level exception if an error is signaled after "
380 "one listened stream completes", () { 380 "one listened stream completes", () {
381 expect(stream1.toList(), completion(equals(['value1', 'value2']))); 381 expect(stream1.toList(), completion(equals(['value1', 'value2'])));
382 controller1..add('value1')..add('value2')..close(); 382 controller1..add('value1')..add('value2')..close();
383 383
384 expect(stream1.toList().then((_) { 384 expect(stream1.toList().then((_) {
385 // shouldn't cause a top-level exception 385 // shouldn't cause a top-level exception
(...skipping 14 matching lines...) Expand all
400 stream = errorGroup.registerStream(controller.stream); 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.addError(new AsyncError(new FormatException()));
411 }); 411 });
412 412
413 test("should pipe exceptions from the future to the stream", () { 413 test("should pipe exceptions from the future to the stream", () {
414 expect(stream.first, throwsFormatException); 414 expect(stream.first, throwsFormatException);
415 expect(future, throwsFormatException); 415 expect(future, throwsFormatException);
416 expect(errorGroup.done, throwsFormatException); 416 expect(errorGroup.done, throwsFormatException);
417 417
418 completer.completeError(new FormatException()); 418 completer.completeError(new FormatException());
419 }); 419 });
420 420
421 test("the stream and the future should be able to complete/emit values " 421 test("the stream and the future should be able to complete/emit values "
422 "independently", () { 422 "independently", () {
423 expect(stream.toList(), completion(equals(['value1.1', 'value1.2']))); 423 expect(stream.toList(), completion(equals(['value1.1', 'value1.2'])));
424 expect(future, completion(equals('value2.0'))); 424 expect(future, completion(equals('value2.0')));
425 expect(errorGroup.done, completes); 425 expect(errorGroup.done, completes);
426 426
427 controller..add('value1.1')..add('value1.2')..close(); 427 controller..add('value1.1')..add('value1.2')..close();
428 completer.complete('value2.0'); 428 completer.complete('value2.0');
429 }); 429 });
430 430
431 test("shouldn't throw a top-level exception if the stream receives an error " 431 test("shouldn't throw a top-level exception if the stream receives an error "
432 "after the listened future completes", () { 432 "after the listened future completes", () {
433 expect(future, completion(equals('value'))); 433 expect(future, completion(equals('value')));
434 completer.complete('value'); 434 completer.complete('value');
435 435
436 expect(future.then((_) { 436 expect(future.then((_) {
437 // shouldn't cause a top-level exception 437 // shouldn't cause a top-level exception
438 controller.signalError(new AsyncError(new FormatException())); 438 controller.addError(new AsyncError(new FormatException()));
439 }), completes); 439 }), completes);
440 }); 440 });
441 441
442 test("shouldn't throw a top-level exception if the future receives an " 442 test("shouldn't throw a top-level exception if the future receives an "
443 "error after the listened stream completes", () { 443 "error after the listened stream completes", () {
444 expect(stream.toList(), completion(equals(['value1', 'value2']))); 444 expect(stream.toList(), completion(equals(['value1', 'value2'])));
445 controller..add('value1')..add('value2')..close(); 445 controller..add('value1')..add('value2')..close();
446 446
447 expect(stream.toList().then((_) { 447 expect(stream.toList().then((_) {
448 // shouldn't cause a top-level exception 448 // shouldn't cause a top-level exception
449 completer.completeError(new FormatException()); 449 completer.completeError(new FormatException());
450 }), completes); 450 }), completes);
451 }); 451 });
452 }); 452 });
453 } 453 }
OLDNEW
« sdk/lib/_internal/compiler/compiler.dart ('K') | « utils/pub/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698