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 for testing order of constructor invocation. | 4 // Dart test for testing order of constructor invocation. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 var trace = ""; | 8 var trace = ""; |
9 | 9 |
10 int rec(int i) { | 10 int rec(int i) { |
11 trace += "$i "; | 11 trace += "$i "; |
12 return i; | 12 return i; |
13 } | 13 } |
14 | 14 |
15 class A { | 15 class A { |
16 A(int x) : x = rec(2) { | 16 A(int x) : x = rec(2) { |
17 Expect.equals(1, x); // Parameter x | 17 Expect.equals(1, x); // Parameter x |
18 Expect.equals(2, this.x); | 18 Expect.equals(2, this.x); |
19 rec(5); | 19 rec(5); |
20 } | 20 } |
21 final int x; | 21 final int x; |
22 } | 22 } |
23 | 23 |
24 class B extends A { | 24 class B extends A { |
25 B(this.a, int y, int z) | 25 B(this.a, int y, int z) |
26 : super(rec(1)), z = rec(3), y = rec(4) { | 26 : super(rec(1)), |
| 27 z = rec(3), |
| 28 y = rec(4) { |
27 rec(6); | 29 rec(6); |
28 } | 30 } |
29 int a; | 31 int a; |
30 int y; | 32 int y; |
31 int z; | 33 int z; |
32 } | 34 } |
33 | 35 |
34 main() { | 36 main() { |
35 var test = new B(rec(0), 0, 0); | 37 var test = new B(rec(0), 0, 0); |
36 Expect.equals(0, test.a); | 38 Expect.equals(0, test.a); |
37 Expect.equals(2, test.x); | 39 Expect.equals(2, test.x); |
38 Expect.equals(4, test.y); | 40 Expect.equals(4, test.y); |
39 Expect.equals(3, test.z); | 41 Expect.equals(3, test.z); |
40 Expect.equals("0 1 2 3 4 5 6 ", trace); | 42 Expect.equals("0 1 2 3 4 5 6 ", trace); |
41 } | 43 } |
42 | |
OLD | NEW |