| 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 // Dart test program for testing named parameters. | 4 // Dart test program for testing named parameters. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 | 8 |
| 9 class TypeTester<T> {} | 9 class TypeTester<T> {} |
| 10 | 10 |
| 11 // Expect compile-time error as no default values are allowed | 11 // Expect compile-time error as no default values are allowed |
| 12 // in closure type definitions. | 12 // in closure type definitions. |
| 13 typedef void Callback([String msg | 13 typedef void Callback([String msg |
| 14 = "" /// 01: compile-time error | 14 = "" // /// 01: compile-time error |
| 15 ]); | 15 ]); |
| 16 | 16 |
| 17 class NamedParametersAggregatedTests { | 17 class NamedParametersAggregatedTests { |
| 18 | 18 |
| 19 static int F31(int a, {int b: 20, int c: 30}) { | 19 static int F31(int a, {int b: 20, int c: 30}) { |
| 20 return 100*(100*a + b) + c; | 20 return 100*(100*a + b) + c; |
| 21 } | 21 } |
| 22 | 22 |
| 23 static int f_missing_comma(a | 23 static int f_missing_comma(a |
| 24 [b = 42] /// 02: compile-time error | 24 [b = 42] /// 02: compile-time error |
| 25 ) => a; | 25 ) => a; |
| 26 | 26 |
| 27 var _handler = null; | 27 var _handler = null; |
| 28 | 28 |
| 29 // Expect compile-time error as no default values | 29 // Expect compile-time error as no default values |
| 30 // are allowed in closure type. | 30 // are allowed in closure type. |
| 31 void InstallCallback(void cb({String msg | 31 void InstallCallback(void cb({String msg |
| 32 : null /// 03: compile-time error | 32 : null /// 03: compile-time error |
| 33 })) { | 33 })) { |
| 34 _handler = cb; | 34 _handler = cb; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 main() { | 40 main() { |
| 41 // Expect compile-time error due to missing comma in function definition. | 41 // Expect compile-time error due to missing comma in function definition. |
| 42 NamedParametersAggregatedTests.f_missing_comma(10 | 42 NamedParametersAggregatedTests.f_missing_comma(10 |
| 43 , 25 /// 02: continued | 43 , 25 // /// 02: continued |
| 44 ); | 44 ); |
| 45 | 45 |
| 46 // Expect compile-time erorr due to duplicate named argument. | 46 // Expect compile-time erorr due to duplicate named argument. |
| 47 NamedParametersAggregatedTests.F31(10, b:25 | 47 NamedParametersAggregatedTests.F31(10, b:25 |
| 48 , b:35 /// 04: compile-time error | 48 , b:35 // /// 04: compile-time error |
| 49 ); | 49 ); |
| 50 | 50 |
| 51 // Expect compile-time error due to missing positional argument. | 51 // Expect compile-time error due to missing positional argument. |
| 52 Expect.throws(() => NamedParametersAggregatedTests.F31(b:25, c:35), (e) => e i
s NoSuchMethodError); /// 05: static type warning | 52 Expect.throws(() => NamedParametersAggregatedTests.F31(b:25, c:35), (e) => e i
s NoSuchMethodError); // /// 05: static type warning |
| 53 | 53 |
| 54 new TypeTester<Callback>(); | 54 new TypeTester<Callback>(); |
| 55 | 55 |
| 56 (new NamedParametersAggregatedTests()).InstallCallback(null); | 56 (new NamedParametersAggregatedTests()).InstallCallback(null); |
| 57 | 57 |
| 58 } | 58 } |
| OLD | NEW |