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; |
11 } | 11 } |
12 operator [](i) { | 12 operator [](i) { |
13 count++; | 13 count++; |
14 return _f; | 14 return _f; |
15 } | 15 } |
16 var count; | 16 var count; |
17 var _f; | 17 var _f; |
18 } | 18 } |
19 | 19 |
20 var result; | 20 var result; |
21 | 21 |
22 class A { | 22 class A { |
23 get field() { result.add(1); return 1; } | 23 get field { result.add(1); return 1; } |
24 set field(value) {} | 24 set field(value) {} |
25 | 25 |
26 static get static_field() { result.add(0); return 1; } | 26 static get static_field { result.add(0); return 1; } |
27 static set static_field(value) { result.add(1); } | 27 static set static_field(value) { result.add(1); } |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 class CompoundAssignmentOperatorTest { | 31 class CompoundAssignmentOperatorTest { |
32 | 32 |
33 static void testIndexed() { | 33 static void testIndexed() { |
34 Indexed indexed = new Indexed(); | 34 Indexed indexed = new Indexed(); |
35 Expect.equals(0, indexed.count); | 35 Expect.equals(0, indexed.count); |
36 var tmp = indexed[0]; | 36 var tmp = indexed[0]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 testIndexed(); | 81 testIndexed(); |
82 testIndexedMore(); | 82 testIndexedMore(); |
83 testIndexedMoreMore(); | 83 testIndexedMoreMore(); |
84 } | 84 } |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 main() { | 88 main() { |
89 CompoundAssignmentOperatorTest.testMain(); | 89 CompoundAssignmentOperatorTest.testMain(); |
90 } | 90 } |
OLD | NEW |