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 default constructors. | 4 // Dart test program for default constructors. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 String message; | 8 String message; |
9 | 9 |
10 foo() { | 10 foo() { |
11 message += 'foo'; | 11 message += 'foo'; |
12 return 1; | 12 return 1; |
13 } | 13 } |
14 | 14 |
15 bar() { | 15 bar() { |
16 message += 'bar'; | 16 message += 'bar'; |
17 return 2; | 17 return 2; |
18 } | 18 } |
19 | 19 |
20 class X { | 20 class X { |
21 var i; | 21 var i; |
22 var j; | 22 var j; |
23 X({a: 'defa', b: 'defb'}) : this.i = a, this.j = b; | 23 X({a: 'defa', b: 'defb'}) : this.i = a, this.j = b; |
24 X.foo() : this(b: 1, a: 2); | 24 X.foo() : this(b: 1, a: 2); |
25 X.bar() : this( | 25 X.bar() : this( |
26 1, /// 01: static type warning, runtime error | 26 1, // /// 01: static type warning, runtime error |
27 a: 2); | 27 a: 2); |
28 X.baz() : this(a: 1, b: 2); | 28 X.baz() : this(a: 1, b: 2); |
29 X.qux() : this(b: 2); | 29 X.qux() : this(b: 2); |
30 X.hest() : this(); | 30 X.hest() : this(); |
31 X.fisk() : this(b: bar(), a: foo()); | 31 X.fisk() : this(b: bar(), a: foo()); |
32 X.naebdyr() : this(a: foo(), b: bar()); | 32 X.naebdyr() : this(a: foo(), b: bar()); |
33 } | 33 } |
34 | 34 |
35 test(x, a, b) { | 35 test(x, a, b) { |
36 Expect.equals(x.i, a); | 36 Expect.equals(x.i, a); |
37 Expect.equals(x.j, b); | 37 Expect.equals(x.j, b); |
38 } | 38 } |
39 | 39 |
40 main() { | 40 main() { |
41 test(new X.foo(), 2, 1); | 41 test(new X.foo(), 2, 1); |
42 test(new X.bar(), 2, 'defb'); | 42 test(new X.bar(), 2, 'defb'); |
43 test(new X.baz(), 1, 2); | 43 test(new X.baz(), 1, 2); |
44 test(new X.qux(), 'defa', 2); | 44 test(new X.qux(), 'defa', 2); |
45 test(new X.hest(), 'defa', 'defb'); | 45 test(new X.hest(), 'defa', 'defb'); |
46 | 46 |
47 message = ''; | 47 message = ''; |
48 new X.fisk(); | 48 new X.fisk(); |
49 Expect.equals('barfoo', message); | 49 Expect.equals('barfoo', message); |
50 | 50 |
51 message = ''; | 51 message = ''; |
52 new X.naebdyr(); | 52 new X.naebdyr(); |
53 Expect.equals('foobar', message); | 53 Expect.equals('foobar', message); |
54 } | 54 } |
OLD | NEW |