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 // Tests that lhs of a compound assignement is executed only once. | |
5 | |
6 | |
7 class Indexed { | |
8 Indexed() : _f = new List(10), count = 0 { | |
9 _f[0] = 100; | |
10 _f[1] = 200; | |
11 } | |
12 operator [](i) { | |
13 count++; | |
14 return _f; | |
15 } | |
16 var count; | |
17 var _f; | |
18 } | |
19 | |
20 class CompoundAssignmentOperatorTest { | |
21 | |
22 static void testIndexed() { | |
23 Indexed indexed = new Indexed(); | |
24 Expect.equals(0, indexed.count); | |
25 var tmp = indexed[0]; | |
26 Expect.equals(1, indexed.count); | |
27 Expect.equals(100, indexed[4][0]); | |
28 Expect.equals(2, indexed.count); | |
29 Expect.equals(100, indexed[4][0]++); | |
30 Expect.equals(3, indexed.count); | |
31 Expect.equals(101, indexed[4][0]); | |
32 Expect.equals(4, indexed.count); | |
33 indexed[4][0] += 10; | |
34 Expect.equals(5, indexed.count); | |
35 Expect.equals(111, indexed[4][0]); | |
36 var i = 0; | |
37 indexed[3][i++] += 1; | |
38 Expect.equals(1, i); | |
39 } | |
40 | |
41 static void testMain() { | |
42 testIndexed(); | |
43 } | |
44 } | |
45 main() { | |
46 CompoundAssignmentOperatorTest.testMain(); | |
47 } | |
OLD | NEW |