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

Unified Diff: tests/language/conditional_rewrite_test.dart

Issue 1185333002: dart2js cps: Use JS semantics for logical operators in the tree IR. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Renamed method Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/optimization/logical_rewriter.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/conditional_rewrite_test.dart
diff --git a/tests/language/conditional_rewrite_test.dart b/tests/language/conditional_rewrite_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..69a6398b42932bc649fb47eef6e9b782830e353c
--- /dev/null
+++ b/tests/language/conditional_rewrite_test.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2015, 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";
+
+// Test that dart2js does not rewrite conditional into logical operators
+// in cases where it changes which falsy value is returned.
+
+posFalse(x, y) => x != null ? y : false;
+negFalse(x, y) => x != null ? !y : false;
+posNull(x, y) => x != null ? y : null;
+negNull(x, y) => x != null ? !y : null;
+
+main() {
+ bool isCheckedMode = false;
+ assert((isCheckedMode = true));
+
+ Expect.equals(false, posFalse(null, false));
+ Expect.equals(false, negFalse(null, false));
+ Expect.equals(null, posNull(null, false));
+ Expect.equals(null, negNull(null, false));
+
+ Expect.equals(false, posFalse(null, true));
+ Expect.equals(false, negFalse(null, true));
+ Expect.equals(null, posNull(null, true));
+ Expect.equals(null, negNull(null, true));
+
+ Expect.equals(false, posFalse([], false));
+ Expect.equals(true, negFalse([], false));
+ Expect.equals(false, posNull([], false));
+ Expect.equals(true, negNull([], false));
+
+ Expect.equals(true, posFalse([], true));
+ Expect.equals(false, negFalse([], true));
+ Expect.equals(true, posNull([], true));
+ Expect.equals(false, negNull([], true));
+
+ if (!isCheckedMode) {
+ Expect.equals(null, posFalse([], null));
+ Expect.equals(true, negFalse([], null));
+ Expect.equals(null, posNull([], null));
+ Expect.equals(true, negNull([], null));
+
+ var y = {};
+ Expect.identical(y, posFalse([], y));
+ Expect.equals(true, negFalse([], y));
+ Expect.identical(y, posNull([], y));
+ Expect.equals(true, negNull([], y));
+ }
+}
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/optimization/logical_rewriter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698