OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart test for new function type alias. | 5 // Dart test for new function type alias. |
6 | 6 |
7 class FunctionLiteralsTest { | 7 class FunctionLiteralsTest { |
8 | 8 |
9 static void testMain() { | 9 static void testMain() { |
10 f(x) { return x * 2;} | 10 f(x) { return x * 2;} |
11 f(42); // make sure it is parsed as a function call | 11 f(42); // make sure it is parsed as a function call |
12 Expect.equals(20, f(10)); | 12 Expect.equals(20, f(10)); |
13 | 13 |
14 int g(x) { return x * 2;} | 14 int g(x) { return x * 2;} |
15 g(42); // make sure it is parsed as a function call | 15 g(42); // make sure it is parsed as a function call |
16 Expect.equals(20, g(10)); | 16 Expect.equals(20, g(10)); |
17 | 17 |
18 h(x) { return x * 2;} | 18 h(x) { return x * 2;} |
19 h(42); // make sure it is parsed as a function call | 19 h(42); // make sure it is parsed as a function call |
20 Expect.equals(20, h(10)); | 20 Expect.equals(20, h(10)); |
21 | 21 |
22 var a = int _(x) {return x + 2;}; | 22 var a = (x) {return x + 2;}; |
23 Expect.equals(7, a(5)); | 23 Expect.equals(7, a(5)); |
24 | 24 |
25 Expect.equals(10, apply((k) { return k << 1;}, 5)); | 25 Expect.equals(10, apply((k) { return k << 1;}, 5)); |
26 Expect.equals(20, apply((k) => k << 1, 10)); | 26 Expect.equals(20, apply((k) => k << 1, 10)); |
27 | 27 |
28 a = new A(3); | 28 a = new A(3); |
29 Expect.equals(-1, a.f); | 29 Expect.equals(-1, a.f); |
30 Expect.equals(-3, a.f2); | 30 Expect.equals(-3, a.f2); |
31 | 31 |
32 a = new A.n(5); | 32 a = new A.n(5); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class B { | 67 class B { |
68 var f; | 68 var f; |
69 int n; | 69 int n; |
70 B(z) : f = ((x) => x * x) { n = z; } | 70 B(z) : f = ((x) => x * x) { n = z; } |
71 B.withZ(z) : f = ((x) { return x * x + 1; }) { n = z; } | 71 B.withZ(z) : f = ((x) { return x * x + 1; }) { n = z; } |
72 } | 72 } |
73 | 73 |
74 main() { | 74 main() { |
75 FunctionLiteralsTest.testMain(); | 75 FunctionLiteralsTest.testMain(); |
76 } | 76 } |
OLD | NEW |