| 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 fields when | |
| 5 // only getter/setter methods are specified. | |
| 6 | |
| 7 class First { | |
| 8 First(int val) : a_ = val { } | |
| 9 | |
| 10 void testMethod() { | |
| 11 a = 20; | |
| 12 } | |
| 13 static void testStaticMethod() { | |
| 14 b = 20; | |
| 15 } | |
| 16 | |
| 17 int get a() { | |
| 18 return a_; | |
| 19 } | |
| 20 void set a(int val) { | |
| 21 a_ = a_ + val; | |
| 22 } | |
| 23 | |
| 24 static int get b() { | |
| 25 return b_; | |
| 26 } | |
| 27 static void set b(int val) { | |
| 28 b_ = val; | |
| 29 } | |
| 30 | |
| 31 int a_; | |
| 32 static int b_; | |
| 33 } | |
| 34 | |
| 35 | |
| 36 class Second { | |
| 37 static int c; | |
| 38 int a_; | |
| 39 | |
| 40 Second(int value) : a_ = value { } | |
| 41 | |
| 42 void testMethod() { | |
| 43 a = 20; | |
| 44 } | |
| 45 | |
| 46 static void testStaticMethod() { | |
| 47 int i; | |
| 48 b = 20; | |
| 49 i = d; | |
| 50 // TODO(asiva): Turn these on once we have error handling. | |
| 51 // i = b; // Should be an error. | |
| 52 // d = 40; // Should be an error. | |
| 53 } | |
| 54 | |
| 55 int get a() { | |
| 56 return a_; | |
| 57 } | |
| 58 void set a(int value) { | |
| 59 a_ = a_ + value; | |
| 60 } | |
| 61 | |
| 62 static void set b(int value) { | |
| 63 Second.c = value; | |
| 64 } | |
| 65 static int get d() { | |
| 66 return Second.c; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 | |
| 71 class Setter1Test { | |
| 72 static testMain() { | |
| 73 First obj1 = new First(10); | |
| 74 Expect.equals(10, obj1.a); | |
| 75 obj1.testMethod(); | |
| 76 Expect.equals(30, obj1.a); | |
| 77 First.b = 10; | |
| 78 Expect.equals(10, First.b); | |
| 79 First.testStaticMethod(); | |
| 80 Expect.equals(20, First.b); | |
| 81 | |
| 82 Second obj = new Second(10); | |
| 83 Expect.equals(10, obj.a); | |
| 84 obj.testMethod(); | |
| 85 Expect.equals(30, obj.a); | |
| 86 | |
| 87 Second.testStaticMethod(); | |
| 88 Expect.equals(20, Second.c); | |
| 89 Expect.equals(20, Second.d); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 | |
| 94 main() { | |
| 95 Setter1Test.testMain(); | |
| 96 } | |
| OLD | NEW |