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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class ParameterInitializerTest { | 7 class ParameterInitializerTest { |
8 | |
9 static testMain() { | 8 static testMain() { |
10 | |
11 var obj = new Foo.untyped(1); | 9 var obj = new Foo.untyped(1); |
12 Expect.equals(1, obj.x); | 10 Expect.equals(1, obj.x); |
13 | 11 |
14 obj = new Foo.supertype(9); | 12 obj = new Foo.supertype(9); |
15 Expect.equals(9, obj.x); | 13 Expect.equals(9, obj.x); |
16 | 14 |
17 obj = new Foo.subtype(7); | 15 obj = new Foo.subtype(7); |
18 Expect.equals(7, obj.x); | 16 Expect.equals(7, obj.x); |
19 | 17 |
20 obj = new Foo.optional(111); | 18 obj = new Foo.optional(111); |
(...skipping 22 matching lines...) Expand all Loading... |
43 | 41 |
44 Foo.untyped(this.x) {} | 42 Foo.untyped(this.x) {} |
45 Foo.supertype(Object this.x) {} | 43 Foo.supertype(Object this.x) {} |
46 Foo.subtype(int this.x) {} | 44 Foo.subtype(int this.x) {} |
47 Foo.optional([this.x = 5]) {} | 45 Foo.optional([this.x = 5]) {} |
48 | 46 |
49 num x; | 47 num x; |
50 } | 48 } |
51 | 49 |
52 class SubFoo extends Foo { | 50 class SubFoo extends Foo { |
53 SubFoo(num y) : super(y), x_ = 0 { | 51 SubFoo(num y) |
| 52 : super(y), |
| 53 x_ = 0 { |
54 // Subfoo.setter of x has been invoked in the Foo constructor. | 54 // Subfoo.setter of x has been invoked in the Foo constructor. |
55 Expect.equals(x, 1); | 55 Expect.equals(x, 1); |
56 Expect.equals(x_, 1); | 56 Expect.equals(x_, 1); |
57 | 57 |
58 // The super.x will resolved to the field in Foo. | 58 // The super.x will resolved to the field in Foo. |
59 Expect.equals(super.x, y); | 59 Expect.equals(super.x, y); |
60 } | 60 } |
61 | 61 |
62 get x { | 62 get x { |
63 return x_; | 63 return x_; |
(...skipping 13 matching lines...) Expand all Loading... |
77 Expect.equals(x_, 1); | 77 Expect.equals(x_, 1); |
78 | 78 |
79 // There is no way to get to the field in Foo. | 79 // There is no way to get to the field in Foo. |
80 Expect.equals(super.x, 1); | 80 Expect.equals(super.x, 1); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 main() { | 84 main() { |
85 ParameterInitializerTest.testMain(); | 85 ParameterInitializerTest.testMain(); |
86 } | 86 } |
OLD | NEW |