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 | |
6 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
7 | 6 |
8 import 'dart:async'; | 7 import 'dart:async'; |
9 | 8 |
10 topLevelFunction() async { } | 9 topLevelFunction() async {} |
11 | 10 |
12 Future<int> topLevelWithParameter(int a) async { | 11 Future<int> topLevelWithParameter(int a) async { |
13 return 7 + a; | 12 return 7 + a; |
14 } | 13 } |
15 | 14 |
16 topLevelWithParameterWrongType(int a) async { | 15 topLevelWithParameterWrongType(int a) async { |
17 return 7 + a; | 16 return 7 + a; |
18 } | 17 } |
19 | 18 |
20 var what = 'async getter'; | 19 var what = 'async getter'; |
21 Future<String> get topLevelGetter async { | 20 Future<String> get topLevelGetter async { |
22 return 'I want to be an ${what}'; | 21 return 'I want to be an ${what}'; |
23 } | 22 } |
24 | 23 |
25 class A { | 24 class A { |
26 static int staticVar = 1; | 25 static int staticVar = 1; |
27 | 26 |
28 static staticMethod(int param) async => staticVar + param; | 27 static staticMethod(int param) async => staticVar + param; |
29 static get staticGetter async => staticVar + 3; | 28 static get staticGetter async => staticVar + 3; |
30 | 29 |
31 int _x; | 30 int _x; |
32 A(this._x); | 31 A(this._x); |
33 | 32 |
34 operator+(A other) async { | 33 operator +(A other) async { |
35 return new A(_x + other._x); | 34 return new A(_x + other._x); |
36 } | 35 } |
37 | 36 |
38 get value => _x; | 37 get value => _x; |
39 } | 38 } |
40 | 39 |
41 class B { | 40 class B { |
42 final _y; | 41 final _y; |
43 const B._internal(this._y); | 42 const B._internal(this._y); |
44 | 43 |
45 B() : _y = null; | 44 B() : _y = null; |
46 } | 45 } |
47 | 46 |
48 | |
49 main() { | 47 main() { |
50 var asyncReturn; | 48 var asyncReturn; |
51 | 49 |
52 asyncReturn = topLevelFunction(); | 50 asyncReturn = topLevelFunction(); |
53 Expect.isTrue(asyncReturn is Future); | 51 Expect.isTrue(asyncReturn is Future); |
54 | 52 |
55 asyncReturn = topLevelWithParameter(4); | 53 asyncReturn = topLevelWithParameter(4); |
56 Expect.isTrue(asyncReturn is Future); | 54 Expect.isTrue(asyncReturn is Future); |
57 asyncReturn.then((int result) => Expect.equals(result, 11)); | 55 asyncReturn.then((int result) => Expect.equals(result, 11)); |
58 | 56 |
(...skipping 15 matching lines...) Expand all Loading... |
74 var b = new A(9); | 72 var b = new A(9); |
75 asyncReturn = a + b; | 73 asyncReturn = a + b; |
76 Expect.isTrue(asyncReturn is Future); | 74 Expect.isTrue(asyncReturn is Future); |
77 asyncReturn.then((A result) => Expect.equals(result.value, 22)); | 75 asyncReturn.then((A result) => Expect.equals(result.value, 22)); |
78 | 76 |
79 var foo = 17; | 77 var foo = 17; |
80 bar(int p1, p2) async { | 78 bar(int p1, p2) async { |
81 var z = 8; | 79 var z = 8; |
82 return p2 + z + foo; | 80 return p2 + z + foo; |
83 } | 81 } |
84 asyncReturn = bar(1,2); | 82 |
| 83 asyncReturn = bar(1, 2); |
85 Expect.isTrue(asyncReturn is Future); | 84 Expect.isTrue(asyncReturn is Future); |
86 asyncReturn.then((int result) => Expect.equals(result, 27)); | 85 asyncReturn.then((int result) => Expect.equals(result, 27)); |
87 | 86 |
88 var moreNesting = (int shadowP1, String p2, num p3) { | 87 var moreNesting = (int shadowP1, String p2, num p3) { |
89 var z = 3; | 88 var z = 3; |
90 aa(int shadowP1) async { | 89 aa(int shadowP1) async { |
91 return foo + z + p3 + shadowP1; | 90 return foo + z + p3 + shadowP1; |
92 } | 91 } |
| 92 |
93 return aa(6); | 93 return aa(6); |
94 }; | 94 }; |
95 asyncReturn = moreNesting(1, "ignore", 2); | 95 asyncReturn = moreNesting(1, "ignore", 2); |
96 Expect.isTrue(asyncReturn is Future); | 96 Expect.isTrue(asyncReturn is Future); |
97 asyncReturn.then((int result) => Expect.equals(result, 28)); | 97 asyncReturn.then((int result) => Expect.equals(result, 28)); |
98 | 98 |
99 var checkAsync = (var someFunc) { | 99 var checkAsync = (var someFunc) { |
100 var toTest = someFunc(); | 100 var toTest = someFunc(); |
101 Expect.isTrue(toTest is Future); | 101 Expect.isTrue(toTest is Future); |
102 toTest.then((int result) => Expect.equals(result, 4)); | 102 toTest.then((int result) => Expect.equals(result, 4)); |
103 }; | 103 }; |
104 checkAsync(() async => 4); | 104 checkAsync(() async => 4); |
105 } | 105 } |
OLD | NEW |