| 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 // Tests function statement and expression syntax. | 5 // Tests function statement and expression syntax. |
| 6 | 6 |
| 7 class FunctionSyntaxTest { | 7 class FunctionSyntaxTest { |
| 8 | 8 |
| 9 static void testMain() { | 9 static void testMain |
| 10 /* /// 00: compile-time error |
| 11 () |
| 12 */ /// 00: continued |
| 13 { |
| 10 testNestedFunctions(); | 14 testNestedFunctions(); |
| 11 testFunctionExpressions(); | 15 testFunctionExpressions(); |
| 12 testPrecedence(); | 16 testPrecedence(); |
| 13 testInitializers(); | 17 testInitializers(); |
| 14 testFunctionParameter(); | 18 testFunctionParameter(); |
| 15 testFunctionIdentifierExpression(); | 19 testFunctionIdentifierExpression(); |
| 16 testFunctionIdentifierStatement(); | 20 testFunctionIdentifierStatement(); |
| 17 } | 21 } |
| 18 | 22 |
| 19 static void testNestedFunctions() { | 23 static void testNestedFunctions |
| 24 /* /// 01: compile-time error |
| 25 () |
| 26 */ /// 01: continued |
| 27 { |
| 20 // No types - braces. | 28 // No types - braces. |
| 21 nb0() { return 42; } | 29 nb0 |
| 22 nb1(a) { return a; } | 30 /* /// 02: compile-time error |
| 23 nb2(a, b) { return a + b; } | 31 () |
| 32 */ /// 02: continued |
| 33 { return 42; } |
| 34 nb1 |
| 35 /* /// 03: compile-time error |
| 36 (a) |
| 37 */ /// 03: continued |
| 38 { return a; } |
| 39 nb2 |
| 40 /* /// 04: compile-time error |
| 41 (a, b) |
| 42 */ /// 04: continued |
| 43 { return a + b; } |
| 24 Expect.equals(42, nb0()); | 44 Expect.equals(42, nb0()); |
| 25 Expect.equals(87, nb1(87)); | 45 Expect.equals(87, nb1(87)); |
| 26 Expect.equals(1 + 2, nb2(1, 2)); | 46 Expect.equals(1 + 2, nb2(1, 2)); |
| 27 | 47 |
| 28 // No types - arrows. | 48 // No types - arrows. |
| 29 na0() => 42; | 49 na0 |
| 30 na1(a) => a; | 50 /* /// 05: compile-time error |
| 31 na2(a, b) => a + b; | 51 () |
| 52 */ /// 05: continued |
| 53 => 42; |
| 54 na1 |
| 55 /* /// 06: compile-time error |
| 56 (a) |
| 57 */ /// 06: continued |
| 58 => a; |
| 59 na2 |
| 60 /* /// 07: compile-time error |
| 61 (a, b) |
| 62 */ /// 07: continued |
| 63 => a + b; |
| 32 Expect.equals(42, na0()); | 64 Expect.equals(42, na0()); |
| 33 Expect.equals(87, na1(87)); | 65 Expect.equals(87, na1(87)); |
| 34 Expect.equals(1 + 2, na2(1, 2)); | 66 Expect.equals(1 + 2, na2(1, 2)); |
| 35 | 67 |
| 36 // Return type - braces. | 68 // Return type - braces. |
| 37 int rb0() { return 42; } | 69 int rb0 |
| 38 int rb1(a) { return a; } | 70 /* /// 08: compile-time error |
| 39 int rb2(a, b) { return a + b; } | 71 () |
| 72 */ /// 08: continued |
| 73 { return 42; } |
| 74 int rb1 |
| 75 /* /// 09: compile-time error |
| 76 (a) |
| 77 */ /// 09: continued |
| 78 { return a; } |
| 79 int rb2 |
| 80 /* /// 10: compile-time error |
| 81 (a, b) |
| 82 */ /// 10: continued |
| 83 { return a + b; } |
| 40 Expect.equals(42, rb0()); | 84 Expect.equals(42, rb0()); |
| 41 Expect.equals(87, rb1(87)); | 85 Expect.equals(87, rb1(87)); |
| 42 Expect.equals(1 + 2, rb2(1, 2)); | 86 Expect.equals(1 + 2, rb2(1, 2)); |
| 43 | 87 |
| 44 // Return type - arrows. | 88 // Return type - arrows. |
| 45 int ra0() => 42; | 89 int ra0 |
| 46 int ra1(a) => a; | 90 /* /// 11: compile-time error |
| 47 int ra2(a, b) => a + b; | 91 () |
| 92 */ /// 11: continued |
| 93 => 42; |
| 94 int ra1 |
| 95 /* /// 12: compile-time error |
| 96 (a) |
| 97 */ /// 12: continued |
| 98 => a; |
| 99 int ra2 |
| 100 /* /// 13: compile-time error |
| 101 (a, b) |
| 102 */ /// 13: continued |
| 103 => a + b; |
| 48 Expect.equals(42, ra0()); | 104 Expect.equals(42, ra0()); |
| 49 Expect.equals(87, ra1(87)); | 105 Expect.equals(87, ra1(87)); |
| 50 Expect.equals(1 + 2, ra2(1, 2)); | 106 Expect.equals(1 + 2, ra2(1, 2)); |
| 51 | 107 |
| 52 // Fully typed - braces. | 108 // Fully typed - braces. |
| 53 int fb1(int a) { return a; } | 109 int fb1 |
| 54 int fb2(int a, int b) { return a + b; } | 110 /* /// 14: compile-time error |
| 111 (int a) |
| 112 */ /// 14: continued |
| 113 { return a; } |
| 114 int fb2 |
| 115 /* /// 15: compile-time error |
| 116 (int a, int b) |
| 117 */ /// 15: continued |
| 118 { return a + b; } |
| 55 Expect.equals(42, rb0()); | 119 Expect.equals(42, rb0()); |
| 56 Expect.equals(87, rb1(87)); | 120 Expect.equals(87, rb1(87)); |
| 57 Expect.equals(1 + 2, rb2(1, 2)); | 121 Expect.equals(1 + 2, rb2(1, 2)); |
| 58 | 122 |
| 59 // Fully typed - arrows. | 123 // Fully typed - arrows. |
| 60 int fa1(int a) => a; | 124 int fa1 |
| 61 int fa2(int a, int b) => a + b; | 125 /* /// 16: compile-time error |
| 126 (int a) |
| 127 */ /// 16: continued |
| 128 => a; |
| 129 int fa2 |
| 130 /* /// 17: compile-time error |
| 131 (int a, int b) |
| 132 */ /// 17: continued |
| 133 => a + b; |
| 62 Expect.equals(42, ra0()); | 134 Expect.equals(42, ra0()); |
| 63 Expect.equals(87, ra1(87)); | 135 Expect.equals(87, ra1(87)); |
| 64 Expect.equals(1 + 2, ra2(1, 2)); | 136 Expect.equals(1 + 2, ra2(1, 2)); |
| 65 | 137 |
| 66 // Generic types - braces. | 138 // Generic types - braces. |
| 67 List<int> gb0() { return [42]; } | 139 List<int> gb0 |
| 68 List<int> gb1(List<int> a) { return a; } | 140 /* /// 18: compile-time error |
| 141 () |
| 142 */ /// 18: continued |
| 143 { return [42]; } |
| 144 List<int> gb1 |
| 145 /* /// 19: compile-time error |
| 146 (List<int> a) |
| 147 */ /// 19: continued |
| 148 { return a; } |
| 69 Expect.equals(42, gb0()[0]); | 149 Expect.equals(42, gb0()[0]); |
| 70 Expect.equals(87, gb1([87])[0]); | 150 Expect.equals(87, gb1([87])[0]); |
| 71 | 151 |
| 72 // Generic types - arrows. | 152 // Generic types - arrows. |
| 73 List<int> ga0() => [42]; | 153 List<int> ga0 |
| 74 List<int> ga1(List<int> a) => a; | 154 /* /// 20: compile-time error |
| 155 () |
| 156 */ /// 20: continued |
| 157 => [42]; |
| 158 List<int> ga1 |
| 159 /* /// 21: compile-time error |
| 160 (List<int> a) |
| 161 */ /// 21: continued |
| 162 => a; |
| 75 Expect.equals(42, ga0()[0]); | 163 Expect.equals(42, ga0()[0]); |
| 76 Expect.equals(87, ga1([87])[0]); | 164 Expect.equals(87, ga1([87])[0]); |
| 77 } | 165 } |
| 78 | 166 |
| 79 static void testFunctionExpressions() { | 167 static void testFunctionExpressions |
| 80 eval0(fn) => fn(); | 168 /* /// 22: compile-time error |
| 81 eval1(fn, a) => fn(a); | 169 () |
| 82 eval2(fn, a, b) => fn(a, b); | 170 */ /// 22: continued |
| 171 { |
| 172 eval0 |
| 173 /* /// 23: compile-time error |
| 174 (fn) |
| 175 */ /// 23: continued |
| 176 => fn(); |
| 177 eval1 |
| 178 /* /// 24: compile-time error |
| 179 (fn, a) |
| 180 */ /// 24: continued |
| 181 => fn(a); |
| 182 eval2 |
| 183 /* /// 25: compile-time error |
| 184 (fn, a, b) |
| 185 */ /// 25: continued |
| 186 => fn(a, b); |
| 83 | 187 |
| 84 // No types - braces. | 188 // No types - braces. |
| 85 Expect.equals(42, eval0(() { return 42; })); | 189 Expect.equals(42, eval0( |
| 86 Expect.equals(87, eval1((a) { return a; }, 87)); | 190 /* /// 26: compile-time error |
| 87 Expect.equals(1 + 2, eval2((a, b) { return a + b; }, 1, 2)); | 191 () |
| 88 Expect.equals(42, eval0(nb0() { return 42; })); | 192 */ /// 26: continued |
| 89 Expect.equals(87, eval1(nb1(a) { return a; }, 87)); | 193 { return 42; })); |
| 90 Expect.equals(1 + 2, eval2(nb2(a, b) { return a + b; }, 1, 2)); | 194 Expect.equals(87, eval1( |
| 195 /* /// 27: compile-time error |
| 196 (a) |
| 197 */ /// 27: continued |
| 198 { return a; }, 87)); |
| 199 Expect.equals(1 + 2, eval2( |
| 200 /* /// 28: compile-time error |
| 201 (a, b) |
| 202 */ /// 28: continued |
| 203 { return a + b; }, 1, 2)); |
| 204 Expect.equals(42, eval0(nb0 |
| 205 /* /// 29: compile-time error |
| 206 () |
| 207 */ /// 29: continued |
| 208 { return 42; })); |
| 209 Expect.equals(87, eval1(nb1 |
| 210 /* /// 30: compile-time error |
| 211 (a) |
| 212 */ /// 30: continued |
| 213 { return a; }, 87)); |
| 214 Expect.equals(1 + 2, eval2(nb2 |
| 215 /* /// 31: compile-time error |
| 216 (a, b) |
| 217 */ /// 31: continued |
| 218 { return a + b; }, 1, 2)); |
| 91 | 219 |
| 92 // No types - arrows. | 220 // No types - arrows. |
| 93 Expect.equals(42, eval0(() => 42)); | 221 Expect.equals(42, eval0( |
| 94 Expect.equals(87, eval1((a) => a, 87)); | 222 /* /// 32: compile-time error |
| 95 Expect.equals(1 + 2, eval2((a, b) => a + b, 1, 2)); | 223 () |
| 96 Expect.equals(42, eval0(na0() => 42)); | 224 */ /// 32: continued |
| 97 Expect.equals(87, eval1(na1(a) => a, 87)); | 225 => 42)); |
| 98 Expect.equals(1 + 2, eval2(na2(a, b) => a + b, 1, 2)); | 226 Expect.equals(87, eval1( |
| 227 /* /// 33: compile-time error |
| 228 (a) |
| 229 */ /// 33: continued |
| 230 => a, 87)); |
| 231 Expect.equals(1 + 2, eval2( |
| 232 /* /// 34: compile-time error |
| 233 (a, b) |
| 234 */ /// 34: continued |
| 235 => a + b, 1, 2)); |
| 236 Expect.equals(42, eval0(na0 |
| 237 /* /// 35: compile-time error |
| 238 () |
| 239 */ /// 35: continued |
| 240 => 42)); |
| 241 Expect.equals(87, eval1(na1 |
| 242 /* /// 36: compile-time error |
| 243 (a) |
| 244 */ /// 36: continued |
| 245 => a, 87)); |
| 246 Expect.equals(1 + 2, eval2(na2 |
| 247 /* /// 37: compile-time error |
| 248 (a, b) |
| 249 */ /// 37: continued |
| 250 => a + b, 1, 2)); |
| 99 | 251 |
| 100 // Return type - braces. | 252 // Return type - braces. |
| 101 Expect.equals(42, eval0(int rb0() { return 42; })); | 253 Expect.equals(42, eval0(int rb0 |
| 102 Expect.equals(87, eval1(int rb1(a) { return a; }, 87)); | 254 /* /// 38: compile-time error |
| 103 Expect.equals(1 + 2, eval2(int rb2(a, b) { return a + b; }, 1, 2)); | 255 () |
| 256 */ /// 38: continued |
| 257 { return 42; })); |
| 258 Expect.equals(87, eval1(int rb1 |
| 259 /* /// 39: compile-time error |
| 260 (a) |
| 261 */ /// 39: continued |
| 262 { return a; }, 87)); |
| 263 Expect.equals(1 + 2, eval2(int rb2 |
| 264 /* /// 40: compile-time error |
| 265 (a, b) |
| 266 */ /// 40: continued |
| 267 { return a + b; }, 1, 2)); |
| 104 | 268 |
| 105 // Return type - arrows. | 269 // Return type - arrows. |
| 106 Expect.equals(42, eval0(int ra0() => 42)); | 270 Expect.equals(42, eval0(int ra0 |
| 107 Expect.equals(87, eval1(int ra1(a) => a, 87)); | 271 /* /// 41: compile-time error |
| 108 Expect.equals(1 + 2, eval2(int ra2(a, b) => a + b, 1, 2)); | 272 () |
| 273 */ /// 41: continued |
| 274 => 42)); |
| 275 Expect.equals(87, eval1(int ra1 |
| 276 /* /// 42: compile-time error |
| 277 (a) |
| 278 */ /// 42: continued |
| 279 => a, 87)); |
| 280 Expect.equals(1 + 2, eval2(int ra2 |
| 281 /* /// 43: compile-time error |
| 282 (a, b) |
| 283 */ /// 43: continued |
| 284 => a + b, 1, 2)); |
| 109 | 285 |
| 110 // Argument types - braces. | 286 // Argument types - braces. |
| 111 Expect.equals(42, eval0(() { return 42; })); | 287 Expect.equals(42, eval0( |
| 112 Expect.equals(87, eval1((int a) { return a; }, 87)); | 288 /* /// 44: compile-time error |
| 113 Expect.equals(1 + 2, eval2((int a, int b) { return a + b; }, 1, 2)); | 289 () |
| 114 Expect.equals(42, eval0( ab0() { return 42; })); | 290 */ /// 44: continued |
| 115 Expect.equals(87, eval1(ab1(int a) { return a; }, 87)); | 291 { return 42; })); |
| 116 Expect.equals(1 + 2, eval2(ab2(int a, int b) { return a + b; }, 1, 2)); | 292 Expect.equals(87, eval1( |
| 293 /* /// 45: compile-time error |
| 294 (int a) |
| 295 */ /// 45: continued |
| 296 { return a; }, 87)); |
| 297 Expect.equals(1 + 2, eval2( |
| 298 /* /// 46: compile-time error |
| 299 (int a, int b) |
| 300 */ /// 46: continued |
| 301 { return a + b; }, 1, 2)); |
| 302 Expect.equals(42, eval0( ab0 |
| 303 /* /// 47: compile-time error |
| 304 () |
| 305 */ /// 47: continued |
| 306 { return 42; })); |
| 307 Expect.equals(87, eval1(ab1 |
| 308 /* /// 48: compile-time error |
| 309 (int a) |
| 310 */ /// 48: continued |
| 311 { return a; }, 87)); |
| 312 Expect.equals(1 + 2, eval2(ab2 |
| 313 /* /// 49: compile-time error |
| 314 (int a, int b) |
| 315 */ /// 49: continued |
| 316 { return a + b; }, 1, 2)); |
| 117 | 317 |
| 118 // Argument types - arrows. | 318 // Argument types - arrows. |
| 119 Expect.equals(42, eval0(() => 42)); | 319 Expect.equals(42, eval0( |
| 120 Expect.equals(87, eval1((int a) => a, 87)); | 320 /* /// 50: compile-time error |
| 121 Expect.equals(1 + 2, eval2((int a, int b) => a + b, 1, 2)); | 321 () |
| 122 Expect.equals(42, eval0(aa0() => 42)); | 322 */ /// 50: continued |
| 123 Expect.equals(87, eval1(aa1(int a) => a, 87)); | 323 => 42)); |
| 124 Expect.equals(1 + 2, eval2(aa2(int a, int b) => a + b, 1, 2)); | 324 Expect.equals(87, eval1( |
| 325 /* /// 51: compile-time error |
| 326 (int a) |
| 327 */ /// 51: continued |
| 328 => a, 87)); |
| 329 Expect.equals(1 + 2, eval2( |
| 330 /* /// 52: compile-time error |
| 331 (int a, int b) |
| 332 */ /// 52: continued |
| 333 => a + b, 1, 2)); |
| 334 Expect.equals(42, eval0(aa0 |
| 335 /* /// 53: compile-time error |
| 336 () |
| 337 */ /// 53: continued |
| 338 => 42)); |
| 339 Expect.equals(87, eval1(aa1 |
| 340 /* /// 54: compile-time error |
| 341 (int a) |
| 342 */ /// 54: continued |
| 343 => a, 87)); |
| 344 Expect.equals(1 + 2, eval2(aa2 |
| 345 /* /// 55: compile-time error |
| 346 (int a, int b) |
| 347 */ /// 55: continued |
| 348 => a + b, 1, 2)); |
| 125 | 349 |
| 126 // Fully typed - braces. | 350 // Fully typed - braces. |
| 127 Expect.equals(87, eval1(int fb1(int a) { return a; }, 87)); | 351 Expect.equals(87, eval1(int fb1 |
| 128 Expect.equals(1 + 2, eval2(int fb2(int a, int b) { return a + b; }, 1, 2)); | 352 /* /// 56: compile-time error |
| 353 (int a) |
| 354 */ /// 56: continued |
| 355 { return a; }, 87)); |
| 356 Expect.equals(1 + 2, eval2(int fb2 |
| 357 /* /// 57: compile-time error |
| 358 (int a, int b) |
| 359 */ /// 57: continued |
| 360 { return a + b; }, 1, 2)); |
| 129 | 361 |
| 130 // Fully typed - arrows. | 362 // Fully typed - arrows. |
| 131 Expect.equals(87, eval1(int fa1(int a) => a, 87)); | 363 Expect.equals(87, eval1(int fa1 |
| 132 Expect.equals(1 + 2, eval2(int fa2(int a, int b) => a + b, 1, 2)); | 364 /* /// 58: compile-time error |
| 365 (int a) |
| 366 */ /// 58: continued |
| 367 => a, 87)); |
| 368 Expect.equals(1 + 2, eval2(int fa2 |
| 369 /* /// 59: compile-time error |
| 370 (int a, int b) |
| 371 */ /// 59: continued |
| 372 => a + b, 1, 2)); |
| 133 | 373 |
| 134 // Generic types - braces. | 374 // Generic types - braces. |
| 135 Expect.equals(42, eval0(List<int> gb0() { return [42]; })[0]); | 375 Expect.equals(42, eval0(List<int> gb0 |
| 136 Expect.equals(87, eval1(List<int> gb1(List<int> a) { return a; }, [87])[0]); | 376 /* /// 60: compile-time error |
| 377 () |
| 378 */ /// 60: continued |
| 379 { return [42]; })[0]); |
| 380 Expect.equals(87, eval1(List<int> gb1 |
| 381 /* /// 61: compile-time error |
| 382 (List<int> a) |
| 383 */ /// 61: continued |
| 384 { return a; }, [87])[0]); |
| 137 | 385 |
| 138 // Generic types - arrows. | 386 // Generic types - arrows. |
| 139 Expect.equals(42, eval0(List<int> ga0() => [42])[0]); | 387 Expect.equals(42, eval0(List<int> ga0 |
| 140 Expect.equals(87, eval1(List<int> ga1(List<int> a) => a, [87])[0]); | 388 /* /// 62: compile-time error |
| 389 () |
| 390 */ /// 62: continued |
| 391 => [42])[0]); |
| 392 Expect.equals(87, eval1(List<int> ga1 |
| 393 /* /// 63: compile-time error |
| 394 (List<int> a) |
| 395 */ /// 63: continued |
| 396 => a, [87])[0]); |
| 141 } | 397 } |
| 142 | 398 |
| 143 static void testPrecedence() { | 399 static void testPrecedence |
| 144 expectEvaluatesTo(value, fn) { Expect.equals(value, fn()); } | 400 /* /// 64: compile-time error |
| 401 () |
| 402 */ /// 64: continued |
| 403 { |
| 404 expectEvaluatesTo |
| 405 /* /// 65: compile-time error |
| 406 (value, fn) |
| 407 */ /// 65: continued |
| 408 { Expect.equals(value, fn()); } |
| 145 | 409 |
| 146 // Assignment. | 410 // Assignment. |
| 147 var x; | 411 var x; |
| 148 expectEvaluatesTo(42, ()=> x = 42); | 412 expectEvaluatesTo(42, ()=> x = 42); |
| 149 Expect.equals(42, x); | 413 Expect.equals(42, x); |
| 150 x = 1; | 414 x = 1; |
| 151 expectEvaluatesTo(100, ()=> x += 99); | 415 expectEvaluatesTo(100, ()=> x += 99); |
| 152 Expect.equals(100, x); | 416 Expect.equals(100, x); |
| 153 x = 1; | 417 x = 1; |
| 154 expectEvaluatesTo(87, ()=> x *= 87); | 418 expectEvaluatesTo(87, ()=> x *= 87); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 475 |
| 212 // Postfix / prefix. | 476 // Postfix / prefix. |
| 213 var y = 0; | 477 var y = 0; |
| 214 expectEvaluatesTo(0, ()=> y++); | 478 expectEvaluatesTo(0, ()=> y++); |
| 215 expectEvaluatesTo(2, ()=> ++y); | 479 expectEvaluatesTo(2, ()=> ++y); |
| 216 expectEvaluatesTo(1, ()=> --y); | 480 expectEvaluatesTo(1, ()=> --y); |
| 217 expectEvaluatesTo(1, ()=> y--); | 481 expectEvaluatesTo(1, ()=> y--); |
| 218 Expect.equals(0, y); | 482 Expect.equals(0, y); |
| 219 | 483 |
| 220 // Selector. | 484 // Selector. |
| 221 fn() => 42; | 485 fn |
| 486 /* /// 66: compile-time error |
| 487 () |
| 488 */ /// 66: continued |
| 489 => 42; |
| 222 var list = [87]; | 490 var list = [87]; |
| 223 expectEvaluatesTo(42, ()=> fn()); | 491 expectEvaluatesTo(42, ()=> fn()); |
| 224 expectEvaluatesTo(1, ()=> list.length); | 492 expectEvaluatesTo(1, ()=> list.length); |
| 225 expectEvaluatesTo(87, ()=> list[0]); | 493 expectEvaluatesTo(87, ()=> list[0]); |
| 226 expectEvaluatesTo(87, ()=> list.removeLast()); | 494 expectEvaluatesTo(87, ()=> list.removeLast()); |
| 227 } | 495 } |
| 228 | 496 |
| 229 static void testInitializers() { | 497 static void testInitializers |
| 498 /* /// 67: compile-time error |
| 499 () |
| 500 */ /// 67: continued |
| 501 { |
| 230 Expect.equals(42, (new C.cb0().fn)()); | 502 Expect.equals(42, (new C.cb0().fn)()); |
| 231 Expect.equals(43, (new C.ca0().fn)()); | 503 Expect.equals(43, (new C.ca0().fn)()); |
| 232 Expect.equals(44, (new C.cb1().fn)()); | 504 Expect.equals(44, (new C.cb1().fn)()); |
| 233 Expect.equals(45, (new C.ca1().fn)()); | 505 Expect.equals(45, (new C.ca1().fn)()); |
| 234 Expect.equals(46, (new C.cb2().fn)()); | 506 Expect.equals(46, (new C.cb2().fn)()); |
| 235 Expect.equals(47, (new C.ca2().fn)()); | 507 Expect.equals(47, (new C.ca2().fn)()); |
| 236 Expect.equals(48, (new C.cb3().fn)()); | 508 Expect.equals(48, (new C.cb3().fn)()); |
| 237 Expect.equals(49, (new C.ca3().fn)()); | 509 Expect.equals(49, (new C.ca3().fn)()); |
| 238 | 510 |
| 239 Expect.equals(52, (new C.nb0().fn)()); | 511 Expect.equals(52, (new C.nb0().fn)()); |
| 240 Expect.equals(53, (new C.na0().fn)()); | 512 Expect.equals(53, (new C.na0().fn)()); |
| 241 Expect.equals(54, (new C.nb1().fn)()); | 513 Expect.equals(54, (new C.nb1().fn)()); |
| 242 Expect.equals(55, (new C.na1().fn)()); | 514 Expect.equals(55, (new C.na1().fn)()); |
| 243 Expect.equals(56, (new C.nb2().fn)()); | 515 Expect.equals(56, (new C.nb2().fn)()); |
| 244 Expect.equals(57, (new C.na2().fn)()); | 516 Expect.equals(57, (new C.na2().fn)()); |
| 245 Expect.equals(58, (new C.nb3().fn)()); | 517 Expect.equals(58, (new C.nb3().fn)()); |
| 246 Expect.equals(59, (new C.na3().fn)()); | 518 Expect.equals(59, (new C.na3().fn)()); |
| 247 | 519 |
| 248 Expect.equals(62, (new C.rb0().fn)()); | 520 Expect.equals(62, (new C.rb0().fn)()); |
| 249 Expect.equals(63, (new C.ra0().fn)()); | 521 Expect.equals(63, (new C.ra0().fn)()); |
| 250 Expect.equals(64, (new C.rb1().fn)()); | 522 Expect.equals(64, (new C.rb1().fn)()); |
| 251 Expect.equals(65, (new C.ra1().fn)()); | 523 Expect.equals(65, (new C.ra1().fn)()); |
| 252 Expect.equals(66, (new C.rb2().fn)()); | 524 Expect.equals(66, (new C.rb2().fn)()); |
| 253 Expect.equals(67, (new C.ra2().fn)()); | 525 Expect.equals(67, (new C.ra2().fn)()); |
| 254 Expect.equals(68, (new C.rb3().fn)()); | 526 Expect.equals(68, (new C.rb3().fn)()); |
| 255 Expect.equals(69, (new C.ra3().fn)()); | 527 Expect.equals(69, (new C.ra3().fn)()); |
| 256 } | 528 } |
| 257 | 529 |
| 258 static void testFunctionParameter() { | 530 static void testFunctionParameter |
| 531 /* /// 68: compile-time error |
| 532 () |
| 533 */ /// 68: continued |
| 534 { |
| 259 f0(fn()) => fn(); | 535 f0(fn()) => fn(); |
| 260 Expect.equals(42, f0(()=> 42)); | 536 Expect.equals(42, f0(()=> 42)); |
| 261 | 537 |
| 262 f1(int fn()) => fn(); | 538 f1(int fn()) => fn(); |
| 263 Expect.equals(87, f1(()=> 87)); | 539 Expect.equals(87, f1(()=> 87)); |
| 264 | 540 |
| 265 f2(fn(a)) => fn(42); | 541 f2(fn(a)) => fn(42); |
| 266 Expect.equals(43, f2((a)=> a + 1)); | 542 Expect.equals(43, f2((a)=> a + 1)); |
| 267 | 543 |
| 268 f3(fn(int a)) => fn(42); | 544 f3(fn(int a)) => fn(42); |
| 269 Expect.equals(44, f3((int a)=> a + 2)); | 545 Expect.equals(44, f3((int a)=> a + 2)); |
| 270 } | 546 } |
| 271 | 547 |
| 272 static void testFunctionIdentifierExpression() { | 548 static void testFunctionIdentifierExpression |
| 273 Expect.equals(87, (function() => 87)()); | 549 /* /// 69: compile-time error |
| 550 () |
| 551 */ /// 69: continued |
| 552 { |
| 553 Expect.equals(87, (function |
| 554 /* /// 70: compile-time error |
| 555 () |
| 556 */ /// 70: continued |
| 557 => 87)()); |
| 274 } | 558 } |
| 275 | 559 |
| 276 static void testFunctionIdentifierStatement() { | 560 static void testFunctionIdentifierStatement |
| 277 function() => 42; | 561 /* /// 71: compile-time error |
| 562 () |
| 563 */ /// 71: continued |
| 564 { |
| 565 function |
| 566 /* /// 72: compile-time error |
| 567 () |
| 568 */ /// 72: continued |
| 569 => 42; |
| 278 Expect.equals(42, function()); | 570 Expect.equals(42, function()); |
| 279 Expect.equals(true, function is Function); | 571 Expect.equals(true, function is Function); |
| 280 } | 572 } |
| 281 | 573 |
| 282 } | 574 } |
| 283 | 575 |
| 284 | 576 |
| 285 class C { | 577 class C { |
| 286 | 578 |
| 287 C.cb0() : fn = (() { return 42; }) { } | 579 C.cb0() : fn = (() { return 42; }) { } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 313 | 605 |
| 314 C.rb1() : fn = wrap(int _() { return 64; }) { } | 606 C.rb1() : fn = wrap(int _() { return 64; }) { } |
| 315 C.ra1() : fn = wrap(int _()=> 65) { } | 607 C.ra1() : fn = wrap(int _()=> 65) { } |
| 316 | 608 |
| 317 C.rb2() : fn = [int _() { return 66; }][0] { } | 609 C.rb2() : fn = [int _() { return 66; }][0] { } |
| 318 C.ra2() : fn = [int _() => 67][0] { } | 610 C.ra2() : fn = [int _() => 67][0] { } |
| 319 | 611 |
| 320 C.rb3() : fn = {'x': int _() { return 68; }}['x'] { } | 612 C.rb3() : fn = {'x': int _() { return 68; }}['x'] { } |
| 321 C.ra3() : fn = {'x': int _() => 69}['x'] { } | 613 C.ra3() : fn = {'x': int _() => 69}['x'] { } |
| 322 | 614 |
| 323 static wrap(fn) { return fn; } | 615 static wrap |
| 616 /* /// 73: compile-time error |
| 617 (fn) |
| 618 */ /// 73: continued |
| 619 { return fn; } |
| 324 | 620 |
| 325 final fn; | 621 final fn; |
| 326 | 622 |
| 327 } | 623 } |
| 328 | 624 |
| 329 main() { | 625 main |
| 626 /* /// 74: compile-time error |
| 627 () |
| 628 */ /// 74: continued |
| 629 { |
| 330 FunctionSyntaxTest.testMain(); | 630 FunctionSyntaxTest.testMain(); |
| 331 } | 631 } |
| OLD | NEW |