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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Tests function statement and expression syntax. | 7 // Tests function statement and expression syntax. |
8 | 8 |
9 class FunctionSyntaxTest { | 9 class FunctionSyntaxTest { |
10 | |
11 static void testMain | 10 static void testMain |
12 /* //# 00: compile-time error | 11 /* //# 00: compile-time error |
13 () | 12 () |
14 */ //# 00: continued | 13 */ //# 00: continued |
15 { | 14 { |
16 testNestedFunctions(); | 15 testNestedFunctions(); |
17 testFunctionExpressions(); | 16 testFunctionExpressions(); |
18 testPrecedence(); | 17 testPrecedence(); |
19 testInitializers(); | 18 testInitializers(); |
20 testFunctionParameter(); | 19 testFunctionParameter(); |
21 testFunctionIdentifierExpression(); | 20 testFunctionIdentifierExpression(); |
22 testFunctionIdentifierStatement(); | 21 testFunctionIdentifierStatement(); |
23 } | 22 } |
24 | 23 |
25 static void testNestedFunctions | 24 static void testNestedFunctions |
26 /* //# 01: compile-time error | 25 /* //# 01: compile-time error |
27 () | 26 () |
28 */ //# 01: continued | 27 */ //# 01: continued |
29 { | 28 { |
30 // No types - braces. | 29 // No types - braces. |
31 nb0 | 30 nb0 |
32 /* //# 02: compile-time error | 31 /* //# 02: compile-time error |
33 () | 32 () |
34 */ //# 02: continued | 33 */ //# 02: continued |
35 { return 42; } | 34 { |
| 35 return 42; |
| 36 } |
| 37 |
36 nb1 | 38 nb1 |
37 /* //# 03: compile-time error | 39 /* //# 03: compile-time error |
38 (a) | 40 (a) |
39 */ //# 03: continued | 41 */ //# 03: continued |
40 { return a; } | 42 { |
| 43 return a; |
| 44 } |
| 45 |
41 nb2 | 46 nb2 |
42 /* //# 04: compile-time error | 47 /* //# 04: compile-time error |
43 (a, b) | 48 (a, b) |
44 */ //# 04: continued | 49 */ //# 04: continued |
45 { return a + b; } | 50 { |
| 51 return a + b; |
| 52 } |
| 53 |
46 Expect.equals(42, nb0()); | 54 Expect.equals(42, nb0()); |
47 Expect.equals(87, nb1(87)); | 55 Expect.equals(87, nb1(87)); |
48 Expect.equals(1 + 2, nb2(1, 2)); | 56 Expect.equals(1 + 2, nb2(1, 2)); |
49 | 57 |
50 // No types - arrows. | 58 // No types - arrows. |
51 na0 | 59 na0 |
52 /* //# 05: compile-time error | 60 /* //# 05: compile-time error |
53 () | 61 () |
54 */ //# 05: continued | 62 */ //# 05: continued |
55 => 42; | 63 => |
| 64 42; |
56 na1 | 65 na1 |
57 /* //# 06: compile-time error | 66 /* //# 06: compile-time error |
58 (a) | 67 (a) |
59 */ //# 06: continued | 68 */ //# 06: continued |
60 => a; | 69 => |
| 70 a; |
61 na2 | 71 na2 |
62 /* //# 07: compile-time error | 72 /* //# 07: compile-time error |
63 (a, b) | 73 (a, b) |
64 */ //# 07: continued | 74 */ //# 07: continued |
65 => a + b; | 75 => |
| 76 a + b; |
66 Expect.equals(42, na0()); | 77 Expect.equals(42, na0()); |
67 Expect.equals(87, na1(87)); | 78 Expect.equals(87, na1(87)); |
68 Expect.equals(1 + 2, na2(1, 2)); | 79 Expect.equals(1 + 2, na2(1, 2)); |
69 | 80 |
70 // Return type - braces. | 81 // Return type - braces. |
71 int rb0 | 82 int rb0 |
72 /* //# 08: compile-time error | 83 /* //# 08: compile-time error |
73 () | 84 () |
74 */ //# 08: continued | 85 */ //# 08: continued |
75 { return 42; } | 86 { |
| 87 return 42; |
| 88 } |
| 89 |
76 int rb1 | 90 int rb1 |
77 /* //# 09: compile-time error | 91 /* //# 09: compile-time error |
78 (a) | 92 (a) |
79 */ //# 09: continued | 93 */ //# 09: continued |
80 { return a; } | 94 { |
| 95 return a; |
| 96 } |
| 97 |
81 int rb2 | 98 int rb2 |
82 /* //# 10: compile-time error | 99 /* //# 10: compile-time error |
83 (a, b) | 100 (a, b) |
84 */ //# 10: continued | 101 */ //# 10: continued |
85 { return a + b; } | 102 { |
| 103 return a + b; |
| 104 } |
| 105 |
86 Expect.equals(42, rb0()); | 106 Expect.equals(42, rb0()); |
87 Expect.equals(87, rb1(87)); | 107 Expect.equals(87, rb1(87)); |
88 Expect.equals(1 + 2, rb2(1, 2)); | 108 Expect.equals(1 + 2, rb2(1, 2)); |
89 | 109 |
90 // Return type - arrows. | 110 // Return type - arrows. |
91 int ra0 | 111 int ra0 |
92 /* //# 11: compile-time error | 112 /* //# 11: compile-time error |
93 () | 113 () |
94 */ //# 11: continued | 114 */ //# 11: continued |
95 => 42; | 115 => |
| 116 42; |
96 int ra1 | 117 int ra1 |
97 /* //# 12: compile-time error | 118 /* //# 12: compile-time error |
98 (a) | 119 (a) |
99 */ //# 12: continued | 120 */ //# 12: continued |
100 => a; | 121 => |
| 122 a; |
101 int ra2 | 123 int ra2 |
102 /* //# 13: compile-time error | 124 /* //# 13: compile-time error |
103 (a, b) | 125 (a, b) |
104 */ //# 13: continued | 126 */ //# 13: continued |
105 => a + b; | 127 => |
| 128 a + b; |
106 Expect.equals(42, ra0()); | 129 Expect.equals(42, ra0()); |
107 Expect.equals(87, ra1(87)); | 130 Expect.equals(87, ra1(87)); |
108 Expect.equals(1 + 2, ra2(1, 2)); | 131 Expect.equals(1 + 2, ra2(1, 2)); |
109 | 132 |
110 // Fully typed - braces. | 133 // Fully typed - braces. |
111 int fb1 | 134 int fb1 |
112 /* //# 14: compile-time error | 135 /* //# 14: compile-time error |
113 (int a) | 136 (int a) |
114 */ //# 14: continued | 137 */ //# 14: continued |
115 { return a; } | 138 { |
| 139 return a; |
| 140 } |
| 141 |
116 int fb2 | 142 int fb2 |
117 /* //# 15: compile-time error | 143 /* //# 15: compile-time error |
118 (int a, int b) | 144 (int a, int b) |
119 */ //# 15: continued | 145 */ //# 15: continued |
120 { return a + b; } | 146 { |
| 147 return a + b; |
| 148 } |
| 149 |
121 Expect.equals(42, rb0()); | 150 Expect.equals(42, rb0()); |
122 Expect.equals(87, rb1(87)); | 151 Expect.equals(87, rb1(87)); |
123 Expect.equals(1 + 2, rb2(1, 2)); | 152 Expect.equals(1 + 2, rb2(1, 2)); |
124 | 153 |
125 // Fully typed - arrows. | 154 // Fully typed - arrows. |
126 int fa1 | 155 int fa1 |
127 /* //# 16: compile-time error | 156 /* //# 16: compile-time error |
128 (int a) | 157 (int a) |
129 */ //# 16: continued | 158 */ //# 16: continued |
130 => a; | 159 => |
| 160 a; |
131 int fa2 | 161 int fa2 |
132 /* //# 17: compile-time error | 162 /* //# 17: compile-time error |
133 (int a, int b) | 163 (int a, int b) |
134 */ //# 17: continued | 164 */ //# 17: continued |
135 => a + b; | 165 => |
| 166 a + b; |
136 Expect.equals(42, ra0()); | 167 Expect.equals(42, ra0()); |
137 Expect.equals(87, ra1(87)); | 168 Expect.equals(87, ra1(87)); |
138 Expect.equals(1 + 2, ra2(1, 2)); | 169 Expect.equals(1 + 2, ra2(1, 2)); |
139 | 170 |
140 // Generic types - braces. | 171 // Generic types - braces. |
141 List<int> gb0 | 172 List<int> gb0 |
142 /* //# 18: compile-time error | 173 /* //# 18: compile-time error |
143 () | 174 () |
144 */ //# 18: continued | 175 */ //# 18: continued |
145 { return [42]; } | 176 { |
| 177 return [42]; |
| 178 } |
| 179 |
146 List<int> gb1 | 180 List<int> gb1 |
147 /* //# 19: compile-time error | 181 /* //# 19: compile-time error |
148 (List<int> a) | 182 (List<int> a) |
149 */ //# 19: continued | 183 */ //# 19: continued |
150 { return a; } | 184 { |
| 185 return a; |
| 186 } |
| 187 |
151 Expect.equals(42, gb0()[0]); | 188 Expect.equals(42, gb0()[0]); |
152 Expect.equals(87, gb1([87])[0]); | 189 Expect.equals(87, gb1([87])[0]); |
153 | 190 |
154 // Generic types - arrows. | 191 // Generic types - arrows. |
155 List<int> ga0 | 192 List<int> ga0 |
156 /* //# 20: compile-time error | 193 /* //# 20: compile-time error |
157 () | 194 () |
158 */ //# 20: continued | 195 */ //# 20: continued |
159 => [42]; | 196 => |
| 197 [42]; |
160 List<int> ga1 | 198 List<int> ga1 |
161 /* //# 21: compile-time error | 199 /* //# 21: compile-time error |
162 (List<int> a) | 200 (List<int> a) |
163 */ //# 21: continued | 201 */ //# 21: continued |
164 => a; | 202 => |
| 203 a; |
165 Expect.equals(42, ga0()[0]); | 204 Expect.equals(42, ga0()[0]); |
166 Expect.equals(87, ga1([87])[0]); | 205 Expect.equals(87, ga1([87])[0]); |
167 } | 206 } |
168 | 207 |
169 static void testFunctionExpressions | 208 static void testFunctionExpressions |
170 /* //# 22: compile-time error | 209 /* //# 22: compile-time error |
171 () | 210 () |
172 */ //# 22: continued | 211 */ //# 22: continued |
173 { | 212 { |
174 eval0 | 213 eval0 |
175 /* //# 23: compile-time error | 214 /* //# 23: compile-time error |
176 (fn) | 215 (fn) |
177 */ //# 23: continued | 216 */ //# 23: continued |
178 => fn(); | 217 => |
| 218 fn(); |
179 eval1 | 219 eval1 |
180 /* //# 24: compile-time error | 220 /* //# 24: compile-time error |
181 (fn, a) | 221 (fn, a) |
182 */ //# 24: continued | 222 */ //# 24: continued |
183 => fn(a); | 223 => |
| 224 fn(a); |
184 eval2 | 225 eval2 |
185 /* //# 25: compile-time error | 226 /* //# 25: compile-time error |
186 (fn, a, b) | 227 (fn, a, b) |
187 */ //# 25: continued | 228 */ //# 25: continued |
188 => fn(a, b); | 229 => |
| 230 fn(a, b); |
189 | 231 |
190 // No types - braces. | 232 // No types - braces. |
191 Expect.equals(42, eval0( | 233 Expect.equals(42, eval0( |
192 /* //# 26: compile-time error | 234 /* //# 26: compile-time error |
193 () | 235 () |
194 */ //# 26: continued | 236 */ //# 26: continued |
195 { return 42; })); | 237 { |
196 Expect.equals(87, eval1( | 238 return 42; |
| 239 })); |
| 240 Expect.equals( |
| 241 87, |
| 242 eval1( |
197 /* //# 27: compile-time error | 243 /* //# 27: compile-time error |
198 (a) | 244 (a) |
199 */ //# 27: continued | 245 */ //# 27: continued |
200 { return a; }, 87)); | 246 { |
201 Expect.equals(1 + 2, eval2( | 247 return a; |
| 248 }, 87)); |
| 249 Expect.equals( |
| 250 1 + 2, |
| 251 eval2( |
202 /* //# 28: compile-time error | 252 /* //# 28: compile-time error |
203 (a, b) | 253 (a, b) |
204 */ //# 28: continued | 254 */ //# 28: continued |
205 { return a + b; }, 1, 2)); | 255 { |
| 256 return a + b; |
| 257 }, 1, 2)); |
206 Expect.equals(42, eval0( | 258 Expect.equals(42, eval0( |
207 /* //# 29: compile-time error | 259 /* //# 29: compile-time error |
208 () | 260 () |
209 */ //# 29: continued | 261 */ //# 29: continued |
210 { return 42; })); | 262 { |
211 Expect.equals(87, eval1( | 263 return 42; |
| 264 })); |
| 265 Expect.equals( |
| 266 87, |
| 267 eval1( |
212 /* //# 30: compile-time error | 268 /* //# 30: compile-time error |
213 (a) | 269 (a) |
214 */ //# 30: continued | 270 */ //# 30: continued |
215 { return a; }, 87)); | 271 { |
216 Expect.equals(1 + 2, eval2( | 272 return a; |
| 273 }, 87)); |
| 274 Expect.equals( |
| 275 1 + 2, |
| 276 eval2( |
217 /* //# 31: compile-time error | 277 /* //# 31: compile-time error |
218 (a, b) | 278 (a, b) |
219 */ //# 31: continued | 279 */ //# 31: continued |
220 { return a + b; }, 1, 2)); | 280 { |
| 281 return a + b; |
| 282 }, 1, 2)); |
221 | 283 |
222 // No types - arrows. | 284 // No types - arrows. |
223 Expect.equals(42, eval0( | 285 Expect.equals( |
| 286 42, |
| 287 eval0( |
224 /* //# 32: compile-time error | 288 /* //# 32: compile-time error |
225 () | 289 () |
226 */ //# 32: continued | 290 */ //# 32: continued |
227 => 42)); | 291 => |
228 Expect.equals(87, eval1( | 292 42)); |
| 293 Expect.equals( |
| 294 87, |
| 295 eval1( |
229 /* //# 33: compile-time error | 296 /* //# 33: compile-time error |
230 (a) | 297 (a) |
231 */ //# 33: continued | 298 */ //# 33: continued |
232 => a, 87)); | 299 => |
233 Expect.equals(1 + 2, eval2( | 300 a, |
| 301 87)); |
| 302 Expect.equals( |
| 303 1 + 2, |
| 304 eval2( |
234 /* //# 34: compile-time error | 305 /* //# 34: compile-time error |
235 (a, b) | 306 (a, b) |
236 */ //# 34: continued | 307 */ //# 34: continued |
237 => a + b, 1, 2)); | 308 => |
238 Expect.equals(42, eval0( | 309 a + b, |
| 310 1, |
| 311 2)); |
| 312 Expect.equals( |
| 313 42, |
| 314 eval0( |
239 /* //# 35: compile-time error | 315 /* //# 35: compile-time error |
240 () | 316 () |
241 */ //# 35: continued | 317 */ //# 35: continued |
242 => 42)); | 318 => |
243 Expect.equals(87, eval1( | 319 42)); |
| 320 Expect.equals( |
| 321 87, |
| 322 eval1( |
244 /* //# 36: compile-time error | 323 /* //# 36: compile-time error |
245 (a) | 324 (a) |
246 */ //# 36: continued | 325 */ //# 36: continued |
247 => a, 87)); | 326 => |
248 Expect.equals(1 + 2, eval2( | 327 a, |
| 328 87)); |
| 329 Expect.equals( |
| 330 1 + 2, |
| 331 eval2( |
249 /* //# 37: compile-time error | 332 /* //# 37: compile-time error |
250 (a, b) | 333 (a, b) |
251 */ //# 37: continued | 334 */ //# 37: continued |
252 => a + b, 1, 2)); | 335 => |
| 336 a + b, |
| 337 1, |
| 338 2)); |
253 | 339 |
254 // Argument types - braces. | 340 // Argument types - braces. |
255 Expect.equals(42, eval0( | 341 Expect.equals(42, eval0( |
256 /* //# 44: compile-time error | 342 /* //# 44: compile-time error |
257 () | 343 () |
258 */ //# 44: continued | 344 */ //# 44: continued |
259 { return 42; })); | 345 { |
260 Expect.equals(87, eval1( | 346 return 42; |
| 347 })); |
| 348 Expect.equals( |
| 349 87, |
| 350 eval1( |
261 /* //# 45: compile-time error | 351 /* //# 45: compile-time error |
262 (int a) | 352 (int a) |
263 */ //# 45: continued | 353 */ //# 45: continued |
264 { return a; }, 87)); | 354 { |
265 Expect.equals(1 + 2, eval2( | 355 return a; |
| 356 }, 87)); |
| 357 Expect.equals( |
| 358 1 + 2, |
| 359 eval2( |
266 /* //# 46: compile-time error | 360 /* //# 46: compile-time error |
267 (int a, int b) | 361 (int a, int b) |
268 */ //# 46: continued | 362 */ //# 46: continued |
269 { return a + b; }, 1, 2)); | 363 { |
| 364 return a + b; |
| 365 }, 1, 2)); |
270 Expect.equals(42, eval0( | 366 Expect.equals(42, eval0( |
271 /* //# 47: compile-time error | 367 /* //# 47: compile-time error |
272 () | 368 () |
273 */ //# 47: continued | 369 */ //# 47: continued |
274 { return 42; })); | 370 { |
275 Expect.equals(87, eval1( | 371 return 42; |
| 372 })); |
| 373 Expect.equals( |
| 374 87, |
| 375 eval1( |
276 /* //# 48: compile-time error | 376 /* //# 48: compile-time error |
277 (int a) | 377 (int a) |
278 */ //# 48: continued | 378 */ //# 48: continued |
279 { return a; }, 87)); | 379 { |
280 Expect.equals(1 + 2, eval2( | 380 return a; |
| 381 }, 87)); |
| 382 Expect.equals( |
| 383 1 + 2, |
| 384 eval2( |
281 /* //# 49: compile-time error | 385 /* //# 49: compile-time error |
282 (int a, int b) | 386 (int a, int b) |
283 */ //# 49: continued | 387 */ //# 49: continued |
284 { return a + b; }, 1, 2)); | 388 { |
| 389 return a + b; |
| 390 }, 1, 2)); |
285 | 391 |
286 // Argument types - arrows. | 392 // Argument types - arrows. |
287 Expect.equals(42, eval0( | 393 Expect.equals( |
| 394 42, |
| 395 eval0( |
288 /* //# 50: compile-time error | 396 /* //# 50: compile-time error |
289 () | 397 () |
290 */ //# 50: continued | 398 */ //# 50: continued |
291 => 42)); | 399 => |
292 Expect.equals(87, eval1( | 400 42)); |
| 401 Expect.equals( |
| 402 87, |
| 403 eval1( |
293 /* //# 51: compile-time error | 404 /* //# 51: compile-time error |
294 (int a) | 405 (int a) |
295 */ //# 51: continued | 406 */ //# 51: continued |
296 => a, 87)); | 407 => |
297 Expect.equals(1 + 2, eval2( | 408 a, |
| 409 87)); |
| 410 Expect.equals( |
| 411 1 + 2, |
| 412 eval2( |
298 /* //# 52: compile-time error | 413 /* //# 52: compile-time error |
299 (int a, int b) | 414 (int a, int b) |
300 */ //# 52: continued | 415 */ //# 52: continued |
301 => a + b, 1, 2)); | 416 => |
302 Expect.equals(42, eval0( | 417 a + b, |
| 418 1, |
| 419 2)); |
| 420 Expect.equals( |
| 421 42, |
| 422 eval0( |
303 /* //# 53: compile-time error | 423 /* //# 53: compile-time error |
304 () | 424 () |
305 */ //# 53: continued | 425 */ //# 53: continued |
306 => 42)); | 426 => |
307 Expect.equals(87, eval1( | 427 42)); |
| 428 Expect.equals( |
| 429 87, |
| 430 eval1( |
308 /* //# 54: compile-time error | 431 /* //# 54: compile-time error |
309 (int a) | 432 (int a) |
310 */ //# 54: continued | 433 */ //# 54: continued |
311 => a, 87)); | 434 => |
312 Expect.equals(1 + 2, eval2( | 435 a, |
| 436 87)); |
| 437 Expect.equals( |
| 438 1 + 2, |
| 439 eval2( |
313 /* //# 55: compile-time error | 440 /* //# 55: compile-time error |
314 (int a, int b) | 441 (int a, int b) |
315 */ //# 55: continued | 442 */ //# 55: continued |
316 => a + b, 1, 2)); | 443 => |
317 | 444 a + b, |
| 445 1, |
| 446 2)); |
318 } | 447 } |
319 | 448 |
320 static void testPrecedence | 449 static void testPrecedence |
321 /* //# 64: compile-time error | 450 /* //# 64: compile-time error |
322 () | 451 () |
323 */ //# 64: continued | 452 */ //# 64: continued |
324 { | 453 { |
325 expectEvaluatesTo | 454 expectEvaluatesTo |
326 /* //# 65: compile-time error | 455 /* //# 65: compile-time error |
327 (value, fn) | 456 (value, fn) |
328 */ //# 65: continued | 457 */ //# 65: continued |
329 { Expect.equals(value, fn()); } | 458 { |
| 459 Expect.equals(value, fn()); |
| 460 } |
330 | 461 |
331 // Assignment. | 462 // Assignment. |
332 var x; | 463 var x; |
333 expectEvaluatesTo(42, ()=> x = 42); | 464 expectEvaluatesTo(42, () => x = 42); |
334 Expect.equals(42, x); | 465 Expect.equals(42, x); |
335 x = 1; | 466 x = 1; |
336 expectEvaluatesTo(100, ()=> x += 99); | 467 expectEvaluatesTo(100, () => x += 99); |
337 Expect.equals(100, x); | 468 Expect.equals(100, x); |
338 x = 1; | 469 x = 1; |
339 expectEvaluatesTo(87, ()=> x *= 87); | 470 expectEvaluatesTo(87, () => x *= 87); |
340 Expect.equals(87, x); | 471 Expect.equals(87, x); |
341 | 472 |
342 // Conditional. | 473 // Conditional. |
343 expectEvaluatesTo(42, ()=> true ? 42 : 87); | 474 expectEvaluatesTo(42, () => true ? 42 : 87); |
344 expectEvaluatesTo(87, ()=> false ? 42 : 87); | 475 expectEvaluatesTo(87, () => false ? 42 : 87); |
345 | 476 |
346 // Logical or. | 477 // Logical or. |
347 expectEvaluatesTo(true, ()=> true || true); | 478 expectEvaluatesTo(true, () => true || true); |
348 expectEvaluatesTo(true, ()=> true || false); | 479 expectEvaluatesTo(true, () => true || false); |
349 expectEvaluatesTo(true, ()=> false || true); | 480 expectEvaluatesTo(true, () => false || true); |
350 expectEvaluatesTo(false, ()=> false || false); | 481 expectEvaluatesTo(false, () => false || false); |
351 | 482 |
352 // Logical and. | 483 // Logical and. |
353 expectEvaluatesTo(true, ()=> true && true); | 484 expectEvaluatesTo(true, () => true && true); |
354 expectEvaluatesTo(false, ()=> true && false); | 485 expectEvaluatesTo(false, () => true && false); |
355 expectEvaluatesTo(false, ()=> false && true); | 486 expectEvaluatesTo(false, () => false && true); |
356 expectEvaluatesTo(false, ()=> false && false); | 487 expectEvaluatesTo(false, () => false && false); |
357 | 488 |
358 // Bitwise operations. | 489 // Bitwise operations. |
359 expectEvaluatesTo(3, ()=> 1 | 2); | 490 expectEvaluatesTo(3, () => 1 | 2); |
360 expectEvaluatesTo(2, ()=> 3 ^ 1); | 491 expectEvaluatesTo(2, () => 3 ^ 1); |
361 expectEvaluatesTo(1, ()=> 3 & 1); | 492 expectEvaluatesTo(1, () => 3 & 1); |
362 | 493 |
363 // Equality. | 494 // Equality. |
364 expectEvaluatesTo(true, ()=> 1 == 1); | 495 expectEvaluatesTo(true, () => 1 == 1); |
365 expectEvaluatesTo(false, ()=> 1 != 1); | 496 expectEvaluatesTo(false, () => 1 != 1); |
366 expectEvaluatesTo(true, ()=> identical(1, 1)); | 497 expectEvaluatesTo(true, () => identical(1, 1)); |
367 expectEvaluatesTo(false, ()=> !identical(1, 1)); | 498 expectEvaluatesTo(false, () => !identical(1, 1)); |
368 | 499 |
369 // Relational. | 500 // Relational. |
370 expectEvaluatesTo(true, ()=> 1 <= 1); | 501 expectEvaluatesTo(true, () => 1 <= 1); |
371 expectEvaluatesTo(false, ()=> 1 < 1); | 502 expectEvaluatesTo(false, () => 1 < 1); |
372 expectEvaluatesTo(false, ()=> 1 > 1); | 503 expectEvaluatesTo(false, () => 1 > 1); |
373 expectEvaluatesTo(true, ()=> 1 >= 1); | 504 expectEvaluatesTo(true, () => 1 >= 1); |
374 | 505 |
375 // Is. | 506 // Is. |
376 expectEvaluatesTo(true, ()=> 1 is int); | 507 expectEvaluatesTo(true, () => 1 is int); |
377 expectEvaluatesTo(true, ()=> 1.0 is double); | 508 expectEvaluatesTo(true, () => 1.0 is double); |
378 | 509 |
379 // Shift. | 510 // Shift. |
380 expectEvaluatesTo(2, ()=> 1 << 1); | 511 expectEvaluatesTo(2, () => 1 << 1); |
381 expectEvaluatesTo(1, ()=> 2 >> 1); | 512 expectEvaluatesTo(1, () => 2 >> 1); |
382 | 513 |
383 // Additive. | 514 // Additive. |
384 expectEvaluatesTo(2, ()=> 1 + 1); | 515 expectEvaluatesTo(2, () => 1 + 1); |
385 expectEvaluatesTo(1, ()=> 2 - 1); | 516 expectEvaluatesTo(1, () => 2 - 1); |
386 | 517 |
387 // Multiplicative. | 518 // Multiplicative. |
388 expectEvaluatesTo(2, ()=> 1 * 2); | 519 expectEvaluatesTo(2, () => 1 * 2); |
389 expectEvaluatesTo(2.0, ()=> 4 / 2); | 520 expectEvaluatesTo(2.0, () => 4 / 2); |
390 expectEvaluatesTo(2, ()=> 4 ~/ 2); | 521 expectEvaluatesTo(2, () => 4 ~/ 2); |
391 expectEvaluatesTo(0, ()=> 4 % 2); | 522 expectEvaluatesTo(0, () => 4 % 2); |
392 | 523 |
393 // Negate. | 524 // Negate. |
394 expectEvaluatesTo(false, ()=> !true); | 525 expectEvaluatesTo(false, () => !true); |
395 | 526 |
396 // Postfix / prefix. | 527 // Postfix / prefix. |
397 var y = 0; | 528 var y = 0; |
398 expectEvaluatesTo(0, ()=> y++); | 529 expectEvaluatesTo(0, () => y++); |
399 expectEvaluatesTo(2, ()=> ++y); | 530 expectEvaluatesTo(2, () => ++y); |
400 expectEvaluatesTo(1, ()=> --y); | 531 expectEvaluatesTo(1, () => --y); |
401 expectEvaluatesTo(1, ()=> y--); | 532 expectEvaluatesTo(1, () => y--); |
402 Expect.equals(0, y); | 533 Expect.equals(0, y); |
403 | 534 |
404 // Selector. | 535 // Selector. |
405 fn | 536 fn |
406 /* //# 66: compile-time error | 537 /* //# 66: compile-time error |
407 () | 538 () |
408 */ //# 66: continued | 539 */ //# 66: continued |
409 => 42; | 540 => |
| 541 42; |
410 var list = [87]; | 542 var list = [87]; |
411 expectEvaluatesTo(42, ()=> fn()); | 543 expectEvaluatesTo(42, () => fn()); |
412 expectEvaluatesTo(1, ()=> list.length); | 544 expectEvaluatesTo(1, () => list.length); |
413 expectEvaluatesTo(87, ()=> list[0]); | 545 expectEvaluatesTo(87, () => list[0]); |
414 expectEvaluatesTo(87, ()=> list.removeLast()); | 546 expectEvaluatesTo(87, () => list.removeLast()); |
415 } | 547 } |
416 | 548 |
417 static void testInitializers | 549 static void testInitializers |
418 /* //# 67: compile-time error | 550 /* //# 67: compile-time error |
419 () | 551 () |
420 */ //# 67: continued | 552 */ //# 67: continued |
421 { | 553 { |
422 Expect.equals(42, (new C.cb0().fn)()); | 554 Expect.equals(42, (new C.cb0().fn)()); |
423 Expect.equals(43, (new C.ca0().fn)()); | 555 Expect.equals(43, (new C.ca0().fn)()); |
424 Expect.equals(44, (new C.cb1().fn)()); | 556 Expect.equals(44, (new C.cb1().fn)()); |
425 Expect.equals(45, (new C.ca1().fn)()); | 557 Expect.equals(45, (new C.ca1().fn)()); |
426 Expect.equals(46, (new C.cb2().fn)()); | 558 Expect.equals(46, (new C.cb2().fn)()); |
427 Expect.equals(47, (new C.ca2().fn)()); | 559 Expect.equals(47, (new C.ca2().fn)()); |
428 Expect.equals(48, (new C.cb3().fn)()); | 560 Expect.equals(48, (new C.cb3().fn)()); |
429 Expect.equals(49, (new C.ca3().fn)()); | 561 Expect.equals(49, (new C.ca3().fn)()); |
430 | 562 |
431 Expect.equals(52, (new C.nb0().fn)()); | 563 Expect.equals(52, (new C.nb0().fn)()); |
(...skipping 10 matching lines...) Expand all Loading... |
442 Expect.equals(64, (new C.rb1().fn)()); | 574 Expect.equals(64, (new C.rb1().fn)()); |
443 Expect.equals(65, (new C.ra1().fn)()); | 575 Expect.equals(65, (new C.ra1().fn)()); |
444 Expect.equals(66, (new C.rb2().fn)()); | 576 Expect.equals(66, (new C.rb2().fn)()); |
445 Expect.equals(67, (new C.ra2().fn)()); | 577 Expect.equals(67, (new C.ra2().fn)()); |
446 Expect.equals(68, (new C.rb3().fn)()); | 578 Expect.equals(68, (new C.rb3().fn)()); |
447 Expect.equals(69, (new C.ra3().fn)()); | 579 Expect.equals(69, (new C.ra3().fn)()); |
448 } | 580 } |
449 | 581 |
450 static void testFunctionParameter | 582 static void testFunctionParameter |
451 /* //# 68: compile-time error | 583 /* //# 68: compile-time error |
452 () | 584 () |
453 */ //# 68: continued | 585 */ //# 68: continued |
454 { | 586 { |
455 f0(fn()) => fn(); | 587 f0(fn()) => fn(); |
456 Expect.equals(42, f0(()=> 42)); | 588 Expect.equals(42, f0(() => 42)); |
457 | 589 |
458 f1(int fn()) => fn(); | 590 f1(int fn()) => fn(); |
459 Expect.equals(87, f1(()=> 87)); | 591 Expect.equals(87, f1(() => 87)); |
460 | 592 |
461 f2(fn(a)) => fn(42); | 593 f2(fn(a)) => fn(42); |
462 Expect.equals(43, f2((a)=> a + 1)); | 594 Expect.equals(43, f2((a) => a + 1)); |
463 | 595 |
464 f3(fn(int a)) => fn(42); | 596 f3(fn(int a)) => fn(42); |
465 Expect.equals(44, f3((int a)=> a + 2)); | 597 Expect.equals(44, f3((int a) => a + 2)); |
466 } | 598 } |
467 | 599 |
468 static void testFunctionIdentifierExpression | 600 static void testFunctionIdentifierExpression |
469 /* //# 69: compile-time error | 601 /* //# 69: compile-time error |
470 () | 602 () |
471 */ //# 69: continued | 603 */ //# 69: continued |
472 { | 604 { |
473 Expect.equals(87, ( | 605 Expect.equals( |
| 606 87, |
| 607 ( |
474 /* //# 70: compile-time error | 608 /* //# 70: compile-time error |
475 () | 609 () |
476 */ //# 70: continued | 610 */ //# 70: continued |
477 => 87)()); | 611 => |
| 612 87)()); |
478 } | 613 } |
479 | 614 |
480 static void testFunctionIdentifierStatement | 615 static void testFunctionIdentifierStatement |
481 /* //# 71: compile-time error | 616 /* //# 71: compile-time error |
482 () | 617 () |
483 */ //# 71: continued | 618 */ //# 71: continued |
484 { | 619 { |
485 function | 620 function |
486 /* //# 72: compile-time error | 621 /* //# 72: compile-time error |
487 () | 622 () |
488 */ //# 72: continued | 623 */ //# 72: continued |
489 => 42; | 624 => |
| 625 42; |
490 Expect.equals(42, function()); | 626 Expect.equals(42, function()); |
491 Expect.equals(true, function is Function); | 627 Expect.equals(true, function is Function); |
492 } | 628 } |
493 | |
494 } | 629 } |
495 | 630 |
| 631 class C { |
| 632 C.cb0() |
| 633 : fn = (() { |
| 634 return 42; |
| 635 }) {} |
| 636 C.ca0() : fn = (() => 43) {} |
496 | 637 |
497 class C { | 638 C.cb1() |
| 639 : fn = wrap(() { |
| 640 return 44; |
| 641 }) {} |
| 642 C.ca1() : fn = wrap(() => 45) {} |
498 | 643 |
499 C.cb0() : fn = (() { return 42; }) { } | 644 C.cb2() |
500 C.ca0() : fn = (() => 43) { } | 645 : fn = [ |
| 646 () { |
| 647 return 46; |
| 648 } |
| 649 ][0] {} |
| 650 C.ca2() : fn = [() => 47][0] {} |
501 | 651 |
502 C.cb1() : fn = wrap(() { return 44; }) { } | 652 C.cb3() |
503 C.ca1() : fn = wrap(()=> 45) { } | 653 : fn = { |
| 654 'x': () { |
| 655 return 48; |
| 656 } |
| 657 }['x'] {} |
| 658 C.ca3() : fn = {'x': () => 49}['x'] {} |
504 | 659 |
505 C.cb2() : fn = [() { return 46; }][0] { } | 660 C.nb0() |
506 C.ca2() : fn = [() => 47][0] { } | 661 : fn = (() { |
| 662 return 52; |
| 663 }) {} |
| 664 C.na0() : fn = (() => 53) {} |
507 | 665 |
508 C.cb3() : fn = {'x': () { return 48; }}['x'] { } | 666 C.nb1() |
509 C.ca3() : fn = {'x': () => 49}['x'] { } | 667 : fn = wrap(() { |
| 668 return 54; |
| 669 }) {} |
| 670 C.na1() : fn = wrap(() => 55) {} |
510 | 671 |
511 C.nb0() : fn = (() { return 52; }) { } | 672 C.nb2() |
512 C.na0() : fn = (() => 53) { } | 673 : fn = [ |
| 674 () { |
| 675 return 56; |
| 676 } |
| 677 ][0] {} |
| 678 C.na2() : fn = [() => 57][0] {} |
513 | 679 |
514 C.nb1() : fn = wrap(() { return 54; }) { } | 680 C.nb3() |
515 C.na1() : fn = wrap(()=> 55) { } | 681 : fn = { |
| 682 'x': () { |
| 683 return 58; |
| 684 } |
| 685 }['x'] {} |
| 686 C.na3() : fn = {'x': () => 59}['x'] {} |
516 | 687 |
517 C.nb2() : fn = [() { return 56; }][0] { } | 688 C.rb0() |
518 C.na2() : fn = [() => 57][0] { } | 689 : fn = (() { |
| 690 return 62; |
| 691 }) {} |
| 692 C.ra0() : fn = (() => 63) {} |
519 | 693 |
520 C.nb3() : fn = {'x': () { return 58; }}['x'] { } | 694 C.rb1() |
521 C.na3() : fn = {'x': () => 59}['x'] { } | 695 : fn = wrap(() { |
| 696 return 64; |
| 697 }) {} |
| 698 C.ra1() : fn = wrap(() => 65) {} |
522 | 699 |
523 C.rb0() : fn = (() { return 62; }) { } | 700 C.rb2() |
524 C.ra0() : fn = (() => 63) { } | 701 : fn = [ |
| 702 () { |
| 703 return 66; |
| 704 } |
| 705 ][0] {} |
| 706 C.ra2() : fn = [() => 67][0] {} |
525 | 707 |
526 C.rb1() : fn = wrap(() { return 64; }) { } | 708 C.rb3() |
527 C.ra1() : fn = wrap(()=> 65) { } | 709 : fn = { |
528 | 710 'x': () { |
529 C.rb2() : fn = [() { return 66; }][0] { } | 711 return 68; |
530 C.ra2() : fn = [() => 67][0] { } | 712 } |
531 | 713 }['x'] {} |
532 C.rb3() : fn = {'x': () { return 68; }}['x'] { } | 714 C.ra3() : fn = {'x': () => 69}['x'] {} |
533 C.ra3() : fn = {'x': () => 69}['x'] { } | |
534 | 715 |
535 static wrap | 716 static wrap |
536 /* //# 73: compile-time error | 717 /* //# 73: compile-time error |
537 (fn) | 718 (fn) |
538 */ //# 73: continued | 719 */ //# 73: continued |
539 { return fn; } | 720 { |
| 721 return fn; |
| 722 } |
540 | 723 |
541 final fn; | 724 final fn; |
542 | |
543 } | 725 } |
544 | 726 |
545 main | 727 main |
546 /* //# 74: compile-time error | 728 /* //# 74: compile-time error |
547 () | 729 () |
548 */ //# 74: continued | 730 */ //# 74: continued |
549 { | 731 { |
550 FunctionSyntaxTest.testMain(); | 732 FunctionSyntaxTest.testMain(); |
551 } | 733 } |
OLD | NEW |