Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: tests/language/compound_assignment_operator_test.dart

Issue 10270028: Fix wrong order of execution in compound assignment nodes (located by Kevin). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/vm/parser.cc ('K') | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
21
22 class A {
23 get field() { result.add(1); return 1; }
24 set field(value) {}
25 }
26
27
20 class CompoundAssignmentOperatorTest { 28 class CompoundAssignmentOperatorTest {
21 29
22 static void testIndexed() { 30 static void testIndexed() {
23 Indexed indexed = new Indexed(); 31 Indexed indexed = new Indexed();
24 Expect.equals(0, indexed.count); 32 Expect.equals(0, indexed.count);
25 var tmp = indexed[0]; 33 var tmp = indexed[0];
26 Expect.equals(1, indexed.count); 34 Expect.equals(1, indexed.count);
27 Expect.equals(100, indexed[4][0]); 35 Expect.equals(100, indexed[4][0]);
28 Expect.equals(2, indexed.count); 36 Expect.equals(2, indexed.count);
29 Expect.equals(100, indexed[4][0]++); 37 Expect.equals(100, indexed[4][0]++);
30 Expect.equals(3, indexed.count); 38 Expect.equals(3, indexed.count);
31 Expect.equals(101, indexed[4][0]); 39 Expect.equals(101, indexed[4][0]);
32 Expect.equals(4, indexed.count); 40 Expect.equals(4, indexed.count);
33 indexed[4][0] += 10; 41 indexed[4][0] += 10;
34 Expect.equals(5, indexed.count); 42 Expect.equals(5, indexed.count);
35 Expect.equals(111, indexed[4][0]); 43 Expect.equals(111, indexed[4][0]);
36 var i = 0; 44 var i = 0;
37 indexed[3][i++] += 1; 45 indexed[3][i++] += 1;
38 Expect.equals(1, i); 46 Expect.equals(1, i);
39 } 47 }
48
49
50 static testIndexedMore() {
51 result = [];
52 array() { result.add(0); return [0]; }
53 index() { result.add(1); return 0; }
54 middle() { result.add(2); }
55 sequence(a, b, c) { result.add(3); }
56
57 sequence(array()[index()] += 1, middle(), array()[index()] += 1);
58 Expect.listEquals([0, 1, 2, 0, 1, 3], result);
59 }
60
61 static testIndexedMoreMore() {
62 result = [];
63 middle() { result.add(2); }
64 obj() { result.add(0); return new A(); }
65 sequence(a, b, c) { result.add(3); }
66
67 sequence(obj().field += 1, middle(), obj().field += 1);
68 Expect.listEquals([0, 1, 2, 0, 1, 3], result);
69 }
70
40 71
41 static void testMain() { 72 static void testMain() {
42 testIndexed(); 73 testIndexed();
74 testIndexedMore();
75 testIndexedMoreMore();
43 } 76 }
44 } 77 }
78
45 main() { 79 main() {
46 CompoundAssignmentOperatorTest.testMain(); 80 CompoundAssignmentOperatorTest.testMain();
47 } 81 }
OLDNEW
« runtime/vm/parser.cc ('K') | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698