| 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 // Tests that lhs of a compound assignement is executed only once. | 4 // Tests that lhs of a compound assignement is executed only once. |
| 5 | 5 |
| 6 | 6 |
| 7 class Indexed { | 7 class Indexed { |
| 8 Indexed() : _f = new List(10), count = 0 { | 8 Indexed() : _f = new List(10), count = 0 { |
| 9 _f[0] = 100; | 9 _f[0] = 100; |
| 10 _f[1] = 200; | 10 _f[1] = 200; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 Expect.equals(3, indexed.count); | 41 Expect.equals(3, indexed.count); |
| 42 Expect.equals(101, indexed[4][0]); | 42 Expect.equals(101, indexed[4][0]); |
| 43 Expect.equals(4, indexed.count); | 43 Expect.equals(4, indexed.count); |
| 44 indexed[4][0] += 10; | 44 indexed[4][0] += 10; |
| 45 Expect.equals(5, indexed.count); | 45 Expect.equals(5, indexed.count); |
| 46 Expect.equals(111, indexed[4][0]); | 46 Expect.equals(111, indexed[4][0]); |
| 47 var i = 0; | 47 var i = 0; |
| 48 indexed[3][i++] += 1; | 48 indexed[3][i++] += 1; |
| 49 Expect.equals(1, i); | 49 Expect.equals(1, i); |
| 50 } | 50 } |
| 51 | 51 |
| 52 | |
| 53 static testIndexedMore() { | 52 static testIndexedMore() { |
| 54 result = []; | 53 result = []; |
| 55 array() { result.add(0); return [0]; } | 54 array() { result.add(0); return [0]; } |
| 56 index() { result.add(1); return 0; } | 55 index() { result.add(1); return 0; } |
| 57 middle() { result.add(2); } | 56 middle() { result.add(2); } |
| 58 sequence(a, b, c) { result.add(3); } | 57 sequence(a, b, c) { result.add(3); } |
| 59 | 58 |
| 60 sequence(array()[index()] += 1, middle(), array()[index()] += 1); | 59 sequence(array()[index()] += 1, middle(), array()[index()] += 1); |
| 61 Expect.listEquals([0, 1, 2, 0, 1, 3], result); | 60 Expect.listEquals([0, 1, 2, 0, 1, 3], result); |
| 62 } | 61 } |
| 63 | 62 |
| 64 static testIndexedMoreMore() { | 63 static testIndexedMoreMore() { |
| 65 result = []; | 64 result = []; |
| 66 middle() { result.add(2); } | 65 middle() { result.add(2); } |
| 67 obj() { result.add(0); return new A(); } | 66 obj() { result.add(0); return new A(); } |
| 68 sequence(a, b, c) { result.add(3); } | 67 sequence(a, b, c) { result.add(3); } |
| 69 | 68 |
| 70 sequence(obj().field += 1, middle(), obj().field += 1); | 69 sequence(obj().field += 1, middle(), obj().field += 1); |
| 71 Expect.listEquals([0, 1, 2, 0, 1, 3], result); | 70 Expect.listEquals([0, 1, 2, 0, 1, 3], result); |
| 72 | 71 |
| 73 result = []; | 72 result = []; |
| 74 sequence(A.static_field++, middle(), A.static_field++); | 73 sequence(A.static_field++, middle(), A.static_field++); |
| 75 Expect.listEquals([0, 1, 2, 0, 1, 3], result); | 74 Expect.listEquals([0, 1, 2, 0, 1, 3], result); |
| 76 } | 75 } |
| 77 | |
| 78 | 76 |
| 79 static void testMain() { | 77 static void testMain() { |
| 80 for (int i = 0; i < 1000; i++) { | 78 for (int i = 0; i < 1000; i++) { |
| 81 testIndexed(); | 79 testIndexed(); |
| 82 testIndexedMore(); | 80 testIndexedMore(); |
| 83 testIndexedMoreMore(); | 81 testIndexedMoreMore(); |
| 84 } | 82 } |
| 85 } | 83 } |
| 86 } | 84 } |
| 87 | 85 |
| 88 main() { | 86 main() { |
| 89 CompoundAssignmentOperatorTest.testMain(); | 87 CompoundAssignmentOperatorTest.testMain(); |
| 90 } | 88 } |
| OLD | NEW |