| 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 class Alpha { | 26 abstract 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.'; |
| 30 } | 31 } |
| 31 | 32 |
| 32 class Beta extends Alpha { | 33 class Beta extends Alpha { |
| 33 Beta(v) : super(v), b = 1 {} | 34 Beta(v) : super(v), b = 1 {} |
| 34 | 35 |
| 35 foo(v) { | 36 foo(v) { |
| 36 // Check that 'b' was initialized. | 37 // Check that 'b' was initialized. |
| 37 Expect.equals(1, b); | 38 Expect.equals(1, b); |
| 38 b = v; | 39 b = v; |
| 39 } | 40 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 Expect.equals(22, o.a + o.b + o1.b); | 54 Expect.equals(22, o.a + o.b + o1.b); |
| 54 | 55 |
| 55 var beta = new Beta(3); | 56 var beta = new Beta(3); |
| 56 Expect.equals(3, beta.b); | 57 Expect.equals(3, beta.b); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 main() { | 61 main() { |
| 61 ConstructorTest.testMain(); | 62 ConstructorTest.testMain(); |
| 62 } | 63 } |
| OLD | NEW |