OLD | NEW |
1 // Copyright (c) 2011, 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 class ParameterInitializerTest { | 5 class ParameterInitializerTest { |
6 | 6 |
7 static testMain() { | 7 static testMain() { |
8 var obj = new Foo.untyped(1); | 8 var obj = new Foo.untyped(1); |
9 Expect.equals(1, obj.x); | 9 Expect.equals(1, obj.x); |
10 | 10 |
11 obj = new Foo.supertype(9); | 11 obj = new Foo.supertype(9); |
12 Expect.equals(9, obj.x); | 12 Expect.equals(9, obj.x); |
13 | 13 |
14 obj = new Foo.subtype(7); | 14 obj = new Foo.subtype(7); |
15 Expect.equals(7, obj.x); | 15 Expect.equals(7, obj.x); |
16 | 16 |
17 obj = new Foo.optional(x: 111); | 17 obj = new Foo.optional(x: 111); |
18 Expect.equals(111, obj.x); | 18 Expect.equals(111, obj.x); |
19 | 19 |
20 obj = new Foo.optional(); | 20 obj = new Foo.optional(); |
21 Expect.equals(5, obj.x); | 21 Expect.equals(5, obj.x); |
22 | 22 |
23 obj = new Foo.optional_private(_y: 222); | |
24 Expect.equals(222, obj._y); | |
25 | |
26 obj = new Foo.optional_private(); | |
27 Expect.equals(77, obj._y); | |
28 | |
29 obj = new Foo(1); | 23 obj = new Foo(1); |
30 Expect.equals(2, obj.x); | 24 Expect.equals(2, obj.x); |
31 | 25 |
32 obj = new SubFoo(42); | 26 obj = new SubFoo(42); |
33 Expect.equals(1, obj.x); | 27 Expect.equals(1, obj.x); |
34 | 28 |
35 obj = new SubSubFoo(42); | 29 obj = new SubSubFoo(42); |
36 Expect.equals(1, obj.x); | 30 Expect.equals(1, obj.x); |
37 } | 31 } |
38 } | 32 } |
39 | 33 |
40 class Foo { | 34 class Foo { |
41 Foo(num this.x) { | 35 Foo(num this.x) { |
42 // Reference to x must resolve to the field. | 36 // Reference to x must resolve to the field. |
43 x++; | 37 x++; |
44 Expect.equals(this.x, x); | 38 Expect.equals(this.x, x); |
45 } | 39 } |
46 | 40 |
47 Foo.untyped(this.x) {} | 41 Foo.untyped(this.x) {} |
48 Foo.supertype(Object this.x) {} | 42 Foo.supertype(Object this.x) {} |
49 Foo.subtype(int this.x) {} | 43 Foo.subtype(int this.x) {} |
50 Foo.optional([this.x = 5]) {} | 44 Foo.optional([this.x = 5]) {} |
51 Foo.optional_private([this._y = 77]) {} | |
52 | 45 |
53 num x; | 46 num x; |
54 num _y; | |
55 } | 47 } |
56 | 48 |
57 class SubFoo extends Foo { | 49 class SubFoo extends Foo { |
58 SubFoo(num y) : super(y), x_ = 0 { | 50 SubFoo(num y) : super(y), x_ = 0 { |
59 // Subfoo.setter of x has been invoked in the Foo constructor. | 51 // Subfoo.setter of x has been invoked in the Foo constructor. |
60 Expect.equals(x, 1); | 52 Expect.equals(x, 1); |
61 Expect.equals(x_, 1); | 53 Expect.equals(x_, 1); |
62 | 54 |
63 // The super.x will resolved to the field in Foo. | 55 // The super.x will resolved to the field in Foo. |
64 Expect.equals(super.x, y); | 56 Expect.equals(super.x, y); |
(...skipping 17 matching lines...) Expand all Loading... |
82 Expect.equals(x_, 1); | 74 Expect.equals(x_, 1); |
83 | 75 |
84 // There is no way to get to the field in Foo. | 76 // There is no way to get to the field in Foo. |
85 Expect.equals(super.x, 1); | 77 Expect.equals(super.x, 1); |
86 } | 78 } |
87 } | 79 } |
88 | 80 |
89 main() { | 81 main() { |
90 ParameterInitializerTest.testMain(); | 82 ParameterInitializerTest.testMain(); |
91 } | 83 } |
OLD | NEW |