| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Test correct instance compound assignment operator. | 4 // Test correct instance compound assignment operator. |
| 5 | 5 |
| 6 class A { | 6 class A { |
| 7 A() : f = 2 {} | 7 A() : f = 2 {} |
| 8 var f; | 8 var f; |
| 9 operator [](index) => f; |
| 10 operator []=(index, value) => f = value; |
| 11 |
| 12 var _g = 0; |
| 13 var gGetCount = 0; |
| 14 var gSetCount = 0; |
| 15 get g() { |
| 16 gGetCount++; |
| 17 return _g; |
| 18 } |
| 19 set g(value) { |
| 20 gSetCount++; |
| 21 _g = value; |
| 22 } |
| 9 } | 23 } |
| 10 | 24 |
| 11 | 25 |
| 12 class B { | 26 class B { |
| 13 B() : _a = new A(), count = 0 {} | 27 B() : _a = new A(), count = 0 {} |
| 14 get a() { | 28 get a() { |
| 15 count++; | 29 count++; |
| 16 return _a; | 30 return _a; |
| 17 } | 31 } |
| 18 var _a; | 32 var _a; |
| 19 var count; | 33 var count; |
| 20 } | 34 } |
| 21 | 35 |
| 36 var globalA; |
| 37 var fooCounter = 0; |
| 38 foo() { |
| 39 fooCounter++; |
| 40 return globalA; |
| 41 } |
| 22 | 42 |
| 23 class InstanceCompoundAssignmentOperatorTest { | 43 main() { |
| 24 static void testMain() { | 44 B b = new B(); |
| 25 B b = new B(); | 45 Expect.equals(0, b.count); |
| 26 Expect.equals(0, b.count); | 46 Expect.equals(2, b.a.f); |
| 27 Expect.equals(2, b.a.f); | 47 Expect.equals(1, b.count); |
| 28 Expect.equals(1, b.count); | 48 var o = b.a; |
| 29 var o = b.a; | 49 Expect.equals(2, b.count); |
| 30 Expect.equals(2, b.count); | 50 b.a.f = 1; |
| 31 b.a.f = 1; | 51 Expect.equals(3, b.count); |
| 32 Expect.equals(3, b.count); | 52 Expect.equals(1, b._a.f); |
| 33 b.a.f += 1; | 53 b.a.f += 1; |
| 34 Expect.equals(4, b.count); | 54 Expect.equals(4, b.count); |
| 35 } | 55 Expect.equals(2, b._a.f); |
| 56 |
| 57 b.count = 0; |
| 58 b._a.f = 2; |
| 59 Expect.equals(0, b.count); |
| 60 Expect.equals(2, b.a[0]); |
| 61 Expect.equals(1, b.count); |
| 62 o = b.a; |
| 63 Expect.equals(2, b.count); |
| 64 b.a[0] = 1; |
| 65 Expect.equals(3, b.count); |
| 66 Expect.equals(1, b._a.f); |
| 67 b.a[0] += 1; |
| 68 Expect.equals(4, b.count); |
| 69 Expect.equals(2, b._a.f); |
| 70 |
| 71 b._a.g++; |
| 72 Expect.equals(1, b._a.gGetCount); |
| 73 Expect.equals(1, b._a.gSetCount); |
| 74 Expect.equals(1, b._a._g); |
| 75 |
| 76 globalA = b._a; |
| 77 globalA.f = 0; |
| 78 foo().f += 1; |
| 79 Expect.equals(1, fooCounter); |
| 80 Expect.equals(1, globalA.f); |
| 36 } | 81 } |
| 37 main() { | |
| 38 InstanceCompoundAssignmentOperatorTest.testMain(); | |
| 39 } | |
| OLD | NEW |