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