| 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 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 | |
| 9 class NamedParametersTest { | 8 class NamedParametersTest { |
| 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 ? 0 : c)) + d; | 50 return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + 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 ? 0 : c)) + d; | 54 return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + d; |
| 57 } | 55 } |
| 58 | 56 |
| 59 static testMain() { | 57 static testMain() { |
| 60 NamedParametersTest np = new NamedParametersTest(); | 58 NamedParametersTest np = new NamedParametersTest(); |
| 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()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 main() { | 106 main() { |
| 109 NamedParametersTest.testMain(); | 107 NamedParametersTest.testMain(); |
| 110 var i = new I(); | 108 var i = new I(); |
| 111 Expect.equals(100, i.mul(10)); | 109 Expect.equals(100, i.mul(10)); |
| 112 Expect.equals(1000, i.mul(10, 100)); | 110 Expect.equals(1000, i.mul(10, 100)); |
| 113 var c = new C(); | 111 var c = new C(); |
| 114 Expect.equals(100, c.mul(10)); | 112 Expect.equals(100, c.mul(10)); |
| 115 Expect.equals(1000, c.mul(10, 100)); | 113 Expect.equals(1000, c.mul(10, 100)); |
| 116 Expect.equals("Edna sent gladiolas to possums", message()); | 114 Expect.equals("Edna sent gladiolas to possums", message()); |
| 117 } | 115 } |
| OLD | NEW |