| 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 // Dart test program for constructors and initializers. | 4 // Dart test program for constructors and initializers. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 class A extends B { | 8 class A extends B { |
| 9 A(x, y) : super(y), a = x { } | 9 A(x, y) : super(y), a = x { } |
| 10 | 10 |
| 11 var a; | 11 var a; |
| 12 } | 12 } |
| 13 | 13 |
| 14 | 14 |
| 15 class B { | 15 class B { |
| 16 var b; | 16 var b; |
| 17 | 17 |
| 18 B(x) : b = x { } | 18 B(x) : b = x { } |
| 19 | 19 |
| 20 B.namedB(var x) : b = x {} | 20 B.namedB(var x) : b = x {} |
| 21 } | 21 } |
| 22 | 22 |
| 23 | 23 |
| 24 // Test the order of initialization: first the instance variable then | 24 // Test the order of initialization: first the instance variable then |
| 25 // the super constructor. | 25 // the super constructor. |
| 26 abstract class Alpha { | 26 class Alpha { |
| 27 Alpha(v) { | 27 Alpha(v) { |
| 28 this.foo(v); | 28 this.foo(v); |
| 29 } | 29 } |
| 30 foo(v) => throw 'Alpha.foo should never be called.'; | |
| 31 } | 30 } |
| 32 | 31 |
| 33 class Beta extends Alpha { | 32 class Beta extends Alpha { |
| 34 Beta(v) : super(v), b = 1 {} | 33 Beta(v) : super(v), b = 1 {} |
| 35 | 34 |
| 36 foo(v) { | 35 foo(v) { |
| 37 // Check that 'b' was initialized. | 36 // Check that 'b' was initialized. |
| 38 Expect.equals(1, b); | 37 Expect.equals(1, b); |
| 39 b = v; | 38 b = v; |
| 40 } | 39 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 Expect.equals(22, o.a + o.b + o1.b); | 53 Expect.equals(22, o.a + o.b + o1.b); |
| 55 | 54 |
| 56 var beta = new Beta(3); | 55 var beta = new Beta(3); |
| 57 Expect.equals(3, beta.b); | 56 Expect.equals(3, beta.b); |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 main() { | 60 main() { |
| 62 ConstructorTest.testMain(); | 61 ConstructorTest.testMain(); |
| 63 } | 62 } |
| OLD | NEW |