| 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 f = () { return 499; }; | 8 var f = () { |
| 9 return 499; |
| 10 }; |
| 9 Expect.equals(499, f()); | 11 Expect.equals(499, f()); |
| 10 } | 12 } |
| 11 | 13 |
| 12 class A { | 14 class A { |
| 13 closure1() { | 15 closure1() { |
| 14 var f = () { return 499; }; | 16 var f = () { |
| 17 return 499; |
| 18 }; |
| 15 Expect.equals(499, f()); | 19 Expect.equals(499, f()); |
| 16 } | 20 } |
| 17 } | 21 } |
| 18 | 22 |
| 19 applyFun(f) { | 23 applyFun(f) { |
| 20 return f(); | 24 return f(); |
| 21 } | 25 } |
| 22 | 26 |
| 23 closure2() { | 27 closure2() { |
| 24 Expect.equals(499, applyFun(() { return 499; })); | 28 Expect.equals(499, applyFun(() { |
| 29 return 499; |
| 30 })); |
| 25 } | 31 } |
| 26 | 32 |
| 27 closure3() { | 33 closure3() { |
| 28 var f = (x) { return 400 + x; }; | 34 var f = (x) { |
| 35 return 400 + x; |
| 36 }; |
| 29 Expect.equals(499, f(99)); | 37 Expect.equals(499, f(99)); |
| 30 } | 38 } |
| 31 | 39 |
| 32 applyFun2(f) { | 40 applyFun2(f) { |
| 33 return f(400, 99); | 41 return f(400, 99); |
| 34 } | 42 } |
| 35 | 43 |
| 36 closure4() { | 44 closure4() { |
| 37 Expect.equals(499, applyFun2((x, y) { return x + y; })); | 45 Expect.equals(499, applyFun2((x, y) { |
| 46 return x + y; |
| 47 })); |
| 38 } | 48 } |
| 39 | 49 |
| 40 main() { | 50 main() { |
| 41 closure0(); | 51 closure0(); |
| 42 new A().closure1(); | 52 new A().closure1(); |
| 43 closure2(); | 53 closure2(); |
| 44 closure3(); | 54 closure3(); |
| 45 closure4(); | 55 closure4(); |
| 46 } | 56 } |
| OLD | NEW |