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

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

Issue 295933006: dart2dart: Introduce compound assignment and prefix increment in dart_codegen. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: SVN rebase Created 6 years, 6 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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree_printer.dart ('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
(Empty)
1 // Copyright (c) 2014, 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
5 import "package:expect/expect.dart";
6
7 var global = 0;
8
9 class Foo {
10 var field = 0;
11 static var staticField = 0;
12 }
13
14 field_compound1(obj) {
15 return obj.field = obj.field + 5;
16 }
17 field_compound2(obj) {
18 return obj.field = obj.field + 1;
19 }
20 field_compound3(obj) {
21 return obj.field = obj.field - 1;
22 }
23 field_compound4(obj) {
24 return obj.field = obj.field * 1;
25 }
26
27 static_compound1() {
28 return Foo.staticField = Foo.staticField + 5;
29 }
30 static_compound2() {
31 return Foo.staticField = Foo.staticField + 1;
32 }
33 static_compound3() {
34 return Foo.staticField = Foo.staticField - 1;
35 }
36 static_compound4() {
37 return Foo.staticField = Foo.staticField * 1;
38 }
39
40 global_compound1() {
41 return global = global + 5;
42 }
43 global_compound2() {
44 return global = global + 1;
45 }
46 global_compound3() {
47 return global = global - 1;
48 }
49 global_compound4() {
50 return global = global * 1;
51 }
52
53 local_compound1(x) {
54 x = x + 5;
55 if (x > 0) {
56 return x;
57 }
58 return -x;
59 }
60 local_compound2(x) {
61 x = x + 1;
62 if (x > 0) {
63 return x;
64 }
65 return -x;
66 }
67 local_compound3(x) {
68 x = x - 1;
69 if (x > 0) {
70 return x;
71 }
72 return -x;
73 }
74 local_compound4(x) {
75 x = x * 1;
76 if (x > 0) {
77 return x;
78 }
79 return -x;
80 }
81
82 main() {
83 var obj = new Foo();
84 Expect.equals(5, field_compound1(obj));
85 Expect.equals(5, obj.field);
86 Expect.equals(6, field_compound2(obj));
87 Expect.equals(6, obj.field);
88 Expect.equals(5, field_compound3(obj));
89 Expect.equals(5, obj.field);
90 Expect.equals(5, field_compound4(obj));
91 Expect.equals(5, obj.field);
92
93 Expect.equals(5, static_compound1());
94 Expect.equals(5, Foo.staticField);
95 Expect.equals(6, static_compound2());
96 Expect.equals(6, Foo.staticField);
97 Expect.equals(5, static_compound3());
98 Expect.equals(5, Foo.staticField);
99 Expect.equals(5, static_compound4());
100 Expect.equals(5, Foo.staticField);
101
102 Expect.equals(5, global_compound1());
103 Expect.equals(5, global);
104 Expect.equals(6, global_compound2());
105 Expect.equals(6, global);
106 Expect.equals(5, global_compound3());
107 Expect.equals(5, global);
108 Expect.equals(5, global_compound4());
109 Expect.equals(5, global);
110
111 Expect.equals(8, local_compound1(3));
112 Expect.equals(3, local_compound1(-8));
113 Expect.equals(4, local_compound2(3));
114 Expect.equals(7, local_compound2(-8));
115 Expect.equals(2, local_compound3(3));
116 Expect.equals(9, local_compound3(-8));
117 Expect.equals(3, local_compound4(3));
118 Expect.equals(8, local_compound4(-8));
119 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree_printer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698