| 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 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); | 23 obj = new Foo.optional_private(y: 222); |
| 24 Expect.equals(222, obj._y); | 24 Expect.equals(222, obj._y); |
| 25 | 25 |
| 26 obj = new Foo.optional_private(); | 26 obj = new Foo.optional_private(); |
| 27 Expect.equals(77, obj._y); | 27 Expect.equals(77, obj._y); |
| 28 | 28 |
| 29 obj = new Foo(1); | 29 obj = new Foo(1); |
| 30 Expect.equals(2, obj.x); | 30 Expect.equals(2, obj.x); |
| 31 | 31 |
| 32 obj = new SubFoo(42); | 32 obj = new SubFoo(42); |
| 33 Expect.equals(1, obj.x); | 33 Expect.equals(1, obj.x); |
| 34 | 34 |
| 35 obj = new SubSubFoo(42); | 35 obj = new SubSubFoo(42); |
| 36 Expect.equals(1, obj.x); | 36 Expect.equals(1, obj.x); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 class Foo { | 40 class Foo { |
| 41 Foo(num this.x) { | 41 Foo(num this.x) { |
| 42 // Reference to x must resolve to the field. | 42 // Reference to x must resolve to the field. |
| 43 x++; | 43 x++; |
| 44 Expect.equals(this.x, x); | 44 Expect.equals(this.x, x); |
| 45 } | 45 } |
| 46 | 46 |
| 47 Foo.untyped(this.x) {} | 47 Foo.untyped(this.x) {} |
| 48 Foo.supertype(Object this.x) {} | 48 Foo.supertype(Object this.x) {} |
| 49 Foo.subtype(int this.x) {} | 49 Foo.subtype(int this.x) {} |
| 50 Foo.optional([this.x = 5]) {} | 50 Foo.optional([this.x = 5]) {} |
| 51 Foo.optional_private([this._y = 77]) {} | 51 Foo.optional_private([y = 77]) : _y = y {} |
| 52 | 52 |
| 53 num x; | 53 num x; |
| 54 num _y; | 54 num _y; |
| 55 } | 55 } |
| 56 | 56 |
| 57 class SubFoo extends Foo { | 57 class SubFoo extends Foo { |
| 58 SubFoo(num y) : super(y), x_ = 0 { | 58 SubFoo(num y) : super(y), x_ = 0 { |
| 59 // Subfoo.setter of x has been invoked in the Foo constructor. | 59 // Subfoo.setter of x has been invoked in the Foo constructor. |
| 60 Expect.equals(x, 1); | 60 Expect.equals(x, 1); |
| 61 Expect.equals(x_, 1); | 61 Expect.equals(x_, 1); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 Expect.equals(x_, 1); | 82 Expect.equals(x_, 1); |
| 83 | 83 |
| 84 // There is no way to get to the field in Foo. | 84 // There is no way to get to the field in Foo. |
| 85 Expect.equals(super.x, 1); | 85 Expect.equals(super.x, 1); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 main() { | 89 main() { |
| 90 ParameterInitializerTest.testMain(); | 90 ParameterInitializerTest.testMain(); |
| 91 } | 91 } |
| OLD | NEW |