OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 closure0() { | 7 closure0() { |
8 var x = 499; | 8 var x = 499; |
9 var f = () { return x; }; | 9 var f = () { |
| 10 return x; |
| 11 }; |
10 Expect.equals(499, f()); | 12 Expect.equals(499, f()); |
11 } | 13 } |
12 | 14 |
13 class A { | 15 class A { |
14 closure1() { | 16 closure1() { |
15 var x = 499; | 17 var x = 499; |
16 var f = () { return x; }; | 18 var f = () { |
| 19 return x; |
| 20 }; |
17 Expect.equals(499, f()); | 21 Expect.equals(499, f()); |
18 } | 22 } |
19 } | 23 } |
20 | 24 |
21 applyFun(f) { | 25 applyFun(f) { |
22 return f(); | 26 return f(); |
23 } | 27 } |
24 | 28 |
25 closure2() { | 29 closure2() { |
26 var x = 499; | 30 var x = 499; |
27 Expect.equals(499, applyFun(() { return x; })); | 31 Expect.equals(499, applyFun(() { |
| 32 return x; |
| 33 })); |
28 } | 34 } |
29 | 35 |
30 closure3() { | 36 closure3() { |
31 var y = 400; | 37 var y = 400; |
32 var f = (x) { return y + x; }; | 38 var f = (x) { |
| 39 return y + x; |
| 40 }; |
33 Expect.equals(499, f(99)); | 41 Expect.equals(499, f(99)); |
34 } | 42 } |
35 | 43 |
36 applyFun2(f) { | 44 applyFun2(f) { |
37 return f(400, 90); | 45 return f(400, 90); |
38 } | 46 } |
39 | 47 |
40 closure4() { | 48 closure4() { |
41 var z = 9; | 49 var z = 9; |
42 Expect.equals(499, applyFun2((x, y) { return x + y + z; })); | 50 Expect.equals(499, applyFun2((x, y) { |
| 51 return x + y + z; |
| 52 })); |
43 } | 53 } |
44 | 54 |
45 closure5() { | 55 closure5() { |
46 var x = 498; | 56 var x = 498; |
47 var f = () { return x; }; | 57 var f = () { |
| 58 return x; |
| 59 }; |
48 x++; | 60 x++; |
49 Expect.equals(499, f()); | 61 Expect.equals(499, f()); |
50 } | 62 } |
51 | 63 |
52 class A2 { | 64 class A2 { |
53 closure6() { | 65 closure6() { |
54 var x = 498; | 66 var x = 498; |
55 var f = () { return x; }; | 67 var f = () { |
| 68 return x; |
| 69 }; |
56 x++; | 70 x++; |
57 Expect.equals(499, f()); | 71 Expect.equals(499, f()); |
58 } | 72 } |
59 } | 73 } |
60 | 74 |
61 closure7() { | 75 closure7() { |
62 var x = 498; | 76 var x = 498; |
63 var f = () { return x; }; | 77 var f = () { |
| 78 return x; |
| 79 }; |
64 x++; | 80 x++; |
65 Expect.equals(499, applyFun(f)); | 81 Expect.equals(499, applyFun(f)); |
66 } | 82 } |
67 | 83 |
68 closure8() { | 84 closure8() { |
69 var y = 399; | 85 var y = 399; |
70 var f = (x) { return y + x; }; | 86 var f = (x) { |
| 87 return y + x; |
| 88 }; |
71 y++; | 89 y++; |
72 Expect.equals(499, f(99)); | 90 Expect.equals(499, f(99)); |
73 } | 91 } |
74 | 92 |
75 closure9() { | 93 closure9() { |
76 var z = 9; | 94 var z = 9; |
77 Expect.equals(499, applyFun2((x, y) { return x + y + z; })); | 95 Expect.equals(499, applyFun2((x, y) { |
| 96 return x + y + z; |
| 97 })); |
78 } | 98 } |
79 | 99 |
80 main() { | 100 main() { |
81 closure0(); | 101 closure0(); |
82 new A().closure1(); | 102 new A().closure1(); |
83 closure2(); | 103 closure2(); |
84 closure3(); | 104 closure3(); |
85 closure4(); | 105 closure4(); |
86 closure5(); | 106 closure5(); |
87 new A2().closure6(); | 107 new A2().closure6(); |
88 closure7(); | 108 closure7(); |
89 closure8(); | 109 closure8(); |
90 closure9(); | 110 closure9(); |
91 } | 111 } |
OLD | NEW |