| 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 |
| 8 class NamedParametersTest { | 9 class NamedParametersTest { |
| 10 |
| 9 static int F00() { | 11 static int F00() { |
| 10 return 0; | 12 return 0; |
| 11 } | 13 } |
| 12 | 14 |
| 13 int f11() { | 15 int f11() { |
| 14 return 0; | 16 return 0; |
| 15 } | 17 } |
| 16 | 18 |
| 17 static int F11(int a) { | 19 static int F11(int a) { |
| 18 return a; | 20 return a; |
| 19 } | 21 } |
| 20 | 22 |
| 21 int f22(int a) { | 23 int f22(int a) { |
| 22 return a; | 24 return a; |
| 23 } | 25 } |
| 24 | 26 |
| 25 static int F10([int b = 20]) { | 27 static int F10([int b = 20]) { |
| 26 return b; | 28 return b; |
| 27 } | 29 } |
| 28 | 30 |
| 29 int f21([int b = 20]) { | 31 int f21([int b = 20]) { |
| 30 return b; | 32 return b; |
| 31 } | 33 } |
| 32 | 34 |
| 33 static int F21(int a, [int b = 20]) { | 35 static int F21(int a, [int b = 20]) { |
| 34 return 100 * a + b; | 36 return 100*a + b; |
| 35 } | 37 } |
| 36 | 38 |
| 37 int f32(int a, [int b = 20]) { | 39 int f32(int a, [int b = 20]) { |
| 38 return 100 * a + b; | 40 return 100*a + b; |
| 39 } | 41 } |
| 40 | 42 |
| 41 static int F31(int a, [int b = 20, int c = 30]) { | 43 static int F31(int a, [int b = 20, int c = 30]) { |
| 42 return 100 * (100 * a + b) + c; | 44 return 100*(100*a + b) + c; |
| 43 } | 45 } |
| 44 | 46 |
| 45 int f42(int a, [int b = 20, int c = 30]) { | 47 int f42(int a, [int b = 20, int c = 30]) { |
| 46 return 100 * (100 * a + b) + c; | 48 return 100*(100*a + b) + c; |
| 47 } | 49 } |
| 48 | 50 |
| 49 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]) { |
| 50 return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + d; | 52 return 100*(100*(100*a + b) + (c == null ? 0 : c)) + d; |
| 51 } | 53 } |
| 52 | 54 |
| 53 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]) { |
| 54 return 100 * (100 * (100 * a + b) + (c == null ? 0 : c)) + d; | 56 return 100*(100*(100*a + b) + (c == null ? 0 : c)) + d; |
| 55 } | 57 } |
| 56 | 58 |
| 57 static testMain() { | 59 static testMain() { |
| 58 NamedParametersTest np = new NamedParametersTest(); | 60 NamedParametersTest np = new NamedParametersTest(); |
| 59 Expect.equals(0, F00()); | 61 Expect.equals(0, F00()); |
| 60 Expect.equals(0, np.f11()); | 62 Expect.equals(0, np.f11()); |
| 61 Expect.equals(10, F11(10)); | 63 Expect.equals(10, F11(10)); |
| 62 Expect.equals(10, np.f22(10)); | 64 Expect.equals(10, np.f22(10)); |
| 63 Expect.equals(20, F10()); | 65 Expect.equals(20, F10()); |
| 64 Expect.equals(20, np.f21()); | 66 Expect.equals(20, np.f21()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 main() { | 108 main() { |
| 107 NamedParametersTest.testMain(); | 109 NamedParametersTest.testMain(); |
| 108 var i = new I(); | 110 var i = new I(); |
| 109 Expect.equals(100, i.mul(10)); | 111 Expect.equals(100, i.mul(10)); |
| 110 Expect.equals(1000, i.mul(10, 100)); | 112 Expect.equals(1000, i.mul(10, 100)); |
| 111 var c = new C(); | 113 var c = new C(); |
| 112 Expect.equals(100, c.mul(10)); | 114 Expect.equals(100, c.mul(10)); |
| 113 Expect.equals(1000, c.mul(10, 100)); | 115 Expect.equals(1000, c.mul(10, 100)); |
| 114 Expect.equals("Edna sent gladiolas to possums", message()); | 116 Expect.equals("Edna sent gladiolas to possums", message()); |
| 115 } | 117 } |
| OLD | NEW |