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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Test Parameter Intializer. | 7 // Test Parameter Intializer. |
8 | 8 |
9 | |
10 class ParameterInitializer2Test { | 9 class ParameterInitializer2Test { |
11 static testMain() { | 10 static testMain() { |
12 var a = new A(123); | 11 var a = new A(123); |
13 Expect.equals(123, a.x); | 12 Expect.equals(123, a.x); |
14 | 13 |
15 var b = new B(123); | 14 var b = new B(123); |
16 Expect.equals(123, b.x); | 15 Expect.equals(123, b.x); |
17 | 16 |
18 var c = new C(123); | 17 var c = new C(123); |
19 Expect.equals(123, c.x); | 18 Expect.equals(123, c.x); |
20 | 19 |
21 var d = new D(123); | 20 var d = new D(123); |
22 Expect.equals(123, d.x); | 21 Expect.equals(123, d.x); |
23 | 22 |
24 var e = new E(1); | 23 var e = new E(1); |
25 Expect.equals(4, e.x); | 24 Expect.equals(4, e.x); |
26 | 25 |
27 var f = new F(1,2,3,4); | 26 var f = new F(1, 2, 3, 4); |
28 Expect.equals(4, f.z); | 27 Expect.equals(4, f.z); |
29 } | 28 } |
30 } | 29 } |
31 | 30 |
32 // untyped | 31 // untyped |
33 class A { | 32 class A { |
34 A(this.x) { | 33 A(this.x) {} |
35 } | |
36 int x; | 34 int x; |
37 } | 35 } |
38 | 36 |
39 // typed | 37 // typed |
40 class B { | 38 class B { |
41 B(int this.x) { | 39 B(int this.x) {} |
42 } | |
43 int x; | 40 int x; |
44 } | 41 } |
45 | 42 |
46 // const typed | 43 // const typed |
47 class C { | 44 class C { |
48 const C(int this.x); | 45 const C(int this.x); |
49 final int x; | 46 final int x; |
50 } | 47 } |
51 | 48 |
52 // const untyped | 49 // const untyped |
53 class D { | 50 class D { |
54 const D(this.x); | 51 const D(this.x); |
55 final x; | 52 final x; |
56 } | 53 } |
57 | 54 |
58 // make sure this.<X> references work properly in the constructor scope. | 55 // make sure this.<X> references work properly in the constructor scope. |
59 class E { | 56 class E { |
60 E(this.x) { | 57 E(this.x) { |
61 var myVar = this.x * 2; | 58 var myVar = this.x * 2; |
62 this.x = myVar + 1; | 59 this.x = myVar + 1; |
63 x = myVar + 2; | 60 x = myVar + 2; |
64 var foo = x + 1; | 61 var foo = x + 1; |
65 } | 62 } |
66 int x; | 63 int x; |
67 } | 64 } |
68 | 65 |
69 | |
70 // mixed | 66 // mixed |
71 class F { | 67 class F { |
72 F(x, this.y_, int w, int this.z) : x_ = x, w_ = w { } | 68 F(x, this.y_, int w, int this.z) |
73 F.foobar(this.z, int this.x_, int this.az_) { } | 69 : x_ = x, |
| 70 w_ = w {} |
| 71 F.foobar(this.z, int this.x_, int this.az_) {} |
74 int x_; | 72 int x_; |
75 int y_; | 73 int y_; |
76 int w_; | 74 int w_; |
77 int z; | 75 int z; |
78 int az_; | 76 int az_; |
79 } | 77 } |
80 | 78 |
81 | |
82 main() { | 79 main() { |
83 ParameterInitializer2Test.testMain(); | 80 ParameterInitializer2Test.testMain(); |
84 } | 81 } |
OLD | NEW |