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

Side by Side Diff: pkg/scheduled_test/test/value_future_test.dart

Issue 12377093: Add a ScheduledProcess class to pkg/scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library value_future_test;
6
7 import 'dart:async';
8
9 import 'package:scheduled_test/src/value_future.dart';
10 import 'package:unittest/unittest.dart';
11
12 void main() {
13 group('works like a normal Future for', () {
14 var completer;
15 var future;
16
17 setUp(() {
18 completer = new Completer();
19 future = new ValueFuture(completer.future);
20 });
21
22 test('.asStream on success', () {
23 expect(future.asStream().toList(), completion(equals(['success'])));
24 completer.complete('success');
25 });
26
27 test('.asStream on error', () {
28 expect(future.asStream().toList(), throwsA(equals('error')));
29 completer.completeError('error');
30 });
31
32 test('.then and .catchError on success', () {
33 expect(future.then((v) => "transformed $v")
34 .catchError((e) => "caught ${e.error}"),
35 completion(equals('transformed success')));
36 completer.complete('success');
37 });
38
39 test('.then and .catchError on error', () {
40 expect(future.then((v) => "transformed $v")
41 .catchError((e) => "caught ${e.error}"),
42 completion(equals('caught error')));
43 completer.completeError('error');
44 });
45
46 test('.then with onError on success', () {
47 expect(future.then((v) => "transformed $v",
48 onError: (e) => "caught ${e.error}"),
49 completion(equals('transformed success')));
50 completer.complete('success');
51 });
52
53 test('.then with onError on error', () {
54 expect(future.then((v) => "transformed $v",
55 onError: (e) => "caught ${e.error}"),
56 completion(equals('caught error')));
57 completer.completeError('error');
58 });
59
60 test('.whenComplete on success', () {
61 expect(future.whenComplete(() {
62 throw 'whenComplete';
63 }), throwsA(equals('whenComplete')));
64 completer.complete('success');
65 });
66
67 test('.whenComplete on error', () {
68 expect(future.whenComplete(() {
69 throw 'whenComplete';
70 }), throwsA(equals('whenComplete')));
71 completer.completeError('error');
72 });
73 });
74
75 group('before completion', () {
76 var future;
77
78 setUp(() {
79 future = new ValueFuture(new Completer().future);
80 });
81
82 test('.value is null', () {
83 expect(future.value, isNull);
84 });
85
86 test('.hasValue is false', () {
87 expect(future.hasValue, isFalse);
88 });
89 });
90
91 group('after successful completion', () {
92 var future;
93
94 setUp(() {
95 var completer = new Completer();
96 future = new ValueFuture(completer.future);
97 completer.complete(12);
98 });
99
100 test('.value is the result of the future', () {
101 expect(future.value, equals(12));
102 });
103
104 test('.hasValue is true', () {
105 expect(future.hasValue, isTrue);
106 });
107 });
108
109 group('after an error completion', () {
110 var future;
111
112 setUp(() {
113 var completer = new Completer();
114 future = new ValueFuture(completer.future);
115 future.catchError((e) {});
116 completer.completeError('bad');
117 });
118
119 test('.value is null', () {
120 expect(future.value, isNull);
121 });
122
123 test('.hasValue is false', () {
124 expect(future.hasValue, isFalse);
125 });
126 });
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698