OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 5 |
6 | |
7 import 'dart:async'; | 6 import 'dart:async'; |
8 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
9 | 8 |
10 later(vodka) => new Future.value(vodka); | 9 later(vodka) => new Future.value(vodka); |
11 | 10 |
12 manana(tequila) async => tequila; | 11 manana(tequila) async => tequila; |
13 | 12 |
14 // Regression test for issue 21536. | 13 // Regression test for issue 21536. |
15 testNestedFunctions() async { | 14 testNestedFunctions() async { |
16 var a = await later('Asterix').then((tonic) { | 15 var a = await later('Asterix').then((tonic) { |
17 return later(tonic); | 16 return later(tonic); |
18 }); | 17 }); |
19 var o = await manana('Obelix').then(manana); | 18 var o = await manana('Obelix').then(manana); |
20 Expect.equals("$a and $o", "Asterix and Obelix"); | 19 Expect.equals("$a and $o", "Asterix and Obelix"); |
21 } | 20 } |
22 | 21 |
23 addLater({a, b}) => new Future.value(a + b); | 22 addLater({a, b}) => new Future.value(a + b); |
24 | 23 |
25 // Regression test for issue 21480. | 24 // Regression test for issue 21480. |
26 testNamedArguments() async { | 25 testNamedArguments() async { |
27 var sum = await addLater(a:5, b:10); | 26 var sum = await addLater(a: 5, b: 10); |
28 Expect.equals(sum, 15); | 27 Expect.equals(sum, 15); |
29 sum = await addLater(b:11, a:-11); | 28 sum = await addLater(b: 11, a: -11); |
30 Expect.equals(sum, 0); | 29 Expect.equals(sum, 0); |
31 } | 30 } |
32 | 31 |
33 testSideEffects() async { | 32 testSideEffects() async { |
34 Future foo(int a1, int a2) { | 33 Future foo(int a1, int a2) { |
35 Expect.equals(10, a1); | 34 Expect.equals(10, a1); |
36 Expect.equals(11, a2); | 35 Expect.equals(11, a2); |
37 return new Future.value(); | 36 return new Future.value(); |
38 } | 37 } |
| 38 |
39 int a = 10; | 39 int a = 10; |
40 await foo(a++, a++); | 40 await foo(a++, a++); |
41 Expect.equals(12, a); | 41 Expect.equals(12, a); |
42 } | 42 } |
43 | 43 |
44 main() async { | 44 main() async { |
45 testNestedFunctions(); | 45 testNestedFunctions(); |
46 testNamedArguments(); | 46 testNamedArguments(); |
47 testSideEffects(); | 47 testSideEffects(); |
48 } | 48 } |
OLD | NEW |