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