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 |
9 class NamedParametersTest { | 9 class NamedParametersTest { |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 static testMain() { | 59 static testMain() { |
60 NamedParametersTest np = new NamedParametersTest(); | 60 NamedParametersTest np = new NamedParametersTest(); |
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()); |
67 Expect.equals(20, F10(20)); | 67 Expect.equals(20, F10(20)); |
68 Expect.equals(20, np.f21(20)); | 68 Expect.equals(20, np.f21(20)); |
69 Expect.equals(20, F10(b:20)); /// 01: runtime error | 69 Expect.equals(20, F10(b:20)); //# 01: runtime error |
70 Expect.equals(20, np.f21(b:20)); /// 02: runtime error | 70 Expect.equals(20, np.f21(b:20)); //# 02: runtime error |
71 Expect.equals(1020, F21(10)); | 71 Expect.equals(1020, F21(10)); |
72 Expect.equals(1020, np.f32(10)); | 72 Expect.equals(1020, np.f32(10)); |
73 Expect.equals(1025, F21(10, 25)); | 73 Expect.equals(1025, F21(10, 25)); |
74 Expect.equals(1025, np.f32(10, 25)); | 74 Expect.equals(1025, np.f32(10, 25)); |
75 Expect.equals(1025, F21(10, b:25)); /// 03: runtime error | 75 Expect.equals(1025, F21(10, b:25)); //# 03: runtime error |
76 Expect.equals(1025, np.f32(10, b:25)); /// 04: runtime error | 76 Expect.equals(1025, np.f32(10, b:25)); //# 04: runtime error |
77 Expect.equals(102030, F31(10)); | 77 Expect.equals(102030, F31(10)); |
78 Expect.equals(102030, np.f42(10)); | 78 Expect.equals(102030, np.f42(10)); |
79 Expect.equals(102530, F31(10, 25)); | 79 Expect.equals(102530, F31(10, 25)); |
80 Expect.equals(102530, np.f42(10, 25)); | 80 Expect.equals(102530, np.f42(10, 25)); |
81 Expect.equals(102035, F31(10, c:35)); /// 05: runtime error | 81 Expect.equals(102035, F31(10, c:35)); //# 05: runtime error |
82 Expect.equals(102035, np.f42(10, c:35)); /// 06: runtime error | 82 Expect.equals(102035, np.f42(10, c:35)); //# 06: runtime error |
83 Expect.equals(102535, F31(10, 25, 35)); | 83 Expect.equals(102535, F31(10, 25, 35)); |
84 Expect.equals(102535, np.f42(10, 25, 35)); | 84 Expect.equals(102535, np.f42(10, 25, 35)); |
85 Expect.equals(102535, F31(10, 25, c:35)); /// 07: runtime error | 85 Expect.equals(102535, F31(10, 25, c:35)); //# 07: runtime error |
86 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 |
87 Expect.equals(10200040, F41(10)); | 87 Expect.equals(10200040, F41(10)); |
88 Expect.equals(10200040, np.f52(10)); | 88 Expect.equals(10200040, np.f52(10)); |
89 Expect.equals(10203540, F41(10, c:35)); /// 09: runtime error | 89 Expect.equals(10203540, F41(10, c:35)); //# 09: runtime error |
90 Expect.equals(10203540, np.f52(10, c:35)); /// 10: runtime error | 90 Expect.equals(10203540, np.f52(10, c:35)); //# 10: runtime error |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 abstract class I { | 94 abstract class I { |
95 factory I() = C; | 95 factory I() = C; |
96 int mul(int a, [int factor]); | 96 int mul(int a, [int factor]); |
97 } | 97 } |
98 | 98 |
99 class C implements I { | 99 class C implements I { |
100 int mul(int a, [int factor = 10]) { | 100 int mul(int a, [int factor = 10]) { |
101 return a * factor; | 101 return a * factor; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 hello(msg, to, {from}) => '${from} sent ${msg} to ${to}'; | 105 hello(msg, to, {from}) => '${from} sent ${msg} to ${to}'; |
106 message() => hello("gladiolas", "possums", from: "Edna"); | 106 message() => hello("gladiolas", "possums", from: "Edna"); |
107 | 107 |
108 main() { | 108 main() { |
109 NamedParametersTest.testMain(); | 109 NamedParametersTest.testMain(); |
110 var i = new I(); | 110 var i = new I(); |
111 Expect.equals(100, i.mul(10)); | 111 Expect.equals(100, i.mul(10)); |
112 Expect.equals(1000, i.mul(10, 100)); | 112 Expect.equals(1000, i.mul(10, 100)); |
113 var c = new C(); | 113 var c = new C(); |
114 Expect.equals(100, c.mul(10)); | 114 Expect.equals(100, c.mul(10)); |
115 Expect.equals(1000, c.mul(10, 100)); | 115 Expect.equals(1000, c.mul(10, 100)); |
116 Expect.equals("Edna sent gladiolas to possums", message()); | 116 Expect.equals("Edna sent gladiolas to possums", message()); |
117 } | 117 } |
OLD | NEW |