| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Dart test program for constructors and initializers. | |
| 5 | |
| 6 class A extends B { | |
| 7 A(x, y) : super(y), a = x { } | |
| 8 | |
| 9 var a; | |
| 10 } | |
| 11 | |
| 12 | |
| 13 class B { | |
| 14 var b; | |
| 15 | |
| 16 B(x) : b = x { } | |
| 17 | |
| 18 B.namedB(var x) : b = x {} | |
| 19 } | |
| 20 | |
| 21 | |
| 22 // Test the order of initialization: first the instance variable then | |
| 23 // the super constructor. | |
| 24 class Alpha { | |
| 25 Alpha(v) { | |
| 26 this.foo(v); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 class Beta extends Alpha { | |
| 31 Beta(v) : super(v), b = 1 {} | |
| 32 | |
| 33 foo(v) { | |
| 34 // Check that 'b' was initialized. | |
| 35 Expect.equals(1, b); | |
| 36 b = v; | |
| 37 } | |
| 38 | |
| 39 var b; | |
| 40 } | |
| 41 | |
| 42 class ConstructorTest { | |
| 43 static testMain() { | |
| 44 var o = new A(10, 2); | |
| 45 Expect.equals(10, o.a); | |
| 46 Expect.equals(2, o.b); | |
| 47 | |
| 48 var o1 = new B.namedB(10); | |
| 49 Expect.equals(10, o1.b); | |
| 50 | |
| 51 Expect.equals(22, o.a + o.b + o1.b); | |
| 52 | |
| 53 var beta = new Beta(3); | |
| 54 Expect.equals(3, beta.b); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 main() { | |
| 59 ConstructorTest.testMain(); | |
| 60 } | |
| OLD | NEW |