Chromium Code Reviews| 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; | |
| 9 } | 11 } |
| 10 | 12 |
| 11 | 13 |
| 12 class B { | 14 class B { |
| 13 B() : _a = new A(), count = 0 {} | 15 B() : _a = new A(), count = 0 {} |
| 14 get a() { | 16 get a() { |
| 15 count++; | 17 count++; |
| 16 return _a; | 18 return _a; |
| 17 } | 19 } |
| 18 var _a; | 20 var _a; |
| 19 var count; | 21 var count; |
| 20 } | 22 } |
| 21 | 23 |
| 22 | 24 |
| 23 class InstanceCompoundAssignmentOperatorTest { | 25 main() { |
| 24 static void testMain() { | 26 B b = new B(); |
| 25 B b = new B(); | 27 Expect.equals(0, b.count); |
| 26 Expect.equals(0, b.count); | 28 Expect.equals(2, b.a.f); |
| 27 Expect.equals(2, b.a.f); | 29 Expect.equals(1, b.count); |
| 28 Expect.equals(1, b.count); | 30 var o = b.a; |
|
Lasse Reichstein Nielsen
2012/04/10 12:31:13
How about also counting gets/sets of 'f' (i.e., ma
floitsch
2012/04/10 15:51:00
Done.
| |
| 29 var o = b.a; | 31 Expect.equals(2, b.count); |
| 30 Expect.equals(2, b.count); | 32 b.a.f = 1; |
| 31 b.a.f = 1; | 33 Expect.equals(3, b.count); |
| 32 Expect.equals(3, b.count); | 34 Expect.equals(1, b._a.f); |
| 33 b.a.f += 1; | 35 b.a.f += 1; |
| 34 Expect.equals(4, b.count); | 36 Expect.equals(4, b.count); |
| 35 } | 37 Expect.equals(2, b._a.f); |
| 38 | |
| 39 b.count = 0; | |
| 40 b._a.f = 2; | |
| 41 Expect.equals(0, b.count); | |
| 42 Expect.equals(2, b.a[0]); | |
| 43 Expect.equals(1, b.count); | |
| 44 o = b.a; | |
| 45 Expect.equals(2, b.count); | |
| 46 b.a[0] = 1; | |
| 47 Expect.equals(3, b.count); | |
| 48 Expect.equals(1, b._a.f); | |
| 49 b.a[0] += 1; | |
| 50 Expect.equals(4, b.count); | |
| 51 Expect.equals(2, b._a.f); | |
| 36 } | 52 } |
| 37 main() { | |
| 38 InstanceCompoundAssignmentOperatorTest.testMain(); | |
| 39 } | |
| OLD | NEW |