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

Side by Side Diff: tests/corelib/src/PromiseTest.dart

Issue 9401030: remove promise from corelib (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 8 years, 10 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class PromiseTest {
6
7 static void testMain() {
8 testNormalComplete();
9 testFromValue();
10 testNormalCompleteWithHandler();
11 testNormalCompleteManyHandlers();
12 testError();
13 testErrorWithHandler();
14 testCancel();
15 testCancelWithHandler();
16 testChainComplete();
17 testChainError();
18 testChainCancel();
19 testFlatten();
20 testJoinSelectSecond();
21 testWaitFor1();
22 testWaitForAll();
23 }
24
25 static void testNormalComplete() {
26 Promise<int> a = new Promise<int>();
27 Expect.equals(false, a.isDone());
28 Expect.equals(false, a.hasValue());
29 Expect.equals(false, a.hasError());
30 Expect.equals(false, a.isCancelled());
31
32 readValueThrowsException_(a);
33 readErrorThrowsException_(a);
34 a.complete(3);
35 Expect.equals(true, a.isDone());
36 Expect.equals(true, a.hasValue());
37 Expect.equals(false, a.hasError());
38 Expect.equals(false, a.isCancelled());
39 Expect.equals(3, a.value);
40 Expect.equals(null, a.error);
41 }
42
43 static void testFromValue() {
44 Promise<int> a = new Promise<int>.fromValue(3);
45 Expect.equals(true, a.isDone());
46 Expect.equals(false, a.isCancelled());
47 Expect.equals(true, a.hasValue());
48 Expect.equals(false, a.hasError());
49 Expect.equals(false, a.isCancelled());
50 Expect.equals(3, a.value);
51 Expect.equals(null, a.error);
52 }
53
54 static void testNormalCompleteWithHandler() {
55 Promise<int> a = new Promise<int>();
56 Promise<int> b = new Promise<int>();
57 Expect.equals(false, a.isDone());
58 Expect.equals(false, a.hasValue());
59 Expect.equals(false, a.hasError());
60 Expect.equals(false, a.isCancelled());
61 Expect.equals(false, b.isDone());
62 Expect.equals(false, b.hasValue());
63 Expect.equals(false, b.hasError());
64 Expect.equals(false, b.isCancelled());
65 readValueThrowsException_(a);
66 readErrorThrowsException_(a);
67 readValueThrowsException_(b);
68 readErrorThrowsException_(b);
69 int afterA = null;
70 int afterB = null;
71
72 // value computed after setup is done.
73 a.addCompleteHandler((int v) { afterA = v; });
74 a.complete(3);
75
76 // value computed before setup was done.
77 b.complete(4);
78 b.addCompleteHandler((int v) { afterB = v; });
79
80 Expect.equals(true, a.isDone());
81 Expect.equals(true, a.hasValue());
82 Expect.equals(false, a.hasError());
83 Expect.equals(false, a.isCancelled());
84 Expect.equals(true, b.isDone());
85 Expect.equals(true, b.hasValue());
86 Expect.equals(false, b.hasError());
87 Expect.equals(false, b.isCancelled());
88 Expect.equals(null, a.error);
89 Expect.equals(null, b.error);
90
91 Expect.equals(3, a.value);
92 Expect.equals(4, b.value);
93 Expect.equals(3, afterA);
94 Expect.equals(4, afterB);
95 }
96
97 static void testNormalCompleteManyHandlers() {
98 Promise<int> a = new Promise<int>();
99 Expect.equals(false, a.isDone());
100 Expect.equals(false, a.hasValue());
101 Expect.equals(false, a.hasError());
102 Expect.equals(false, a.isCancelled());
103 readValueThrowsException_(a);
104 readErrorThrowsException_(a);
105 int afterA1 = null;
106 int afterA2 = null;
107 int afterA3 = null;
108
109 // value computed after setup is done.
110 a.addCompleteHandler((int v) { afterA1 = v; });
111 a.complete(3);
112 a.addCompleteHandler((int v) { afterA2 = v; });
113 a.addCompleteHandler((int v) { afterA3 = v; });
114
115 Expect.equals(true, a.isDone());
116 Expect.equals(true, a.hasValue());
117 Expect.equals(false, a.hasError());
118 Expect.equals(false, a.isCancelled());
119 Expect.equals(null, a.error);
120 Expect.equals(3, a.value);
121 Expect.equals(3, afterA1);
122 Expect.equals(3, afterA2);
123 Expect.equals(3, afterA3);
124 }
125
126 static void testError() {
127 Promise<int> a = new Promise<int>();
128 Expect.equals(false, a.isDone());
129 Expect.equals(false, a.hasValue());
130 Expect.equals(false, a.hasError());
131 Expect.equals(false, a.isCancelled());
132 readValueThrowsException_(a);
133 readErrorThrowsException_(a);
134 a.fail("Err");
135 Expect.equals(true, a.isDone());
136 Expect.equals(false, a.hasValue());
137 Expect.equals(true, a.hasError());
138 Expect.equals(false, a.isCancelled());
139 Expect.equals("Err", a.error);
140 readValueThrowsException_(a, a.error);
141 }
142
143 static void testErrorWithHandler() {
144 Promise<int> a = new Promise<int>();
145 Promise<int> b = new Promise<int>();
146 Expect.equals(false, a.isDone());
147 Expect.equals(false, a.hasValue());
148 Expect.equals(false, a.hasError());
149 Expect.equals(false, a.isCancelled());
150 Expect.equals(false, b.isDone());
151 Expect.equals(false, b.hasValue());
152 Expect.equals(false, b.hasError());
153 Expect.equals(false, b.isCancelled());
154 readValueThrowsException_(a);
155 readErrorThrowsException_(a);
156 readValueThrowsException_(b);
157 readErrorThrowsException_(b);
158 String afterA = null;
159 String afterB = null;
160
161 // error after set up is done
162 a.addErrorHandler((v) { afterA = v; });
163 a.fail("ErrA");
164
165 // error before setup is done
166 b.fail("ErrB");
167 b.addErrorHandler((v) { afterB = v; });
168
169 Expect.equals(true, a.isDone());
170 Expect.equals(false, a.hasValue());
171 Expect.equals(true, a.hasError());
172 Expect.equals(false, a.isCancelled());
173
174 Expect.equals(true, b.isDone());
175 Expect.equals(false, b.hasValue());
176 Expect.equals(true, b.hasError());
177 Expect.equals(false, b.isCancelled());
178
179 Expect.equals("ErrA", a.error);
180 Expect.equals("ErrB", b.error);
181 Expect.equals("ErrA", afterA);
182 Expect.equals("ErrB", afterB);
183
184 readValueThrowsException_(a, a.error);
185 readValueThrowsException_(b, b.error);
186 }
187
188 static void testCancel() {
189 Promise<int> a = new Promise<int>();
190 Expect.equals(false, a.isDone());
191 Expect.equals(false, a.hasValue());
192 Expect.equals(false, a.hasError());
193 Expect.equals(false, a.isCancelled());
194
195 readValueThrowsException_(a);
196 readErrorThrowsException_(a);
197 a.cancel();
198 Expect.equals(true, a.isDone());
199 Expect.equals(false, a.hasValue());
200 Expect.equals(false, a.hasError());
201 Expect.equals(true, a.isCancelled());
202 Expect.equals(null, a.value);
203 Expect.equals(null, a.error);
204 }
205
206 static void testCancelWithHandler() {
207 Promise<int> a = new Promise<int>();
208 Promise<int> b = new Promise<int>();
209 Expect.equals(false, a.isDone());
210 Expect.equals(false, a.hasValue());
211 Expect.equals(false, a.hasError());
212 Expect.equals(false, a.isCancelled());
213 Expect.equals(false, b.isDone());
214 Expect.equals(false, b.hasValue());
215 Expect.equals(false, b.hasError());
216 Expect.equals(false, b.isCancelled());
217 readValueThrowsException_(a);
218 readErrorThrowsException_(a);
219 readValueThrowsException_(b);
220 readErrorThrowsException_(b);
221 bool aCancel = false;
222 bool bCancel = false;
223
224 // cancel after setup
225 a.addCancelHandler(() { aCancel = true; });
226 a.cancel();
227
228 // cancel before setup is done
229 b.cancel();
230 b.addCancelHandler(() { bCancel = true; });
231
232 Expect.equals(true, a.isDone());
233 Expect.equals(false, a.hasValue());
234 Expect.equals(false, a.hasError());
235 Expect.equals(true, a.isCancelled());
236 Expect.equals(true, b.isDone());
237 Expect.equals(false, b.hasValue());
238 Expect.equals(false, b.hasError());
239 Expect.equals(true, b.isCancelled());
240 Expect.equals(null, a.value);
241 Expect.equals(null, b.value);
242 Expect.equals(null, a.error);
243 Expect.equals(null, b.error);
244 Expect.equals(true, aCancel);
245 Expect.equals(true, bCancel);
246
247 Promise<int> c = new Promise<int>();
248 bool cCancel = false;
249 c.cancel();
250 c.complete(3);
251 c.addCancelHandler(() { cCancel = true; });
252 Expect.equals(true, cCancel);
253 Expect.equals(true, c.isDone());
254 Expect.equals(true, c.hasValue());
255 Expect.equals(false, c.hasError());
256 Expect.equals(true, c.isCancelled());
257
258 Promise<int> d = new Promise<int>();
259 bool dCancel = false;
260 d.cancel();
261 d.fail("fail");
262 d.addCancelHandler(() { dCancel = true; });
263 Expect.equals(true, dCancel);
264 Expect.equals(true, d.isDone());
265 Expect.equals(false, d.hasValue());
266 Expect.equals(true, d.hasError());
267 Expect.equals(true, d.isCancelled());
268 }
269
270 static void testChainComplete() {
271 Promise<int> a = new Promise<int>();
272 Promise<int> b = a.then((int ares) => ares + 1);
273 Expect.equals(false, a.isDone());
274 Expect.equals(false, a.hasValue());
275 Expect.equals(false, a.hasError());
276 Expect.equals(false, a.isCancelled());
277 Expect.equals(false, b.isDone());
278 Expect.equals(false, b.hasValue());
279 Expect.equals(false, b.hasError());
280 Expect.equals(false, b.isCancelled());
281 readValueThrowsException_(a);
282 readErrorThrowsException_(a);
283 readValueThrowsException_(b);
284 readErrorThrowsException_(b);
285 int resA = null;
286 a.addCompleteHandler((int v) { resA = v; });
287 int resB = null;
288 b.addCompleteHandler((int v) { resB = v; });
289
290 a.complete(3);
291
292 Expect.equals(true, a.isDone());
293 Expect.equals(true, a.hasValue());
294 Expect.equals(false, a.hasError());
295 Expect.equals(false, a.isCancelled());
296
297 Expect.equals(true, b.isDone());
298 Expect.equals(true, b.hasValue());
299 Expect.equals(false, b.hasError());
300 Expect.equals(false, b.isCancelled());
301
302 Expect.equals(3, a.value);
303 Expect.equals(4, b.value);
304 Expect.equals(null, a.error);
305 Expect.equals(null, b.error);
306 Expect.equals(3, resA);
307 Expect.equals(4, resB);
308 }
309
310 static void testChainError() {
311 Promise<int> a = new Promise<int>();
312 Promise<int> b = a.then((int ares) => ares + 1);
313 Expect.equals(false, a.isDone());
314 Expect.equals(false, a.hasValue());
315 Expect.equals(false, a.hasError());
316 Expect.equals(false, a.isCancelled());
317 Expect.equals(false, b.isDone());
318 Expect.equals(false, b.hasValue());
319 Expect.equals(false, b.hasError());
320 Expect.equals(false, b.isCancelled());
321 readValueThrowsException_(a);
322 readErrorThrowsException_(a);
323 readValueThrowsException_(b);
324 readErrorThrowsException_(b);
325 String errA = null;
326 a.addErrorHandler((e) { errA = e; });
327 String errB = null;
328 b.addErrorHandler((e) { errB = e; });
329
330 a.fail("err-from-a");
331
332 Expect.equals(true, a.isDone());
333 Expect.equals(false, a.hasValue());
334 Expect.equals(true, a.hasError());
335 Expect.equals(false, a.isCancelled());
336 Expect.equals(true, b.isDone());
337 Expect.equals(false, b.hasValue());
338 Expect.equals(true, b.hasError());
339 Expect.equals(false, b.isCancelled());
340
341 Expect.equals("err-from-a", a.error);
342 Expect.equals("err-from-a", b.error);
343 Expect.equals("err-from-a", errA);
344 Expect.equals("err-from-a", errB);
345
346 readValueThrowsException_(a, a.error);
347 readValueThrowsException_(b, b.error);
348 }
349
350 static void testChainCancel() {
351 Promise<int> a = new Promise<int>();
352 Promise<int> b = a.then((int ares) => ares + 1);
353 Expect.equals(false, a.isDone());
354 Expect.equals(false, a.hasValue());
355 Expect.equals(false, a.hasError());
356 Expect.equals(false, a.isCancelled());
357 Expect.equals(false, b.isDone());
358 Expect.equals(false, b.hasValue());
359 Expect.equals(false, b.hasError());
360 Expect.equals(false, b.isCancelled());
361 readValueThrowsException_(a);
362 readErrorThrowsException_(a);
363 readValueThrowsException_(b);
364 readErrorThrowsException_(b);
365 bool bCancel = false;
366 b.addCancelHandler(() { bCancel = true; });
367 bool bError = false;
368 b.addErrorHandler((e) { bError = true; });
369 bool aCancel = false;
370 a.addCancelHandler(() { aCancel = true; });
371
372 a.cancel();
373
374 Expect.equals(true, a.isDone());
375 Expect.equals(false, a.hasValue());
376 Expect.equals(false, a.hasError());
377 Expect.equals(true, a.isCancelled());
378 Expect.equals(true, b.isDone());
379 Expect.equals(false, b.hasValue());
380 Expect.equals(true, b.hasError());
381 Expect.equals(false, b.isCancelled());
382 Expect.equals(null, a.value);
383 Expect.equals(null, a.error);
384 Expect.equals("Source promise was cancelled", b.error);
385 readValueThrowsException_(b, b.error);
386 Expect.equals(false, bCancel);
387 Expect.equals(true, bError);
388 Expect.equals(true, aCancel);
389 }
390
391 static void testFlatten() {
392 Promise<int> a = new Promise<int>();
393 Promise<Promise<int>> b = new Promise<Promise<int>>();
394 Promise<Promise<Promise<int>>> c = new Promise<Promise<Promise<int>>>();
395 Promise<Promise<Promise<Promise<int>>>> d =
396 new Promise<Promise<Promise<Promise<int>>>>();
397 Promise<int> flat = d.flatten();
398
399 Expect.equals(false, a.isDone());
400 Expect.equals(false, b.isDone());
401 Expect.equals(false, c.isDone());
402 Expect.equals(false, d.isDone());
403 Expect.equals(false, flat.isDone());
404 readValueThrowsException_(a);
405 readValueThrowsException_(b);
406 readValueThrowsException_(c);
407 readValueThrowsException_(d);
408 readValueThrowsException_(flat);
409
410 b.complete(a);
411
412 Expect.equals(false, a.isDone());
413 Expect.equals(true, b.isDone());
414 Expect.equals(false, c.isDone());
415 Expect.equals(false, d.isDone());
416 Expect.equals(false, flat.isDone());
417 readValueThrowsException_(a);
418 Expect.equals(a, b.value);
419 readValueThrowsException_(c);
420 readValueThrowsException_(d);
421 readValueThrowsException_(flat);
422
423 d.complete(c);
424
425 Expect.equals(false, a.isDone());
426 Expect.equals(true, b.isDone());
427 Expect.equals(false, c.isDone());
428 Expect.equals(true, d.isDone());
429 Expect.equals(false, flat.isDone());
430 readValueThrowsException_(a);
431 Expect.equals(a, b.value);
432 readValueThrowsException_(c);
433 Expect.equals(c, d.value);
434 readValueThrowsException_(flat);
435
436 a.complete(2);
437
438 Expect.equals(true, a.isDone());
439 Expect.equals(true, b.isDone());
440 Expect.equals(false, c.isDone());
441 Expect.equals(true, d.isDone());
442 Expect.equals(false, flat.isDone());
443 Expect.equals(2, a.value);
444 Expect.equals(a, b.value);
445 readValueThrowsException_(c);
446 Expect.equals(c, d.value);
447 readValueThrowsException_(flat);
448
449 c.complete(b);
450
451 Expect.equals(true, a.isDone());
452 Expect.equals(true, b.isDone());
453 Expect.equals(true, c.isDone());
454 Expect.equals(true, d.isDone());
455 Expect.equals(true, flat.isDone());
456 Expect.equals(2, a.value);
457 Expect.equals(a, b.value);
458 Expect.equals(b, c.value);
459 Expect.equals(c, d.value);
460 Expect.equals(2, flat.value);
461 }
462
463 static void testJoinSelectSecond() {
464 Promise<int> a = new Promise<int>();
465 Promise<int> b = new Promise<int>();
466 Promise<int> c = new Promise<int>();
467 Promise<int> second = new Promise<int>();
468 bool first = true;
469 second.join([a, b, c], (p) {
470 if (first == true) {
471 first = false;
472 return false;
473 } else {
474 return true;
475 }
476 });
477
478 Expect.equals(false, a.isDone());
479 Expect.equals(false, b.isDone());
480 Expect.equals(false, c.isDone());
481 readValueThrowsException_(a);
482 readErrorThrowsException_(a);
483 readValueThrowsException_(b);
484 readErrorThrowsException_(b);
485 readValueThrowsException_(c);
486 readErrorThrowsException_(c);
487 Expect.equals(false, second.isDone());
488 readValueThrowsException_(second);
489 readErrorThrowsException_(second);
490
491 b.complete(2);
492
493 Expect.equals(false, a.isDone());
494 Expect.equals(true, b.isDone());
495 Expect.equals(false, c.isDone());
496 readValueThrowsException_(a);
497 readErrorThrowsException_(a);
498 Expect.equals(2, b.value);
499 Expect.equals(null, b.error);
500 readValueThrowsException_(c);
501 readErrorThrowsException_(c);
502 Expect.equals(false, second.isDone());
503 readValueThrowsException_(second);
504 readErrorThrowsException_(second);
505
506 c.complete(3);
507
508 Expect.equals(true, second.isDone());
509 Expect.equals(false, a.isDone());
510 Expect.equals(true, b.isDone());
511 Expect.equals(true, c.isDone());
512
513 readValueThrowsException_(a);
514 readErrorThrowsException_(a);
515 Expect.equals(2, b.value);
516 Expect.equals(null, b.error);
517 Expect.equals(3, c.value);
518 Expect.equals(null, c.error);
519 Expect.equals(3, second.value);
520 }
521
522 static void testWaitFor1() {
523 Promise<int> a = new Promise<int>();
524 Promise<int> b = new Promise<int>();
525 Promise<int> c = new Promise<int>();
526 Promise<int> first = new Promise<int>();
527 first.waitFor([a, b, c], 1);
528
529 Expect.equals(false, a.isDone());
530 Expect.equals(false, a.hasValue());
531 Expect.equals(false, a.hasError());
532 Expect.equals(false, a.isCancelled());
533 Expect.equals(false, b.isDone());
534 Expect.equals(false, b.hasValue());
535 Expect.equals(false, b.hasError());
536 Expect.equals(false, b.isCancelled());
537 Expect.equals(false, c.isDone());
538 Expect.equals(false, c.hasValue());
539 Expect.equals(false, c.hasError());
540 Expect.equals(false, c.isCancelled());
541 readValueThrowsException_(a);
542 readErrorThrowsException_(a);
543 readValueThrowsException_(b);
544 readErrorThrowsException_(b);
545 readValueThrowsException_(c);
546 readErrorThrowsException_(c);
547 Expect.equals(false, first.isDone());
548
549 b.complete(2);
550
551 // a & c got cancelled
552 Expect.equals(true, first.isDone());
553 Expect.equals(true, first.hasValue());
554 Expect.equals(false, first.hasError());
555 Expect.equals(false, first.isCancelled());
556 Expect.equals(true, a.isDone());
557 Expect.equals(false, a.hasValue());
558 Expect.equals(false, a.hasError());
559 Expect.equals(true, a.isCancelled());
560 Expect.equals(true, b.isDone());
561 Expect.equals(true, b.hasValue());
562 Expect.equals(false, b.hasError());
563 Expect.equals(false, b.isCancelled());
564 Expect.equals(true, c.isDone());
565 Expect.equals(false, c.hasValue());
566 Expect.equals(false, c.hasError());
567 Expect.equals(true, c.isCancelled());
568
569 Expect.equals(null, a.value);
570 Expect.equals(2, b.value);
571 Expect.equals(null, c.value);
572 Expect.equals(null, a.error);
573 Expect.equals(null, b.error);
574 Expect.equals(null, c.error);
575 Expect.equals(2, first.value);
576 }
577
578 static void testWaitForAll() {
579 Promise<int> a = new Promise<int>();
580 Promise<int> b = new Promise<int>();
581 Promise<int> c = new Promise<int>();
582 Promise<int> all = new Promise<int>();
583 all.waitFor([a, b, c], 3);
584
585 Expect.equals(false, a.isDone());
586 Expect.equals(false, a.hasValue());
587 Expect.equals(false, a.hasError());
588 Expect.equals(false, a.isCancelled());
589 Expect.equals(false, b.isDone());
590 Expect.equals(false, b.hasValue());
591 Expect.equals(false, b.hasError());
592 Expect.equals(false, b.isCancelled());
593 Expect.equals(false, c.isDone());
594 Expect.equals(false, c.hasValue());
595 Expect.equals(false, c.hasError());
596 Expect.equals(false, c.isCancelled());
597 Expect.equals(false, all.isDone());
598 Expect.equals(false, all.hasValue());
599 Expect.equals(false, all.hasError());
600 Expect.equals(false, all.isCancelled());
601 readValueThrowsException_(a);
602 readErrorThrowsException_(a);
603 readValueThrowsException_(b);
604 readErrorThrowsException_(b);
605 readValueThrowsException_(c);
606 readErrorThrowsException_(c);
607 readValueThrowsException_(all);
608 readErrorThrowsException_(all);
609
610 b.complete(2);
611
612 Expect.equals(false, a.isDone());
613 Expect.equals(false, a.hasValue());
614 Expect.equals(false, a.hasError());
615 Expect.equals(false, a.isCancelled());
616 Expect.equals(true, b.isDone());
617 Expect.equals(true, b.hasValue());
618 Expect.equals(false, b.hasError());
619 Expect.equals(false, b.isCancelled());
620 Expect.equals(false, c.isDone());
621 Expect.equals(false, c.hasValue());
622 Expect.equals(false, c.hasError());
623 Expect.equals(false, c.isCancelled());
624 Expect.equals(false, all.isDone());
625 Expect.equals(false, all.hasValue());
626 Expect.equals(false, all.hasError());
627 Expect.equals(false, all.isCancelled());
628
629 readValueThrowsException_(a);
630 readErrorThrowsException_(a);
631 Expect.equals(2, b.value);
632 Expect.equals(null, b.error);
633 readValueThrowsException_(c);
634 readErrorThrowsException_(c);
635 readValueThrowsException_(all);
636 readErrorThrowsException_(all);
637
638 c.complete(3);
639
640 Expect.equals(false, a.isDone());
641 Expect.equals(false, a.hasValue());
642 Expect.equals(false, a.hasError());
643 Expect.equals(false, a.isCancelled());
644 Expect.equals(true, b.isDone());
645 Expect.equals(true, b.hasValue());
646 Expect.equals(false, b.hasError());
647 Expect.equals(false, b.isCancelled());
648 Expect.equals(true, c.isDone());
649 Expect.equals(true, c.hasValue());
650 Expect.equals(false, c.hasError());
651 Expect.equals(false, c.isCancelled());
652 Expect.equals(false, all.isDone());
653 Expect.equals(false, all.hasValue());
654 Expect.equals(false, all.hasError());
655 Expect.equals(false, all.isCancelled());
656
657 readValueThrowsException_(a);
658 readErrorThrowsException_(a);
659 Expect.equals(2, b.value);
660 Expect.equals(null, b.error);
661 Expect.equals(3, c.value);
662 Expect.equals(null, c.error);
663 readValueThrowsException_(all);
664 readErrorThrowsException_(all);
665
666 a.complete(1);
667
668 Expect.equals(true, a.isDone());
669 Expect.equals(true, a.hasValue());
670 Expect.equals(false, a.hasError());
671 Expect.equals(false, a.isCancelled());
672 Expect.equals(true, b.isDone());
673 Expect.equals(true, b.hasValue());
674 Expect.equals(false, b.hasError());
675 Expect.equals(false, b.isCancelled());
676 Expect.equals(true, c.isDone());
677 Expect.equals(true, c.hasValue());
678 Expect.equals(false, c.hasError());
679 Expect.equals(false, c.isCancelled());
680 Expect.equals(true, all.isDone());
681 Expect.equals(true, all.hasValue());
682 Expect.equals(false, all.hasError());
683 Expect.equals(false, all.isCancelled());
684
685 Expect.equals(1, a.value);
686 Expect.equals(null, a.error);
687 Expect.equals(2, b.value);
688 Expect.equals(null, b.error);
689 Expect.equals(3, c.value);
690 Expect.equals(null, c.error);
691 Expect.equals(1, all.value);
692 Expect.equals(null, all.error);
693 }
694
695 static void readValueThrowsException_(Promise p, [var error = null]) {
696 bool errorFound = false;
697 try {
698 var x = p.value;
699 } catch (var e) {
700 errorFound = true;
701 if (error !== null) {
702 Expect.equals(true, error === e);
703 }
704 }
705 Expect.equals(true, errorFound);
706 }
707
708 static void readErrorThrowsException_(Promise p) {
709 bool errorFound = false;
710 try {
711 var x = p.error;
712 } catch (var e) {
713 errorFound = true;
714 }
715 Expect.equals(true, errorFound);
716 }
717 }
718
719 main() {
720 PromiseTest.testMain();
721 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698