| 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 // TODO(floitsch): remove name from functions. | 9 var f = () { return x; }; |
| 10 var f = fun() { return x; }; | |
| 11 Expect.equals(499, f()); | 10 Expect.equals(499, f()); |
| 12 } | 11 } |
| 13 | 12 |
| 14 class A { | 13 class A { |
| 15 closure1() { | 14 closure1() { |
| 16 var x = 499; | 15 var x = 499; |
| 17 var f = fun() { return x; }; | 16 var f = () { return x; }; |
| 18 Expect.equals(499, f()); | 17 Expect.equals(499, f()); |
| 19 } | 18 } |
| 20 } | 19 } |
| 21 | 20 |
| 22 applyFun(f) { | 21 applyFun(f) { |
| 23 return f(); | 22 return f(); |
| 24 } | 23 } |
| 25 | 24 |
| 26 closure2() { | 25 closure2() { |
| 27 var x = 499; | 26 var x = 499; |
| 28 Expect.equals(499, applyFun(fun() { return x; })); | 27 Expect.equals(499, applyFun(() { return x; })); |
| 29 } | 28 } |
| 30 | 29 |
| 31 closure3() { | 30 closure3() { |
| 32 var y = 400; | 31 var y = 400; |
| 33 var f = fun(x) { return y + x; }; | 32 var f = (x) { return y + x; }; |
| 34 Expect.equals(499, f(99)); | 33 Expect.equals(499, f(99)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 applyFun2(f) { | 36 applyFun2(f) { |
| 38 return f(400, 90); | 37 return f(400, 90); |
| 39 } | 38 } |
| 40 | 39 |
| 41 closure4() { | 40 closure4() { |
| 42 var z = 9; | 41 var z = 9; |
| 43 Expect.equals(499, applyFun2(fun(x, y) { return x + y + z; })); | 42 Expect.equals(499, applyFun2((x, y) { return x + y + z; })); |
| 44 } | 43 } |
| 45 | 44 |
| 46 closure5() { | 45 closure5() { |
| 47 var x = 498; | 46 var x = 498; |
| 48 // TODO(floitsch): remove name from functions. | 47 var f = () { return x; }; |
| 49 var f = fun() { return x; }; | |
| 50 x++; | 48 x++; |
| 51 Expect.equals(499, f()); | 49 Expect.equals(499, f()); |
| 52 } | 50 } |
| 53 | 51 |
| 54 class A2 { | 52 class A2 { |
| 55 closure6() { | 53 closure6() { |
| 56 var x = 498; | 54 var x = 498; |
| 57 var f = fun() { return x; }; | 55 var f = () { return x; }; |
| 58 x++; | 56 x++; |
| 59 Expect.equals(499, f()); | 57 Expect.equals(499, f()); |
| 60 } | 58 } |
| 61 } | 59 } |
| 62 | 60 |
| 63 closure7() { | 61 closure7() { |
| 64 var x = 498; | 62 var x = 498; |
| 65 var f = fun() { return x; }; | 63 var f = () { return x; }; |
| 66 x++; | 64 x++; |
| 67 Expect.equals(499, applyFun(f)); | 65 Expect.equals(499, applyFun(f)); |
| 68 } | 66 } |
| 69 | 67 |
| 70 closure8() { | 68 closure8() { |
| 71 var y = 399; | 69 var y = 399; |
| 72 var f = fun(x) { return y + x; }; | 70 var f = (x) { return y + x; }; |
| 73 y++; | 71 y++; |
| 74 Expect.equals(499, f(99)); | 72 Expect.equals(499, f(99)); |
| 75 } | 73 } |
| 76 | 74 |
| 77 closure9() { | 75 closure9() { |
| 78 var z = 9; | 76 var z = 9; |
| 79 Expect.equals(499, applyFun2(fun(x, y) { return x + y + z; })); | 77 Expect.equals(499, applyFun2((x, y) { return x + y + z; })); |
| 80 } | 78 } |
| 81 | 79 |
| 82 main() { | 80 main() { |
| 83 closure0(); | 81 closure0(); |
| 84 new A().closure1(); | 82 new A().closure1(); |
| 85 closure2(); | 83 closure2(); |
| 86 closure3(); | 84 closure3(); |
| 87 closure4(); | 85 closure4(); |
| 88 closure5(); | 86 closure5(); |
| 89 new A2().closure6(); | 87 new A2().closure6(); |
| 90 closure7(); | 88 closure7(); |
| 91 closure8(); | 89 closure8(); |
| 92 closure9(); | 90 closure9(); |
| 93 } | 91 } |
| OLD | NEW |