| OLD | NEW |
| 1 // Copyright (c) 2012, 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 // Dart test program for testing optional named parameters. | 4 // Dart test program for testing optional named parameters. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 | |
| 9 class OptionalNamedParametersTest { | 8 class OptionalNamedParametersTest { |
| 10 | |
| 11 static int F00() { | 9 static int F00() { |
| 12 return 0; | 10 return 0; |
| 13 } | 11 } |
| 14 | 12 |
| 15 int f11() { | 13 int f11() { |
| 16 return 0; | 14 return 0; |
| 17 } | 15 } |
| 18 | 16 |
| 19 static int F11(int a) { | 17 static int F11(int a) { |
| 20 return a; | 18 return a; |
| 21 } | 19 } |
| 22 | 20 |
| 23 int f22(int a) { | 21 int f22(int a) { |
| 24 return a; | 22 return a; |
| 25 } | 23 } |
| 26 | 24 |
| 27 static int F10({int b: 20}) { | 25 static int F10({int b: 20}) { |
| 28 return b; | 26 return b; |
| 29 } | 27 } |
| 30 | 28 |
| 31 int f21({int b: 20}) { | 29 int f21({int b: 20}) { |
| 32 return b; | 30 return b; |
| 33 } | 31 } |
| 34 | 32 |
| 35 static int F21(int a, {int b: 20}) { | 33 static int F21(int a, {int b: 20}) { |
| 36 return 100*a + b; | 34 return 100 * a + b; |
| 37 } | 35 } |
| 38 | 36 |
| 39 int f32(int a, {int b: 20}) { | 37 int f32(int a, {int b: 20}) { |
| 40 return 100*a + b; | 38 return 100 * a + b; |
| 41 } | 39 } |
| 42 | 40 |
| 43 static int F31(int a, {int b: 20, int c: 30}) { | 41 static int F31(int a, {int b: 20, int c: 30}) { |
| 44 return 100*(100*a + b) + c; | 42 return 100 * (100 * a + b) + c; |
| 45 } | 43 } |
| 46 | 44 |
| 47 int f42(int a, {int b: 20, int c: 30}) { | 45 int f42(int a, {int b: 20, int c: 30}) { |
| 48 return 100*(100*a + b) + c; | 46 return 100 * (100 * a + b) + c; |
| 49 } | 47 } |
| 50 | 48 |
| 51 static int F41(int a, {int b: 20, int c, int d: 40}) { | 49 static int F41(int a, {int b: 20, int c, int d: 40}) { |
| 52 return 100*(100*(100*a + b) + ((c != null) ? c : 0)) + d; | 50 return 100 * (100 * (100 * a + b) + ((c != null) ? c : 0)) + d; |
| 53 } | 51 } |
| 54 | 52 |
| 55 int f52(int a, {int b: 20, int c, int d: 40}) { | 53 int f52(int a, {int b: 20, int c, int d: 40}) { |
| 56 return 100*(100*(100*a + b) + ((c != null) ? c : 0)) + d; | 54 return 100 * (100 * (100 * a + b) + ((c != null) ? c : 0)) + d; |
| 57 } | 55 } |
| 58 | 56 |
| 59 static void test() { | 57 static void test() { |
| 60 OptionalNamedParametersTest np = new OptionalNamedParametersTest(); | 58 OptionalNamedParametersTest np = new OptionalNamedParametersTest(); |
| 61 Expect.equals(0, F00()); | 59 Expect.equals(0, F00()); |
| 62 Expect.equals(0, np.f11()); | 60 Expect.equals(0, np.f11()); |
| 63 Expect.equals(10, F11(10)); | 61 Expect.equals(10, F11(10)); |
| 64 Expect.equals(10, np.f22(10)); | 62 Expect.equals(10, np.f22(10)); |
| 65 Expect.equals(20, F10()); | 63 Expect.equals(20, F10()); |
| 66 Expect.equals(20, np.f21()); | 64 Expect.equals(20, np.f21()); |
| 67 Expect.equals(20, F10(20)); // //# 01: runtime error | 65 Expect.equals(20, F10(20)); // //# 01: runtime error |
| 68 Expect.equals(20, np.f21(20)); // //# 02: runtime error | 66 Expect.equals(20, np.f21(20)); // //# 02: runtime error |
| 69 Expect.equals(20, F10(b:20)); | 67 Expect.equals(20, F10(b: 20)); |
| 70 Expect.equals(20, np.f21(b:20)); | 68 Expect.equals(20, np.f21(b: 20)); |
| 71 Expect.equals(1020, F21(10)); | 69 Expect.equals(1020, F21(10)); |
| 72 Expect.equals(1020, np.f32(10)); | 70 Expect.equals(1020, np.f32(10)); |
| 73 Expect.equals(1025, F21(10, 25)); // //# 03: runtime error | 71 Expect.equals(1025, F21(10, 25)); // //# 03: runtime error |
| 74 Expect.equals(1025, np.f32(10, 25)); // //# 04: runtime error | 72 Expect.equals(1025, np.f32(10, 25)); // //# 04: runtime error |
| 75 Expect.equals(1025, F21(10, b:25)); | 73 Expect.equals(1025, F21(10, b: 25)); |
| 76 Expect.equals(1025, np.f32(10, b:25)); | 74 Expect.equals(1025, np.f32(10, b: 25)); |
| 77 Expect.equals(102030, F31(10)); | 75 Expect.equals(102030, F31(10)); |
| 78 Expect.equals(102030, np.f42(10)); | 76 Expect.equals(102030, np.f42(10)); |
| 79 Expect.equals(102530, F31(10, 25)); // //# 05: runtime error | 77 Expect.equals(102530, F31(10, 25)); // //# 05: runtime error |
| 80 Expect.equals(102530, np.f42(10, 25)); // //# 06: runtime error | 78 Expect.equals(102530, np.f42(10, 25)); // //# 06: runtime error |
| 81 Expect.equals(102530, F31(10, b:25)); | 79 Expect.equals(102530, F31(10, b: 25)); |
| 82 Expect.equals(102530, np.f42(10, b:25)); | 80 Expect.equals(102530, np.f42(10, b: 25)); |
| 83 Expect.equals(102035, F31(10, c:35)); | 81 Expect.equals(102035, F31(10, c: 35)); |
| 84 Expect.equals(102035, np.f42(10, c:35)); | 82 Expect.equals(102035, np.f42(10, c: 35)); |
| 85 Expect.equals(102535, F31(10, b:25, c:35)); | 83 Expect.equals(102535, F31(10, b: 25, c: 35)); |
| 86 Expect.equals(102535, np.f42(10, b:25, c:35)); | 84 Expect.equals(102535, np.f42(10, b: 25, c: 35)); |
| 87 Expect.equals(102535, F31(10, 25, c:35)); // //# 07: runtime error | 85 Expect.equals(102535, F31(10, 25, c:35)); // //# 07: runtime error |
| 88 Expect.equals(102535, np.f42(10, 25, c:35)); // //# 08: runtime error | 86 Expect.equals(102535, np.f42(10, 25, c:35)); // //# 08: runtime error |
| 89 Expect.equals(102535, F31(10, c:35, b:25)); | 87 Expect.equals(102535, F31(10, c: 35, b: 25)); |
| 90 Expect.equals(102535, np.f42(10, c:35, b:25)); | 88 Expect.equals(102535, np.f42(10, c: 35, b: 25)); |
| 91 Expect.equals(10200040, F41(10)); | 89 Expect.equals(10200040, F41(10)); |
| 92 Expect.equals(10200040, np.f52(10)); | 90 Expect.equals(10200040, np.f52(10)); |
| 93 Expect.equals(10203540, F41(10, c:35)); | 91 Expect.equals(10203540, F41(10, c: 35)); |
| 94 Expect.equals(10203540, np.f52(10, c:35)); | 92 Expect.equals(10203540, np.f52(10, c: 35)); |
| 95 Expect.equals(10250045, F41(10, d:45, b:25)); | 93 Expect.equals(10250045, F41(10, d: 45, b: 25)); |
| 96 Expect.equals(10250045, F41(10, 25, d:45)); // //# 09: runtime error | 94 Expect.equals(10250045, F41(10, 25, d:45)); // //# 09: runtime error |
| 97 Expect.equals(10250045, np.f52(10, d:45, b:25)); | 95 Expect.equals(10250045, np.f52(10, d: 45, b: 25)); |
| 98 Expect.equals(10253545, F41(10, d:45, c:35, b:25)); | 96 Expect.equals(10253545, F41(10, d: 45, c: 35, b: 25)); |
| 99 Expect.equals(10253545, np.f52(10, d:45, c:35, b:25)); | 97 Expect.equals(10253545, np.f52(10, d: 45, c: 35, b: 25)); |
| 100 } | 98 } |
| 101 } | 99 } |
| 102 | 100 |
| 103 main() { | 101 main() { |
| 104 OptionalNamedParametersTest.test(); | 102 OptionalNamedParametersTest.test(); |
| 105 } | 103 } |
| OLD | NEW |