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

Unified Diff: tests/compiler/dart2js/field_update_test.dart

Issue 218993003: Emit read-modify-write of fields as assignment op. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add test Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/tracer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/field_update_test.dart
diff --git a/tests/compiler/dart2js/field_update_test.dart b/tests/compiler/dart2js/field_update_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f5a93bae397e71dd00f90e095660f18d259afb41
--- /dev/null
+++ b/tests/compiler/dart2js/field_update_test.dart
@@ -0,0 +1,97 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+import 'compiler_helper.dart';
+
+// Test for emitting JavaScript pre- and post-increment and assignment ops.
+
+const String TEST_1 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a + 1; return r; } // this.a++
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+const String TEST_2 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a + 1; return a; } // ++this.a
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+const String TEST_3 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a - 1; return r; } // this.a--
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+const String TEST_4 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a - 1; return a; } // --this.a
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+const String TEST_5 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a - 2; return a; } // this.a -= 2
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+const String TEST_6 = """
+class A {
+ var a = 42;
+ int foo() { var r = a; a = a * 2; return a; } // this.a *= 2
+}
+
+void main() {
+ var a = new A();
+ print(a.foo());
+}
+""";
+
+
+main() {
+ test(String code, Function f) {
+ asyncTest(() => compileAll(code, disableInlining: true).then((generated) {
+ Expect.isTrue(f(generated));
+ }));
+ }
+
+ test(TEST_1, (generated) => generated.contains(r'return this.a++;'));
+ test(TEST_2, (generated) => generated.contains(r'return ++this.a;'));
+ test(TEST_3, (generated) => generated.contains(r'return this.a--;'));
+ test(TEST_4, (generated) => generated.contains(r'return --this.a;'));
+ test(TEST_5, (generated) => generated.contains(r' this.a -= 2;'));
+ test(TEST_6, (generated) => generated.contains(r' this.a *= 2;'));
+}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/tracer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698