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