blob: eb7239c50b4855e33eeaea321733d029db7d1af9 [file] [log] [blame]
dgrove@google.comebe43942011-10-05 06:22:36 +00001// 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
floitsch@google.com8fd6d0a2013-04-05 19:43:16 +00006import "package:expect/expect.dart";
7
dgrove@google.comebe43942011-10-05 06:22:36 +00008class A extends B {
9 A(x, y) : super(y), a = x { }
10
11 var a;
12}
13
14
15class B {
16 var b;
17
18 B(x) : b = x { }
19
20 B.namedB(var x) : b = x {}
21}
22
23
24// Test the order of initialization: first the instance variable then
25// the super constructor.
26class Alpha {
27 Alpha(v) {
28 this.foo(v);
29 }
30}
31
32class Beta extends Alpha {
33 Beta(v) : super(v), b = 1 {}
34
35 foo(v) {
36 // Check that 'b' was initialized.
37 Expect.equals(1, b);
38 b = v;
39 }
40
41 var b;
42}
43
44class ConstructorTest {
45 static testMain() {
46 var o = new A(10, 2);
47 Expect.equals(10, o.a);
48 Expect.equals(2, o.b);
49
50 var o1 = new B.namedB(10);
51 Expect.equals(10, o1.b);
52
53 Expect.equals(22, o.a + o.b + o1.b);
54
55 var beta = new Beta(3);
56 Expect.equals(3, beta.b);
57 }
58}
59
60main() {
61 ConstructorTest.testMain();
62}