| 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 | 8 |
| 9 class OptionalNamedParametersTest { | 9 class OptionalNamedParametersTest { |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 static int F31(int a, {int b: 20, int c: 30}) { | 43 static int F31(int a, {int b: 20, int c: 30}) { |
| 44 return 100*(100*a + b) + c; | 44 return 100*(100*a + b) + c; |
| 45 } | 45 } |
| 46 | 46 |
| 47 int f42(int a, {int b: 20, int c: 30}) { | 47 int f42(int a, {int b: 20, int c: 30}) { |
| 48 return 100*(100*a + b) + c; | 48 return 100*(100*a + b) + c; |
| 49 } | 49 } |
| 50 | 50 |
| 51 static int F41(int a, {int b: 20, int c, int d: 40}) { | 51 static int F41(int a, {int b: 20, int c, int d: 40}) { |
| 52 return 100*(100*(100*a + b) + (?c ? c : 0)) + d; | 52 return 100*(100*(100*a + b) + ((c != null) ? c : 0)) + d; |
| 53 } | 53 } |
| 54 | 54 |
| 55 int f52(int a, {int b: 20, int c, int d: 40}) { | 55 int f52(int a, {int b: 20, int c, int d: 40}) { |
| 56 return 100*(100*(100*a + b) + (?c ? c : 0)) + d; | 56 return 100*(100*(100*a + b) + ((c != null) ? c : 0)) + d; |
| 57 } | 57 } |
| 58 | 58 |
| 59 static void test() { | 59 static void test() { |
| 60 OptionalNamedParametersTest np = new OptionalNamedParametersTest(); | 60 OptionalNamedParametersTest np = new OptionalNamedParametersTest(); |
| 61 Expect.equals(0, F00()); | 61 Expect.equals(0, F00()); |
| 62 Expect.equals(0, np.f11()); | 62 Expect.equals(0, np.f11()); |
| 63 Expect.equals(10, F11(10)); | 63 Expect.equals(10, F11(10)); |
| 64 Expect.equals(10, np.f22(10)); | 64 Expect.equals(10, np.f22(10)); |
| 65 Expect.equals(20, F10()); | 65 Expect.equals(20, F10()); |
| 66 Expect.equals(20, np.f21()); | 66 Expect.equals(20, np.f21()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 Expect.equals(10253545, F41(10, d:45, c:35, b:25)); | 98 Expect.equals(10253545, F41(10, d:45, c:35, b:25)); |
| 99 Expect.equals(10253545, np.f52(10, d:45, c:35, b:25)); | 99 Expect.equals(10253545, np.f52(10, d:45, c:35, b:25)); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 main() { | 103 main() { |
| 104 OptionalNamedParametersTest.test(); | 104 OptionalNamedParametersTest.test(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // TODO(regis): negative tests: [} {] [a:0] {a=0} | 107 // TODO(regis): negative tests: [} {] [a:0] {a=0} |
| OLD | NEW |