| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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 // VMOptions=--enable_async |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 expectThenValue(future, value) { |
| 12 Expect.isTrue(future is Future); |
| 13 future.then((result) { |
| 14 Expect.equals(value, result); |
| 15 }); |
| 16 } |
| 17 |
| 18 asyncIf(condition) async { |
| 19 if(condition) { |
| 20 return 1; |
| 21 } else { |
| 22 return 2; |
| 23 } |
| 24 return 3; |
| 25 } |
| 26 |
| 27 asyncFor(condition) async { |
| 28 for (int i = 0; i < 10; i++) { |
| 29 if (i == 5 && condition) { |
| 30 return 1; |
| 31 } |
| 32 } |
| 33 return 2; |
| 34 } |
| 35 |
| 36 asyncTryCatchFinally(overrideInFinally, doThrow) async { |
| 37 try { |
| 38 if (doThrow) throw 444; |
| 39 return 1; |
| 40 } catch (e) { |
| 41 return e; |
| 42 } finally { |
| 43 if (overrideInFinally) return 3; |
| 44 } |
| 45 } |
| 46 |
| 47 asyncTryCatchLoop() async { |
| 48 var i = 0; |
| 49 var throws = 13; |
| 50 while (true) { |
| 51 try { |
| 52 throw throws; |
| 53 } catch (e) { |
| 54 if (i == throws) { return e; } |
| 55 } finally { |
| 56 i++; |
| 57 } |
| 58 } |
| 59 } |
| 60 |
| 61 asyncImplicitReturn() async { |
| 62 try {} |
| 63 catch (e) {} |
| 64 finally {} |
| 65 } |
| 66 |
| 67 main() { |
| 68 var asyncReturn; |
| 69 |
| 70 asyncReturn = asyncIf(true); |
| 71 expectThenValue(asyncReturn, 1); |
| 72 asyncReturn = asyncIf(false); |
| 73 expectThenValue(asyncReturn, 2); |
| 74 |
| 75 asyncReturn = asyncFor(true); |
| 76 expectThenValue(asyncReturn, 1); |
| 77 asyncReturn = asyncFor(false); |
| 78 expectThenValue(asyncReturn, 2); |
| 79 |
| 80 asyncReturn = asyncTryCatchFinally(true, false); |
| 81 expectThenValue(asyncReturn, 3); |
| 82 asyncReturn = asyncTryCatchFinally(false, false); |
| 83 expectThenValue(asyncReturn, 1); |
| 84 asyncReturn = asyncTryCatchFinally(true, true); |
| 85 expectThenValue(asyncReturn, 3); |
| 86 asyncReturn = asyncTryCatchFinally(false, true); |
| 87 expectThenValue(asyncReturn, 444); |
| 88 asyncReturn = asyncTryCatchLoop(); |
| 89 expectThenValue(asyncReturn, 13); |
| 90 |
| 91 asyncReturn = asyncImplicitReturn(); |
| 92 expectThenValue(asyncReturn, null); |
| 93 } |
| OLD | NEW |