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 testing setting/getting of instance fields. | |
5 | |
6 class First { | |
7 First() {} | |
8 var a; | |
9 var b; | |
10 | |
11 addFields() { | |
12 return a + b; | |
13 } | |
14 | |
15 setValues() { | |
16 a = 24; | |
17 b = 10; | |
18 return a + b; | |
19 } | |
20 } | |
21 | |
22 class Second extends First { | |
23 // TODO: consider removing once http://b/4254120 is fixed. | |
24 Second() : super() {} | |
25 var c; | |
26 get a() { return -12; } | |
27 set b(a) { a.c = 12; } | |
28 } | |
29 | |
30 class FieldTest { | |
31 static one() { | |
32 var f = new First(); | |
33 f.a = 3; | |
34 f.b = f.a; | |
35 Expect.equals(3, f.a); | |
36 Expect.equals(f.a, f.b); | |
37 f.b = (f.a = 10); | |
38 Expect.equals(10, f.a); | |
39 Expect.equals(10, f.b); | |
40 f.b = f.a = 15; | |
41 Expect.equals(15, f.a); | |
42 Expect.equals(15, f.b); | |
43 Expect.equals(30, f.addFields()); | |
44 Expect.equals(34, f.setValues()); | |
45 Expect.equals(24, f.a); | |
46 Expect.equals(10, f.b); | |
47 } | |
48 | |
49 static two() { | |
50 // The tests below are a little cumbersome because not | |
51 // everything is implemented yet. | |
52 var o = new Second(); | |
53 // 'a' getter is overriden, always returns -12. | |
54 Expect.equals(-12, o.a); | |
55 o.a = 2; | |
56 Expect.equals(-12, o.a); | |
57 // 'b' setter is overriden to write 12 to field 'c'. | |
58 o.b = o; | |
59 Expect.equals(12, o.c); | |
60 } | |
61 | |
62 static testMain() { | |
63 // FieldTest.one(); | |
64 FieldTest.two(); | |
65 } | |
66 } | |
67 | |
68 | |
69 main() { | |
70 FieldTest.testMain(); | |
71 } | |
OLD | NEW |