OLD | NEW |
1 // Copyright (c) 2011, 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 /** | 5 /** |
6 * Test various forms of function literals. | 6 * Test various forms of function literals. |
7 */ | 7 */ |
8 typedef int IntFunc(int); | 8 typedef int IntFunc(int); |
9 | 9 |
10 class FunctionLiteralsTest { | 10 class FunctionLiteralsTest { |
11 static void checkIntFunction(expected, int f(x), arg) { | 11 static void checkIntFunction(expected, int f(x), arg) { |
(...skipping 24 matching lines...) Expand all Loading... |
36 test.testArrowArrow(); | 36 test.testArrowArrow(); |
37 test.testArrowBlock(); | 37 test.testArrowBlock(); |
38 test.testBlock(); | 38 test.testBlock(); |
39 test.testBlockArrow(); | 39 test.testBlockArrow(); |
40 test.testBlockBlock(); | 40 test.testBlockBlock(); |
41 test.testFunctionRef(); | 41 test.testFunctionRef(); |
42 } | 42 } |
43 | 43 |
44 void testArrow() { | 44 void testArrow() { |
45 checkIntFunction(42, (x) => x, 42); | 45 checkIntFunction(42, (x) => x, 42); |
46 checkIntFunction(42, _(x) => x, 42); | |
47 checkIntFunction(42, int f(x) => x, 42); | |
48 checkIntFunction(42, (int x) => x, 42); | 46 checkIntFunction(42, (int x) => x, 42); |
49 checkIntFunction(42, _(int x) => x, 42); | |
50 checkIntFunction(42, int f(int x) => x, 42); | |
51 } | 47 } |
52 | 48 |
53 void testArrowArrow() { | 49 void testArrowArrow() { |
54 checkIntFuncFunction(84, (x) => (y) => x+y, 42); | 50 checkIntFuncFunction(84, (x) => (y) => x+y, 42); |
55 checkIntFuncFunction(84, _(x) => (y) => x+y, 42); | |
56 checkIntFuncFunction(84, IntFunc f(x) => (y) => x+y, 42); | |
57 checkIntFuncFunction(84, (int x) => (y) => x+y, 42); | 51 checkIntFuncFunction(84, (int x) => (y) => x+y, 42); |
58 checkIntFuncFunction(84, _(int x) => (y) => x+y, 42); | 52 checkIntFuncFunction(84, (x) => (y) => x+y, 42); |
59 checkIntFuncFunction(84, IntFunc f(int x) => (y) => x+y, 42); | 53 checkIntFuncFunction(84, (int x) => (y) => x+y, 42); |
60 checkIntFuncFunction(84, (x) => f(y) => x+y, 42); | |
61 checkIntFuncFunction(84, _(x) => f(y) => x+y, 42); | |
62 checkIntFuncFunction(84, IntFunc f(x) => f(y) => x+y, 42); | |
63 checkIntFuncFunction(84, (int x) => f(y) => x+y, 42); | |
64 checkIntFuncFunction(84, _(int x) => f(y) => x+y, 42); | |
65 checkIntFuncFunction(84, IntFunc f(int x) => f(y) => x+y, 42); | |
66 checkIntFuncFunction(84, (x) => int f(y) => x+y, 42); | |
67 checkIntFuncFunction(84, _(x) => int f(y) => x+y, 42); | |
68 checkIntFuncFunction(84, IntFunc f(x) => int f(y) => x+y, 42); | |
69 checkIntFuncFunction(84, (int x) => int f(y) => x+y, 42); | |
70 checkIntFuncFunction(84, _(int x) => int f(y) => x+y, 42); | |
71 checkIntFuncFunction(84, IntFunc f(int x) => int f(y) => x+y, 42); | |
72 checkIntFuncFunction(84, (int x) => int f(int y) => x+y, 42); | |
73 checkIntFuncFunction(84, _(int x) => int f(int y) => x+y, 42); | |
74 checkIntFuncFunction(84, IntFunc f(int x) => int f(int y) => x+y, 42); | |
75 } | 54 } |
76 | 55 |
77 void testArrowBlock() { | 56 void testArrowBlock() { |
78 checkIntFuncFunction(84, (x) => (y) { return x+y; }, 42); | 57 checkIntFuncFunction(84, (x) => (y) { return x+y; }, 42); |
79 checkIntFuncFunction(84, _(x) => (y) { return x+y; }, 42); | |
80 checkIntFuncFunction(84, IntFunc f(x) => (y) { return x+y; }, 42); | |
81 checkIntFuncFunction(84, (int x) => (y) { return x+y; }, 42); | 58 checkIntFuncFunction(84, (int x) => (y) { return x+y; }, 42); |
82 checkIntFuncFunction(84, _(int x) => (y) { return x+y; }, 42); | |
83 checkIntFuncFunction(84, IntFunc f(int x) => (y) { return x+y; }, 42); | |
84 checkIntFuncFunction(84, (x) => f(y) { return x+y; }, 42); | |
85 checkIntFuncFunction(84, _(x) => f(y) { return x+y; }, 42); | |
86 checkIntFuncFunction(84, IntFunc f(x) => f(y) { return x+y; }, 42); | |
87 checkIntFuncFunction(84, (int x) => f(y) { return x+y; }, 42); | |
88 checkIntFuncFunction(84, _(int x) => f(y) { return x+y; }, 42); | |
89 checkIntFuncFunction(84, IntFunc f(int x) => f(y) { return x+y; }, 42); | |
90 checkIntFuncFunction(84, (x) => int f(y) { return x+y; }, 42); | |
91 checkIntFuncFunction(84, _(x) => int f(y) { return x+y; }, 42); | |
92 checkIntFuncFunction(84, IntFunc f(x) => int f(y) { return x+y; }, 42); | |
93 checkIntFuncFunction(84, (int x) => int f(y) { return x+y; }, 42); | |
94 checkIntFuncFunction(84, _(int x) => int f(y) { return x+y; }, 42); | |
95 checkIntFuncFunction(84, IntFunc f(int x) => int f(y) { return x+y; }, 42); | |
96 } | 59 } |
97 | 60 |
98 void testBlock() { | 61 void testBlock() { |
99 checkIntFunction(42, (x) { return x; }, 42); | 62 checkIntFunction(42, (x) { return x; }, 42); |
100 checkIntFunction(42, _(x) { return x; }, 42); | |
101 checkIntFunction(42, int f(x) { return x; }, 42); | |
102 checkIntFunction(42, (int x) { return x; }, 42); | 63 checkIntFunction(42, (int x) { return x; }, 42); |
103 checkIntFunction(42, _(int x) { return x; }, 42); | |
104 checkIntFunction(42, int f(int x) { return x; }, 42); | |
105 } | 64 } |
106 | 65 |
107 void testBlockArrow() { | 66 void testBlockArrow() { |
108 checkIntFuncFunction(84, (x) { return (y) => x+y; }, 42); | 67 checkIntFuncFunction(84, (x) { return (y) => x+y; }, 42); |
109 checkIntFuncFunction(84, _(x) { return (y) => x+y; }, 42); | |
110 checkIntFuncFunction(84, IntFunc f(x) { return (y) => x+y; }, 42); | |
111 checkIntFuncFunction(84, (int x) { return (y) => x+y; }, 42); | 68 checkIntFuncFunction(84, (int x) { return (y) => x+y; }, 42); |
112 checkIntFuncFunction(84, _(int x) { return (y) => x+y; }, 42); | |
113 checkIntFuncFunction(84, IntFunc f(int x) { return (y) => x+y; }, 42); | |
114 checkIntFuncFunction(84, (x) { return f(y) => x+y; }, 42); | |
115 checkIntFuncFunction(84, _(x) { return f(y) => x+y; }, 42); | |
116 checkIntFuncFunction(84, IntFunc f(x) { return f(y) => x+y; }, 42); | |
117 checkIntFuncFunction(84, (int x) { return f(y) => x+y; }, 42); | |
118 checkIntFuncFunction(84, _(int x) { return f(y) => x+y; }, 42); | |
119 checkIntFuncFunction(84, IntFunc f(int x) { return f(y) => x+y; }, 42); | |
120 checkIntFuncFunction(84, (x) { return int f(y) => x+y; }, 42); | |
121 checkIntFuncFunction(84, _(x) { return int f(y) => x+y; }, 42); | |
122 checkIntFuncFunction(84, IntFunc f(x) { return int f(y) => x+y; }, 42); | |
123 checkIntFuncFunction(84, (int x) { return int f(y) => x+y; }, 42); | |
124 checkIntFuncFunction(84, _(int x) { return int f(y) => x+y; }, 42); | |
125 checkIntFuncFunction(84, IntFunc f(int x) { return int f(y) => x+y; }, 42); | |
126 } | 69 } |
127 | 70 |
128 void testBlockBlock() { | 71 void testBlockBlock() { |
129 checkIntFuncFunction(84, (x) { return (y) { return x+y; }; }, 42); | 72 checkIntFuncFunction(84, (x) { return (y) { return x+y; }; }, 42); |
130 checkIntFuncFunction(84, _(x) { return (y) { return x+y; }; }, 42); | |
131 checkIntFuncFunction(84, IntFunc f(x) { return (y) { return x+y; }; }, 42); | |
132 checkIntFuncFunction(84, (int x) { return (y) { return x+y; }; }, 42); | 73 checkIntFuncFunction(84, (int x) { return (y) { return x+y; }; }, 42); |
133 checkIntFuncFunction(84, _(int x) { return (y) { return x+y; }; }, 42); | |
134 checkIntFuncFunction(84, IntFunc f(int x) { return (y) { return x+y; }; }, 4
2); | |
135 checkIntFuncFunction(84, (x) { return f(y) { return x+y; }; }, 42); | |
136 checkIntFuncFunction(84, _(x) { return f(y) { return x+y; }; }, 42); | |
137 checkIntFuncFunction(84, IntFunc f(x) { return f(y) { return x+y; }; }, 42); | |
138 checkIntFuncFunction(84, (int x) { return f(y) { return x+y; }; }, 42); | |
139 checkIntFuncFunction(84, _(int x) { return f(y) { return x+y; }; }, 42); | |
140 checkIntFuncFunction(84, IntFunc f(int x) { return f(y) { return x+y; }; },
42); | |
141 checkIntFuncFunction(84, (x) { return int f(y) { return x+y; }; }, 42); | |
142 checkIntFuncFunction(84, _(x) { return int f(y) { return x+y; }; }, 42); | |
143 checkIntFuncFunction(84, IntFunc f(x) { return int f(y) { return x+y; }; },
42); | |
144 checkIntFuncFunction(84, (int x) { return int f(y) { return x+y; }; }, 42); | |
145 checkIntFuncFunction(84, _(int x) { return int f(y) { return x+y; }; }, 42); | |
146 checkIntFuncFunction(84, IntFunc f(int x) { return int f(y) { return x+y; };
}, 42); | |
147 } | 74 } |
148 | 75 |
149 void testFunctionRef() { | 76 void testFunctionRef() { |
150 checkIntFunction(42, func1, 42); | 77 checkIntFunction(42, func1, 42); |
151 checkIntFunction(42, func2, 42); | 78 checkIntFunction(42, func2, 42); |
152 checkIntFunction(42, func3, 42); | 79 checkIntFunction(42, func3, 42); |
153 checkIntFunction(42, func4, 42); | 80 checkIntFunction(42, func4, 42); |
154 } | 81 } |
155 } | 82 } |
156 | 83 |
157 | 84 |
158 main() { | 85 main() { |
159 FunctionLiteralsTest.testMain(); | 86 FunctionLiteralsTest.testMain(); |
160 } | 87 } |
OLD | NEW |